#include #include #include #include #include #include #include /*#define UNW_LOCAL_ONLY*/ #include #define USE_TIMER #define panic(args...) \ do { fprintf (stderr, args); exit (EXIT_FAILURE); } while (0) static int loop = 1; #ifdef USE_TIMER static void sig_handler (int sig, siginfo_t *si, void *uc1) #else static void sig_handler (int sig) #endif { unw_cursor_t cursor; unw_context_t uc; int ret; loop = 0; unw_getcontext (&uc); if (unw_init_local (&cursor, &uc) < 0) panic ("unw_init_local() failed\n"); do { unw_word_t ip, sp, offp; char buf[512]; unw_get_reg (&cursor, UNW_REG_IP, &ip); unw_get_reg (&cursor, UNW_REG_SP, &sp); unw_get_proc_name (&cursor, buf, sizeof (buf), &offp); if (unw_is_signal_frame (&cursor)) printf ("signal frame\tip: %10p, sp: %10p %s\n", (void*) ip, (void*) sp, buf); else printf ("standard frame\tip: %10p, sp: %10p %s\n", (void*) ip, (void*) sp, buf); } while ((ret = unw_step (&cursor)) > 0); if (ret < 0) panic ("unw_step() failed\n"); } #ifdef USE_TIMER static void setup_timer (void) { struct sigaction act; struct sigevent sev; timer_t timerid; struct itimerspec its; memset (&its, 0, sizeof (its)); /* establish a handler for the timer signal */ act.sa_flags = SA_SIGINFO; act.sa_sigaction = sig_handler; if (sigaction (SIGRTMIN, &act, NULL) == -1) panic ("sigaction failed\n"); /* create the timer */ sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIGRTMIN; sev.sigev_value.sival_ptr = &timerid; if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) panic ("timer_create\n"); /* start the timer */ its.it_value.tv_sec = 1; /* 1 second */ if (timer_settime(timerid, 0, &its, NULL) == -1) panic ("timer_settime\n"); } #endif int main () { #ifdef USE_TIMER setup_timer (); while (loop); #else signal (SIGUSR1, sig_handler); kill (getpid (), SIGUSR1); #endif return 0; }