Reputation:
I use GDB to attach to a running process and catch a breakpoint. I execute the following commands sequence:
$ gdb -tui
(gdb) attach PID
And now I have the GUI TUI view open without any source file in.
I have been desperately trying to google a way to load / open a source file to be able to execute command "break ", but unfortunately I could not find anything that would simply work.
Upvotes: 3
Views: 17782
Reputation: 477
I found that in gdb, the list
knows about symbols, so
l main()
will open the main in whatever file it's defined (I'm assuming C in this example - you didn't specify a language).
TAB
also completes function names (as on linux command line),
Upvotes: 1
Reputation: 525
I FINALLY found out how to do this in cgdb:
Now you can set breakpoints in this file.
Upvotes: 3
Reputation: 1
Read the examine source file chapter of GDB documentation.
You could use the list
command.
Of course you need to set appropriately the directory list. Use the dir
command.
The GDB documentation starts with a tutorial chapter, so please read it.
Of course, all your software should be compiled with -g
(or even -g3
) to get its debug information from the compiler.
BTW your source file is already opened by (that is : visible to) gdb
. You could want to list
part of it, or to put a breakpoint (using break
or tbreak
) in it. No specific action from your part is needed to have it visible to gdb
(except perhaps the dir
command).
Upvotes: 0
Reputation: 525
I have the same problem; it's amazing that such a basic function is so obscure. My workaround is to use the file name and function name to set the breakpoint:
b <filename>:<function name>
Upvotes: 2