| 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 12 matching lines...) Expand all Loading... |
| 48 | 47 |
| 49 std::map<std::string, std::string> MachOImageAnnotationsReader::SimpleMap() | 48 std::map<std::string, std::string> MachOImageAnnotationsReader::SimpleMap() |
| 50 const { | 49 const { |
| 51 std::map<std::string, std::string> simple_map_annotations; | 50 std::map<std::string, std::string> simple_map_annotations; |
| 52 | 51 |
| 53 ReadCrashpadSimpleAnnotations(&simple_map_annotations); | 52 ReadCrashpadSimpleAnnotations(&simple_map_annotations); |
| 54 | 53 |
| 55 return simple_map_annotations; | 54 return simple_map_annotations; |
| 56 } | 55 } |
| 57 | 56 |
| 57 bool MachOImageAnnotationsReader::GetCrashpadInfo( |
| 58 process_types::CrashpadInfo* crashpad_info) const { |
| 59 mach_vm_address_t crashpad_info_address; |
| 60 const process_types::section* crashpad_info_section = |
| 61 image_reader_->GetSectionByName( |
| 62 SEG_DATA, "__crashpad_info", &crashpad_info_address); |
| 63 if (!crashpad_info_section) { |
| 64 return false; |
| 65 } |
| 66 |
| 67 if (crashpad_info_section->size < |
| 68 crashpad_info->ExpectedSize(process_reader_)) { |
| 69 LOG(WARNING) << "small crashpad info section size " |
| 70 << crashpad_info_section->size << " in " << name_; |
| 71 return false; |
| 72 } |
| 73 |
| 74 if (!crashpad_info->Read(process_reader_, crashpad_info_address)) { |
| 75 LOG(WARNING) << "could not read crashpad info from " << name_; |
| 76 return false; |
| 77 } |
| 78 |
| 79 if (crashpad_info->signature != CrashpadInfo::kSignature || |
| 80 crashpad_info->size != crashpad_info_section->size || |
| 81 crashpad_info->version < 1) { |
| 82 LOG(WARNING) << "unexpected crashpad info data in " << name_; |
| 83 return false; |
| 84 } |
| 85 |
| 86 return true; |
| 87 } |
| 88 |
| 58 void MachOImageAnnotationsReader::ReadCrashReporterClientAnnotations( | 89 void MachOImageAnnotationsReader::ReadCrashReporterClientAnnotations( |
| 59 std::vector<std::string>* vector_annotations) const { | 90 std::vector<std::string>* vector_annotations) const { |
| 60 mach_vm_address_t crash_info_address; | 91 mach_vm_address_t crash_info_address; |
| 61 const process_types::section* crash_info_section = | 92 const process_types::section* crash_info_section = |
| 62 image_reader_->GetSectionByName( | 93 image_reader_->GetSectionByName( |
| 63 SEG_DATA, "__crash_info", &crash_info_address); | 94 SEG_DATA, "__crash_info", &crash_info_address); |
| 64 if (!crash_info_section) { | 95 if (!crash_info_section) { |
| 65 return; | 96 return; |
| 66 } | 97 } |
| 67 | 98 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (!message.empty()) { | 162 if (!message.empty()) { |
| 132 vector_annotations->push_back(message); | 163 vector_annotations->push_back(message); |
| 133 } | 164 } |
| 134 } else { | 165 } else { |
| 135 LOG(WARNING) << "could not read dylinker error string from " << name_; | 166 LOG(WARNING) << "could not read dylinker error string from " << name_; |
| 136 } | 167 } |
| 137 } | 168 } |
| 138 | 169 |
| 139 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( | 170 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( |
| 140 std::map<std::string, std::string>* simple_map_annotations) const { | 171 std::map<std::string, std::string>* simple_map_annotations) const { |
| 141 mach_vm_address_t crashpad_info_address; | 172 process_types::CrashpadInfo crashpad_info; |
| 142 const process_types::section* crashpad_info_section = | 173 if (!GetCrashpadInfo(&crashpad_info)) { |
| 143 image_reader_->GetSectionByName( | |
| 144 SEG_DATA, "__crashpad_info", &crashpad_info_address); | |
| 145 if (!crashpad_info_section) { | |
| 146 return; | 174 return; |
| 147 } | 175 } |
| 148 | 176 |
| 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) { | 177 if (!crashpad_info.simple_annotations) { |
| 170 return; | 178 return; |
| 171 } | 179 } |
| 172 | 180 |
| 173 std::vector<SimpleStringDictionary::Entry> | 181 std::vector<SimpleStringDictionary::Entry> |
| 174 simple_annotations(SimpleStringDictionary::num_entries); | 182 simple_annotations(SimpleStringDictionary::num_entries); |
| 175 if (!process_reader_->Memory() | 183 if (!process_reader_->Memory() |
| 176 ->Read(crashpad_info.simple_annotations, | 184 ->Read(crashpad_info.simple_annotations, |
| 177 simple_annotations.size() * sizeof(simple_annotations[0]), | 185 simple_annotations.size() * sizeof(simple_annotations[0]), |
| 178 &simple_annotations[0])) { | 186 &simple_annotations[0])) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 189 simple_map_annotations->insert( | 197 simple_map_annotations->insert( |
| 190 std::pair<std::string, std::string>(key, value)); | 198 std::pair<std::string, std::string>(key, value)); |
| 191 } else { | 199 } else { |
| 192 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; | 200 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; |
| 193 } | 201 } |
| 194 } | 202 } |
| 195 } | 203 } |
| 196 } | 204 } |
| 197 | 205 |
| 198 } // namespace crashpad | 206 } // namespace crashpad |
| OLD | NEW |