Getting stacktrace of all threads without attaching GDB

后端 未结 6 854
甜味超标
甜味超标 2021-02-13 16:24

Is there a way to print stacktrace of all threads without attaching GDB?

Or is there a command which I can use as gdb batch mode to print stacktrace of all threads?

6条回答
  •  感动是毒
    2021-02-13 16:41

    The following script works for me on linux Please note that it first finds out the directory of the executable and changes to that directory (because executable can have shared libraries with relative path by using -Wl,-rpath,$dir specified during linking, and you would like gdb to find the symbols for these shared libraries for the stack trace). It also assumes that gdb is present on the system.

    #!/bin/bash
    
    pid=$1
    
    EXE=`readlink -f /proc/$pid/exe`
    
    DIR=`dirname $EXE`
    
    cd $DIR
    
    gdb $EXE --batch -ex "attach $pid" -ex "thread apply all bt"
    

提交回复
热议问题