> Included is a manpage documenting backtrace(); it is not presently
> ready for inclusion; some issues remain.  

> I'm sending it for review
> and for help..

Justin, I probably need you to do as much as possible.
Have you read the other documentation, and integrated relevant
ideas into the page?

My helping time is limited.  Happily, Stefan is willing to help.
Converse with him, and keep me in the loop.

> You can view it with something like "nroff -man backtrace.3 |less".

It was a while beore I realised that "man -l" is simpler...

> The most important thing that needs fixing is figuring out why the
> backtrace doesn't work :)  I don't know how to get the function names
> to resolve from their addresses.  Apparently -rdynamic does this, but
> it doesn't work for me...

It works for me:

$ cat t_backtrace.c
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void
myfunc3(void)
{
    int size, j;
#define SIZE 100
    void *buffer[SIZE];
    char **strings;

    size = backtrace(buffer, SIZE);

    strings = backtrace_symbols(buffer, size);
    if (strings == NULL) {
        perror("backtrace_symbols");
        exit(EXIT_FAILURE);
    }

    for (j = 0; j < size; j++) {
        printf("%s\n", strings[j]);
    }
}

void
myfunc2(void)
{
    myfunc3();
}

static void   /* 'static' means don't export the symbol... */
myfunc(void)
{
    myfunc2();
}

int
main(int argc, char *argv[])
{
    myfunc();
    exit(EXIT_SUCCESS);
} /* main */


$ cc -rdynamic t_backtrace.c
$ ./a.out
./a.out(myfunc3+0x1f) [0x8048693]
./a.out(myfunc2+0xb) [0x8048701]
./a.out [0x804870e]
./a.out(main+0x16) [0x8048726]
/lib/libc.so.6(__libc_start_main+0xdc) [0xb7e6f87c]
./a.out [0x80485f1]

Note the effect that "static" has for "myfunc()".

Without -rdynamic, we get:

$ cc t_backtrace.c
$ ./a.out
./a.out [0x80484d3]
./a.out [0x8048541]
./a.out [0x804854e]
./a.out [0x8048566]
/lib/libc.so.6(__libc_start_main+0xdc) [0xb7e1d87c]
./a.out [0x8048431]

Cheers,

Michael
-- 
Michael Kerrisk
maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 

Want to help with man page maintenance?  
Grab the latest tarball at
ftp://ftp.win.tue.nl/pub/linux-local/manpages/, 
read the HOWTOHELP file and grep the source 
files for 'FIXME'.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to