Print current expression in GDB

Each time I am with n , it prints the next statement to be executed.

How to see the next statement that will execute as if I typed n , but without actually entering the code?

I am currently using where , and this gives me the line number of the next statement, and I can use list to see some source code. Does it require two separate commands?

+6
source share
3 answers

Define yourself macro in your .gdbinit in your home directory.

 define shownext where list end 

Well, I'm not sure what I said works, but see here how to do it.

+1
source

Try the "frame" command. You will see something like this:

  (gdb) frame #0 main () at dummy.c:11 11 FILE*f = fopen("somefile","r"); (gdb) 
+1
source

If your gdb was built with Python support, this list.current.py script will add a new list, the current gdb, which does what you want.

Session Example:

 $ gdb -x list-current.py /bin/true (gdb) start Temporary breakpoint 1 at 0x4014c0: file true.c, line 59. Starting program: /usr/bin/true Temporary breakpoint 1, main (argc=1, argv=0x7fffffffde88) at true.c:59 59 if (argc == 2) (gdb) list-current 59 if (argc == 2) (gdb) list-current 3 59 if (argc == 2) 60 { 61 initialize_main (&argc, &argv); (gdb) list-current -2 58 argument. */ 59 if (argc == 2) (gdb) 
0
source

All Articles