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 #ifndef CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_ANNOTATIONS_READER_H_ 16 #define CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_ANNOTATIONS_READER_H_ 17 18 #include <map> 19 #include <string> 20 #include <vector> 21 22 #include "base/macros.h" 23 #include "snapshot/annotation_snapshot.h" 24 25 namespace crashpad { 26 27 class PEImageReader; 28 class ProcessReaderWin; 29 30 //! \brief A reader of annotations stored in a PE image mapped into another 31 //! process. 32 //! 33 //! These annotations are stored for the benefit of crash reporters, and provide 34 //! information thought to be potentially useful for crash analysis. 35 //! 36 //! Currently, this class can decode information stored only in the CrashpadInfo 37 //! structure. This format is used by Crashpad clients. The "simple annotations" 38 //! are recovered from any module with a compatible data section, and are 39 //! included in the annotations returned by SimpleMap(). 40 class PEImageAnnotationsReader { 41 public: 42 //! \brief Constructs the object. 43 //! 44 //! \param[in] process_reader The reader for the remote process. 45 //! \param[in] pe_image_reader The PEImageReader for the PE image file 46 //! contained within the remote process. 47 //! \param[in] name The module's name, a string to be used in logged messages. 48 //! This string is for diagnostic purposes only, and may be empty. 49 PEImageAnnotationsReader(ProcessReaderWin* process_reader, 50 const PEImageReader* pe_image_reader, 51 const std::wstring& name); ~PEImageAnnotationsReader()52 ~PEImageAnnotationsReader() {} 53 54 //! \brief Returns the module's annotations that are organized as key-value 55 //! pairs, where all keys and values are strings. 56 std::map<std::string, std::string> SimpleMap() const; 57 58 //! \brief Returns the module's annotations that are organized as a list of 59 //! typed annotation objects. 60 std::vector<AnnotationSnapshot> AnnotationsList() const; 61 62 private: 63 // Reads CrashpadInfo::simple_annotations_ on behalf of SimpleMap(). 64 template <class Traits> 65 void ReadCrashpadSimpleAnnotations( 66 std::map<std::string, std::string>* simple_map_annotations) const; 67 68 // Reads CrashpadInfo::annotations_list_ on behalf of AnnotationsList(). 69 template <class Traits> 70 void ReadCrashpadAnnotationsList( 71 std::vector<AnnotationSnapshot>* vector_annotations) const; 72 73 std::wstring name_; 74 ProcessReaderWin* process_reader_; // weak 75 const PEImageReader* pe_image_reader_; // weak 76 77 DISALLOW_COPY_AND_ASSIGN(PEImageAnnotationsReader); 78 }; 79 80 } // namespace crashpad 81 82 #endif // CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_ANNOTATIONS_READER_H_ 83