How to dump more info when received a SIGSEGV signal?



Hi,

I try to dump more system information when process receives a SIGSEGV
signal by using sigaction() system call, the code is showed below.
However the result is not expected, e.g. the eip is not the the fault
instruction when I use objdump to see the binary.

P.S.
The processor is IA32 and Linux kernel is 2.6

------------------------------------------------------------------------------------------

void segv_handler(int sig, struct sigcontext ctx)
{
printf("eip = %x\n", ctx.eip);
printf("trapno = %x\n", ctx.trapno);
exit(0);
}

main()
{
struct sigaction m;
char *p = (char *)0x0,*q, arr[]="Ma";
q=arr;

m.sa_flags = SA_SIGINFO;
m.sa_handler = (void (*)(int))segv_handler;
sigaction(SIGSEGV, &m, (struct sigaction *)NULL);
*p++ = *q++;
return 0;
}

.