Can I use GDB to debug a running process?

前端 未结 8 1987
Happy的楠姐
Happy的楠姐 2020-12-02 05:52

Under linux, can I use GDB to debug a process that is currently running?

相关标签:
8条回答
  • 2020-12-02 06:48

    Easiest way is to provide the process id.

    gdb -p `pidof your_running_program_name`
    

    Please get the full list of option in man gdb command.

    In case there are multiple process for the same program running, then the following command will list the processes.

    ps -C program -o pid h
    <number>
    

    Then the output process id (number) can be used as argument to gdb.

    gdb -p <process id>
    
    0 讨论(0)
  • 2020-12-02 06:49

    Yes you can. Assume a process foo is running...

    ps -elf | grep foo
    
    look for the PID number
    
    gdb -a {PID number}
    
    0 讨论(0)
提交回复
热议问题