2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2015-11-06 10:52:09 -08:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "handler/handler_main.h"
|
|
|
|
|
|
2017-02-07 13:55:48 -05:00
|
|
|
|
#include <errno.h>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <getopt.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include <stdint.h>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <stdlib.h>
|
2017-02-07 13:55:48 -05:00
|
|
|
|
#include <sys/types.h>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
#include <algorithm>
|
2022-02-02 14:02:27 -08:00
|
|
|
|
#include <atomic>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <map>
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <string>
|
2015-12-09 17:36:32 -05:00
|
|
|
|
#include <utility>
|
2017-02-22 13:39:46 -05:00
|
|
|
|
#include <vector>
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
2015-11-09 16:29:25 -05:00
|
|
|
|
#include "base/auto_reset.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
|
#include "base/files/scoped_file.h"
|
|
|
|
|
#include "base/logging.h"
|
2016-09-16 13:21:50 -07:00
|
|
|
|
#include "base/metrics/persistent_histogram_allocator.h"
|
2015-11-09 16:29:25 -05:00
|
|
|
|
#include "base/scoped_generic.h"
|
2018-02-20 15:03:14 -08:00
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
2017-04-04 14:26:52 -04:00
|
|
|
|
#include "base/strings/stringprintf.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
|
#include "build/build_config.h"
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#include "build/chromeos_buildflags.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "client/crash_report_database.h"
|
|
|
|
|
#include "client/crashpad_client.h"
|
2017-04-04 14:26:52 -04:00
|
|
|
|
#include "client/crashpad_info.h"
|
2016-01-05 15:09:00 -05:00
|
|
|
|
#include "client/prune_crash_reports.h"
|
2017-04-04 14:26:52 -04:00
|
|
|
|
#include "client/simple_string_dictionary.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "handler/crash_report_upload_thread.h"
|
2016-01-05 15:09:00 -05:00
|
|
|
|
#include "handler/prune_crash_reports_thread.h"
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include "tools/tool_support.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "util/file/file_io.h"
|
2018-02-20 15:03:14 -08:00
|
|
|
|
#include "util/misc/address_types.h"
|
2017-02-07 13:55:48 -05:00
|
|
|
|
#include "util/misc/metrics.h"
|
2017-04-04 10:08:56 -04:00
|
|
|
|
#include "util/misc/paths.h"
|
2017-02-07 13:55:48 -05:00
|
|
|
|
#include "util/numeric/in_range_cast.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "util/stdlib/map_insert.h"
|
|
|
|
|
#include "util/stdlib/string_number_conversion.h"
|
|
|
|
|
#include "util/string/split_string.h"
|
|
|
|
|
#include "util/synchronization/semaphore.h"
|
|
|
|
|
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
#include "handler/linux/cros_crash_report_exception_handler.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "handler/linux/crash_report_exception_handler.h"
|
|
|
|
|
#include "handler/linux/exception_handler_server.h"
|
|
|
|
|
#include "util/posix/signals.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <libgen.h>
|
2015-11-09 16:29:25 -05:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
2023-08-16 16:30:40 -04:00
|
|
|
|
#include "base/apple/scoped_mach_port.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "handler/mac/crash_report_exception_handler.h"
|
|
|
|
|
#include "handler/mac/exception_handler_server.h"
|
2017-04-18 11:50:39 -04:00
|
|
|
|
#include "handler/mac/file_limit_annotation.h"
|
2020-04-17 11:29:09 -04:00
|
|
|
|
#include "util/mach/bootstrap.h"
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "util/mach/child_port_handshake.h"
|
|
|
|
|
#include "util/posix/close_stdio.h"
|
2017-03-01 10:00:59 -05:00
|
|
|
|
#include "util/posix/signals.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include <windows.h>
|
2015-11-09 16:29:25 -05:00
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
#include "handler/win/crash_report_exception_handler.h"
|
|
|
|
|
#include "util/win/exception_handler_server.h"
|
|
|
|
|
#include "util/win/handle.h"
|
2016-10-21 13:08:18 -07:00
|
|
|
|
#include "util/win/initial_client_data.h"
|
2017-02-22 13:39:46 -05:00
|
|
|
|
#include "util/win/session_end_watcher.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
|
|
|
|
|
BUILDFLAG(IS_ANDROID)
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#define ATTACHMENTS_SUPPORTED 1
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
|
|
|
|
|
// BUILDFLAG(IS_ANDROID)
|
2020-08-03 13:39:14 -07:00
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
void Usage(const base::FilePath& me) {
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format off
|
2015-11-06 10:52:09 -08:00
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Usage: %" PRFilePath " [OPTION]...\n"
|
|
|
|
|
"Crashpad's exception handler server.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" --annotation=KEY=VALUE set a process annotation in each crash report\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#if defined(ATTACHMENTS_SUPPORTED)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format off
|
2020-06-24 09:03:47 +02:00
|
|
|
|
" --attachment=FILE_PATH attach specified file to each crash report\n"
|
|
|
|
|
" at the time of the crash\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#endif // ATTACHMENTS_SUPPORTED
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format off
|
2015-11-06 10:52:09 -08:00
|
|
|
|
" --database=PATH store the crash report database at PATH\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
|
|
|
|
// clang-format off
|
2015-11-06 10:52:09 -08:00
|
|
|
|
" --handshake-fd=FD establish communication with the client over FD\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
|
// clang-format off
|
2016-10-21 13:08:18 -07:00
|
|
|
|
" --initial-client-data=HANDLE_request_crash_dump,\n"
|
|
|
|
|
" HANDLE_request_non_crash_dump,\n"
|
|
|
|
|
" HANDLE_non_crash_dump_completed,\n"
|
|
|
|
|
" HANDLE_pipe,\n"
|
|
|
|
|
" HANDLE_client_process,\n"
|
|
|
|
|
" Address_crash_exception_information,\n"
|
|
|
|
|
" Address_non_crash_exception_information,\n"
|
|
|
|
|
" Address_debug_critical_section\n"
|
|
|
|
|
" use precreated data to register initial client\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
|
|
|
|
// clang-format off
|
2019-05-01 22:19:21 -07:00
|
|
|
|
" --initial-client-fd=FD a socket connected to a client.\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) ||
|
|
|
|
|
// BUILDFLAG(IS_CHROMEOS)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
|
|
|
|
// clang-format off
|
2017-04-04 10:08:56 -04:00
|
|
|
|
" --mach-service=SERVICE register SERVICE with the bootstrap server\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
// clang-format off
|
2016-09-16 13:21:50 -07:00
|
|
|
|
" --metrics-dir=DIR store metrics files in DIR (only in Chromium)\n"
|
2017-04-04 10:08:56 -04:00
|
|
|
|
" --monitor-self run a second handler to catch crashes in the first\n"
|
2017-04-04 14:26:52 -04:00
|
|
|
|
" --monitor-self-annotation=KEY=VALUE\n"
|
|
|
|
|
" set a module annotation in the handler\n"
|
2017-04-04 10:08:56 -04:00
|
|
|
|
" --monitor-self-argument=ARGUMENT\n"
|
|
|
|
|
" provide additional arguments to the second handler\n"
|
2017-09-28 09:53:39 -07:00
|
|
|
|
" --no-identify-client-via-url\n"
|
|
|
|
|
" when uploading crash report, don't add\n"
|
|
|
|
|
" client-identifying arguments to URL\n"
|
2017-04-14 14:50:11 -04:00
|
|
|
|
" --no-periodic-tasks don't scan for new reports or prune the database\n"
|
2016-01-06 09:59:54 -08:00
|
|
|
|
" --no-rate-limit don't rate limit crash uploads\n"
|
2017-02-15 19:54:19 -05:00
|
|
|
|
" --no-upload-gzip don't use gzip compression when uploading\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
|
|
|
|
// clang-format off
|
2020-01-28 12:02:55 -08:00
|
|
|
|
" --no-write-minidump-to-database\n"
|
|
|
|
|
" don't write minidump to database\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
|
// clang-format off
|
2017-04-04 10:08:56 -04:00
|
|
|
|
" --pipe-name=PIPE communicate with the client over PIPE\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
|
|
|
|
// clang-format off
|
2016-01-06 09:59:54 -08:00
|
|
|
|
" --reset-own-crash-exception-port-to-system-default\n"
|
|
|
|
|
" reset the server's exception handler to default\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
|
|
|
|
// clang-format off
|
2019-05-01 22:19:21 -07:00
|
|
|
|
" --sanitization-information=SANITIZATION_INFORMATION_ADDRESS\n"
|
|
|
|
|
" the address of a SanitizationInformation struct.\n"
|
|
|
|
|
" --shared-client-connection the file descriptor provided by\n"
|
|
|
|
|
" --initial-client-fd is shared among multiple\n"
|
|
|
|
|
" clients\n"
|
2018-02-20 15:03:14 -08:00
|
|
|
|
" --trace-parent-with-exception=EXCEPTION_INFORMATION_ADDRESS\n"
|
|
|
|
|
" request a dump for the handler's parent process\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
|
|
|
|
|
// BUILDFLAG(IS_ANDROID)
|
|
|
|
|
// clang-format off
|
2015-11-06 10:52:09 -08:00
|
|
|
|
" --url=URL send crash reports to this Breakpad server URL,\n"
|
|
|
|
|
" only if uploads are enabled for the database\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format off
|
2019-08-30 11:51:47 -07:00
|
|
|
|
" --use-cros-crash-reporter\n"
|
2019-09-11 10:37:54 -07:00
|
|
|
|
" pass crash reports to /sbin/crash_reporter\n"
|
|
|
|
|
" instead of storing them in the database\n"
|
2019-09-09 14:55:20 -07:00
|
|
|
|
" --minidump-dir-for-tests=TEST_MINIDUMP_DIR\n"
|
2019-09-11 10:37:54 -07:00
|
|
|
|
" causes /sbin/crash_reporter to leave dumps in\n"
|
|
|
|
|
" this directory instead of the normal location\n"
|
2019-12-23 16:19:07 -08:00
|
|
|
|
" --always-allow-feedback\n"
|
|
|
|
|
" pass the --always_allow_feedback flag to\n"
|
|
|
|
|
" crash_reporter, thus skipping metrics consent\n"
|
|
|
|
|
" checks\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
|
|
|
|
// clang-format off
|
2020-01-28 12:02:55 -08:00
|
|
|
|
" --write-minidump-to-log write minidump to log\n"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
// clang-format off
|
2015-11-06 10:52:09 -08:00
|
|
|
|
" --help display this help and exit\n"
|
|
|
|
|
" --version output version information and exit\n",
|
|
|
|
|
me.value().c_str());
|
2022-01-19 15:00:24 -05:00
|
|
|
|
// clang-format on
|
2015-11-06 10:52:09 -08:00
|
|
|
|
ToolSupport::UsageTail(me);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
struct Options {
|
|
|
|
|
std::map<std::string, std::string> annotations;
|
2017-04-04 14:26:52 -04:00
|
|
|
|
std::map<std::string, std::string> monitor_self_annotations;
|
2017-04-04 10:08:56 -04:00
|
|
|
|
std::string url;
|
|
|
|
|
base::FilePath database;
|
|
|
|
|
base::FilePath metrics_dir;
|
|
|
|
|
std::vector<std::string> monitor_self_arguments;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
std::string mach_service;
|
|
|
|
|
int handshake_fd;
|
|
|
|
|
bool reset_own_crash_exception_port_to_system_default;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
VMAddress exception_information_address;
|
2018-06-12 08:30:36 -07:00
|
|
|
|
VMAddress sanitization_information_address;
|
2019-05-01 22:19:21 -07:00
|
|
|
|
int initial_client_fd;
|
|
|
|
|
bool shared_client_connection;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
bool write_minidump_to_log;
|
|
|
|
|
bool write_minidump_to_database;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
std::string pipe_name;
|
|
|
|
|
InitialClientData initial_client_data;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2017-09-28 09:53:39 -07:00
|
|
|
|
bool identify_client_via_url;
|
2017-04-04 10:08:56 -04:00
|
|
|
|
bool monitor_self;
|
2017-04-14 14:50:11 -04:00
|
|
|
|
bool periodic_tasks;
|
2017-04-04 10:08:56 -04:00
|
|
|
|
bool rate_limit;
|
|
|
|
|
bool upload_gzip;
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-12-23 16:19:07 -08:00
|
|
|
|
bool use_cros_crash_reporter = false;
|
2019-09-09 14:55:20 -07:00
|
|
|
|
base::FilePath minidump_dir_for_tests;
|
2019-12-23 16:19:07 -08:00
|
|
|
|
bool always_allow_feedback = false;
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#if defined(ATTACHMENTS_SUPPORTED)
|
2020-06-24 09:03:47 +02:00
|
|
|
|
std::vector<base::FilePath> attachments;
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#endif // ATTACHMENTS_SUPPORTED
|
2017-04-04 10:08:56 -04:00
|
|
|
|
};
|
|
|
|
|
|
2017-04-04 14:26:52 -04:00
|
|
|
|
// Splits |key_value| on '=' and inserts the resulting key and value into |map|.
|
|
|
|
|
// If |key_value| has the wrong format, logs an error and returns false. If the
|
|
|
|
|
// key is already in the map, logs a warning, replaces the existing value, and
|
|
|
|
|
// returns true. If the key and value were inserted into the map, returns true.
|
|
|
|
|
// |argument| is used to give context to logged messages.
|
|
|
|
|
bool AddKeyValueToMap(std::map<std::string, std::string>* map,
|
|
|
|
|
const std::string& key_value,
|
|
|
|
|
const char* argument) {
|
|
|
|
|
std::string key;
|
|
|
|
|
std::string value;
|
|
|
|
|
if (!SplitStringFirst(key_value, '=', &key, &value)) {
|
|
|
|
|
LOG(ERROR) << argument << " requires KEY=VALUE";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string old_value;
|
|
|
|
|
if (!MapInsertOrReplace(map, key, value, &old_value)) {
|
|
|
|
|
LOG(WARNING) << argument << " has duplicate key " << key
|
|
|
|
|
<< ", discarding value " << old_value;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
// Calls Metrics::HandlerLifetimeMilestone, but only on the first call. This is
|
|
|
|
|
// to prevent multiple exit events from inadvertently being recorded, which
|
|
|
|
|
// might happen if a crash occurs during destruction in what would otherwise be
|
|
|
|
|
// a normal exit, or if a CallMetricsRecordNormalExit object is destroyed after
|
|
|
|
|
// something else logs an exit event.
|
|
|
|
|
void MetricsRecordExit(Metrics::LifetimeMilestone milestone) {
|
2022-05-05 15:19:17 -07:00
|
|
|
|
#if !defined(__cpp_lib_atomic_value_initialization) || \
|
|
|
|
|
__cpp_lib_atomic_value_initialization < 201911L
|
2022-02-02 14:02:27 -08:00
|
|
|
|
static std::atomic_flag metrics_exit_recorded = ATOMIC_FLAG_INIT;
|
2022-05-05 15:19:17 -07:00
|
|
|
|
#else
|
|
|
|
|
static std::atomic_flag metrics_exit_recorded;
|
|
|
|
|
#endif
|
2022-02-02 14:02:27 -08:00
|
|
|
|
if (!metrics_exit_recorded.test_and_set()) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
Metrics::HandlerLifetimeMilestone(milestone);
|
2022-02-02 14:02:27 -08:00
|
|
|
|
}
|
2017-02-22 13:39:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calls MetricsRecordExit() to record a failure, and returns EXIT_FAILURE for
|
|
|
|
|
// the convenience of callers in main() which can simply write “return
|
|
|
|
|
// ExitFailure();”.
|
|
|
|
|
int ExitFailure() {
|
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kFailed);
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CallMetricsRecordNormalExit {
|
|
|
|
|
public:
|
|
|
|
|
CallMetricsRecordNormalExit() {}
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
CallMetricsRecordNormalExit(const CallMetricsRecordNormalExit&) = delete;
|
|
|
|
|
CallMetricsRecordNormalExit& operator=(const CallMetricsRecordNormalExit&) =
|
|
|
|
|
delete;
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
~CallMetricsRecordNormalExit() {
|
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kExitedNormally);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
|
|
|
|
|
BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
|
2017-02-07 13:55:48 -05:00
|
|
|
|
void HandleCrashSignal(int sig, siginfo_t* siginfo, void* context) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kCrashed);
|
|
|
|
|
|
2017-02-07 13:55:48 -05:00
|
|
|
|
// Is siginfo->si_code useful? The only interesting values on macOS are 0 (not
|
|
|
|
|
// useful, signals generated asynchronously such as by kill() or raise()) and
|
|
|
|
|
// small positive numbers (useful, signal generated via a hardware fault). The
|
|
|
|
|
// standard specifies these other constants, and while xnu never uses them,
|
|
|
|
|
// they are intended to denote signals generated asynchronously and are
|
|
|
|
|
// included here. Additionally, existing practice on other systems
|
|
|
|
|
// (acknowledged by the standard) is for negative numbers to indicate that a
|
|
|
|
|
// signal was generated asynchronously. Although xnu does not do this, allow
|
|
|
|
|
// for the possibility for completeness.
|
|
|
|
|
bool si_code_valid = !(siginfo->si_code <= 0 ||
|
|
|
|
|
siginfo->si_code == SI_USER ||
|
|
|
|
|
siginfo->si_code == SI_QUEUE ||
|
|
|
|
|
siginfo->si_code == SI_TIMER ||
|
|
|
|
|
siginfo->si_code == SI_ASYNCIO ||
|
|
|
|
|
siginfo->si_code == SI_MESGQ);
|
|
|
|
|
|
|
|
|
|
// 0x5343 = 'SC', signifying “signal and code”, disambiguates from the schema
|
|
|
|
|
// used by ExceptionCodeForMetrics(). That system primarily uses Mach
|
|
|
|
|
// exception types and codes, which are not available to a POSIX signal
|
|
|
|
|
// handler. It does provide a way to encode only signal numbers, but does so
|
|
|
|
|
// with the understanding that certain “raw” signals would not be encountered
|
|
|
|
|
// without a Mach exception. Furthermore, it does not allow siginfo->si_code
|
|
|
|
|
// to be encoded, because that’s not available to Mach exception handlers. It
|
|
|
|
|
// would be a shame to lose that information available to a POSIX signal
|
|
|
|
|
// handler.
|
|
|
|
|
int metrics_code = 0x53430000 | (InRangeCast<uint8_t>(sig, 0xff) << 8);
|
|
|
|
|
if (si_code_valid) {
|
|
|
|
|
metrics_code |= InRangeCast<uint8_t>(siginfo->si_code, 0xff);
|
|
|
|
|
}
|
|
|
|
|
Metrics::HandlerCrashed(metrics_code);
|
|
|
|
|
|
2019-09-30 13:56:12 -07:00
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(siginfo, nullptr);
|
2017-02-07 13:55:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
void HandleTerminateSignal(int sig, siginfo_t* siginfo, void* context) {
|
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kTerminated);
|
2017-03-01 10:00:59 -05:00
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(siginfo, nullptr);
|
2017-02-22 13:39:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
void ReinstallCrashHandler() {
|
|
|
|
|
// This is used to re-enable the metrics-recording crash handler after
|
|
|
|
|
// MonitorSelf() sets up a Crashpad exception handler. On macOS, the
|
|
|
|
|
// metrics-recording handler uses signals and the Crashpad handler uses Mach
|
|
|
|
|
// exceptions, so there’s nothing to re-enable.
|
2019-09-30 13:56:12 -07:00
|
|
|
|
// On Linux, the signal handler installed by StartHandler() restores the
|
|
|
|
|
// previously installed signal handler by default.
|
2017-04-04 10:08:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
void InstallCrashHandler() {
|
2017-03-01 10:00:59 -05:00
|
|
|
|
Signals::InstallCrashHandlers(HandleCrashSignal, 0, nullptr);
|
|
|
|
|
|
|
|
|
|
// Not a crash handler, but close enough.
|
|
|
|
|
Signals::InstallTerminateHandlers(HandleTerminateSignal, 0, nullptr);
|
2017-02-07 13:55:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2019-09-30 13:56:12 -07:00
|
|
|
|
|
2015-11-09 16:29:25 -05:00
|
|
|
|
struct ResetSIGTERMTraits {
|
|
|
|
|
static struct sigaction* InvalidValue() {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Free(struct sigaction* sa) {
|
|
|
|
|
int rv = sigaction(SIGTERM, sa, nullptr);
|
|
|
|
|
PLOG_IF(ERROR, rv != 0) << "sigaction";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
using ScopedResetSIGTERM =
|
|
|
|
|
base::ScopedGeneric<struct sigaction*, ResetSIGTERMTraits>;
|
|
|
|
|
|
|
|
|
|
ExceptionHandlerServer* g_exception_handler_server;
|
|
|
|
|
|
|
|
|
|
// This signal handler is only operative when being run from launchd.
|
|
|
|
|
void HandleSIGTERM(int sig, siginfo_t* siginfo, void* context) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
// Don’t call MetricsRecordExit(). This is part of the normal exit path when
|
|
|
|
|
// running from launchd.
|
|
|
|
|
|
2015-11-09 16:29:25 -05:00
|
|
|
|
DCHECK(g_exception_handler_server);
|
|
|
|
|
g_exception_handler_server->Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2015-11-09 16:29:25 -05:00
|
|
|
|
|
2016-12-15 14:50:58 -05:00
|
|
|
|
LONG(WINAPI* g_original_exception_filter)(EXCEPTION_POINTERS*) = nullptr;
|
|
|
|
|
|
2016-09-28 12:49:46 -07:00
|
|
|
|
LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kCrashed);
|
2016-09-28 12:49:46 -07:00
|
|
|
|
Metrics::HandlerCrashed(exception_pointers->ExceptionRecord->ExceptionCode);
|
2016-12-15 14:50:58 -05:00
|
|
|
|
|
|
|
|
|
if (g_original_exception_filter)
|
|
|
|
|
return g_original_exception_filter(exception_pointers);
|
|
|
|
|
else
|
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
2016-09-28 12:49:46 -07:00
|
|
|
|
}
|
2017-02-07 13:55:48 -05:00
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
// Handles events like Control-C and Control-Break on a console.
|
|
|
|
|
BOOL WINAPI ConsoleHandler(DWORD console_event) {
|
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kTerminated);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handles a WM_ENDSESSION message sent when the user session is ending.
|
|
|
|
|
class TerminateHandler final : public SessionEndWatcher {
|
|
|
|
|
public:
|
|
|
|
|
TerminateHandler() : SessionEndWatcher() {}
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
TerminateHandler(const TerminateHandler&) = delete;
|
|
|
|
|
TerminateHandler& operator=(const TerminateHandler&) = delete;
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
~TerminateHandler() override {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// SessionEndWatcher:
|
|
|
|
|
void SessionEnding() override {
|
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kTerminated);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
void ReinstallCrashHandler() {
|
|
|
|
|
// This is used to re-enable the metrics-recording crash handler after
|
|
|
|
|
// MonitorSelf() sets up a Crashpad exception handler. The Crashpad handler
|
2017-04-04 14:26:52 -04:00
|
|
|
|
// takes over the UnhandledExceptionFilter, so reinstall the metrics-recording
|
2017-04-04 10:08:56 -04:00
|
|
|
|
// one.
|
2017-02-07 13:55:48 -05:00
|
|
|
|
g_original_exception_filter =
|
|
|
|
|
SetUnhandledExceptionFilter(&UnhandledExceptionHandler);
|
2017-04-04 10:08:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InstallCrashHandler() {
|
|
|
|
|
ReinstallCrashHandler();
|
2017-02-22 13:39:46 -05:00
|
|
|
|
|
|
|
|
|
// These are termination handlers, not crash handlers, but that’s close
|
|
|
|
|
// enough. Note that destroying the TerminateHandler would wait for its thread
|
|
|
|
|
// to exit, which isn’t necessary or desirable.
|
|
|
|
|
SetConsoleCtrlHandler(ConsoleHandler, true);
|
2022-01-14 17:51:32 -05:00
|
|
|
|
[[maybe_unused]] static TerminateHandler* terminate_handler =
|
|
|
|
|
new TerminateHandler();
|
2017-02-07 13:55:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2016-09-28 12:49:46 -07:00
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
void MonitorSelf(const Options& options) {
|
|
|
|
|
base::FilePath executable_path;
|
|
|
|
|
if (!Paths::Executable(&executable_path)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (std::find(options.monitor_self_arguments.begin(),
|
|
|
|
|
options.monitor_self_arguments.end(),
|
|
|
|
|
"--monitor-self") != options.monitor_self_arguments.end()) {
|
|
|
|
|
LOG(WARNING) << "--monitor-self-argument=--monitor-self is not supported";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::string> extra_arguments(options.monitor_self_arguments);
|
2017-09-28 09:53:39 -07:00
|
|
|
|
if (!options.identify_client_via_url) {
|
|
|
|
|
extra_arguments.push_back("--no-identify-client-via-url");
|
|
|
|
|
}
|
2017-04-14 14:50:11 -04:00
|
|
|
|
extra_arguments.push_back("--no-periodic-tasks");
|
2017-04-04 10:08:56 -04:00
|
|
|
|
if (!options.rate_limit) {
|
|
|
|
|
extra_arguments.push_back("--no-rate-limit");
|
|
|
|
|
}
|
|
|
|
|
if (!options.upload_gzip) {
|
|
|
|
|
extra_arguments.push_back("--no-upload-gzip");
|
|
|
|
|
}
|
2017-04-04 14:26:52 -04:00
|
|
|
|
for (const auto& iterator : options.monitor_self_annotations) {
|
|
|
|
|
extra_arguments.push_back(
|
|
|
|
|
base::StringPrintf("--monitor-self-annotation=%s=%s",
|
|
|
|
|
iterator.first.c_str(),
|
|
|
|
|
iterator.second.c_str()));
|
|
|
|
|
}
|
2017-04-04 10:08:56 -04:00
|
|
|
|
|
|
|
|
|
// Don’t use options.metrics_dir. The current implementation only allows one
|
|
|
|
|
// instance of crashpad_handler to be writing metrics at a time, and it should
|
|
|
|
|
// be the primary instance.
|
|
|
|
|
CrashpadClient crashpad_client;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
if (!crashpad_client.StartHandlerAtCrash(executable_path,
|
|
|
|
|
options.database,
|
|
|
|
|
base::FilePath(),
|
|
|
|
|
options.url,
|
|
|
|
|
options.annotations,
|
|
|
|
|
extra_arguments)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#else
|
2017-04-04 10:08:56 -04:00
|
|
|
|
if (!crashpad_client.StartHandler(executable_path,
|
|
|
|
|
options.database,
|
|
|
|
|
base::FilePath(),
|
|
|
|
|
options.url,
|
|
|
|
|
options.annotations,
|
|
|
|
|
extra_arguments,
|
|
|
|
|
true,
|
|
|
|
|
false)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-02-20 15:03:14 -08:00
|
|
|
|
#endif
|
2017-04-04 10:08:56 -04:00
|
|
|
|
|
|
|
|
|
// Make sure that appropriate metrics will be recorded on crash before this
|
|
|
|
|
// process is terminated.
|
|
|
|
|
ReinstallCrashHandler();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 10:55:17 -08:00
|
|
|
|
class ScopedStoppable {
|
|
|
|
|
public:
|
|
|
|
|
ScopedStoppable() = default;
|
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
|
ScopedStoppable(const ScopedStoppable&) = delete;
|
|
|
|
|
ScopedStoppable& operator=(const ScopedStoppable&) = delete;
|
|
|
|
|
|
2018-02-20 10:55:17 -08:00
|
|
|
|
~ScopedStoppable() {
|
|
|
|
|
if (stoppable_) {
|
|
|
|
|
stoppable_->Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset(Stoppable* stoppable) { stoppable_.reset(stoppable); }
|
|
|
|
|
|
|
|
|
|
Stoppable* Get() { return stoppable_.get(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_ptr<Stoppable> stoppable_;
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-21 11:10:25 -07:00
|
|
|
|
void InitCrashpadLogging() {
|
|
|
|
|
logging::LoggingSettings settings;
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
2020-10-21 11:10:25 -07:00
|
|
|
|
settings.logging_dest = logging::LOG_TO_FILE;
|
|
|
|
|
settings.log_file_path = "/var/log/chrome/chrome";
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2020-10-21 11:10:25 -07:00
|
|
|
|
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
|
|
|
|
#else
|
|
|
|
|
settings.logging_dest =
|
|
|
|
|
logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
|
|
|
|
|
#endif
|
|
|
|
|
logging::InitLogging(settings);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
} // namespace
|
|
|
|
|
|
2017-04-11 14:48:10 -04:00
|
|
|
|
int HandlerMain(int argc,
|
|
|
|
|
char* argv[],
|
|
|
|
|
const UserStreamDataSources* user_stream_sources) {
|
2020-10-21 11:10:25 -07:00
|
|
|
|
InitCrashpadLogging();
|
2019-08-19 15:43:02 -07:00
|
|
|
|
|
2017-02-07 13:55:48 -05:00
|
|
|
|
InstallCrashHandler();
|
2017-02-22 13:39:46 -05:00
|
|
|
|
CallMetricsRecordNormalExit metrics_record_normal_exit;
|
2016-09-28 12:49:46 -07:00
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
const base::FilePath argv0(
|
|
|
|
|
ToolSupport::CommandLineArgumentToFilePathStringType(argv[0]));
|
|
|
|
|
const base::FilePath me(argv0.BaseName());
|
|
|
|
|
|
|
|
|
|
enum OptionFlags {
|
|
|
|
|
// Long options without short equivalents.
|
|
|
|
|
kOptionLastChar = 255,
|
|
|
|
|
kOptionAnnotation,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
|
|
|
|
|
BUILDFLAG(IS_ANDROID)
|
2020-06-24 09:03:47 +02:00
|
|
|
|
kOptionAttachment,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
kOptionDatabase,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
kOptionHandshakeFD,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
kOptionInitialClientData,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2019-05-01 22:19:21 -07:00
|
|
|
|
kOptionInitialClientFD,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) ||
|
|
|
|
|
// BUILDFLAG(IS_CHROMEOS)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
kOptionMachService,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2016-09-16 13:21:50 -07:00
|
|
|
|
kOptionMetrics,
|
2017-04-04 10:08:56 -04:00
|
|
|
|
kOptionMonitorSelf,
|
2017-04-04 14:26:52 -04:00
|
|
|
|
kOptionMonitorSelfAnnotation,
|
2017-04-04 10:08:56 -04:00
|
|
|
|
kOptionMonitorSelfArgument,
|
2017-09-28 09:53:39 -07:00
|
|
|
|
kOptionNoIdentifyClientViaUrl,
|
2017-04-14 14:50:11 -04:00
|
|
|
|
kOptionNoPeriodicTasks,
|
2016-01-06 09:59:54 -08:00
|
|
|
|
kOptionNoRateLimit,
|
2017-02-15 19:54:19 -05:00
|
|
|
|
kOptionNoUploadGzip,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
kOptionNoWriteMinidumpToDatabase,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
kOptionPipeName,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2016-01-06 09:59:54 -08:00
|
|
|
|
kOptionResetOwnCrashExceptionPortToSystemDefault,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-06-12 08:30:36 -07:00
|
|
|
|
kOptionSanitizationInformation,
|
2019-05-01 22:19:21 -07:00
|
|
|
|
kOptionSharedClientConnection,
|
|
|
|
|
kOptionTraceParentWithException,
|
2018-02-20 15:03:14 -08:00
|
|
|
|
#endif
|
2015-11-06 10:52:09 -08:00
|
|
|
|
kOptionURL,
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
kOptionUseCrosCrashReporter,
|
2019-09-09 14:55:20 -07:00
|
|
|
|
kOptionMinidumpDirForTests,
|
2019-12-23 16:19:07 -08:00
|
|
|
|
kOptionAlwaysAllowFeedback,
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
kOptionWriteMinidumpToLog,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
|
|
|
|
// Standard options.
|
|
|
|
|
kOptionHelp = -2,
|
|
|
|
|
kOptionVersion = -3,
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr option long_options[] = {
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"annotation", required_argument, nullptr, kOptionAnnotation},
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#if defined(ATTACHMENTS_SUPPORTED)
|
2020-06-24 09:03:47 +02:00
|
|
|
|
{"attachment", required_argument, nullptr, kOptionAttachment},
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#endif // ATTACHMENTS_SUPPORTED
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"database", required_argument, nullptr, kOptionDatabase},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"handshake-fd", required_argument, nullptr, kOptionHandshakeFD},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"initial-client-data",
|
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionInitialClientData},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2019-05-01 22:19:21 -07:00
|
|
|
|
{"initial-client-fd", required_argument, nullptr, kOptionInitialClientFD},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) ||
|
|
|
|
|
// BUILDFLAG(IS_CHROMEOS)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"mach-service", required_argument, nullptr, kOptionMachService},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"metrics-dir", required_argument, nullptr, kOptionMetrics},
|
2017-04-04 10:08:56 -04:00
|
|
|
|
{"monitor-self", no_argument, nullptr, kOptionMonitorSelf},
|
2017-04-04 14:26:52 -04:00
|
|
|
|
{"monitor-self-annotation",
|
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionMonitorSelfAnnotation},
|
2017-04-04 10:08:56 -04:00
|
|
|
|
{"monitor-self-argument",
|
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionMonitorSelfArgument},
|
2017-09-28 09:53:39 -07:00
|
|
|
|
{"no-identify-client-via-url",
|
|
|
|
|
no_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionNoIdentifyClientViaUrl},
|
2017-04-14 14:50:11 -04:00
|
|
|
|
{"no-periodic-tasks", no_argument, nullptr, kOptionNoPeriodicTasks},
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"no-rate-limit", no_argument, nullptr, kOptionNoRateLimit},
|
2017-02-15 19:54:19 -05:00
|
|
|
|
{"no-upload-gzip", no_argument, nullptr, kOptionNoUploadGzip},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
{"no-write-minidump-to-database",
|
|
|
|
|
no_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionNoWriteMinidumpToDatabase},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
{"pipe-name", required_argument, nullptr, kOptionPipeName},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"reset-own-crash-exception-port-to-system-default",
|
|
|
|
|
no_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionResetOwnCrashExceptionPortToSystemDefault},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-06-12 08:30:36 -07:00
|
|
|
|
{"sanitization-information",
|
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionSanitizationInformation},
|
2019-05-01 22:19:21 -07:00
|
|
|
|
{"shared-client-connection",
|
|
|
|
|
no_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionSharedClientConnection},
|
|
|
|
|
{"trace-parent-with-exception",
|
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionTraceParentWithException},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
|
|
|
|
|
// BUILDFLAG(IS_ANDROID)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"url", required_argument, nullptr, kOptionURL},
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
{"use-cros-crash-reporter",
|
2022-01-19 15:00:24 -05:00
|
|
|
|
no_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionUseCrosCrashReporter},
|
2019-12-19 12:09:25 -08:00
|
|
|
|
{"minidump-dir-for-tests",
|
2022-01-19 15:00:24 -05:00
|
|
|
|
required_argument,
|
|
|
|
|
nullptr,
|
|
|
|
|
kOptionMinidumpDirForTests},
|
|
|
|
|
{"always-allow-feedback", no_argument, nullptr, kOptionAlwaysAllowFeedback},
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
{"write-minidump-to-log", no_argument, nullptr, kOptionWriteMinidumpToLog},
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
{"help", no_argument, nullptr, kOptionHelp},
|
|
|
|
|
{"version", no_argument, nullptr, kOptionVersion},
|
|
|
|
|
{nullptr, 0, nullptr, 0},
|
2015-11-06 10:52:09 -08:00
|
|
|
|
};
|
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
Options options = {};
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
options.handshake_fd = -1;
|
|
|
|
|
#endif
|
2017-09-28 09:53:39 -07:00
|
|
|
|
options.identify_client_via_url = true;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
options.initial_client_fd = kInvalidFileHandle;
|
|
|
|
|
#endif
|
2019-05-01 22:19:21 -07:00
|
|
|
|
options.periodic_tasks = true;
|
|
|
|
|
options.rate_limit = true;
|
|
|
|
|
options.upload_gzip = true;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
options.write_minidump_to_database = true;
|
|
|
|
|
#endif
|
2017-04-04 10:08:56 -04:00
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
int opt;
|
|
|
|
|
while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) {
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case kOptionAnnotation: {
|
2017-04-04 14:26:52 -04:00
|
|
|
|
if (!AddKeyValueToMap(&options.annotations, optarg, "--annotation")) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#if defined(ATTACHMENTS_SUPPORTED)
|
2020-06-24 09:03:47 +02:00
|
|
|
|
case kOptionAttachment: {
|
|
|
|
|
options.attachments.push_back(base::FilePath(
|
|
|
|
|
ToolSupport::CommandLineArgumentToFilePathStringType(optarg)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#endif // ATTACHMENTS_SUPPORTED
|
2015-11-06 10:52:09 -08:00
|
|
|
|
case kOptionDatabase: {
|
2017-04-04 10:08:56 -04:00
|
|
|
|
options.database = base::FilePath(
|
|
|
|
|
ToolSupport::CommandLineArgumentToFilePathStringType(optarg));
|
2015-11-06 10:52:09 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
case kOptionHandshakeFD: {
|
|
|
|
|
if (!StringToNumber(optarg, &options.handshake_fd) ||
|
|
|
|
|
options.handshake_fd < 0) {
|
|
|
|
|
ToolSupport::UsageHint(me,
|
|
|
|
|
"--handshake-fd requires a file descriptor");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kOptionMachService: {
|
|
|
|
|
options.mach_service = optarg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
case kOptionInitialClientData: {
|
|
|
|
|
if (!options.initial_client_data.InitializeFromString(optarg)) {
|
|
|
|
|
ToolSupport::UsageHint(
|
|
|
|
|
me, "failed to parse --initial-client-data");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
break; after handling --initial-client-data on command line
Not surprisingly,
"0x278,0x27c,0x280,0x274,0x288,0x978a70,0x978a80,0x978a90" is not a
valid directory to store metrics in.
Fortunately --metrics was processed before --initial-client-data in a
local build, otherwise this could have lurked for a long time. :(
R=mark@chromium.org
BUG=655788,656800
Change-Id: I3ac3d1b487f55ddf0172bac51f8d9efc411c3329
Reviewed-on: https://chromium-review.googlesource.com/406938
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-11-02 15:34:53 -07:00
|
|
|
|
break;
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2019-05-01 22:19:21 -07:00
|
|
|
|
case kOptionInitialClientFD: {
|
|
|
|
|
if (!base::StringToInt(optarg, &options.initial_client_fd)) {
|
|
|
|
|
ToolSupport::UsageHint(me, "failed to parse --initial-client-fd");
|
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) ||
|
|
|
|
|
// BUILDFLAG(IS_CHROMEOS)
|
2016-09-16 13:21:50 -07:00
|
|
|
|
case kOptionMetrics: {
|
2017-04-04 10:08:56 -04:00
|
|
|
|
options.metrics_dir = base::FilePath(
|
|
|
|
|
ToolSupport::CommandLineArgumentToFilePathStringType(optarg));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kOptionMonitorSelf: {
|
|
|
|
|
options.monitor_self = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-04 14:26:52 -04:00
|
|
|
|
case kOptionMonitorSelfAnnotation: {
|
|
|
|
|
if (!AddKeyValueToMap(&options.monitor_self_annotations,
|
|
|
|
|
optarg,
|
|
|
|
|
"--monitor-self-annotation")) {
|
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-04 10:08:56 -04:00
|
|
|
|
case kOptionMonitorSelfArgument: {
|
|
|
|
|
options.monitor_self_arguments.push_back(optarg);
|
2016-09-16 13:21:50 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-09-28 09:53:39 -07:00
|
|
|
|
case kOptionNoIdentifyClientViaUrl: {
|
|
|
|
|
options.identify_client_via_url = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-14 14:50:11 -04:00
|
|
|
|
case kOptionNoPeriodicTasks: {
|
|
|
|
|
options.periodic_tasks = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-01-06 09:59:54 -08:00
|
|
|
|
case kOptionNoRateLimit: {
|
|
|
|
|
options.rate_limit = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-15 19:54:19 -05:00
|
|
|
|
case kOptionNoUploadGzip: {
|
|
|
|
|
options.upload_gzip = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
case kOptionNoWriteMinidumpToDatabase: {
|
|
|
|
|
options.write_minidump_to_database = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
case kOptionPipeName: {
|
|
|
|
|
options.pipe_name = optarg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2016-01-06 09:59:54 -08:00
|
|
|
|
case kOptionResetOwnCrashExceptionPortToSystemDefault: {
|
|
|
|
|
options.reset_own_crash_exception_port_to_system_default = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2019-05-01 22:19:21 -07:00
|
|
|
|
case kOptionSanitizationInformation: {
|
|
|
|
|
if (!StringToNumber(optarg,
|
|
|
|
|
&options.sanitization_information_address)) {
|
|
|
|
|
ToolSupport::UsageHint(me,
|
|
|
|
|
"failed to parse --sanitization-information");
|
2018-02-20 15:03:14 -08:00
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
|
case kOptionSharedClientConnection: {
|
|
|
|
|
options.shared_client_connection = true;
|
2018-02-20 15:03:14 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
|
case kOptionTraceParentWithException: {
|
|
|
|
|
if (!StringToNumber(optarg, &options.exception_information_address)) {
|
|
|
|
|
ToolSupport::UsageHint(
|
|
|
|
|
me, "failed to parse --trace-parent-with-exception");
|
2018-06-12 08:30:36 -07:00
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
|
|
|
|
|
// BUILDFLAG(IS_ANDROID)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
case kOptionURL: {
|
|
|
|
|
options.url = optarg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
case kOptionUseCrosCrashReporter: {
|
|
|
|
|
options.use_cros_crash_reporter = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-09-09 14:55:20 -07:00
|
|
|
|
case kOptionMinidumpDirForTests: {
|
|
|
|
|
options.minidump_dir_for_tests = base::FilePath(
|
|
|
|
|
ToolSupport::CommandLineArgumentToFilePathStringType(optarg));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-12-23 16:19:07 -08:00
|
|
|
|
case kOptionAlwaysAllowFeedback: {
|
|
|
|
|
options.always_allow_feedback = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
case kOptionWriteMinidumpToLog: {
|
|
|
|
|
options.write_minidump_to_log = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
case kOptionHelp: {
|
|
|
|
|
Usage(me);
|
2017-02-22 13:39:46 -05:00
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kExitedEarly);
|
2015-11-06 10:52:09 -08:00
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
case kOptionVersion: {
|
|
|
|
|
ToolSupport::Version(me);
|
2017-02-22 13:39:46 -05:00
|
|
|
|
MetricsRecordExit(Metrics::LifetimeMilestone::kExitedEarly);
|
2015-11-06 10:52:09 -08:00
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
ToolSupport::UsageHint(me, nullptr);
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
if (options.handshake_fd < 0 && options.mach_service.empty()) {
|
|
|
|
|
ToolSupport::UsageHint(me, "--handshake-fd or --mach-service is required");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
if (options.handshake_fd >= 0 && !options.mach_service.empty()) {
|
|
|
|
|
ToolSupport::UsageHint(
|
|
|
|
|
me, "--handshake-fd and --mach-service are incompatible");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
if (!options.initial_client_data.IsValid() && options.pipe_name.empty()) {
|
|
|
|
|
ToolSupport::UsageHint(me,
|
|
|
|
|
"--initial-client-data or --pipe-name is required");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
2016-10-21 13:08:18 -07:00
|
|
|
|
if (options.initial_client_data.IsValid() && !options.pipe_name.empty()) {
|
2015-11-06 10:52:09 -08:00
|
|
|
|
ToolSupport::UsageHint(
|
2016-10-21 13:08:18 -07:00
|
|
|
|
me, "--initial-client-data and --pipe-name are incompatible");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
if (!options.exception_information_address &&
|
|
|
|
|
options.initial_client_fd == kInvalidFileHandle) {
|
2018-06-12 08:30:36 -07:00
|
|
|
|
ToolSupport::UsageHint(
|
2019-05-01 22:19:21 -07:00
|
|
|
|
me, "--trace-parent-with-exception or --initial-client-fd is required");
|
2018-06-12 08:30:36 -07:00
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
if (options.sanitization_information_address &&
|
|
|
|
|
!options.exception_information_address) {
|
2018-02-20 15:03:14 -08:00
|
|
|
|
ToolSupport::UsageHint(
|
|
|
|
|
me,
|
2018-06-12 08:30:36 -07:00
|
|
|
|
"--sanitization_information requires --trace-parent-with-exception");
|
2018-02-20 15:03:14 -08:00
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
|
if (options.shared_client_connection &&
|
|
|
|
|
options.initial_client_fd == kInvalidFileHandle) {
|
|
|
|
|
ToolSupport::UsageHint(
|
|
|
|
|
me, "--shared-client-connection requires --initial-client-fd");
|
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
if (!options.write_minidump_to_log && !options.write_minidump_to_database) {
|
|
|
|
|
ToolSupport::UsageHint(me,
|
|
|
|
|
"--no_write_minidump_to_database is required to use "
|
|
|
|
|
"with --write_minidump_to_log.");
|
|
|
|
|
ExitFailure();
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
2017-04-04 10:08:56 -04:00
|
|
|
|
if (options.database.empty()) {
|
2015-11-06 10:52:09 -08:00
|
|
|
|
ToolSupport::UsageHint(me, "--database is required");
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (argc) {
|
|
|
|
|
ToolSupport::UsageHint(me, nullptr);
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
if (options.reset_own_crash_exception_port_to_system_default) {
|
|
|
|
|
CrashpadClient::UseSystemDefaultHandler();
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2017-04-04 10:08:56 -04:00
|
|
|
|
|
|
|
|
|
if (options.monitor_self) {
|
|
|
|
|
MonitorSelf(options);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 14:26:52 -04:00
|
|
|
|
if (!options.monitor_self_annotations.empty()) {
|
|
|
|
|
// Establish these annotations even if --monitor-self is not present, in
|
|
|
|
|
// case something such as generate_dump wants to try to access them later.
|
2017-04-04 16:12:12 -04:00
|
|
|
|
//
|
|
|
|
|
// If the handler is part of a multi-purpose executable, simple annotations
|
|
|
|
|
// may already be present for this module. If they are, use them.
|
|
|
|
|
CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo();
|
|
|
|
|
SimpleStringDictionary* module_annotations =
|
|
|
|
|
crashpad_info->simple_annotations();
|
|
|
|
|
if (!module_annotations) {
|
|
|
|
|
module_annotations = new SimpleStringDictionary();
|
|
|
|
|
crashpad_info->set_simple_annotations(module_annotations);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 14:26:52 -04:00
|
|
|
|
for (const auto& iterator : options.monitor_self_annotations) {
|
|
|
|
|
module_annotations->SetKeyValue(iterator.first.c_str(),
|
|
|
|
|
iterator.second.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:03:14 -08:00
|
|
|
|
std::unique_ptr<CrashReportDatabase> database(
|
|
|
|
|
CrashReportDatabase::Initialize(options.database));
|
|
|
|
|
if (!database) {
|
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScopedStoppable upload_thread;
|
|
|
|
|
if (!options.url.empty()) {
|
|
|
|
|
// TODO(scottmg): options.rate_limit should be removed when we have a
|
|
|
|
|
// configurable database setting to control upload limiting.
|
|
|
|
|
// See https://crashpad.chromium.org/bug/23.
|
|
|
|
|
CrashReportUploadThread::Options upload_thread_options;
|
|
|
|
|
upload_thread_options.identify_client_via_url =
|
|
|
|
|
options.identify_client_via_url;
|
|
|
|
|
upload_thread_options.rate_limit = options.rate_limit;
|
|
|
|
|
upload_thread_options.upload_gzip = options.upload_gzip;
|
|
|
|
|
upload_thread_options.watch_pending_reports = options.periodic_tasks;
|
|
|
|
|
|
|
|
|
|
upload_thread.Reset(new CrashReportUploadThread(
|
2022-09-09 15:25:08 -06:00
|
|
|
|
database.get(),
|
|
|
|
|
options.url,
|
|
|
|
|
upload_thread_options,
|
|
|
|
|
CrashReportUploadThread::ProcessPendingReportsObservationCallback()));
|
2018-02-20 15:03:14 -08:00
|
|
|
|
upload_thread.Get()->Start();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
std::unique_ptr<ExceptionHandlerServer::Delegate> exception_handler;
|
|
|
|
|
#else
|
|
|
|
|
std::unique_ptr<CrashReportExceptionHandler> exception_handler;
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2019-08-30 11:51:47 -07:00
|
|
|
|
if (options.use_cros_crash_reporter) {
|
2019-09-11 10:37:54 -07:00
|
|
|
|
auto cros_handler = std::make_unique<CrosCrashReportExceptionHandler>(
|
2019-08-30 11:51:47 -07:00
|
|
|
|
database.get(),
|
|
|
|
|
&options.annotations,
|
|
|
|
|
user_stream_sources);
|
2019-09-11 10:37:54 -07:00
|
|
|
|
|
|
|
|
|
if (!options.minidump_dir_for_tests.empty()) {
|
|
|
|
|
cros_handler->SetDumpDir(options.minidump_dir_for_tests);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 16:19:07 -08:00
|
|
|
|
if (options.always_allow_feedback) {
|
|
|
|
|
cros_handler->SetAlwaysAllowFeedback();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 10:37:54 -07:00
|
|
|
|
exception_handler = std::move(cros_handler);
|
2019-08-30 11:51:47 -07:00
|
|
|
|
} else {
|
|
|
|
|
exception_handler = std::make_unique<CrashReportExceptionHandler>(
|
|
|
|
|
database.get(),
|
|
|
|
|
static_cast<CrashReportUploadThread*>(upload_thread.Get()),
|
|
|
|
|
&options.annotations,
|
2020-07-01 17:54:10 -04:00
|
|
|
|
&options.attachments,
|
2020-01-31 13:25:29 -08:00
|
|
|
|
true,
|
|
|
|
|
false,
|
2019-08-30 11:51:47 -07:00
|
|
|
|
user_stream_sources);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
exception_handler = std::make_unique<CrashReportExceptionHandler>(
|
2018-02-20 15:03:14 -08:00
|
|
|
|
database.get(),
|
|
|
|
|
static_cast<CrashReportUploadThread*>(upload_thread.Get()),
|
|
|
|
|
&options.annotations,
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#if defined(ATTACHMENTS_SUPPORTED)
|
2020-06-24 09:03:47 +02:00
|
|
|
|
&options.attachments,
|
2020-08-03 13:39:14 -07:00
|
|
|
|
#endif // ATTACHMENTS_SUPPORTED
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
options.write_minidump_to_database,
|
|
|
|
|
options.write_minidump_to_log,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
true,
|
|
|
|
|
false,
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_LINUX)
|
2020-01-28 12:02:55 -08:00
|
|
|
|
user_stream_sources);
|
2021-01-12 13:45:14 -08:00
|
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
if (options.exception_information_address) {
|
2019-04-23 09:59:29 -07:00
|
|
|
|
ExceptionHandlerProtocol::ClientInformation info;
|
2018-06-12 08:30:36 -07:00
|
|
|
|
info.exception_information_address = options.exception_information_address;
|
|
|
|
|
info.sanitization_information_address =
|
|
|
|
|
options.sanitization_information_address;
|
2019-08-30 11:51:47 -07:00
|
|
|
|
return exception_handler->HandleException(getppid(), geteuid(), info)
|
2019-08-19 15:43:02 -07:00
|
|
|
|
? EXIT_SUCCESS
|
|
|
|
|
: ExitFailure();
|
2018-02-20 15:03:14 -08:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
|
|
|
|
|
// BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
|
|
|
|
|
ScopedStoppable prune_thread;
|
|
|
|
|
if (options.periodic_tasks) {
|
|
|
|
|
prune_thread.Reset(new PruneCrashReportThread(
|
|
|
|
|
database.get(), PruneCondition::GetDefault()));
|
|
|
|
|
prune_thread.Get()->Start();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
if (options.mach_service.empty()) {
|
|
|
|
|
// Don’t do this when being run by launchd. See launchd.plist(5).
|
|
|
|
|
CloseStdinAndStdout();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 16:30:40 -04:00
|
|
|
|
base::apple::ScopedMachReceiveRight receive_right;
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
|
|
|
|
if (options.handshake_fd >= 0) {
|
|
|
|
|
receive_right.reset(
|
|
|
|
|
ChildPortHandshake::RunServerForFD(
|
|
|
|
|
base::ScopedFD(options.handshake_fd),
|
|
|
|
|
ChildPortHandshake::PortRightType::kReceiveRight));
|
|
|
|
|
} else if (!options.mach_service.empty()) {
|
|
|
|
|
receive_right = BootstrapCheckIn(options.mach_service);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!receive_right.is_valid()) {
|
2017-02-22 13:39:46 -05:00
|
|
|
|
return ExitFailure();
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExceptionHandlerServer exception_handler_server(
|
2015-12-09 17:36:32 -05:00
|
|
|
|
std::move(receive_right), !options.mach_service.empty());
|
2015-11-09 16:29:25 -05:00
|
|
|
|
base::AutoReset<ExceptionHandlerServer*> reset_g_exception_handler_server(
|
|
|
|
|
&g_exception_handler_server, &exception_handler_server);
|
|
|
|
|
|
2017-03-01 10:00:59 -05:00
|
|
|
|
struct sigaction old_sigterm_action;
|
2015-11-09 16:29:25 -05:00
|
|
|
|
ScopedResetSIGTERM reset_sigterm;
|
|
|
|
|
if (!options.mach_service.empty()) {
|
|
|
|
|
// When running from launchd, no no-senders notification could ever be
|
|
|
|
|
// triggered, because launchd maintains a send right to the service. When
|
|
|
|
|
// launchd wants the job to exit, it will send a SIGTERM. See
|
|
|
|
|
// launchd.plist(5).
|
|
|
|
|
//
|
|
|
|
|
// Set up a SIGTERM handler that will call exception_handler_server.Stop().
|
2017-02-22 13:39:46 -05:00
|
|
|
|
// This replaces the HandleTerminateSignal handler for SIGTERM.
|
2017-03-01 10:00:59 -05:00
|
|
|
|
if (Signals::InstallHandler(
|
|
|
|
|
SIGTERM, HandleSIGTERM, 0, &old_sigterm_action)) {
|
|
|
|
|
reset_sigterm.reset(&old_sigterm_action);
|
|
|
|
|
}
|
2015-11-09 16:29:25 -05:00
|
|
|
|
}
|
2017-04-18 11:50:39 -04:00
|
|
|
|
|
|
|
|
|
RecordFileLimitAnnotation();
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2015-12-08 16:55:02 -08:00
|
|
|
|
// Shut down as late as possible relative to programs we're watching.
|
|
|
|
|
if (!SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY))
|
|
|
|
|
PLOG(ERROR) << "SetProcessShutdownParameters";
|
|
|
|
|
|
2015-11-06 10:52:09 -08:00
|
|
|
|
ExceptionHandlerServer exception_handler_server(!options.pipe_name.empty());
|
|
|
|
|
|
|
|
|
|
if (!options.pipe_name.empty()) {
|
2020-09-12 09:20:14 +02:00
|
|
|
|
exception_handler_server.SetPipeName(base::UTF8ToWide(options.pipe_name));
|
2015-11-06 10:52:09 -08:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2017-12-06 10:08:11 -08:00
|
|
|
|
ExceptionHandlerServer exception_handler_server;
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_APPLE)
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
2016-09-16 13:21:50 -07:00
|
|
|
|
base::GlobalHistogramAllocator* histogram_allocator = nullptr;
|
2017-04-04 10:08:56 -04:00
|
|
|
|
if (!options.metrics_dir.empty()) {
|
2017-07-25 13:34:04 -04:00
|
|
|
|
static constexpr char kMetricsName[] = "CrashpadMetrics";
|
2017-07-25 19:15:48 -04:00
|
|
|
|
constexpr size_t kMetricsFileSize = 1 << 20;
|
2016-09-16 13:21:50 -07:00
|
|
|
|
if (base::GlobalHistogramAllocator::CreateWithActiveFileInDir(
|
2017-04-04 10:08:56 -04:00
|
|
|
|
options.metrics_dir, kMetricsFileSize, 0, kMetricsName)) {
|
2016-09-16 13:21:50 -07:00
|
|
|
|
histogram_allocator = base::GlobalHistogramAllocator::Get();
|
|
|
|
|
histogram_allocator->CreateTrackingHistograms(kMetricsName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 13:39:46 -05:00
|
|
|
|
Metrics::HandlerLifetimeMilestone(Metrics::LifetimeMilestone::kStarted);
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
if (options.initial_client_data.IsValid()) {
|
|
|
|
|
exception_handler_server.InitializeWithInheritedDataForInitialClient(
|
2019-08-30 11:51:47 -07:00
|
|
|
|
options.initial_client_data, exception_handler.get());
|
2016-10-21 13:08:18 -07:00
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
2018-02-20 15:03:14 -08:00
|
|
|
|
if (options.initial_client_fd == kInvalidFileHandle ||
|
2019-04-29 14:28:53 -07:00
|
|
|
|
!exception_handler_server.InitializeWithClient(
|
2019-05-01 22:19:21 -07:00
|
|
|
|
ScopedFileHandle(options.initial_client_fd),
|
|
|
|
|
options.shared_client_connection)) {
|
2018-02-20 15:03:14 -08:00
|
|
|
|
return ExitFailure();
|
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2016-10-21 13:08:18 -07:00
|
|
|
|
|
2019-08-30 11:51:47 -07:00
|
|
|
|
exception_handler_server.Run(exception_handler.get());
|
2015-11-06 10:52:09 -08:00
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|