Getting a backtrace of other thread

前端 未结 3 477
忘掉有多难
忘掉有多难 2020-11-29 07:34

In Linux, to get a backtrace you can use backtrace() library call, but it only returns backtrace of current thread. Is there any way to get a backtrace of some other thread,

3条回答
  •  北海茫月
    2020-11-29 07:59

    gdb provides these facilities for debugging multi-thread programs:

    • automatic notification of new threads
    • ‘thread thread-id’, a command to switch among threads
    • ‘info threads’, a command to inquire about existing threads
    • ‘thread apply [thread-id-list] [all] args’, a command to apply a command to a list of threads
    • thread-specific breakpoints
    • ‘set print thread-events’, which controls printing of messages on thread start and exit.
    • ‘set libthread-db-search-path path’, which lets the user specify which libthread_db to use if the default choice isn't compatible with the program.

    So just goto required thread in GDB by cmd: 'thread thread-id'. Then do 'bt' in that thread context to print the thread backtrace.

提交回复
热议问题