2016-01-08 23:40:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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 17:15:03 +03:00
|
|
|
#include "CrashReporterParent.h"
|
2015-05-26 21:33:55 +03:00
|
|
|
#include "mozilla/Snprintf.h"
|
2013-06-03 14:14:37 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-24 01:30:40 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2011-06-08 23:56:31 +04:00
|
|
|
#include <time.h>
|
|
|
|
|
2014-12-12 22:13:28 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
2013-09-30 21:38:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
2014-05-12 22:58:18 +04:00
|
|
|
#include "nsICrashService.h"
|
2014-07-18 21:31:21 +04:00
|
|
|
#include "mozilla/SyncRunnable.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-09-30 21:38:05 +04:00
|
|
|
#endif
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
void
|
|
|
|
CrashReporterParent::AnnotateCrashReport(const nsCString& key,
|
|
|
|
const nsCString& data)
|
2011-06-08 23:56:31 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2016-01-05 12:59:30 +03:00
|
|
|
mNotes.Put(key, data);
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-02 22:44:13 +04:00
|
|
|
void
|
|
|
|
CrashReporterParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005155
|
|
|
|
}
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
bool
|
|
|
|
CrashReporterParent::RecvAppendAppNotes(const nsCString& data)
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
mAppNotes.Append(data);
|
|
|
|
return true;
|
2011-06-08 23:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
mozilla::ipc::IProtocol*
|
|
|
|
CrashReporterParent::CloneProtocol(Channel* aChannel,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
2013-09-30 21:38:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2016-01-05 12:59:30 +03: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;
|
|
|
|
}
|
2013-06-03 14:14:37 +04:00
|
|
|
|
2016-01-05 12:59:30 +03:00
|
|
|
return actor.forget();
|
2013-09-30 21:38:05 +04:00
|
|
|
#else
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_CRASH("Not Implemented");
|
|
|
|
return nullptr;
|
2013-09-30 21:38:05 +04:00
|
|
|
#endif
|
2013-06-03 14:14:37 +04:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
CrashReporterParent::CrashReporterParent()
|
2016-01-05 12:59:30 +03:00
|
|
|
:
|
2011-06-08 23:56:31 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2016-01-05 12:59:30 +03:00
|
|
|
mNotes(4),
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
2016-01-05 12:59:30 +03:00
|
|
|
mStartTime(::time(nullptr))
|
|
|
|
, mInitialized(false)
|
2013-09-02 12:41:57 +04:00
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_COUNT_CTOR(CrashReporterParent);
|
2010-11-24 17:15:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporterParent::~CrashReporterParent()
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_COUNT_DTOR(CrashReporterParent);
|
2010-11-24 17:15:03 +03:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
void
|
|
|
|
CrashReporterParent::SetChildData(const NativeThreadId& tid,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t& processType)
|
2011-06-08 23:56:31 +04:00
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
mInitialized = true;
|
|
|
|
mMainThread = tid;
|
|
|
|
mProcessType = processType;
|
2011-06-08 23:56:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-07-11 06:20:05 +04:00
|
|
|
bool
|
|
|
|
CrashReporterParent::GenerateCrashReportForMinidump(nsIFile* minidump,
|
2016-01-05 12:59:30 +03:00
|
|
|
const AnnotationTable* processNotes)
|
2012-07-11 06:20:05 +04:00
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
if (!CrashReporter::GetIDFromMinidump(minidump, mChildDumpID)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = GenerateChildData(processNotes);
|
|
|
|
FinalizeChildData();
|
|
|
|
return result;
|
2012-07-11 06:20:05 +04:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:56:31 +04:00
|
|
|
bool
|
|
|
|
CrashReporterParent::GenerateChildData(const AnnotationTable* processNotes)
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
|
|
|
|
if (mChildDumpID.IsEmpty()) {
|
|
|
|
NS_WARNING("problem with GenerateChildData: no child dump id yet!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString type;
|
|
|
|
switch (mProcessType) {
|
|
|
|
case GeckoProcessType_Content:
|
|
|
|
type = NS_LITERAL_CSTRING("content");
|
|
|
|
break;
|
|
|
|
case GeckoProcessType_Plugin:
|
|
|
|
case GeckoProcessType_GMPlugin:
|
|
|
|
type = NS_LITERAL_CSTRING("plugin");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("unknown process type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("ProcessType"), type);
|
|
|
|
|
|
|
|
char startTime[32];
|
|
|
|
snprintf_literal(startTime, "%lld", static_cast<long long>(mStartTime));
|
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("StartupTime"), nsDependentCString(startTime));
|
|
|
|
|
|
|
|
if (!mAppNotes.IsEmpty()) {
|
|
|
|
mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append these notes to the end of the extra file based on the current
|
|
|
|
// dump id we obtained from CreatePairedMinidumps.
|
|
|
|
bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes);
|
|
|
|
if (ret && processNotes) {
|
|
|
|
ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
NS_WARNING("problem appending child data to .extra");
|
|
|
|
}
|
|
|
|
return ret;
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrashReporterParent::FinalizeChildData()
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// Inline, this is the main thread. Get this done.
|
|
|
|
NotifyCrashService();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
|
2016-04-26 03:23:21 +03:00
|
|
|
class NotifyOnMainThread : public Runnable
|
2016-01-05 12:59:30 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit NotifyOnMainThread(CrashReporterParent* aCR)
|
|
|
|
: mCR(aCR)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mCR->NotifyCrashService();
|
|
|
|
return NS_OK;
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
2016-01-05 12:59:30 +03:00
|
|
|
private:
|
|
|
|
CrashReporterParent* mCR;
|
|
|
|
};
|
|
|
|
SyncRunnable::DispatchToThread(mainThread, new NotifyOnMainThread(this));
|
2011-06-08 23:56:31 +04:00
|
|
|
}
|
2014-05-12 22:58:18 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
CrashReporterParent::NotifyCrashService()
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mChildDumpID.IsEmpty());
|
|
|
|
|
|
|
|
nsCOMPtr<nsICrashService> crashService =
|
|
|
|
do_GetService("@mozilla.org/crashservice;1");
|
|
|
|
if (!crashService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t processType;
|
|
|
|
int32_t crashType = nsICrashService::CRASH_TYPE_CRASH;
|
|
|
|
|
|
|
|
nsCString telemetryKey;
|
|
|
|
|
|
|
|
switch (mProcessType) {
|
|
|
|
case GeckoProcessType_Content:
|
|
|
|
processType = nsICrashService::PROCESS_TYPE_CONTENT;
|
|
|
|
telemetryKey.AssignLiteral("content");
|
|
|
|
break;
|
|
|
|
case GeckoProcessType_Plugin: {
|
|
|
|
processType = nsICrashService::PROCESS_TYPE_PLUGIN;
|
|
|
|
telemetryKey.AssignLiteral("plugin");
|
|
|
|
nsAutoCString val;
|
|
|
|
if (mNotes.Get(NS_LITERAL_CSTRING("PluginHang"), &val) &&
|
|
|
|
val.Equals(NS_LITERAL_CSTRING("1"))) {
|
|
|
|
crashType = nsICrashService::CRASH_TYPE_HANG;
|
|
|
|
telemetryKey.AssignLiteral("pluginhang");
|
|
|
|
}
|
|
|
|
break;
|
2014-05-12 22:58:18 +04:00
|
|
|
}
|
2016-01-05 12:59:30 +03:00
|
|
|
case GeckoProcessType_GMPlugin:
|
|
|
|
processType = nsICrashService::PROCESS_TYPE_GMPLUGIN;
|
|
|
|
telemetryKey.AssignLiteral("gmplugin");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("unknown process type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
crashService->AddCrash(processType, crashType, mChildDumpID);
|
|
|
|
Telemetry::Accumulate(Telemetry::SUBPROCESS_CRASHES_WITH_DUMP, telemetryKey, 1);
|
|
|
|
mNotes.Clear();
|
2014-05-12 22:58:18 +04:00
|
|
|
}
|
2011-06-08 23:56:31 +04:00
|
|
|
#endif
|
|
|
|
|
2010-11-24 17:15:03 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|