[PATCH] os/backtrace: Use backtrace_symbols where available

Jeremy Huddleston jeremyhu at apple.com
Sat Apr 23 01:19:50 PDT 2011


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




More information about the xorg-devel mailing list