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

Unified Diff: src/base/logging.cc

Issue 1018313003: Use libdl to get symbols for backtraces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 9 months 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
« no previous file with comments | « BUILD.gn ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/logging.cc
diff --git a/src/base/logging.cc b/src/base/logging.cc
index 25d77bb1ec1dc9b9e9e84e3ac2460eb689ac088f..a2688c9c9aefb1f566f048e79c7f6ec4c0f9db16 100644
--- a/src/base/logging.cc
+++ b/src/base/logging.cc
@@ -5,10 +5,11 @@
#include "src/base/logging.h"
#if V8_LIBC_GLIBC || V8_OS_BSD
-# include <cxxabi.h>
-# include <execinfo.h>
+#include <cxxabi.h>
+#include <dlfcn.h>
+#include <execinfo.h>
#elif V8_OS_QNX
-# include <backtrace.h>
+#include <backtrace.h>
#endif // V8_LIBC_GLIBC || V8_OS_BSD
#include <cstdio>
@@ -54,28 +55,24 @@ void DumpBacktrace() {
#if V8_LIBC_GLIBC || V8_OS_BSD
void* trace[100];
int size = backtrace(trace, arraysize(trace));
- char** symbols = backtrace_symbols(trace, size);
OS::PrintError("\n==== C stack trace ===============================\n\n");
if (size == 0) {
OS::PrintError("(empty)\n");
- } else if (symbols == NULL) {
- OS::PrintError("(no symbols)\n");
} else {
for (int i = 1; i < size; ++i) {
OS::PrintError("%2d: ", i);
- char mangled[201];
- if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
- int status;
- size_t length;
- char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
- OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
+ Dl_info info;
+ char* demangled = NULL;
+ if (!dladdr(trace[i], &info) || !info.dli_sname) {
+ OS::PrintError("%p\n", trace[i]);
+ } else if ((demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0))) {
+ OS::PrintError("%s\n", demangled);
free(demangled);
} else {
- OS::PrintError("??\n");
+ OS::PrintError("%s\n", info.dli_sname);
}
}
}
- free(symbols);
#elif V8_OS_QNX
char out[1024];
bt_accessor_t acc;
« no previous file with comments | « BUILD.gn ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698