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