gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:26:31 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com