如何在 gdb 中为 C++ 设置 operator() 断点?
我在 C++ 类中有 2 个方法,如下所示:
class myClass {
public:
void operator()( string myString ) {
// Some code
}
void myMethod() { ... }
}
对于常规方法,我可以简单地在 GDB 中将断点设置为:
b myClass::myMethod
但是如何为第一个方法设置断点?
更新:
最初答案 (b myClass ::operator()) 中的建议不起作用:(
b myClass::operator()
Function "myClass::operator()" not defined.
谢谢!
I have 2 methods in C++ class as follows:
class myClass {
public:
void operator()( string myString ) {
// Some code
}
void myMethod() { ... }
}
For a regular method, I can simply set the breakpoint in GDB as:
b myClass::myMethod
But how do I set the breakpoint for the first method?
UPDATE:
The suggestions from initial answers (b myClass ::operator()) does not work :(
b myClass::operator()
Function "myClass::operator()" not defined.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
gdb 还会在特定行号处设置断点。例如
b 文件.cc:45
gdb will also take breakpoints at specific line numbers. For example
b file.cc:45
一样。
myClass::operator()(string)
是一个常规方法。如果您有多个重载的
operator()
方法(例如 const 和非 const 版本),gdb 应该提供在何处设置断点的选择:http://sunsite.ualberta.ca/Documentation/Gnu/gdb-5.0/html_node/gdb_35.html# SEC35
您可能必须确保方法
operator()(string)
确实已编译。编辑:
我测试了以下文件test.cpp:
用
g++ test.cpp -o test
编译,运行gdb test
(版本GNU gdb 6.3.50-20050815(苹果版gdb-1344)),输入start
才可以设置断点。b 'myClass::operator()(string)'
和b myClass::operator()
都有效。
Just the same.
myClass::operator()(string)
is a regular method.If you have several overloaded
operator()
methods (e.g. a const and a non-const version) gdb should offer the choice where to set the breakpoint:http://sunsite.ualberta.ca/Documentation/Gnu/gdb-5.0/html_node/gdb_35.html#SEC35
You may have to make sure that method
operator()(string)
is actually compiled.Edit:
I've tested the following file test.cpp:
Compiled with
g++ test.cpp -o test
, rangdb test
(version GNU gdb 6.3.50-20050815 (Apple version gdb-1344)), typedstart
and only then could I set breakpoints.b 'myClass::operator()(string)'
andb myClass::operator()
both worked.
一些 C++ 函数名称确实很难正确输入。更糟糕的是,gdb 的自动完成功能经常与 C++ 名称混淆。我使用这个技巧
注意函数开头的单引号。这有助于 gdb 的自动完成程序。
Some C++ functions names can be really hard to type out correctly. Worse yet, gdb's autocompletion often gets confused with c++ names. I use this trick
Note the single quote at the beginning of the function. That helps gdb's autocompleter.