Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gdb break on implicit class methods?

The compiler generates some class methods like copy constructors, destructors, etc. Is it possible to have gdb break on those methods to, e.g., observe where objects are being copied or destroyed?

like image 269
pythonic metaphor Avatar asked Apr 03 '14 19:04

pythonic metaphor


People also ask

How do I break in gdb?

To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

What is a break point in gdb?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.

How do I list breakpoints in gdb?

You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.


1 Answers

Can gdb break on implicit class methods?

Yes, of course, it can.

(gdb) break MyClass::MyClass(const MyClass &)     // break when copied
(gdb) break MyClass::~MyClass()                   // break when object destroyed

as simple as that. These are breakpoints based, NOT on file:line, but on function names. If you've a namespace wrapping the class then make sure you give the fully qualified name for it e.g.

(gdb) break NyNamespace::MyClass::MyClass(const MyClass &)

Look here for a list of ways to specify breakpoints in GDB.

like image 122
legends2k Avatar answered Oct 03 '22 05:10

legends2k