gecko-dev/ipc/glue/CrashReporterHelper.h
Gabriele Svelto ca8ae39a56 Bug 1544147 - Ensure orphaned crashes are properly notified to the rest of the system r=froydnj
When a content or plug-in process crashes too early we haven't initialized the
CrashReporterHost for that process. This will cause the crash to be orphaned,
i.e. to miss most of its crash annotations. We added code to finalize those
crashes in bug 1282776 so that we wouldn't miss them entirely. This ensured
that crash reports would have both their .dmp and .extra files but the patch
failed to modify the code that notified various listeners about the crash
report's presence.

This changes always send the crash ID alongside the crash notifications, even
for orphaned crashes, so that listeners such as the content crash handler or
the test harnesses can always find the minidump and .extra file. Additionally
orphaned crashes are recorded in the CrashManager and in telemetry just like
normal crashes.

This also re-enables dom/ipc/tests/process_error.xul which failed frequently
because of this bug.

Differential Revision: https://phabricator.services.mozilla.com/D57634

--HG--
extra : moz-landing-system : lando
2019-12-20 17:50:45 +00:00

68 lines
2.2 KiB
C++

/* 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/. */
#ifndef mozilla_ipc_CrashReporterHelper_h
#define mozilla_ipc_CrashReporterHelper_h
#include "CrashReporterHost.h"
#include "mozilla/ipc/Shmem.h"
#include "mozilla/UniquePtr.h"
#include "nsExceptionHandler.h"
#include "nsICrashService.h"
namespace mozilla {
namespace ipc {
/**
* This class encapsulates the common elements of crash report handling for
* toplevel protocols representing processes. To use this class, you should:
*
* 1. Declare a method to initialize the crash reporter in your IPDL:
* `async InitCrashReporter(Shmem shmem, NativeThreadId threadId)`
*
* 2. Inherit from this class, providing the appropriate `GeckoProcessType`
* enum value for the template parameter PT.
*
* 3. When your protocol actor is destroyed with a reason of `AbnormalShutdown`,
* you should call `GenerateCrashReport(OtherPid())`. If you need the crash
* report ID it will be copied in the second optional parameter upon
* successful crash report generation.
*/
template <GeckoProcessType PT>
class CrashReporterHelper {
public:
CrashReporterHelper() : mCrashReporter(nullptr) {}
IPCResult RecvInitCrashReporter(Shmem&& aShmem,
const CrashReporter::ThreadId& aThreadId) {
mCrashReporter = MakeUnique<ipc::CrashReporterHost>(PT, aShmem, aThreadId);
return IPC_OK();
}
protected:
bool GenerateCrashReport(base::ProcessId aPid,
nsString* aMinidumpId = nullptr) {
if (!mCrashReporter) {
CrashReporter::FinalizeOrphanedMinidump(aPid, PT, aMinidumpId);
CrashReporterHost::RecordCrash(PT, nsICrashService::CRASH_TYPE_CRASH,
*aMinidumpId);
return false;
}
bool generated = mCrashReporter->GenerateCrashReport(aPid);
if (generated && aMinidumpId) {
*aMinidumpId = mCrashReporter->MinidumpID();
}
mCrashReporter = nullptr;
return generated;
}
UniquePtr<ipc::CrashReporterHost> mCrashReporter;
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_CrashReporterHelper_h