ipc/chromium/src/base/debug_util.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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
     3 // found in the LICENSE file.
     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
     7 // would like to yield (breakpoint) into the debugger.
     9 #ifndef BASE_DEBUG_UTIL_H_
    10 #define BASE_DEBUG_UTIL_H_
    12 #include <ostream>
    13 #include <vector>
    15 #include "base/basictypes.h"
    17 // 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
    19 // can later see where the given object was created from.
    20 class StackTrace {
    21  public:
    22   // Create a stacktrace from the current location
    23   StackTrace();
    24   // Get an array of instruction pointer values.
    25   //   count: (output) the number of elements in the returned array
    26   const void *const *Addresses(size_t* count);
    27   // Print a backtrace to stderr
    28   void PrintBacktrace();
    30   // Resolve backtrace to symbols and write to stream.
    31   void OutputToStream(std::ostream* os);
    33  private:
    34   std::vector<void*> trace_;
    36   DISALLOW_EVIL_CONSTRUCTORS(StackTrace);
    37 };
    39 class DebugUtil {
    40  public:
    41   // Starts the registered system-wide JIT debugger to attach it to specified
    42   // process.
    43   static bool SpawnDebuggerOnProcess(unsigned process_id);
    45   // Waits wait_seconds seconds for a debugger to attach to the current process.
    46   // When silent is false, an exception is thrown when a debugger is detected.
    47   static bool WaitForDebugger(int wait_seconds, bool silent);
    49   // Are we running under a debugger?
    50   // On OS X, the underlying mechanism doesn't work when the sandbox is enabled.
    51   // To get around this, this function caches its value.
    52   // WARNING: Because of this, on OS X, a call MUST be made to this function
    53   // BEFORE the sandbox is enabled.
    54   static bool BeingDebugged();
    56   // Break into the debugger, assumes a debugger is present.
    57   static void BreakDebugger();
    59 #if defined(OS_MACOSX)
    60   // On OS X, it can take a really long time for the OS Crash handler to
    61   // process a Chrome crash.  This translates into a long wait till the process
    62   // actually dies.
    63   // This method disables OS Crash reporting entireley.
    64   // TODO(playmobil): Remove this when we have Breakpad integration enabled -
    65   // see http://crbug.com/7652
    66   static void DisableOSCrashDumps();
    67 #endif  // defined(OS_MACOSX)
    68 };
    70 namespace mozilla {
    72 class EnvironmentLog
    73 {
    74 public:
    75   EnvironmentLog(const char* varname);
    76   ~EnvironmentLog();
    78   void print(const char* format, ...);
    80 private:
    81   std::string fname_;
    83   DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog);
    84 };
    86 } // namespace mozilla
    88 #endif  // BASE_DEBUG_UTIL_H_

mercurial