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?
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 ;-).
精彩评论