OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // This is a cross platform interface for helper functions related to debuggers. | 5 // This is a cross platform interface for helper functions related to debuggers. |
6 // You should use this to test if you're running under a debugger, and if you | 6 // You should use this to test if you're running under a debugger, and if you |
7 // would like to yield (breakpoint) into the debugger. | 7 // would like to yield (breakpoint) into the debugger. |
8 | 8 |
9 #ifndef BASE_DEBUG_UTIL_H_ | 9 #ifndef BASE_DEBUG_UTIL_H_ |
10 #define BASE_DEBUG_UTIL_H_ | 10 #define BASE_DEBUG_UTIL_H_ |
11 | 11 |
12 #include <iosfwd> | 12 #include <iosfwd> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 | 16 |
| 17 #if defined(OS_WIN) |
| 18 struct _EXCEPTION_POINTERS; |
| 19 #endif |
| 20 |
17 // A stacktrace can be helpful in debugging. For example, you can include a | 21 // A stacktrace can be helpful in debugging. For example, you can include a |
18 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you | 22 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you |
19 // can later see where the given object was created from. | 23 // can later see where the given object was created from. |
20 class StackTrace { | 24 class StackTrace { |
21 public: | 25 public: |
22 // Create a stacktrace from the current location | 26 // Creates a stacktrace from the current location |
23 StackTrace(); | 27 StackTrace(); |
24 // Get an array of instruction pointer values. | 28 #if defined(OS_WIN) |
| 29 // Creates a stacktrace for an exception. |
| 30 // Note: this function will throw an import not found (StackWalk64) exception |
| 31 // on system without dbghelp 5.1. |
| 32 StackTrace(_EXCEPTION_POINTERS* exception_pointers); |
| 33 #endif |
| 34 // Gets an array of instruction pointer values. |
25 // count: (output) the number of elements in the returned array | 35 // count: (output) the number of elements in the returned array |
26 const void *const *Addresses(size_t* count); | 36 const void *const *Addresses(size_t* count); |
27 // Print a backtrace to stderr | 37 // Prints a backtrace to stderr |
28 void PrintBacktrace(); | 38 void PrintBacktrace(); |
29 | 39 |
30 // Resolve backtrace to symbols and write to stream. | 40 // Resolves backtrace to symbols and write to stream. |
31 void OutputToStream(std::ostream* os); | 41 void OutputToStream(std::ostream* os); |
32 | 42 |
33 private: | 43 private: |
34 std::vector<void*> trace_; | 44 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, |
| 45 // the sum of FramesToSkip and FramesToCapture must be less than 63, |
| 46 // so set it to 62. Even if on POSIX it could be a larger value, it usually |
| 47 // doesn't give much more information. |
| 48 static const int MAX_TRACES = 62; |
| 49 void* trace_[MAX_TRACES]; |
| 50 int count_; |
35 | 51 |
36 DISALLOW_EVIL_CONSTRUCTORS(StackTrace); | 52 DISALLOW_EVIL_CONSTRUCTORS(StackTrace); |
37 }; | 53 }; |
38 | 54 |
39 class DebugUtil { | 55 class DebugUtil { |
40 public: | 56 public: |
41 // Starts the registered system-wide JIT debugger to attach it to specified | 57 // Starts the registered system-wide JIT debugger to attach it to specified |
42 // process. | 58 // process. |
43 static bool SpawnDebuggerOnProcess(unsigned process_id); | 59 static bool SpawnDebuggerOnProcess(unsigned process_id); |
44 | 60 |
(...skipping 16 matching lines...) Expand all Loading... |
61 // process a Chrome crash. This translates into a long wait till the process | 77 // process a Chrome crash. This translates into a long wait till the process |
62 // actually dies. | 78 // actually dies. |
63 // This method disables OS Crash reporting entireley. | 79 // This method disables OS Crash reporting entireley. |
64 // TODO(playmobil): Remove this when we have Breakpad integration enabled - | 80 // TODO(playmobil): Remove this when we have Breakpad integration enabled - |
65 // see http://crbug.com/7652 | 81 // see http://crbug.com/7652 |
66 static void DisableOSCrashDumps(); | 82 static void DisableOSCrashDumps(); |
67 #endif // defined(OS_MACOSX) | 83 #endif // defined(OS_MACOSX) |
68 }; | 84 }; |
69 | 85 |
70 #endif // BASE_DEBUG_UTIL_H_ | 86 #endif // BASE_DEBUG_UTIL_H_ |
OLD | NEW |