How does one obtain the pid of the currently debugged process in gdb?

前端 未结 2 1298
轮回少年
轮回少年 2021-01-01 14:07

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 th

相关标签:
2条回答
  • 2021-01-01 14:40

    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
    
    0 讨论(0)
  • 2021-01-01 14:58

    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

    0 讨论(0)
提交回复
热议问题