1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
diff -u -p -8 -r1.12 nsStackFrameUnix.cpp
--- xpcom/base/nsStackFrameUnix.cpp 18 Apr 2004 14:18:12 -0000 1.12
+++ xpcom/base/nsStackFrameUnix.cpp 23 Jan 2006 09:23:04 -0000
@@ -77,19 +77,30 @@ void DemangleSymbol(const char * aSymbol
if (demangled)
{
strncpy(aBuffer,demangled,aBufLen);
free(demangled);
}
#endif // MOZ_DEMANGLE_SYMBOLS
}
+#if defined(linux) // Linux
+#if (__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) // use glibc backtrace()
+#include <execinfo.h>
+void DumpStackToFile(FILE* aStream)
+{
+ void *array[20];
+ size_t size;
-#if defined(linux) && defined(__GLIBC__) && (defined(__i386) || defined(PPC)) // i386 or PPC Linux stackwalking code
+ fflush(aStream);
+ size = backtrace (array, 20);
+ backtrace_symbols_fd (array, size, fileno(aStream));
+}
+#elif defined(__GLIBC__) && (defined(__i386) || defined(PPC)) // old style i386 or PPC Linux stackwalking code
#include <setjmp.h>
//
void DumpStackToFile(FILE* aStream)
{
jmp_buf jb;
setjmp(jb);
@@ -135,16 +146,23 @@ void DumpStackToFile(FILE* aStream)
PRUint32 off = (char*)pc - (char*)info.dli_saddr;
fprintf(aStream, "%s+0x%08X [%s +0x%08X]\n",
symbol, off, info.dli_fname, foff);
}
}
}
+#else // not implemented
+void DumpStackToFile(FILE* aStream)
+{
+ fprintf(aStream, "Info: Stacktrace not implemented for this Linux platform\n");
+}
+#endif // Linux
+
#elif defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))
/*
* Stack walking code for Solaris courtesy of Bart Smaalder's "memtrak".
*/
#include <synch.h>
#include <ucontext.h>
diff -u -p -8 -r1.96 nsTraceRefcntImpl.cpp
--- xpcom/base/nsTraceRefcntImpl.cpp 24 Jun 2005 00:24:41 -0000 1.96
+++ xpcom/base/nsTraceRefcntImpl.cpp 23 Jan 2006 09:24:05 -0000
@@ -823,18 +823,18 @@ static void InitTraceLog(void)
#include "nsStackFrameWin.h"
void
nsTraceRefcntImpl::WalkTheStack(FILE* aStream)
{
DumpStackToFile(aStream);
}
// WIN32 x86 stack walking code
-// i386 or PPC Linux stackwalking code or Solaris
-#elif (defined(linux) && defined(__GLIBC__) && (defined(__i386) || defined(PPC))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386)))
+// Linux stackwalking code or Solaris
+#elif (defined(linux) && defined(__GLIBC__)) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386)))
#include "nsStackFrameUnix.h"
void
nsTraceRefcntImpl::WalkTheStack(FILE* aStream)
{
DumpStackToFile(aStream);
}
#else // unsupported platform.
|