OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
Jakob Kummerow
2016/08/18 09:36:13
If this is copied from Chromium, it should probabl
Michael Starzinger
2016/08/18 10:39:18
+1. Applies to all five stack-trace files I suppos
rmcilroy
2016/08/18 11:39:48
Thanks. I changed this since presumbit hooks compl
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_DEBUG_STACK_TRACE_H_ | |
Michael Starzinger
2016/08/18 10:39:19
nit: V8_BASE_DEBUG_STACK_TRACE_H_
rmcilroy
2016/08/18 11:39:48
Done.
| |
6 #define BASE_DEBUG_STACK_TRACE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <iosfwd> | |
11 #include <string> | |
12 | |
13 #include "src/base/build_config.h" | |
14 | |
15 #if V8_OS_POSIX | |
16 #include <unistd.h> | |
17 #endif | |
18 | |
19 #if V8_OS_WIN | |
20 struct _EXCEPTION_POINTERS; | |
21 struct _CONTEXT; | |
22 #endif | |
23 | |
24 namespace v8 { | |
25 namespace base { | |
26 namespace debug { | |
27 | |
28 // Enables stack dump to console output on exception and signals. | |
29 // When enabled, the process will quit immediately. This is meant to be used in | |
30 // tests only! | |
31 bool EnableInProcessStackDumping(); | |
32 void DisableSignalStackDump(); | |
33 | |
34 // A stacktrace can be helpful in debugging. For example, you can include a | |
35 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you | |
36 // can later see where the given object was created from. | |
37 class StackTrace { | |
38 public: | |
39 // Creates a stacktrace from the current location. | |
40 StackTrace(); | |
41 | |
42 // Creates a stacktrace from an existing array of instruction | |
43 // pointers (such as returned by Addresses()). |count| will be | |
44 // trimmed to |kMaxTraces|. | |
45 StackTrace(const void* const* trace, size_t count); | |
46 | |
47 #if V8_OS_WIN | |
48 // Creates a stacktrace for an exception. | |
49 // Note: this function will throw an import not found (StackWalk64) exception | |
50 // on system without dbghelp 5.1. | |
51 explicit StackTrace(_EXCEPTION_POINTERS* exception_pointers); | |
52 explicit StackTrace(const _CONTEXT* context); | |
53 #endif | |
54 | |
55 // Copying and assignment are allowed with the default functions. | |
56 | |
57 ~StackTrace(); | |
58 | |
59 // Gets an array of instruction pointer values. |*count| will be set to the | |
60 // number of elements in the returned array. | |
61 const void* const* Addresses(size_t* count) const; | |
62 | |
63 // Prints the stack trace to stderr. | |
64 void Print() const; | |
65 | |
66 // Resolves backtrace to symbols and write to stream. | |
67 void OutputToStream(std::ostream* os) const; | |
68 | |
69 // Resolves backtrace to symbols and returns as string. | |
70 std::string ToString() const; | |
71 | |
72 private: | |
73 #if V8_OS_WIN | |
74 void InitTrace(const _CONTEXT* context_record); | |
75 #endif | |
76 | |
77 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, | |
78 // the sum of FramesToSkip and FramesToCapture must be less than 63, | |
79 // so set it to 62. Even if on POSIX it could be a larger value, it usually | |
80 // doesn't give much more information. | |
81 static const int kMaxTraces = 62; | |
82 | |
83 void* trace_[kMaxTraces]; | |
84 | |
85 // The number of valid frames in |trace_|. | |
86 size_t count_; | |
87 }; | |
88 | |
89 } // namespace debug | |
90 } // namespace base | |
91 } // namespace v8 | |
92 | |
93 #endif // BASE_DEBUG_STACK_TRACE_H_ | |
Michael Starzinger
2016/08/18 10:39:18
nit: V8_BASE_DEBUG_STACK_TRACE_H_
rmcilroy
2016/08/18 11:39:48
Done.
| |
OLD | NEW |