Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: how to print the current line or find the current line number?

Tags:

gcc

debugging

gdb

list commands prints a set of lines, but I need one single line, where I am and where an error has probably occurred.

like image 331
Boris Burkov Avatar asked Jan 29 '13 11:01

Boris Burkov


People also ask

How do I jump a line number in gdb?

To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".

What is list command in gdb?

(gdb) help list List specified function or line. With no argument, lists ten more lines after or around previous listing. "list -" lists the ten lines before a previous ten-line listing. One argument specifies a line, and ten lines are listed around that line.

How do I know if I have BT in gdb?

To print a backtrace of the entire stack, use the backtrace command, or its alias bt . This command will print one line per frame for frames in the stack. By default, all stack frames are printed. You can stop the backtrace at any time by typing the system interrupt character, normally Ctrl-c .

What is display gdb?

Enables automatic displaying of certain expressions each time GDB stops at a breakpoint or after a step.


1 Answers

The 'frame' command will give you what you are looking for. (This can be abbreviated just 'f'). Here is an example:

(gdb) frame \#0  zmq::xsub_t::xrecv (this=0x617180, msg_=0x7ffff00008e0) at xsub.cpp:139 139         int rc = fq.recv (msg_); (gdb) 

Without an argument, 'frame' just tells you where you are at (with an argument it changes the frame). More information on the frame command can be found here.

like image 166
user3162307 Avatar answered Sep 22 '22 18:09

user3162307