c++ - GDB:警告:在重载方法上设置了多个断点

标签 c++ gdb breakpoints

anisha@linux-dopx:~> g++ -Wall -pedantic breakpoints.cpp -g
anisha@linux-dopx:~> gdb a.out
(gdb) b X::X
Breakpoint 1 at 0x400ac1: file breakpoints.cpp, line 14.
Breakpoint 2 at 0x400aa0: file breakpoints.cpp, line 9.
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.
(gdb)

设置断点的方法是什么 在默认构造函数上,这样 GDB 不会创建不必要的断点 在其重载的同行上?

或者是它预期的GDB的问题 用户删除它的烂摊子? 还是我漏掉了一点?

编辑 1.

对于下面的代码:

class X
{
    public:
        X   () 
        {
            std :: cout << "\nIn the default constructor";
        }

        X   (int) 
        {
            std :: cout << "\nIn the parameterized constructor";
        }

        ~X () {}
};

我试过:

(gdb) b X:: X (11)
the class X does not have any method named X (11)
Hint: try 'X:: X (11)<TAB> or 'X:: X (11)<ESC-?>
(Note leading single quote.)
Make breakpoint pending on future shared library load? (y or [n]) 

没有帮助!

编辑 2.

感谢 osgx,以下工作:

(gdb) b X::X(int)
Breakpoint 5 at 0x400ac1: file breakpoints.cpp, line 14.
(gdb) b X::X()
Breakpoint 6 at 0x400aa0: file breakpoints.cpp, line 9.
(gdb) 

最佳答案

我认为,这种情况很正常。有些 ABI 会为一个类生成两个构造函数。当您询问 b X::X 时,gdb 将检测两个构造函数并设置两个断点。 (抱歉,这不是你的情况)

“设置了多个断点。”重载方法也可能会发出警告(这是您的情况):http://www.delorie.com/gnu/docs/gdb/gdb_36.html

Some programming languages (notably C++) permit a single function name to be defined several times, for application in different contexts. This is called overloading. When a function name is overloaded, `break function' is not enough to tell GDB where you want a breakpoint.

对于此类方法,您可以通过键入其类型来选择一种方法:

break function(types)

更新:根据同一文档,gdb 应该要求用户选择一些重载方法:

GDB offers you a menu of numbered choices for different possible breakpoints, and waits for your selection with the prompt >'. The first two options are always [0] cancel' and `[1] all'. Typing 1 sets a breakpoint at each definition of function, and typing 0 aborts the break command without setting any new breakpoints.

For example, the following session excerpt shows an attempt to set a breakpoint at the overloaded symbol String::after. We choose three particular definitions of that function name:

(gdb) b String::after
[0] cancel
[1] all
[2] file:String.cc; line number:867
[3] file:String.cc; line number:860
[4] file:String.cc; line number:875
[5] file:String.cc; line number:853
[6] file:String.cc; line number:846
[7] file:String.cc; line number:735
> 2 4 6
Breakpoint 1 at 0xb26c: file String.cc, line 867.
Breakpoint 2 at 0xb344: file String.cc, line 875.
Breakpoint 3 at 0xafcc: file String.cc, line 846.
Multiple breakpoints were set.
Use the "delete" command to delete unwanted
 breakpoints.
(gdb)

更新 1:http://sourceware.org/gdb/onlinedocs/gdb/Ambiguous-Expressions.html#Ambiguous-Expressions说这个菜单可以打开和关闭(默认是关闭的):

set multiple-symbols mode

This option allows you to adjust the debugger behavior when an expression is ambiguous. By default, mode is set to all. If the command with which the expression is used allows more than one choice, then gdb automatically selects all possible choices.

When mode is set to ask, the debugger always uses the menu when an ambiguity is detected.

Finally, when mode is set to cancel, the debugger reports an error due to the ambiguity and the command is aborted.

关于c++ - GDB:警告:在重载方法上设置了多个断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7330364/

相关文章:

gdb - 执行期间的疯狂行为

swift - Xcode无缘无故创建断点

c++ - 将 CString 转换为 float 数组

c# - WPF 模板表单

c++ - 在 GDB 中的捕获点停止后退出

c - 存储 gdb 调用 expr 返回值

c++ - C++类网络编程的段错误

c++ - 将主类传递给其他类,以便它们可以访问其功能

google-chrome - Chrome 调试器/断点停在错误的行

vue.js - 在 VScode 和 Chrome 中调试 Vue,未绑定(bind)断点