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 <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 | 13 |
14 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
15 #include <unistd.h> | 15 #include <unistd.h> |
16 #endif | 16 #endif |
17 | 17 |
18 #if defined(OS_WIN) | |
19 struct _EXCEPTION_POINTERS; | |
20 struct _CONTEXT; | |
21 #endif | |
22 | |
23 namespace base { | 18 namespace base { |
24 namespace debug { | 19 namespace debug { |
25 | 20 |
26 // Enables stack dump to console output on exception and signals. | 21 // Enables stack dump to console output on exception and signals. |
27 // When enabled, the process will quit immediately. This is meant to be used in | 22 // When enabled, the process will quit immediately. This is meant to be used in |
28 // unit_tests only! This is not thread-safe: only call from main thread. | 23 // unit_tests only! This is not thread-safe: only call from main thread. |
29 BASE_EXPORT bool EnableInProcessStackDumping(); | 24 BASE_EXPORT bool EnableInProcessStackDumping(); |
30 | 25 |
31 // A different version of EnableInProcessStackDumping that also works for | 26 // A different version of EnableInProcessStackDumping that also works for |
32 // sandboxed processes. For more details take a look at the description | 27 // sandboxed processes. For more details take a look at the description |
(...skipping 10 matching lines...) Expand all Loading... |
43 class BASE_EXPORT StackTrace { | 38 class BASE_EXPORT StackTrace { |
44 public: | 39 public: |
45 // Creates a stacktrace from the current location. | 40 // Creates a stacktrace from the current location. |
46 StackTrace(); | 41 StackTrace(); |
47 | 42 |
48 // Creates a stacktrace from an existing array of instruction | 43 // Creates a stacktrace from an existing array of instruction |
49 // pointers (such as returned by Addresses()). |count| will be | 44 // pointers (such as returned by Addresses()). |count| will be |
50 // trimmed to |kMaxTraces|. | 45 // trimmed to |kMaxTraces|. |
51 StackTrace(const void* const* trace, size_t count); | 46 StackTrace(const void* const* trace, size_t count); |
52 | 47 |
53 #if defined(OS_WIN) | |
54 // Creates a stacktrace for an exception. | |
55 // Note: this function will throw an import not found (StackWalk64) exception | |
56 // on system without dbghelp 5.1. | |
57 StackTrace(const _EXCEPTION_POINTERS* exception_pointers); | |
58 StackTrace(const _CONTEXT* context); | |
59 #endif | |
60 | |
61 // Copying and assignment are allowed with the default functions. | 48 // Copying and assignment are allowed with the default functions. |
62 | 49 |
63 ~StackTrace(); | 50 ~StackTrace(); |
64 | 51 |
65 // Gets an array of instruction pointer values. |*count| will be set to the | 52 // Gets an array of instruction pointer values. |*count| will be set to the |
66 // number of elements in the returned array. | 53 // number of elements in the returned array. |
67 const void* const* Addresses(size_t* count) const; | 54 const void* const* Addresses(size_t* count) const; |
68 | 55 |
69 // Prints the stack trace to stderr. | 56 // Prints the stack trace to stderr. |
70 void Print() const; | 57 void Print() const; |
71 | 58 |
72 #if !defined(__UCLIBC__) && !defined(FNL_MUSL) | 59 // Resolves backtrace to symbols and write to stream (if supported). |
73 // Resolves backtrace to symbols and write to stream. | |
74 void OutputToStream(std::ostream* os) const; | 60 void OutputToStream(std::ostream* os) const; |
75 #endif | |
76 | 61 |
77 // Resolves backtrace to symbols and returns as string. | 62 // Resolves backtrace to symbols and returns as string. |
78 std::string ToString() const; | 63 std::string ToString() const; |
79 | 64 |
80 private: | 65 private: |
81 #if defined(OS_WIN) | |
82 void InitTrace(_CONTEXT* context_record); | |
83 #endif | |
84 | |
85 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, | 66 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, |
86 // the sum of FramesToSkip and FramesToCapture must be less than 63, | 67 // the sum of FramesToSkip and FramesToCapture must be less than 63, |
87 // so set it to 62. Even if on POSIX it could be a larger value, it usually | 68 // so set it to 62. Even if on POSIX it could be a larger value, it usually |
88 // doesn't give much more information. | 69 // doesn't give much more information. |
89 static const int kMaxTraces = 62; | 70 static const int kMaxTraces = 62; |
90 | 71 |
91 void* trace_[kMaxTraces]; | 72 void* trace_[kMaxTraces]; |
92 | 73 |
93 // The number of valid frames in |trace_|. | 74 // The number of valid frames in |trace_|. |
94 size_t count_; | 75 size_t count_; |
(...skipping 14 matching lines...) Expand all Loading... |
109 int base, | 90 int base, |
110 size_t padding); | 91 size_t padding); |
111 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 92 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
112 | 93 |
113 } // namespace internal | 94 } // namespace internal |
114 | 95 |
115 } // namespace debug | 96 } // namespace debug |
116 } // namespace base | 97 } // namespace base |
117 | 98 |
118 #endif // BASE_DEBUG_STACK_TRACE_H_ | 99 #endif // BASE_DEBUG_STACK_TRACE_H_ |
OLD | NEW |