gecko-dev/ipc/glue/CrashReporterHelper.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 строки
2.5 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/UniquePtr.h"
#include "nsExceptionHandler.h"
#include "nsICrashService.h"
#include "nsPrintfCString.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:
Bug 1614933 - Gather content processes' crash annotations at exception time instead of using IPC; r=froydnj Crash annotations in content processes are currently sent over IPC via shared memory buffers. To pave the way for the Rust rewrite of the exception handler we are removing this code and gathering all the crash annotations within the content processes themselves. This patch causes annotations to be stored in the global table of each content process. They are then streamed out to the parent process by the exception handler together with the exception-time annotations. This has a number of benefits: * we have one less channel to exchange data between content processes and the parent process * we save memory because we don't need to allocate the shared memory buffers * annotations are faster because we don't stream them all out every time one changes * we won't truncate annotations anymore if we run out of space in the shared segment. * we don't need delayed annotations anymore, so we can get rid of the associated machinery As I refactored the code I tried to adjust all the obsolete comments, consolidate shared code and remove the redundant steps that were sometimes present. In many places we had two entire crash annotation tables we merged to change just a couple; that comes from the fact that historically we loaded them from disk. Now it doesn't matter anymore and we can just go ahead and change the ones we care about. Differential Revision: https://phabricator.services.mozilla.com/D62586 --HG-- extra : moz-landing-system : lando
2020-04-08 09:55:40 +03:00
* `async InitCrashReporter(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) {}
Bug 1614933 - Gather content processes' crash annotations at exception time instead of using IPC; r=froydnj Crash annotations in content processes are currently sent over IPC via shared memory buffers. To pave the way for the Rust rewrite of the exception handler we are removing this code and gathering all the crash annotations within the content processes themselves. This patch causes annotations to be stored in the global table of each content process. They are then streamed out to the parent process by the exception handler together with the exception-time annotations. This has a number of benefits: * we have one less channel to exchange data between content processes and the parent process * we save memory because we don't need to allocate the shared memory buffers * annotations are faster because we don't stream them all out every time one changes * we won't truncate annotations anymore if we run out of space in the shared segment. * we don't need delayed annotations anymore, so we can get rid of the associated machinery As I refactored the code I tried to adjust all the obsolete comments, consolidate shared code and remove the redundant steps that were sometimes present. In many places we had two entire crash annotation tables we merged to change just a couple; that comes from the fact that historically we loaded them from disk. Now it doesn't matter anymore and we can just go ahead and change the ones we care about. Differential Revision: https://phabricator.services.mozilla.com/D62586 --HG-- extra : moz-landing-system : lando
2020-04-08 09:55:40 +03:00
IPCResult RecvInitCrashReporter(const CrashReporter::ThreadId& aThreadId) {
mCrashReporter = MakeUnique<ipc::CrashReporterHost>(PT, aThreadId);
return IPC_OK();
}
protected:
void GenerateCrashReport(base::ProcessId aPid,
nsString* aMinidumpId = nullptr) {
nsAutoString minidumpId;
if (!mCrashReporter) {
HandleOrphanedMinidump(aPid, minidumpId);
} else if (mCrashReporter->GenerateCrashReport(aPid)) {
minidumpId = mCrashReporter->MinidumpID();
}
if (aMinidumpId) {
*aMinidumpId = minidumpId;
}
mCrashReporter = nullptr;
}
private:
void HandleOrphanedMinidump(base::ProcessId aPid, nsString& aMinidumpId) {
if (CrashReporter::FinalizeOrphanedMinidump(aPid, PT, &aMinidumpId)) {
CrashReporterHost::RecordCrash(PT, nsICrashService::CRASH_TYPE_CRASH,
aMinidumpId);
} else {
NS_WARNING(nsPrintfCString("child process pid = %d crashed without "
"leaving a minidump behind",
aPid)
.get());
}
}
protected:
UniquePtr<ipc::CrashReporterHost> mCrashReporter;
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_CrashReporterHelper_h