Set a breakpoint using wildcards?

I am trying to debug a class that is heavily dependent on inheritance. A debugging session is tedious because it involves one object calling the same function on another object in the chain. I spend a lot of time making unnecessary code that could be better spent elsewhere.

Here is a simple one: I want to set a breakpoint for an instance of the class using a wildcard, for example b Foo::* . That way, when the material that interests me falls within the scope (e.g., a static function or a member function), the debugger will be bound.

Here's the tricky one: a parameterized class: I want to set a breakpoint on the template function of a class member using a wildcard, for example b Foo<*>::bar . (The real problem is much worse, because the template parameters themselves are templates themselves).

Although GDB seems to allow me to install one, the debugger does not stop (see below). He claims to set a milestone for future workloads. In fact, I used static binding and the characters are already present. No libraries will be loaded.

How to set a breakpoint using wildcards?


 (gdb) b CryptoPP::PK_EncryptorFilter::* Function "CryptoPP::PK_EncryptorFilter::*" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 2 (CryptoPP::PK_EncryptorFilter::*) pending. (gdb) r Starting program: /home/cryptopp-ecies/ecies-test.exe Attack at dawn! [Inferior 1 (process 5163) exited normally] 

and

 (gdb) rbreak CryptoPP::DL_EncryptionAlgorithm_Xor<*>::SymmetricEncrypt (gdb) r Starting program: /home/cryptopp-ecies/ecies-test.exe Attack at dawn! [Inferior 1 (process 5470) exited normally] ... (gdb) rbreak CryptoPP::*::SymmetricEncrypt (gdb) r Starting program: /home/cryptopp-ecies/ecies-test.exe Attack at dawn! [Inferior 1 (process 5487) exited normally] 
+6
source share
1 answer

You can use rbreak in the syntax:

 (gdb) rbreak ^CryptoPP::PK_EncryptorFilter::.* 

See man gdb: https://sourceware.org/gdb/onlinedocs/gdb/Set-Breaks.html

Edit:

I did some research and created main.cc as follows:

 #include <cstdio> template <class OnlyOne> class MyTemplate { public: OnlyOne oo; void myfunc(){ printf("debug\n"); } }; int main() { MyTemplate<int> mt; mt.myfunc(); return 0; } 

Then in gdb:

 (gdb) rbreak MyTemplate<.*>::myfunc Breakpoint 1 at 0x40055e: file main.cc, line 7. void MyTemplate<int>::myfunc(); (gdb) r 

Debuger has no problem finding dot breaks ... you need to try .* Instead of just a wildcard.

+7
source

Source: https://habr.com/ru/post/985447/


All Articles