| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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 "snapshot/mac/mach_o_image_annotations_reader.h" | 15 #include "snapshot/mac/mach_o_image_annotations_reader.h" |
| 16 | 16 |
| 17 #include <mach-o/loader.h> | 17 #include <mach-o/loader.h> |
| 18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 19 | 19 |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "client/crashpad_info.h" | 21 #include "client/crashpad_info.h" |
| 22 #include "client/simple_string_dictionary.h" | 22 #include "client/simple_string_dictionary.h" |
| 23 #include "snapshot/mac/mach_o_image_reader.h" | 23 #include "snapshot/mac/mach_o_image_reader.h" |
| 24 #include "snapshot/mac/process_reader.h" | 24 #include "snapshot/mac/process_reader.h" |
| 25 #include "snapshot/mac/process_types.h" | |
| 26 #include "util/mach/task_memory.h" | 25 #include "util/mach/task_memory.h" |
| 27 #include "util/stdlib/strnlen.h" | 26 #include "util/stdlib/strnlen.h" |
| 28 | 27 |
| 29 namespace crashpad { | 28 namespace crashpad { |
| 30 | 29 |
| 31 MachOImageAnnotationsReader::MachOImageAnnotationsReader( | 30 MachOImageAnnotationsReader::MachOImageAnnotationsReader( |
| 32 ProcessReader* process_reader, | 31 ProcessReader* process_reader, |
| 33 const MachOImageReader* image_reader, | 32 const MachOImageReader* image_reader, |
| 34 const std::string& name) | 33 const std::string& name) |
| 35 : name_(name), | 34 : name_(name), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (!message.empty()) { | 130 if (!message.empty()) { |
| 132 vector_annotations->push_back(message); | 131 vector_annotations->push_back(message); |
| 133 } | 132 } |
| 134 } else { | 133 } else { |
| 135 LOG(WARNING) << "could not read dylinker error string from " << name_; | 134 LOG(WARNING) << "could not read dylinker error string from " << name_; |
| 136 } | 135 } |
| 137 } | 136 } |
| 138 | 137 |
| 139 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( | 138 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( |
| 140 std::map<std::string, std::string>* simple_map_annotations) const { | 139 std::map<std::string, std::string>* simple_map_annotations) const { |
| 141 mach_vm_address_t crashpad_info_address; | 140 process_types::CrashpadInfo crashpad_info; |
| 142 const process_types::section* crashpad_info_section = | 141 if (!image_reader_->GetCrashpadInfo(&crashpad_info)) { |
| 143 image_reader_->GetSectionByName( | |
| 144 SEG_DATA, "__crashpad_info", &crashpad_info_address); | |
| 145 if (!crashpad_info_section) { | |
| 146 return; | 142 return; |
| 147 } | 143 } |
| 148 | 144 |
| 149 process_types::CrashpadInfo crashpad_info; | |
| 150 if (crashpad_info_section->size < | |
| 151 crashpad_info.ExpectedSize(process_reader_)) { | |
| 152 LOG(WARNING) << "small crashpad info section size " | |
| 153 << crashpad_info_section->size << " in " << name_; | |
| 154 return; | |
| 155 } | |
| 156 | |
| 157 if (!crashpad_info.Read(process_reader_, crashpad_info_address)) { | |
| 158 LOG(WARNING) << "could not read crashpad info from " << name_; | |
| 159 return; | |
| 160 } | |
| 161 | |
| 162 if (crashpad_info.signature != CrashpadInfo::kSignature || | |
| 163 crashpad_info.size != crashpad_info_section->size || | |
| 164 crashpad_info.version < 1) { | |
| 165 LOG(WARNING) << "unexpected crashpad info data in " << name_; | |
| 166 return; | |
| 167 } | |
| 168 | |
| 169 if (!crashpad_info.simple_annotations) { | 145 if (!crashpad_info.simple_annotations) { |
| 170 return; | 146 return; |
| 171 } | 147 } |
| 172 | 148 |
| 173 std::vector<SimpleStringDictionary::Entry> | 149 std::vector<SimpleStringDictionary::Entry> |
| 174 simple_annotations(SimpleStringDictionary::num_entries); | 150 simple_annotations(SimpleStringDictionary::num_entries); |
| 175 if (!process_reader_->Memory() | 151 if (!process_reader_->Memory() |
| 176 ->Read(crashpad_info.simple_annotations, | 152 ->Read(crashpad_info.simple_annotations, |
| 177 simple_annotations.size() * sizeof(simple_annotations[0]), | 153 simple_annotations.size() * sizeof(simple_annotations[0]), |
| 178 &simple_annotations[0])) { | 154 &simple_annotations[0])) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 189 simple_map_annotations->insert( | 165 simple_map_annotations->insert( |
| 190 std::pair<std::string, std::string>(key, value)); | 166 std::pair<std::string, std::string>(key, value)); |
| 191 } else { | 167 } else { |
| 192 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; | 168 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; |
| 193 } | 169 } |
| 194 } | 170 } |
| 195 } | 171 } |
| 196 } | 172 } |
| 197 | 173 |
| 198 } // namespace crashpad | 174 } // namespace crashpad |
| OLD | NEW |