toolkit/crashreporter/nsExceptionHandler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/nsExceptionHandler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,221 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsExceptionHandler_h__
    1.10 +#define nsExceptionHandler_h__
    1.11 +
    1.12 +#include <stddef.h>
    1.13 +#include <stdint.h>
    1.14 +#include "nsError.h"
    1.15 +#include "nsStringGlue.h"
    1.16 +
    1.17 +#if defined(XP_WIN32)
    1.18 +#ifdef WIN32_LEAN_AND_MEAN
    1.19 +#undef WIN32_LEAN_AND_MEAN
    1.20 +#endif
    1.21 +#include <windows.h>
    1.22 +#endif
    1.23 +
    1.24 +#if defined(XP_MACOSX)
    1.25 +#include <mach/mach.h>
    1.26 +#endif
    1.27 +
    1.28 +#if defined(XP_LINUX)
    1.29 +#include <signal.h>
    1.30 +#endif
    1.31 +
    1.32 +class nsIFile;
    1.33 +template<class KeyClass, class DataType> class nsDataHashtable;
    1.34 +class nsCStringHashKey;
    1.35 +
    1.36 +namespace CrashReporter {
    1.37 +nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force=false);
    1.38 +nsresult UnsetExceptionHandler();
    1.39 +
    1.40 +/**
    1.41 + * Tell the crash reporter to recalculate where crash events files should go.
    1.42 + *
    1.43 + * This should be called during crash reporter initialization and when a
    1.44 + * profile is activated or deactivated.
    1.45 + */
    1.46 +void UpdateCrashEventsDir();
    1.47 +
    1.48 +/**
    1.49 + * Get the path where crash event files should be written.
    1.50 + */
    1.51 +bool     GetCrashEventsDir(nsAString& aPath);
    1.52 +
    1.53 +bool     GetEnabled();
    1.54 +bool     GetServerURL(nsACString& aServerURL);
    1.55 +nsresult SetServerURL(const nsACString& aServerURL);
    1.56 +bool     GetMinidumpPath(nsAString& aPath);
    1.57 +nsresult SetMinidumpPath(const nsAString& aPath);
    1.58 +
    1.59 +
    1.60 +// AnnotateCrashReport and AppendAppNotesToCrashReport may be called from any
    1.61 +// thread in a chrome process, but may only be called from the main thread in
    1.62 +// a content process.
    1.63 +nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
    1.64 +nsresult AppendAppNotesToCrashReport(const nsACString& data);
    1.65 +
    1.66 +void AnnotateOOMAllocationSize(size_t size);
    1.67 +nsresult SetGarbageCollecting(bool collecting);
    1.68 +void SetEventloopNestingLevel(uint32_t level);
    1.69 +
    1.70 +nsresult SetRestartArgs(int argc, char** argv);
    1.71 +nsresult SetupExtraData(nsIFile* aAppDataDirectory,
    1.72 +                        const nsACString& aBuildID);
    1.73 +bool GetLastRunCrashID(nsAString& id);
    1.74 +
    1.75 +// Registers an additional memory region to be included in the minidump
    1.76 +nsresult RegisterAppMemory(void* ptr, size_t length);
    1.77 +nsresult UnregisterAppMemory(void* ptr);
    1.78 +
    1.79 +// Functions for working with minidumps and .extras
    1.80 +typedef nsDataHashtable<nsCStringHashKey, nsCString> AnnotationTable;
    1.81 +
    1.82 +bool GetMinidumpForID(const nsAString& id, nsIFile** minidump);
    1.83 +bool GetIDFromMinidump(nsIFile* minidump, nsAString& id);
    1.84 +bool GetExtraFileForID(const nsAString& id, nsIFile** extraFile);
    1.85 +bool GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile);
    1.86 +bool AppendExtraData(const nsAString& id, const AnnotationTable& data);
    1.87 +bool AppendExtraData(nsIFile* extraFile, const AnnotationTable& data);
    1.88 +void RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump,
    1.89 +                                  const nsACString& name);
    1.90 +
    1.91 +#ifdef XP_WIN32
    1.92 +  nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo);
    1.93 +#endif
    1.94 +#ifdef XP_LINUX
    1.95 +  bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc);
    1.96 +#endif
    1.97 +#ifdef XP_MACOSX
    1.98 +  nsresult AppendObjCExceptionInfoToAppNotes(void *inException);
    1.99 +#endif
   1.100 +nsresult GetSubmitReports(bool* aSubmitReport);
   1.101 +nsresult SetSubmitReports(bool aSubmitReport);
   1.102 +
   1.103 +// Out-of-process crash reporter API.
   1.104 +
   1.105 +// Initializes out-of-process crash reporting. This method must be called
   1.106 +// before the platform-specifi notificationpipe APIs are called.
   1.107 +void OOPInit();
   1.108 +
   1.109 +// Return true if a dump was found for |childPid|, and return the
   1.110 +// path in |dump|.  The caller owns the last reference to |dump| if it
   1.111 +// is non-nullptr. The sequence parameter will be filled with an ordinal
   1.112 +// indicating which remote process crashed first.
   1.113 +bool TakeMinidumpForChild(uint32_t childPid,
   1.114 +                          nsIFile** dump,
   1.115 +                          uint32_t* aSequence = nullptr);
   1.116 +
   1.117 +#if defined(XP_WIN)
   1.118 +typedef HANDLE ProcessHandle;
   1.119 +typedef DWORD ThreadId;
   1.120 +#elif defined(XP_MACOSX)
   1.121 +typedef task_t ProcessHandle;
   1.122 +typedef mach_port_t ThreadId;
   1.123 +#else
   1.124 +typedef int ProcessHandle;
   1.125 +typedef int ThreadId;
   1.126 +#endif
   1.127 +
   1.128 +// Return the current thread's ID.
   1.129 +//
   1.130 +// XXX: this is a somewhat out-of-place interface to expose through
   1.131 +// crashreporter, but it takes significant work to call sys_gettid()
   1.132 +// correctly on Linux and breakpad has already jumped through those
   1.133 +// hoops for us.
   1.134 +ThreadId CurrentThreadId();
   1.135 +
   1.136 +// Create a hang report with two minidumps that are snapshots of the state
   1.137 +// of this parent process and |childPid|. The "main" minidump will be the
   1.138 +// child process, and this parent process will have the -browser extension.
   1.139 +//
   1.140 +// Returns true on success. If this function fails, it will attempt to delete
   1.141 +// any files that were created.
   1.142 +//
   1.143 +// The .extra information created will not include an additional_minidumps
   1.144 +// annotation: the caller should annotate additional_minidumps with
   1.145 +// at least "browser" and perhaps other minidumps attached to this report.
   1.146 +bool CreatePairedMinidumps(ProcessHandle childPid,
   1.147 +                           ThreadId childBlamedThread,
   1.148 +                           nsIFile** childDump);
   1.149 +
   1.150 +// Create an additional minidump for a child of a process which already has
   1.151 +// a minidump (|parentMinidump|).
   1.152 +// The resulting dump will get the id of the parent and use the |name| as
   1.153 +// an extension.
   1.154 +bool CreateAdditionalChildMinidump(ProcessHandle childPid,
   1.155 +                                   ThreadId childBlamedThread,
   1.156 +                                   nsIFile* parentMinidump,
   1.157 +                                   const nsACString& name);
   1.158 +
   1.159 +#  if defined(XP_WIN32) || defined(XP_MACOSX)
   1.160 +// Parent-side API for children
   1.161 +const char* GetChildNotificationPipe();
   1.162 +
   1.163 +#ifdef MOZ_CRASHREPORTER_INJECTOR
   1.164 +// Inject a crash report client into an arbitrary process, and inform the
   1.165 +// callback object when it crashes. Parent process only.
   1.166 +
   1.167 +class InjectorCrashCallback
   1.168 +{
   1.169 +public:
   1.170 +  InjectorCrashCallback() { }
   1.171 +
   1.172 +  /**
   1.173 +   * Inform the callback of a crash. The client code should call
   1.174 +   * TakeMinidumpForChild to remove it from the PID mapping table.
   1.175 +   *
   1.176 +   * The callback will not be fired if the client has already called
   1.177 +   * TakeMinidumpForChild for this process ID.
   1.178 +   */
   1.179 +  virtual void OnCrash(DWORD processID) = 0;
   1.180 +};
   1.181 +
   1.182 +// This method implies OOPInit
   1.183 +void InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb);
   1.184 +void UnregisterInjectorCallback(DWORD processID);
   1.185 +#endif
   1.186 +
   1.187 +// Child-side API
   1.188 +bool SetRemoteExceptionHandler(const nsACString& crashPipe);
   1.189 +
   1.190 +#  elif defined(XP_LINUX)
   1.191 +// Parent-side API for children
   1.192 +
   1.193 +// Set the outparams for crash reporter server's fd (|childCrashFd|)
   1.194 +// and the magic fd number it should be remapped to
   1.195 +// (|childCrashRemapFd|) before exec() in the child process.
   1.196 +// |SetRemoteExceptionHandler()| in the child process expects to find
   1.197 +// the server at |childCrashRemapFd|.  Return true iff successful.
   1.198 +//
   1.199 +// If crash reporting is disabled, both outparams will be set to -1
   1.200 +// and |true| will be returned.
   1.201 +bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd);
   1.202 +
   1.203 +// Child-side API
   1.204 +bool SetRemoteExceptionHandler();
   1.205 +
   1.206 +#endif  // XP_WIN32
   1.207 +
   1.208 +bool UnsetRemoteExceptionHandler();
   1.209 +
   1.210 +#if defined(MOZ_WIDGET_ANDROID)
   1.211 +// Android builds use a custom library loader, so /proc/<pid>/maps
   1.212 +// will just show anonymous mappings for all the non-system
   1.213 +// shared libraries. This API is to work around that by providing
   1.214 +// info about the shared libraries that are mapped into these anonymous
   1.215 +// mappings.
   1.216 +void AddLibraryMapping(const char* library_name,
   1.217 +                       uintptr_t   start_address,
   1.218 +                       size_t      mapping_length,
   1.219 +                       size_t      file_offset);
   1.220 +
   1.221 +#endif
   1.222 +}
   1.223 +
   1.224 +#endif /* nsExceptionHandler_h__ */

mercurial