Posts Tagged debug
python print trace for lines in execution
python:
# be careful with the output, it will flush your screen 😉 python -m trace --trace yourscript.py
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
valgrind can check memory leak in your program
valgrind:
# valgrind needs debug symbols to give you more information about errors valgrind ./myprogram # show-reachable will show memory not freed, but you have maintained pointers to these memory valgrind --show-reachable=yes ./myprogram
valgrind has been my best friend for many years now. It provides you more than memory checking. I keep the example simple, check the man page to find discover new world.
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.