You can define a breakpoint in the constructor.
(gdb) break 'A::A()' Breakpoint 1 at 0x8048724: file x.cc, line 4. (gdb) run Starting program: /.../a.out Breakpoint 1, A::A (this=0x804a0ce <a>) at x.cc:4 4 std::cout << __func__ << std::endl; (gdb) bt
Note the use of single quotes to indicate that the C ++ identifier is malformed. Also note that the stack trace shows that main() has not yet been called.
From the stack trace, there are many options for setting a breakpoint that will exist before the global constructor is called. One such breakpoint is on _start .
(gdb) break _start Breakpoint 1 at 0x80485b0 (gdb) run Starting program: /.../a.out Breakpoint 1, 0x080485b0 in _start () (gdb) bt #0 0x080485b0 in _start () (gdb)
source share