GDB中特定对象的断点

Breakpoint in GDB for specific object

本文关键字:断点 对象 GDB      更新时间:2023-10-16

我需要检查从哪里调用某个特定对象的析构函数。假设它是std::字符串,位于0x9b993e4。我尝试执行以下操作:

b std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string if (this==0x9b993e4)

但GDB说"没有符号",这是"在当前的背景下"我也试过

b std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string if (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::this==0x9b993e4)

GDB看起来像设置断点,但当我运行时,它会停止并写入

Error in testing breakpoint condition:
There is no field named this

有人能告诉我如何破解特定对象的析构函数吗?

提前感谢!

我找不到比使用寄存器更好的方法了。所以,在x86上,你可以检查EAX,在ARM上,可能是R0。

b ClassName::~ClassName if ($eax==<object_address>)

在我的情况下,这个解决方案不适用于某些全局静态对象。

break std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()