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
|
|
|
|
|
|
|
#include "nscore.h"
|
2010-03-25 00:22:01 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2007-07-25 05:05:54 +04:00
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
2010-01-15 01:38:00 +03:00
|
|
|
#include "nsIFile.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
|
|
|
|
|
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();
|
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
|
|
|
|
|
|
|
|
2012-01-25 18:43:52 +04:00
|
|
|
// AnnotateCrashReport 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);
|
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data);
|
2012-01-25 18:43:52 +04:00
|
|
|
|
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);
|
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;
|
|
|
|
|
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);
|
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
|
|
|
|
#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
|
|
|
|
// before the platform-specifi notificationpipe APIs are called.
|
|
|
|
void OOPInit();
|
|
|
|
|
|
|
|
// 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
|
2012-07-11 06:20:05 +04:00
|
|
|
// is non-NULL. The sequence parameter will be filled with an ordinal
|
|
|
|
// indicating which remote process crashed first.
|
2010-03-25 00:22:01 +03:00
|
|
|
bool TakeMinidumpForChild(PRUint32 childPid,
|
2012-07-07 00:14:07 +04:00
|
|
|
nsIFile** dump,
|
2012-07-11 06:20:05 +04:00
|
|
|
PRUint32* aSequence = NULL);
|
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();
|
|
|
|
|
2010-03-25 00:22:00 +03:00
|
|
|
// Create new minidumps that are snapshots of the state of this parent
|
|
|
|
// process and |childPid|. Return true on success along with the
|
|
|
|
// minidumps and a new UUID that can be used to correlate the dumps.
|
|
|
|
//
|
|
|
|
// If this function fails, it's the caller's responsibility to clean
|
|
|
|
// up |childDump| and |parentDump|. Either or both can be created and
|
|
|
|
// returned non-null on failure.
|
|
|
|
bool CreatePairedMinidumps(ProcessHandle childPid,
|
2010-03-31 04:24:45 +04:00
|
|
|
ThreadId childBlamedThread,
|
2012-07-07 00:14:07 +04:00
|
|
|
nsAString* pairGUID,
|
|
|
|
nsIFile** childDump,
|
|
|
|
nsIFile** parentDump);
|
2010-03-25 00:22:00 +03:00
|
|
|
|
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);
|
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
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
// 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,
|
|
|
|
const char* file_id,
|
|
|
|
uintptr_t start_address,
|
|
|
|
size_t mapping_length,
|
|
|
|
size_t file_offset);
|
2010-11-24 17:15:03 +03:00
|
|
|
|
|
|
|
void AddLibraryMappingForChild(PRUint32 childPid,
|
|
|
|
const char* library_name,
|
|
|
|
const char* file_id,
|
|
|
|
uintptr_t start_address,
|
|
|
|
size_t mapping_length,
|
|
|
|
size_t file_offset);
|
|
|
|
void RemoveLibraryMappingsForChild(PRUint32 childPid);
|
|
|
|
#endif
|
2007-07-25 05:05:55 +04:00
|
|
|
}
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2007-08-08 19:19:57 +04:00
|
|
|
#endif /* nsExceptionHandler_h__ */
|