* eval.c (parse_and_eval_address_1): Remove function.
[deliverable/binutils-gdb.git] / gold / dwarf_reader.h
CommitLineData
5c2c6c95
ILT
1// dwarf_reader.h -- parse dwarf2/3 debug information for gold -*- C++ -*-
2
4dbfafcc 3// Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5c2c6c95
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
23#ifndef GOLD_DWARF_READER_H
24#define GOLD_DWARF_READER_H
25
26#include <vector>
4c50553d 27#include <map>
5c2c6c95 28
4c50553d 29#include "elfcpp.h"
5c2c6c95
ILT
30#include "elfcpp_swap.h"
31#include "dwarf.h"
24badc65 32#include "reloc.h"
5c2c6c95
ILT
33
34namespace gold
35{
36
4c50553d
ILT
37template<int size, bool big_endian>
38class Track_relocs;
5c2c6c95
ILT
39struct LineStateMachine;
40
79e052ea
ILT
41// We can't do better than to keep the offsets in a sorted vector.
42// Here, offset is the key, and file_num/line_num is the value.
43struct Offset_to_lineno_entry
44{
45 off_t offset;
46 int header_num; // which file-list to use (i.e. which .o file are we in)
47 int file_num; // a pointer into files_
48 int line_num; // the line number in the source file
7500420b
ILT
49
50 // When we add entries to the table, we always use the last entry
51 // with a given offset. Given proper DWARF info, this should ensure
52 // that the offset is a sufficient sort key.
79e052ea
ILT
53 bool operator<(const Offset_to_lineno_entry& that) const
54 { return this->offset < that.offset; }
55};
56
5c2c6c95
ILT
57// This class is used to read the line information from the debugging
58// section of an object file.
59
60class Dwarf_line_info
61{
62 public:
a55ce7fe
ILT
63 Dwarf_line_info()
64 { }
65
66 virtual
67 ~Dwarf_line_info()
68 { }
5c2c6c95
ILT
69
70 // Given a section number and an offset, returns the associated
71 // file and line-number, as a string: "file:lineno". If unable
72 // to do the mapping, returns the empty string. You must call
73 // read_line_mappings() before calling this function.
74 std::string
a55ce7fe
ILT
75 addr2line(unsigned int shndx, off_t offset)
76 { return do_addr2line(shndx, offset); }
77
e4e5049b
CS
78 // A helper function for a single addr2line lookup. It also keeps a
79 // cache of the last CACHE_SIZE Dwarf_line_info objects it created;
80 // set to 0 not to cache at all. The larger CACHE_SIZE is, the more
81 // chance this routine won't have to re-create a Dwarf_line_info
82 // object for its addr2line computation; such creations are slow.
83 // NOTE: Not thread-safe, so only call from one thread at a time.
a55ce7fe 84 static std::string
e4e5049b
CS
85 one_addr2line(Object* object, unsigned int shndx, off_t offset,
86 size_t cache_size);
87
88 // This reclaims all the memory that one_addr2line may have cached.
89 // Use this when you know you will not be calling one_addr2line again.
90 static void
91 clear_addr2line_cache();
5c2c6c95
ILT
92
93 private:
a55ce7fe
ILT
94 virtual std::string
95 do_addr2line(unsigned int shndx, off_t offset) = 0;
96};
97
98template<int size, bool big_endian>
a18f2bd6 99class Sized_dwarf_line_info : public Dwarf_line_info
a55ce7fe
ILT
100{
101 public:
102 // Initializes a .debug_line reader for a given object file.
9430daf8
ILT
103 // If SHNDX is specified and non-negative, only read the debug
104 // information that pertains to the specified section.
75aea3d0 105 Sized_dwarf_line_info(Object* object, unsigned int read_shndx = -1U);
a55ce7fe 106
a55ce7fe
ILT
107 private:
108 std::string
109 do_addr2line(unsigned int shndx, off_t offset);
110
24badc65 111 // Start processing line info, and populates the offset_map_.
9430daf8
ILT
112 // If SHNDX is non-negative, only store debug information that
113 // pertains to the specified section.
24badc65 114 void
75aea3d0 115 read_line_mappings(Object*, unsigned int shndx);
24badc65 116
4c50553d
ILT
117 // Reads the relocation section associated with .debug_line and
118 // stores relocation information in reloc_map_.
119 void
d491d34e 120 read_relocs(Object*);
4c50553d
ILT
121
122 // Looks in the symtab to see what section a symbol is in.
123 unsigned int
d491d34e
ILT
124 symbol_section(Object*, unsigned int sym,
125 typename elfcpp::Elf_types<size>::Elf_Addr* value,
126 bool* is_ordinary);
4c50553d 127
5c2c6c95
ILT
128 // Reads the DWARF2/3 header for this line info. Each takes as input
129 // a starting buffer position, and returns the ending position.
5c2c6c95
ILT
130 const unsigned char*
131 read_header_prolog(const unsigned char* lineptr);
132
133 const unsigned char*
134 read_header_tables(const unsigned char* lineptr);
135
9430daf8
ILT
136 // Reads the DWARF2/3 line information. If shndx is non-negative,
137 // discard all line information that doesn't pertain to the given
138 // section.
5c2c6c95 139 const unsigned char*
75aea3d0 140 read_lines(const unsigned char* lineptr, unsigned int shndx);
5c2c6c95
ILT
141
142 // Process a single line info opcode at START using the state
143 // machine at LSM. Return true if we should define a line using the
144 // current state of the line state machine. Place the length of the
145 // opcode in LEN.
146 bool
e43872e9 147 process_one_opcode(const unsigned char* start,
5c2c6c95
ILT
148 struct LineStateMachine* lsm, size_t* len);
149
af674d1d
ILT
150 // Some parts of processing differ depending on whether the input
151 // was a .o file or not.
152 bool input_is_relobj();
153
4c50553d
ILT
154 // If we saw anything amiss while parsing, we set this to false.
155 // Then addr2line will always fail (rather than return possibly-
156 // corrupt data).
157 bool data_valid_;
158
5c2c6c95
ILT
159 // A DWARF2/3 line info header. This is not the same size as in the
160 // actual file, as the one in the file may have a 32 bit or 64 bit
161 // lengths.
162
163 struct Dwarf_line_infoHeader
164 {
165 off_t total_length;
166 int version;
167 off_t prologue_length;
168 int min_insn_length; // insn stands for instructin
169 bool default_is_stmt; // stmt stands for statement
170 signed char line_base;
171 int line_range;
172 unsigned char opcode_base;
173 std::vector<unsigned char> std_opcode_lengths;
174 int offset_size;
175 } header_;
176
177 // buffer is the buffer for our line info, starting at exactly where
178 // the line info to read is.
179 const unsigned char* buffer_;
24badc65 180 const unsigned char* buffer_end_;
5c2c6c95 181
4c50553d 182 // This has relocations that point into buffer.
24badc65 183 Track_relocs<size, big_endian> track_relocs_;
4dbfafcc
ILT
184 // The type of the reloc section in track_relocs_--SHT_REL or SHT_RELA.
185 unsigned int track_relocs_type_;
4c50553d
ILT
186
187 // This is used to figure out what section to apply a relocation to.
24badc65 188 const unsigned char* symtab_buffer_;
8383303e 189 section_size_type symtab_buffer_size_;
4c50553d 190
af674d1d
ILT
191 // Holds the directories and files as we see them. We have an array
192 // of directory-lists, one for each .o file we're reading (usually
193 // there will just be one, but there may be more if input is a .so).
194 std::vector<std::vector<std::string> > directories_;
5c2c6c95 195 // The first part is an index into directories_, the second the filename.
af674d1d
ILT
196 std::vector<std::vector< std::pair<int, std::string> > > files_;
197
198 // An index into the current directories_ and files_ vectors.
199 int current_header_index_;
5c2c6c95 200
af674d1d
ILT
201 // A sorted map from offset of the relocation target to the shndx
202 // and addend for the relocation.
4c50553d
ILT
203 typedef std::map<typename elfcpp::Elf_types<size>::Elf_Addr,
204 std::pair<unsigned int,
205 typename elfcpp::Elf_types<size>::Elf_Swxword> >
206 Reloc_map;
207 Reloc_map reloc_map_;
208
5c2c6c95
ILT
209 // We have a vector of offset->lineno entries for every input section.
210 typedef Unordered_map<unsigned int, std::vector<Offset_to_lineno_entry> >
211 Lineno_map;
212
213 Lineno_map line_number_map_;
214};
215
216} // End namespace gold.
217
218#endif // !defined(GOLD_DWARF_READER_H)
This page took 0.154357 seconds and 4 git commands to generate.