Linux: Migrate from breakpad to crashpad (see issue #3249)

Renderer process crashes are currently only reported with `--no-sandbox`.
This commit is contained in:
Marshall Greenblatt 2022-03-15 15:42:15 -04:00
parent 8fc6aced6c
commit c38d62b233
12 changed files with 187 additions and 272 deletions

View File

@ -903,6 +903,7 @@ static_library("libcef_static") {
"//third_party/blink/public:blink", "//third_party/blink/public:blink",
"//third_party/brotli:dec", "//third_party/brotli:dec",
"//third_party/cld_3/src/src:cld_3", "//third_party/cld_3/src/src:cld_3",
"//third_party/crashpad/crashpad/handler",
"//third_party/hunspell", "//third_party/hunspell",
"//third_party/leveldatabase", "//third_party/leveldatabase",
"//third_party/libxml:libxml", "//third_party/libxml:libxml",
@ -975,6 +976,8 @@ static_library("libcef_static") {
"libcef/browser/osr/browser_platform_delegate_osr_linux.h", "libcef/browser/osr/browser_platform_delegate_osr_linux.h",
"libcef/browser/printing/print_dialog_linux.cc", "libcef/browser/printing/print_dialog_linux.cc",
"libcef/browser/printing/print_dialog_linux.h", "libcef/browser/printing/print_dialog_linux.h",
"libcef/common/util_linux.h",
"libcef/common/util_linux.cc",
] ]
if (ozone_platform_x11) { if (ozone_platform_x11) {
@ -1017,26 +1020,10 @@ static_library("libcef_static") {
] ]
} }
if (is_win || is_mac) {
deps += [ "//third_party/crashpad/crashpad/handler" ]
}
if (ozone_platform_x11) { if (ozone_platform_x11) {
deps += [ "//ui/events/devices/x11" ] deps += [ "//ui/events/devices/x11" ]
} }
if (is_posix && !is_mac) {
sources += [
"libcef/common/cef_crash_report_utils.cc",
"libcef/common/cef_crash_report_utils.h",
]
deps += [
"//components/crash/core/app",
"//components/crash/content/browser",
]
}
if (v8_use_external_startup_data && use_v8_context_snapshot) { if (v8_use_external_startup_data && use_v8_context_snapshot) {
deps += [ "//tools/v8_context_snapshot" ] deps += [ "//tools/v8_context_snapshot" ]
} }

View File

@ -143,17 +143,14 @@
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "url/gurl.h" #include "url/gurl.h"
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#include "base/debug/leak_annotations.h"
#include "chrome/common/chrome_paths.h"
#include "components/crash/content/browser/crash_handler_host_linux.h"
#include "components/crash/core/app/breakpad_linux.h"
#include "content/public/common/content_descriptors.h"
#endif
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
#include "net/ssl/client_cert_store_mac.h" #include "net/ssl/client_cert_store_mac.h"
#include "services/video_capture/public/mojom/constants.mojom.h" #include "services/video_capture/public/mojom/constants.mojom.h"
#elif BUILDFLAG(IS_POSIX)
#include "components/crash/core/app/crash_switches.h"
#include "components/crash/core/app/crashpad.h"
#include "content/public/common/content_descriptors.h"
#include "libcef/common/crash_reporting.h"
#endif #endif
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
@ -409,59 +406,13 @@ class CefQuotaPermissionContext : public content::QuotaPermissionContext {
}; };
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( int GetCrashSignalFD() {
const std::string& process_type) { if (!crash_reporting::Enabled())
base::FilePath dumps_path;
base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
{
ANNOTATE_SCOPED_MEMORY_LEAK;
// Uploads will only occur if a non-empty crash URL is specified in
// AlloyMainDelegate::InitCrashReporter.
breakpad::CrashHandlerHostLinux* crash_handler =
new breakpad::CrashHandlerHostLinux(process_type, dumps_path,
true /* upload */);
crash_handler->StartUploaderThread();
return crash_handler;
}
}
int GetCrashSignalFD(const base::CommandLine& command_line) {
if (!breakpad::IsCrashReporterEnabled())
return -1; return -1;
// Extensions have the same process type as renderers. int fd;
if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { pid_t pid;
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
if (!crash_handler)
crash_handler = CreateCrashHandlerHost("extension");
return crash_handler->GetDeathSignalSocket();
}
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
if (process_type == switches::kRendererProcess) {
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
if (!crash_handler)
crash_handler = CreateCrashHandlerHost(process_type);
return crash_handler->GetDeathSignalSocket();
}
if (process_type == switches::kPpapiPluginProcess) {
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
if (!crash_handler)
crash_handler = CreateCrashHandlerHost(process_type);
return crash_handler->GetDeathSignalSocket();
}
if (process_type == switches::kGpuProcess) {
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
if (!crash_handler)
crash_handler = CreateCrashHandlerHost(process_type);
return crash_handler->GetDeathSignalSocket();
}
return -1;
} }
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) #endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
@ -797,7 +748,7 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
} }
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
if (process_type == switches::kZygoteProcess) { if (process_type == switches::kZygoteProcess) {
if (browser_cmd->HasSwitch(switches::kBrowserSubprocessPath)) { if (browser_cmd->HasSwitch(switches::kBrowserSubprocessPath)) {
// Force use of the sub-process executable path for the zygote process. // Force use of the sub-process executable path for the zygote process.
@ -815,7 +766,17 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames, command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
base::size(kSwitchNames)); base::size(kSwitchNames));
} }
#endif // BUILDFLAG(IS_LINUX)
if (crash_reporting::Enabled()) {
int fd;
pid_t pid;
if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
command_line->AppendSwitchASCII(
crash_reporter::switches::kCrashpadHandlerPid,
base::NumberToString(pid));
}
}
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication(); CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
if (app.get()) { if (app.get()) {
@ -1132,17 +1093,17 @@ AlloyContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
return interceptors; return interceptors;
} }
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void AlloyContentBrowserClient::GetAdditionalMappedFilesForChildProcess( void AlloyContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line, const base::CommandLine& command_line,
int child_process_id, int child_process_id,
content::PosixFileDescriptorInfo* mappings) { content::PosixFileDescriptorInfo* mappings) {
int crash_signal_fd = GetCrashSignalFD(command_line); int crash_signal_fd = GetCrashSignalFD();
if (crash_signal_fd >= 0) { if (crash_signal_fd >= 0) {
mappings->Share(kCrashDumpSignal, crash_signal_fd); mappings->Share(kCrashDumpSignal, crash_signal_fd);
} }
} }
#endif // BUILDFLAG(IS_LINUX) #endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void AlloyContentBrowserClient::ExposeInterfacesToRenderer( void AlloyContentBrowserClient::ExposeInterfacesToRenderer(
service_manager::BinderRegistry* registry, service_manager::BinderRegistry* registry,

View File

@ -137,7 +137,7 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
const scoped_refptr<network::SharedURLLoaderFactory>& const scoped_refptr<network::SharedURLLoaderFactory>&
network_loader_factory) override; network_loader_factory) override;
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void GetAdditionalMappedFilesForChildProcess( void GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line, const base::CommandLine& command_line,
int child_process_id, int child_process_id,

View File

@ -21,12 +21,14 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "components/crash/core/app/crash_switches.h"
#include "content/app/content_main_runner_impl.h" #include "content/app/content_main_runner_impl.h"
#include "content/browser/scheduler/browser_task_executor.h" #include "content/browser/scheduler/browser_task_executor.h"
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#include "content/public/app/content_main_runner.h" #include "content/public/app/content_main_runner.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "third_party/crashpad/crashpad/handler/handler_main.h"
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
#include <Objbase.h> #include <Objbase.h>
@ -35,11 +37,6 @@
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
#endif #endif
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
#include "components/crash/core/app/crash_switches.h"
#include "third_party/crashpad/crashpad/handler/handler_main.h"
#endif
namespace { namespace {
enum class RuntimeType { enum class RuntimeType {
@ -65,16 +62,14 @@ std::unique_ptr<CefMainRunnerDelegate> MakeDelegate(
} }
} }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
// Based on components/crash/core/app/run_as_crashpad_handler_win.cc // Based on components/crash/core/app/run_as_crashpad_handler_win.cc
// Remove the "--type=crashpad-handler" command-line flag that will otherwise // Remove the "--type=crashpad-handler" command-line flag that will otherwise
// confuse the crashpad handler. // confuse the crashpad handler.
// Chrome uses an embedded crashpad handler on Windows only and imports this // Chrome uses an embedded crashpad handler on Windows only and imports this
// function via the existing "run_as_crashpad_handler" target defined in // function via the existing "run_as_crashpad_handler" target defined in
// components/crash/core/app/BUILD.gn. CEF uses an embedded handler on both // components/crash/core/app/BUILD.gn. CEF uses an embedded handler on all
// Windows and macOS so we define the function here instead of using the // platforms so we define the function here instead of using the existing
// existing target (because we can't use that target on macOS). // target (because we can't use that target on macOS).
int RunAsCrashpadHandler(const base::CommandLine& command_line) { int RunAsCrashpadHandler(const base::CommandLine& command_line) {
base::CommandLine::StringVector argv = command_line.argv(); base::CommandLine::StringVector argv = command_line.argv();
const base::CommandLine::StringType process_type = const base::CommandLine::StringType process_type =
@ -88,8 +83,8 @@ int RunAsCrashpadHandler(const base::CommandLine& command_line) {
}), }),
argv.end()); argv.end());
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_POSIX)
// HandlerMain on macOS uses the system version of getopt_long which expects // HandlerMain on POSIX uses the system version of getopt_long which expects
// the first argument to be the program name. // the first argument to be the program name.
argv.insert(argv.begin(), command_line.GetProgram().value()); argv.insert(argv.begin(), command_line.GetProgram().value());
#endif #endif
@ -111,8 +106,6 @@ int RunAsCrashpadHandler(const base::CommandLine& command_line) {
argv_as_utf8.get(), nullptr); argv_as_utf8.get(), nullptr);
} }
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
} // namespace } // namespace
// Used to run the UI on a separate thread. // Used to run the UI on a separate thread.
@ -327,13 +320,11 @@ int CefMainRunner::RunAsHelperProcess(const CefMainArgs& args,
int result; int result;
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
if (process_type == crash_reporter::switches::kCrashpadHandler) { if (process_type == crash_reporter::switches::kCrashpadHandler) {
result = RunAsCrashpadHandler(command_line); result = RunAsCrashpadHandler(command_line);
main_delegate->AfterExecuteProcess(); main_delegate->AfterExecuteProcess();
return result; return result;
} }
#endif
// Execute the secondary process. // Execute the secondary process.
content::ContentMainParams main_params( content::ContentMainParams main_params(

View File

@ -52,6 +52,8 @@
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
#include "libcef/common/util_mac.h" #include "libcef/common/util_mac.h"
#elif BUILDFLAG(IS_POSIX)
#include "libcef/common/util_linux.h"
#endif #endif
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
@ -94,8 +96,7 @@ bool AlloyMainDelegate::BasicStartupComplete(int* exit_code) {
command_line->GetSwitchValueASCII(switches::kProcessType); command_line->GetSwitchValueASCII(switches::kProcessType);
#if BUILDFLAG(IS_POSIX) #if BUILDFLAG(IS_POSIX)
// Read the crash configuration file. Platforms using Breakpad also add a // Read the crash configuration file. On Windows this is done from chrome_elf.
// command-line switch. On Windows this is done from chrome_elf.
crash_reporting::BasicStartupComplete(command_line); crash_reporting::BasicStartupComplete(command_line);
#endif #endif
@ -355,6 +356,8 @@ void AlloyMainDelegate::PreSandboxStartup() {
// Only override these paths when executing the main process. // Only override these paths when executing the main process.
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
util_mac::PreSandboxStartup(); util_mac::PreSandboxStartup();
#elif BUILDFLAG(IS_POSIX)
util_linux::PreSandboxStartup();
#endif #endif
resource_util::OverrideDefaultDownloadDir(); resource_util::OverrideDefaultDownloadDir();

View File

@ -24,6 +24,12 @@
#include "third_party/blink/public/common/switches.h" #include "third_party/blink/public/common/switches.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IS_MAC)
#include "libcef/common/util_mac.h"
#elif BUILDFLAG(IS_POSIX)
#include "libcef/common/util_linux.h"
#endif
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
#include "libcef/common/util_mac.h" #include "libcef/common/util_mac.h"
#endif #endif
@ -58,8 +64,7 @@ bool ChromeMainDelegateCef::BasicStartupComplete(int* exit_code) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(IS_POSIX) #if BUILDFLAG(IS_POSIX)
// Read the crash configuration file. Platforms using Breakpad also add a // Read the crash configuration file. On Windows this is done from chrome_elf.
// command-line switch. On Windows this is done from chrome_elf.
crash_reporting::BasicStartupComplete(command_line); crash_reporting::BasicStartupComplete(command_line);
#endif #endif
@ -143,11 +148,13 @@ void ChromeMainDelegateCef::PreSandboxStartup() {
const std::string& process_type = const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType); command_line->GetSwitchValueASCII(switches::kProcessType);
#if BUILDFLAG(IS_MAC)
if (process_type.empty()) { if (process_type.empty()) {
#if BUILDFLAG(IS_MAC)
util_mac::PreSandboxStartup(); util_mac::PreSandboxStartup();
#elif BUILDFLAG(IS_POSIX)
util_linux::PreSandboxStartup();
#endif
} }
#endif // BUILDFLAG(IS_MAC)
// Since this may be configured via CefSettings we override the value on // Since this may be configured via CefSettings we override the value on
// all platforms. We can't use the default implementation on macOS because // all platforms. We can't use the default implementation on macOS because

View File

@ -615,22 +615,6 @@ void CefCrashReporterClient::GetProductNameAndVersion(std::string* product_name,
*version = product_version_; *version = product_version_;
} }
#if !BUILDFLAG(IS_MAC)
base::FilePath CefCrashReporterClient::GetReporterLogFilename() {
return base::FilePath(FILE_PATH_LITERAL("uploads.log"));
}
bool CefCrashReporterClient::EnableBreakpadForProcess(
const std::string& process_type) {
return process_type == switches::kRendererProcess ||
process_type == switches::kPpapiPluginProcess ||
process_type == switches::kZygoteProcess ||
process_type == switches::kGpuProcess;
}
#endif // !BUILDFLAG(IS_MAC)
bool CefCrashReporterClient::GetCrashDumpLocation(base::FilePath* crash_dir) { bool CefCrashReporterClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
// location to write breakpad crash dumps can be set. // location to write breakpad crash dumps can be set.
@ -654,21 +638,11 @@ bool CefCrashReporterClient::GetCollectStatsInSample() {
return true; return true;
} }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
bool CefCrashReporterClient::ReportingIsEnforcedByPolicy( bool CefCrashReporterClient::ReportingIsEnforcedByPolicy(
bool* crashpad_enabled) { bool* crashpad_enabled) {
*crashpad_enabled = true; *crashpad_enabled = true;
return true; return true;
} }
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
bool CefCrashReporterClient::IsRunningUnattended() {
// Crash upload will only be enabled with Breakpad on Linux if this method
// returns false.
return false;
}
#endif
std::string CefCrashReporterClient::GetUploadUrl() { std::string CefCrashReporterClient::GetUploadUrl() {
return server_url_; return server_url_;
@ -721,13 +695,6 @@ bool CefCrashReporterClient::EnableBrowserCrashForwarding() {
} }
#endif #endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
CefCrashReporterClient::ParameterMap CefCrashReporterClient::FilterParameters(
const ParameterMap& parameters) {
return crash_report_utils::FilterParameters(parameters);
}
#endif
// The new Crashpad Annotation API requires that annotations be declared using // The new Crashpad Annotation API requires that annotations be declared using
// static storage. We work around this limitation by defining a fixed amount of // static storage. We work around this limitation by defining a fixed amount of
// storage for each key size and later substituting the actual key name during // storage for each key size and later substituting the actual key name during

View File

@ -57,23 +57,13 @@ class CefCrashReporterClient : public crash_reporter::CrashReporterClient {
void GetProductNameAndVersion(std::string* product_name, void GetProductNameAndVersion(std::string* product_name,
std::string* version, std::string* version,
std::string* channel) override; std::string* channel) override;
#if !BUILDFLAG(IS_MAC)
base::FilePath GetReporterLogFilename() override;
bool EnableBreakpadForProcess(const std::string& process_type) override;
#endif
bool GetCrashDumpLocation(base::FilePath* crash_dir) override; bool GetCrashDumpLocation(base::FilePath* crash_dir) override;
#endif // BUILDFLAG(IS_POSIX) #endif // BUILDFLAG(IS_POSIX)
// All of these methods must return true to enable crash report upload. // All of these methods must return true to enable crash report upload.
bool GetCollectStatsConsent() override; bool GetCollectStatsConsent() override;
bool GetCollectStatsInSample() override; bool GetCollectStatsInSample() override;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
bool ReportingIsEnforcedByPolicy(bool* crashpad_enabled) override; bool ReportingIsEnforcedByPolicy(bool* crashpad_enabled) override;
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
bool IsRunningUnattended() override;
#endif
std::string GetUploadUrl() override; std::string GetUploadUrl() override;
void GetCrashOptionalArguments(std::vector<std::string>* arguments) override; void GetCrashOptionalArguments(std::vector<std::string>* arguments) override;
@ -87,10 +77,6 @@ class CefCrashReporterClient : public crash_reporter::CrashReporterClient {
bool EnableBrowserCrashForwarding() override; bool EnableBrowserCrashForwarding() override;
#endif #endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
ParameterMap FilterParameters(const ParameterMap& parameters) override;
#endif
// Set or clear a crash key value. // Set or clear a crash key value.
bool SetCrashKeyValue(const base::StringPiece& key, bool SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value); const base::StringPiece& value);

View File

@ -22,21 +22,16 @@
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "components/crash/core/app/crashpad.h"
#include "components/crash/core/common/crash_keys.h" #include "components/crash/core/common/crash_keys.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#endif #endif
#if BUILDFLAG(IS_POSIX) #if BUILDFLAG(IS_POSIX)
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "components/crash/core/app/crashpad.h"
#include "libcef/common/crash_reporter_client.h" #include "libcef/common/crash_reporter_client.h"
#endif #endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#include "components/crash/core/app/breakpad_linux.h"
#include "v8/include/v8-wasm-trap-handler-posix.h"
#endif
namespace crash_reporting { namespace crash_reporting {
namespace { namespace {
@ -131,11 +126,10 @@ void InitCrashReporter(const base::CommandLine& command_line,
g_crash_reporting_enabled = true; g_crash_reporting_enabled = true;
#else // !BUILDFLAG(IS_MAC) #else // !BUILDFLAG(IS_MAC)
if (process_type != switches::kZygoteProcess) { if (process_type != switches::kZygoteProcess) {
// Crash reporting for subprocesses created using the zygote will be // Crash reporting for subprocesses created using the zygote will be
// initialized in ZygoteForked. // initialized in ZygoteForked.
breakpad::InitCrashReporter(process_type); crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
g_crash_reporting_enabled = true; g_crash_reporting_enabled = true;
} }
@ -196,10 +190,8 @@ void BasicStartupComplete(base::CommandLine* command_line) {
CefCrashReporterClient* crash_client = g_crash_reporter_client.Pointer(); CefCrashReporterClient* crash_client = g_crash_reporter_client.Pointer();
if (crash_client->ReadCrashConfigFile()) { if (crash_client->ReadCrashConfigFile()) {
#if !BUILDFLAG(IS_MAC) #if !BUILDFLAG(IS_MAC)
// Breakpad requires this switch. // Crashpad requires this switch on Linux.
command_line->AppendSwitch(switches::kEnableCrashReporter); command_line->AppendSwitch(switches::kEnableCrashpad);
breakpad::SetFirstChanceExceptionHandler(v8::TryHandleWebAssemblyTrapPosix);
#endif #endif
} }
} }
@ -232,8 +224,8 @@ void ZygoteForked(base::CommandLine* command_line,
const std::string& process_type) { const std::string& process_type) {
CefCrashReporterClient* crash_client = g_crash_reporter_client.Pointer(); CefCrashReporterClient* crash_client = g_crash_reporter_client.Pointer();
if (crash_client->HasCrashConfigFile()) { if (crash_client->HasCrashConfigFile()) {
// Breakpad requires this switch. // Crashpad requires this switch on Linux.
command_line->AppendSwitch(switches::kEnableCrashReporter); command_line->AppendSwitch(switches::kEnableCrashpad);
} }
InitCrashReporter(*command_line, process_type); InitCrashReporter(*command_line, process_type);

View File

@ -0,0 +1,34 @@
// Copyright 2022 The Chromium Embedded Framework Authors. Portions copyright
// 2011 The Chromium Authors. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
#include "libcef/common/util_linux.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
namespace util_linux {
namespace {
void OverrideChildProcessPath() {
base::FilePath child_process_path =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kBrowserSubprocessPath);
if (child_process_path.empty())
return;
// Used by ChildProcessHost::GetChildPath and PlatformCrashpadInitialization.
base::PathService::Override(content::CHILD_PROCESS_EXE, child_process_path);
}
} // namespace
void PreSandboxStartup() {
OverrideChildProcessPath();
}
} // namespace util_linux

View File

@ -0,0 +1,16 @@
// Copyright 2022 The Chromium Embedded Framework Authors. Portions copyright
// 2011 The Chromium Authors. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
#ifndef CEF_LIBCEF_COMMON_UTIL_LINUX_H_
#define CEF_LIBCEF_COMMON_UTIL_LINUX_H_
#pragma once
namespace util_linux {
// Called from MainDelegate::PreSandboxStartup for the main process.
void PreSandboxStartup();
} // namespace util_linux
#endif // CEF_LIBCEF_COMMON_UTIL_LINUX_H_

View File

@ -135,98 +135,8 @@ index e2d53ac83dde0..6ac76e407a748 100644
// Sets the kNumSwitches key and the set of keys named using kSwitchFormat based // Sets the kNumSwitches key and the set of keys named using kSwitchFormat based
// on the given |command_line|. // on the given |command_line|.
void SetCrashKeysFromCommandLine(const base::CommandLine& command_line); void SetCrashKeysFromCommandLine(const base::CommandLine& command_line);
diff --git components/crash/core/app/breakpad_linux.cc components/crash/core/app/breakpad_linux.cc
index 823e49a234e3d..3f0f95a330bf4 100644
--- components/crash/core/app/breakpad_linux.cc
+++ components/crash/core/app/breakpad_linux.cc
@@ -29,6 +29,7 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
+#include "base/debug/leak_annotations.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/linux_util.h"
@@ -721,7 +722,7 @@ bool CrashDone(const MinidumpDescriptor& minidump,
info.process_type_length = 7;
info.distro = base::g_linux_distro;
info.distro_length = my_strlen(base::g_linux_distro);
- info.upload = upload;
+ info.upload = upload && g_upload_url;
info.process_start_time = g_process_start_time;
info.oom_size = base::g_oom_size;
info.pid = g_pid;
@@ -1735,10 +1736,27 @@ void HandleCrashDump(const BreakpadInfo& info) {
GetCrashReporterClient()->GetProductNameAndVersion(&product_name, &version);
writer.AddBoundary();
- writer.AddPairString("prod", product_name);
+ writer.AddPairString("product", product_name);
+ writer.AddBoundary();
+ writer.AddPairString("version", version);
writer.AddBoundary();
- writer.AddPairString("ver", version);
+
+#if defined(ARCH_CPU_ARM_FAMILY)
+#if defined(ARCH_CPU_32_BITS)
+ const char* platform = "linuxarm";
+#elif defined(ARCH_CPU_64_BITS)
+ const char* platform = "linuxarm64";
+#endif
+#else
+#if defined(ARCH_CPU_32_BITS)
+ const char* platform = "linux32";
+#elif defined(ARCH_CPU_64_BITS)
+ const char* platform = "linux64";
+#endif
+#endif // defined(ARCH_CPU_ARM_FAMILY)
+ writer.AddPairString("platform", platform);
writer.AddBoundary();
+
if (info.pid > 0) {
char pid_value_buf[kUint64StringSize];
uint64_t pid_value_len = my_uint64_len(info.pid);
@@ -1855,6 +1873,9 @@ void HandleCrashDump(const BreakpadInfo& info) {
crash_reporter::internal::TransitionalCrashKeyStorage;
CrashKeyStorage::Iterator crash_key_iterator(*info.crash_keys);
const CrashKeyStorage::Entry* entry;
+
+ crash_reporter::CrashReporterClient::ParameterMap parameters;
+
while ((entry = crash_key_iterator.Next())) {
size_t key_size, value_size;
// Check for malformed messages.
@@ -1865,7 +1886,13 @@ void HandleCrashDump(const BreakpadInfo& info) {
? CrashKeyStorage::value_size - 1
: my_strlen(entry->value);
- writer.AddPairData(entry->key, key_size, entry->value, value_size);
+ parameters.insert(std::make_pair(std::string{entry->key, key_size}, std::string{entry->value, value_size}));
+ }
+ if (!parameters.empty())
+ parameters = GetCrashReporterClient()->FilterParameters(parameters);
+
+ for (const auto& param : parameters) {
+ writer.AddPairData(param.first.data(), param.first.size(), param.second.data(), param.second.size());
writer.AddBoundary();
writer.Flush();
}
diff --git components/crash/core/app/breakpad_linux.h components/crash/core/app/breakpad_linux.h
index 2f0d4c555506a..c537846b21568 100644
--- components/crash/core/app/breakpad_linux.h
+++ components/crash/core/app/breakpad_linux.h
@@ -20,6 +20,9 @@ extern void InitCrashReporter(const std::string& process_type);
// Sets the product/distribution channel crash key.
void SetChannelCrashKey(const std::string& channel);
+// Set the crash server URL.
+void SetCrashServerURL(const std::string& url);
+
#if BUILDFLAG(IS_ANDROID)
extern void InitCrashKeysForTesting();
diff --git components/crash/core/app/crash_reporter_client.cc components/crash/core/app/crash_reporter_client.cc diff --git components/crash/core/app/crash_reporter_client.cc components/crash/core/app/crash_reporter_client.cc
index 82b7f241e2618..d3cd5524bb253 100644 index 82b7f241e2618..525f1efe5aa6a 100644
--- components/crash/core/app/crash_reporter_client.cc --- components/crash/core/app/crash_reporter_client.cc
+++ components/crash/core/app/crash_reporter_client.cc +++ components/crash/core/app/crash_reporter_client.cc
@@ -89,7 +89,7 @@ bool CrashReporterClient::GetShouldDumpLargerDumps() { @@ -89,7 +89,7 @@ bool CrashReporterClient::GetShouldDumpLargerDumps() {
@ -283,23 +193,18 @@ index 82b7f241e2618..d3cd5524bb253 100644
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
unsigned int CrashReporterClient::GetCrashDumpPercentage() { unsigned int CrashReporterClient::GetCrashDumpPercentage() {
return 100; return 100;
@@ -203,9 +227,11 @@ bool CrashReporterClient::ShouldMonitorCrashHandlerExpensively() { @@ -203,9 +227,4 @@ bool CrashReporterClient::ShouldMonitorCrashHandlerExpensively() {
return false; return false;
} }
-bool CrashReporterClient::EnableBreakpadForProcess( -bool CrashReporterClient::EnableBreakpadForProcess(
- const std::string& process_type) { - const std::string& process_type) {
- return false; - return false;
+#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) -}
+CrashReporterClient::ParameterMap -
+CrashReporterClient::FilterParameters(const ParameterMap& parameters) {
+ return parameters;
}
+#endif
} // namespace crash_reporter } // namespace crash_reporter
diff --git components/crash/core/app/crash_reporter_client.h components/crash/core/app/crash_reporter_client.h diff --git components/crash/core/app/crash_reporter_client.h components/crash/core/app/crash_reporter_client.h
index 24e53fa62c2c4..68011566b5723 100644 index 24e53fa62c2c4..ffc72f79d67b0 100644
--- components/crash/core/app/crash_reporter_client.h --- components/crash/core/app/crash_reporter_client.h
+++ components/crash/core/app/crash_reporter_client.h +++ components/crash/core/app/crash_reporter_client.h
@@ -5,7 +5,9 @@ @@ -5,7 +5,9 @@
@ -337,7 +242,7 @@ index 24e53fa62c2c4..68011566b5723 100644
#endif #endif
// The location where minidump files should be written. Returns true if // The location where minidump files should be written. Returns true if
@@ -206,6 +210,27 @@ class CrashReporterClient { @@ -206,6 +210,20 @@ class CrashReporterClient {
// Returns true if breakpad should run in the given process type. // Returns true if breakpad should run in the given process type.
virtual bool EnableBreakpadForProcess(const std::string& process_type); virtual bool EnableBreakpadForProcess(const std::string& process_type);
@ -354,13 +259,6 @@ index 24e53fa62c2c4..68011566b5723 100644
+ // Returns true if forwarding of crashes to the system crash reporter is + // Returns true if forwarding of crashes to the system crash reporter is
+ // enabled for the browser process. + // enabled for the browser process.
+ virtual bool EnableBrowserCrashForwarding(); + virtual bool EnableBrowserCrashForwarding();
+#endif
+
+#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
+ // Provides an oportunity to modify the parameters that will be sent with a
+ // crash upload.
+ using ParameterMap = std::map<std::string, std::string>;
+ virtual ParameterMap FilterParameters(const ParameterMap& parameters);
+#endif +#endif
}; };
@ -379,6 +277,79 @@ index 6da6be46cee4a..5e3067c081867 100644
crashpad::CrashpadInfo::GetCrashpadInfo() crashpad::CrashpadInfo::GetCrashpadInfo()
->set_system_crash_reporter_forwarding(crashpad::TriState::kDisabled); ->set_system_crash_reporter_forwarding(crashpad::TriState::kDisabled);
} }
diff --git components/crash/core/app/crashpad_linux.cc components/crash/core/app/crashpad_linux.cc
index dc2b18b322350..be84c0d0d1d7a 100644
--- components/crash/core/app/crashpad_linux.cc
+++ components/crash/core/app/crashpad_linux.cc
@@ -23,6 +23,7 @@
#include "components/crash/core/app/crash_reporter_client.h"
#include "components/crash/core/app/crash_switches.h"
#include "content/public/common/content_descriptors.h"
+#include "content/public/common/content_paths.h"
#include "sandbox/linux/services/namespace_sandbox.h"
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
#include "third_party/crashpad/crashpad/client/crashpad_info.h"
@@ -117,11 +118,10 @@ bool PlatformCrashpadInitialization(
crash_reporter_client->GetCrashDumpLocation(database_path);
crash_reporter_client->GetCrashMetricsLocation(&metrics_path);
+ // Use the same main (default) or subprocess helper exe.
base::FilePath handler_path;
- if (!base::PathService::Get(base::DIR_EXE, &handler_path)) {
- return false;
- }
- handler_path = handler_path.Append("chrome_crashpad_handler");
+ base::PathService::Get(content::CHILD_PROCESS_EXE, &handler_path);
+ DCHECK(!handler_path.empty());
// When --use-cros-crash-reporter is set (below), the handler passes dumps
// to ChromeOS's /sbin/crash_reporter which in turn passes the dump to
@@ -138,8 +138,8 @@ bool PlatformCrashpadInitialization(
&product_version, &channel);
std::map<std::string, std::string> annotations;
- annotations["prod"] = product_name;
- annotations["ver"] = product_version;
+ annotations["product"] = product_name;
+ annotations["version"] = product_version;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Empty means stable.
@@ -156,7 +156,20 @@ bool PlatformCrashpadInitialization(
annotations["channel"] = channel;
}
- annotations["plat"] = std::string("Linux");
+#if defined(ARCH_CPU_ARM_FAMILY)
+#if defined(ARCH_CPU_32_BITS)
+ const char* platform = "linuxarm";
+#elif defined(ARCH_CPU_64_BITS)
+ const char* platform = "linuxarm64";
+#endif
+#else
+#if defined(ARCH_CPU_32_BITS)
+ const char* platform = "linux32";
+#elif defined(ARCH_CPU_64_BITS)
+ const char* platform = "linux64";
+#endif
+#endif // defined(ARCH_CPU_ARM_FAMILY)
+ annotations["platform"] = platform;
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// "build_time_millis" is used on LaCros chrome to determine when to stop
@@ -201,6 +214,12 @@ bool PlatformCrashpadInitialization(
}
#endif
+ // Since we're using the same main or subprocess helper exe we must specify
+ // the process type.
+ arguments.push_back(std::string("--type=") + switches::kCrashpadHandler);
+
+ crash_reporter_client->GetCrashOptionalArguments(&arguments);
+
bool result =
client.StartHandler(handler_path, *database_path, metrics_path, url,
annotations, arguments, false, false);
diff --git components/crash/core/app/crashpad_mac.mm components/crash/core/app/crashpad_mac.mm diff --git components/crash/core/app/crashpad_mac.mm components/crash/core/app/crashpad_mac.mm
index dc041c43371fd..1d060ae55c586 100644 index dc041c43371fd..1d060ae55c586 100644
--- components/crash/core/app/crashpad_mac.mm --- components/crash/core/app/crashpad_mac.mm