fix: use crashpad on Windows (#18483)

* Initial changes to use crashpad for windows

* Remove crashpad patch

* Report error when failed to connect pipe

* Allow crashpad to communicate with named pipe

* Add patch to make crashpad named pipe work

* Windows also needs crashReporter on main process

* Call SetUnhandledExceptionFilter in node process

Node can also use crash reporter.

* Do not treat node process as browser process

* No more need to manually start crash service

* Use base::StringPrintf for better readbility

* Print error when pipe name not available

* Make sure pipe name is updated

Note that the crashpad may be started after renderer process gets
created.

* Fix some tests

* Update node

* Exclude crashpad files on Linux and MAS

* Fix lint warning

* Remove unused checks

* kCrashpadPipeName is only available on Windows

* Fix uploadToServer tests

* Fix extra params tests

* Fix getCrashesDirectory tests

* Run crashReporter tests on CI

* Style fixes

* Update crashreporter docs

* Rename InitBreakpad to Init

* Add comment for process_type_.empty() and UTF16ToASCII to UTF16ToUTF8.

* Update build.gn include crashpad headers

* Address comment https://github.com/electron/electron/pull/18483#discussion_r290887898

* Avoid using api::WebContents

* Put kRunAsNode in atom_constants

* Remove duplicate settings on upload params

* Fix building on macOS

* Update description for crashpad_pid_check.patch
This commit is contained in:
Nitish Sakhawalkar 2019-06-12 23:42:21 -07:00 committed by Cheng Zhao
parent ddec3c0e78
commit f98454e5dd
39 changed files with 561 additions and 812 deletions

View file

@ -4,6 +4,7 @@
#include "atom/app/atom_main.h"
#include <algorithm>
#include <cstdlib>
#include <memory>
#include <vector>
@ -39,6 +40,7 @@
#include "atom/app/node_main.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/atom_constants.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "electron/buildflags/buildflags.h"
@ -49,10 +51,6 @@
namespace {
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
#endif
ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
#if defined(OS_WIN)
size_t required_size;
@ -86,6 +84,11 @@ void FixStdioStreams() {
} // namespace
#if defined(OS_WIN)
namespace crash_reporter {
extern const char kCrashpadProcess[];
}
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
struct Arguments {
int argc = 0;
@ -122,7 +125,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
#endif
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
bool run_as_node = IsEnvSet(kRunAsNode);
bool run_as_node = IsEnvSet(atom::kRunAsNode);
#else
bool run_as_node = false;
#endif
@ -148,13 +151,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
atexit([]() { OnThreadExit(nullptr, DLL_THREAD_DETACH, nullptr); });
#endif
std::vector<char*> argv(arguments.argc);
std::transform(arguments.argv, arguments.argv + arguments.argc, argv.begin(),
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (run_as_node) {
std::vector<char*> argv(arguments.argc);
std::transform(
arguments.argv, arguments.argv + arguments.argc, argv.begin(),
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });
base::AtExitManager atexit_manager;
base::i18n::InitializeICU();
auto ret = atom::NodeMain(argv.size(), argv.data());
@ -163,8 +164,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
}
#endif
if (IsEnvSet("ELECTRON_INTERNAL_CRASH_SERVICE")) {
return crash_service::Main(cmd);
base::CommandLine::Init(argv.size(), argv.data());
const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
if (cmd_line.GetSwitchValueASCII("type") ==
crash_reporter::kCrashpadProcess) {
return crash_service::Main(&argv);
}
if (!atom::CheckCommandLineArguments(arguments.argc, arguments.argv))
@ -187,7 +191,7 @@ int main(int argc, char* argv[]) {
FixStdioStreams();
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
base::i18n::InitializeICU();
base::AtExitManager atexit_manager;
return atom::NodeMain(argc, argv);
@ -208,7 +212,7 @@ int main(int argc, char* argv[]) {
FixStdioStreams();
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
return AtomInitializeICUandStartNode(argc, argv);
}
#endif