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

Side by Side Diff: third_party/crashpad/crashpad/snapshot/win/pe_image_annotations_reader.cc

Issue 1505213004: Copy Crashpad into the Chrome tree instead of importing it via DEPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments, update README.chromium Created 5 years 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/win/pe_image_annotations_reader.h"
16
17 #include <string.h>
18
19 #include "base/strings/utf_string_conversions.h"
20 #include "client/simple_string_dictionary.h"
21 #include "snapshot/win/pe_image_reader.h"
22 #include "snapshot/win/process_reader_win.h"
23 #include "util/win/process_structs.h"
24
25 namespace crashpad {
26
27 PEImageAnnotationsReader::PEImageAnnotationsReader(
28 ProcessReaderWin* process_reader,
29 const PEImageReader* pe_image_reader,
30 const std::wstring& name)
31 : name_(name),
32 process_reader_(process_reader),
33 pe_image_reader_(pe_image_reader) {
34 }
35
36 std::map<std::string, std::string> PEImageAnnotationsReader::SimpleMap() const {
37 std::map<std::string, std::string> simple_map_annotations;
38 if (process_reader_->Is64Bit()) {
39 ReadCrashpadSimpleAnnotations<process_types::internal::Traits64>(
40 &simple_map_annotations);
41 } else {
42 ReadCrashpadSimpleAnnotations<process_types::internal::Traits32>(
43 &simple_map_annotations);
44 }
45 return simple_map_annotations;
46 }
47
48 template <class Traits>
49 void PEImageAnnotationsReader::ReadCrashpadSimpleAnnotations(
50 std::map<std::string, std::string>* simple_map_annotations) const {
51 process_types::CrashpadInfo<Traits> crashpad_info;
52 if (!pe_image_reader_->GetCrashpadInfo(&crashpad_info))
53 return;
54
55 if (!crashpad_info.simple_annotations)
56 return;
57
58 std::vector<SimpleStringDictionary::Entry>
59 simple_annotations(SimpleStringDictionary::num_entries);
60 if (!process_reader_->ReadMemory(
61 crashpad_info.simple_annotations,
62 simple_annotations.size() * sizeof(simple_annotations[0]),
63 &simple_annotations[0])) {
64 LOG(WARNING) << "could not read simple annotations from "
65 << base::UTF16ToUTF8(name_);
66 return;
67 }
68
69 for (const auto& entry : simple_annotations) {
70 size_t key_length = strnlen(entry.key, sizeof(entry.key));
71 if (key_length) {
72 std::string key(entry.key, key_length);
73 std::string value(entry.value, strnlen(entry.value, sizeof(entry.value)));
74 if (!simple_map_annotations->insert(std::make_pair(key, value)).second) {
75 LOG(INFO) << "duplicate simple annotation " << key << " in "
76 << base::UTF16ToUTF8(name_);
77 }
78 }
79 }
80 }
81
82 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698