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

Side by Side Diff: snapshot/minidump/process_snapshot_minidump.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, 10 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/process_snapshot_minidump.h"
16
17 #include "util/file/file_io.h"
18 #include "snapshot/minidump/minidump_simple_string_dictionary_reader.h"
19
20 namespace crashpad {
21
22 ProcessSnapshotMinidump::ProcessSnapshotMinidump()
23 : ProcessSnapshot(),
24 header_(),
25 stream_directory_(),
26 stream_map_(),
27 crashpad_info_(),
28 annotations_simple_map_(),
29 file_reader_(nullptr),
30 initialized_() {
31 }
32
33 ProcessSnapshotMinidump::~ProcessSnapshotMinidump() {
34 }
35
36 bool ProcessSnapshotMinidump::Initialize(FileReaderInterface* file_reader) {
37 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
38
39 file_reader_ = file_reader;
40
41 if (!file_reader_->SeekSet(0)) {
42 return false;
43 }
44
45 if (!file_reader_->ReadExactly(&header_, sizeof(header_))) {
46 return false;
47 }
48
49 if (header_.Signature != MINIDUMP_SIGNATURE) {
50 LOG(ERROR) << "minidump signature mismatch";
51 return false;
52 }
53
54 if (header_.Version != MINIDUMP_VERSION) {
55 LOG(ERROR) << "minidump version mismatch";
56 return false;
57 }
58
59 if (!file_reader->SeekSet(header_.StreamDirectoryRva)) {
60 return false;
61 }
62
63 stream_directory_.resize(header_.NumberOfStreams);
64 if (!file_reader_->ReadExactly(
65 &stream_directory_[0],
66 header_.NumberOfStreams * sizeof(stream_directory_[0]))) {
67 return false;
68 }
69
70 for (const MINIDUMP_DIRECTORY& directory : stream_directory_) {
71 const MinidumpStreamType stream_type =
72 static_cast<MinidumpStreamType>(directory.StreamType);
73 if (stream_map_.find(stream_type) != stream_map_.end()) {
74 LOG(ERROR) << "duplicate streams for type " << directory.StreamType;
75 return false;
76 }
77
78 stream_map_[stream_type] = &directory.Location;
79 }
80
81 INITIALIZATION_STATE_SET_VALID(initialized_);
82
83 InitializeCrashpadInfo();
84
85 return true;
86 }
87
88 pid_t ProcessSnapshotMinidump::ProcessID() const {
89 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
90 NOTREACHED();
91 return 0;
92 }
93
94 pid_t ProcessSnapshotMinidump::ParentProcessID() const {
95 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
96 NOTREACHED();
97 return 0;
98 }
99
100 void ProcessSnapshotMinidump::SnapshotTime(timeval* snapshot_time) const {
101 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
102 NOTREACHED();
103 snapshot_time->tv_sec = 0;
104 snapshot_time->tv_usec = 0;
105 }
106
107 void ProcessSnapshotMinidump::ProcessStartTime(timeval* start_time) const {
108 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
109 NOTREACHED();
110 start_time->tv_sec = 0;
111 start_time->tv_usec = 0;
112 }
113
114 void ProcessSnapshotMinidump::ProcessCPUTimes(timeval* user_time,
115 timeval* system_time) const {
116 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
117 NOTREACHED();
118 user_time->tv_sec = 0;
119 user_time->tv_usec = 0;
120 system_time->tv_sec = 0;
121 system_time->tv_usec = 0;
122 }
123
124 const std::map<std::string, std::string>&
125 ProcessSnapshotMinidump::AnnotationsSimpleMap() const {
126 // TODO(mark): This method should not be const, although the interface
127 // currently imposes this requirement. Making it non-const would allow
128 // annotations_simple_map_ to be lazily constructed: InitializeCrashpadInfo()
129 // could be called here, and from other locations that require it, rather than
130 // calling it from Initialize().
131 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
132 return annotations_simple_map_;
133 }
134
135 const SystemSnapshot* ProcessSnapshotMinidump::System() const {
136 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
137 NOTREACHED();
138 return nullptr;
139 }
140
141 std::vector<const ThreadSnapshot*> ProcessSnapshotMinidump::Threads() const {
142 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
143 NOTREACHED();
144 return std::vector<const ThreadSnapshot*>();
145 }
146
147 std::vector<const ModuleSnapshot*> ProcessSnapshotMinidump::Modules() const {
148 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
149 NOTREACHED();
150 return std::vector<const ModuleSnapshot*>();
151 }
152
153 const ExceptionSnapshot* ProcessSnapshotMinidump::Exception() const {
154 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
155 NOTREACHED();
156 return nullptr;
157 }
158
159 void ProcessSnapshotMinidump::InitializeCrashpadInfo() {
160 const auto& it = stream_map_.find(kMinidumpStreamTypeCrashpadInfo);
161 if (it == stream_map_.end()) {
162 return;
163 }
164
165 if (it->second->DataSize < sizeof(crashpad_info_)) {
166 LOG(ERROR) << "crashpad_info size mismatch";
167 return;
168 }
169
170 if (!file_reader_->SeekSet(it->second->Rva)) {
171 return;
172 }
173
174 if (!file_reader_->ReadExactly(&crashpad_info_, sizeof(crashpad_info_))) {
175 return;
176 }
177
178 if (crashpad_info_.version != MinidumpCrashpadInfo::kVersion) {
179 LOG(ERROR) << "crashpad_info version mismatch";
180 return;
181 }
182
183 internal::ReadMinidumpSimpleStringDictionary(
184 file_reader_,
185 crashpad_info_.simple_annotations,
186 &annotations_simple_map_);
187 }
188
189 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/minidump/process_snapshot_minidump.h ('k') | snapshot/minidump/process_snapshot_minidump_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698