OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
26 #include "client/crash_report_database.h" | 26 #include "client/crash_report_database.h" |
27 #include "tools/tool_support.h" | 27 #include "tools/tool_support.h" |
28 #include "handler/mac/crash_report_exception_handler.h" | 28 #include "handler/mac/crash_report_exception_handler.h" |
29 #include "handler/mac/crash_report_upload_thread.h" | 29 #include "handler/mac/crash_report_upload_thread.h" |
30 #include "handler/mac/exception_handler_server.h" | 30 #include "handler/mac/exception_handler_server.h" |
31 #include "util/mach/child_port_handshake.h" | 31 #include "util/mach/child_port_handshake.h" |
32 #include "util/posix/close_stdio.h" | 32 #include "util/posix/close_stdio.h" |
33 #include "util/stdlib/string_number_conversion.h" | 33 #include "util/stdlib/string_number_conversion.h" |
| 34 #include "util/string/split_string.h" |
34 #include "util/synchronization/semaphore.h" | 35 #include "util/synchronization/semaphore.h" |
35 | 36 |
36 namespace crashpad { | 37 namespace crashpad { |
37 namespace { | 38 namespace { |
38 | 39 |
39 bool SplitString(const std::string& string, | |
40 std::string* left, | |
41 std::string* right) { | |
42 size_t equals_pos = string.find('='); | |
43 if (equals_pos == 0 || equals_pos == std::string::npos) { | |
44 return false; | |
45 } | |
46 | |
47 left->assign(string, 0, equals_pos); | |
48 right->assign(string, equals_pos + 1, std::string::npos); | |
49 return true; | |
50 } | |
51 | |
52 void Usage(const std::string& me) { | 40 void Usage(const std::string& me) { |
53 fprintf(stderr, | 41 fprintf(stderr, |
54 "Usage: %s [OPTION]...\n" | 42 "Usage: %s [OPTION]...\n" |
55 "Crashpad's exception handler server.\n" | 43 "Crashpad's exception handler server.\n" |
56 "\n" | 44 "\n" |
57 " --annotation=KEY=VALUE set a process annotation in each crash report\n" | 45 " --annotation=KEY=VALUE set a process annotation in each crash report\n" |
58 " --database=PATH store the crash report database at PATH\n" | 46 " --database=PATH store the crash report database at PATH\n" |
59 " --handshake-fd=FD establish communication with the client over FD\n
" | 47 " --handshake-fd=FD establish communication with the client over FD\n
" |
| 48 " --url=URL send crash reports to this Breakpad server URL\n" |
60 " --help display this help and exit\n" | 49 " --help display this help and exit\n" |
61 " --version output version information and exit\n", | 50 " --version output version information and exit\n", |
62 me.c_str()); | 51 me.c_str()); |
63 ToolSupport::UsageTail(me); | 52 ToolSupport::UsageTail(me); |
64 } | 53 } |
65 | 54 |
66 int HandlerMain(int argc, char* argv[]) { | 55 int HandlerMain(int argc, char* argv[]) { |
67 const std::string me(basename(argv[0])); | 56 const std::string me(basename(argv[0])); |
68 | 57 |
69 enum OptionFlags { | 58 enum OptionFlags { |
(...skipping 26 matching lines...) Expand all Loading... |
96 {"version", no_argument, nullptr, kOptionVersion}, | 85 {"version", no_argument, nullptr, kOptionVersion}, |
97 {nullptr, 0, nullptr, 0}, | 86 {nullptr, 0, nullptr, 0}, |
98 }; | 87 }; |
99 | 88 |
100 int opt; | 89 int opt; |
101 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { | 90 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { |
102 switch (opt) { | 91 switch (opt) { |
103 case kOptionAnnotation: { | 92 case kOptionAnnotation: { |
104 std::string key; | 93 std::string key; |
105 std::string value; | 94 std::string value; |
106 if (!SplitString(optarg, &key, &value)) { | 95 if (!SplitString(optarg, '=', &key, &value)) { |
107 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); | 96 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); |
108 return EXIT_FAILURE; | 97 return EXIT_FAILURE; |
109 } | 98 } |
110 auto it = options.annotations.find(key); | 99 auto it = options.annotations.find(key); |
111 if (it != options.annotations.end()) { | 100 if (it != options.annotations.end()) { |
112 LOG(WARNING) << "duplicate key " << key << ", discarding value " | 101 LOG(WARNING) << "duplicate key " << key << ", discarding value " |
113 << it->second; | 102 << it->second; |
114 it->second = value; | 103 it->second = value; |
115 } else { | 104 } else { |
116 options.annotations.insert(std::make_pair(key, value)); | 105 options.annotations.insert(std::make_pair(key, value)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 181 |
193 return EXIT_SUCCESS; | 182 return EXIT_SUCCESS; |
194 } | 183 } |
195 | 184 |
196 } // namespace | 185 } // namespace |
197 } // namespace crashpad | 186 } // namespace crashpad |
198 | 187 |
199 int main(int argc, char* argv[]) { | 188 int main(int argc, char* argv[]) { |
200 return crashpad::HandlerMain(argc, argv); | 189 return crashpad::HandlerMain(argc, argv); |
201 } | 190 } |
OLD | NEW |