使用通配符设置断点?

时间:2015-04-19 06:22:41

标签: c++ debugging gdb wildcard breakpoints

我试图调试一个严重依赖继承的类。调试会话很繁琐,因为它涉及一个对象在链中的另一个对象上调用相同的函数。我浪费了大量时间来处理不相关的代码,这些代码可以更好地用于其他地方。

这里很简单:我想使用通配符在类实例上设置断点,例如b Foo::*。这样,当我感兴趣的东西进入范围(如静态函数或成员函数)时,调试器将会捕捉。

这里有一个难点:参数化类:我想使用通配符(如b Foo<*>::bar)在模板化类的成员函数上设置断点。 (真正的问题比这更糟糕,因为模板参数本身就是模板类。)

虽然GDB似乎让我设置了一个,但调试器并没有停止(见下文)。它声称它设置了未来负载的断点。事实上,我使用静态链接,符号已经存在。将不会加载库。

如何使用通配符设置断点?


(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]

(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]

1 个答案:

答案 0 :(得分:7)

您可以在语法中使用rbreak:

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

请参阅gdb man:https://sourceware.org/gdb/onlinedocs/gdb/Set-Breaks.html

编辑:

我做了一些调查并创建了main.cc如下:

#include <cstdio>

template <class OnlyOne> class MyTemplate {
public:
    OnlyOne oo;
    void myfunc(){
       printf("debug\n");
    }
};


int main() {
   MyTemplate<int> mt;
   mt.myfunc();
   return 0;
}

然后在gdb中:

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

Debuger找到要破解的点没有问题......你需要尝试.*而不是普通的通配符。

相关问题