1 // Copyright 2006 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 // simple_symbol_supplier.h: A simple SymbolSupplier implementation 30 // 31 // SimpleSymbolSupplier is a straightforward implementation of SymbolSupplier 32 // that stores symbol files in a filesystem tree. A SimpleSymbolSupplier is 33 // created with one or more base directories, which are the root paths for all 34 // symbol files. Each symbol file contained therein has a directory entry in 35 // the base directory with a name identical to the corresponding debugging 36 // file (pdb). Within each of these directories, there are subdirectories 37 // named for the debugging file's identifier. For recent pdb files, this is 38 // a concatenation of the pdb's uuid and age, presented in hexadecimal form, 39 // without any dashes or separators. The uuid is in uppercase hexadecimal 40 // and the age is in lowercase hexadecimal. Within that subdirectory, 41 // SimpleSymbolSupplier expects to find the symbol file, which is named 42 // identically to the debug file, but with a .sym extension. If the original 43 // debug file had a name ending in .pdb, the .pdb extension will be replaced 44 // with .sym. This sample hierarchy is rooted at the "symbols" base 45 // directory: 46 // 47 // symbols 48 // symbols/test_app.pdb 49 // symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1 50 // symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1/test_app.sym 51 // symbols/kernel32.pdb 52 // symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542 53 // symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542/kernel32.sym 54 // 55 // In this case, the uuid of test_app.pdb is 56 // 63fe4780-728d-4937-9b9d-7bb6460cb42a and its age is 1. 57 // 58 // This scheme was chosen to be roughly analogous to the way that 59 // symbol files may be accessed from Microsoft Symbol Server. A hierarchy 60 // used for Microsoft Symbol Server storage is usable as a hierarchy for 61 // SimpleSymbolServer, provided that the pdb files are transformed to dumped 62 // format using a tool such as dump_syms, and given a .sym extension. 63 // 64 // SimpleSymbolSupplier will iterate over all root paths searching for 65 // a symbol file existing in that path. 66 // 67 // SimpleSymbolSupplier supports any debugging file which can be identified 68 // by a CodeModule object's debug_file and debug_identifier accessors. The 69 // expected ultimate source of these CodeModule objects are MinidumpModule 70 // objects; it is this class that is responsible for assigning appropriate 71 // values for debug_file and debug_identifier. 72 // 73 // Author: Mark Mentovai 74 75 #ifndef PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 76 #define PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 77 78 #include <map> 79 #include <string> 80 #include <vector> 81 82 #include "common/using_std_string.h" 83 #include "google_breakpad/processor/symbol_supplier.h" 84 85 namespace google_breakpad { 86 87 using std::map; 88 using std::vector; 89 90 class CodeModule; 91 92 class SimpleSymbolSupplier : public SymbolSupplier { 93 public: 94 // Creates a new SimpleSymbolSupplier, using path as the root path where 95 // symbols are stored. SimpleSymbolSupplier(const string & path)96 explicit SimpleSymbolSupplier(const string& path) : paths_(1, path) {} 97 98 // Creates a new SimpleSymbolSupplier, using paths as a list of root 99 // paths where symbols may be stored. SimpleSymbolSupplier(const vector<string> & paths)100 explicit SimpleSymbolSupplier(const vector<string>& paths) : paths_(paths) {} 101 ~SimpleSymbolSupplier()102 virtual ~SimpleSymbolSupplier() {} 103 104 // Returns the path to the symbol file for the given module. See the 105 // description above. 106 virtual SymbolResult GetSymbolFile(const CodeModule* module, 107 const SystemInfo* system_info, 108 string* symbol_file); 109 110 virtual SymbolResult GetSymbolFile(const CodeModule* module, 111 const SystemInfo* system_info, 112 string* symbol_file, 113 string* symbol_data); 114 115 // Allocates data buffer on heap and writes symbol data into buffer. 116 // Symbol supplier ALWAYS takes ownership of the data buffer. 117 virtual SymbolResult GetCStringSymbolData(const CodeModule* module, 118 const SystemInfo* system_info, 119 string* symbol_file, 120 char** symbol_data, 121 size_t* symbol_data_size); 122 123 // Free the data buffer allocated in the above GetCStringSymbolData(); 124 virtual void FreeSymbolData(const CodeModule* module); 125 126 protected: 127 SymbolResult GetSymbolFileAtPathFromRoot(const CodeModule* module, 128 const SystemInfo* system_info, 129 const string& root_path, 130 string* symbol_file); 131 132 private: 133 map<string, char*> memory_buffers_; 134 vector<string> paths_; 135 }; 136 137 } // namespace google_breakpad 138 139 #endif // PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 140