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"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2013-06-03 14:14:37 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2016-10-12 00:25:17 +03:00
|
|
|
#include "mozilla/ipc/CrashReporterHost.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 {
|
|
|
|
|
2016-10-12 00:25:17 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2011-06-08 23:56:31 +04:00
|
|
|
CrashReporterParent::RecvAppendAppNotes(const nsCString& data)
|
|
|
|
{
|
2016-01-05 12:59:30 +03:00
|
|
|
mAppNotes.Append(data);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2011-06-08 23:56:31 +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;
|
2016-10-12 00:25:17 +03:00
|
|
|
mProcessType = GeckoProcessType(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];
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(startTime, "%lld", static_cast<long long>(mStartTime));
|
2016-01-05 12:59:30 +03:00
|
|
|
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);
|
|
|
|
|
2016-10-12 00:25:17 +03:00
|
|
|
CrashReporterHost::NotifyCrashService(mProcessType, mChildDumpID, &mNotes);
|
2016-01-05 12:59:30 +03:00
|
|
|
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
|