dom/ipc/CrashReporterParent.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: set sw=4 ts=8 et tw=80 :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_CrashReporterParent_h
michael@0 8 #define mozilla_dom_CrashReporterParent_h
michael@0 9
michael@0 10 #include "mozilla/dom/PCrashReporterParent.h"
michael@0 11 #include "mozilla/dom/TabMessageUtils.h"
michael@0 12 #include "nsIFile.h"
michael@0 13 #ifdef MOZ_CRASHREPORTER
michael@0 14 #include "nsExceptionHandler.h"
michael@0 15 #include "nsDataHashtable.h"
michael@0 16 #endif
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19 namespace dom {
michael@0 20 class ProcessReporter;
michael@0 21
michael@0 22 class CrashReporterParent :
michael@0 23 public PCrashReporterParent
michael@0 24 {
michael@0 25 #ifdef MOZ_CRASHREPORTER
michael@0 26 typedef CrashReporter::AnnotationTable AnnotationTable;
michael@0 27 #endif
michael@0 28 public:
michael@0 29 CrashReporterParent();
michael@0 30 virtual ~CrashReporterParent();
michael@0 31
michael@0 32 #ifdef MOZ_CRASHREPORTER
michael@0 33 /* Attempt to generate a parent/child pair of minidumps from the given
michael@0 34 toplevel actor in the event of a hang. Returns true if successful,
michael@0 35 false otherwise.
michael@0 36 */
michael@0 37 template<class Toplevel>
michael@0 38 bool
michael@0 39 GeneratePairedMinidump(Toplevel* t);
michael@0 40
michael@0 41 /* Attempt to create a bare-bones crash report, along with extra process-
michael@0 42 specific annotations present in the given AnnotationTable. Returns true if
michael@0 43 successful, false otherwise.
michael@0 44 */
michael@0 45 template<class Toplevel>
michael@0 46 bool
michael@0 47 GenerateCrashReport(Toplevel* t, const AnnotationTable* processNotes);
michael@0 48
michael@0 49 /**
michael@0 50 * Add the .extra data for an existing crash report.
michael@0 51 */
michael@0 52 bool
michael@0 53 GenerateChildData(const AnnotationTable* processNotes);
michael@0 54
michael@0 55 bool
michael@0 56 GenerateCrashReportForMinidump(nsIFile* minidump,
michael@0 57 const AnnotationTable* processNotes);
michael@0 58
michael@0 59 /* Instantiate a new crash reporter actor from a given parent that manages
michael@0 60 the protocol.
michael@0 61 */
michael@0 62 template<class Toplevel>
michael@0 63 static bool CreateCrashReporter(Toplevel* actor);
michael@0 64 #endif
michael@0 65 /* Initialize this reporter with data from the child process */
michael@0 66 void
michael@0 67 SetChildData(const NativeThreadId& id, const uint32_t& processType);
michael@0 68
michael@0 69 /* Returns the ID of the child minidump.
michael@0 70 GeneratePairedMinidump or GenerateCrashReport must be called first.
michael@0 71 */
michael@0 72 const nsString& ChildDumpID() {
michael@0 73 return mChildDumpID;
michael@0 74 }
michael@0 75
michael@0 76 void
michael@0 77 AnnotateCrashReport(const nsCString& key, const nsCString& data);
michael@0 78
michael@0 79 protected:
michael@0 80 virtual bool
michael@0 81 RecvAnnotateCrashReport(const nsCString& key, const nsCString& data) MOZ_OVERRIDE {
michael@0 82 AnnotateCrashReport(key, data);
michael@0 83 return true;
michael@0 84 }
michael@0 85 virtual bool
michael@0 86 RecvAppendAppNotes(const nsCString& data) MOZ_OVERRIDE;
michael@0 87 virtual mozilla::ipc::IProtocol*
michael@0 88 CloneProtocol(Channel* aChannel,
michael@0 89 mozilla::ipc::ProtocolCloneContext *aCtx) MOZ_OVERRIDE;
michael@0 90
michael@0 91 #ifdef MOZ_CRASHREPORTER
michael@0 92 AnnotationTable mNotes;
michael@0 93 #endif
michael@0 94 nsCString mAppNotes;
michael@0 95 nsString mChildDumpID;
michael@0 96 NativeThreadId mMainThread;
michael@0 97 time_t mStartTime;
michael@0 98 uint32_t mProcessType;
michael@0 99 bool mInitialized;
michael@0 100 };
michael@0 101
michael@0 102 #ifdef MOZ_CRASHREPORTER
michael@0 103 template<class Toplevel>
michael@0 104 inline bool
michael@0 105 CrashReporterParent::GeneratePairedMinidump(Toplevel* t)
michael@0 106 {
michael@0 107 CrashReporter::ProcessHandle child;
michael@0 108 #ifdef XP_MACOSX
michael@0 109 child = t->Process()->GetChildTask();
michael@0 110 #else
michael@0 111 child = t->OtherProcess();
michael@0 112 #endif
michael@0 113 nsCOMPtr<nsIFile> childDump;
michael@0 114 if (CrashReporter::CreatePairedMinidumps(child,
michael@0 115 mMainThread,
michael@0 116 getter_AddRefs(childDump)) &&
michael@0 117 CrashReporter::GetIDFromMinidump(childDump, mChildDumpID)) {
michael@0 118 return true;
michael@0 119 }
michael@0 120 return false;
michael@0 121 }
michael@0 122
michael@0 123 template<class Toplevel>
michael@0 124 inline bool
michael@0 125 CrashReporterParent::GenerateCrashReport(Toplevel* t,
michael@0 126 const AnnotationTable* processNotes)
michael@0 127 {
michael@0 128 nsCOMPtr<nsIFile> crashDump;
michael@0 129 if (t->TakeMinidump(getter_AddRefs(crashDump), nullptr) &&
michael@0 130 CrashReporter::GetIDFromMinidump(crashDump, mChildDumpID)) {
michael@0 131 return GenerateChildData(processNotes);
michael@0 132 }
michael@0 133 return false;
michael@0 134 }
michael@0 135
michael@0 136 template<class Toplevel>
michael@0 137 /* static */ bool
michael@0 138 CrashReporterParent::CreateCrashReporter(Toplevel* actor)
michael@0 139 {
michael@0 140 #ifdef MOZ_CRASHREPORTER
michael@0 141 NativeThreadId id;
michael@0 142 uint32_t processType;
michael@0 143 PCrashReporterParent* p =
michael@0 144 actor->CallPCrashReporterConstructor(&id, &processType);
michael@0 145 if (p) {
michael@0 146 static_cast<CrashReporterParent*>(p)->SetChildData(id, processType);
michael@0 147 } else {
michael@0 148 NS_ERROR("Error creating crash reporter actor");
michael@0 149 }
michael@0 150 return !!p;
michael@0 151 #endif
michael@0 152 return false;
michael@0 153 }
michael@0 154
michael@0 155 #endif
michael@0 156
michael@0 157 } // namespace dom
michael@0 158 } // namespace mozilla
michael@0 159
michael@0 160 #endif // mozilla_dom_CrashReporterParent_h

mercurial