source_line_resolver_interface.h revision 181f307ffe521026d7344ed58d1545321d352ca6
17daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// Copyright (c) 2006, Google Inc. 27daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// All rights reserved. 3cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// 47daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// Redistribution and use in source and binary forms, with or without 57daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// modification, are permitted provided that the following conditions are 67daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// met: 7cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// 87daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// * Redistributions of source code must retain the above copyright 97daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// notice, this list of conditions and the following disclaimer. 107daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// * Redistributions in binary form must reproduce the above 117daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// copyright notice, this list of conditions and the following disclaimer 127daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// in the documentation and/or other materials provided with the 137daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// distribution. 147daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// * Neither the name of Google Inc. nor the names of its 157daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// contributors may be used to endorse or promote products derived from 167daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// this software without specific prior written permission. 17cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// 187daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 197daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 207daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 217daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 227daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 237daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 247daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 257daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 267daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 277daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 287daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 30cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// SourceLineResolver returns function/file/line info for a memory address. 31cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// It uses address map files produced by a compatible writer, e.g. 32cb91a2f879250f2ef5f74321b5d08807247d41a7bryner// PDBSourceLineWriter. 33cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 3407f8ef56aca4fbab3e1a975ad2a439a23007f065bryner#ifndef PROCESSOR_SOURCE_LINE_RESOLVER_H__ 3507f8ef56aca4fbab3e1a975ad2a439a23007f065bryner#define PROCESSOR_SOURCE_LINE_RESOLVER_H__ 36cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 37cb91a2f879250f2ef5f74321b5d08807247d41a7bryner#include <string> 38cb91a2f879250f2ef5f74321b5d08807247d41a7bryner#include <ext/hash_map> 39cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 40425d256321f590e4ca86e3294055e9fad135f9b2mmentovainamespace google_airbag { 41cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 42425d256321f590e4ca86e3294055e9fad135f9b2mmentovaiusing std::string; 43cb91a2f879250f2ef5f74321b5d08807247d41a7brynerusing __gnu_cxx::hash_map; 44cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 45fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovaistruct StackFrame; 46fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovaistruct StackFrameInfo; 4739716226cf6ffcfaa37c991f82c3f2b19354413fbryner 48cb91a2f879250f2ef5f74321b5d08807247d41a7brynerclass SourceLineResolver { 49cb91a2f879250f2ef5f74321b5d08807247d41a7bryner public: 50cb91a2f879250f2ef5f74321b5d08807247d41a7bryner typedef unsigned long long MemAddr; 51cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 52cb91a2f879250f2ef5f74321b5d08807247d41a7bryner SourceLineResolver(); 53cb91a2f879250f2ef5f74321b5d08807247d41a7bryner ~SourceLineResolver(); 54cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 55cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // Adds a module to this resolver, returning true on success. 56cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // 57cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // module_name may be an arbitrary string. Typically, it will be the 58cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // filename of the module, optionally with version identifiers. 59cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // 60cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // map_file should contain line/address mappings for this module. 61cb91a2f879250f2ef5f74321b5d08807247d41a7bryner bool LoadModule(const string &module_name, const string &map_file); 62cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 63181f307ffe521026d7344ed58d1545321d352ca6bryner // Returns true if a module with the given name has been loaded. 64181f307ffe521026d7344ed58d1545321d352ca6bryner bool HasModule(const string &module_name) const; 65181f307ffe521026d7344ed58d1545321d352ca6bryner 6639716226cf6ffcfaa37c991f82c3f2b19354413fbryner // Fills in the function_base, function_name, source_file_name, 6739716226cf6ffcfaa37c991f82c3f2b19354413fbryner // and source_line fields of the StackFrame. The instruction and 68fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovai // module_name fields must already be filled in. Additional debugging 69fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovai // information, if available, is placed in frame_info. 70fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovai void FillSourceLineInfo(StackFrame *frame, StackFrameInfo *frame_info) const; 71cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 72cb91a2f879250f2ef5f74321b5d08807247d41a7bryner private: 73cb91a2f879250f2ef5f74321b5d08807247d41a7bryner template<class T> class MemAddrMap; 74cb91a2f879250f2ef5f74321b5d08807247d41a7bryner struct Line; 75cb91a2f879250f2ef5f74321b5d08807247d41a7bryner struct Function; 76cb91a2f879250f2ef5f74321b5d08807247d41a7bryner struct File; 77cb91a2f879250f2ef5f74321b5d08807247d41a7bryner struct HashString { 78cb91a2f879250f2ef5f74321b5d08807247d41a7bryner size_t operator()(const string &s) const; 79cb91a2f879250f2ef5f74321b5d08807247d41a7bryner }; 80cb91a2f879250f2ef5f74321b5d08807247d41a7bryner class Module; 81cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 82cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // All of the modules we've loaded 83cb91a2f879250f2ef5f74321b5d08807247d41a7bryner typedef hash_map<string, Module*, HashString> ModuleMap; 84cb91a2f879250f2ef5f74321b5d08807247d41a7bryner ModuleMap *modules_; 85cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 86cb91a2f879250f2ef5f74321b5d08807247d41a7bryner // Disallow unwanted copy ctor and assignment operator 87cb91a2f879250f2ef5f74321b5d08807247d41a7bryner SourceLineResolver(const SourceLineResolver&); 88cb91a2f879250f2ef5f74321b5d08807247d41a7bryner void operator=(const SourceLineResolver&); 89cb91a2f879250f2ef5f74321b5d08807247d41a7bryner}; 90cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 91425d256321f590e4ca86e3294055e9fad135f9b2mmentovai} // namespace google_airbag 92cb91a2f879250f2ef5f74321b5d08807247d41a7bryner 9307f8ef56aca4fbab3e1a975ad2a439a23007f065bryner#endif // PROCESSOR_SOURCE_LINE_RESOLVER_H__ 94