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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include <getopt.h> | 15 #include <getopt.h> |
16 #include <libgen.h> | 16 #include <libgen.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 | 18 |
19 #include <map> | 19 #include <map> |
20 #include <string> | 20 #include <string> |
21 #include <utility> | |
22 | 21 |
23 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
24 #include "base/logging.h" | 23 #include "base/logging.h" |
25 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
26 #include "client/crash_report_database.h" | 25 #include "client/crash_report_database.h" |
27 #include "tools/tool_support.h" | 26 #include "tools/tool_support.h" |
28 #include "handler/mac/crash_report_exception_handler.h" | 27 #include "handler/mac/crash_report_exception_handler.h" |
29 #include "handler/mac/crash_report_upload_thread.h" | 28 #include "handler/mac/crash_report_upload_thread.h" |
30 #include "handler/mac/exception_handler_server.h" | 29 #include "handler/mac/exception_handler_server.h" |
31 #include "util/mach/child_port_handshake.h" | 30 #include "util/mach/child_port_handshake.h" |
32 #include "util/posix/close_stdio.h" | 31 #include "util/posix/close_stdio.h" |
| 32 #include "util/stdlib/map_insert.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/string/split_string.h" |
35 #include "util/synchronization/semaphore.h" | 35 #include "util/synchronization/semaphore.h" |
36 | 36 |
37 namespace crashpad { | 37 namespace crashpad { |
38 namespace { | 38 namespace { |
39 | 39 |
40 void Usage(const std::string& me) { | 40 void Usage(const std::string& me) { |
41 fprintf(stderr, | 41 fprintf(stderr, |
42 "Usage: %s [OPTION]...\n" | 42 "Usage: %s [OPTION]...\n" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 int opt; | 90 int opt; |
91 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { | 91 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { |
92 switch (opt) { | 92 switch (opt) { |
93 case kOptionAnnotation: { | 93 case kOptionAnnotation: { |
94 std::string key; | 94 std::string key; |
95 std::string value; | 95 std::string value; |
96 if (!SplitString(optarg, '=', &key, &value)) { | 96 if (!SplitString(optarg, '=', &key, &value)) { |
97 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); | 97 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); |
98 return EXIT_FAILURE; | 98 return EXIT_FAILURE; |
99 } | 99 } |
100 auto it = options.annotations.find(key); | 100 std::string old_value; |
101 if (it != options.annotations.end()) { | 101 if (!MapInsertOrReplace(&options.annotations, key, value, &old_value)) { |
102 LOG(WARNING) << "duplicate key " << key << ", discarding value " | 102 LOG(WARNING) << "duplicate key " << key << ", discarding value " |
103 << it->second; | 103 << old_value; |
104 it->second = value; | |
105 } else { | |
106 options.annotations.insert(std::make_pair(key, value)); | |
107 } | 104 } |
108 break; | 105 break; |
109 } | 106 } |
110 case kOptionDatabase: { | 107 case kOptionDatabase: { |
111 options.database = optarg; | 108 options.database = optarg; |
112 break; | 109 break; |
113 } | 110 } |
114 case kOptionHandshakeFD: { | 111 case kOptionHandshakeFD: { |
115 if (!StringToNumber(optarg, &options.handshake_fd) || | 112 if (!StringToNumber(optarg, &options.handshake_fd) || |
116 options.handshake_fd < 0) { | 113 options.handshake_fd < 0) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 179 |
183 return EXIT_SUCCESS; | 180 return EXIT_SUCCESS; |
184 } | 181 } |
185 | 182 |
186 } // namespace | 183 } // namespace |
187 } // namespace crashpad | 184 } // namespace crashpad |
188 | 185 |
189 int main(int argc, char* argv[]) { | 186 int main(int argc, char* argv[]) { |
190 return crashpad::HandlerMain(argc, argv); | 187 return crashpad::HandlerMain(argc, argv); |
191 } | 188 } |
OLD | NEW |