1
// Copyright (c) 2010 Google Inc. All Rights Reserved.
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are
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
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.
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.
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.
34
#ifndef COMMON_DWARF_FUNCTIONINFO_H__
35
#define COMMON_DWARF_FUNCTIONINFO_H__
42
#include "common/dwarf/dwarf2reader.h"
45
namespace dwarf2reader {
48
// Name of the function
50
// Mangled name of the function
51
std::string mangled_name;
52
// File containing this function
54
// Line number for start of function.
56
// Beginning address for this function
58
// End address for this function.
62
struct SourceFileInfo {
63
// Name of the source file name
65
// Low address of source file name
69
typedef std::map<uint64, FunctionInfo*> FunctionMap;
70
typedef std::map<uint64, std::pair<std::string, uint32> > LineMap;
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
75
class CULineInfoHandler: public LineInfoHandler {
79
CULineInfoHandler(std::vector<SourceFileInfo>* files,
80
std::vector<std::string>* dirs,
82
virtual ~CULineInfoHandler() { }
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);
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);
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);
105
std::vector<SourceFileInfo>* files_;
106
std::vector<std::string>* dirs_;
109
class CUFunctionInfoHandler: public Dwarf2Handler {
111
CUFunctionInfoHandler(std::vector<SourceFileInfo>* files,
112
std::vector<std::string>* dirs,
114
FunctionMap* offset_to_funcinfo,
115
FunctionMap* address_to_funcinfo,
116
CULineInfoHandler* linehandler,
117
const SectionMap& sections,
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) { }
125
virtual ~CUFunctionInfoHandler() { }
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.
131
virtual bool StartCompilationUnit(uint64 offset, uint8 address_size,
132
uint8 offset_size, uint64 cu_length,
133
uint8 dwarf_version);
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);
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,
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,
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,
166
const std::string& data);
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);
175
std::vector<SourceFileInfo>* files_;
176
std::vector<std::string>* dirs_;
178
FunctionMap* offset_to_funcinfo_;
179
FunctionMap* address_to_funcinfo_;
180
CULineInfoHandler* linehandler_;
181
const SectionMap& sections_;
183
FunctionInfo* current_function_info_;
184
uint64 current_compilation_unit_offset_;
187
} // namespace dwarf2reader
188
#endif // COMMON_DWARF_FUNCTIONINFO_H__