6

Each time I step with n it prints out the next statement to be executed.

How do I see the next statement to be executed, as if I had typed n, but without actually stepping the code?

Currently I am 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 to get what I want?

3 Answers3

2

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

   (gdb) frame
   #0 main () at dummy.c:11
   11    FILE*f = fopen("somefile","r");
   (gdb)
olegst
  • 1,209
  • 1
  • 13
  • 33
1

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

define shownext
where
list
end

Well, I am not sure if what I stated works out, but see here on how to do things like this.

bash.d
  • 13,029
  • 3
  • 29
  • 42
  • For some reason running `list` twice in a row moves the code focus/window. –  Mar 08 '13 at 11:46
  • @infact - this is the defined behaviour. The documentation states "If the last lines printed were printed with a list command, this prints lines following the last lines printed;" – borrible Mar 08 '13 at 11:51
0

If your gdb was built with Python support, this list.current.py script would add a new list-current gdb command that does what you want.

Sample session:

$ 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) 
scottt
  • 7,008
  • 27
  • 37