| 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 <stddef.h> | 10 #include <stddef.h> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #include <sys/param.h> | 14 #include <sys/param.h> |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 #include <sys/types.h> | 16 #include <sys/types.h> |
| 17 #include <unistd.h> | 17 #include <unistd.h> |
| 18 | 18 |
| 19 #include <algorithm> |
| 19 #include <map> | 20 #include <map> |
| 20 #include <memory> | 21 #include <memory> |
| 21 #include <ostream> | 22 #include <ostream> |
| 22 #include <string> | 23 #include <string> |
| 23 #include <vector> | 24 #include <vector> |
| 24 | 25 |
| 25 #if !defined(USE_SYMBOLIZE) | 26 #if !defined(USE_SYMBOLIZE) |
| 26 #include <cxxabi.h> | 27 #include <cxxabi.h> |
| 27 #endif | 28 #endif |
| 28 #if !defined(__UCLIBC__) | 29 #if !defined(__UCLIBC__) |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 success &= (sigaction(SIGBUS, &action, NULL) == 0); | 710 success &= (sigaction(SIGBUS, &action, NULL) == 0); |
| 710 success &= (sigaction(SIGSEGV, &action, NULL) == 0); | 711 success &= (sigaction(SIGSEGV, &action, NULL) == 0); |
| 711 // On Linux, SIGSYS is reserved by the kernel for seccomp-bpf sandboxing. | 712 // On Linux, SIGSYS is reserved by the kernel for seccomp-bpf sandboxing. |
| 712 #if !defined(OS_LINUX) | 713 #if !defined(OS_LINUX) |
| 713 success &= (sigaction(SIGSYS, &action, NULL) == 0); | 714 success &= (sigaction(SIGSYS, &action, NULL) == 0); |
| 714 #endif // !defined(OS_LINUX) | 715 #endif // !defined(OS_LINUX) |
| 715 | 716 |
| 716 return success; | 717 return success; |
| 717 } | 718 } |
| 718 | 719 |
| 719 StackTrace::StackTrace() { | 720 StackTrace::StackTrace(size_t count) { |
| 720 // NOTE: This code MUST be async-signal safe (it's used by in-process | 721 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 721 // stack dumping signal handler). NO malloc or stdio is allowed here. | 722 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 722 | 723 |
| 723 #if !defined(__UCLIBC__) | 724 #if !defined(__UCLIBC__) |
| 725 count = std::min(arraysize(trace_), count); |
| 726 |
| 724 // Though the backtrace API man page does not list any possible negative | 727 // Though the backtrace API man page does not list any possible negative |
| 725 // return values, we take no chance. | 728 // return values, we take no chance. |
| 726 count_ = base::saturated_cast<size_t>(backtrace(trace_, arraysize(trace_))); | 729 count_ = base::saturated_cast<size_t>(backtrace(trace_, count)); |
| 727 #else | 730 #else |
| 728 count_ = 0; | 731 count_ = 0; |
| 729 #endif | 732 #endif |
| 730 } | 733 } |
| 731 | 734 |
| 732 void StackTrace::Print() const { | 735 void StackTrace::Print() const { |
| 733 // NOTE: This code MUST be async-signal safe (it's used by in-process | 736 // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 734 // stack dumping signal handler). NO malloc or stdio is allowed here. | 737 // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 735 | 738 |
| 736 #if !defined(__UCLIBC__) | 739 #if !defined(__UCLIBC__) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 *ptr = *start; | 810 *ptr = *start; |
| 808 *start++ = ch; | 811 *start++ = ch; |
| 809 } | 812 } |
| 810 return buf; | 813 return buf; |
| 811 } | 814 } |
| 812 | 815 |
| 813 } // namespace internal | 816 } // namespace internal |
| 814 | 817 |
| 815 } // namespace debug | 818 } // namespace debug |
| 816 } // namespace base | 819 } // namespace base |
| OLD | NEW |