Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 // Slightly adapted for inclusion in V8. | 5 // Slightly adapted for inclusion in V8. |
| 6 // Copyright 2016 the V8 project authors. All rights reserved. | 6 // Copyright 2016 the V8 project authors. All rights reserved. |
| 7 | 7 |
| 8 #include "src/base/debug/stack_trace.h" | 8 #include "src/base/debug/stack_trace.h" |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 void ProcessBacktrace(void* const* trace, size_t size, | 138 void ProcessBacktrace(void* const* trace, size_t size, |
| 139 BacktraceOutputHandler* handler) { | 139 BacktraceOutputHandler* handler) { |
| 140 // NOTE: This code MUST be async-signal safe (it's used by in-process | 140 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 141 // stack dumping signal handler). NO malloc or stdio is allowed here. | 141 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 142 handler->HandleOutput("\n"); | 142 handler->HandleOutput("\n"); |
| 143 handler->HandleOutput("==== C stack trace ===============================\n"); | 143 handler->HandleOutput("==== C stack trace ===============================\n"); |
| 144 handler->HandleOutput("\n"); | 144 handler->HandleOutput("\n"); |
| 145 | 145 |
| 146 bool printed = false; | 146 bool printed = false; |
| 147 | 147 |
| 148 // NOTE: backtrace_symbol API is not supported on AIX and there is no | |
| 149 // equivalent user-mode API. For now disabling the call to the API | |
|
rmcilroy
2016/09/08 10:10:10
No need for the comment (there are probably other
| |
| 150 #if !V8_OS_AIX | |
|
rmcilroy
2016/09/08 10:10:10
Could you instead ifdef out the whole of ProcessBa
| |
| 148 // Below part is async-signal unsafe (uses malloc), so execute it only | 151 // Below part is async-signal unsafe (uses malloc), so execute it only |
| 149 // when we are not executing the signal handler. | 152 // when we are not executing the signal handler. |
| 150 if (in_signal_handler == 0) { | 153 if (in_signal_handler == 0) { |
| 151 std::unique_ptr<char*, FreeDeleter> trace_symbols( | 154 std::unique_ptr<char*, FreeDeleter> trace_symbols( |
| 152 backtrace_symbols(trace, static_cast<int>(size))); | 155 backtrace_symbols(trace, static_cast<int>(size))); |
| 153 if (trace_symbols.get()) { | 156 if (trace_symbols.get()) { |
| 154 for (size_t i = 0; i < size; ++i) { | 157 for (size_t i = 0; i < size; ++i) { |
| 155 std::string trace_symbol = trace_symbols.get()[i]; | 158 std::string trace_symbol = trace_symbols.get()[i]; |
| 156 DemangleSymbols(&trace_symbol); | 159 DemangleSymbols(&trace_symbol); |
| 157 handler->HandleOutput(" "); | 160 handler->HandleOutput(" "); |
| 158 handler->HandleOutput(trace_symbol.c_str()); | 161 handler->HandleOutput(trace_symbol.c_str()); |
| 159 handler->HandleOutput("\n"); | 162 handler->HandleOutput("\n"); |
| 160 } | 163 } |
| 161 | 164 |
| 162 printed = true; | 165 printed = true; |
| 163 } | 166 } |
| 164 } | 167 } |
| 168 #endif | |
| 165 | 169 |
| 166 if (!printed) { | 170 if (!printed) { |
| 167 for (size_t i = 0; i < size; ++i) { | 171 for (size_t i = 0; i < size; ++i) { |
| 168 handler->HandleOutput(" ["); | 172 handler->HandleOutput(" ["); |
| 169 OutputPointer(trace[i], handler); | 173 OutputPointer(trace[i], handler); |
| 170 handler->HandleOutput("]\n"); | 174 handler->HandleOutput("]\n"); |
| 171 } | 175 } |
| 172 } | 176 } |
| 173 } | 177 } |
| 174 | 178 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 dump_stack_in_signal_handler = true; | 353 dump_stack_in_signal_handler = true; |
| 350 | 354 |
| 351 return success; | 355 return success; |
| 352 } | 356 } |
| 353 | 357 |
| 354 void DisableSignalStackDump() { | 358 void DisableSignalStackDump() { |
| 355 dump_stack_in_signal_handler = false; | 359 dump_stack_in_signal_handler = false; |
| 356 } | 360 } |
| 357 | 361 |
| 358 StackTrace::StackTrace() { | 362 StackTrace::StackTrace() { |
| 363 // NOTE: backtrace API is not supported on AIX and there is no | |
| 364 // equivalent user-mode API. For now disabling the call to the API | |
|
rmcilroy
2016/09/08 10:10:10
No need for the comment
| |
| 365 #if V8_OS_AIX | |
|
rmcilroy
2016/09/08 10:10:10
Could you make this #if !V8_OS_AIX and swap the br
| |
| 366 count_ = 0; | |
| 367 #else | |
| 359 // NOTE: This code MUST be async-signal safe (it's used by in-process | 368 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 360 // stack dumping signal handler). NO malloc or stdio is allowed here. | 369 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 361 | 370 |
| 362 // Though the backtrace API man page does not list any possible negative | 371 // Though the backtrace API man page does not list any possible negative |
| 363 // return values, we take no chance. | 372 // return values, we take no chance. |
| 364 count_ = static_cast<size_t>(backtrace(trace_, arraysize(trace_))); | 373 count_ = static_cast<size_t>(backtrace(trace_, arraysize(trace_))); |
| 374 #endif | |
| 365 } | 375 } |
| 366 | 376 |
| 367 void StackTrace::Print() const { | 377 void StackTrace::Print() const { |
| 368 // NOTE: This code MUST be async-signal safe (it's used by in-process | 378 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 369 // stack dumping signal handler). NO malloc or stdio is allowed here. | 379 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 370 | 380 |
| 371 PrintBacktraceOutputHandler handler; | 381 PrintBacktraceOutputHandler handler; |
| 372 ProcessBacktrace(trace_, count_, &handler); | 382 ProcessBacktrace(trace_, count_, &handler); |
| 373 } | 383 } |
| 374 | 384 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 *start++ = ch; | 447 *start++ = ch; |
| 438 } | 448 } |
| 439 return buf; | 449 return buf; |
| 440 } | 450 } |
| 441 | 451 |
| 442 } // namespace internal | 452 } // namespace internal |
| 443 | 453 |
| 444 } // namespace debug | 454 } // namespace debug |
| 445 } // namespace base | 455 } // namespace base |
| 446 } // namespace v8 | 456 } // namespace v8 |
| OLD | NEW |