jww*_*jww 6 c++ debugging gdb breakpoints wildcard
我正在尝试调试一个严重依赖继承的类.调试会话很繁琐,因为它涉及一个对象在链中的另一个对象上调用相同的函数.我浪费了很多时间来处理不相关的代码,这些代码可以更好地用于其他地方.
这是一个简单的方法:我想使用通配符在类实例上设置断点,例如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]
Run Code Online (Sandbox Code Playgroud)
和:
(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]
Run Code Online (Sandbox Code Playgroud)
您可以在语法中使用rbreak:
(gdb) rbreak ^CryptoPP::PK_EncryptorFilter::.*
Run Code Online (Sandbox Code Playgroud)
请参阅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;
}
Run Code Online (Sandbox Code Playgroud)
然后在gdb中:
(gdb) rbreak MyTemplate<.*>::myfunc
Breakpoint 1 at 0x40055e: file main.cc, line 7.
void MyTemplate<int>::myfunc();
(gdb) r
Run Code Online (Sandbox Code Playgroud)
Debuger找到要破解的点没有问题......你需要尝试.*而不是普通的通配符.