Inside gdb, what command will provide the pid of the process getting debugged?
Most of the google results discuss only how to attach gdb to a process once we know the pid.
One simple way is info inferior
. Here I'm debugging gdb with itself and this command shows the PID of the debuggee:
(top-gdb) info inferior
Num Description Executable
* 1 process 14068 /home/tromey/gdb/build/gdb/gdb
You can also just call the ordinary C function:
(top-gdb) print getpid()
$3 = 14068
Another method:
(gdb) python print(gdb.selected_inferior().pid)
32737
See more info about the gdb Python inferior API: https://sourceware.org/gdb/onlinedocs/gdb/Inferiors-In-Python.html#Inferiors-In-Python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With