GDB能否杀死一个特定的线程? [英] Can GDB kill a specific thread?

查看:353
本文介绍了GDB能否杀死一个特定的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我知道这个操作可能会导致应用程序崩溃。



<在这个调试会话中, ps -ax 显示firefox pid是1328 :

  $ gdb /Applications/Firefox.app/Contents/MacOS/firefox 1328 
GNU gdb 6.3.50- 20050815(Apple版本gdb-1708)(Thu Nov 3 21:59:02 UTC 2011)
版权所有2004 Free Software Foundation,Inc.
GDB是GNU通用公共许可证涵盖的免费软件,您有
欢迎在特定条件下更改和/或分发它的副本。
输入show copying查看条件。
GDB绝对没有担保。输入显示保修以获取详细信息。
这个GDB配置为x86_64-apple-darwin...阅读共享库的符号.......完成

/ Users / karlphillip / 1328:没有这样的文件或目录
附加到程序:`/Applications/Firefox.app/Contents/MacOS/firefox',进程1328.
阅读共享库的符号+ done
阅读共享库的符号++ ++++ .............................................. .................................................. .................................................. .................................................. .....
0x00007fff90b9a67a在$ __psynch_cvwait()
24 0x00007fff90b9bbca在__psynch_cvwait()
23 0x00007fff90b9bbca($)
(gdb)信息线程
25 0x00007fff90b9bbca在__psynch_cvwait()
中22 0x00007fff90b9a67a mach_msg_trap()
21 0x00007fff90b9bbca在__psynch_cvwait()
20 0x00007fff90b9bbca在__psynch_cvwait()
19分配0x00007fff90b9bbca在__psynch_cvwait()
在__psynch_cvwait 18 0x00007fff90b9bbca()
17分配0x00007fff90b9bbca在__psynch_cvwait()
16分配0x00007fff90b9bbca在__psynch_cvwait()
15分配0x00007fff90b9bbca在__psynch_cvwait()
14分配0x00007fff90b9bbca在__psynch_cvwait()
13分配0x00007fff90b9bbca在__psynch_cvwait()
12分配0x00007fff90b9bbca在__psynch_cvwait()
11分配__psynch_cvwait()中的0x00007fff90b9bbca()
10 __psynch_cvwait()中的0x00007fff90b9bbca
9 0x00007fff90b9bbca在__psynch_cvwait()
8分配0x00007fff90b9bbca在__psynch_cvwait()
7分配0x00007fff90b9bdf2在选择$ DARWIN_EXTSN()
6分配0x00007fff90b9bbca在__psynch_cvwait()
5分配0x00007fff90b9bbca在__psynch_cvwait()$ B $ ()
3 0x00007fff90b9a67a in mach_msg_trap()
2com.apple.libdispatch-manager0x00007fff90b9c7e6 in kevent()
* 1com.apple.main-thread mach_msg_trap()中的0x00007fff90b9a67a
(gdb)调用raise(6,NOHUP)
没有加载符号表。使用文件命令。
(gdb)


解决方案

一个特定的线程与GDB 调用raise(kernel-thread-id,signo)调用pthread_kill(pthread-thread-id,signo) / code>。



编辑:



否符号表被加载。使用file命令。

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

  gdb 
...
(gdb)附加< pid>

在某些平台上,GDB可以计算出某个进程中运行的可执行文件(例如<$ c在Linux上为$ c> / proc /< pid> / exe )。我猜MacOS不是这些平台之一,所以你必须告诉GDB。改为:

  gdb / path / to / exe< pid> 


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) or call pthread_kill(pthread-thread-id, signo).

EDIT:

No symbol table is loaded. Use the "file" command.

My guess is that you did something like this:

gdb
...
(gdb) attach <pid>

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:

gdb /path/to/exe <pid>

这篇关于GDB能否杀死一个特定的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆