Bug 1402519 - When the crash reporter code is disabled at configure time replace it with a dummy implementation; r=ted.mielczarek

MozReview-Commit-ID: F5QbaI1LlmZ

--HG--
extra : rebase_source : f05c929911d27dc1598bc040df54022cd90aa06a
This commit is contained in:
Gabriele Svelto 2017-11-14 14:49:33 +01:00
parent 1a5bb16905
commit 5ff191810d
16 changed files with 645 additions and 179 deletions

View File

@ -86,8 +86,9 @@ add_task(async function navigate() {
});
add_task(async function crash() {
if (!gMultiProcessBrowser || !("nsICrashReporter" in Ci))
if (!gMultiProcessBrowser || !AppConstants.MOZ_CRASHREPORTER) {
return;
}
let tab = BrowserTestUtils.addTab(gBrowser, DUMMY);
let browser = tab.linkedBrowser;

View File

@ -1195,7 +1195,7 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
#ifdef MOZ_CRASHREPORTER
const char* val = getenv("MOZ_CRASHREPORTER");
if (val && *val) {
if (val && *val && !CrashReporter::IsDummy()) {
rv = CrashReporter::SetExceptionHandler(greDir, true);
if (NS_FAILED(rv)) {
printf("CrashReporter::SetExceptionHandler failed!\n");

View File

@ -8,15 +8,13 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/Vector.h"
#include "mozmemory.h"
#include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#include "Utils.h"
#include "gtest/gtest.h"
#ifdef MOZ_CRASHREPORTER
#include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#endif
#ifdef NIGHTLY_BUILD
#if defined(DEBUG) && !defined(XP_WIN) && !defined(ANDROID)
@ -28,13 +26,11 @@ extern unsigned int _gdb_sleep_duration;
#ifndef XP_DARWIN
static void DisableCrashReporter()
{
#ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
#endif
}
// Wrap ASSERT_DEATH_IF_SUPPORTED to disable the crash reporter

View File

@ -1991,9 +1991,7 @@ var BrowserApp = {
// Crash reporter submit pref must be fetched from nsICrashReporter
// service.
case "datareporting.crashreporter.submitEnabled":
let crashReporterBuilt = "nsICrashReporter" in Ci &&
Services.appinfo instanceof Ci.nsICrashReporter;
if (crashReporterBuilt) {
if (AppConstants.MOZ_CRASHREPORTER) {
aSubject.setAsBool(Services.appinfo.submitReports);
}
break;
@ -2046,9 +2044,7 @@ var BrowserApp = {
// Crash reporter preference is in a service; set and return.
case "datareporting.crashreporter.submitEnabled":
let crashReporterBuilt = "nsICrashReporter" in Ci &&
Services.appinfo instanceof Ci.nsICrashReporter;
if (crashReporterBuilt) {
if (AppConstants.MOZ_CRASHREPORTER) {
Services.appinfo.submitReports = value;
aSubject.setAsEmpty();
}

View File

@ -1239,8 +1239,7 @@ SessionStore.prototype = {
},
_updateCrashReportURL: function ss_updateCrashReportURL(aWindow) {
let crashReporterBuilt = "nsICrashReporter" in Ci && Services.appinfo instanceof Ci.nsICrashReporter;
if (!crashReporterBuilt) {
if (!AppConstants.MOZ_CRASHREPORTER) {
return;
}

View File

@ -1088,7 +1088,7 @@ this.BrowserTestUtils = {
}
let dumpID;
if ('nsICrashReporter' in Ci) {
if (AppConstants.MOZ_CRASHREPORTER) {
dumpID = subject.getPropertyAsAString('dumpID');
if (!dumpID) {
return reject("dumpID was not present despite crash reporting " +

View File

@ -6,6 +6,13 @@
SPHINX_TREES['crash-manager'] = 'docs'
XPIDL_MODULE = 'toolkit_crashservice'
XPIDL_SOURCES += [
'nsICrashService.idl',
]
if CONFIG['MOZ_CRASHREPORTER']:
EXTRA_COMPONENTS += [
'CrashService.js',
'CrashService.manifest',
@ -21,11 +28,6 @@ TESTING_JS_MODULES += [
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
XPIDL_MODULE = 'toolkit_crashservice'
XPIDL_SOURCES += [
'nsICrashService.idl',
]
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Crash Reporting')

View File

@ -26,6 +26,7 @@ DIRS += [
'commandlines',
'contentprefs',
'contextualidentity',
'crashes',
'crashmonitor',
'diskspacewatcher',
'downloads',
@ -80,9 +81,6 @@ if CONFIG['MOZ_BUILD_APP'] != 'mobile/android':
if CONFIG['NS_PRINTING']:
DIRS += ['printing']
if CONFIG['MOZ_CRASHREPORTER']:
DIRS += ['crashes']
if CONFIG['BUILD_CTYPES']:
DIRS += ['ctypes']

View File

@ -3,5 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
toolkit.jar:
#ifdef MOZ_CRASHREPORTER
content/global/crashes.xhtml (content/crashes.xhtml)
content/global/crashes.js (content/crashes.js)
#endif

View File

@ -6,6 +6,19 @@
SPHINX_TREES['crashreporter'] = 'docs'
EXPORTS += [
'nsExceptionHandler.h',
]
JAR_MANIFESTS += ['jar.mn']
UNIFIED_SOURCES = [
'nsExceptionHandlerUtils.cpp',
]
FINAL_LIBRARY = 'xul'
if CONFIG['MOZ_CRASHREPORTER']:
if CONFIG['OS_ARCH'] == 'WINNT':
DIRS += [
'google-breakpad/src/common',
@ -58,10 +71,6 @@ if CONFIG['ENABLE_TESTS']:
TEST_DIRS += ['test']
EXPORTS += [
'nsExceptionHandler.h',
]
UNIFIED_SOURCES += [
'nsExceptionHandler.cpp',
'ThreadAnnotation.cpp',
@ -80,8 +89,6 @@ EXTRA_JS_MODULES += [
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
if CONFIG['OS_TARGET'] == 'Android':
DEFINES['ANDROID_NDK_MAJOR_VERSION'] = CONFIG['ANDROID_NDK_MAJOR_VERSION']
DEFINES['ANDROID_NDK_MINOR_VERSION'] = CONFIG['ANDROID_NDK_MINOR_VERSION']
@ -96,8 +103,6 @@ if CONFIG['OS_TARGET'] == 'Android':
DEFINES['UNICODE'] = True
DEFINES['_UNICODE'] = True
JAR_MANIFESTS += ['jar.mn']
LOCAL_INCLUDES += [
'google-breakpad/src',
]
@ -108,8 +113,13 @@ PYTHON_UNITTEST_MANIFESTS += [
include('/toolkit/crashreporter/crashreporter.mozbuild')
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Crash Reporting')
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-shadow']
else:
UNIFIED_SOURCES += [
'nsDummyExceptionHandler.cpp',
]
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Crash Reporting')

View File

@ -0,0 +1,425 @@
/* -*- 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
* 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/. */
#include "nsExceptionHandler.h"
#include "nsExceptionHandlerUtils.h"
namespace CrashReporter {
void
AnnotateOOMAllocationSize(size_t size)
{
}
void
AnnotateTexturesSize(size_t size)
{
}
void
AnnotatePendingIPC(size_t aNumOfPendingIPC,
uint32_t aTopPendingIPCCount,
const char* aTopPendingIPCName,
uint32_t aTopPendingIPCType)
{
}
nsresult
SetExceptionHandler(nsIFile* aXREDirectory,
bool force/*=false*/)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
bool
GetEnabled()
{
return false;
}
bool
GetMinidumpPath(nsAString& aPath)
{
return false;
}
nsresult
SetMinidumpPath(const nsAString& aPath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
SetupExtraData(nsIFile* aAppDataDirectory,
const nsACString& aBuildID)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
UnsetExceptionHandler()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
AnnotateCrashReport(const nsACString& key,
const nsACString& data)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoveCrashReportAnnotation(const nsACString& key)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
SetGarbageCollecting(bool collecting)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
SetEventloopNestingLevel(uint32_t level)
{
}
void
SetMinidumpAnalysisAllThreads()
{
}
nsresult
AppendAppNotesToCrashReport(const nsACString& data)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
bool
GetAnnotation(const nsACString& key, nsACString& data)
{
return false;
}
nsresult
RegisterAppMemory(void* ptr, size_t length)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
UnregisterAppMemory(void* ptr)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
SetIncludeContextHeap(bool aValue)
{
}
bool
GetServerURL(nsACString& aServerURL)
{
return false;
}
nsresult
SetServerURL(const nsACString& aServerURL)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
SetRestartArgs(int argc, char** argv)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#ifdef XP_WIN32
nsresult
WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif
#ifdef XP_LINUX
bool
WriteMinidumpForSigInfo(int signo,
siginfo_t* info,
void* uc)
{
return false;
}
#endif
#ifdef XP_MACOSX
nsresult
AppendObjCExceptionInfoToAppNotes(void *inException)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif
nsresult
GetSubmitReports(bool* aSubmitReports)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
SetSubmitReports(bool aSubmitReports)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
SetProfileDirectory(nsIFile* aDir)
{
}
void
SetUserAppDataDirectory(nsIFile* aDir)
{
}
void
UpdateCrashEventsDir()
{
}
bool
GetCrashEventsDir(nsAString& aPath)
{
return false;
}
void
SetMemoryReportFile(nsIFile* aFile)
{
}
nsresult
GetDefaultMemoryReportFile(nsIFile** aFile)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
SetTelemetrySessionId(const nsACString& id)
{
}
void
DeleteMinidumpFilesForID(const nsAString& id)
{
}
bool
GetMinidumpForID(const nsAString& id, nsIFile** minidump)
{
return false;
}
bool
GetIDFromMinidump(nsIFile* minidump, nsAString& id)
{
return false;
}
bool
GetExtraFileForID(const nsAString& id,
nsIFile** extraFile)
{
return false;
}
bool
GetExtraFileForMinidump(nsIFile* minidump,
nsIFile** extraFile)
{
return false;
}
bool
AppendExtraData(const nsAString& id,
const AnnotationTable& data)
{
return false;
}
bool
AppendExtraData(nsIFile* extraFile,
const AnnotationTable& data)
{
return false;
}
void
OOPInit()
{
}
void
GetChildProcessTmpDir(nsIFile** aOutTmpDir)
{
}
#if defined(XP_WIN) || defined(XP_MACOSX)
const char*
GetChildNotificationPipe()
{
return nullptr;
}
#endif
#ifdef MOZ_CRASHREPORTER_INJECTOR
void
InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb)
{
}
void
UnregisterInjectorCallback(DWORD processID)
{
}
#endif // MOZ_CRASHREPORTER_INJECTOR
bool
GetLastRunCrashID(nsAString& id)
{
return false;
}
#if defined(XP_WIN) || defined(XP_MACOSX)
void
InitChildProcessTmpDir(nsIFile* aDirOverride)
{
}
#endif // defined(XP_WIN) || defined(XP_MACOSX)
#if defined(XP_WIN)
bool
SetRemoteExceptionHandler(const nsACString& crashPipe)
{
return false;
}
#elif defined(XP_LINUX) || defined(OS_BSD) || defined(OS_SOLARIS)
bool
CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd)
{
return false;
}
bool
SetRemoteExceptionHandler()
{
return false;
}
#elif defined(XP_MACOSX)
bool
SetRemoteExceptionHandler(const nsACString& crashPipe)
{
return false;
}
#endif // XP_WIN
bool
TakeMinidumpForChild(uint32_t childPid, nsIFile** dump, uint32_t* aSequence)
{
return false;
}
void
RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump,
const nsACString& name)
{
}
ThreadId
CurrentThreadId()
{
return -1;
}
bool
TakeMinidump(nsIFile** aResult, bool aMoveToPending)
{
return false;
}
void
CreateMinidumpsAndPair(ProcessHandle aTargetPid,
ThreadId aTargetBlamedThread,
const nsACString& aIncomingPairName,
nsIFile* aIncomingDumpToPair,
nsIFile** aMainDumpOut,
std::function<void(bool)>&& aCallback,
bool aAsync)
{
}
bool
CreateAdditionalChildMinidump(ProcessHandle childPid,
ThreadId childBlamedThread,
nsIFile* parentMinidump,
const nsACString& name)
{
return false;
}
bool
UnsetRemoteExceptionHandler()
{
return false;
}
#if defined(MOZ_WIDGET_ANDROID)
void
SetNotificationPipeForChild(int childCrashFd)
{
}
void
AddLibraryMapping(const char* library_name,
uintptr_t start_address,
size_t mapping_length,
size_t file_offset)
{
}
#endif
// From ThreadAnnotation.cpp
void
InitThreadAnnotation()
{
}
void
SetCurrentThreadName(const char* aName)
{
}
void
GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback)
{
}
void
ShutdownThreadAnnotation()
{
}
} // namespace CrashReporter

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsExceptionHandler.h"
#include "nsExceptionHandlerUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
@ -87,7 +88,6 @@ using mozilla::InjectCrashRunnable;
#include <map>
#include <vector>
#include "mozilla/double-conversion.h"
#include "mozilla/IOInterposer.h"
#include "mozilla/mozalloc_oom.h"
#include "mozilla/WindowsDllBlocklist.h"
@ -413,54 +413,6 @@ typedef std::map<uint32_t,google_breakpad::MappingList> MappingMap;
#endif
}
// Format a non-negative double to a string, without using C-library functions,
// which need to be avoided (.e.g. bug 1240160, comment 10). Leave the utility
// non-file static so that we can gtest it. Return false if we failed to
// get the formatting done correctly.
bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength)
{
// aBufferLength is the size of the buffer. Be paranoid.
aBuffer[aBufferLength-1] = '\0';
if (aValue < 0) {
return false;
}
int length, point, i;
bool sign;
bool ok = true;
double_conversion::DoubleToStringConverter::DoubleToAscii(
aValue,
double_conversion::DoubleToStringConverter::SHORTEST,
8,
aBuffer,
aBufferLength,
&sign,
&length,
&point);
// length does not account for the 0 terminator.
if (length > point && (length+1) < (aBufferLength-1)) {
// We have to insert a decimal point. Not worried about adding a leading zero
// in the < 1 (point == 0) case.
aBuffer[length+1] = '\0';
for (i=length; i>point; i-=1) {
aBuffer[i] = aBuffer[i-1];
}
aBuffer[i] = '.'; // Not worried about locales
} else if (length < point) {
// Trailing zeros scenario
for (i=length; i<point; i+=1) {
if (i >= aBufferLength-2) {
ok = false;
}
aBuffer[i] = '0';
}
aBuffer[i] = '\0';
}
return ok;
}
namespace CrashReporter {
#ifdef XP_LINUX

View File

@ -3,6 +3,12 @@
* 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/. */
// This header has two implementations, the real one in nsExceptionHandler.cpp
// and a dummy in nsDummyExceptionHandler.cpp. The latter is used in builds
// configured with --disable-crashreporter. If you add or remove a function
// from this header you must update both implementations otherwise you'll break
// builds that disable the crash reporter.
#ifndef nsExceptionHandler_h__
#define nsExceptionHandler_h__
@ -34,6 +40,19 @@ template<class KeyClass, class DataType> class nsDataHashtable;
class nsCStringHashKey;
namespace CrashReporter {
/**
* Returns true if the crash reporter is using the dummy implementation.
*/
static inline bool
IsDummy() {
#ifdef MOZ_CRASHREPORTER
return false;
#else
return true;
#endif
}
nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force=false);
nsresult UnsetExceptionHandler();
@ -248,7 +267,7 @@ void UnregisterInjectorCallback(DWORD processID);
bool SetRemoteExceptionHandler(const nsACString& crashPipe);
void InitChildProcessTmpDir(nsIFile* aDirOverride = nullptr);
# elif defined(XP_LINUX)
# elif defined(XP_LINUX) || defined(OS_BSD) || defined(OS_SOLARIS)
// Parent-side API for children
// Set the outparams for crash reporter server's fd (|childCrashFd|)

View File

@ -0,0 +1,56 @@
/* -*- 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
* 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/. */
#include "nsExceptionHandlerUtils.h"
#include "mozilla/double-conversion.h"
// Format a non-negative double to a string, without using C-library functions,
// which need to be avoided (.e.g. bug 1240160, comment 10). Return false if
// we failed to get the formatting done correctly.
bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength)
{
// aBufferLength is the size of the buffer. Be paranoid.
aBuffer[aBufferLength-1] = '\0';
if (aValue < 0) {
return false;
}
int length, point, i;
bool sign;
bool ok = true;
double_conversion::DoubleToStringConverter::DoubleToAscii(
aValue,
double_conversion::DoubleToStringConverter::SHORTEST,
8,
aBuffer,
aBufferLength,
&sign,
&length,
&point);
// length does not account for the 0 terminator.
if (length > point && (length+1) < (aBufferLength-1)) {
// We have to insert a decimal point. Not worried about adding a leading zero
// in the < 1 (point == 0) case.
aBuffer[length+1] = '\0';
for (i=length; i>point; i-=1) {
aBuffer[i] = aBuffer[i-1];
}
aBuffer[i] = '.'; // Not worried about locales
} else if (length < point) {
// Trailing zeros scenario
for (i=length; i<point; i+=1) {
if (i >= aBufferLength-2) {
ok = false;
}
aBuffer[i] = '0';
}
aBuffer[i] = '\0';
}
return ok;
}

View File

@ -0,0 +1,12 @@
/* -*- 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
* 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/. */
#ifndef nsExceptionHandlerUtils_h__
#define nsExceptionHandlerUtils_h__
bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength);
#endif // nsExceptionHandlerUtils_h__

View File

@ -7,6 +7,7 @@
DIRS += [
'components',
'content',
'crashreporter',
'forgetaboutsite',
'locales',
'modules',
@ -46,9 +47,6 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
DIRS += ['system/androidproxy']
if CONFIG['MOZ_CRASHREPORTER']:
DIRS += ['crashreporter']
TEST_HARNESS_FILES.testing.mochitest.browser.toolkit.crashreporter.test.browser += [
'crashreporter/test/browser/crashreport.sjs',
]