简体   繁体   English

GDB中针对特定对象的断点

[英]Breakpoint in GDB for specific object

I need to check where destructor of some specific object is called from. 我需要检查一些特定对象的析构函数是从哪里调用的。 Let's say it is std::string at 0x9b993e4. 假设它是在0x9b993e4的std :: string。 I tried to execute following: 我试着执行以下内容:

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

But GDB says "No symbol "this" in current context." 但是GDB在当前的背景下说“没有符号”。 I also tried 我也试过了

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 looks like set breakpoint, but when I run, it stops and writes GDB看起来像设置断点,但是当我运行时,它会停止并写入

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

Can anyone tell me how to break in destructor of specific object? 任何人都可以告诉我如何打破特定对象的析构函数?

Thanks in advance! 提前致谢!

I could not find any better way than use registers. 我找不到比使用寄存器更好的方法。 So, on x86 you can check EAX, on ARM, probably, R0. 因此,在x86上,您可以检查ARM上的EAX,可能是R0。

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

This solution doesn't work for some global static objects in my case. 在我的情况下,此解决方案不适用于某些全局静态对象。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM