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.

michael@0 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 // This is a cross platform interface for helper functions related to debuggers.
michael@0 6 // You should use this to test if you're running under a debugger, and if you
michael@0 7 // would like to yield (breakpoint) into the debugger.
michael@0 8
michael@0 9 #ifndef BASE_DEBUG_UTIL_H_
michael@0 10 #define BASE_DEBUG_UTIL_H_
michael@0 11
michael@0 12 #include <ostream>
michael@0 13 #include <vector>
michael@0 14
michael@0 15 #include "base/basictypes.h"
michael@0 16
michael@0 17 // A stacktrace can be helpful in debugging. For example, you can include a
michael@0 18 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you
michael@0 19 // can later see where the given object was created from.
michael@0 20 class StackTrace {
michael@0 21 public:
michael@0 22 // Create a stacktrace from the current location
michael@0 23 StackTrace();
michael@0 24 // Get an array of instruction pointer values.
michael@0 25 // count: (output) the number of elements in the returned array
michael@0 26 const void *const *Addresses(size_t* count);
michael@0 27 // Print a backtrace to stderr
michael@0 28 void PrintBacktrace();
michael@0 29
michael@0 30 // Resolve backtrace to symbols and write to stream.
michael@0 31 void OutputToStream(std::ostream* os);
michael@0 32
michael@0 33 private:
michael@0 34 std::vector<void*> trace_;
michael@0 35
michael@0 36 DISALLOW_EVIL_CONSTRUCTORS(StackTrace);
michael@0 37 };
michael@0 38
michael@0 39 class DebugUtil {
michael@0 40 public:
michael@0 41 // Starts the registered system-wide JIT debugger to attach it to specified
michael@0 42 // process.
michael@0 43 static bool SpawnDebuggerOnProcess(unsigned process_id);
michael@0 44
michael@0 45 // Waits wait_seconds seconds for a debugger to attach to the current process.
michael@0 46 // When silent is false, an exception is thrown when a debugger is detected.
michael@0 47 static bool WaitForDebugger(int wait_seconds, bool silent);
michael@0 48
michael@0 49 // Are we running under a debugger?
michael@0 50 // On OS X, the underlying mechanism doesn't work when the sandbox is enabled.
michael@0 51 // To get around this, this function caches its value.
michael@0 52 // WARNING: Because of this, on OS X, a call MUST be made to this function
michael@0 53 // BEFORE the sandbox is enabled.
michael@0 54 static bool BeingDebugged();
michael@0 55
michael@0 56 // Break into the debugger, assumes a debugger is present.
michael@0 57 static void BreakDebugger();
michael@0 58
michael@0 59 #if defined(OS_MACOSX)
michael@0 60 // On OS X, it can take a really long time for the OS Crash handler to
michael@0 61 // process a Chrome crash. This translates into a long wait till the process
michael@0 62 // actually dies.
michael@0 63 // This method disables OS Crash reporting entireley.
michael@0 64 // TODO(playmobil): Remove this when we have Breakpad integration enabled -
michael@0 65 // see http://crbug.com/7652
michael@0 66 static void DisableOSCrashDumps();
michael@0 67 #endif // defined(OS_MACOSX)
michael@0 68 };
michael@0 69
michael@0 70 namespace mozilla {
michael@0 71
michael@0 72 class EnvironmentLog
michael@0 73 {
michael@0 74 public:
michael@0 75 EnvironmentLog(const char* varname);
michael@0 76 ~EnvironmentLog();
michael@0 77
michael@0 78 void print(const char* format, ...);
michael@0 79
michael@0 80 private:
michael@0 81 std::string fname_;
michael@0 82
michael@0 83 DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog);
michael@0 84 };
michael@0 85
michael@0 86 } // namespace mozilla
michael@0 87
michael@0 88 #endif // BASE_DEBUG_UTIL_H_

mercurial