michael@0: // Copyright (c) 2010 Google Inc. 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: michael@0: // This file contains the definitions for a DWARF2/3 information michael@0: // collector that uses the DWARF2/3 reader interface to build a mapping michael@0: // of addresses to files, lines, and functions. michael@0: michael@0: #ifndef COMMON_DWARF_FUNCTIONINFO_H__ michael@0: #define COMMON_DWARF_FUNCTIONINFO_H__ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "common/dwarf/dwarf2reader.h" michael@0: #include "common/using_std_string.h" michael@0: michael@0: michael@0: namespace dwarf2reader { michael@0: michael@0: struct FunctionInfo { michael@0: // Name of the function michael@0: string name; michael@0: // Mangled name of the function michael@0: string mangled_name; michael@0: // File containing this function michael@0: string file; michael@0: // Line number for start of function. michael@0: uint32 line; michael@0: // Beginning address for this function michael@0: uint64 lowpc; michael@0: // End address for this function. michael@0: uint64 highpc; michael@0: }; michael@0: michael@0: struct SourceFileInfo { michael@0: // Name of the source file name michael@0: string name; michael@0: // Low address of source file name michael@0: uint64 lowpc; michael@0: }; michael@0: michael@0: typedef std::map FunctionMap; michael@0: typedef std::map > LineMap; michael@0: michael@0: // This class is a basic line info handler that fills in the dirs, michael@0: // file, and linemap passed into it with the data produced from the michael@0: // LineInfoHandler. michael@0: class CULineInfoHandler: public LineInfoHandler { michael@0: public: michael@0: michael@0: // michael@0: CULineInfoHandler(std::vector* files, michael@0: std::vector* dirs, michael@0: LineMap* linemap); michael@0: virtual ~CULineInfoHandler() { } michael@0: michael@0: // Called when we define a directory. We just place NAME into dirs_ michael@0: // at position DIR_NUM. michael@0: virtual void DefineDir(const string& name, uint32 dir_num); michael@0: michael@0: // Called when we define a filename. We just place michael@0: // concat(dirs_[DIR_NUM], NAME) into files_ at position FILE_NUM. michael@0: virtual void DefineFile(const string& name, int32 file_num, michael@0: uint32 dir_num, uint64 mod_time, uint64 length); michael@0: michael@0: michael@0: // Called when the line info reader has a new line, address pair michael@0: // ready for us. ADDRESS is the address of the code, LENGTH is the michael@0: // length of its machine code in bytes, FILE_NUM is the file number michael@0: // containing the code, LINE_NUM is the line number in that file for michael@0: // the code, and COLUMN_NUM is the column number the code starts at, michael@0: // if we know it (0 otherwise). michael@0: virtual void AddLine(uint64 address, uint64 length, michael@0: uint32 file_num, uint32 line_num, uint32 column_num); michael@0: michael@0: private: michael@0: LineMap* linemap_; michael@0: std::vector* files_; michael@0: std::vector* dirs_; michael@0: }; michael@0: michael@0: class CUFunctionInfoHandler: public Dwarf2Handler { michael@0: public: michael@0: CUFunctionInfoHandler(std::vector* files, michael@0: std::vector* dirs, michael@0: LineMap* linemap, michael@0: FunctionMap* offset_to_funcinfo, michael@0: FunctionMap* address_to_funcinfo, michael@0: CULineInfoHandler* linehandler, michael@0: const SectionMap& sections, michael@0: ByteReader* reader) michael@0: : files_(files), dirs_(dirs), linemap_(linemap), michael@0: offset_to_funcinfo_(offset_to_funcinfo), michael@0: address_to_funcinfo_(address_to_funcinfo), michael@0: linehandler_(linehandler), sections_(sections), michael@0: reader_(reader), current_function_info_(NULL) { } michael@0: michael@0: virtual ~CUFunctionInfoHandler() { } michael@0: michael@0: // Start to process a compilation unit at OFFSET from the beginning of the michael@0: // .debug_info section. We want to see all compilation units, so we michael@0: // always return true. michael@0: michael@0: virtual bool StartCompilationUnit(uint64 offset, uint8 address_size, michael@0: uint8 offset_size, uint64 cu_length, michael@0: uint8 dwarf_version); michael@0: michael@0: // Start to process a DIE at OFFSET from the beginning of the michael@0: // .debug_info section. We only care about function related DIE's. michael@0: virtual bool StartDIE(uint64 offset, enum DwarfTag tag); michael@0: michael@0: // Called when we have an attribute with unsigned data to give to michael@0: // our handler. The attribute is for the DIE at OFFSET from the michael@0: // beginning of the .debug_info section, has a name of ATTR, a form of michael@0: // FORM, and the actual data of the attribute is in DATA. michael@0: virtual void ProcessAttributeUnsigned(uint64 offset, michael@0: enum DwarfAttribute attr, michael@0: enum DwarfForm form, michael@0: uint64 data); michael@0: michael@0: // Called when we have an attribute with a DIE reference to give to michael@0: // our handler. The attribute is for the DIE at OFFSET from the michael@0: // beginning of the .debug_info section, has a name of ATTR, a form of michael@0: // FORM, and the offset of the referenced DIE from the start of the michael@0: // .debug_info section is in DATA. michael@0: virtual void ProcessAttributeReference(uint64 offset, michael@0: enum DwarfAttribute attr, michael@0: enum DwarfForm form, michael@0: uint64 data); michael@0: michael@0: // Called when we have an attribute with string data to give to michael@0: // our handler. The attribute is for the DIE at OFFSET from the michael@0: // beginning of the .debug_info section, has a name of ATTR, a form of michael@0: // FORM, and the actual data of the attribute is in DATA. michael@0: virtual void ProcessAttributeString(uint64 offset, michael@0: enum DwarfAttribute attr, michael@0: enum DwarfForm form, michael@0: const string& data); michael@0: michael@0: // Called when finished processing the DIE at OFFSET. michael@0: // Because DWARF2/3 specifies a tree of DIEs, you may get starts michael@0: // before ends of the previous DIE, as we process children before michael@0: // ending the parent. michael@0: virtual void EndDIE(uint64 offset); michael@0: michael@0: private: michael@0: std::vector* files_; michael@0: std::vector* dirs_; michael@0: LineMap* linemap_; michael@0: FunctionMap* offset_to_funcinfo_; michael@0: FunctionMap* address_to_funcinfo_; michael@0: CULineInfoHandler* linehandler_; michael@0: const SectionMap& sections_; michael@0: ByteReader* reader_; michael@0: FunctionInfo* current_function_info_; michael@0: uint64 current_compilation_unit_offset_; michael@0: }; michael@0: michael@0: } // namespace dwarf2reader michael@0: #endif // COMMON_DWARF_FUNCTIONINFO_H__