gdb cheatsheet

  • # unlimit the size of core dump
    • ulimit -c unlimited
  • # Set the filename pattern of core dump
    • echo "core.%e.%p" | sudo tee /proc/sys/kernel/core_pattern
      • %e = executable filename
      • %p = pid
    • echo "kernel.core_pattern = core.%e.%p" >> /etc/sysctl.conf 
  • # compile code with debug info
    • gcc -g -Wall -o example example.c
  • # start debugger
    • gdb example core.example.pid
  • (gdb)
bt backtrace
disas [func] disassembly
disas/s disassembly with source code
b func breakpoint at function
b *func + xxx breakpoint 
i proc m memory mappings (info proc mappings)
i r check registers (info registers)
si step inside (stepi)
list func  
print  
delete xxx  
frame xxx  
quit  
set var name=value  
info break  
info watch  
watch  
rwatch  
c continue
next  
start  
  • Reference: http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer