How to get process signal information in GDB?
Is there a way to get signal information (which signals are enabled, which are blocked, what are the handlers/options) for the process in gdb? There's info signals
, but that gives me gdb's signal handling info, and I need this info for process being debugged - e.g. to see if it blocks certain signal or to see which handler it installs 开发者_如何转开发for that signal.
If it's relevent, my gdb is GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
.
Assuming you are attached to a running process and are not inspecting a core dump, and assuming that gdb can access symbols, you should be able to call (via gdb) the POSIX signal handling functions to determine information such as what signals are blocked, and what are the register signal handlers.
For example, something like the following could be used to determine if a handler is registered for a SIGSEGV==11 signal using the sigaction function:
(gdb) call malloc(sizeof(struct sigaction))
$1 = (void *) 0x...
(gdb) call malloc(sizeof(struct sigaction))
$2 = (void *) 0x...
(gdb) call memset($2, 0, sizeof(struct sigaction))
...
(gdb) call sigaction(11, $2, $1)
$... = 0
(gdb) print *((struct sigaction *)$1)
<prints struct sigaction info>
This info should allow you to determine the address of the handler and then you can just pass that to the 'info symbol' command to determine what function is being used as the handler.
Similar operations can be performed to determine which signals are blocked.
Also, the special GDB variable $_siginfo may be of use to you. See here for more info: http://sourceware.org/gdb/onlinedocs/gdb/Signals.html
Although my guess would be that $_siginfo isn't available for Apple/darwin targets.
精彩评论