GDB: warning: Multiple breakpoints were set on overloaded methods

百般思念 提交于 2020-01-03 13:58:21

问题


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) 

回答1:


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.



来源:https://stackoverflow.com/questions/7330364/gdb-warning-multiple-breakpoints-were-set-on-overloaded-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!