(lldb) command script import lldb.macosx.heap
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.
(lldb) ptr_refs 0x000060000000c000
0x00007ff7bfeff1f0: stack in frame #0 of thread #1: tid 0x14e058 in variable at 0x7ff7bfeff1f0:
(int *) newPtr = 0x000060000000c000
0x00007ff7bfeff1f8: stack in frame #0 of thread #1: tid 0x14e058 in variable at 0x7ff7bfeff1f8:
(int *) var = 0x000060000000c000
0x00007ff7bfeff210: stack in frame #1 of thread #1: tid 0x14e058
0x00007ff7bfeff218: stack in frame #1 of thread #1: tid 0x14e058 in variable at 0x7ff7bfeff218:
(int *) ptr2 = 0x000060000000c000
0x00007ff7bfeff220: stack in frame #1 of thread #1: tid 0x14e058 in variable at 0x7ff7bfeff220:
(int *) ptr = 0x000060000000c000
最后,在lldb下,您可以使用frame命令检查frame #1实际上是什么:
(lldb) frame select 1
frame #1: 0x0000000100003115 CPPPlayground`main at main.cpp:19:5
16 int* ptr = new int{2};
17 delete ptr;
18 int* ptr2 = ptr;
-> 19 func(ptr);
^
20 }
(lldb) frame info
frame #1: 0x0000000100003115 CPPPlayground`main at main.cpp:19:5
1条答案
按热度按时间baubqpgj1#
在macOS下有所谓的
lldb.macosx.heap
脚本,它们在整个系统范围内可用,并为lldb
提供额外的诊断手段。让我们假设您有这样一个极简的代码(其中相当多的指针指向int
的一个已删除示例):首先,在调试会话下,您需要加载这些工具:
然后,假设你已经在
std::cout
行停止了执行,并且可以看到newPtr
指向的地址(在我的例子中是0x000060000000c000
),你可以打印所有其他指向同一地址的指针:最后,在
lldb
下,您可以使用frame
命令检查frame #1
实际上是什么: