PageRenderTime 96ms CodeModel.GetById 59ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 1ms

/thirdparty/breakpad/common/dwarf/functioninfo.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 188 lines | 86 code | 28 blank | 74 comment | 0 complexity | d4ed5ae8aee2b9770e8df7d9471722f8 MD5 | raw file
  1// Copyright (c) 2010 Google Inc. All Rights Reserved.
  2//
  3// Redistribution and use in source and binary forms, with or without
  4// modification, are permitted provided that the following conditions are
  5// met:
  6//
  7//     * Redistributions of source code must retain the above copyright
  8// notice, this list of conditions and the following disclaimer.
  9//     * Redistributions in binary form must reproduce the above
 10// copyright notice, this list of conditions and the following disclaimer
 11// in the documentation and/or other materials provided with the
 12// distribution.
 13//     * Neither the name of Google Inc. nor the names of its
 14// contributors may be used to endorse or promote products derived from
 15// this software without specific prior written permission.
 16//
 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28
 29
 30// This file contains the definitions for a DWARF2/3 information
 31// collector that uses the DWARF2/3 reader interface to build a mapping
 32// of addresses to files, lines, and functions.
 33
 34#ifndef COMMON_DWARF_FUNCTIONINFO_H__
 35#define COMMON_DWARF_FUNCTIONINFO_H__
 36
 37#include <map>
 38#include <string>
 39#include <utility>
 40#include <vector>
 41
 42#include "common/dwarf/dwarf2reader.h"
 43
 44
 45namespace dwarf2reader {
 46
 47struct FunctionInfo {
 48  // Name of the function
 49  std::string name;
 50  // Mangled name of the function
 51  std::string mangled_name;
 52  // File containing this function
 53  std::string file;
 54  // Line number for start of function.
 55  uint32 line;
 56  // Beginning address for this function
 57  uint64 lowpc;
 58  // End address for this function.
 59  uint64 highpc;
 60};
 61
 62struct SourceFileInfo {
 63  // Name of the source file name
 64  std::string name;
 65  // Low address of source file name
 66  uint64 lowpc;
 67};
 68
 69typedef std::map<uint64, FunctionInfo*> FunctionMap;
 70typedef std::map<uint64, std::pair<std::string, uint32> > LineMap;
 71
 72// This class is a basic line info handler that fills in the dirs,
 73// file, and linemap passed into it with the data produced from the
 74// LineInfoHandler.
 75class CULineInfoHandler: public LineInfoHandler {
 76 public:
 77
 78  //
 79  CULineInfoHandler(std::vector<SourceFileInfo>* files,
 80                    std::vector<std::string>* dirs,
 81                    LineMap* linemap);
 82  virtual ~CULineInfoHandler() { }
 83
 84  // Called when we define a directory.  We just place NAME into dirs_
 85  // at position DIR_NUM.
 86  virtual void DefineDir(const std::string& name, uint32 dir_num);
 87
 88  // Called when we define a filename.  We just place
 89  // concat(dirs_[DIR_NUM], NAME) into files_ at position FILE_NUM.
 90  virtual void DefineFile(const std::string& name, int32 file_num,
 91                          uint32 dir_num, uint64 mod_time, uint64 length);
 92
 93
 94  // Called when the line info reader has a new line, address pair
 95  // ready for us. ADDRESS is the address of the code, LENGTH is the
 96  // length of its machine code in bytes, FILE_NUM is the file number
 97  // containing the code, LINE_NUM is the line number in that file for
 98  // the code, and COLUMN_NUM is the column number the code starts at,
 99  // if we know it (0 otherwise).
100  virtual void AddLine(uint64 address, uint64 length,
101                       uint32 file_num, uint32 line_num, uint32 column_num);
102
103 private:
104  LineMap* linemap_;
105  std::vector<SourceFileInfo>* files_;
106  std::vector<std::string>* dirs_;
107};
108
109class CUFunctionInfoHandler: public Dwarf2Handler {
110 public:
111  CUFunctionInfoHandler(std::vector<SourceFileInfo>* files,
112                        std::vector<std::string>* dirs,
113                        LineMap* linemap,
114                        FunctionMap* offset_to_funcinfo,
115                        FunctionMap* address_to_funcinfo,
116                        CULineInfoHandler* linehandler,
117                        const SectionMap& sections,
118                        ByteReader* reader)
119      : files_(files), dirs_(dirs), linemap_(linemap),
120        offset_to_funcinfo_(offset_to_funcinfo),
121        address_to_funcinfo_(address_to_funcinfo),
122        linehandler_(linehandler), sections_(sections),
123        reader_(reader), current_function_info_(NULL) { }
124
125  virtual ~CUFunctionInfoHandler() { }
126
127  // Start to process a compilation unit at OFFSET from the beginning of the
128  // .debug_info section.  We want to see all compilation units, so we
129  // always return true.
130
131  virtual bool StartCompilationUnit(uint64 offset, uint8 address_size,
132                                    uint8 offset_size, uint64 cu_length,
133                                    uint8 dwarf_version);
134
135  // Start to process a DIE at OFFSET from the beginning of the
136  // .debug_info section.  We only care about function related DIE's.
137  virtual bool StartDIE(uint64 offset, enum DwarfTag tag,
138                        const AttributeList& attrs);
139
140  // Called when we have an attribute with unsigned data to give to
141  // our handler.  The attribute is for the DIE at OFFSET from the
142  // beginning of the .debug_info section, has a name of ATTR, a form of
143  // FORM, and the actual data of the attribute is in DATA.
144  virtual void ProcessAttributeUnsigned(uint64 offset,
145                                        enum DwarfAttribute attr,
146                                        enum DwarfForm form,
147                                        uint64 data);
148
149  // Called when we have an attribute with a DIE reference to give to
150  // our handler.  The attribute is for the DIE at OFFSET from the
151  // beginning of the .debug_info section, has a name of ATTR, a form of
152  // FORM, and the offset of the referenced DIE from the start of the
153  // .debug_info section is in DATA.
154  virtual void ProcessAttributeReference(uint64 offset,
155                                         enum DwarfAttribute attr,
156                                         enum DwarfForm form,
157                                         uint64 data);
158
159  // Called when we have an attribute with string data to give to
160  // our handler.  The attribute is for the DIE at OFFSET from the
161  // beginning of the .debug_info section, has a name of ATTR, a form of
162  // FORM, and the actual data of the attribute is in DATA.
163  virtual void ProcessAttributeString(uint64 offset,
164                                      enum DwarfAttribute attr,
165                                      enum DwarfForm form,
166                                      const std::string& data);
167
168  // Called when finished processing the DIE at OFFSET.
169  // Because DWARF2/3 specifies a tree of DIEs, you may get starts
170  // before ends of the previous DIE, as we process children before
171  // ending the parent.
172  virtual void EndDIE(uint64 offset);
173
174 private:
175  std::vector<SourceFileInfo>* files_;
176  std::vector<std::string>* dirs_;
177  LineMap* linemap_;
178  FunctionMap* offset_to_funcinfo_;
179  FunctionMap* address_to_funcinfo_;
180  CULineInfoHandler* linehandler_;
181  const SectionMap& sections_;
182  ByteReader* reader_;
183  FunctionInfo* current_function_info_;
184  uint64 current_compilation_unit_offset_;
185};
186
187}  // namespace dwarf2reader
188#endif  // COMMON_DWARF_FUNCTIONINFO_H__