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 <android/log.h> | 7 #include <android/log.h> |
8 #include <unwind.h> | 8 #include <unwind.h> |
9 #include <ostream> | 9 #include <ostream> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 StackTrace::StackTrace() { | 69 StackTrace::StackTrace() { |
70 StackCrawlState state(reinterpret_cast<uintptr_t*>(trace_), kMaxTraces); | 70 StackCrawlState state(reinterpret_cast<uintptr_t*>(trace_), kMaxTraces); |
71 _Unwind_Backtrace(&TraceStackFrame, &state); | 71 _Unwind_Backtrace(&TraceStackFrame, &state); |
72 count_ = state.frame_count; | 72 count_ = state.frame_count; |
73 } | 73 } |
74 | 74 |
75 void StackTrace::Print() const { | 75 void StackTrace::Print() const { |
76 std::string backtrace = ToString(); | 76 std::string backtrace = ToString(); |
77 __android_log_write(ANDROID_LOG_ERROR, "chromium", backtrace.c_str()); | 77 __android_log_write(ANDROID_LOG_ERROR, ANDROID_LOG_TAG, backtrace.c_str()); |
78 } | 78 } |
79 | 79 |
80 // NOTE: Native libraries in APKs are stripped before installing. Print out the | 80 // NOTE: Native libraries in APKs are stripped before installing. Print out the |
81 // relocatable address and library names so host computers can use tools to | 81 // relocatable address and library names so host computers can use tools to |
82 // symbolize and demangle (e.g., addr2line, c++filt). | 82 // symbolize and demangle (e.g., addr2line, c++filt). |
83 void StackTrace::OutputToStream(std::ostream* os) const { | 83 void StackTrace::OutputToStream(std::ostream* os) const { |
84 std::string proc_maps; | 84 std::string proc_maps; |
85 std::vector<MappedMemoryRegion> regions; | 85 std::vector<MappedMemoryRegion> regions; |
86 // Allow IO to read /proc/self/maps. Reading this file doesn't hit the disk | 86 // Allow IO to read /proc/self/maps. Reading this file doesn't hit the disk |
87 // since it lives in procfs, and this is currently used to print a stack trace | 87 // since it lives in procfs, and this is currently used to print a stack trace |
88 // on fatal log messages in debug builds only. If the restriction is enabled | 88 // on fatal log messages in debug builds only. If the restriction is enabled |
89 // then it will recursively trigger fatal failures when this enters on the | 89 // then it will recursively trigger fatal failures when this enters on the |
90 // UI thread. | 90 // UI thread. |
91 base::ThreadRestrictions::ScopedAllowIO allow_io; | 91 base::ThreadRestrictions::ScopedAllowIO allow_io; |
92 if (!ReadProcMaps(&proc_maps)) { | 92 if (!ReadProcMaps(&proc_maps)) { |
93 __android_log_write( | 93 __android_log_write( |
94 ANDROID_LOG_ERROR, "chromium", "Failed to read /proc/self/maps"); | 94 ANDROID_LOG_ERROR, ANDROID_LOG_TAG, "Failed to read /proc/self/maps"); |
95 } else if (!ParseProcMaps(proc_maps, ®ions)) { | 95 } else if (!ParseProcMaps(proc_maps, ®ions)) { |
96 __android_log_write( | 96 __android_log_write( |
97 ANDROID_LOG_ERROR, "chromium", "Failed to parse /proc/self/maps"); | 97 ANDROID_LOG_ERROR, ANDROID_LOG_TAG, "Failed to parse /proc/self/maps"); |
98 } | 98 } |
99 | 99 |
100 for (size_t i = 0; i < count_; ++i) { | 100 for (size_t i = 0; i < count_; ++i) { |
101 // Subtract one as return address of function may be in the next | 101 // Subtract one as return address of function may be in the next |
102 // function when a function is annotated as noreturn. | 102 // function when a function is annotated as noreturn. |
103 uintptr_t address = reinterpret_cast<uintptr_t>(trace_[i]) - 1; | 103 uintptr_t address = reinterpret_cast<uintptr_t>(trace_[i]) - 1; |
104 | 104 |
105 std::vector<MappedMemoryRegion>::iterator iter = regions.begin(); | 105 std::vector<MappedMemoryRegion>::iterator iter = regions.begin(); |
106 while (iter != regions.end()) { | 106 while (iter != regions.end()) { |
107 if (address >= iter->start && address < iter->end && | 107 if (address >= iter->start && address < iter->end && |
(...skipping 12 matching lines...) Expand all Loading... |
120 } else { | 120 } else { |
121 *os << "<unknown>"; | 121 *os << "<unknown>"; |
122 } | 122 } |
123 | 123 |
124 *os << "\n"; | 124 *os << "\n"; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 } // namespace debug | 128 } // namespace debug |
129 } // namespace base | 129 } // namespace base |
OLD | NEW |