I'm running an application (firefox) and I would like to know if it's possible to use GDB to attach to the process and kill a specific thread. Is there a way to do this?
I understand that this operation will probably crash the app.
EDIT:
In this debugging session, ps -ax
revealed that firefox pid is 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)
You can certainly send a specific thread a signal with GDB
call raise(kernel-thread-id, signo)
orcall pthread_kill(pthread-thread-id, signo)
.EDIT:
My guess is that you did something like this:
On some platforms GDB can figure out which executable is running in a given process (e.g. from
/proc/<pid>/exe
on Linux). I am guessing that MacOS is not one of these platforms, and so you must tell GDB. Do this instead: