1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/ipc/CrashReporterParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,135 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set sw=4 ts=8 et tw=80 : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#include "CrashReporterParent.h" 1.10 +#include "mozilla/dom/ContentParent.h" 1.11 +#include "nsXULAppAPI.h" 1.12 +#include <time.h> 1.13 + 1.14 +#ifdef MOZ_CRASHREPORTER 1.15 +#include "nsExceptionHandler.h" 1.16 +#endif 1.17 + 1.18 +using namespace base; 1.19 + 1.20 +namespace mozilla { 1.21 +namespace dom { 1.22 + 1.23 +void 1.24 +CrashReporterParent::AnnotateCrashReport(const nsCString& key, 1.25 + const nsCString& data) 1.26 +{ 1.27 +#ifdef MOZ_CRASHREPORTER 1.28 + mNotes.Put(key, data); 1.29 +#endif 1.30 +} 1.31 + 1.32 +bool 1.33 +CrashReporterParent::RecvAppendAppNotes(const nsCString& data) 1.34 +{ 1.35 + mAppNotes.Append(data); 1.36 + return true; 1.37 +} 1.38 + 1.39 +mozilla::ipc::IProtocol* 1.40 +CrashReporterParent::CloneProtocol(Channel* aChannel, 1.41 + mozilla::ipc::ProtocolCloneContext* aCtx) 1.42 +{ 1.43 +#ifdef MOZ_CRASHREPORTER 1.44 + ContentParent* contentParent = aCtx->GetContentParent(); 1.45 + CrashReporter::ThreadId childThreadId = contentParent->Pid(); 1.46 + GeckoProcessType childProcessType = 1.47 + contentParent->Process()->GetProcessType(); 1.48 + 1.49 + nsAutoPtr<PCrashReporterParent> actor( 1.50 + contentParent->AllocPCrashReporterParent(childThreadId, 1.51 + childProcessType) 1.52 + ); 1.53 + if (!actor || 1.54 + !contentParent->RecvPCrashReporterConstructor(actor, 1.55 + childThreadId, 1.56 + childThreadId)) { 1.57 + return nullptr; 1.58 + } 1.59 + 1.60 + return actor.forget(); 1.61 +#else 1.62 + MOZ_CRASH("Not Implemented"); 1.63 + return nullptr; 1.64 +#endif 1.65 +} 1.66 + 1.67 +CrashReporterParent::CrashReporterParent() 1.68 + : 1.69 +#ifdef MOZ_CRASHREPORTER 1.70 + mNotes(4), 1.71 +#endif 1.72 + mStartTime(::time(nullptr)) 1.73 + , mInitialized(false) 1.74 +{ 1.75 + MOZ_COUNT_CTOR(CrashReporterParent); 1.76 +} 1.77 + 1.78 +CrashReporterParent::~CrashReporterParent() 1.79 +{ 1.80 + MOZ_COUNT_DTOR(CrashReporterParent); 1.81 +} 1.82 + 1.83 +void 1.84 +CrashReporterParent::SetChildData(const NativeThreadId& tid, 1.85 + const uint32_t& processType) 1.86 +{ 1.87 + mInitialized = true; 1.88 + mMainThread = tid; 1.89 + mProcessType = processType; 1.90 +} 1.91 + 1.92 +#ifdef MOZ_CRASHREPORTER 1.93 +bool 1.94 +CrashReporterParent::GenerateCrashReportForMinidump(nsIFile* minidump, 1.95 + const AnnotationTable* processNotes) 1.96 +{ 1.97 + if (!CrashReporter::GetIDFromMinidump(minidump, mChildDumpID)) 1.98 + return false; 1.99 + return GenerateChildData(processNotes); 1.100 +} 1.101 + 1.102 +bool 1.103 +CrashReporterParent::GenerateChildData(const AnnotationTable* processNotes) 1.104 +{ 1.105 + MOZ_ASSERT(mInitialized); 1.106 + 1.107 + nsAutoCString type; 1.108 + switch (mProcessType) { 1.109 + case GeckoProcessType_Content: 1.110 + type = NS_LITERAL_CSTRING("content"); 1.111 + break; 1.112 + case GeckoProcessType_Plugin: 1.113 + type = NS_LITERAL_CSTRING("plugin"); 1.114 + break; 1.115 + default: 1.116 + NS_ERROR("unknown process type"); 1.117 + break; 1.118 + } 1.119 + mNotes.Put(NS_LITERAL_CSTRING("ProcessType"), type); 1.120 + 1.121 + char startTime[32]; 1.122 + sprintf(startTime, "%lld", static_cast<long long>(mStartTime)); 1.123 + mNotes.Put(NS_LITERAL_CSTRING("StartupTime"), nsDependentCString(startTime)); 1.124 + 1.125 + if (!mAppNotes.IsEmpty()) 1.126 + mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes); 1.127 + 1.128 + bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes); 1.129 + if (ret && processNotes) 1.130 + ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes); 1.131 + if (!ret) 1.132 + NS_WARNING("problem appending child data to .extra"); 1.133 + return ret; 1.134 +} 1.135 +#endif 1.136 + 1.137 +} // namespace dom 1.138 +} // namespace mozilla