| 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 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); | 395 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); |
| 396 #endif // ARCH_CPU_32_BITS | 396 #endif // ARCH_CPU_32_BITS |
| 397 #endif // defined(OS_MACOSX) | 397 #endif // defined(OS_MACOSX) |
| 398 _exit(1); | 398 _exit(1); |
| 399 } | 399 } |
| 400 | 400 |
| 401 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { | 401 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { |
| 402 public: | 402 public: |
| 403 PrintBacktraceOutputHandler() {} | 403 PrintBacktraceOutputHandler() {} |
| 404 | 404 |
| 405 virtual void HandleOutput(const char* output) OVERRIDE { | 405 void HandleOutput(const char* output) override { |
| 406 // NOTE: This code MUST be async-signal safe (it's used by in-process | 406 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 407 // stack dumping signal handler). NO malloc or stdio is allowed here. | 407 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 408 PrintToStderr(output); | 408 PrintToStderr(output); |
| 409 } | 409 } |
| 410 | 410 |
| 411 private: | 411 private: |
| 412 DISALLOW_COPY_AND_ASSIGN(PrintBacktraceOutputHandler); | 412 DISALLOW_COPY_AND_ASSIGN(PrintBacktraceOutputHandler); |
| 413 }; | 413 }; |
| 414 | 414 |
| 415 class StreamBacktraceOutputHandler : public BacktraceOutputHandler { | 415 class StreamBacktraceOutputHandler : public BacktraceOutputHandler { |
| 416 public: | 416 public: |
| 417 explicit StreamBacktraceOutputHandler(std::ostream* os) : os_(os) { | 417 explicit StreamBacktraceOutputHandler(std::ostream* os) : os_(os) { |
| 418 } | 418 } |
| 419 | 419 |
| 420 virtual void HandleOutput(const char* output) OVERRIDE { | 420 void HandleOutput(const char* output) override { (*os_) << output; } |
| 421 (*os_) << output; | |
| 422 } | |
| 423 | 421 |
| 424 private: | 422 private: |
| 425 std::ostream* os_; | 423 std::ostream* os_; |
| 426 | 424 |
| 427 DISALLOW_COPY_AND_ASSIGN(StreamBacktraceOutputHandler); | 425 DISALLOW_COPY_AND_ASSIGN(StreamBacktraceOutputHandler); |
| 428 }; | 426 }; |
| 429 | 427 |
| 430 void WarmUpBacktrace() { | 428 void WarmUpBacktrace() { |
| 431 // Warm up stack trace infrastructure. It turns out that on the first | 429 // Warm up stack trace infrastructure. It turns out that on the first |
| 432 // call glibc initializes some internal data structures using pthread_once, | 430 // call glibc initializes some internal data structures using pthread_once, |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 *ptr = *start; | 824 *ptr = *start; |
| 827 *start++ = ch; | 825 *start++ = ch; |
| 828 } | 826 } |
| 829 return buf; | 827 return buf; |
| 830 } | 828 } |
| 831 | 829 |
| 832 } // namespace internal | 830 } // namespace internal |
| 833 | 831 |
| 834 } // namespace debug | 832 } // namespace debug |
| 835 } // namespace base | 833 } // namespace base |
| OLD | NEW |