| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" |
| 13 |
| 14 #include <vector> |
| 15 |
| 16 // A stacktrace can be helpful in debugging. For example, you can include a |
| 17 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you |
| 18 // can later see where the given object was created from. |
| 19 class StackTrace { |
| 20 public: |
| 21 // Create a stacktrace from the current location |
| 22 StackTrace(); |
| 23 // Get an array of instruction pointer values. |
| 24 // count: (output) the number of elements in the returned array |
| 25 const void *const *Addresses(size_t* count); |
| 26 // Print a backtrace to stderr |
| 27 void PrintBacktrace(); |
| 28 |
| 29 private: |
| 30 std::vector<void*> trace_; |
| 31 |
| 32 DISALLOW_EVIL_CONSTRUCTORS(StackTrace); |
| 33 }; |
| 34 |
| 12 class DebugUtil { | 35 class DebugUtil { |
| 13 public: | 36 public: |
| 14 // Starts the registered system-wide JIT debugger to attach it to specified | 37 // Starts the registered system-wide JIT debugger to attach it to specified |
| 15 // process. | 38 // process. |
| 16 static bool SpawnDebuggerOnProcess(unsigned process_id); | 39 static bool SpawnDebuggerOnProcess(unsigned process_id); |
| 17 | 40 |
| 18 // Waits wait_seconds seconds for a debugger to attach to the current process. | 41 // Waits wait_seconds seconds for a debugger to attach to the current process. |
| 19 // When silent is false, an exception is thrown when a debugger is detected. | 42 // When silent is false, an exception is thrown when a debugger is detected. |
| 20 static bool WaitForDebugger(int wait_seconds, bool silent); | 43 static bool WaitForDebugger(int wait_seconds, bool silent); |
| 21 | 44 |
| 22 // Are we running under a debugger? | 45 // Are we running under a debugger? |
| 23 static bool BeingDebugged(); | 46 static bool BeingDebugged(); |
| 24 | 47 |
| 25 // Break into the debugger, assumes a debugger is present. | 48 // Break into the debugger, assumes a debugger is present. |
| 26 static void BreakDebugger(); | 49 static void BreakDebugger(); |
| 27 }; | 50 }; |
| 28 | 51 |
| 29 #endif // BASE_DEBUG_UTIL_H_ | 52 #endif // BASE_DEBUG_UTIL_H_ |
| 30 | |
| OLD | NEW |