| Index: handler/main.cc
|
| diff --git a/handler/mac/main.cc b/handler/main.cc
|
| similarity index 74%
|
| rename from handler/mac/main.cc
|
| rename to handler/main.cc
|
| index 39e5c8c4e30d5cf70a27221eee5ef5983aaca74c..0f3c3643498a1dae93679517dc2e9f071fb092a0 100644
|
| --- a/handler/mac/main.cc
|
| +++ b/handler/main.cc
|
| @@ -13,7 +13,6 @@
|
| // limitations under the License.
|
|
|
| #include <getopt.h>
|
| -#include <libgen.h>
|
| #include <stdlib.h>
|
|
|
| #include <map>
|
| @@ -22,46 +21,66 @@
|
| #include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "build/build_config.h"
|
| #include "client/crash_report_database.h"
|
| #include "tools/tool_support.h"
|
| #include "handler/crash_report_upload_thread.h"
|
| -#include "handler/mac/crash_report_exception_handler.h"
|
| -#include "handler/mac/exception_handler_server.h"
|
| -#include "util/mach/child_port_handshake.h"
|
| -#include "util/posix/close_stdio.h"
|
| #include "util/stdlib/map_insert.h"
|
| #include "util/stdlib/string_number_conversion.h"
|
| #include "util/string/split_string.h"
|
| #include "util/synchronization/semaphore.h"
|
|
|
| +#if defined(OS_MACOSX)
|
| +#include <libgen.h>
|
| +#include "handler/mac/crash_report_exception_handler.h"
|
| +#include "handler/mac/exception_handler_server.h"
|
| +#include "util/mach/child_port_handshake.h"
|
| +#include "util/posix/close_stdio.h"
|
| +#elif defined(OS_WIN)
|
| +#include <windows.h>
|
| +#include "handler/win/crash_report_exception_handler.h"
|
| +#include "util/win/exception_handler_server.h"
|
| +#endif // OS_MACOSX
|
| +
|
| namespace crashpad {
|
| namespace {
|
|
|
| -void Usage(const std::string& me) {
|
| +void Usage(const base::FilePath& me) {
|
| fprintf(stderr,
|
| -"Usage: %s [OPTION]...\n"
|
| +"Usage: %" PRFilePath " [OPTION]...\n"
|
| "Crashpad's exception handler server.\n"
|
| "\n"
|
| " --annotation=KEY=VALUE set a process annotation in each crash report\n"
|
| " --database=PATH store the crash report database at PATH\n"
|
| +#if defined(OS_MACOSX)
|
| " --handshake-fd=FD establish communication with the client over FD\n"
|
| +#elif defined(OS_WIN)
|
| +" --pipe-name=PIPE communicate with the client over PIPE\n"
|
| +#endif // OS_MACOSX
|
| " --url=URL send crash reports to this Breakpad server URL,\n"
|
| " only if uploads are enabled for the database\n"
|
| " --help display this help and exit\n"
|
| " --version output version information and exit\n",
|
| - me.c_str());
|
| + me.value().c_str());
|
| ToolSupport::UsageTail(me);
|
| }
|
|
|
| int HandlerMain(int argc, char* argv[]) {
|
| - const std::string me(basename(argv[0]));
|
| + const base::FilePath argv0(
|
| + ToolSupport::CommandLineArgumentToFilePathStringType(argv[0]));
|
| + const base::FilePath me(argv0.BaseName());
|
|
|
| enum OptionFlags {
|
| // Long options without short equivalents.
|
| kOptionLastChar = 255,
|
| kOptionAnnotation,
|
| kOptionDatabase,
|
| +#if defined(OS_MACOSX)
|
| kOptionHandshakeFD,
|
| +#elif defined(OS_WIN)
|
| + kOptionPipeName,
|
| +#endif // OS_MACOSX
|
| kOptionURL,
|
|
|
| // Standard options.
|
| @@ -73,14 +92,24 @@ int HandlerMain(int argc, char* argv[]) {
|
| std::map<std::string, std::string> annotations;
|
| std::string url;
|
| const char* database;
|
| +#if defined(OS_MACOSX)
|
| int handshake_fd;
|
| +#elif defined(OS_WIN)
|
| + std::string pipe_name;
|
| +#endif
|
| } options = {};
|
| +#if defined(OS_MACOSX)
|
| options.handshake_fd = -1;
|
| +#endif
|
|
|
| const option long_options[] = {
|
| {"annotation", required_argument, nullptr, kOptionAnnotation},
|
| {"database", required_argument, nullptr, kOptionDatabase},
|
| +#if defined(OS_MACOSX)
|
| {"handshake-fd", required_argument, nullptr, kOptionHandshakeFD},
|
| +#elif defined(OS_WIN)
|
| + {"pipe-name", required_argument, nullptr, kOptionPipeName},
|
| +#endif
|
| {"url", required_argument, nullptr, kOptionURL},
|
| {"help", no_argument, nullptr, kOptionHelp},
|
| {"version", no_argument, nullptr, kOptionVersion},
|
| @@ -108,6 +137,7 @@ int HandlerMain(int argc, char* argv[]) {
|
| options.database = optarg;
|
| break;
|
| }
|
| +#if defined(OS_MACOSX)
|
| case kOptionHandshakeFD: {
|
| if (!StringToNumber(optarg, &options.handshake_fd) ||
|
| options.handshake_fd < 0) {
|
| @@ -117,6 +147,12 @@ int HandlerMain(int argc, char* argv[]) {
|
| }
|
| break;
|
| }
|
| +#elif defined(OS_WIN)
|
| + case kOptionPipeName: {
|
| + options.pipe_name = optarg;
|
| + break;
|
| + }
|
| +#endif // OS_MACOSX
|
| case kOptionURL: {
|
| options.url = optarg;
|
| break;
|
| @@ -138,10 +174,17 @@ int HandlerMain(int argc, char* argv[]) {
|
| argc -= optind;
|
| argv += optind;
|
|
|
| +#if defined(OS_MACOSX)
|
| if (options.handshake_fd < 0) {
|
| ToolSupport::UsageHint(me, "--handshake-fd is required");
|
| return EXIT_FAILURE;
|
| }
|
| +#elif defined(OS_WIN)
|
| + if (options.pipe_name.empty()) {
|
| + ToolSupport::UsageHint(me, "--pipe-name is required");
|
| + return EXIT_FAILURE;
|
| + }
|
| +#endif
|
|
|
| if (!options.database) {
|
| ToolSupport::UsageHint(me, "--database is required");
|
| @@ -153,16 +196,23 @@ int HandlerMain(int argc, char* argv[]) {
|
| return EXIT_FAILURE;
|
| }
|
|
|
| - CloseStdinAndStdout();
|
| -
|
| ExceptionHandlerServer exception_handler_server;
|
|
|
| +#if defined(OS_MACOSX)
|
| + CloseStdinAndStdout();
|
| ChildPortHandshake::RunClient(options.handshake_fd,
|
| exception_handler_server.receive_port(),
|
| MACH_MSG_TYPE_MAKE_SEND);
|
| +#endif // OS_MACOSX
|
|
|
| scoped_ptr<CrashReportDatabase> database(
|
| - CrashReportDatabase::Initialize(base::FilePath(options.database)));
|
| + CrashReportDatabase::Initialize(base::FilePath(
|
| +#if defined(OS_MACOSX)
|
| + options.database
|
| +#elif defined(OS_WIN)
|
| + base::UTF8ToUTF16(options.database)
|
| +#endif
|
| + )));
|
| if (!database) {
|
| return EXIT_FAILURE;
|
| }
|
| @@ -173,7 +223,11 @@ int HandlerMain(int argc, char* argv[]) {
|
| CrashReportExceptionHandler exception_handler(
|
| database.get(), &upload_thread, &options.annotations);
|
|
|
| +#if defined(OS_MACOSX)
|
| exception_handler_server.Run(&exception_handler);
|
| +#elif defined(OS_WIN)
|
| + exception_handler_server.Run(&exception_handler, options.pipe_name);
|
| +#endif // OS_MACOSX
|
|
|
| upload_thread.Stop();
|
|
|
| @@ -183,6 +237,12 @@ int HandlerMain(int argc, char* argv[]) {
|
| } // namespace
|
| } // namespace crashpad
|
|
|
| +#if defined(OS_MACOSX)
|
| int main(int argc, char* argv[]) {
|
| return crashpad::HandlerMain(argc, argv);
|
| }
|
| +#elif defined(OS_WIN)
|
| +int wmain(int argc, wchar_t* argv[]) {
|
| + return crashpad::ToolSupport::Wmain(argc, argv, crashpad::HandlerMain);
|
| +}
|
| +#endif // OS_MACOSX
|
|
|