1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/debug_util.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +// This is a cross platform interface for helper functions related to debuggers. 1.9 +// You should use this to test if you're running under a debugger, and if you 1.10 +// would like to yield (breakpoint) into the debugger. 1.11 + 1.12 +#ifndef BASE_DEBUG_UTIL_H_ 1.13 +#define BASE_DEBUG_UTIL_H_ 1.14 + 1.15 +#include <ostream> 1.16 +#include <vector> 1.17 + 1.18 +#include "base/basictypes.h" 1.19 + 1.20 +// A stacktrace can be helpful in debugging. For example, you can include a 1.21 +// stacktrace member in a object (probably around #ifndef NDEBUG) so that you 1.22 +// can later see where the given object was created from. 1.23 +class StackTrace { 1.24 + public: 1.25 + // Create a stacktrace from the current location 1.26 + StackTrace(); 1.27 + // Get an array of instruction pointer values. 1.28 + // count: (output) the number of elements in the returned array 1.29 + const void *const *Addresses(size_t* count); 1.30 + // Print a backtrace to stderr 1.31 + void PrintBacktrace(); 1.32 + 1.33 + // Resolve backtrace to symbols and write to stream. 1.34 + void OutputToStream(std::ostream* os); 1.35 + 1.36 + private: 1.37 + std::vector<void*> trace_; 1.38 + 1.39 + DISALLOW_EVIL_CONSTRUCTORS(StackTrace); 1.40 +}; 1.41 + 1.42 +class DebugUtil { 1.43 + public: 1.44 + // Starts the registered system-wide JIT debugger to attach it to specified 1.45 + // process. 1.46 + static bool SpawnDebuggerOnProcess(unsigned process_id); 1.47 + 1.48 + // Waits wait_seconds seconds for a debugger to attach to the current process. 1.49 + // When silent is false, an exception is thrown when a debugger is detected. 1.50 + static bool WaitForDebugger(int wait_seconds, bool silent); 1.51 + 1.52 + // Are we running under a debugger? 1.53 + // On OS X, the underlying mechanism doesn't work when the sandbox is enabled. 1.54 + // To get around this, this function caches its value. 1.55 + // WARNING: Because of this, on OS X, a call MUST be made to this function 1.56 + // BEFORE the sandbox is enabled. 1.57 + static bool BeingDebugged(); 1.58 + 1.59 + // Break into the debugger, assumes a debugger is present. 1.60 + static void BreakDebugger(); 1.61 + 1.62 +#if defined(OS_MACOSX) 1.63 + // On OS X, it can take a really long time for the OS Crash handler to 1.64 + // process a Chrome crash. This translates into a long wait till the process 1.65 + // actually dies. 1.66 + // This method disables OS Crash reporting entireley. 1.67 + // TODO(playmobil): Remove this when we have Breakpad integration enabled - 1.68 + // see http://crbug.com/7652 1.69 + static void DisableOSCrashDumps(); 1.70 +#endif // defined(OS_MACOSX) 1.71 +}; 1.72 + 1.73 +namespace mozilla { 1.74 + 1.75 +class EnvironmentLog 1.76 +{ 1.77 +public: 1.78 + EnvironmentLog(const char* varname); 1.79 + ~EnvironmentLog(); 1.80 + 1.81 + void print(const char* format, ...); 1.82 + 1.83 +private: 1.84 + std::string fname_; 1.85 + 1.86 + DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog); 1.87 +}; 1.88 + 1.89 +} // namespace mozilla 1.90 + 1.91 +#endif // BASE_DEBUG_UTIL_H_