24

How do I check the current line number that I'm stopped in when debugging with GDB? I would have thought this would be obvious (and maybe it is) but I don't see it on the GDB Cheat Sheet.

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
  • possible duplicate of [gdb: how to print the current line or find the current line number?](http://stackoverflow.com/questions/14581837/gdb-how-to-print-the-current-line-or-find-the-current-line-number) – Ciro Santilli OurBigBook.com Jun 10 '15 at 19:15

2 Answers2

38

Some digging around revealed the following methods:

  1. frame: This command was exactly what I was looking for. Output looked as follows:

    (gdb) frame
    #0  MyDialog::on_saveButton_clicked (this=0x72bf9e0) at src/ui/dialog/MyDialog.cxx:86
    86          _item->save();
    (gdb) 
    
  2. where or bt (same effect): This prints out the call stack, ending on the current line.

  3. list *$pc: This doesn't tell you the exact line but it prints out the surrounding lines with the current line in the center.
Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
  • 3
    I know you mention GDB but just as a suggestion have you tried using gdbtui? It has a nice terminal GUI that let's you see the current and surround lines. You can also scroll up down using the keyboard directional keys. – Nobilis May 21 '13 at 03:12
  • @Nobilis Thanks for the tip! gdbtui looks pretty sweet! – Freedom_Ben May 21 '13 at 04:12
0

x/i $eip
eip(rip) points to the next instruction

sueaki
  • 45
  • 2