1c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// Copyright (c) 2006, Google Inc. 2c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// All rights reserved. 3c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 4c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// Redistribution and use in source and binary forms, with or without 5c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// modification, are permitted provided that the following conditions are 6c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// met: 7c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 8c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// * Redistributions of source code must retain the above copyright 9c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// notice, this list of conditions and the following disclaimer. 10c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// * Redistributions in binary form must reproduce the above 11c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// copyright notice, this list of conditions and the following disclaimer 12c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// in the documentation and/or other materials provided with the 13c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// distribution. 14c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// * Neither the name of Google Inc. nor the names of its 15c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// contributors may be used to endorse or promote products derived from 16c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// this software without specific prior written permission. 17c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 18c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 30c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// simple_symbol_supplier.h: A simple SymbolSupplier implementation 31c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 32c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// SimpleSymbolSupplier is a straightforward implementation of SymbolSupplier 33c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// that stores symbol files in a filesystem tree. A SimpleSymbolSupplier is 34a14ef803d70614a01725a269acb509027fe84942mmentovai// created with one or more base directories, which are the root paths for all 35a14ef803d70614a01725a269acb509027fe84942mmentovai// symbol files. Each symbol file contained therein has a directory entry in 36a14ef803d70614a01725a269acb509027fe84942mmentovai// the base directory with a name identical to the corresponding debugging 37a14ef803d70614a01725a269acb509027fe84942mmentovai// file (pdb). Within each of these directories, there are subdirectories 38a14ef803d70614a01725a269acb509027fe84942mmentovai// named for the debugging file's identifier. For recent pdb files, this is 39a14ef803d70614a01725a269acb509027fe84942mmentovai// a concatenation of the pdb's uuid and age, presented in hexadecimal form, 40a14ef803d70614a01725a269acb509027fe84942mmentovai// without any dashes or separators. The uuid is in uppercase hexadecimal 41a14ef803d70614a01725a269acb509027fe84942mmentovai// and the age is in lowercase hexadecimal. Within that subdirectory, 42c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// SimpleSymbolSupplier expects to find the symbol file, which is named 43db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// identically to the debug file, but with a .sym extension. If the original 44db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// debug file had a name ending in .pdb, the .pdb extension will be replaced 45db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// with .sym. This sample hierarchy is rooted at the "symbols" base 46db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// directory: 47c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 48c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols 49c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/test_app.pdb 50c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1 51c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/test_app.pdb/63FE4780728D49379B9D7BB6460CB42A1/test_app.sym 52c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/kernel32.pdb 53c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542 54c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbols/kernel32.pdb/BCE8785C57B44245A669896B6A19B9542/kernel32.sym 55c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 56c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// In this case, the uuid of test_app.pdb is 57c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 63fe4780-728d-4937-9b9d-7bb6460cb42a and its age is 1. 58c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 59c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// This scheme was chosen to be roughly analogous to the way that 60c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// symbol files may be accessed from Microsoft Symbol Server. A hierarchy 61c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// used for Microsoft Symbol Server storage is usable as a hierarchy for 62c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// SimpleSymbolServer, provided that the pdb files are transformed to dumped 63c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// format using a tool such as dump_syms, and given a .sym extension. 64c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 65a14ef803d70614a01725a269acb509027fe84942mmentovai// SimpleSymbolSupplier will iterate over all root paths searching for 66a14ef803d70614a01725a269acb509027fe84942mmentovai// a symbol file existing in that path. 67a14ef803d70614a01725a269acb509027fe84942mmentovai// 68db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// SimpleSymbolSupplier supports any debugging file which can be identified 69db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// by a CodeModule object's debug_file and debug_identifier accessors. The 70db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// expected ultimate source of these CodeModule objects are MinidumpModule 71db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// objects; it is this class that is responsible for assigning appropriate 72db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovai// values for debug_file and debug_identifier. 73c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// 74c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai// Author: Mark Mentovai 75c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 76c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai#ifndef PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 77c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai#define PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 78c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 79a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com#include <map> 80c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai#include <string> 81a14ef803d70614a01725a269acb509027fe84942mmentovai#include <vector> 82c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 834e518a4357a2d1c379d4a91df6d4e153ee791101ivan.penkov@gmail.com#include "common/using_std_string.h" 84e5dc60822e5938fea2ae892ccddb906641ba174emmentovai#include "google_breakpad/processor/symbol_supplier.h" 85c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 86e5dc60822e5938fea2ae892ccddb906641ba174emmentovainamespace google_breakpad { 87c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 88a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.comusing std::map; 89a14ef803d70614a01725a269acb509027fe84942mmentovaiusing std::vector; 90c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 91db3342a10ec30902aa9018b80e1d9a40bd01c487mmentovaiclass CodeModule; 92c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 93c34850a2023442a22fa653ab8546e72738ed2dd4mmentovaiclass SimpleSymbolSupplier : public SymbolSupplier { 94c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai public: 95c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai // Creates a new SimpleSymbolSupplier, using path as the root path where 96c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai // symbols are stored. 97a14ef803d70614a01725a269acb509027fe84942mmentovai explicit SimpleSymbolSupplier(const string &path) : paths_(1, path) {} 98a14ef803d70614a01725a269acb509027fe84942mmentovai 99a14ef803d70614a01725a269acb509027fe84942mmentovai // Creates a new SimpleSymbolSupplier, using paths as a list of root 100a14ef803d70614a01725a269acb509027fe84942mmentovai // paths where symbols may be stored. 101a14ef803d70614a01725a269acb509027fe84942mmentovai explicit SimpleSymbolSupplier(const vector<string> &paths) : paths_(paths) {} 102c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 103c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai virtual ~SimpleSymbolSupplier() {} 104c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 105c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai // Returns the path to the symbol file for the given module. See the 106c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai // description above. 1070fd2f1ae2152782f2127c56fb5302002c95502d3nealsid virtual SymbolResult GetSymbolFile(const CodeModule *module, 1080fd2f1ae2152782f2127c56fb5302002c95502d3nealsid const SystemInfo *system_info, 1090fd2f1ae2152782f2127c56fb5302002c95502d3nealsid string *symbol_file); 1107573d1dd4412171794f76bea833e4ae5f72929f8mmentovai 1110fd2f1ae2152782f2127c56fb5302002c95502d3nealsid virtual SymbolResult GetSymbolFile(const CodeModule *module, 1122ad976ef0ba44f36842b9b7a11848f6b40fd25d5nealsid const SystemInfo *system_info, 1132ad976ef0ba44f36842b9b7a11848f6b40fd25d5nealsid string *symbol_file, 1142ad976ef0ba44f36842b9b7a11848f6b40fd25d5nealsid string *symbol_data); 1155b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com 116a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com // Allocates data buffer on heap and writes symbol data into buffer. 117a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com // Symbol supplier ALWAYS takes ownership of the data buffer. 1185b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com virtual SymbolResult GetCStringSymbolData(const CodeModule *module, 1195b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com const SystemInfo *system_info, 1205b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com string *symbol_file, 1212d460c37d16a99fd4bcdac045298e87b6b5735b0ivan.penkov@gmail.com char **symbol_data, 1222d460c37d16a99fd4bcdac045298e87b6b5735b0ivan.penkov@gmail.com size_t *symbol_data_size); 1235b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com 124a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com // Free the data buffer allocated in the above GetCStringSymbolData(); 125a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com virtual void FreeSymbolData(const CodeModule *module); 126a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com 1277573d1dd4412171794f76bea833e4ae5f72929f8mmentovai protected: 1280fd2f1ae2152782f2127c56fb5302002c95502d3nealsid SymbolResult GetSymbolFileAtPathFromRoot(const CodeModule *module, 1290fd2f1ae2152782f2127c56fb5302002c95502d3nealsid const SystemInfo *system_info, 1300fd2f1ae2152782f2127c56fb5302002c95502d3nealsid const string &root_path, 1310fd2f1ae2152782f2127c56fb5302002c95502d3nealsid string *symbol_file); 132c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 133c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai private: 134a8c1c466a16ad4c85bfd1ca20ab8fc056d669abeSiyangXie@gmail.com map<string, char *> memory_buffers_; 135a14ef803d70614a01725a269acb509027fe84942mmentovai vector<string> paths_; 136c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai}; 137c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 138e5dc60822e5938fea2ae892ccddb906641ba174emmentovai} // namespace google_breakpad 139c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai 140c34850a2023442a22fa653ab8546e72738ed2dd4mmentovai#endif // PROCESSOR_SIMPLE_SYMBOL_SUPPLIER_H__ 141