GDB
gdb
make sure debug flag is enabled when compiling the program.
e.g.,
gcc -ge.g.,
set(CMAKE_BUILD_TYPE RelWithDebInfo)orcmake -DCMAKE_BUILD_TYPE=Debug
gdb <program_name>gdb --args <program_name> arg1 arg2 arg3(gdb) break mainadd a breakpoint atmainfunction(gdb) rrun the program(gdb) listlist current function (in its original programming language)(gdb) tbreak 48add a temporary breakpoint at line 48 of current function(gdb) ccontinue running the program(gdb) btprint backtrace (of current stack)(gdb) print <var>print a variable(gdb) info localsprint all local variables (of current stack)(gdb) x /x 0x7fffffffd9b0exam the memory at this address using hex format(gdb) qquit
More useful commands
(gdb) sstep into next function(gdb) ngo to next instruction(gdb) bt fullprint full stack info including variables(gdb) info argsprint localargcandargvinformation(gdb) whatis vcheck variable type(gdb) disasdisassemble current function into assembly language(gdb) list <filename:function_name>list a function(gdb) list <filename:line_number>list a file around this line number(gdb) tbreak 0x000055555576bf00add a temporary breakpoint at the address (of an instruction)(gdb) x /2xw 0xffffprint two-word length of the memory at this address using hex formatbbyte,hhalf-word (2 bytes),wword (4 bytes),ggiant word (8 bytes)xhex,apointer,cchar,dinteger,uuint,sstring,tbinary,ffloat,ooctal
Fancy usage of extended gdb commands
need to download and
source stl-views-1.0.3.gdb; can be added to~/.gdbinit(gdb) pvector <name>print information about the STL vector classstd::vector<T>(gdb) pmap <name>print information about the STL map classstd::map<T,T>
references: gdb cheatsheet; gdb commands; gdb STL support; download stl-views-1.0.3.gdb;
Last updated
Was this helpful?