GDB可以杀死一个特定的线程吗?

时间:2012-01-08 20:08:30

标签: multithreading gdb kill

我正在运行一个应用程序(firefox),我想知道是否可以使用GDB附加到进程并杀死特定的线程。有没有办法做到这一点?

我知道此操作可能会使应用程序崩溃。

修改

在此调试会话中,ps -ax显示firefox pid为1328:

$ gdb /Applications/Firefox.app/Contents/MacOS/firefox 1328
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ....... done

/Users/karlphillip/1328: No such file or directory
Attaching to program: `/Applications/Firefox.app/Contents/MacOS/firefox', process 1328.
Reading symbols for shared libraries + done
Reading symbols for shared libraries ++++++......................................................................................................................................................................................................... done
0x00007fff90b9a67a in mach_msg_trap ()
(gdb) info threads
  25                                 0x00007fff90b9bbca in __psynch_cvwait ()
  24                                 0x00007fff90b9bbca in __psynch_cvwait ()
  23                                 0x00007fff90b9bbca in __psynch_cvwait ()
  22                                 0x00007fff90b9a67a in mach_msg_trap ()
  21                                 0x00007fff90b9bbca in __psynch_cvwait ()
  20                                 0x00007fff90b9bbca in __psynch_cvwait ()
  19                                 0x00007fff90b9bbca in __psynch_cvwait ()
  18                                 0x00007fff90b9bbca in __psynch_cvwait ()
  17                                 0x00007fff90b9bbca in __psynch_cvwait ()
  16                                 0x00007fff90b9bbca in __psynch_cvwait ()
  15                                 0x00007fff90b9bbca in __psynch_cvwait ()
  14                                 0x00007fff90b9bbca in __psynch_cvwait ()
  13                                 0x00007fff90b9bbca in __psynch_cvwait ()
  12                                 0x00007fff90b9bbca in __psynch_cvwait ()
  11                                 0x00007fff90b9bbca in __psynch_cvwait ()
  10                                 0x00007fff90b9bbca in __psynch_cvwait ()
   9                                 0x00007fff90b9bbca in __psynch_cvwait ()
   8                                 0x00007fff90b9bbca in __psynch_cvwait ()
   7                                 0x00007fff90b9bdf2 in select$DARWIN_EXTSN ()
   6                                 0x00007fff90b9bbca in __psynch_cvwait ()
   5                                 0x00007fff90b9bbca in __psynch_cvwait ()
   4                                 0x00007fff90b9c7e6 in kevent ()
   3                                 0x00007fff90b9a67a in mach_msg_trap ()
   2 "com.apple.libdispatch-manager" 0x00007fff90b9c7e6 in kevent ()
*  1 "com.apple.main-thread"         0x00007fff90b9a67a in mach_msg_trap ()
(gdb) call raise(6, NOHUP)
No symbol table is loaded.  Use the "file" command.
(gdb)

1 个答案:

答案 0 :(得分:2)

您当然可以使用GDB call raise(kernel-thread-id, signo)call pthread_kill(pthread-thread-id, signo)向特定线程发送信号。

编辑:

  

未加载符号表。使用“file”命令。

我的猜测是你做了这样的事情:

gdb
...
(gdb) attach <pid>

在某些平台上,GDB可以找出在给定进程中运行的可执行文件(例如,来自Linux上的/proc/<pid>/exe)。我猜测MacOS不是这些平台之一,所以你必须告诉GDB。这样做:

gdb /path/to/exe <pid>