This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How to get a context ?


I hope this is the rigth place for this question, I thinks that gdb dev team
can give me some hints.

I'm trying to get information on a process when a signal is raised like a
sigsegv in order to print a backtrace.
I first try to get the address of the instruction that cause the segfault
with the siginfo_t structure, but this one is most of the time empty and not
filled by the kernel (it depends of the signal and how the crash happen).


Here the code I use :

#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>

void handler(int cause, siginfo_t *HowCome, void *uap)  {
        printf("SIGSEGV raised at adress %p\n", HowCome->si_addr);
        exit(0);
}


int main(void) {
        struct sigaction sa;
        
        sa.sa_sigaction = handler;
        sigemptyset( &sa.sa_mask);
        sa.sa_flags = SA_SIGINFO;
        if (sigaction( SIGSEGV, &sa, 0)) {
                perror("Sigaction SUGSEGV");
                exit(0);
        }
	
	  *((int*)0) = 0;
        return 0;
}

}




I'd tryed to look on te gdb source but I cant figured out how it is done.

If you can give me some pist I can explore I would be very pleased.


Thanks In advance.

julien


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]