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> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 BASE_EXPORT bool EnableInProcessStackDumping(); | 46 BASE_EXPORT bool EnableInProcessStackDumping(); |
| 47 | 47 |
| 48 // A stacktrace can be helpful in debugging. For example, you can include a | 48 // A stacktrace can be helpful in debugging. For example, you can include a |
| 49 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you | 49 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you |
| 50 // can later see where the given object was created from. | 50 // can later see where the given object was created from. |
| 51 class BASE_EXPORT StackTrace { | 51 class BASE_EXPORT StackTrace { |
| 52 public: | 52 public: |
| 53 // Creates a stacktrace from the current location. | 53 // Creates a stacktrace from the current location. |
| 54 StackTrace(); | 54 StackTrace(); |
| 55 | 55 |
| 56 // Creates a stacktrace from the current location, of up to |count| entries. | |
| 57 // |count| will be trimmed to |kMaxTraces|. | |
|
dcheng
2017/01/28 01:00:33
Nit: to me, trimmed isn't an operation that applie
Wez
2017/01/29 04:25:01
Agreed; I just copied the wording from the constru
| |
| 58 explicit StackTrace(size_t count); | |
| 59 | |
| 56 // Creates a stacktrace from an existing array of instruction | 60 // Creates a stacktrace from an existing array of instruction |
| 57 // pointers (such as returned by Addresses()). |count| will be | 61 // pointers (such as returned by Addresses()). |count| will be |
| 58 // trimmed to |kMaxTraces|. | 62 // trimmed to |kMaxTraces|. |
| 59 StackTrace(const void* const* trace, size_t count); | 63 StackTrace(const void* const* trace, size_t count); |
| 60 | 64 |
| 61 #if defined(OS_WIN) | 65 #if defined(OS_WIN) |
| 62 // Creates a stacktrace for an exception. | 66 // Creates a stacktrace for an exception. |
| 63 // Note: this function will throw an import not found (StackWalk64) exception | 67 // Note: this function will throw an import not found (StackWalk64) exception |
| 64 // on system without dbghelp 5.1. | 68 // on system without dbghelp 5.1. |
| 65 StackTrace(_EXCEPTION_POINTERS* exception_pointers); | 69 StackTrace(_EXCEPTION_POINTERS* exception_pointers); |
| 66 StackTrace(const _CONTEXT* context); | 70 StackTrace(const _CONTEXT* context); |
| 67 #endif | 71 #endif |
| 68 | 72 |
| 69 // Copying and assignment are allowed with the default functions. | 73 // Copying and assignment are allowed with the default functions. |
| 70 | 74 |
| 71 ~StackTrace(); | |
| 72 | |
| 73 // Gets an array of instruction pointer values. |*count| will be set to the | 75 // Gets an array of instruction pointer values. |*count| will be set to the |
| 74 // number of elements in the returned array. | 76 // number of elements in the returned array. |
| 75 const void* const* Addresses(size_t* count) const; | 77 const void* const* Addresses(size_t* count) const; |
| 76 | 78 |
| 77 // Prints the stack trace to stderr. | 79 // Prints the stack trace to stderr. |
| 78 void Print() const; | 80 void Print() const; |
| 79 | 81 |
| 80 #if !defined(__UCLIBC__) | 82 #if !defined(__UCLIBC__) |
| 81 // Resolves backtrace to symbols and write to stream. | 83 // Resolves backtrace to symbols and write to stream. |
| 82 void OutputToStream(std::ostream* os) const; | 84 void OutputToStream(std::ostream* os) const; |
| 83 #endif | 85 #endif |
| 84 | 86 |
| 85 // Resolves backtrace to symbols and returns as string. | 87 // Resolves backtrace to symbols and returns as string. |
| 86 std::string ToString() const; | 88 std::string ToString() const; |
| 87 | 89 |
| 88 private: | 90 private: |
| 89 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
| 90 void InitTrace(const _CONTEXT* context_record); | 92 void InitTrace(const _CONTEXT* context_record); |
| 91 #endif | 93 #endif |
| 92 | 94 |
| 95 protected: | |
|
dcheng
2017/01/28 01:00:33
Why protected?
Wez
2017/01/29 04:25:01
Oh, strange; no idea where that came from :-/
| |
| 93 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, | 96 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, |
| 94 // the sum of FramesToSkip and FramesToCapture must be less than 63, | 97 // the sum of FramesToSkip and FramesToCapture must be less than 63, |
| 95 // so set it to 62. Even if on POSIX it could be a larger value, it usually | 98 // so set it to 62. Even if on POSIX it could be a larger value, it usually |
| 96 // doesn't give much more information. | 99 // doesn't give much more information. |
| 97 static const int kMaxTraces = 62; | 100 static const int kMaxTraces = 62; |
| 98 | 101 |
| 99 void* trace_[kMaxTraces]; | 102 void* trace_[kMaxTraces]; |
| 100 | 103 |
| 101 // The number of valid frames in |trace_|. | 104 // The number of valid frames in |trace_|. |
| 102 size_t count_; | 105 size_t count_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 int base, | 185 int base, |
| 183 size_t padding); | 186 size_t padding); |
| 184 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 187 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
| 185 | 188 |
| 186 } // namespace internal | 189 } // namespace internal |
| 187 | 190 |
| 188 } // namespace debug | 191 } // namespace debug |
| 189 } // namespace base | 192 } // namespace base |
| 190 | 193 |
| 191 #endif // BASE_DEBUG_STACK_TRACE_H_ | 194 #endif // BASE_DEBUG_STACK_TRACE_H_ |
| OLD | NEW |