Originally posted by: SystemAdmin
Hi,
I want to dump a stack trace in my program.In linux we will backtrace function for this.Here is the small program to do this. Can anybody tell me how we can do the same in aix.Equivalent code will be very helpful.
#include <signal.h>
#include <execinfo.h> //this is not there in AIX
/* get REG_EIP from ucontext.h */
#define __USE_GNU
#include <ucontext.h>
void bt_sighandler(int sig, siginfo_t *info, void *sigcontext) {
void *trace
16;
char **messages = (char **)NULL;
int i, trace_size = 0;
ucontext_t *uc = (ucontext_t *)sigcontext;
/* Do something useful with siginfo_t */
if (sig == SIGSEGV)
printf("Got signal %d, faulty address is %p, ", sig, info->si_addr);
else
printf("Got signal %d\n", sig);
trace_size = backtrace(trace, 16); //what is equivalent function in AIX5.0
/* overwrite sigaction with caller's address */
trace[1] = (void *) uc->uc_mcontext.gregs
REG_EIP; // ? in AIX5.0
messages = backtrace_symbols(trace, trace_size); // ? in AIX5.0
/* skip first stack frame (points here) */
printf("path.....\n");
for (i=1; i<trace_size; ++i)
printf("
bt %s\n", messages
);
exit(0);
}
struct sigaction sa;
sa.sa_sigaction = (void *)bt_sighandler;
sigemptyset (&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
Can we use mt_trce() here?
Sharath.