Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 FileOffset original_offset = file_reader_->SeekGet(); | |
| 42 if (original_offset < 0) { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 if (!file_reader_->SeekSet(0)) { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 if (!file_reader_->ReadExactly(&header_, sizeof(header_))) { | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 if (header_.Signature != MINIDUMP_SIGNATURE) { | |
| 55 LOG(ERROR) << "minidump signature mismatch"; | |
| 56 return false; | |
| 57 } | |
| 58 | |
| 59 if (header_.Version != MINIDUMP_VERSION) { | |
| 60 LOG(ERROR) << "minidump version mismatch"; | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 if (!file_reader->SeekSet(header_.StreamDirectoryRva)) { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 stream_directory_.resize(header_.NumberOfStreams); | |
| 69 if (!file_reader_->ReadExactly( | |
| 70 &stream_directory_[0], | |
| 71 header_.NumberOfStreams * sizeof(stream_directory_[0]))) { | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 for (const MINIDUMP_DIRECTORY& directory : stream_directory_) { | |
| 76 const MinidumpStreamType stream_type = | |
| 77 static_cast<MinidumpStreamType>(directory.StreamType); | |
| 78 if (stream_map_.find(stream_type) != stream_map_.end()) { | |
| 79 LOG(ERROR) << "duplicate streams for type " << directory.StreamType; | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 stream_map_[stream_type] = &directory.Location; | |
| 84 } | |
| 85 | |
| 86 if (!file_reader->SeekSet(original_offset)) { | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 INITIALIZATION_STATE_SET_VALID(initialized_); | |
| 91 | |
| 92 InitializeCrashpadInfo(); | |
| 93 | |
| 94 return true; | |
| 95 } | |
| 96 | |
| 97 pid_t ProcessSnapshotMinidump::ProcessID() const { | |
| 98 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 99 NOTREACHED(); | |
| 100 return 0; | |
| 101 } | |
| 102 | |
| 103 pid_t ProcessSnapshotMinidump::ParentProcessID() const { | |
| 104 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 105 NOTREACHED(); | |
| 106 return 0; | |
| 107 } | |
| 108 | |
| 109 void ProcessSnapshotMinidump::SnapshotTime(timeval* snapshot_time) const { | |
| 110 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 111 NOTREACHED(); | |
| 112 snapshot_time->tv_sec = 0; | |
| 113 snapshot_time->tv_usec = 0; | |
| 114 } | |
| 115 | |
| 116 void ProcessSnapshotMinidump::ProcessStartTime(timeval* start_time) const { | |
| 117 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 118 NOTREACHED(); | |
| 119 start_time->tv_sec = 0; | |
| 120 start_time->tv_usec = 0; | |
| 121 } | |
| 122 | |
| 123 void ProcessSnapshotMinidump::ProcessCPUTimes(timeval* user_time, | |
| 124 timeval* system_time) const { | |
| 125 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 126 NOTREACHED(); | |
| 127 user_time->tv_sec = 0; | |
| 128 user_time->tv_usec = 0; | |
| 129 system_time->tv_sec = 0; | |
| 130 system_time->tv_usec = 0; | |
| 131 } | |
| 132 | |
| 133 const std::map<std::string, std::string>& | |
| 134 ProcessSnapshotMinidump::AnnotationsSimpleMap() const { | |
| 135 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 136 return annotations_simple_map_; | |
| 137 } | |
| 138 | |
| 139 const SystemSnapshot* ProcessSnapshotMinidump::System() const { | |
| 140 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 141 NOTREACHED(); | |
| 142 return nullptr; | |
| 143 } | |
| 144 | |
| 145 std::vector<const ThreadSnapshot*> ProcessSnapshotMinidump::Threads() const { | |
| 146 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 147 NOTREACHED(); | |
| 148 return std::vector<const ThreadSnapshot*>(); | |
| 149 } | |
| 150 | |
| 151 std::vector<const ModuleSnapshot*> ProcessSnapshotMinidump::Modules() const { | |
| 152 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 153 NOTREACHED(); | |
| 154 return std::vector<const ModuleSnapshot*>(); | |
| 155 } | |
| 156 | |
| 157 const ExceptionSnapshot* ProcessSnapshotMinidump::Exception() const { | |
| 158 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
| 159 NOTREACHED(); | |
| 160 return nullptr; | |
| 161 } | |
| 162 | |
| 163 void ProcessSnapshotMinidump::InitializeCrashpadInfo() { | |
| 164 const auto it = stream_map_.find(kMinidumpStreamTypeCrashpadInfo); | |
|
Robert Sesek
2015/02/19 15:13:19
Make this a reference, too?
| |
| 165 if (it == stream_map_.end()) { | |
| 166 return; | |
| 167 } | |
| 168 | |
| 169 if (it->second->DataSize < sizeof(crashpad_info_)) { | |
| 170 LOG(ERROR) << "crashpad_info size mismatch"; | |
| 171 return; | |
| 172 } | |
| 173 | |
| 174 if (!file_reader_->SeekSet(it->second->Rva)) { | |
| 175 return; | |
| 176 } | |
| 177 | |
| 178 if (!file_reader_->ReadExactly(&crashpad_info_, sizeof(crashpad_info_))) { | |
| 179 return; | |
| 180 } | |
| 181 | |
| 182 if (crashpad_info_.version != MinidumpCrashpadInfo::kVersion) { | |
| 183 LOG(ERROR) << "crashpad_info version mismatch"; | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 internal::ReadMinidumpSimpleStringDictionary( | |
| 188 file_reader_, | |
| 189 crashpad_info_.simple_annotations, | |
| 190 &annotations_simple_map_); | |
| 191 } | |
| 192 | |
| 193 } // namespace crashpad | |
| OLD | NEW |