| 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 <errno.h> | 15 #include <errno.h> |
| 16 #include <getopt.h> | 16 #include <getopt.h> |
| 17 #include <libgen.h> | 17 #include <libgen.h> |
| 18 #include <stdio.h> | 18 #include <stdio.h> |
| 19 #include <stdlib.h> | 19 #include <stdlib.h> |
| 20 #include <unistd.h> | 20 #include <unistd.h> |
| 21 | 21 |
| 22 #include <map> | 22 #include <map> |
| 23 #include <string> | 23 #include <string> |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/files/file_path.h" | 26 #include "base/files/file_path.h" |
| 27 #include "base/logging.h" | 27 #include "base/logging.h" |
| 28 #include "client/crashpad_client.h" | 28 #include "client/crashpad_client.h" |
| 29 #include "tools/tool_support.h" | 29 #include "tools/tool_support.h" |
| 30 #include "util/stdlib/map_insert.h" |
| 30 #include "util/string/split_string.h" | 31 #include "util/string/split_string.h" |
| 31 | 32 |
| 32 namespace crashpad { | 33 namespace crashpad { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 void Usage(const std::string& me) { | 36 void Usage(const std::string& me) { |
| 36 fprintf(stderr, | 37 fprintf(stderr, |
| 37 "Usage: %s [OPTION]... COMMAND [ARG]...\n" | 38 "Usage: %s [OPTION]... COMMAND [ARG]...\n" |
| 38 "Start a Crashpad handler and have it handle crashes from COMMAND.\n" | 39 "Start a Crashpad handler and have it handle crashes from COMMAND.\n" |
| 39 "\n" | 40 "\n" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 options.handler = optarg; | 112 options.handler = optarg; |
| 112 break; | 113 break; |
| 113 } | 114 } |
| 114 case kOptionAnnotation: { | 115 case kOptionAnnotation: { |
| 115 std::string key; | 116 std::string key; |
| 116 std::string value; | 117 std::string value; |
| 117 if (!SplitString(optarg, '=', &key, &value)) { | 118 if (!SplitString(optarg, '=', &key, &value)) { |
| 118 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); | 119 ToolSupport::UsageHint(me, "--annotation requires KEY=VALUE"); |
| 119 return EXIT_FAILURE; | 120 return EXIT_FAILURE; |
| 120 } | 121 } |
| 121 auto it = options.annotations.find(key); | 122 std::string old_value; |
| 122 if (it != options.annotations.end()) { | 123 if (!MapInsertOrReplace(&options.annotations, key, value, &old_value)) { |
| 123 LOG(WARNING) << "duplicate key " << key << ", discarding value " | 124 LOG(WARNING) << "duplicate key " << key << ", discarding value " |
| 124 << it->second; | 125 << old_value; |
| 125 it->second = value; | |
| 126 } else { | |
| 127 options.annotations.insert(std::make_pair(key, value)); | |
| 128 } | 126 } |
| 129 break; | 127 break; |
| 130 } | 128 } |
| 131 case kOptionDatabase: { | 129 case kOptionDatabase: { |
| 132 options.database = optarg; | 130 options.database = optarg; |
| 133 break; | 131 break; |
| 134 } | 132 } |
| 135 case kOptionURL: { | 133 case kOptionURL: { |
| 136 options.url = optarg; | 134 options.url = optarg; |
| 137 break; | 135 break; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 PLOG(ERROR) << "execvp " << argv[0]; | 180 PLOG(ERROR) << "execvp " << argv[0]; |
| 183 return errno == ENOENT ? kExitExecENOENT : kExitExecFailure; | 181 return errno == ENOENT ? kExitExecENOENT : kExitExecFailure; |
| 184 } | 182 } |
| 185 | 183 |
| 186 } // namespace | 184 } // namespace |
| 187 } // namespace crashpad | 185 } // namespace crashpad |
| 188 | 186 |
| 189 int main(int argc, char* argv[]) { | 187 int main(int argc, char* argv[]) { |
| 190 return crashpad::RunWithCrashpadMain(argc, argv); | 188 return crashpad::RunWithCrashpadMain(argc, argv); |
| 191 } | 189 } |
| OLD | NEW |