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

Side by Side Diff: src/base/debug/stack_trace_posix.cc

Issue 2324453002: AIX: Disable backtrace API call (Closed)
Patch Set: Addressed comments Created 4 years, 3 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 | « no previous file | src/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 (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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void OutputPointer(void* pointer, BacktraceOutputHandler* handler) { 128 void OutputPointer(void* pointer, BacktraceOutputHandler* handler) {
129 // This should be more than enough to store a 64-bit number in hex: 129 // This should be more than enough to store a 64-bit number in hex:
130 // 16 hex digits + 1 for null-terminator. 130 // 16 hex digits + 1 for null-terminator.
131 char buf[17] = {'\0'}; 131 char buf[17] = {'\0'};
132 handler->HandleOutput("0x"); 132 handler->HandleOutput("0x");
133 internal::itoa_r(reinterpret_cast<intptr_t>(pointer), buf, sizeof(buf), 16, 133 internal::itoa_r(reinterpret_cast<intptr_t>(pointer), buf, sizeof(buf), 16,
134 12); 134 12);
135 handler->HandleOutput(buf); 135 handler->HandleOutput(buf);
136 } 136 }
137 137
138 #if !V8_OS_AIX
138 void ProcessBacktrace(void* const* trace, size_t size, 139 void ProcessBacktrace(void* const* trace, size_t size,
139 BacktraceOutputHandler* handler) { 140 BacktraceOutputHandler* handler) {
140 // NOTE: This code MUST be async-signal safe (it's used by in-process 141 // 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. 142 // stack dumping signal handler). NO malloc or stdio is allowed here.
142 handler->HandleOutput("\n"); 143 handler->HandleOutput("\n");
143 handler->HandleOutput("==== C stack trace ===============================\n"); 144 handler->HandleOutput("==== C stack trace ===============================\n");
144 handler->HandleOutput("\n"); 145 handler->HandleOutput("\n");
145 146
146 bool printed = false; 147 bool printed = false;
147 148
(...skipping 16 matching lines...) Expand all
164 } 165 }
165 166
166 if (!printed) { 167 if (!printed) {
167 for (size_t i = 0; i < size; ++i) { 168 for (size_t i = 0; i < size; ++i) {
168 handler->HandleOutput(" ["); 169 handler->HandleOutput(" [");
169 OutputPointer(trace[i], handler); 170 OutputPointer(trace[i], handler);
170 handler->HandleOutput("]\n"); 171 handler->HandleOutput("]\n");
171 } 172 }
172 } 173 }
173 } 174 }
175 #endif // !V8_OS_AIX
174 176
175 void PrintToStderr(const char* output) { 177 void PrintToStderr(const char* output) {
176 // NOTE: This code MUST be async-signal safe (it's used by in-process 178 // NOTE: This code MUST be async-signal safe (it's used by in-process
177 // stack dumping signal handler). NO malloc or stdio is allowed here. 179 // stack dumping signal handler). NO malloc or stdio is allowed here.
178 ssize_t return_val = write(STDERR_FILENO, output, strlen(output)); 180 ssize_t return_val = write(STDERR_FILENO, output, strlen(output));
179 USE(return_val); 181 USE(return_val);
180 } 182 }
181 183
182 void StackDumpSignalHandler(int signal, siginfo_t* info, void* void_context) { 184 void StackDumpSignalHandler(int signal, siginfo_t* info, void* void_context) {
183 // NOTE: This code MUST be async-signal safe. 185 // NOTE: This code MUST be async-signal safe.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 354 }
353 355
354 void DisableSignalStackDump() { 356 void DisableSignalStackDump() {
355 dump_stack_in_signal_handler = false; 357 dump_stack_in_signal_handler = false;
356 } 358 }
357 359
358 StackTrace::StackTrace() { 360 StackTrace::StackTrace() {
359 // NOTE: This code MUST be async-signal safe (it's used by in-process 361 // 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. 362 // stack dumping signal handler). NO malloc or stdio is allowed here.
361 363
364 #if !V8_OS_AIX
362 // Though the backtrace API man page does not list any possible negative 365 // Though the backtrace API man page does not list any possible negative
363 // return values, we take no chance. 366 // return values, we take no chance.
364 count_ = static_cast<size_t>(backtrace(trace_, arraysize(trace_))); 367 count_ = static_cast<size_t>(backtrace(trace_, arraysize(trace_)));
368 #else
369 count_ = 0;
370 #endif
365 } 371 }
366 372
367 void StackTrace::Print() const { 373 void StackTrace::Print() const {
368 // NOTE: This code MUST be async-signal safe (it's used by in-process 374 // 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. 375 // stack dumping signal handler). NO malloc or stdio is allowed here.
370 376
377 #if !V8_OS_AIX
371 PrintBacktraceOutputHandler handler; 378 PrintBacktraceOutputHandler handler;
372 ProcessBacktrace(trace_, count_, &handler); 379 ProcessBacktrace(trace_, count_, &handler);
380 #endif
373 } 381 }
374 382
383 #if !V8_OS_AIX
375 void StackTrace::OutputToStream(std::ostream* os) const { 384 void StackTrace::OutputToStream(std::ostream* os) const {
376 StreamBacktraceOutputHandler handler(os); 385 StreamBacktraceOutputHandler handler(os);
377 ProcessBacktrace(trace_, count_, &handler); 386 ProcessBacktrace(trace_, count_, &handler);
378 } 387 }
388 #endif
379 389
380 namespace internal { 390 namespace internal {
381 391
382 // NOTE: code from sandbox/linux/seccomp-bpf/demo.cc. 392 // NOTE: code from sandbox/linux/seccomp-bpf/demo.cc.
383 char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) { 393 char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) {
384 // Make sure we can write at least one NUL byte. 394 // Make sure we can write at least one NUL byte.
385 size_t n = 1; 395 size_t n = 1;
386 if (n > sz) return NULL; 396 if (n > sz) return NULL;
387 397
388 if (base < 2 || base > 16) { 398 if (base < 2 || base > 16) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698