andras
andras

Reputation:

GDB breakpoint same function appears more times

Using gdb, I have encountered a strange issue: there is a method which appears three times:

(gdb) b Logger::Logger
[0] cancel
[1] all
[2] Logger at src/Logger.cpp:52
[3] Logger at src/Logger.cpp:52
[4] Logger at src/Logger.cpp:52

From the fact that all three instances are on line 552 of the file Logger.cpp, it can be deduced, that they are in fact referring to the same method. What is the meaning of this? Has Logger::Logger constructor accidentally got into the binary three times, or is this a gdb bug?

Upvotes: 1

Views: 2444

Answers (3)

RandomNickName42
RandomNickName42

Reputation: 5955

You can use "info break" and disable, enable for perhaps a breakpoint set to the same line.... however, you should also know, step vs. stepi (stepi will execute single machiene code instruction, not by source level, which is what step does).

You can also c #, to continue a specific amoutn of times, to pass that breakpoint... so if it's 1 breakpoint in a loop, which is being evaluated 3 times, you go c 3, and you will pass this perticular loop...

Upvotes: 0

Norman Ramsey
Norman Ramsey

Reputation: 202505

Either the method got inlined because gcc thought it would perform better, or it was used in a template which got instantiated in more than one way. Either path could lead to multiple versions in the executable binary.

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213596

Recent versions of GCC (and many other compilers) create several versions of constructors and destructors.

There was a bug in GDB, where it neglected to set a breakpoint on all versions, which resulted in your breakpoint never firing at all. Now, with the GDB bug corrected, you get multiple breakpoints.

Select all, then do info break, and note that the addresses of the 3 breakpoints all differ, and are in fact in different functions.

Upvotes: 5

Related Questions