GDBをアタッチせずにすべてのスレッドのスタックトレースを出力する方法はありますか?
または、すべてのスレッドのスタックトレースを出力するためにgdbバッチモードとして使用できるコマンドはありますか?
There is a thread apply all command in GDB:
(gdb) thread apply all bt
Thread 12 (Thread 0x7f7fe2116700 (LWP 5466)):
#0 sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
#1 0x0000000000425358 in ?? ()
...
Thread 1 (Thread 0x7f7feabc27c0 (LWP 5465)):
#0 0x00007f7fe76c5203 in select () at ../sysdeps/unix/syscall-template.S:82
Sadly, GDB seems not to be able to read the commands from a pipe, so to run the commands in its batch mode, a temporary file must be used:
$ gdbbt() {
tmp=$(tempfile)
echo thread apply all bt >"$tmp"
gdb -batch -nx -q -x "$tmp" -p "$1"
rm -f "$tmp"
}
$ gdbbt $(pidof $SHELL)
Then you'll only "temporarily" attach with gdb and then detach.
pstack?
使用法:
pstack <pid>
マニュアルページから:
pstack - print a stack trace of a running process
...
If the process is part of a thread group, then pstack will print out a stack trace for each of the threads in the group.
私はこれを使用しています:
pidof program | xargs -n1 sudo gdb --batch -ex "thread apply all bt" -p
Linux と同様に、すべてのスレッドは基本的に軽量プロセスであり、個々の LWP PID を取得します。psまたはtopベースのスクリプト を使用するかecho、win を実行することで、これらのステータスをダンプできます/proc/sysrq-trigger。これI/Oにより、 内のスレッドの状態が得られます/var/log/messages。
ただし、これでは完全なスタック トレースは得られません。しかし、定期的にスレッドの状態をデバッグするには良い方法です。
/proc/sched_debugどのタスクがスケジュールされているかなどを調べて、現在のスケジューラの状態を調べることもできます。