2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2013-11-26 20:39:19 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_CrashReporterParent_h
|
|
|
|
#define mozilla_dom_CrashReporterParent_h
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
#include "mozilla/dom/PCrashReporterParent.h"
|
2011-06-08 23:56:31 +04:00
|
|
|
#include "mozilla/dom/TabMessageUtils.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2011-06-08 23:56:31 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
2013-09-22 07:04:10 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
2010-11-24 17:15:03 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-06-08 23:56:31 +04:00
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
class CrashReporterParent :
|
|
|
|
public PCrashReporterParent
|
|
|
|
{
|
2011-06-08 23:56:31 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
typedef CrashReporter::AnnotationTable AnnotationTable;
|
|
|
|
#endif
|
2010-11-24 17:15:03 +03:00
|
|
|
public:
|
2011-06-08 23:56:31 +04:00
|
|
|
CrashReporterParent();
|
|
|
|
virtual ~CrashReporterParent();
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2015-06-11 20:25:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to create a bare-bones crash report, along with extra process-
|
|
|
|
* specific annotations present in the given AnnotationTable.
|
|
|
|
*
|
|
|
|
* @returns true if successful, false otherwise.
|
|
|
|
*/
|
2011-06-08 23:56:31 +04:00
|
|
|
template<class Toplevel>
|
|
|
|
bool
|
2015-06-11 20:25:45 +03:00
|
|
|
GenerateCrashReport(Toplevel* t, const AnnotationTable* processNotes);
|
2011-06-08 23:56:31 +04:00
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Attempt to generate a parent/child pair of minidumps from the given
|
|
|
|
* toplevel actor. This calls CrashReporter::CreatePairedMinidumps to
|
|
|
|
* generate the minidumps. Crash reporter annotations set prior to this
|
|
|
|
* call will be saved via PairedDumpCallbackExtra into an .extra file
|
|
|
|
* under the proper crash id. AnnotateCrashReport annotations are not
|
|
|
|
* set in this call, use GenerateChildData.
|
|
|
|
*
|
|
|
|
* @returns true if successful, false otherwise.
|
|
|
|
*/
|
2011-06-08 23:56:31 +04:00
|
|
|
template<class Toplevel>
|
|
|
|
bool
|
2015-06-11 20:25:45 +03:00
|
|
|
GeneratePairedMinidump(Toplevel* t);
|
2011-06-08 23:56:31 +04:00
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
/**
|
2015-06-11 20:25:45 +03:00
|
|
|
* Apply child process annotations to an existing paired mindump generated
|
|
|
|
* with GeneratePairedMinidump.
|
|
|
|
*
|
|
|
|
* Be careful about calling generate apis immediately after this call,
|
|
|
|
* see FinalizeChildData.
|
|
|
|
*
|
|
|
|
* @param processNotes (optional) - Additional notes to append. Annotations
|
|
|
|
* stored in mNotes will also be applied. processNotes can be null.
|
|
|
|
* @returns true if successful, false otherwise.
|
2012-09-08 21:20:59 +04:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
GenerateChildData(const AnnotationTable* processNotes);
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/**
|
|
|
|
* Handles main thread finalization tasks after a report has been
|
|
|
|
* generated. Does the following:
|
|
|
|
* - register the finished report with the crash service manager
|
|
|
|
* - records telemetry related data about crashes
|
|
|
|
*
|
|
|
|
* Be careful about calling generate apis immediately after this call,
|
|
|
|
* if this api is called on a non-main thread it will fire off a runnable
|
|
|
|
* to complete its work async.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
FinalizeChildData();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to generate a full paired dump complete with any child
|
|
|
|
* annoations, and finalizes the report. Note this call is only valid
|
|
|
|
* on the main thread. Calling on a background thread will fail.
|
|
|
|
*
|
|
|
|
* @returns true if successful, false otherwise.
|
|
|
|
*/
|
|
|
|
template<class Toplevel>
|
|
|
|
bool
|
|
|
|
GenerateCompleteMinidump(Toplevel* t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits a raw minidump handed in, calls GenerateChildData. Used
|
|
|
|
* by plugins.
|
|
|
|
*
|
|
|
|
* @returns true if successful, false otherwise.
|
|
|
|
*/
|
2012-07-11 06:20:05 +04:00
|
|
|
bool
|
|
|
|
GenerateCrashReportForMinidump(nsIFile* minidump,
|
|
|
|
const AnnotationTable* processNotes);
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Instantiate a new crash reporter actor from a given parent that manages
|
|
|
|
* the protocol.
|
|
|
|
*
|
|
|
|
* @returns true if successful, false otherwise.
|
|
|
|
*/
|
2011-06-08 23:56:31 +04:00
|
|
|
template<class Toplevel>
|
2011-10-19 23:32:17 +04:00
|
|
|
static bool CreateCrashReporter(Toplevel* actor);
|
2015-06-11 20:25:45 +03:00
|
|
|
#endif // MOZ_CRASHREPORTER
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize this reporter with data from the child process.
|
|
|
|
*/
|
2011-06-08 23:56:31 +04:00
|
|
|
void
|
2015-06-11 20:25:45 +03:00
|
|
|
SetChildData(const NativeThreadId& id, const uint32_t& processType);
|
2011-06-08 23:56:31 +04:00
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Returns the ID of the child minidump.
|
|
|
|
* GeneratePairedMinidump or GenerateCrashReport must be called first.
|
|
|
|
*/
|
2011-06-08 23:56:31 +04:00
|
|
|
const nsString& ChildDumpID() {
|
|
|
|
return mChildDumpID;
|
|
|
|
}
|
2010-11-24 17:15:03 +03:00
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
/*
|
|
|
|
* Add an annotation to our internally tracked list of annotations.
|
|
|
|
* Callers must apply these notes using GenerateChildData otherwise
|
|
|
|
* the notes will get dropped.
|
|
|
|
*/
|
2012-09-08 21:20:59 +04:00
|
|
|
void
|
|
|
|
AnnotateCrashReport(const nsCString& key, const nsCString& data);
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
protected:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
2014-05-02 22:44:13 +04:00
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
virtual bool
|
2015-03-21 19:28:04 +03:00
|
|
|
RecvAnnotateCrashReport(const nsCString& key, const nsCString& data) override {
|
2012-09-08 21:20:59 +04:00
|
|
|
AnnotateCrashReport(key, data);
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-08 23:56:31 +04:00
|
|
|
virtual bool
|
2015-03-21 19:28:04 +03:00
|
|
|
RecvAppendAppNotes(const nsCString& data) override;
|
2013-06-03 14:14:37 +04:00
|
|
|
virtual mozilla::ipc::IProtocol*
|
|
|
|
CloneProtocol(Channel* aChannel,
|
2015-03-21 19:28:04 +03:00
|
|
|
mozilla::ipc::ProtocolCloneContext *aCtx) override;
|
2011-06-08 23:56:31 +04:00
|
|
|
|
2014-05-12 22:58:18 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
void
|
|
|
|
NotifyCrashService();
|
|
|
|
#endif
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
AnnotationTable mNotes;
|
|
|
|
#endif
|
|
|
|
nsCString mAppNotes;
|
|
|
|
nsString mChildDumpID;
|
|
|
|
NativeThreadId mMainThread;
|
|
|
|
time_t mStartTime;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mProcessType;
|
2011-06-08 23:56:31 +04:00
|
|
|
bool mInitialized;
|
2010-11-24 17:15:03 +03:00
|
|
|
};
|
2011-06-08 23:56:31 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
template<class Toplevel>
|
|
|
|
inline bool
|
|
|
|
CrashReporterParent::GeneratePairedMinidump(Toplevel* t)
|
|
|
|
{
|
2015-04-01 11:40:35 +03:00
|
|
|
mozilla::ipc::ScopedProcessHandle child;
|
2011-06-08 23:56:31 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
child = t->Process()->GetChildTask();
|
|
|
|
#else
|
2015-04-01 11:40:35 +03:00
|
|
|
if (!base::OpenPrivilegedProcessHandle(t->OtherPid(), &child.rwget())) {
|
|
|
|
NS_WARNING("Failed to open child process handle.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> childDump;
|
2011-06-08 23:56:31 +04:00
|
|
|
if (CrashReporter::CreatePairedMinidumps(child,
|
|
|
|
mMainThread,
|
2012-09-08 21:20:59 +04:00
|
|
|
getter_AddRefs(childDump)) &&
|
|
|
|
CrashReporter::GetIDFromMinidump(childDump, mChildDumpID)) {
|
2011-06-08 23:56:31 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Toplevel>
|
|
|
|
inline bool
|
|
|
|
CrashReporterParent::GenerateCrashReport(Toplevel* t,
|
|
|
|
const AnnotationTable* processNotes)
|
|
|
|
{
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> crashDump;
|
2013-10-28 18:04:12 +04:00
|
|
|
if (t->TakeMinidump(getter_AddRefs(crashDump), nullptr) &&
|
2011-06-08 23:56:31 +04:00
|
|
|
CrashReporter::GetIDFromMinidump(crashDump, mChildDumpID)) {
|
|
|
|
return GenerateChildData(processNotes);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
template<class Toplevel>
|
|
|
|
inline bool
|
|
|
|
CrashReporterParent::GenerateCompleteMinidump(Toplevel* t)
|
|
|
|
{
|
|
|
|
mozilla::ipc::ScopedProcessHandle child;
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_WARNING("GenerateCompleteMinidump can't be called on non-main thread.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
child = t->Process()->GetChildTask();
|
|
|
|
#else
|
|
|
|
if (!base::OpenPrivilegedProcessHandle(t->OtherPid(), &child.rwget())) {
|
|
|
|
NS_WARNING("Failed to open child process handle.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsIFile> childDump;
|
|
|
|
if (CrashReporter::CreatePairedMinidumps(child,
|
|
|
|
mMainThread,
|
|
|
|
getter_AddRefs(childDump)) &&
|
|
|
|
CrashReporter::GetIDFromMinidump(childDump, mChildDumpID)) {
|
|
|
|
GenerateChildData(nullptr);
|
|
|
|
FinalizeChildData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
template<class Toplevel>
|
2011-10-19 23:32:17 +04:00
|
|
|
/* static */ bool
|
2011-06-08 23:56:31 +04:00
|
|
|
CrashReporterParent::CreateCrashReporter(Toplevel* actor)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
NativeThreadId id;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t processType;
|
2011-06-08 23:56:31 +04:00
|
|
|
PCrashReporterParent* p =
|
|
|
|
actor->CallPCrashReporterConstructor(&id, &processType);
|
|
|
|
if (p) {
|
|
|
|
static_cast<CrashReporterParent*>(p)->SetChildData(id, processType);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Error creating crash reporter actor");
|
|
|
|
}
|
2011-10-19 23:32:17 +04:00
|
|
|
return !!p;
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
2011-10-19 23:32:17 +04:00
|
|
|
return false;
|
2011-06-08 23:56:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-11-26 20:39:19 +04:00
|
|
|
|
|
|
|
#endif // mozilla_dom_CrashReporterParent_h
|