[PATCH] os/backtrace: Use backtrace_symbols where available

Jeremy Huddleston jeremyhu at apple.com
Sun Apr 24 20:15:35 PDT 2011


hrm... nevermind... I'll come up with something else...

commit eb031d4013d36f6aef4aba45840762ae8635cc13
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Aug 19 15:42:34 2009 -0400

    linux: hand-roll a backtrace printer instead of using backtrace_symbols
    
    Why?  Because backtrace_symbols calls malloc, which you can't do from a
    signal handler.  Face?  Palm.


On Apr 23, 2011, at 01:19, Jeremy Huddleston wrote:

> Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
> ---
> 
> I'm curious why this wasn't done from the beginning...  Is the format printed actually important, or can we trust libc to provide us with useful strings?  I'd prefer seeing the backtrace formatted by backtrace_symbols because I can use existing tools to analyze that backtrace (since it is in a format such tools expect).
> 
> os/backtrace.c |   19 +++++++------------
> 1 files changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/os/backtrace.c b/os/backtrace.c
> index 7ca6dab..5ddb15c 100644
> --- a/os/backtrace.c
> +++ b/os/backtrace.c
> @@ -37,21 +37,16 @@
> 
> void xorg_backtrace(void)
> {
> -    void *array[64];
> -    const char *mod;
> +    void *callstack[64];
>     int size, i;
> -    Dl_info info;
> +    char **strs;
> +
>     ErrorF("\nBacktrace:\n");
> -    size = backtrace(array, 64);
> +    size = backtrace(callstack, 64);
> +    strs = backtrace_symbols(callstack, size);
> +
>     for (i = 0; i < size; i++) {
> -	dladdr(array[i], &info);
> -	mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
> -	if (info.dli_saddr)
> -	    ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
> -		   info.dli_sname, (long unsigned int)((char *) array[i] - (char *) info.dli_saddr), array[i]);
> -	else
> -	    ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
> -		   info.dli_fbase, (long unsigned int)((char *) array[i] - (char *) info.dli_fbase), array[i]);
> +        ErrorF("%s\n", strs[i]);
>     }
> }
> 
> -- 
> 1.7.4.4
> 
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 



More information about the xorg-devel mailing list