Home > Net >  What does this mean in gdb after executing the last line of a function?
What does this mean in gdb after executing the last line of a function?

Time:03-12

Line 31 is the last line in this C function. After stepping over it, this strange number 0x00007ffe1fc6b36b is printed, and it starts walking back up the function, going back to line 30. I imagine it is calling destructors now. I'm just curious what the strange number means.

31              _sock->bind(addr);
(gdb) n
0x00007ffe1fc6b36b      30              _sock = unique_ptr<zmq::socket_t>(new zmq::socket_t(_ctx,zmq::socket_type::req));

CodePudding user response:

If the actual $pc value does not match the start of a line (according to the line table within the debug information), then GDB will print the $pc before printing the line number, and source line.

That's what's going on here. For line 31 GDB stopped at the exact address for the start of line 31, and so no address was printed.

For the line 30 output, which, like you said, is almost certainly the destructor call, the address we are now at 0x00007ffe1fc6b36b is associated with line 30, but is not the start of that line, and so, GDB prints the address.

The important thing to understand here, is that when GDB prints something like:

31              _sock->bind(addr);

No part of that line has yet been executed, while when GDB prints:

0x00007ffe1fc6b36b      30              _sock = unique_ptr<zmq::socket_t>(new zmq::socket_t(_ctx,zmq::socket_type::req));

then that line is part way through being executed, so your program will be in some weird half way state; in this case the object has been constructed, but not yet destructed.

  • Related