Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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." 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

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!

like image 784
Alex Avatar asked Dec 29 '25 21:12

Alex


1 Answers

I could not find any better way than use registers. So, on x86 you can check EAX, on ARM, probably, R0.

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

This solution doesn't work for some global static objects in my case.

like image 119
Alex Avatar answered Jan 01 '26 10:01

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!