GDB中如何获取进程信号信息?

发布于 2024-11-27 17:30:07 字数 230 浏览 0 评论 0原文

有没有办法获取 gdb 中进程的信号信息(哪些信号被启用,哪些信号被阻止,处理程序/选项是什么)?有信息信号,但这为我提供了 gdb 的信号处理信息,并且我需要此信息来调试进程 - 例如,查看它是否阻止某些信号或查看它为该信号安装哪个处理程序。

如果相关的话,我的 gdb 是 GNU gdb 6.3.50-20050815(Apple 版本 gdb-1515)(UTC 2011 年 1 月 15 日星期六 08:33:48)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-12-04 17:30:07

假设您附加到正在运行的进程并且没有检查核心转储,并且假设 gdb 可以访问符号,您应该能够调用(通过 gdb)POSIX 信号处理函数来确定信息,例如哪些信号被阻止,以及什么是寄存器信号处理程序。

例如,类似下面的内容可用于确定是否使用 sigaction 函数为 SIGSEGV==11 信号注册了处理程序:

(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>

此信息应允许您确定处理程序的地址,然后您可以将其传递给'info symbol' 命令来确定哪个函数被用作处理程序。

可以执行类似的操作来确定哪些信号被阻止。

另外,特殊的 GDB 变量 $_siginfo 可能对您有用。请参阅此处了解更多信息:
http://sourceware.org/gdb/onlinedocs/gdb/Signals.html

尽管我的猜测是 $_siginfo 不适用于 Apple/darwin 目标。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文