ps -ef | grep PATTERN | tr -s ' ' | cut -d ' ' -f 2 | \
xargs -I{} gdb -p {} --batch -ex=bt > backtraces
r # run
where
Use -g
.
https://www.geeksforgeeks.org/gdb-command-in-linux-with-examples/
# at line number
b <file_name>:<line_number
b foo.c:123
# at function
b MyFunction
http://web.eecs.umich.edu/~sugih/pointers/gdbQS.html
Must define function.
(gdb) define fn
> finish
> next # step over line (does not enter function calls)
> end
https://unix.stackexchange.com/questions/297982/how-to-step-into-step-over-and-step-out-with-gdb https://stackoverflow.com/questions/1262639/multiple-commands-in-gdb-separated-by-some-sort-of-delimiter
imul edx fmul edx
Implicitly multiplies with eax.
https://stackoverflow.com/questions/3818755/imul-assembly-instruction-one-operand
x/g $rsp # examine 8-byte word starting at address $rsp
x/wx 0xf7bd3040 # examine 4-byte word at address
p/x *0xf7bd3040
x/gx $rsp+0x28 # examine 8-byte word at $rsp+0x28, print as hex
x/48b $rsp # print 48 bytes from $rsp onward
https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html
p/x array[index]
# array is array variable
# length is length of array
p *array@length
p/x *roots@6
https://sourceware.org/gdb/current/onlinedocs/gdb/Arrays.html
print (char*) $esi
x/10i $pc
https://stackoverflow.com/questions/1902901/show-current-assembly-instruction-in-gdb
x/10i my_function
https://stackoverflow.com/questions/10874298/gdb-disassemble-one-line
s # will step into function if line is function call
http://web.eecs.umich.edu/~sugih/pointers/gdbQS.html
fin
https://stackoverflow.com/questions/24712690/step-out-of-current-function-with-gdb
# help FOO
help n
i b
print *(int *) ($rsp)
print (char*) $rbp
print {var1, var2, ...}
https://stackoverflow.com/questions/1882857/print-multiple-variables-with-one-command-in-gdb
print /x {$rbx, $rbp}
https://stackoverflow.com/questions/1882857/print-multiple-variables-with-one-command-in-gdb
IF = interrupt flag
https://en.wikipedia.org/wiki/FLAGS_register
i r
b *0x0000000000401417 // set breakpoint at address 0x401417
b FOO // set breakpoint at function FOO
disas = disassemble current function disas FOO = diassemble function FOO