1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/dwarf/functioninfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,188 @@ 1.4 +// Copyright (c) 2010 Google Inc. All Rights Reserved. 1.5 +// 1.6 +// Redistribution and use in source and binary forms, with or without 1.7 +// modification, are permitted provided that the following conditions are 1.8 +// met: 1.9 +// 1.10 +// * Redistributions of source code must retain the above copyright 1.11 +// notice, this list of conditions and the following disclaimer. 1.12 +// * Redistributions in binary form must reproduce the above 1.13 +// copyright notice, this list of conditions and the following disclaimer 1.14 +// in the documentation and/or other materials provided with the 1.15 +// distribution. 1.16 +// * Neither the name of Google Inc. nor the names of its 1.17 +// contributors may be used to endorse or promote products derived from 1.18 +// this software without specific prior written permission. 1.19 +// 1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 + 1.32 + 1.33 +// This file contains the definitions for a DWARF2/3 information 1.34 +// collector that uses the DWARF2/3 reader interface to build a mapping 1.35 +// of addresses to files, lines, and functions. 1.36 + 1.37 +#ifndef COMMON_DWARF_FUNCTIONINFO_H__ 1.38 +#define COMMON_DWARF_FUNCTIONINFO_H__ 1.39 + 1.40 +#include <map> 1.41 +#include <string> 1.42 +#include <utility> 1.43 +#include <vector> 1.44 + 1.45 +#include "common/dwarf/dwarf2reader.h" 1.46 +#include "common/using_std_string.h" 1.47 + 1.48 + 1.49 +namespace dwarf2reader { 1.50 + 1.51 +struct FunctionInfo { 1.52 + // Name of the function 1.53 + string name; 1.54 + // Mangled name of the function 1.55 + string mangled_name; 1.56 + // File containing this function 1.57 + string file; 1.58 + // Line number for start of function. 1.59 + uint32 line; 1.60 + // Beginning address for this function 1.61 + uint64 lowpc; 1.62 + // End address for this function. 1.63 + uint64 highpc; 1.64 +}; 1.65 + 1.66 +struct SourceFileInfo { 1.67 + // Name of the source file name 1.68 + string name; 1.69 + // Low address of source file name 1.70 + uint64 lowpc; 1.71 +}; 1.72 + 1.73 +typedef std::map<uint64, FunctionInfo*> FunctionMap; 1.74 +typedef std::map<uint64, std::pair<string, uint32> > LineMap; 1.75 + 1.76 +// This class is a basic line info handler that fills in the dirs, 1.77 +// file, and linemap passed into it with the data produced from the 1.78 +// LineInfoHandler. 1.79 +class CULineInfoHandler: public LineInfoHandler { 1.80 + public: 1.81 + 1.82 + // 1.83 + CULineInfoHandler(std::vector<SourceFileInfo>* files, 1.84 + std::vector<string>* dirs, 1.85 + LineMap* linemap); 1.86 + virtual ~CULineInfoHandler() { } 1.87 + 1.88 + // Called when we define a directory. We just place NAME into dirs_ 1.89 + // at position DIR_NUM. 1.90 + virtual void DefineDir(const string& name, uint32 dir_num); 1.91 + 1.92 + // Called when we define a filename. We just place 1.93 + // concat(dirs_[DIR_NUM], NAME) into files_ at position FILE_NUM. 1.94 + virtual void DefineFile(const string& name, int32 file_num, 1.95 + uint32 dir_num, uint64 mod_time, uint64 length); 1.96 + 1.97 + 1.98 + // Called when the line info reader has a new line, address pair 1.99 + // ready for us. ADDRESS is the address of the code, LENGTH is the 1.100 + // length of its machine code in bytes, FILE_NUM is the file number 1.101 + // containing the code, LINE_NUM is the line number in that file for 1.102 + // the code, and COLUMN_NUM is the column number the code starts at, 1.103 + // if we know it (0 otherwise). 1.104 + virtual void AddLine(uint64 address, uint64 length, 1.105 + uint32 file_num, uint32 line_num, uint32 column_num); 1.106 + 1.107 + private: 1.108 + LineMap* linemap_; 1.109 + std::vector<SourceFileInfo>* files_; 1.110 + std::vector<string>* dirs_; 1.111 +}; 1.112 + 1.113 +class CUFunctionInfoHandler: public Dwarf2Handler { 1.114 + public: 1.115 + CUFunctionInfoHandler(std::vector<SourceFileInfo>* files, 1.116 + std::vector<string>* dirs, 1.117 + LineMap* linemap, 1.118 + FunctionMap* offset_to_funcinfo, 1.119 + FunctionMap* address_to_funcinfo, 1.120 + CULineInfoHandler* linehandler, 1.121 + const SectionMap& sections, 1.122 + ByteReader* reader) 1.123 + : files_(files), dirs_(dirs), linemap_(linemap), 1.124 + offset_to_funcinfo_(offset_to_funcinfo), 1.125 + address_to_funcinfo_(address_to_funcinfo), 1.126 + linehandler_(linehandler), sections_(sections), 1.127 + reader_(reader), current_function_info_(NULL) { } 1.128 + 1.129 + virtual ~CUFunctionInfoHandler() { } 1.130 + 1.131 + // Start to process a compilation unit at OFFSET from the beginning of the 1.132 + // .debug_info section. We want to see all compilation units, so we 1.133 + // always return true. 1.134 + 1.135 + virtual bool StartCompilationUnit(uint64 offset, uint8 address_size, 1.136 + uint8 offset_size, uint64 cu_length, 1.137 + uint8 dwarf_version); 1.138 + 1.139 + // Start to process a DIE at OFFSET from the beginning of the 1.140 + // .debug_info section. We only care about function related DIE's. 1.141 + virtual bool StartDIE(uint64 offset, enum DwarfTag tag); 1.142 + 1.143 + // Called when we have an attribute with unsigned data to give to 1.144 + // our handler. The attribute is for the DIE at OFFSET from the 1.145 + // beginning of the .debug_info section, has a name of ATTR, a form of 1.146 + // FORM, and the actual data of the attribute is in DATA. 1.147 + virtual void ProcessAttributeUnsigned(uint64 offset, 1.148 + enum DwarfAttribute attr, 1.149 + enum DwarfForm form, 1.150 + uint64 data); 1.151 + 1.152 + // Called when we have an attribute with a DIE reference to give to 1.153 + // our handler. The attribute is for the DIE at OFFSET from the 1.154 + // beginning of the .debug_info section, has a name of ATTR, a form of 1.155 + // FORM, and the offset of the referenced DIE from the start of the 1.156 + // .debug_info section is in DATA. 1.157 + virtual void ProcessAttributeReference(uint64 offset, 1.158 + enum DwarfAttribute attr, 1.159 + enum DwarfForm form, 1.160 + uint64 data); 1.161 + 1.162 + // Called when we have an attribute with string data to give to 1.163 + // our handler. The attribute is for the DIE at OFFSET from the 1.164 + // beginning of the .debug_info section, has a name of ATTR, a form of 1.165 + // FORM, and the actual data of the attribute is in DATA. 1.166 + virtual void ProcessAttributeString(uint64 offset, 1.167 + enum DwarfAttribute attr, 1.168 + enum DwarfForm form, 1.169 + const string& data); 1.170 + 1.171 + // Called when finished processing the DIE at OFFSET. 1.172 + // Because DWARF2/3 specifies a tree of DIEs, you may get starts 1.173 + // before ends of the previous DIE, as we process children before 1.174 + // ending the parent. 1.175 + virtual void EndDIE(uint64 offset); 1.176 + 1.177 + private: 1.178 + std::vector<SourceFileInfo>* files_; 1.179 + std::vector<string>* dirs_; 1.180 + LineMap* linemap_; 1.181 + FunctionMap* offset_to_funcinfo_; 1.182 + FunctionMap* address_to_funcinfo_; 1.183 + CULineInfoHandler* linehandler_; 1.184 + const SectionMap& sections_; 1.185 + ByteReader* reader_; 1.186 + FunctionInfo* current_function_info_; 1.187 + uint64 current_compilation_unit_offset_; 1.188 +}; 1.189 + 1.190 +} // namespace dwarf2reader 1.191 +#endif // COMMON_DWARF_FUNCTIONINFO_H__