举例

举例1:简单dict

Swift的Dict值:

{
    2282 = 0;
    4902 = 1;
    5074 = 1;
}

对应的例子,已经放到了内存布局图中了,详见:

Dictionary字典的内存布局图

此处只额外贴出:

相关调试内容

(lldb) po 0x000000028173c680
{
    2282 = 0;
    4902 = 1;
    5074 = 1;
}

->

(lldb) x/8xg 0x000000028173c680
0x28173c680: 0x0000000121881e78 0x0000000000000003
0x28173c690: 0x0000000000000003 0x0000000000000003
0x28173c6a0: 0x1fd62ad000000002 0x000000028173c680
0x28173c6b0: 0x000000028173c6c8 0x000000028173c708
(lldb) x/20xg 0x000000028173c680
0x28173c680: 0x0000000121881e78 0x0000000000000003
0x28173c690: 0x0000000000000003 0x0000000000000003
0x28173c6a0: 0x1fd62ad000000002 0x000000028173c680
0x28173c6b0: 0x000000028173c6c8 0x000000028173c708
0x28173c6c0: 0xfffffffffffffffd 0x0000000032303934
0x28173c6d0: 0xe400000000000000 0x00000002006b11e0
0x28173c6e0: 0x00000002006c4de0 0x0000000032383232
0x28173c6f0: 0xe400000000000000 0x0000000034373035
0x28173c700: 0xe400000000000000 0x0000000000000031
0x28173c710: 0xe100000000000000 0x000000010b615b20

可以继续了:

  • 0xd = 0b 1101
    • 有效index
      • 0
      • 2
      • 3

->

(lldb) x/40xg 0x000000028173c680
0x28173c680: 0x0000000121881e78 0x0000000000000003
0x28173c690: 0x0000000000000003 0x0000000000000003
0x28173c6a0: 0x1fd62ad000000002 0x000000028173c680
0x28173c6b0: 0x000000028173c6c8 0x000000028173c708
0x28173c6c0: 0xfffffffffffffffd 0x0000000032303934
0x28173c6d0: 0xe400000000000000 0x00000002006b11e0
0x28173c6e0: 0x00000002006c4de0 0x0000000032383232
0x28173c6f0: 0xe400000000000000 0x0000000034373035
0x28173c700: 0xe400000000000000 0x0000000000000031
0x28173c710: 0xe100000000000000 0x000000010b615b20
0x28173c720: 0x000000028220fae0 0x0000000000000030
0x28173c730: 0xe100000000000000 0x0000000000000031
0x28173c740: 0xe100000000000000 0x0000000280231180
0x28173c750: 0x0000000000000000 0x0000000000000000
0x28173c760: 0x0000000000000000 0x0000000000000000
0x28173c770: 0x0000000000000000 0x0000000000000000
0x28173c780: 0x0000000000000000 0x0000000000000000
0x28173c790: 0x0000000000000000 0x0000000000000000
0x28173c7a0: 0x0000000000000000 0x0000000000000000
0x28173c7b0: 0x0000000000000000 0x0000000000000000
(lldb) 

(lldb) x/30xg 0x000000028173c680
0x28173c680: 0x0000000121881e78 0x0000000000000003
0x28173c690: 0x0000000000000003 0x0000000000000003
0x28173c6a0: 0x1fd62ad000000002 0x000000028173c680
0x28173c6b0: 0x000000028173c6c8 0x000000028173c708
0x28173c6c0: 0xfffffffffffffffd 0x0000000032303934
0x28173c6d0: 0xe400000000000000 0x00000002006b11e0
0x28173c6e0: 0x00000002006c4de0 0x0000000032383232
0x28173c6f0: 0xe400000000000000 0x0000000034373035
0x28173c700: 0xe400000000000000 0x0000000000000031
0x28173c710: 0xe100000000000000 0x000000010b615b20
0x28173c720: 0x000000028220fae0 0x0000000000000030
0x28173c730: 0xe100000000000000 0x0000000000000031
0x28173c740: 0xe100000000000000 0x0000000280231180
0x28173c750: 0x0000000000000000 0x0000000000000000
0x28173c760: 0x0000000000000000 0x0000000000000000

->

(lldb) po 0x0000000121881e78
_TtGCs18_DictionaryStorageSSSS_$

(lldb) p/c 0x0000000032303934
(int) 4902
(lldb) p/c 0x0000000032383232
(int) 2282
(lldb) p/c 0x0000000034373035
(int) 5074
(lldb) p/c 0x0000000000000031
(int) 1\0\0\0
(lldb) p/c 0x0000000000000030
(int) 0\0\0\0
(lldb) x/2xw 0x28173c6a0
0x28173c6a0: 0x00000002 0x1fd62ad0
(lldb) x/4xh 0x28173c6a0
0x28173c6a0: 0x0002 0x0000 0x2ad0 0x1fd6
(lldb) x/8xb 0x28173c6a0
0x28173c6a0: 0x02 0x00 0x00 0x00 0xd0 0x2a 0xd6 0x1f
(lldb) p/d 0x1fd62ad0
(int) 534129360

举例2:复杂dict - key是String,value是AnyPrimitive

调试到复杂dict:

(lldb) reg r x0 x1 x2 x8
      x0 = 0x000000011100b200
      x1 = 0x00000001031145b0  WhatsApp`$s10LeafFilterVN
      x2 = 0x0000000103114658  WhatsApp`LeafFilter_related_1030B4658
      x8 = 0x00000001006409a8  WhatsApp`sub_1005E09A8
(lldb) po 0x000000011100b200
4580225536
(lldb) x/6xg 0x000000011100b200
0x11100b200: 0x000000010fe175c8 0x0000000000000003
0x11100b210: 0x0000000000000007 0x000000000000000c
0x11100b220: 0xf3473a6200000004 0x000000011100b200
(lldb) po 0x000000010fe175c8
_TtGCs18_DictionaryStorageSSOVO14MainAppLibrary9OfflineAB8UserInfoP10$102e672c012AnyPrimitive_$

->

此处是个Dictionary,value元素是

  • AnyPrimitive
    • MainAppLibrary.OfflineAB.UserInfo 的 AnyPrimitive

查看内存值:

(lldb) x/80xg 0x000000011100b200
0x11100b200: 0x000000010fe175c8 0x0000000000000003
0x11100b210: 0x0000000000000007 0x000000000000000c
0x11100b220: 0xf3473a6200000004 0x000000011100b200
0x11100b230: 0x000000011100b248 0x000000011100b348
0x11100b240: 0xffffffffffff9299 0x6d726f6674616c70
0x11100b250: 0xe800000000000000 0x00000001e84fab78
0x11100b260: 0x00000001e84fab78 0x00000001e84fab78
0x11100b270: 0x00000001e84fab78 0x695f656369766564
0x11100b280: 0xe900000000000064 0x69737265765f736f
0x11100b290: 0xea00000000006e6f 0x00000001e84fab78
0x11100b2a0: 0x00000001e84fab78 0x00000001e84fab78
0x11100b2b0: 0x00000001e84fab78 0x6c6975625f707061
0x11100b2c0: 0xe900000000000064 0x00000001e84fab78
0x11100b2d0: 0x00000001e84fab78 0x6e5f656369766564
0x11100b2e0: 0xeb00000000656d61 0x00000001e84fab78
0x11100b2f0: 0x00000001e84fab78 0x00000001e84fab78
0x11100b300: 0x00000001e84fab78 0x5f657361656c6572
0x11100b310: 0xef6c656e6e616863 0x00000001e84fab78
0x11100b320: 0x00000001e84fab78 0x00000001e84fab78
0x11100b330: 0x00000001e84fab78 0x737265765f707061
0x11100b340: 0xeb000000006e6f69 0x0000656e6f687069
0x11100b350: 0xe600000000000000 0x000000010fe17468
0x11100b360: 0x000000010fe16950 0x000000010fe169f8
0x11100b370: 0x00000001e84fab01 0x00000001e84fab78
0x11100b380: 0x00000001e84fab78 0x00000001e84fab78
0x11100b390: 0x00000001e84fab78 0x00000001e84fab78
0x11100b3a0: 0x00000001e84fab78 0x00000001e84fab78
0x11100b3b0: 0x00000001e84fab78 0x00000001e84fab78
0x11100b3c0: 0x00000001e84fab78 0x00000001e84fab78
0x11100b3d0: 0x00000001e84fab78 0xc000000000000024
0x11100b3e0: 0x40000002820700c0 0x00000002820700c0
0x11100b3f0: 0x000000010fe16950 0x000000010fe169f8
0x11100b400: 0x00000001e84fab01 0x000000014164cccd
0x11100b410: 0xc00000000000000a 0x40000002835413a0
0x11100b420: 0x000000010fe17798 0x000000010fe17840
0x11100b430: 0x00000001e84fab00 0x00000001e84fab78
0x11100b440: 0x00000001e84fab78 0x00000001e84fab78
0x11100b450: 0x00000001e84fab78 0x00000001e84fab78
0x11100b460: 0x00000001e84fab78 0x00000001e84fab78
0x11100b470: 0x00000001e84fab78 0x00000001e84fab78

->

(lldb) p/c 0x6d726f6674616c70
(long) platform

(lldb) p/c 0x695f656369766564
(long) device_i
(lldb) p/c 0xe900000000000064
(unsigned long) d\0\0\0\0\0\0\xe9

(lldb) p/c 0x69737265765f736f
(long) os_versi
(lldb) p/c 0xea00000000006e6f
(unsigned long) on\0\0\0\0\0\xea

(lldb) p/c 0x6c6975625f707061
(long) app_buil
(lldb) p/c 0x64
(int) d\0\0\0

(lldb) p/c 0x6e5f656369766564
(long) device_n
(lldb) p/c 0x00000000656d61
(int) ame\0

(lldb) p/c 0x5f657361656c6572
(long) release_
(lldb) p/c 0xef6c656e6e616863
(unsigned long) channel\xef

(lldb) p/c 0x737265765f707061
(long) app_vers
(lldb) p/c 0xeb000000006e6f69
(unsigned long) ion\0\0\0\0\xeb

keys:

  • platform
  • device_id
  • os_version
  • app_build
  • device_name
  • release_channel
  • app_version
  • iphone

和:

(lldb) p/c 0x0000656e6f687069
(long) iphone\0\0

(lldb) x/s "0x40000002820700c0 + 0x20"
0x2820700e0: "5E8-8164-1AEA05E45CD9"
(lldb) po 0x00000002820700c0
2DE85147-8D62-45E8-8164-1AEA05E45CD9
...

values:

  • iphone
  • 2DE85147-8D62-45E8-8164-1AEA05E45CD9
    • 注:Swift的Shared=Bridged的String
  • ...

results matching ""

    No results matching ""