GDB:warning:在重载方法上设置了多个断点 [英] GDB: warning: Multiple breakpoints were set on overloaded methods

查看:687
本文介绍了GDB:warning:在重载方法上设置了多个断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  anisha @ linux-dopx:〜> g ++ -Wall -pedantic breakpoints.cpp -g 
anisha @ linux-dopx:〜> gdb a.out
(gdb)b X :: X
断点1在0x400ac1:文件breakpoints.cpp,第14行。
断点2在0x400aa0:文件breakpoints.cpp,第9行。
warning:设置了多个断点。
使用delete命令删除不需要的断点。
(gdb)

如何设置断点
默认构造函数,这样
GDB不会在它的重载对象上创建不必要的断点



或者是GDB的问题期望
的用户删除它的混乱?
或者我缺少一点?



编辑1。 >对于以下代码:

  class X 
{
public:
X
{
std :: cout<< \ n在默认构造函数;
}

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

〜X(){}
};

我试过:

 (gdb)b X :: X(11)
类X没有任何名为X的方法(11)
提示:try'X :: X(11)< ; TAB>或'X :: X(11)< ESC-?>
(注意前导单引号。)
在未来共享库加载时使断点挂起? (y或[n])

没有帮助!



编辑2。



感谢osgx ,以下作品:

 (gdb)b X :: X(int)
断点5在0x400ac1:文件断点。 $ b(gdb)b X :: X()
断点6在0x400aa0:文件breakpoints.cpp,第9行。
(gdb)


解决方案

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



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


一些编程语言(特别是C ++)允许单个函数名称为定义了几次,适用于不同的上下文。这称为重载。当函数名重载时,`break function'不足以告诉GDB你想要一个断点。


可以通过键入其类型来选择一种方法:


break函数(types)


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


GDB为您提供了一个包含不同可能断点的编号选项的菜单,并使用提示>'等待您的选择。前两个选项总是 [0] cancel'和`[1] all'。键入1在函数的每个定义处设置断点,输入0将中断断点命令,而不设置任何新的断点。



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




 (gdb)b String :: after 
[0] cancel
[1] all
[2] file:String.cc;行号:867
[3] file:String.cc;行号:860
[4] file:String.cc;行号:875
[5] file:String.cc;行号:853
[6] file:String.cc;行号:846
[7] file:String.cc;行号:735
> 2 4 6
断点1在0xb26c:文件String.cc,行867.
断点2在0xb344:文件String.cc,行875.
断点3在0xafcc:文件String.cc ,第846行。
设置了多个断点。
使用delete命令删除不需要的
断点。
(gdb)

UPDATE1:http://sourceware.org/gdb/onlinedocs/gdb/Ambiguous-Expressions.html#Ambiguous-Expressions 表示此菜单可以(默认为关闭):


设置多符号模式



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



当模式设置为时,调试程序总是在检测到模糊时使用菜单。



最后,当模式设置为 cancel 时,调试器报告由于模糊性导致的错误,并且命令中止。



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) 

解决方案

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.

这篇关于GDB:warning:在重载方法上设置了多个断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆