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 #ifndef BASE_DEBUG_STACK_TRACE_H_ | 5 #ifndef BASE_DEBUG_STACK_TRACE_H_ |
| 6 #define BASE_DEBUG_STACK_TRACE_H_ | 6 #define BASE_DEBUG_STACK_TRACE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iosfwd> | 10 #include <iosfwd> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 | 16 |
| 17 #if defined(OS_POSIX) | 17 #if defined(OS_POSIX) |
| 18 #include <unistd.h> | 18 #include <unistd.h> |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 22 struct _EXCEPTION_POINTERS; | 22 struct _EXCEPTION_POINTERS; |
| 23 struct _CONTEXT; | 23 struct _CONTEXT; |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_POSIX) && ( \ | 26 // TODO(699863): Clean up HAVE_TRACE_STACK_FRAME_POINTERS. |
| 27 defined(__i386__) || defined(__x86_64__) || \ | 27 #if (defined(OS_POSIX) && (defined(__i386__) || defined(__x86_64__) || \ |
| 28 (defined(__arm__) && !defined(__thumb__))) | 28 (defined(__arm__) && !defined(__thumb__)))) || \ |
| 29 defined(OS_WIN) | |
|
dcheng
2017/03/13 02:11:21
Nit: this condition is getting pretty hard to read
Wez
2017/03/14 05:22:39
Done, although I'm keeping the TODO because I woul
| |
| 29 #define HAVE_TRACE_STACK_FRAME_POINTERS 1 | 30 #define HAVE_TRACE_STACK_FRAME_POINTERS 1 |
| 30 #else | 31 #else |
| 31 #define HAVE_TRACE_STACK_FRAME_POINTERS 0 | 32 #define HAVE_TRACE_STACK_FRAME_POINTERS 0 |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 namespace base { | 35 namespace base { |
| 35 namespace debug { | 36 namespace debug { |
| 36 | 37 |
| 37 // Enables stack dump to console output on exception and signals. | 38 // Enables stack dump to console output on exception and signals. |
| 38 // When enabled, the process will quit immediately. This is meant to be used in | 39 // When enabled, the process will quit immediately. This is meant to be used in |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 // but not for release builds (although there are some exceptions). | 116 // but not for release builds (although there are some exceptions). |
| 116 // | 117 // |
| 117 // Writes at most |max_depth| frames (instruction pointers) into |out_trace| | 118 // Writes at most |max_depth| frames (instruction pointers) into |out_trace| |
| 118 // after skipping |skip_initial| frames. Note that the function itself is not | 119 // after skipping |skip_initial| frames. Note that the function itself is not |
| 119 // added to the trace so |skip_initial| should be 0 in most cases. | 120 // added to the trace so |skip_initial| should be 0 in most cases. |
| 120 // Returns number of frames written. | 121 // Returns number of frames written. |
| 121 BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace, | 122 BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace, |
| 122 size_t max_depth, | 123 size_t max_depth, |
| 123 size_t skip_initial); | 124 size_t skip_initial); |
| 124 | 125 |
| 126 #if !defined(OS_WIN) | |
| 125 // Links stack frame |fp| to |parent_fp|, so that during stack unwinding | 127 // Links stack frame |fp| to |parent_fp|, so that during stack unwinding |
| 126 // TraceStackFramePointers() visits |parent_fp| after visiting |fp|. | 128 // TraceStackFramePointers() visits |parent_fp| after visiting |fp|. |
| 127 // Both frame pointers must come from __builtin_frame_address(). | 129 // Both frame pointers must come from __builtin_frame_address(). |
| 128 // Destructor restores original linkage of |fp| to avoid corrupting caller's | 130 // Destructor restores original linkage of |fp| to avoid corrupting caller's |
| 129 // frame register on return. | 131 // frame register on return. |
| 130 // | 132 // |
| 131 // This class can be used to repair broken stack frame chain in cases | 133 // This class can be used to repair broken stack frame chain in cases |
| 132 // when execution flow goes into code built without frame pointers: | 134 // when execution flow goes into code built without frame pointers: |
| 133 // | 135 // |
| 134 // void DoWork() { | 136 // void DoWork() { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 164 ScopedStackFrameLinker(void* fp, void* parent_fp); | 166 ScopedStackFrameLinker(void* fp, void* parent_fp); |
| 165 ~ScopedStackFrameLinker(); | 167 ~ScopedStackFrameLinker(); |
| 166 | 168 |
| 167 private: | 169 private: |
| 168 void* fp_; | 170 void* fp_; |
| 169 void* parent_fp_; | 171 void* parent_fp_; |
| 170 void* original_parent_fp_; | 172 void* original_parent_fp_; |
| 171 | 173 |
| 172 DISALLOW_COPY_AND_ASSIGN(ScopedStackFrameLinker); | 174 DISALLOW_COPY_AND_ASSIGN(ScopedStackFrameLinker); |
| 173 }; | 175 }; |
| 176 #endif // !defined(OS_WIN) | |
| 174 | 177 |
| 175 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 178 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
| 176 | 179 |
| 177 namespace internal { | 180 namespace internal { |
| 178 | 181 |
| 179 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 182 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 180 // POSIX doesn't define any async-signal safe function for converting | 183 // POSIX doesn't define any async-signal safe function for converting |
| 181 // an integer to ASCII. We'll have to define our own version. | 184 // an integer to ASCII. We'll have to define our own version. |
| 182 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the | 185 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the |
| 183 // conversion was successful or NULL otherwise. It never writes more than "sz" | 186 // conversion was successful or NULL otherwise. It never writes more than "sz" |
| 184 // bytes. Output will be truncated as needed, and a NUL character is always | 187 // bytes. Output will be truncated as needed, and a NUL character is always |
| 185 // appended. | 188 // appended. |
| 186 BASE_EXPORT char *itoa_r(intptr_t i, | 189 BASE_EXPORT char *itoa_r(intptr_t i, |
| 187 char *buf, | 190 char *buf, |
| 188 size_t sz, | 191 size_t sz, |
| 189 int base, | 192 int base, |
| 190 size_t padding); | 193 size_t padding); |
| 191 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 194 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
| 192 | 195 |
| 193 } // namespace internal | 196 } // namespace internal |
| 194 | 197 |
| 195 } // namespace debug | 198 } // namespace debug |
| 196 } // namespace base | 199 } // namespace base |
| 197 | 200 |
| 198 #endif // BASE_DEBUG_STACK_TRACE_H_ | 201 #endif // BASE_DEBUG_STACK_TRACE_H_ |
| OLD | NEW |