michael@0: // Copyright (c) 2006, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: // simple_symbol_supplier.h: A simple SymbolSupplier implementation michael@0: // michael@0: // SimpleSymbolSupplier is a straightforward implementation of SymbolSupplier michael@0: // that stores symbol files in a filesystem tree. A SimpleSymbolSupplier is michael@0: // created with one or more base directories, which are the root paths for all michael@0: // symbol files. Each symbol file contained therein has a directory entry in michael@0: // the base directory with a name identical to the corresponding debugging michael@0: // file (pdb). Within each of these directories, there are subdirectories michael@0: // named for the debugging file's identifier. For recent pdb files, this is michael@0: // a concatenation of the pdb's uuid and age, presented in hexadecimal form, michael@0: // without any dashes or separators. The uuid is in uppercase hexadecimal michael@0: // and the age is in lowercase hexadecimal. Within that subdirectory, michael@0: // SimpleSymbolSupplier expects to find the symbol file, which is named michael@0: // identically to the debug file, but with a .sym extension. If the original michael@0: // debug file had a name ending in .pdb, the .pdb extension will be replaced michael@0: // with .sym. This sample hierarchy is rooted at the "symbols" base michael@0: // directory: michael@0: // michael@0: // symbols michael@0: // symbols/test_app.pdb michael@0: // symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1 michael@0: // symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1/test_app.sym michael@0: // symbols/kernel32.pdb michael@0: // symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542 michael@0: // symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542/kernel32.sym michael@0: // michael@0: // In this case, the uuid of test_app.pdb is michael@0: // 63fe4780-728d-4937-9b9d-7bb6460cb42a and its age is 1. michael@0: // michael@0: // This scheme was chosen to be roughly analogous to the way that michael@0: // symbol files may be accessed from Microsoft Symbol Server. A hierarchy michael@0: // used for Microsoft Symbol Server storage is usable as a hierarchy for michael@0: // SimpleSymbolServer, provided that the pdb files are transformed to dumped michael@0: // format using a tool such as dump_syms, and given a .sym extension. michael@0: // michael@0: // SimpleSymbolSupplier will iterate over all root paths searching for michael@0: // a symbol file existing in that path. michael@0: // michael@0: // SimpleSymbolSupplier supports any debugging file which can be identified michael@0: // by a CodeModule object's debug_file and debug_identifier accessors. The michael@0: // expected ultimate source of these CodeModule objects are MinidumpModule michael@0: // objects; it is this class that is responsible for assigning appropriate michael@0: // values for debug_file and debug_identifier. michael@0: // michael@0: // Author: Mark Mentovai michael@0: michael@0: #ifndef PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ michael@0: #define PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "common/using_std_string.h" michael@0: #include "google_breakpad/processor/symbol_supplier.h" michael@0: michael@0: namespace google_breakpad { michael@0: michael@0: using std::map; michael@0: using std::vector; michael@0: michael@0: class CodeModule; michael@0: michael@0: class SimpleSymbolSupplier : public SymbolSupplier { michael@0: public: michael@0: // Creates a new SimpleSymbolSupplier, using path as the root path where michael@0: // symbols are stored. michael@0: explicit SimpleSymbolSupplier(const string &path) : paths_(1, path) {} michael@0: michael@0: // Creates a new SimpleSymbolSupplier, using paths as a list of root michael@0: // paths where symbols may be stored. michael@0: explicit SimpleSymbolSupplier(const vector &paths) : paths_(paths) {} michael@0: michael@0: virtual ~SimpleSymbolSupplier() {} michael@0: michael@0: // Returns the path to the symbol file for the given module. See the michael@0: // description above. michael@0: virtual SymbolResult GetSymbolFile(const CodeModule *module, michael@0: const SystemInfo *system_info, michael@0: string *symbol_file); michael@0: michael@0: virtual SymbolResult GetSymbolFile(const CodeModule *module, michael@0: const SystemInfo *system_info, michael@0: string *symbol_file, michael@0: string *symbol_data); michael@0: michael@0: // Allocates data buffer on heap and writes symbol data into buffer. michael@0: // Symbol supplier ALWAYS takes ownership of the data buffer. michael@0: virtual SymbolResult GetCStringSymbolData(const CodeModule *module, michael@0: const SystemInfo *system_info, michael@0: string *symbol_file, michael@0: char **symbol_data); michael@0: michael@0: // Free the data buffer allocated in the above GetCStringSymbolData(); michael@0: virtual void FreeSymbolData(const CodeModule *module); michael@0: michael@0: protected: michael@0: SymbolResult GetSymbolFileAtPathFromRoot(const CodeModule *module, michael@0: const SystemInfo *system_info, michael@0: const string &root_path, michael@0: string *symbol_file); michael@0: michael@0: private: michael@0: map memory_buffers_; michael@0: vector paths_; michael@0: }; michael@0: michael@0: } // namespace google_breakpad michael@0: michael@0: #endif // PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__