Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: snapshot/minidump/minidump_simple_string_dictionary_reader.cc

Issue 932153003: Add ProcessSnapshotMinidump, the beginning of the minidump variant of the Snapshot family (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "snapshot/minidump/minidump_simple_string_dictionary_reader.h"
16
17 #include <vector>
18 #include <utility>
19
20 #include "base/logging.h"
21 #include "minidump/minidump_extensions.h"
22 #include "snapshot/minidump/minidump_string_reader.h"
23
24 namespace crashpad {
25 namespace internal {
26
27 bool ReadMinidumpSimpleStringDictionary(
28 FileReaderInterface* file_reader,
29 const MINIDUMP_LOCATION_DESCRIPTOR& location,
30 std::map<std::string, std::string>* dictionary) {
31 if (location.Rva == 0) {
32 dictionary->clear();
33 return true;
34 }
35
36 if (location.DataSize < sizeof(MinidumpSimpleStringDictionary)) {
37 LOG(ERROR) << "simple_string_dictionary size mismatch";
38 return false;
39 }
40
41 if (!file_reader->SeekSet(location.Rva)) {
42 return false;
43 }
44
45 uint32_t entry_count;
46 if (!file_reader->ReadExactly(&entry_count, sizeof(entry_count))) {
47 return false;
48 }
49
50 if (location.DataSize !=
51 entry_count * sizeof(MinidumpSimpleStringDictionaryEntry)) {
52 LOG(ERROR) << "simple_string_dictionary size mismatch";
53 return false;
54 }
55
56 std::vector<MinidumpSimpleStringDictionaryEntry> entries(entry_count);
57 if (!file_reader->ReadExactly(&entries[0],
58 entry_count * sizeof(entries[0]))) {
59 return false;
60 }
61
62 std::map<std::string, std::string> local_dictionary;
63 for (const MinidumpSimpleStringDictionaryEntry& entry : entries) {
64 std::string key;
65 if (!ReadMinidumpUTF8String(file_reader, entry.key, &key)) {
66 // Not a hard error, keep trying.
67 continue;
68 }
69
70 std::string value;
71 if (!ReadMinidumpUTF8String(file_reader, entry.value, &value)) {
72 // Not a hard error, keep trying.
73 continue;
74 }
75
76 if (local_dictionary.find(key) != local_dictionary.end()) {
77 LOG(WARNING) << "duplicate key " << key << ", discarding value " << value;
78 continue;
79 }
80
81 local_dictionary.insert(std::make_pair(key, value));
82 }
83
84 dictionary->swap(local_dictionary);
85 return true;
86 }
87
88 } // namespace internal
89 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/minidump/minidump_simple_string_dictionary_reader.h ('k') | snapshot/minidump/minidump_string_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698