2007-07-25 05:05:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2007-08-08 19:19:57 +04:00
|
|
|
#ifndef nsExceptionHandler_h__
|
|
|
|
#define nsExceptionHandler_h__
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2013-09-22 07:04:10 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "nsError.h"
|
2007-07-25 05:05:54 +04:00
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
2008-02-09 05:40:47 +03:00
|
|
|
#if defined(XP_WIN32)
|
|
|
|
#ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#endif
|
|
|
|
|
2014-02-05 22:29:51 +04:00
|
|
|
#if defined(XP_LINUX)
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2013-09-22 07:04:10 +04:00
|
|
|
class nsIFile;
|
|
|
|
template<class KeyClass, class DataType> class nsDataHashtable;
|
|
|
|
class nsCStringHashKey;
|
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
namespace CrashReporter {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force=false);
|
2007-07-25 05:05:55 +04:00
|
|
|
nsresult UnsetExceptionHandler();
|
2014-02-19 03:58:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the crash reporter to recalculate where crash events files should go.
|
2014-05-06 23:48:40 +04:00
|
|
|
* SetCrashEventsDir is used before XPCOM is initialized from the startup
|
|
|
|
* code.
|
2014-02-19 03:58:03 +04:00
|
|
|
*
|
2014-05-06 23:48:40 +04:00
|
|
|
* UpdateCrashEventsDir uses the directory service to re-set the
|
|
|
|
* crash event directory based on the current profile.
|
|
|
|
*
|
|
|
|
* 1. If environment variable is present, use it. We don't expect
|
|
|
|
* the environment variable except for tests and other atypical setups.
|
|
|
|
* 2. <profile>/crashes/events
|
|
|
|
* 3. <UAppData>/Crash Reports/events
|
2014-02-19 03:58:03 +04:00
|
|
|
*/
|
2014-05-06 23:48:40 +04:00
|
|
|
void SetUserAppDataDirectory(nsIFile* aDir);
|
|
|
|
void SetProfileDirectory(nsIFile* aDir);
|
2014-02-19 03:58:03 +04:00
|
|
|
void UpdateCrashEventsDir();
|
2014-08-30 09:21:09 +04:00
|
|
|
void SetMemoryReportFile(nsIFile* aFile);
|
2016-03-14 16:31:19 +03:00
|
|
|
void SetTelemetrySessionId(const nsACString& id);
|
2014-02-19 03:58:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the path where crash event files should be written.
|
|
|
|
*/
|
|
|
|
bool GetCrashEventsDir(nsAString& aPath);
|
|
|
|
|
2009-04-02 19:41:12 +04:00
|
|
|
bool GetEnabled();
|
|
|
|
bool GetServerURL(nsACString& aServerURL);
|
|
|
|
nsresult SetServerURL(const nsACString& aServerURL);
|
|
|
|
bool GetMinidumpPath(nsAString& aPath);
|
|
|
|
nsresult SetMinidumpPath(const nsAString& aPath);
|
2011-10-07 00:33:21 +04:00
|
|
|
|
|
|
|
|
2014-10-28 19:08:46 +03:00
|
|
|
// AnnotateCrashReport, RemoveCrashReportAnnotation and
|
|
|
|
// AppendAppNotesToCrashReport may be called from any thread in a chrome
|
|
|
|
// process, but may only be called from the main thread in a content process.
|
2008-07-27 21:08:03 +04:00
|
|
|
nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
|
2014-10-28 19:08:46 +03:00
|
|
|
nsresult RemoveCrashReportAnnotation(const nsACString& key);
|
2008-07-27 21:08:03 +04:00
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data);
|
2012-01-25 18:43:52 +04:00
|
|
|
|
2015-09-29 18:14:50 +03:00
|
|
|
// NOTE: If you change this definition, also change the definition in Assertions.h
|
|
|
|
// as it is intended to be defining this same function.
|
|
|
|
void AnnotateMozCrashReason(const char* aReason);
|
2013-11-26 00:06:17 +04:00
|
|
|
void AnnotateOOMAllocationSize(size_t size);
|
2012-08-15 21:47:51 +04:00
|
|
|
nsresult SetGarbageCollecting(bool collecting);
|
2014-02-13 21:51:09 +04:00
|
|
|
void SetEventloopNestingLevel(uint32_t level);
|
2012-08-15 21:47:51 +04:00
|
|
|
|
2016-02-03 23:24:47 +03:00
|
|
|
void AnnotateTexturesSize(size_t size);
|
|
|
|
|
2008-07-27 21:08:03 +04:00
|
|
|
nsresult SetRestartArgs(int argc, char** argv);
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult SetupExtraData(nsIFile* aAppDataDirectory,
|
2007-07-25 05:06:15 +04:00
|
|
|
const nsACString& aBuildID);
|
2012-07-17 03:50:52 +04:00
|
|
|
bool GetLastRunCrashID(nsAString& id);
|
2010-03-25 00:22:01 +03:00
|
|
|
|
2011-07-08 04:31:01 +04:00
|
|
|
// Registers an additional memory region to be included in the minidump
|
|
|
|
nsresult RegisterAppMemory(void* ptr, size_t length);
|
|
|
|
nsresult UnregisterAppMemory(void* ptr);
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
// Functions for working with minidumps and .extras
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> AnnotationTable;
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
void DeleteMinidumpFilesForID(const nsAString& id);
|
2012-06-06 06:08:30 +04:00
|
|
|
bool GetMinidumpForID(const nsAString& id, nsIFile** minidump);
|
|
|
|
bool GetIDFromMinidump(nsIFile* minidump, nsAString& id);
|
|
|
|
bool GetExtraFileForID(const nsAString& id, nsIFile** extraFile);
|
|
|
|
bool GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile);
|
2010-03-25 00:22:01 +03:00
|
|
|
bool AppendExtraData(const nsAString& id, const AnnotationTable& data);
|
2012-06-06 06:08:30 +04:00
|
|
|
bool AppendExtraData(nsIFile* extraFile, const AnnotationTable& data);
|
2015-06-11 20:25:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Renames the stand alone dump file aDumpFile to:
|
|
|
|
* |aOwnerDumpFile-aDumpFileProcessType.dmp|
|
|
|
|
* and moves it into the same directory as aOwnerDumpFile. Does not
|
|
|
|
* modify aOwnerDumpFile in any way.
|
|
|
|
*
|
|
|
|
* @param aDumpFile - the dump file to associate with aOwnerDumpFile.
|
|
|
|
* @param aOwnerDumpFile - the new owner of aDumpFile.
|
|
|
|
* @param aDumpFileProcessType - process name associated with aDumpFile.
|
|
|
|
*/
|
|
|
|
void RenameAdditionalHangMinidump(nsIFile* aDumpFile, const nsIFile* aOwnerDumpFile,
|
|
|
|
const nsACString& aDumpFileProcessType);
|
2010-03-25 00:22:01 +03:00
|
|
|
|
2008-02-09 05:40:47 +03:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo);
|
2010-01-15 01:38:00 +03:00
|
|
|
#endif
|
2014-02-05 22:29:51 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc);
|
|
|
|
#endif
|
2010-01-15 01:38:00 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsresult AppendObjCExceptionInfoToAppNotes(void *inException);
|
|
|
|
#endif
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult GetSubmitReports(bool* aSubmitReport);
|
|
|
|
nsresult SetSubmitReports(bool aSubmitReport);
|
2010-01-15 01:38:00 +03:00
|
|
|
|
|
|
|
// Out-of-process crash reporter API.
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
// Initializes out-of-process crash reporting. This method must be called
|
2014-07-18 21:31:45 +04:00
|
|
|
// before the platform-specific notification pipe APIs are called. If called
|
|
|
|
// from off the main thread, this method will synchronously proxy to the main
|
|
|
|
// thread.
|
2012-07-11 06:20:05 +04:00
|
|
|
void OOPInit();
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Takes a minidump for the current process and returns the dump file.
|
|
|
|
* Callers are responsible for managing the resulting file.
|
|
|
|
*
|
|
|
|
* @param aResult - file pointer that holds the resulting minidump.
|
|
|
|
* @param aMoveToPending - if true move the report to the report
|
|
|
|
* pending directory.
|
|
|
|
* @returns boolean indicating success or failure.
|
|
|
|
*/
|
|
|
|
bool TakeMinidump(nsIFile** aResult, bool aMoveToPending = false);
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
// Return true if a dump was found for |childPid|, and return the
|
2010-03-19 01:52:36 +03:00
|
|
|
// path in |dump|. The caller owns the last reference to |dump| if it
|
2013-10-11 00:39:09 +04:00
|
|
|
// is non-nullptr. The sequence parameter will be filled with an ordinal
|
2012-07-11 06:20:05 +04:00
|
|
|
// indicating which remote process crashed first.
|
2012-08-22 19:56:38 +04:00
|
|
|
bool TakeMinidumpForChild(uint32_t childPid,
|
2012-07-07 00:14:07 +04:00
|
|
|
nsIFile** dump,
|
2013-10-11 00:39:09 +04:00
|
|
|
uint32_t* aSequence = nullptr);
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
#if defined(XP_WIN)
|
2010-03-25 00:22:00 +03:00
|
|
|
typedef HANDLE ProcessHandle;
|
2010-03-31 04:24:45 +04:00
|
|
|
typedef DWORD ThreadId;
|
2010-08-16 23:05:09 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-27 17:32:45 +04:00
|
|
|
typedef task_t ProcessHandle;
|
2010-08-16 23:05:09 +04:00
|
|
|
typedef mach_port_t ThreadId;
|
2010-03-25 00:22:00 +03:00
|
|
|
#else
|
|
|
|
typedef int ProcessHandle;
|
2010-03-31 04:24:45 +04:00
|
|
|
typedef int ThreadId;
|
2010-03-25 00:22:00 +03:00
|
|
|
#endif
|
|
|
|
|
2010-03-31 04:24:45 +04:00
|
|
|
// Return the current thread's ID.
|
|
|
|
//
|
|
|
|
// XXX: this is a somewhat out-of-place interface to expose through
|
|
|
|
// crashreporter, but it takes significant work to call sys_gettid()
|
|
|
|
// correctly on Linux and breakpad has already jumped through those
|
|
|
|
// hoops for us.
|
|
|
|
ThreadId CurrentThreadId();
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Take a minidump of the target process and pair it with an incoming minidump
|
|
|
|
* provided by the caller or a new minidump of the calling process and thread.
|
|
|
|
* The caller will own both dumps after this call. If this function fails
|
|
|
|
* it will attempt to delete any files that were created.
|
|
|
|
*
|
|
|
|
* The .extra information created will not include an 'additional_minidumps'
|
|
|
|
* annotation.
|
|
|
|
*
|
|
|
|
* @param aTargetPid The target process for the minidump.
|
|
|
|
* @param aTargetBlamedThread The target thread for the minidump.
|
|
|
|
* @param aIncomingPairName The name to apply to the paired dump the caller
|
|
|
|
* passes in.
|
|
|
|
* @param aIncomingDumpToPair Existing dump to pair with the new dump. if this
|
|
|
|
* is null, TakeMinidumpAndPair will take a new minidump of the calling
|
|
|
|
* process and thread and use it in aIncomingDumpToPairs place.
|
|
|
|
* @param aTargetDumpOut The target minidump file paired up with
|
|
|
|
* aIncomingDumpToPair.
|
|
|
|
* @return bool indicating success or failure
|
|
|
|
*/
|
|
|
|
bool CreateMinidumpsAndPair(ProcessHandle aTargetPid,
|
|
|
|
ThreadId aTargetBlamedThread,
|
|
|
|
const nsACString& aIncomingPairName,
|
|
|
|
nsIFile* aIncomingDumpToPair,
|
|
|
|
nsIFile** aTargetDumpOut);
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2012-09-27 00:49:20 +04:00
|
|
|
// Create an additional minidump for a child of a process which already has
|
|
|
|
// a minidump (|parentMinidump|).
|
|
|
|
// The resulting dump will get the id of the parent and use the |name| as
|
|
|
|
// an extension.
|
|
|
|
bool CreateAdditionalChildMinidump(ProcessHandle childPid,
|
|
|
|
ThreadId childBlamedThread,
|
|
|
|
nsIFile* parentMinidump,
|
|
|
|
const nsACString& name);
|
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
# if defined(XP_WIN32) || defined(XP_MACOSX)
|
2010-01-13 00:14:38 +03:00
|
|
|
// Parent-side API for children
|
2010-01-13 18:44:10 +03:00
|
|
|
const char* GetChildNotificationPipe();
|
2010-01-15 01:38:00 +03:00
|
|
|
|
2012-07-02 22:55:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
// Inject a crash report client into an arbitrary process, and inform the
|
|
|
|
// callback object when it crashes. Parent process only.
|
|
|
|
|
|
|
|
class InjectorCrashCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InjectorCrashCallback() { }
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
/**
|
|
|
|
* Inform the callback of a crash. The client code should call
|
|
|
|
* TakeMinidumpForChild to remove it from the PID mapping table.
|
|
|
|
*
|
|
|
|
* The callback will not be fired if the client has already called
|
|
|
|
* TakeMinidumpForChild for this process ID.
|
|
|
|
*/
|
|
|
|
virtual void OnCrash(DWORD processID) = 0;
|
2012-07-02 22:55:23 +04:00
|
|
|
};
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
// This method implies OOPInit
|
2012-07-02 22:55:23 +04:00
|
|
|
void InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb);
|
|
|
|
void UnregisterInjectorCallback(DWORD processID);
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
// Child-side API
|
|
|
|
bool SetRemoteExceptionHandler(const nsACString& crashPipe);
|
2016-03-16 21:35:50 +03:00
|
|
|
void InitChildProcessTmpDir();
|
2010-01-15 01:38:00 +03:00
|
|
|
|
|
|
|
# elif defined(XP_LINUX)
|
2010-01-13 00:14:38 +03:00
|
|
|
// Parent-side API for children
|
|
|
|
|
|
|
|
// Set the outparams for crash reporter server's fd (|childCrashFd|)
|
|
|
|
// and the magic fd number it should be remapped to
|
|
|
|
// (|childCrashRemapFd|) before exec() in the child process.
|
|
|
|
// |SetRemoteExceptionHandler()| in the child process expects to find
|
|
|
|
// the server at |childCrashRemapFd|. Return true iff successful.
|
|
|
|
//
|
|
|
|
// If crash reporting is disabled, both outparams will be set to -1
|
|
|
|
// and |true| will be returned.
|
|
|
|
bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd);
|
|
|
|
|
|
|
|
// Child-side API
|
|
|
|
bool SetRemoteExceptionHandler();
|
2010-04-13 00:47:47 +04:00
|
|
|
|
2010-01-15 01:38:00 +03:00
|
|
|
#endif // XP_WIN32
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
bool UnsetRemoteExceptionHandler();
|
2010-10-19 23:05:47 +04:00
|
|
|
|
2012-07-17 03:50:52 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 23:05:47 +04:00
|
|
|
// Android builds use a custom library loader, so /proc/<pid>/maps
|
|
|
|
// will just show anonymous mappings for all the non-system
|
|
|
|
// shared libraries. This API is to work around that by providing
|
|
|
|
// info about the shared libraries that are mapped into these anonymous
|
|
|
|
// mappings.
|
|
|
|
void AddLibraryMapping(const char* library_name,
|
|
|
|
uintptr_t start_address,
|
|
|
|
size_t mapping_length,
|
|
|
|
size_t file_offset);
|
2010-11-24 17:15:03 +03:00
|
|
|
|
|
|
|
#endif
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace CrashReporter
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2007-08-08 19:19:57 +04:00
|
|
|
#endif /* nsExceptionHandler_h__ */
|