| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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 "handler/mac/crash_report_upload_thread.h" | 15 #include "handler/mac/crash_report_upload_thread.h" |
| 16 | 16 |
| 17 #include <errno.h> | 17 #include <errno.h> |
| 18 #include <time.h> | 18 #include <time.h> |
| 19 | 19 |
| 20 #include <map> | 20 #include <map> |
| 21 #include <vector> | 21 #include <vector> |
| 22 #include <utility> | |
| 23 | 22 |
| 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/settings.h" | 25 #include "client/settings.h" |
| 27 #include "snapshot/minidump/process_snapshot_minidump.h" | 26 #include "snapshot/minidump/process_snapshot_minidump.h" |
| 28 #include "snapshot/module_snapshot.h" | 27 #include "snapshot/module_snapshot.h" |
| 29 #include "util/file/file_reader.h" | 28 #include "util/file/file_reader.h" |
| 30 #include "util/misc/uuid.h" | 29 #include "util/misc/uuid.h" |
| 31 #include "util/net/http_body.h" | 30 #include "util/net/http_body.h" |
| 32 #include "util/net/http_multipart_builder.h" | 31 #include "util/net/http_multipart_builder.h" |
| 33 #include "util/net/http_transport.h" | 32 #include "util/net/http_transport.h" |
| 33 #include "util/stdlib/map_insert.h" |
| 34 | 34 |
| 35 namespace crashpad { | 35 namespace crashpad { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map, | 39 void InsertOrReplaceMapEntry(std::map<std::string, std::string>* map, |
| 40 const std::string& key, | 40 const std::string& key, |
| 41 const std::string& value) { | 41 const std::string& value) { |
| 42 auto it = map->find(key); | 42 std::string old_value; |
| 43 if (it != map->end()) { | 43 if (!MapInsertOrReplace(map, key, value, &old_value)) { |
| 44 LOG(WARNING) << "duplicate key " << key << ", discarding value " | 44 LOG(WARNING) << "duplicate key " << key << ", discarding value " |
| 45 << it->second; | 45 << old_value; |
| 46 it->second = value; | |
| 47 } else { | |
| 48 map->insert(std::make_pair(key, value)); | |
| 49 } | 46 } |
| 50 } | 47 } |
| 51 | 48 |
| 52 // Given a minidump file readable by |minidump_file_reader|, returns a map of | 49 // Given a minidump file readable by |minidump_file_reader|, returns a map of |
| 53 // key-value pairs to use as HTTP form parameters for upload to a Breakpad | 50 // key-value pairs to use as HTTP form parameters for upload to a Breakpad |
| 54 // server. The map is built by combining the process simple annotations map with | 51 // server. The map is built by combining the process simple annotations map with |
| 55 // each module’s simple annotations map. In the case of duplicate keys, the map | 52 // each module’s simple annotations map. In the case of duplicate keys, the map |
| 56 // will retain the first value found for any key, and will log a warning about | 53 // will retain the first value found for any key, and will log a warning about |
| 57 // discarded values. Each module’s annotations vector is also examined and built | 54 // discarded values. Each module’s annotations vector is also examined and built |
| 58 // into a single string value, with distinct elements separated by newlines, and | 55 // into a single string value, with distinct elements separated by newlines, and |
| 59 // stored at the key named “list_annotations”, which supersedes any other key | 56 // stored at the key named “list_annotations”, which supersedes any other key |
| 60 // found by that name. The client ID stored in the minidump is converted to | 57 // found by that name. The client ID stored in the minidump is converted to |
| 61 // a string and stored at the key named “guid”, which supersedes any other key | 58 // a string and stored at the key named “guid”, which supersedes any other key |
| 62 // found by that name. | 59 // found by that name. |
| 63 // | 60 // |
| 64 // In the event of an error reading the minidump file, a message will be logged. | 61 // In the event of an error reading the minidump file, a message will be logged. |
| 65 std::map<std::string, std::string> BreakpadHTTPFormParametersFromMinidump( | 62 std::map<std::string, std::string> BreakpadHTTPFormParametersFromMinidump( |
| 66 FileReader* minidump_file_reader) { | 63 FileReader* minidump_file_reader) { |
| 67 ProcessSnapshotMinidump minidump_process_snapshot; | 64 ProcessSnapshotMinidump minidump_process_snapshot; |
| 68 if (!minidump_process_snapshot.Initialize(minidump_file_reader)) { | 65 if (!minidump_process_snapshot.Initialize(minidump_file_reader)) { |
| 69 return std::map<std::string, std::string>(); | 66 return std::map<std::string, std::string>(); |
| 70 } | 67 } |
| 71 | 68 |
| 72 std::map<std::string, std::string> parameters = | 69 std::map<std::string, std::string> parameters = |
| 73 minidump_process_snapshot.AnnotationsSimpleMap(); | 70 minidump_process_snapshot.AnnotationsSimpleMap(); |
| 74 | 71 |
| 75 std::string list_annotations; | 72 std::string list_annotations; |
| 76 for (const ModuleSnapshot* module : minidump_process_snapshot.Modules()) { | 73 for (const ModuleSnapshot* module : minidump_process_snapshot.Modules()) { |
| 77 for (const auto& kv : module->AnnotationsSimpleMap()) { | 74 for (const auto& kv : module->AnnotationsSimpleMap()) { |
| 78 if (parameters.find(kv.first) != parameters.end()) { | 75 if (!parameters.insert(kv).second) { |
| 79 LOG(WARNING) << "duplicate key " << kv.first << ", discarding value " | 76 LOG(WARNING) << "duplicate key " << kv.first << ", discarding value " |
| 80 << kv.second; | 77 << kv.second; |
| 81 } else { | |
| 82 parameters.insert(kv); | |
| 83 } | 78 } |
| 84 } | 79 } |
| 85 | 80 |
| 86 for (std::string annotation : module->AnnotationsVector()) { | 81 for (std::string annotation : module->AnnotationsVector()) { |
| 87 list_annotations.append(annotation); | 82 list_annotations.append(annotation); |
| 88 list_annotations.append("\n"); | 83 list_annotations.append("\n"); |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 | 86 |
| 92 if (!list_annotations.empty()) { | 87 if (!list_annotations.empty()) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 357 } |
| 363 | 358 |
| 364 // static | 359 // static |
| 365 void* CrashReportUploadThread::RunThreadMain(void* arg) { | 360 void* CrashReportUploadThread::RunThreadMain(void* arg) { |
| 366 CrashReportUploadThread* self = static_cast<CrashReportUploadThread*>(arg); | 361 CrashReportUploadThread* self = static_cast<CrashReportUploadThread*>(arg); |
| 367 self->ThreadMain(); | 362 self->ThreadMain(); |
| 368 return nullptr; | 363 return nullptr; |
| 369 } | 364 } |
| 370 | 365 |
| 371 } // namespace crashpad | 366 } // namespace crashpad |
| OLD | NEW |