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

发布于 2024-12-03 05:16:53 字数 1297 浏览 0 评论 0原文

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) 
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)

What is the way to set the breakpoint
on the default constructor, such that
GDB doesn't create unnecessary breakpoints
on the its overloaded counterparts?

Or is it a problem with GDB that it expects
the users to delete its mess?
Or am I missing a point?

EDIT 1.

For the following code:

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

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

        ~X () {}
};

I tried:

(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]) 

Didn't help!

EDIT 2.

Thanks to osgx, the following works:

(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) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我一向站在原地 2024-12-10 05:16:53

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

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

某些编程语言(尤其是 C++)允许多次定义单个函数名称,以便在不同的上下文中应用。这称为超载。当函数名重载时,“break function”不足以告诉 GDB 您想要在哪里设置断点。

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

中断函数(类型)

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

GDB 为您提供了一个针对不同可能断点的编号选项菜单,并通过提示符 >' 等待您的选择。前两个选项始终是“[0]取消”和“[1]全部”。键入 1 会在每个函数定义处设置一个断点,键入 0 会中止中断命令,而不设置任何新断点。

例如,以下会话摘录显示了在重载符号 String::after 处设置断点的尝试。我们选择该函数名称的三个特定定义:

(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)

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

设置多个符号模式

此选项允许您在表达式不明确时调整调试器行为。
默认情况下,模式设置为全部。如果使用表达式的命令允许多个选择,则 gdb 会自动选择所有可能的选择。

当模式设置为询问时,调试器在检测到歧义时始终使用菜单。

最后,当模式设置为取消时,调试器会由于不明确而报告错误,并且命令会中止。

I think, this case is normal. Some ABI will generate two constructors for an Class. When you ask b X::X gdb will detect both constructors and set two breakpoints. (Sorry, this is not your case)

The "Multiple breakpoints were set." warning may be also given for overloaded methods (this is your case): 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.

For such methods you can select one method by typing its types:

break function(types)

Update: According to the same document, gdb should ask user to select some of overloaded methods:

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)

UPDATE1: http://sourceware.org/gdb/onlinedocs/gdb/Ambiguous-Expressions.html#Ambiguous-Expressions says that this menu can be switched on and off (default is off):

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文