1 // Copyright 2010 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // 29 // source_line_resolver_base.h: SourceLineResolverBase, an (incomplete) 30 // implementation of SourceLineResolverInterface. It serves as a common base 31 // class for concrete implementations: FastSourceLineResolver and 32 // BasicSourceLineResolver. It is designed for refactoring that removes 33 // code redundancy in the two concrete source line resolver classes. 34 // 35 // See "google_breakpad/processor/source_line_resolver_interface.h" for more 36 // documentation. 37 38 // Author: Siyang Xie ([email protected]) 39 40 #ifndef GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__ 41 #define GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__ 42 43 #include <deque> 44 #include <map> 45 #include <set> 46 #include <string> 47 48 #include "google_breakpad/processor/source_line_resolver_interface.h" 49 50 namespace google_breakpad { 51 52 using std::map; 53 using std::set; 54 55 // Forward declaration. 56 // ModuleFactory is a simple factory interface for creating a Module instance 57 // at run-time. 58 class ModuleFactory; 59 60 class SourceLineResolverBase : public SourceLineResolverInterface { 61 public: 62 // Read the symbol_data from a file with given file_name. 63 // The part of code was originally in BasicSourceLineResolver::Module's 64 // LoadMap() method. 65 // Place dynamically allocated heap buffer in symbol_data. Caller has the 66 // ownership of the buffer, and should call delete [] to free the buffer. 67 static bool ReadSymbolFile(const string& file_name, 68 char** symbol_data, 69 size_t* symbol_data_size); 70 71 protected: 72 // Users are not allowed create SourceLineResolverBase instance directly. 73 SourceLineResolverBase(ModuleFactory* module_factory); 74 virtual ~SourceLineResolverBase(); 75 76 // Virtual methods inherited from SourceLineResolverInterface. 77 virtual bool LoadModule(const CodeModule* module, const string& map_file); 78 virtual bool LoadModuleUsingMapBuffer(const CodeModule* module, 79 const string& map_buffer); 80 virtual bool LoadModuleUsingMemoryBuffer(const CodeModule* module, 81 char* memory_buffer, 82 size_t memory_buffer_size); 83 virtual bool ShouldDeleteMemoryBufferAfterLoadModule(); 84 virtual void UnloadModule(const CodeModule* module); 85 virtual bool HasModule(const CodeModule* module); 86 virtual bool IsModuleCorrupt(const CodeModule* module); 87 virtual void FillSourceLineInfo( 88 StackFrame* frame, 89 std::deque<std::unique_ptr<StackFrame>>* inlined_frames); 90 virtual WindowsFrameInfo* FindWindowsFrameInfo(const StackFrame* frame); 91 virtual CFIFrameInfo* FindCFIFrameInfo(const StackFrame* frame); 92 93 // Nested structs and classes. 94 struct InlineOrigin; 95 struct Inline; 96 struct Line; 97 struct Function; 98 struct PublicSymbol; 99 struct CompareString { 100 bool operator()(const string& s1, const string& s2) const; 101 }; 102 // Module is an interface for an in-memory symbol file. 103 class Module; 104 class AutoFileCloser; 105 106 // All of the modules that are loaded. 107 typedef map<string, Module*, CompareString> ModuleMap; 108 ModuleMap* modules_; 109 110 // The loaded modules that were detecting to be corrupt during load. 111 typedef set<string, CompareString> ModuleSet; 112 ModuleSet* corrupt_modules_; 113 114 // All of heap-allocated buffers that are owned locally by resolver. 115 typedef std::map<string, char*, CompareString> MemoryMap; 116 MemoryMap* memory_buffers_; 117 118 // Creates a concrete module at run-time. 119 ModuleFactory* module_factory_; 120 121 private: 122 // ModuleFactory needs to have access to protected type Module. 123 friend class ModuleFactory; 124 125 // Disallow unwanted copy ctor and assignment operator 126 SourceLineResolverBase(const SourceLineResolverBase&); 127 void operator=(const SourceLineResolverBase&); 128 }; 129 130 } // namespace google_breakpad 131 132 #endif // GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__ 133