1 // gdb-index.h -- generate .gdb_index section for fast debug lookup -*- C++ -*-
3 // Copyright (C) 2012-2019 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #include <sys/types.h>
29 #include "stringpool.h"
31 #ifndef GOLD_GDB_INDEX_H
32 #define GOLD_GDB_INDEX_H
40 template<int size
, bool big_endian
>
42 class Dwarf_range_list
;
45 class Gdb_index_info_reader
;
46 class Dwarf_pubnames_table
;
48 // This class manages the .gdb_index section, which is a fast
49 // lookup table for DWARF information used by the gdb debugger.
50 // The format of this section is described in gdb/doc/gdb.texinfo.
52 class Gdb_index
: public Output_section_data
55 Gdb_index(Output_section
* gdb_index_section
);
59 // Scan a .debug_info or .debug_types input section.
60 void scan_debug_info(bool is_type_unit
,
62 const unsigned char* symbols
,
65 unsigned int reloc_shndx
,
66 unsigned int reloc_type
);
68 // Add a compilation unit.
70 add_comp_unit(off_t cu_offset
, off_t cu_length
)
72 this->comp_units_
.push_back(Comp_unit(cu_offset
, cu_length
));
73 return this->comp_units_
.size() - 1;
78 add_type_unit(off_t tu_offset
, off_t type_offset
, uint64_t signature
)
80 this->type_units_
.push_back(Type_unit(tu_offset
, type_offset
, signature
));
81 return this->type_units_
.size() - 1;
84 // Add an address range.
86 add_address_range_list(Relobj
* object
, unsigned int cu_index
,
87 Dwarf_range_list
* ranges
)
89 this->ranges_
.push_back(Per_cu_range_list(object
, cu_index
, ranges
));
92 // Add a symbol. FLAGS are the gdb_index version 7 flags to be stored in
93 // the high-byte of the cu_index field.
95 add_symbol(int cu_index
, const char* sym_name
, uint8_t flags
);
97 // Return the offset into the pubnames table for the cu at the given
100 find_pubname_offset(off_t cu_offset
);
102 // Return the offset into the pubtypes table for the cu at the
105 find_pubtype_offset(off_t cu_offset
);
107 // Return TRUE if we have already processed the pubnames and types
108 // set for OBJECT of the CUs and TUS associated with the statement
111 pubnames_read(const Relobj
* object
, off_t offset
);
113 // Record that we have already read the pubnames associated with
114 // OBJECT and OFFSET.
116 set_pubnames_read(const Relobj
* object
, off_t offset
);
118 // Return a pointer to the given table.
119 Dwarf_pubnames_table
*
121 { return pubnames_table_
; }
123 Dwarf_pubnames_table
*
125 { return pubtypes_table_
; }
127 // Print usage statistics.
132 // This is called to update the section size prior to assigning
133 // the address and file offset.
136 { this->set_final_data_size(); }
138 // Set the final data size.
140 set_final_data_size();
142 // Write the data to the file.
144 do_write(Output_file
*);
146 // Write to a map file.
148 do_print_to_mapfile(Mapfile
* mapfile
) const
149 { mapfile
->print_output_data(this, _("** gdb_index")); }
151 // Create a map from dies to pubnames.
152 Dwarf_pubnames_table
*
153 map_pubtable_to_dies(unsigned int attr
,
154 Gdb_index_info_reader
* dwinfo
,
156 const unsigned char* symbols
,
159 // Wrapper for map_pubtable_to_dies
161 map_pubnames_and_types_to_dies(Gdb_index_info_reader
* dwinfo
,
163 const unsigned char* symbols
,
167 // An entry in the compilation unit list.
170 Comp_unit(off_t off
, off_t len
)
171 : cu_offset(off
), cu_length(len
)
177 // An entry in the type unit list.
180 Type_unit(off_t off
, off_t toff
, uint64_t sig
)
181 : tu_offset(off
), type_offset(toff
), type_signature(sig
)
184 uint64_t type_offset
;
185 uint64_t type_signature
;
188 // An entry in the address range list.
189 struct Per_cu_range_list
191 Per_cu_range_list(Relobj
* obj
, uint32_t index
, Dwarf_range_list
* r
)
192 : object(obj
), cu_index(index
), ranges(r
)
196 Dwarf_range_list
* ranges
;
199 // A symbol table entry.
202 Stringpool::Key name_key
;
203 unsigned int hashval
;
204 unsigned int cu_vector_index
;
206 // Return the hash value.
209 { return this->hashval
; }
211 // Return true if this symbol is the same as SYMBOL.
213 equal(Gdb_symbol
* symbol
)
214 { return this->name_key
== symbol
->name_key
; }
217 typedef std::vector
<std::pair
<int, uint8_t> > Cu_vector
;
219 typedef Unordered_map
<off_t
, off_t
> Pubname_offset_map
;
220 Pubname_offset_map cu_pubname_map_
;
221 Pubname_offset_map cu_pubtype_map_
;
223 // Scan the given pubtable and build a map of the various dies it
224 // refers to, so we can process the entries when we encounter the
227 map_pubtable_to_dies(Dwarf_pubnames_table
* table
,
228 Pubname_offset_map
* map
);
230 // Tables to store the pubnames section of the current object.
231 Dwarf_pubnames_table
* pubnames_table_
;
232 Dwarf_pubnames_table
* pubtypes_table_
;
234 // The .gdb_index section.
235 Output_section
* gdb_index_section_
;
236 // The list of DWARF compilation units.
237 std::vector
<Comp_unit
> comp_units_
;
238 // The list of DWARF type units.
239 std::vector
<Type_unit
> type_units_
;
240 // The list of address ranges.
241 std::vector
<Per_cu_range_list
> ranges_
;
243 Gdb_hashtab
<Gdb_symbol
>* gdb_symtab_
;
244 // The CU vector portion of the constant pool.
245 std::vector
<Cu_vector
*> cu_vector_list_
;
246 // An array to map from a CU vector index to an offset to the constant pool.
247 off_t
* cu_vector_offsets_
;
248 // The string portion of the constant pool.
249 Stringpool stringpool_
;
250 // Offsets of the various pieces of the .gdb_index section.
253 off_t symtab_offset_
;
254 off_t cu_pool_offset_
;
255 off_t stringpool_offset_
;
256 // Object, stmt list offset of the CUs and TUs associated with the
257 // last read pubnames and pubtypes sections.
258 const Relobj
* pubnames_object_
;
259 off_t stmt_list_offset_
;
262 } // End namespace gold.
264 #endif // !defined(GOLD_GDB_INDEX_H)