Wed, 31 Dec 2014 06:09:35 +0100
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: 4 -*- |
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 | #include "CrashReporterParent.h" |
michael@0 | 7 | #include "mozilla/dom/ContentParent.h" |
michael@0 | 8 | #include "nsXULAppAPI.h" |
michael@0 | 9 | #include <time.h> |
michael@0 | 10 | |
michael@0 | 11 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 12 | #include "nsExceptionHandler.h" |
michael@0 | 13 | #endif |
michael@0 | 14 | |
michael@0 | 15 | using namespace base; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace dom { |
michael@0 | 19 | |
michael@0 | 20 | void |
michael@0 | 21 | CrashReporterParent::AnnotateCrashReport(const nsCString& key, |
michael@0 | 22 | const nsCString& data) |
michael@0 | 23 | { |
michael@0 | 24 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 25 | mNotes.Put(key, data); |
michael@0 | 26 | #endif |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | bool |
michael@0 | 30 | CrashReporterParent::RecvAppendAppNotes(const nsCString& data) |
michael@0 | 31 | { |
michael@0 | 32 | mAppNotes.Append(data); |
michael@0 | 33 | return true; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | mozilla::ipc::IProtocol* |
michael@0 | 37 | CrashReporterParent::CloneProtocol(Channel* aChannel, |
michael@0 | 38 | mozilla::ipc::ProtocolCloneContext* aCtx) |
michael@0 | 39 | { |
michael@0 | 40 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 41 | ContentParent* contentParent = aCtx->GetContentParent(); |
michael@0 | 42 | CrashReporter::ThreadId childThreadId = contentParent->Pid(); |
michael@0 | 43 | GeckoProcessType childProcessType = |
michael@0 | 44 | contentParent->Process()->GetProcessType(); |
michael@0 | 45 | |
michael@0 | 46 | nsAutoPtr<PCrashReporterParent> actor( |
michael@0 | 47 | contentParent->AllocPCrashReporterParent(childThreadId, |
michael@0 | 48 | childProcessType) |
michael@0 | 49 | ); |
michael@0 | 50 | if (!actor || |
michael@0 | 51 | !contentParent->RecvPCrashReporterConstructor(actor, |
michael@0 | 52 | childThreadId, |
michael@0 | 53 | childThreadId)) { |
michael@0 | 54 | return nullptr; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | return actor.forget(); |
michael@0 | 58 | #else |
michael@0 | 59 | MOZ_CRASH("Not Implemented"); |
michael@0 | 60 | return nullptr; |
michael@0 | 61 | #endif |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | CrashReporterParent::CrashReporterParent() |
michael@0 | 65 | : |
michael@0 | 66 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 67 | mNotes(4), |
michael@0 | 68 | #endif |
michael@0 | 69 | mStartTime(::time(nullptr)) |
michael@0 | 70 | , mInitialized(false) |
michael@0 | 71 | { |
michael@0 | 72 | MOZ_COUNT_CTOR(CrashReporterParent); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | CrashReporterParent::~CrashReporterParent() |
michael@0 | 76 | { |
michael@0 | 77 | MOZ_COUNT_DTOR(CrashReporterParent); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void |
michael@0 | 81 | CrashReporterParent::SetChildData(const NativeThreadId& tid, |
michael@0 | 82 | const uint32_t& processType) |
michael@0 | 83 | { |
michael@0 | 84 | mInitialized = true; |
michael@0 | 85 | mMainThread = tid; |
michael@0 | 86 | mProcessType = processType; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 90 | bool |
michael@0 | 91 | CrashReporterParent::GenerateCrashReportForMinidump(nsIFile* minidump, |
michael@0 | 92 | const AnnotationTable* processNotes) |
michael@0 | 93 | { |
michael@0 | 94 | if (!CrashReporter::GetIDFromMinidump(minidump, mChildDumpID)) |
michael@0 | 95 | return false; |
michael@0 | 96 | return GenerateChildData(processNotes); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | bool |
michael@0 | 100 | CrashReporterParent::GenerateChildData(const AnnotationTable* processNotes) |
michael@0 | 101 | { |
michael@0 | 102 | MOZ_ASSERT(mInitialized); |
michael@0 | 103 | |
michael@0 | 104 | nsAutoCString type; |
michael@0 | 105 | switch (mProcessType) { |
michael@0 | 106 | case GeckoProcessType_Content: |
michael@0 | 107 | type = NS_LITERAL_CSTRING("content"); |
michael@0 | 108 | break; |
michael@0 | 109 | case GeckoProcessType_Plugin: |
michael@0 | 110 | type = NS_LITERAL_CSTRING("plugin"); |
michael@0 | 111 | break; |
michael@0 | 112 | default: |
michael@0 | 113 | NS_ERROR("unknown process type"); |
michael@0 | 114 | break; |
michael@0 | 115 | } |
michael@0 | 116 | mNotes.Put(NS_LITERAL_CSTRING("ProcessType"), type); |
michael@0 | 117 | |
michael@0 | 118 | char startTime[32]; |
michael@0 | 119 | sprintf(startTime, "%lld", static_cast<long long>(mStartTime)); |
michael@0 | 120 | mNotes.Put(NS_LITERAL_CSTRING("StartupTime"), nsDependentCString(startTime)); |
michael@0 | 121 | |
michael@0 | 122 | if (!mAppNotes.IsEmpty()) |
michael@0 | 123 | mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes); |
michael@0 | 124 | |
michael@0 | 125 | bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes); |
michael@0 | 126 | if (ret && processNotes) |
michael@0 | 127 | ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes); |
michael@0 | 128 | if (!ret) |
michael@0 | 129 | NS_WARNING("problem appending child data to .extra"); |
michael@0 | 130 | return ret; |
michael@0 | 131 | } |
michael@0 | 132 | #endif |
michael@0 | 133 | |
michael@0 | 134 | } // namespace dom |
michael@0 | 135 | } // namespace mozilla |