在 ptrace 时如何在调试器中获取信号详细信息?

发布于 2024-09-27 01:10:27 字数 468 浏览 4 评论 0原文

我有一个调试器,正在从 linux 移植到 *bsd。目前,我正在开发 OpenBSD 版本。

在某些情况下,我想知道所传递信号的详细信息。例如,假设发送了 SIGSEGV,我想知道错误地址是什么,如果可能的话,是读取还是写入。

另一个例子是,如果我收到陷阱,它是单步事件吗?或者可能是 INT3 操作码。

在 Linux 上,我通过调用以下命令来获取此信息:

ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo);

这非常有效,因为它让我可以访问我可能想了解的有关信号的几乎所有内容。 OpenBSD 上似乎没有类似的东西。我查看了可使用 KVM API 访问的 kinfo_prockinfo_proc2,但我并没有真正注意到它们具有与 siginfo_t 相同类型的信息。获取此信息的正确方法是什么?

I have a debugger that I am porting over to *bsd from linux. Currently, I am working on the OpenBSD version.

Under certain conditions I would like to know the details of the signal that was delivered. For example, suppose a SIGSEGV was delivered, I'd like to know what the faulting address was, and if possible, if it was a read or write.

Another example is if I recieve a trap, was it a single step event? or maybe an INT3 opcode.

On linux I get get this information by calling:

ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo);

This works great since it lets me have access to just about everything I could possibly want to know about the signal. There does not appear to be an equivalent on OpenBSD. I took a look at kinfo_proc and kinfo_proc2 which are accessible using the KVM API, but nothing really jumps out at me as having the same type of information as a siginfo_t does. What would be the correct way to get at this information?

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

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

发布评论

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

评论(1

傲世九天 2024-10-04 01:10:27

我使用 KVM 至少找到了我的问题的部分答案:

char errbuf[_POSIX_LINE_MAX];
kvm_t *const kd = kvm_openfiles(NULL, NULL, NULL, O_READONLY, errbuf);
if(kd != NULL) {
    int rc;
    struct kinfo_proc2 *const proc = kvm_getproc2(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &rc);

    struct sigacts sigacts;
    kvm_read(kd, proc->p_sigacts, &sigacts, sizeof(sigacts));

    // sigacts.ps_code is same as siginfo.si_code
    // sigacts.ps_sigval.sival_ptr is same as siginfo.si_addr
}

几乎是我想要的所有信息,我认为如果我可以继续挖掘相关标题,我将能够找到所有这些信息。希望其他 BSD 架构也能有一些东西;-)。

I have found at least a partial answer to my question using KVM:

char errbuf[_POSIX_LINE_MAX];
kvm_t *const kd = kvm_openfiles(NULL, NULL, NULL, O_READONLY, errbuf);
if(kd != NULL) {
    int rc;
    struct kinfo_proc2 *const proc = kvm_getproc2(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &rc);

    struct sigacts sigacts;
    kvm_read(kd, proc->p_sigacts, &sigacts, sizeof(sigacts));

    // sigacts.ps_code is same as siginfo.si_code
    // sigacts.ps_sigval.sival_ptr is same as siginfo.si_addr
}

This is almost all of the information that I want, I think that if I can continue to dig through the relevant headers I'll be able to find all this information. Hopefully the other BSD arches will have something too ;-).

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