1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2025-01-11 03:23:43 +01:00

Make it compile cleanly on x86.

(Logical change 1.32)
This commit is contained in:
mostang.com!davidm 2002-12-19 07:16:50 +00:00
parent 9f32da41c3
commit ccfcac6e20
3 changed files with 45 additions and 14 deletions

View file

@ -39,6 +39,7 @@ static void
do_backtrace (void)
{
unw_cursor_t cursor;
unw_proc_info_t pi;
unw_word_t ip, sp;
unw_context_t uc;
char buf[512];
@ -53,22 +54,29 @@ do_backtrace (void)
unw_get_reg (&cursor, UNW_REG_IP, &ip);
unw_get_reg (&cursor, UNW_REG_SP, &sp);
unw_get_proc_name (&cursor, buf, sizeof (buf));
printf ("%016lx %-32s (sp=%016lx)\n", ip, buf, sp);
{
unw_proc_info_t pi;
unw_word_t bsp;
printf ("%016lx %-32s (sp=%016lx)\n", (long) ip, buf, (long) sp);
unw_get_proc_info (&cursor, &pi);
printf ("\tproc=%016lx-%016lx\n\thandler=%lx lsda=%lx",
(long) pi.start_ip, (long) pi.end_ip,
(long) pi.handler, (long) pi.lsda);
#if UNW_TARGET_IA64
{
unw_word_t bsp;
unw_get_reg (&cursor, UNW_IA64_BSP, &bsp);
printf ("\tproc=%016lx-%016lx\n\thandler=%lx lsda=%lx bsp=%lx\n",
pi.start_ip, pi.end_ip, pi.handler, pi.lsda, bsp);
printf (" bsp=%lx", bsp);
}
#endif
printf ("\n");
ret = unw_step (&cursor);
if (ret < 0)
{
unw_get_reg (&cursor, UNW_REG_IP, &ip);
printf ("FAILURE: unw_step() returned %d for ip=%lx\n", ret, ip);
printf ("FAILURE: unw_step() returned %d for ip=%lx\n",
ret, (long) ip);
}
}
while (ret > 0);
@ -88,9 +96,19 @@ foo (void)
}
void
#ifdef UNW_TARGET_X86
sighandler (int signal, struct sigcontext sc)
#else
sighandler (int signal, void *siginfo, struct sigcontext *sc)
#endif
{
printf ("sighandler: got signal %d @ %lx\n", signal, sc->sc_ip);
printf ("sighandler: got signal %d", signal);
#if UNW_TARGET_IA64
printf (" @ %lx", sc->sc_ip);
#elif UNW_TARGET_X86
printf (" @ %lx", sc.eip);
#endif
printf ("\n");
do_backtrace();
}

View file

@ -55,7 +55,7 @@ raise_exception (void *addr)
panic ("unw_step() failed!\n");
unw_get_reg (&cursor, UNW_REG_IP, &ip);
printf ("ip = %lx\n", ip);
printf ("ip = %lx\n", (long) ip);
if (unw_set_reg (&cursor, UNW_REG_IP, (unw_word_t) addr) < 0)
panic ("unw_set_reg() failed!\n");
@ -71,11 +71,22 @@ b (void *addr)
printf ("b(): back from raise_exception!!\n");
}
#ifndef __ia64__
void *
__builtin_ia64_bsp (void)
{
return NULL;
}
#endif
static int
a (void)
{
register long sp asm ("r12");
printf("a: sp=%lx bsp=%p\n", sp, __builtin_ia64_bsp ());
long stack;
printf ("a: sp=%p bsp=%p\n", &stack, __builtin_ia64_bsp ());
b (&&handler);
printf ("unexpected return from func()!\n");
@ -83,8 +94,8 @@ a (void)
return -1;
handler:
printf ("exception handler: here we go (sp=%lx, bsp=%p)...\n",
sp, __builtin_ia64_bsp ());
printf ("exception handler: here we go (sp=%p, bsp=%p)...\n",
&stack, __builtin_ia64_bsp ());
return 0;
}

View file

@ -27,6 +27,7 @@ struct fdesc
};
# define get_fdesc(fdesc,func) (fdesc = *(struct fdesc *) &(func))
# define get_funcp(fdesc) ((template_t) &(fdesc))
# define get_gp(fdesc) ((fdesc).gp)
#else
struct fdesc
{
@ -34,14 +35,15 @@ struct fdesc
};
# define get_fdesc(fdesc,func) (fdesc.code = (long) &(func))
# define get_funcp(fdesc) ((template_t) (fdesc).code)
# define get_gp(fdesc) (0)
#endif
static void
flush_cache (void *addr, unsigned long len)
{
#ifdef __ia64__
void *end = (char *) addr + len;
#ifdef __ia64__
while (addr < end)
{
asm volatile ("fc %0" :: "r"(addr));
@ -126,7 +128,7 @@ main (int argc, char *argv[])
memset (&di, 0, sizeof (di));
di.start_ip = (long) mem;
di.end_ip = (long) mem + 256;
di.gp = fdesc.gp;
di.gp = get_gp (fdesc);
di.format = UNW_INFO_FORMAT_DYNAMIC;
di.u.pi.name_ptr = (unw_word_t) "copy_of_template";
di.u.pi.regions = region;