Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set breakpoint using wildcards?

I'm trying to debug a class that relies heavily on inheritance. A debugging session is tedious because it involves one object calling the same function on another object in a chain. I'm wasting a lot of time stepping irrelevant code that could be better spent elsewhere.

Here's the easy one: I want to set a breakpoint on a class instance using a wildcard, like b Foo::*. This way, when the stuff I am interested in enters scope (like a static function or a member function), the debugger will snap.

Here's the hard one: a parametrized class: I want to set a breakpoint on a templated class's member function using a wildcard, like b Foo<*>::bar. (The real problem is much worse than this because the template parameters are themselves template classes).

Though GDB appears to let me set one, the debugger does not stop (see below). It claims its setting a breakpoint on future loads. In fact, I used static linking and the symbols are already present. There will be no libraries loaded.

How do I 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]
like image 313
jww Avatar asked Apr 19 '15 06:04

jww


Video Answer


1 Answers

You could use rbreak in a syntax:

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

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

Edit:

I did some investigation 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 with finding the points to break... You need to try .* instead of plain wildcard character.

like image 110
W.F. Avatar answered Oct 14 '22 16:10

W.F.