2011-06-08 23:56:31 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-11-24 17:15:03 +03:00
|
|
|
* vim: set sw=4 ts=8 et tw=80 :
|
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/. */
|
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
|
|
|
class ProcessReporter;
|
|
|
|
|
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
|
|
|
|
/* Attempt to generate a parent/child pair of minidumps from the given
|
|
|
|
toplevel actor in the event of a hang. Returns true if successful,
|
|
|
|
false otherwise.
|
|
|
|
*/
|
|
|
|
template<class Toplevel>
|
|
|
|
bool
|
|
|
|
GeneratePairedMinidump(Toplevel* t);
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
template<class Toplevel>
|
|
|
|
bool
|
|
|
|
GenerateCrashReport(Toplevel* t, const AnnotationTable* processNotes);
|
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
/**
|
|
|
|
* Add the .extra data for an existing crash report.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
GenerateChildData(const AnnotationTable* processNotes);
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
bool
|
|
|
|
GenerateCrashReportForMinidump(nsIFile* minidump,
|
|
|
|
const AnnotationTable* processNotes);
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
/* Instantiate a new crash reporter actor from a given parent that manages
|
|
|
|
the protocol.
|
|
|
|
*/
|
|
|
|
template<class Toplevel>
|
2011-10-19 23:32:17 +04:00
|
|
|
static bool CreateCrashReporter(Toplevel* actor);
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
|
|
|
/* Initialize this reporter with data from the child process */
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
SetChildData(const NativeThreadId& id, const uint32_t& processType);
|
2011-06-08 23:56:31 +04:00
|
|
|
|
|
|
|
/* Returns the ID of the child minidump.
|
|
|
|
GeneratePairedMinidump or GenerateCrashReport must be called first.
|
|
|
|
*/
|
|
|
|
const nsString& ChildDumpID() {
|
|
|
|
return mChildDumpID;
|
|
|
|
}
|
2010-11-24 17:15:03 +03:00
|
|
|
|
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:
|
2011-06-08 23:56:31 +04:00
|
|
|
virtual bool
|
2012-09-08 21:20:59 +04:00
|
|
|
RecvAnnotateCrashReport(const nsCString& key, const nsCString& data) {
|
|
|
|
AnnotateCrashReport(key, data);
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-08 23:56:31 +04:00
|
|
|
virtual bool
|
|
|
|
RecvAppendAppNotes(const nsCString& data);
|
2013-06-03 14:14:37 +04:00
|
|
|
virtual mozilla::ipc::IProtocol*
|
|
|
|
CloneProtocol(Channel* aChannel,
|
|
|
|
mozilla::ipc::ProtocolCloneContext *aCtx) MOZ_OVERRIDE;
|
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)
|
|
|
|
{
|
|
|
|
CrashReporter::ProcessHandle child;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
child = t->Process()->GetChildTask();
|
|
|
|
#else
|
|
|
|
child = t->OtherProcess();
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|