Posts Tagged gdb
gdb display local variables
gdb:
info locals
gdb starts program with commandline arguments
gdb:
# instead of having to specify command line arguments as # "run arg1 arg2" or "r arg1 arg2", specify them in command line # and use "r" to run program in gdb gdb --args ./program arg1 arg2
gdb support in vim
# debug current buffer with pdb
:Pyclewn pdb %:p
having separate debug file for your executable when coredump
bash:
# we want to release a executable without debug symbols, when it coredump, we still # want to be able to have informations such as function names, line numbers. # make sure you compile your program as release, but with -g to keep debug symbols # keep a debug copy of the executable objcopy --only-keep-debug program program.debug # strip symbols so you can give it to customer strip -g program # when you load coredump in gdb with program, it will automatically load # program.debug in the same directory where program is
debug a running program by attaching gdb to the process
gdb:
# find out the process id of your running program pgrep myprogram # attach gdb to the process gdb --pid process-id
load core dump with gdb
gdb:
# change ulimit to allow core dump to be saved to disk ulimit -c unlimited # run program ./program segfault (coredumped) # load with gdb gdb ./program core # now you are at the line where the program segfaulted, if the program has debug information, you can trace back to the line number
coredump is the term where a program seg-faulted, the os dumps program memory space to disk.
display source in gdb
gdb:
# display source code window in gdb Ctrl+x a # display source code in gdb default mode list
gdb is the most popular debugger on Linux. I use it all the time and really can’t live without it.