Solution sought to GCC 4.1.1 backtrace problem

Blair Barnett blairbarnett@sbcglobal.net
Fri Aug 31 21:55:00 GMT 2007


Hi Andrew,

So our experiment with the 4.1.1 EABI compiler along with your patch provided no new results.

I applied your patch and recompiled arm-linux-gcc and recompiled our little test program. I copied the program to our arm device and ran it, obtaining the following output:

arm-linux-gcc -o fault-unwind fault.c

 ./fault-unwind
in routine1 at 0x00008874
in routine2 at 0x0000882c
in routine3 at 0x000087e4
in routine4 at 0x00008794
in catch_segfault
Obtained 1 stack frames.
/lib/ld-linux.so.2 [0x40012f84]
Segmentation fault


If we run the 4.1.2 compiler included with ubuntu on our little test program, we get the following results:

bbarnett@kitt:~$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
bbarnett@kitt:~$ gcc -o fault fault.c
bbarnett@kitt:~$ ./fault
in routine1 at 0x080486de
in routine2 at 0x080486ae
in routine3 at 0x0804867e
in routine4 at 0x0804864a
in catch_segfault
Obtained 8 stack frames.
./fault [0x8048547]
[0xffffe420]
./fault [0x80486ac]
./fault [0x80486dc]
./fault [0x804870c]
./fault [0x8048730]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xdc) [0xb7e5febc]
./fault [0x8048491]
Segmentation fault (core dumped)

So glibc backtrace() appears to work in an EABI environment, just not an ARM EABI environment.

Here's the little test program:
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <execinfo.h>
#include <signal.h>

static void
catch_segfault (int signal, void *foo)
{
    int *arr[32];
    int size, i;
    struct sigaction sa;
    char **strings;

    printf("in %s\n", __FUNCTION__);

    size = backtrace((void **)arr, 32);

    strings = backtrace_symbols ((void **)arr, size);

    printf ("Obtained %zd stack frames.\n", size);
    for (i = 0; i < size; i++)
        printf ("%s\n", strings[i]);
    free (strings);
    
    /* Pass on the signal (so that a core file is produced).  */
    sa.sa_handler = SIG_DFL;
    sigemptyset (&sa.sa_mask);
    sa.sa_flags = 0;
    sigaction (signal, &sa, NULL);
    raise (signal);
}

#define INSTALL_FOR_SIG(sig)     \
        sigaction(sig, &sa, NULL)
void
install_fh(void)
{
    struct sigaction sa;
    char *path = NULL;
    char *where;
    
    sa.sa_handler = (void *) catch_segfault;
    sigemptyset (&sa.sa_mask);
    sa.sa_flags = SA_RESTART;

    INSTALL_FOR_SIG (SIGSEGV);
}

int
routine4(volatile int arg)
{
    printf("in %s at %.8p\n", __FUNCTION__, routine4);
    *(int *)0 = 0xdeadbeef;
    return 1;
}

int
routine3(volatile int arg)
{
    printf("in %s at %.8p\n", __FUNCTION__, routine3);
    return routine4(0xdead4444);
}

int
routine2(volatile int arg)
{
    printf("in %s at %.8p\n", __FUNCTION__, routine2);
    return routine3(0xdead3333);
}

int
routine1(volatile int arg)
{
    printf("in %s at %.8p\n", __FUNCTION__, routine1);
    return routine2(0xdead2222);
}

int
main(int argc, char **argv)
{
    install_fh();
    routine1(0xdead1111);
    return 1;
}





More information about the Gcc-help mailing list