Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Unified Diff: src/platform-linux.cc

Issue 11577019: V8_Fatal now prints C++ stack trace in debug mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/platform-linux.cc
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index 8022ba2d5af110ab24f155872736ed3d9a6b5f9d..b1d7c5268c75f013319bed6df1fc4c7738a5f8ff 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -37,6 +37,11 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdlib.h>
+#include <execinfo.h>
ulan_google 2012/12/14 12:40:31 This should be guarded by GLIBC too, otherwise it
rossberg 2012/12/14 13:53:20 Done.
+
+#if defined(__GLIBC__)
+#include <cxxabi.h>
+#endif
// Ubuntu Dapper requires memory pages to be marked as
// executable. Otherwise, OS raises an exception when executing code
@@ -415,6 +420,39 @@ void OS::DebugBreak() {
}
+void OS::DumpBacktrace() {
+ void* trace[100];
ulan_google 2012/12/14 12:40:31 This should be guarded by GLIBC
rossberg 2012/12/14 13:53:20 Done.
+ int size = backtrace(trace, ARRAY_SIZE(trace));
+ char** symbols = backtrace_symbols(trace, size);
+ fprintf(stderr, "\n==== C stack trace ===============================\n\n");
+ if (size == 0) {
+ fprintf(stderr, "(empty)\n");
+ } else if (symbols == NULL) {
+ fprintf(stderr, "(no symbols)\n");
+ } else {
+ for (int i = 1; i < size; ++i) {
+ fprintf(stderr, "%2d: ", i);
+#if defined(__GLIBC__)
+ char mangled[201];
+ if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) {
+ int status;
+ size_t length;
+ char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
+ fprintf(stderr, "%s\n", demangled ? demangled : mangled);
+ free(demangled);
+ } else {
+ fprintf(stderr, "??\n");
+ }
+#else
+ fprintf(stderr, "%s\n", symbols[i]);
+#endif
+ }
+ }
+ fflush(stderr);
+ free(symbols);
+}
+
+
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
« build/common.gypi ('K') | « src/platform.h ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698