【问题标题】:Set breakpoint using wildcards?使用通配符设置断点?
【发布时间】:2015-04-19 06:22:40
【问题描述】:

我正在尝试调试一个严重依赖继承的类。调试会话很乏味,因为它涉及一个对象调用链中另一个对象上的相同函数。我浪费了很多时间来执行不相关的代码,而这些代码本来可以更好地花在其他地方。

这很简单:我想使用通配符在类实例上设置断点,例如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]

【问题讨论】:

标签: c++ debugging gdb wildcard breakpoints


【解决方案1】:

您可以在语法中使用 rbreak:

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

见 gdb 人: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

调试器在找到要中断的点方面没有问题...您需要尝试.* 而不是普通的通配符。

【讨论】:

  • 谢谢。难的(C++ 和模板)没有乐趣。我更新了问题以包含结果。
  • 你确定你没有忘记点:CryptoPP::DL_EncryptionAlgorithm_Xor&lt;.*&gt;::SymmetricEncrypt
  • 是的,我没有使用点。手册页说该点已经存在。谢谢,解决了。
猜你喜欢
  • 2017-02-12
  • 2014-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-25
  • 2017-08-08
相关资源
最近更新 更多