19

Can anyone tell me which command is used to display the source code when debugging through GDB. Would be of great help.

Sarwan
  • 595
  • 3
  • 8
  • 21
  • 1
    possible duplicate of [gdb split view with code](http://stackoverflow.com/questions/10115540/gdb-split-view-with-code) – Girardi Aug 25 '15 at 00:37

5 Answers5

26

You can enter or leave the TUI mode with code window using Ctrl+x A key binding. Or use layout src command to enter TUI mode. See other TUI key bindings and commands.

ks1322
  • 33,961
  • 14
  • 109
  • 164
6
  • Start gdb using gdb -tui. tui stands for Text User Interface.

  • Or, use 'ddd' -- a graphical front end for gdb.

Siddhartha Ghosh
  • 2,988
  • 5
  • 18
  • 25
4

The list command will show the code around the line where the program is currently stopped. If you type list again you'll see more.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • 1
    list command shows the below output. (gdb) list No symbol table is loaded. Use the "file" command. – Sarwan Oct 09 '13 at 09:15
  • 2
    You must compile the program with debug information in order to see the source code while debugging. If you use GCC to compile, use the `-g` switch, for example `gcc -g example.c -o example`. – Joni Oct 09 '13 at 09:53
2

This is what the commands in the source category of the manual are for. More specifically, the sub-category list mentions the command list.

Note that gdb is not typically using "windows", it's a console application.

unwind
  • 391,730
  • 64
  • 469
  • 606
2

By using layout next we can see the source code on different window. If the program didn't start running we will see empty screen for the beginning, when it starts the program will appear on different window.

Nagmat
  • 373
  • 4
  • 14