feat: support crashpad on linux (#29719)

This commit is contained in:
Jeremy Rose 2021-07-19 10:11:10 -07:00 committed by GitHub
parent 612361c4da
commit c9ba0d02d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 547 additions and 455 deletions

View file

@ -45,7 +45,7 @@ executors:
type: enum
enum: ["medium", "xlarge", "2xlarge+"]
docker:
- image: electron.azurecr.io/build:4fc81b50f9c0980699d329bc32062fac20a26701
- image: electron.azurecr.io/build:fe71f448c9b00708c7a8a67a0210bcef5055ac64
resource_class: << parameters.size >>
macos:

View file

@ -31,12 +31,6 @@ PATHS_TO_SKIP = [
# //chrome/browser/resources/ssl/ssl_error_assistant, but we don't need to
# ship it.
'pyproto',
# On Windows, this binary doesn't exist (the crashpad handler is built-in).
# On MacOS, the binary is called 'chrome_crashpad_handler' and is inside the
# app bundle.
# On Linux, we don't use crashpad, but this binary is still built for some
# reason. Exclude it from the zip.
'./crashpad_handler',
# Skip because these are outputs that we don't need.
'resources/inspector',
'gen/third_party/devtools-frontend/src',

View file

@ -74,6 +74,32 @@ index 39557cce474439238255ecd28030215085db0c81..5b3f980837911c710686ab91a2a81c31
#if defined(OS_ANDROID)
// Used by WebView to sample crashes without generating the unwanted dumps. If
// the returned value is less than 100, crash dumping will be sampled to that
diff --git a/components/crash/core/app/crashpad_linux.cc b/components/crash/core/app/crashpad_linux.cc
index 5f97c1ef00d9c63a7b16265cc97d9f145adae550..8c3028f228373b5e1145fe3235dc06663f8b087f 100644
--- a/components/crash/core/app/crashpad_linux.cc
+++ b/components/crash/core/app/crashpad_linux.cc
@@ -165,6 +165,7 @@ base::FilePath PlatformCrashpadInitialization(
// where crash_reporter provides it's own values for lsb-release.
annotations["lsb-release"] = base::GetLinuxDistro();
#endif
+ crash_reporter_client->GetProcessSimpleAnnotations(&annotations);
std::vector<std::string> arguments;
if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
@@ -186,6 +187,13 @@ base::FilePath PlatformCrashpadInitialization(
}
#endif
+ if (!crash_reporter_client->GetShouldRateLimit()) {
+ arguments.push_back("--no-rate-limit");
+ }
+ if (!crash_reporter_client->GetShouldCompressUploads()) {
+ arguments.push_back("--no-upload-gzip");
+ }
+
bool result =
client.StartHandler(handler_path, database_path, metrics_path, url,
annotations, arguments, false, false);
diff --git a/components/crash/core/app/crashpad_mac.mm b/components/crash/core/app/crashpad_mac.mm
index e3fc1fb2bcab31d6a7cb325a892acb26dc00d4e4..fd654d6e514de416457c283caeb1895dba6286e1 100644
--- a/components/crash/core/app/crashpad_mac.mm

View file

@ -3,6 +3,7 @@ LICENSES.chromium.html
chrome-sandbox
chrome_100_percent.pak
chrome_200_percent.pak
crashpad_handler
electron
icudtl.dat
libEGL.so

View file

@ -3,6 +3,7 @@ LICENSES.chromium.html
chrome-sandbox
chrome_100_percent.pak
chrome_200_percent.pak
crashpad_handler
electron
icudtl.dat
libEGL.so

View file

@ -3,6 +3,7 @@ LICENSES.chromium.html
chrome-sandbox
chrome_100_percent.pak
chrome_200_percent.pak
crashpad_handler
electron
icudtl.dat
libEGL.so

View file

@ -3,6 +3,7 @@ LICENSES.chromium.html
chrome-sandbox
chrome_100_percent.pak
chrome_200_percent.pak
crashpad_handler
electron
icudtl.dat
libEGL.so

View file

@ -153,6 +153,9 @@ bool ElectronCrashReporterClient::GetCrashDumpLocation(
base::FilePath* crash_dir) {
bool result = base::PathService::Get(electron::DIR_CRASH_DUMPS, crash_dir);
{
// If the DIR_CRASH_DUMPS path is overridden with
// app.setPath('crashDumps', ...) then the directory might not have been
// created.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (result && !base::PathExists(*crash_dir)) {
return base::CreateDirectory(*crash_dir);
@ -162,13 +165,6 @@ bool ElectronCrashReporterClient::GetCrashDumpLocation(
}
#endif
#if defined(OS_MAC) || defined(OS_LINUX)
bool ElectronCrashReporterClient::GetCrashMetricsLocation(
base::FilePath* metrics_dir) {
return base::PathService::Get(chrome::DIR_USER_DATA, metrics_dir);
}
#endif // OS_MAC || OS_LINUX
bool ElectronCrashReporterClient::IsRunningUnattended() {
return !collect_stats_consent_;
}

View file

@ -52,10 +52,6 @@ class ElectronCrashReporterClient : public crash_reporter::CrashReporterClient {
bool GetCrashDumpLocation(base::FilePath* crash_dir) override;
#endif
#if defined(OS_MAC) || defined(OS_LINUX)
bool GetCrashMetricsLocation(base::FilePath* metrics_dir) override;
#endif
bool IsRunningUnattended() override;
bool GetCollectStatsConsent() override;

View file

@ -58,6 +58,7 @@
#endif
#if !defined(MAS_BUILD)
#include "components/crash/core/app/crash_switches.h" // nogncheck
#include "components/crash/core/app/crashpad.h" // nogncheck
#include "components/crash/core/common/crash_key.h"
#include "components/crash/core/common/crash_keys.h"
@ -369,10 +370,20 @@ void ElectronMainDelegate::PreSandboxStartup() {
#endif
#if defined(OS_LINUX)
// Zygote needs to call InitCrashReporter() in RunZygote().
if (process_type != ::switches::kZygoteProcess && !process_type.empty()) {
ElectronCrashReporterClient::Create();
if (crash_reporter::IsCrashpadEnabled()) {
if (command_line->HasSwitch(
crash_reporter::switches::kCrashpadHandlerPid)) {
crash_reporter::InitializeCrashpad(false, process_type);
crash_reporter::SetFirstChanceExceptionHandler(
v8::TryHandleWebAssemblyTrapPosix);
}
} else {
breakpad::InitCrashReporter(process_type);
}
}
#endif
#if !defined(MAS_BUILD)
@ -466,7 +477,16 @@ void ElectronMainDelegate::ZygoteForked() {
base::CommandLine::ForCurrentProcess();
std::string process_type =
command_line->GetSwitchValueASCII(::switches::kProcessType);
if (crash_reporter::IsCrashpadEnabled()) {
if (command_line->HasSwitch(
crash_reporter::switches::kCrashpadHandlerPid)) {
crash_reporter::InitializeCrashpad(false, process_type);
crash_reporter::SetFirstChanceExceptionHandler(
v8::TryHandleWebAssemblyTrapPosix);
}
} else {
breakpad::InitCrashReporter(process_type);
}
// Reset the command line for the newly spawned process.
crash_keys::SetCrashKeysFromCommandLine(*command_line);

View file

@ -44,6 +44,7 @@
#include "base/guid.h"
#include "components/crash/core/app/breakpad_linux.h"
#include "components/crash/core/common/crash_keys.h"
#include "components/upload_list/combining_upload_list.h"
#include "v8/include/v8-wasm-trap-handler-posix.h"
#include "v8/include/v8.h"
#endif
@ -150,6 +151,18 @@ void Start(const std::string& submit_url,
? "node"
: command_line->GetSwitchValueASCII(::switches::kProcessType);
#if defined(OS_LINUX)
if (::crash_reporter::IsCrashpadEnabled()) {
for (const auto& pair : extra)
electron::crash_keys::SetCrashKey(pair.first, pair.second);
{
base::ThreadRestrictions::ScopedAllowIO allow_io;
::crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
}
if (ignore_system_crash_handler) {
crashpad::CrashpadInfo::GetCrashpadInfo()
->set_system_crash_reporter_forwarding(crashpad::TriState::kDisabled);
}
} else {
::crash_keys::SetMetricsClientIdFromGUID(GetClientId());
auto& global_crash_keys = GetGlobalCrashKeysMutable();
for (const auto& pair : global_extra) {
@ -160,6 +173,7 @@ void Start(const std::string& submit_url,
for (const auto& pair : global_extra)
electron::crash_keys::SetCrashKey(pair.first, pair.second);
breakpad::InitCrashReporter(process_type);
}
#elif defined(OS_MAC)
for (const auto& pair : extra)
electron::crash_keys::SetCrashKey(pair.first, pair.second);
@ -203,7 +217,20 @@ scoped_refptr<UploadList> CreateCrashUploadList() {
base::PathService::Get(electron::DIR_CRASH_DUMPS, &crash_dir_path);
base::FilePath upload_log_path =
crash_dir_path.AppendASCII(CrashUploadList::kReporterLogFilename);
return base::MakeRefCounted<TextLogUploadList>(upload_log_path);
scoped_refptr<UploadList> result =
base::MakeRefCounted<TextLogUploadList>(upload_log_path);
if (crash_reporter::IsCrashpadEnabled()) {
// Crashpad keeps the records of C++ crashes (segfaults, etc) in its
// internal database. The JavaScript error reporter writes JS error upload
// records to the older text format. Combine the two to present a complete
// list to the user.
// TODO(nornagon): what is "The JavaScript error reporter", and do we care
// about it?
std::vector<scoped_refptr<UploadList>> uploaders = {
base::MakeRefCounted<CrashUploadListCrashpad>(), std::move(result)};
result = base::MakeRefCounted<CombiningUploadList>(std::move(uploaders));
}
return result;
#endif // defined(OS_MAC) || defined(OS_WIN)
}

View file

@ -298,6 +298,12 @@ breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
}
int GetCrashSignalFD(const base::CommandLine& command_line) {
if (crash_reporter::IsCrashpadEnabled()) {
int fd;
pid_t pid;
return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
}
// Extensions have the same process type as renderers.
if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
@ -526,12 +532,28 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
#if defined(OS_LINUX)
bool enable_crash_reporter = false;
if (crash_reporter::IsCrashpadEnabled()) {
command_line->AppendSwitch(::switches::kEnableCrashpad);
enable_crash_reporter = true;
int fd;
pid_t pid;
if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
command_line->AppendSwitchASCII(
crash_reporter::switches::kCrashpadHandlerPid,
base::NumberToString(pid));
}
} else {
enable_crash_reporter = breakpad::IsCrashReporterEnabled();
}
if (enable_crash_reporter) {
std::string switch_value =
api::crash_reporter::GetClientId() + ",no_channel";
command_line->AppendSwitchASCII(::switches::kEnableCrashReporter,
switch_value);
if (!crash_reporter::IsCrashpadEnabled()) {
for (const auto& pair : api::crash_reporter::GetGlobalCrashKeys()) {
if (!switch_value.empty())
switch_value += ",";
@ -541,6 +563,7 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
}
command_line->AppendSwitchASCII(switches::kGlobalCrashKeys, switch_value);
}
}
#endif
// The zygote process is booted before JS runs, so DIR_USER_DATA isn't usable

View file

@ -138,10 +138,13 @@ function waitForNewFileInDir (dir: string): Promise<string[]> {
// TODO(nornagon): Fix tests on linux/arm.
ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_TESTS)('crashReporter module', function () {
for (const withLinuxCrashpad of (process.platform === 'linux' ? [false, true] : [false])) {
const crashpadExtraArgs = withLinuxCrashpad ? ['--enable-crashpad'] : [];
describe(withLinuxCrashpad ? '(with crashpad)' : '', () => {
describe('should send minidump', () => {
it('when renderer crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('renderer', port);
runCrashApp('renderer', port, crashpadExtraArgs);
const crash = await waitForCrash();
checkCrash('renderer', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
@ -149,7 +152,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
it('when sandboxed renderer crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('sandboxed-renderer', port);
runCrashApp('sandboxed-renderer', port, crashpadExtraArgs);
const crash = await waitForCrash();
checkCrash('renderer', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
@ -160,7 +163,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
// out why.
ifit(!isLinuxOnArm)('when main process crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('main', port);
runCrashApp('main', port, crashpadExtraArgs);
const crash = await waitForCrash();
checkCrash('browser', crash);
expect(crash.mainProcessSpecific).to.equal('mps');
@ -168,7 +171,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
ifit(!isLinuxOnArm)('when a node process crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('node', port);
runCrashApp('node', port, crashpadExtraArgs);
const crash = await waitForCrash();
checkCrash('node', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
@ -179,7 +182,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
for (const processType of ['main', 'renderer', 'sandboxed-renderer']) {
it(`when ${processType} crashes`, async () => {
const { port, waitForCrash } = await startServer();
runCrashApp(processType, port);
runCrashApp(processType, port, crashpadExtraArgs);
const crash = await waitForCrash();
expect(crash.guid).to.be.a('string');
});
@ -190,13 +193,13 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
let crash2Guid;
{
const { port, waitForCrash } = await startServer();
runCrashApp('main', port);
runCrashApp('main', port, crashpadExtraArgs);
const crash = await waitForCrash();
crash1Guid = crash.guid;
}
{
const { port, waitForCrash } = await startServer();
runCrashApp('main', port);
runCrashApp('main', port, crashpadExtraArgs);
const crash = await waitForCrash();
crash2Guid = crash.guid;
}
@ -207,7 +210,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
describe('with extra parameters', () => {
it('when renderer crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('renderer', port, ['--set-extra-parameters-in-renderer']);
runCrashApp('renderer', port, ['--set-extra-parameters-in-renderer', ...crashpadExtraArgs]);
const crash = await waitForCrash();
checkCrash('renderer', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
@ -217,7 +220,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
it('when sandboxed renderer crashes', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('sandboxed-renderer', port, ['--set-extra-parameters-in-renderer']);
runCrashApp('sandboxed-renderer', port, ['--set-extra-parameters-in-renderer', ...crashpadExtraArgs]);
const crash = await waitForCrash();
checkCrash('renderer', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
@ -226,7 +229,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
it('contains v8 crash keys when a v8 crash occurs', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
const { port, waitForCrash } = await startServer();
await remotely((port: number) => {
@ -268,7 +271,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
it('should truncate extra values longer than 5 * 4096 characters', async () => {
const { port, waitForCrash } = await startServer();
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
remotely((port: number) => {
require('electron').crashReporter.start({
submitURL: `http://127.0.0.1:${port}`,
@ -279,13 +282,13 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
setTimeout(() => process.crash());
}, port);
const crash = await waitForCrash();
expect(stitchLongCrashParam(crash, 'longParam')).to.have.lengthOf(160 * 127, 'crash should have truncated longParam');
expect(stitchLongCrashParam(crash, 'longParam')).to.have.lengthOf(160 * 127 + (withLinuxCrashpad ? 159 : 0), 'crash should have truncated longParam');
});
it('should omit extra keys with names longer than the maximum', async () => {
const kKeyLengthMax = 39;
const { port, waitForCrash } = await startServer();
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
remotely((port: number, kKeyLengthMax: number) => {
require('electron').crashReporter.start({
submitURL: `http://127.0.0.1:${port}`,
@ -313,35 +316,35 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
describe('globalExtra', () => {
ifit(!isLinuxOnArm)('should be sent with main process dumps', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('main', port, ['--add-global-param=globalParam:globalValue']);
runCrashApp('main', port, ['--add-global-param=globalParam:globalValue', ...crashpadExtraArgs]);
const crash = await waitForCrash();
expect(crash.globalParam).to.equal('globalValue');
});
it('should be sent with renderer process dumps', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('renderer', port, ['--add-global-param=globalParam:globalValue']);
runCrashApp('renderer', port, ['--add-global-param=globalParam:globalValue', ...crashpadExtraArgs]);
const crash = await waitForCrash();
expect(crash.globalParam).to.equal('globalValue');
});
it('should be sent with sandboxed renderer process dumps', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('sandboxed-renderer', port, ['--add-global-param=globalParam:globalValue']);
runCrashApp('sandboxed-renderer', port, ['--add-global-param=globalParam:globalValue', ...crashpadExtraArgs]);
const crash = await waitForCrash();
expect(crash.globalParam).to.equal('globalValue');
});
ifit(!isLinuxOnArm)('should not be overridden by extra in main process', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('main', port, ['--add-global-param=mainProcessSpecific:global']);
runCrashApp('main', port, ['--add-global-param=mainProcessSpecific:global', ...crashpadExtraArgs]);
const crash = await waitForCrash();
expect(crash.mainProcessSpecific).to.equal('global');
});
ifit(!isLinuxOnArm)('should not be overridden by extra in renderer process', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('main', port, ['--add-global-param=rendererSpecific:global']);
runCrashApp('main', port, ['--add-global-param=rendererSpecific:global', ...crashpadExtraArgs]);
const crash = await waitForCrash();
expect(crash.rendererSpecific).to.equal('global');
});
@ -351,38 +354,15 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
ifit(!isWindowsOnArm)('should not send a minidump when uploadToServer is false', async () => {
const { port, waitForCrash, getCrashes } = await startServer();
waitForCrash().then(() => expect.fail('expected not to receive a dump'));
await runCrashApp('renderer', port, ['--no-upload']);
await runCrashApp('renderer', port, ['--no-upload', ...crashpadExtraArgs]);
// wait a sec in case the crash reporter is about to upload a crash
await delay(1000);
expect(getCrashes()).to.have.length(0);
});
describe('start() option validation', () => {
it('requires that the submitURL option be specified', () => {
expect(() => {
crashReporter.start({} as any);
}).to.throw('submitURL must be specified when uploadToServer is true');
});
it('allows the submitURL option to be omitted when uploadToServer is false', () => {
expect(() => {
crashReporter.start({ uploadToServer: false } as any);
}).not.to.throw();
});
it('can be called twice', async () => {
const { remotely } = await startRemoteControlApp();
await expect(remotely(() => {
const { crashReporter } = require('electron');
crashReporter.start({ submitURL: 'http://127.0.0.1' });
crashReporter.start({ submitURL: 'http://127.0.0.1' });
})).to.be.fulfilled();
});
});
describe('getUploadedReports', () => {
it('returns an array of reports', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
await remotely(() => {
require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' });
});
@ -394,7 +374,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
// TODO(nornagon): re-enable on woa
ifdescribe(!isWindowsOnArm)('getLastCrashReport', () => {
it('returns the last uploaded report', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
const { port, waitForCrash } = await startServer();
// 0. clear the crash reports directory.
@ -428,35 +408,9 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
});
describe('getUploadToServer()', () => {
it('returns true when uploadToServer is set to true (by default)', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' }); });
const uploadToServer = await remotely(() => require('electron').crashReporter.getUploadToServer());
expect(uploadToServer).to.be.true();
});
it('returns false when uploadToServer is set to false in init', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1', uploadToServer: false }); });
const uploadToServer = await remotely(() => require('electron').crashReporter.getUploadToServer());
expect(uploadToServer).to.be.false();
});
it('is updated by setUploadToServer', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' }); });
await remotely(() => { require('electron').crashReporter.setUploadToServer(false); });
expect(await remotely(() => require('electron').crashReporter.getUploadToServer())).to.be.false();
await remotely(() => { require('electron').crashReporter.setUploadToServer(true); });
expect(await remotely(() => require('electron').crashReporter.getUploadToServer())).to.be.true();
});
});
describe('getParameters', () => {
it('returns all of the current parameters', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
await remotely(() => {
require('electron').crashReporter.start({
submitURL: 'http://127.0.0.1',
@ -468,7 +422,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
it('reflects added and removed parameters', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
await remotely(() => {
require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' });
require('electron').crashReporter.addExtraParameter('hello', 'world');
@ -487,7 +441,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
it('can be called in the renderer', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
const rendererParameters = await remotely(async () => {
const { crashReporter, BrowserWindow } = require('electron');
crashReporter.start({ submitURL: 'http://' });
@ -514,6 +468,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
stream.on('error', e => reject(e));
});
}
// TODO(nornagon): how to enable crashpad in a node child process...?
const child = childProcess.fork(path.join(__dirname, 'fixtures', 'module', 'print-crash-parameters.js'), [], { silent: true });
const output = await slurp(child.stdout!);
expect(JSON.parse(output)).to.deep.equal({ hello: 'world' });
@ -565,14 +520,14 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
for (const crashingProcess of processList) {
describe(`when ${crashingProcess} crashes`, () => {
it('stores crashes in the crash dump directory when uploadToServer: false', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
const crashesDir = await remotely(() => {
const { crashReporter, app } = require('electron');
crashReporter.start({ submitURL: 'http://127.0.0.1', uploadToServer: false, ignoreSystemCrashHandler: true });
return app.getPath('crashDumps');
});
let reportsDir = crashesDir;
if (process.platform === 'darwin') {
if (process.platform === 'darwin' || (process.platform === 'linux' && withLinuxCrashpad)) {
reportsDir = path.join(crashesDir, 'completed');
} else if (process.platform === 'win32') {
reportsDir = path.join(crashesDir, 'reports');
@ -581,7 +536,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
crash(crashingProcess, remotely);
const newFiles = await newFileAppeared;
expect(newFiles.length).to.be.greaterThan(0);
if (process.platform === 'linux') {
if (process.platform === 'linux' && !withLinuxCrashpad) {
if (crashingProcess === 'main') {
expect(newFiles[0]).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{8}-[0-9a-f]{8}\.dmp$/);
} else {
@ -595,7 +550,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
it('respects an overridden crash dump directory', async () => {
const { remotely } = await startRemoteControlApp();
const { remotely } = await startRemoteControlApp(crashpadExtraArgs);
const crashesDir = path.join(app.getPath('temp'), uuid.v4());
const remoteCrashesDir = await remotely((crashesDir: string) => {
const { crashReporter, app } = require('electron');
@ -606,7 +561,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
expect(remoteCrashesDir).to.equal(crashesDir);
let reportsDir = crashesDir;
if (process.platform === 'darwin') {
if (process.platform === 'darwin' || (process.platform === 'linux' && withLinuxCrashpad)) {
reportsDir = path.join(crashesDir, 'completed');
} else if (process.platform === 'win32') {
reportsDir = path.join(crashesDir, 'reports');
@ -615,7 +570,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
crash(crashingProcess, remotely);
const newFiles = await newFileAppeared;
expect(newFiles.length).to.be.greaterThan(0);
if (process.platform === 'linux') {
if (process.platform === 'linux' && !withLinuxCrashpad) {
if (crashingProcess === 'main') {
expect(newFiles[0]).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{8}-[0-9a-f]{8}\.dmp$/);
} else {
@ -630,6 +585,57 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
});
}
});
});
}
describe('start() option validation', () => {
it('requires that the submitURL option be specified', () => {
expect(() => {
crashReporter.start({} as any);
}).to.throw('submitURL must be specified when uploadToServer is true');
});
it('allows the submitURL option to be omitted when uploadToServer is false', () => {
expect(() => {
crashReporter.start({ uploadToServer: false } as any);
}).not.to.throw();
});
it('can be called twice', async () => {
const { remotely } = await startRemoteControlApp();
await expect(remotely(() => {
const { crashReporter } = require('electron');
crashReporter.start({ submitURL: 'http://127.0.0.1' });
crashReporter.start({ submitURL: 'http://127.0.0.1' });
})).to.be.fulfilled();
});
});
describe('getUploadToServer()', () => {
it('returns true when uploadToServer is set to true (by default)', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' }); });
const uploadToServer = await remotely(() => require('electron').crashReporter.getUploadToServer());
expect(uploadToServer).to.be.true();
});
it('returns false when uploadToServer is set to false in init', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1', uploadToServer: false }); });
const uploadToServer = await remotely(() => require('electron').crashReporter.getUploadToServer());
expect(uploadToServer).to.be.false();
});
it('is updated by setUploadToServer', async () => {
const { remotely } = await startRemoteControlApp();
await remotely(() => { require('electron').crashReporter.start({ submitURL: 'http://127.0.0.1' }); });
await remotely(() => { require('electron').crashReporter.setUploadToServer(false); });
expect(await remotely(() => require('electron').crashReporter.getUploadToServer())).to.be.false();
await remotely(() => { require('electron').crashReporter.setUploadToServer(true); });
expect(await remotely(() => require('electron').crashReporter.getUploadToServer())).to.be.true();
});
});
describe('when not started', () => {
it('does not prevent process from crashing', async () => {