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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/logging.h" 5 #include "src/base/logging.h"
6 6
7 #if V8_LIBC_GLIBC || V8_OS_BSD 7 #if V8_LIBC_GLIBC || V8_OS_BSD
8 # include <cxxabi.h> 8 #include <cxxabi.h>
9 # include <execinfo.h> 9 #include <dlfcn.h>
10 #include <execinfo.h>
10 #elif V8_OS_QNX 11 #elif V8_OS_QNX
11 # include <backtrace.h> 12 #include <backtrace.h>
12 #endif // V8_LIBC_GLIBC || V8_OS_BSD 13 #endif // V8_LIBC_GLIBC || V8_OS_BSD
13 14
14 #include <cstdio> 15 #include <cstdio>
15 #include <cstdlib> 16 #include <cstdlib>
16 17
17 #include "src/base/platform/platform.h" 18 #include "src/base/platform/platform.h"
18 19
19 namespace v8 { 20 namespace v8 {
20 namespace base { 21 namespace base {
21 22
(...skipping 25 matching lines...) Expand all
47 DEFINE_CHECK_OP_IMPL(GE) 48 DEFINE_CHECK_OP_IMPL(GE)
48 DEFINE_CHECK_OP_IMPL(GT) 49 DEFINE_CHECK_OP_IMPL(GT)
49 #undef DEFINE_CHECK_OP_IMPL 50 #undef DEFINE_CHECK_OP_IMPL
50 51
51 52
52 // Attempts to dump a backtrace (if supported). 53 // Attempts to dump a backtrace (if supported).
53 void DumpBacktrace() { 54 void DumpBacktrace() {
54 #if V8_LIBC_GLIBC || V8_OS_BSD 55 #if V8_LIBC_GLIBC || V8_OS_BSD
55 void* trace[100]; 56 void* trace[100];
56 int size = backtrace(trace, arraysize(trace)); 57 int size = backtrace(trace, arraysize(trace));
57 char** symbols = backtrace_symbols(trace, size);
58 OS::PrintError("\n==== C stack trace ===============================\n\n"); 58 OS::PrintError("\n==== C stack trace ===============================\n\n");
59 if (size == 0) { 59 if (size == 0) {
60 OS::PrintError("(empty)\n"); 60 OS::PrintError("(empty)\n");
61 } else if (symbols == NULL) {
62 OS::PrintError("(no symbols)\n");
63 } else { 61 } else {
64 for (int i = 1; i < size; ++i) { 62 for (int i = 1; i < size; ++i) {
65 OS::PrintError("%2d: ", i); 63 OS::PrintError("%2d: ", i);
66 char mangled[201]; 64 Dl_info info;
67 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT 65 char* demangled = NULL;
68 int status; 66 if (!dladdr(trace[i], &info) || !info.dli_sname) {
69 size_t length; 67 OS::PrintError("%p\n", trace[i]);
70 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); 68 } else if ((demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0))) {
71 OS::PrintError("%s\n", demangled != NULL ? demangled : mangled); 69 OS::PrintError("%s\n", demangled);
72 free(demangled); 70 free(demangled);
73 } else { 71 } else {
74 OS::PrintError("??\n"); 72 OS::PrintError("%s\n", info.dli_sname);
75 } 73 }
76 } 74 }
77 } 75 }
78 free(symbols);
79 #elif V8_OS_QNX 76 #elif V8_OS_QNX
80 char out[1024]; 77 char out[1024];
81 bt_accessor_t acc; 78 bt_accessor_t acc;
82 bt_memmap_t memmap; 79 bt_memmap_t memmap;
83 bt_init_accessor(&acc, BT_SELF); 80 bt_init_accessor(&acc, BT_SELF);
84 bt_load_memmap(&acc, &memmap); 81 bt_load_memmap(&acc, &memmap);
85 bt_sprn_memmap(&memmap, out, sizeof(out)); 82 bt_sprn_memmap(&memmap, out, sizeof(out));
86 OS::PrintError(out); 83 OS::PrintError(out);
87 bt_addr_t trace[100]; 84 bt_addr_t trace[100];
88 int size = bt_get_backtrace(&acc, trace, arraysize(trace)); 85 int size = bt_get_backtrace(&acc, trace, arraysize(trace));
(...skipping 22 matching lines...) Expand all
111 line); 108 line);
112 va_list arguments; 109 va_list arguments;
113 va_start(arguments, format); 110 va_start(arguments, format);
114 v8::base::OS::VPrintError(format, arguments); 111 v8::base::OS::VPrintError(format, arguments);
115 va_end(arguments); 112 va_end(arguments);
116 v8::base::OS::PrintError("\n#\n"); 113 v8::base::OS::PrintError("\n#\n");
117 v8::base::DumpBacktrace(); 114 v8::base::DumpBacktrace();
118 fflush(stderr); 115 fflush(stderr);
119 v8::base::OS::Abort(); 116 v8::base::OS::Abort();
120 } 117 }
OLDNEW
« 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