Use libdl to get symbols for backtraces
With this patch, it'll look like this: $ out/x64.optdebug/d8 --expose-trigger-failure test/mjsunit/mjsunit.js test/mjsunit/verify-assert-false.js ==== C stack trace =============================== 1: V8_Fatal 2: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) 3: 0x727ced 4: 0x72b6ba 5: 0x188c7f607f9b BUG=none R=svenpanne@chromium.org LOG=y Review URL: https://codereview.chromium.org/1018313003 Cr-Commit-Position: refs/heads/master@{#27318}
This commit is contained in:
parent
22d62cea4d
commit
843634994f
2
BUILD.gn
2
BUILD.gn
@ -1393,7 +1393,7 @@ source_set("v8_libbase") {
|
||||
if (is_linux) {
|
||||
sources += [ "src/base/platform/platform-linux.cc" ]
|
||||
|
||||
libs = [ "rt" ]
|
||||
libs = [ "dl", "rt" ]
|
||||
} else if (is_android) {
|
||||
defines += [ "CAN_USE_VFP_INSTRUCTIONS" ]
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1370,6 +1370,7 @@
|
||||
['nacl_target_arch=="none"', {
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'-ldl',
|
||||
'-lrt'
|
||||
],
|
||||
},
|
||||
@ -1389,6 +1390,11 @@
|
||||
'sources': [
|
||||
'../../src/base/platform/platform-posix.cc'
|
||||
],
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'-ldl'
|
||||
]
|
||||
},
|
||||
'conditions': [
|
||||
['host_os=="mac"', {
|
||||
'target_conditions': [
|
||||
|
Loading…
Reference in New Issue
Block a user