1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2025-02-17 02:31:41 +01:00

(do_backtrace): Also pring "gp".

(foo): Add some newlines for better readability.
(sighandler): Always declare as per Single UNIX Spec.
	On HP-UX, use __uc_get_ip() to read the interruption IP.
(main): Always use sigaction() to install a signal handler, so we can
	turn on the SA_SIGINFO flag.

(Logical change 1.87)
This commit is contained in:
mostang.com!davidm 2003-04-24 20:45:07 +00:00
parent a88af79c95
commit 8b7c7e322a

View file

@ -84,9 +84,9 @@ do_backtrace (void)
printf ("%016lx %-32s (sp=%016lx)\n", (long) ip, buf, (long) sp); printf ("%016lx %-32s (sp=%016lx)\n", (long) ip, buf, (long) sp);
unw_get_proc_info (&cursor, &pi); unw_get_proc_info (&cursor, &pi);
printf ("\tproc=%016lx-%016lx\n\thandler=%lx lsda=%lx", printf ("\tproc=%lx-%lx\n\thandler=%lx lsda=%lx gp=%lx",
(long) pi.start_ip, (long) pi.end_ip, (long) pi.start_ip, (long) pi.end_ip,
(long) pi.handler, (long) pi.lsda); (long) pi.handler, (long) pi.lsda, (long) pi.gp);
#if UNW_TARGET_IA64 #if UNW_TARGET_IA64
{ {
@ -118,25 +118,31 @@ foo (void)
printf ("\texplicit backtrace:\n"); printf ("\texplicit backtrace:\n");
do_backtrace (); do_backtrace ();
printf ("\tvia backtrace():\n"); printf ("\n\tvia backtrace():\n");
n = backtrace (buffer, 20); n = backtrace (buffer, 20);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
printf ("[%d] ip=%p\n", i, buffer[i]); printf ("[%d] ip=%p\n", i, buffer[i]);
} }
void void
#ifdef UNW_TARGET_X86 sighandler (int signal, void *siginfo, void *context)
sighandler (int signal, struct sigcontext sc)
#else
sighandler (int signal, void *siginfo, struct sigcontext *sc)
#endif
{ {
ucontext_t *uc = context;
int sp; int sp;
printf ("sighandler: got signal %d, sp=%p", signal, &sp); printf ("sighandler: got signal %d, sp=%p", signal, &sp);
#if UNW_TARGET_IA64 #if UNW_TARGET_IA64
# if defined(__linux__) # if defined(__linux__)
printf (" @ %lx", sc->sc_ip); printf (" @ %lx", uc->uc_mcontext.sc_ip);
# else
{
uint16_t reason;
uint64_t ip;
__uc_get_reason (uc, &reason);
__uc_get_ip (uc, &ip);
printf (" @ %lx (reason=%d)", ip, reason);
}
# endif # endif
#elif UNW_TARGET_X86 #elif UNW_TARGET_X86
printf (" @ %lx", sc.eip); printf (" @ %lx", sc.eip);
@ -155,11 +161,16 @@ main (int argc, char **argv)
printf ("Normal backtrace:\n"); printf ("Normal backtrace:\n");
foo (); foo ();
memset (&act, 0, sizeof (act));
act.sa_handler = (void (*)(int)) sighandler;
act.sa_flags = SA_SIGINFO;
if (sigaction (SIGTERM, &act, NULL) < 0)
panic ("sigaction: %s\n", strerror (errno));
printf ("\nBacktrace across signal handler:\n"); printf ("\nBacktrace across signal handler:\n");
signal (SIGTERM, (sighandler_t) sighandler);
kill (getpid (), SIGTERM); kill (getpid (), SIGTERM);
printf ("Backtrace across signal handler on alternate stack:\n"); printf ("\nBacktrace across signal handler on alternate stack:\n");
stk.ss_sp = malloc (STACK_SIZE); stk.ss_sp = malloc (STACK_SIZE);
if (!stk.ss_sp) if (!stk.ss_sp)
panic ("failed to allocate SIGSTKSZ (%u) bytes\n", SIGSTKSZ); panic ("failed to allocate SIGSTKSZ (%u) bytes\n", SIGSTKSZ);
@ -170,7 +181,7 @@ main (int argc, char **argv)
memset (&act, 0, sizeof (act)); memset (&act, 0, sizeof (act));
act.sa_handler = (void (*)(int)) sighandler; act.sa_handler = (void (*)(int)) sighandler;
act.sa_flags = SA_ONSTACK; act.sa_flags = SA_ONSTACK | SA_SIGINFO;
if (sigaction (SIGTERM, &act, NULL) < 0) if (sigaction (SIGTERM, &act, NULL) < 0)
panic ("sigaction: %s\n", strerror (errno)); panic ("sigaction: %s\n", strerror (errno));
kill (getpid (), SIGTERM); kill (getpid (), SIGTERM);