2010-11-24 06:15:03 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set sw=4 ts=8 et tw=80 :
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2010-11-24 06:15:03 -08:00
|
|
|
#include "CrashReporterParent.h"
|
2013-06-03 03:14:37 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2013-09-23 14:30:40 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2011-06-08 12:56:31 -07:00
|
|
|
#include <time.h>
|
|
|
|
|
2013-09-30 10:38:05 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
2014-05-12 11:58:18 -07:00
|
|
|
#include "nsICrashService.h"
|
2013-09-30 10:38:05 -07:00
|
|
|
#endif
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
using namespace base;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-09-08 10:20:59 -07:00
|
|
|
void
|
|
|
|
CrashReporterParent::AnnotateCrashReport(const nsCString& key,
|
|
|
|
const nsCString& data)
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
mNotes.Put(key, data);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-02 11:44:13 -07:00
|
|
|
void
|
|
|
|
CrashReporterParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005155
|
|
|
|
}
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
bool
|
|
|
|
CrashReporterParent::RecvAppendAppNotes(const nsCString& data)
|
|
|
|
{
|
|
|
|
mAppNotes.Append(data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:37 -07:00
|
|
|
mozilla::ipc::IProtocol*
|
|
|
|
CrashReporterParent::CloneProtocol(Channel* aChannel,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
2013-09-30 10:38:05 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2013-06-03 03:14:37 -07:00
|
|
|
ContentParent* contentParent = aCtx->GetContentParent();
|
|
|
|
CrashReporter::ThreadId childThreadId = contentParent->Pid();
|
|
|
|
GeckoProcessType childProcessType =
|
|
|
|
contentParent->Process()->GetProcessType();
|
|
|
|
|
|
|
|
nsAutoPtr<PCrashReporterParent> actor(
|
|
|
|
contentParent->AllocPCrashReporterParent(childThreadId,
|
|
|
|
childProcessType)
|
|
|
|
);
|
|
|
|
if (!actor ||
|
|
|
|
!contentParent->RecvPCrashReporterConstructor(actor,
|
|
|
|
childThreadId,
|
|
|
|
childThreadId)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return actor.forget();
|
2013-09-30 10:38:05 -07:00
|
|
|
#else
|
|
|
|
MOZ_CRASH("Not Implemented");
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
2013-06-03 03:14:37 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
CrashReporterParent::CrashReporterParent()
|
2013-09-02 01:41:57 -07:00
|
|
|
:
|
2011-06-08 12:56:31 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2013-09-02 01:41:57 -07:00
|
|
|
mNotes(4),
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
2014-02-14 00:43:51 -08:00
|
|
|
mStartTime(::time(nullptr))
|
2013-09-02 01:41:57 -07:00
|
|
|
, mInitialized(false)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(CrashReporterParent);
|
2010-11-24 06:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporterParent::~CrashReporterParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(CrashReporterParent);
|
|
|
|
}
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
void
|
|
|
|
CrashReporterParent::SetChildData(const NativeThreadId& tid,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t& processType)
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
|
|
|
mInitialized = true;
|
|
|
|
mMainThread = tid;
|
|
|
|
mProcessType = processType;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-07-10 19:20:05 -07:00
|
|
|
bool
|
|
|
|
CrashReporterParent::GenerateCrashReportForMinidump(nsIFile* minidump,
|
|
|
|
const AnnotationTable* processNotes)
|
|
|
|
{
|
|
|
|
if (!CrashReporter::GetIDFromMinidump(minidump, mChildDumpID))
|
|
|
|
return false;
|
|
|
|
return GenerateChildData(processNotes);
|
|
|
|
}
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
bool
|
|
|
|
CrashReporterParent::GenerateChildData(const AnnotationTable* processNotes)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString type;
|
2011-06-08 12:56:31 -07:00
|
|
|
switch (mProcessType) {
|
|
|
|
case GeckoProcessType_Content:
|
|
|
|
type = NS_LITERAL_CSTRING("content");
|
|
|
|
break;
|
|
|
|
case GeckoProcessType_Plugin:
|
|
|
|
type = NS_LITERAL_CSTRING("plugin");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("unknown process type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("ProcessType"), type);
|
|
|
|
|
|
|
|
char startTime[32];
|
2012-08-07 00:06:29 -07:00
|
|
|
sprintf(startTime, "%lld", static_cast<long long>(mStartTime));
|
2011-06-08 12:56:31 -07:00
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("StartupTime"), nsDependentCString(startTime));
|
|
|
|
|
|
|
|
if (!mAppNotes.IsEmpty())
|
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes);
|
|
|
|
|
|
|
|
bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes);
|
|
|
|
if (ret && processNotes)
|
|
|
|
ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes);
|
|
|
|
if (!ret)
|
|
|
|
NS_WARNING("problem appending child data to .extra");
|
2014-05-12 11:58:18 -07:00
|
|
|
|
|
|
|
NotifyCrashService();
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2014-05-12 11:58:18 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
CrashReporterParent::NotifyCrashService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsICrashService> crashService =
|
|
|
|
do_GetService("@mozilla.org/crashservice;1");
|
|
|
|
if (!crashService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mProcessType == GeckoProcessType_Content) {
|
|
|
|
crashService->AddCrash(nsICrashService::PROCESS_TYPE_CONTENT,
|
|
|
|
nsICrashService::CRASH_TYPE_CRASH,
|
|
|
|
mChildDumpID);
|
|
|
|
}
|
|
|
|
else if (mProcessType == GeckoProcessType_Plugin) {
|
|
|
|
nsAutoCString val;
|
|
|
|
int32_t crashType = nsICrashService::CRASH_TYPE_CRASH;
|
|
|
|
if (mNotes.Get(NS_LITERAL_CSTRING("PluginHang"), &val) &&
|
|
|
|
val.Equals(NS_LITERAL_CSTRING("1"))) {
|
|
|
|
crashType = nsICrashService::CRASH_TYPE_HANG;
|
|
|
|
}
|
|
|
|
crashService->AddCrash(nsICrashService::PROCESS_TYPE_PLUGIN, crashType,
|
|
|
|
mChildDumpID);
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|