1 /* Reading code for .gdb_index
3 Copyright (C) 2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "read-gdb-index.h"
23 #include "cli/cli-cmds.h"
24 #include "complaints.h"
26 #include "gdb/gdb-index.h"
27 #include "gdbsupport/gdb-checked-static-cast.h"
28 #include "mapped-index.h"
31 /* When true, do not reject deprecated .gdb_index sections. */
32 static bool use_deprecated_index_sections
= false;
34 /* This is a view into the index that converts from bytes to an
35 offset_type, and allows indexing. Unaligned bytes are specifically
36 allowed here, and handled via unpacking. */
41 offset_view () = default;
43 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
48 /* Extract the INDEXth offset_type from the array. */
49 offset_type
operator[] (size_t index
) const
51 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
52 return (offset_type
) extract_unsigned_integer (bytes
,
57 /* Return the number of offset_types in this array. */
60 return m_bytes
.size () / sizeof (offset_type
);
63 /* Return true if this view is empty. */
66 return m_bytes
.empty ();
70 /* The underlying bytes. */
71 gdb::array_view
<const gdb_byte
> m_bytes
;
74 /* A description of .gdb_index index. The file format is described in
75 a comment by the code that writes the index. */
77 struct mapped_gdb_index final
: public mapped_index_base
79 /* Index data format version. */
82 /* The address table data. */
83 gdb::array_view
<const gdb_byte
> address_table
;
85 /* The symbol table, implemented as a hash table. */
86 offset_view symbol_table
;
88 /* A pointer to the constant pool. */
89 gdb::array_view
<const gdb_byte
> constant_pool
;
91 /* Return the index into the constant pool of the name of the IDXth
92 symbol in the symbol table. */
93 offset_type
symbol_name_index (offset_type idx
) const
95 return symbol_table
[2 * idx
];
98 /* Return the index into the constant pool of the CU vector of the
99 IDXth symbol in the symbol table. */
100 offset_type
symbol_vec_index (offset_type idx
) const
102 return symbol_table
[2 * idx
+ 1];
105 bool symbol_name_slot_invalid (offset_type idx
) const override
107 return (symbol_name_index (idx
) == 0
108 && symbol_vec_index (idx
) == 0);
111 /* Convenience method to get at the name of the symbol at IDX in the
113 const char *symbol_name_at
114 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
116 return (const char *) (this->constant_pool
.data ()
117 + symbol_name_index (idx
));
120 size_t symbol_name_count () const override
121 { return this->symbol_table
.size () / 2; }
123 quick_symbol_functions_up
make_quick_functions () const override
;
125 bool version_check () const override
131 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
133 /* This dumps minimal information about the index.
134 It is called via "mt print objfiles".
135 One use is to verify .gdb_index has been loaded by the
136 gdb.dwarf2/gdb-index.exp testcase. */
137 void dump (struct objfile
*objfile
) override
;
139 void expand_matching_symbols
141 const lookup_name_info
&lookup_name
,
144 symbol_compare_ftype
*ordered_compare
) override
;
146 bool expand_symtabs_matching
147 (struct objfile
*objfile
,
148 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
149 const lookup_name_info
*lookup_name
,
150 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
151 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
152 block_search_flags search_flags
,
154 enum search_domain kind
) override
;
157 /* This dumps minimal information about the index.
158 It is called via "mt print objfiles".
159 One use is to verify .gdb_index has been loaded by the
160 gdb.dwarf2/gdb-index.exp testcase. */
163 dwarf2_gdb_index::dump (struct objfile
*objfile
)
165 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
167 mapped_gdb_index
*index
= (gdb::checked_static_cast
<mapped_gdb_index
*>
168 (per_objfile
->per_bfd
->index_table
.get ()));
169 gdb_printf (".gdb_index: version %d\n", index
->version
);
173 /* Struct used to manage iterating over all CUs looking for a symbol. */
175 struct dw2_symtab_iterator
177 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
178 dwarf2_per_objfile
*per_objfile
;
179 /* If set, only look for symbols that match that block. Valid values are
180 GLOBAL_BLOCK and STATIC_BLOCK. */
181 gdb::optional
<block_enum
> block_index
;
182 /* The kind of symbol we're looking for. */
184 /* The list of CUs from the index entry of the symbol,
185 or NULL if not found. */
187 /* The next element in VEC to look at. */
189 /* The number of elements in VEC, or zero if there is no match. */
191 /* Have we seen a global version of the symbol?
192 If so we can ignore all further global instances.
193 This is to work around gold/15646, inefficient gold-generated
198 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
201 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
202 dwarf2_per_objfile
*per_objfile
,
203 gdb::optional
<block_enum
> block_index
,
204 domain_enum domain
, offset_type namei
,
205 mapped_gdb_index
&index
)
207 iter
->per_objfile
= per_objfile
;
208 iter
->block_index
= block_index
;
209 iter
->domain
= domain
;
211 iter
->global_seen
= 0;
215 gdb_assert (!index
.symbol_name_slot_invalid (namei
));
216 offset_type vec_idx
= index
.symbol_vec_index (namei
);
218 iter
->vec
= offset_view (index
.constant_pool
.slice (vec_idx
));
219 iter
->length
= iter
->vec
[0];
222 /* Return the next matching CU or NULL if there are no more. */
224 static struct dwarf2_per_cu_data
*
225 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
,
226 mapped_gdb_index
&index
)
228 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
230 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
232 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
233 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
234 gdb_index_symbol_kind symbol_kind
=
235 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
236 /* Only check the symbol attributes if they're present.
237 Indices prior to version 7 don't record them,
238 and indices >= 7 may elide them for certain symbols
240 int attrs_valid
= (index
.version
>= 7
241 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
243 /* Don't crash on bad data. */
244 if (cu_index
>= per_objfile
->per_bfd
->all_units
.size ())
246 complaint (_(".gdb_index entry has bad CU index"
247 " [in module %s]"), objfile_name (per_objfile
->objfile
));
251 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
253 /* Skip if already read in. */
254 if (per_objfile
->symtab_set_p (per_cu
))
257 /* Check static vs global. */
260 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
262 if (iter
->block_index
.has_value ())
264 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
266 if (is_static
!= want_static
)
270 /* Work around gold/15646. */
272 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
274 if (iter
->global_seen
)
277 iter
->global_seen
= 1;
281 /* Only check the symbol's kind if it has one. */
284 switch (iter
->domain
)
287 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
288 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
289 /* Some types are also in VAR_DOMAIN. */
290 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
294 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
298 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
302 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
318 dwarf2_gdb_index::expand_matching_symbols
319 (struct objfile
*objfile
,
320 const lookup_name_info
&name
, domain_enum domain
,
322 symbol_compare_ftype
*ordered_compare
)
325 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
327 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
329 mapped_gdb_index
&index
330 = *(gdb::checked_static_cast
<mapped_gdb_index
*>
331 (per_objfile
->per_bfd
->index_table
.get ()));
333 const char *match_name
= name
.ada ().lookup_name ().c_str ();
334 auto matcher
= [&] (const char *symname
)
336 if (ordered_compare
== nullptr)
338 return ordered_compare (symname
, match_name
) == 0;
341 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
342 [&] (offset_type namei
)
344 struct dw2_symtab_iterator iter
;
345 struct dwarf2_per_cu_data
*per_cu
;
347 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
, namei
,
349 while ((per_cu
= dw2_symtab_iter_next (&iter
, index
)) != NULL
)
350 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
356 /* Helper for dw2_expand_matching symtabs. Called on each symbol
357 matched, to expand corresponding CUs that were marked. IDX is the
358 index of the symbol name that matched. */
361 dw2_expand_marked_cus
362 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
363 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
364 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
365 block_search_flags search_flags
,
368 offset_type vec_len
, vec_idx
;
369 bool global_seen
= false;
370 mapped_gdb_index
&index
371 = *(gdb::checked_static_cast
<mapped_gdb_index
*>
372 (per_objfile
->per_bfd
->index_table
.get ()));
374 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
376 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
378 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
379 /* This value is only valid for index versions >= 7. */
380 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
381 gdb_index_symbol_kind symbol_kind
=
382 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
383 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
384 /* Only check the symbol attributes if they're present.
385 Indices prior to version 7 don't record them,
386 and indices >= 7 may elide them for certain symbols
390 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
392 /* Work around gold/15646. */
395 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
403 /* Only check the symbol's kind if it has one. */
408 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
413 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
419 case VARIABLES_DOMAIN
:
420 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
423 case FUNCTIONS_DOMAIN
:
424 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
428 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
432 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
440 /* Don't crash on bad data. */
441 if (cu_index
>= per_objfile
->per_bfd
->all_units
.size ())
443 complaint (_(".gdb_index entry has bad CU index"
444 " [in module %s]"), objfile_name (per_objfile
->objfile
));
448 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
449 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
458 dwarf2_gdb_index::expand_symtabs_matching
459 (struct objfile
*objfile
,
460 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
461 const lookup_name_info
*lookup_name
,
462 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
463 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
464 block_search_flags search_flags
,
466 enum search_domain kind
)
468 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
470 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
472 /* This invariant is documented in quick-functions.h. */
473 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
474 if (lookup_name
== nullptr)
476 for (dwarf2_per_cu_data
*per_cu
477 : all_units_range (per_objfile
->per_bfd
))
481 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
489 mapped_gdb_index
&index
490 = *(gdb::checked_static_cast
<mapped_gdb_index
*>
491 (per_objfile
->per_bfd
->index_table
.get ()));
494 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
496 [&] (offset_type idx
)
498 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
499 expansion_notify
, search_flags
, kind
))
507 quick_symbol_functions_up
508 mapped_gdb_index::make_quick_functions () const
510 return quick_symbol_functions_up (new dwarf2_gdb_index
);
513 /* A helper function that reads the .gdb_index from BUFFER and fills
514 in MAP. FILENAME is the name of the file containing the data;
515 it is used for error reporting. DEPRECATED_OK is true if it is
516 ok to use deprecated sections.
518 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
519 out parameters that are filled in with information about the CU and
520 TU lists in the section.
522 Returns true if all went well, false otherwise. */
525 read_gdb_index_from_buffer (const char *filename
,
527 gdb::array_view
<const gdb_byte
> buffer
,
528 mapped_gdb_index
*map
,
529 const gdb_byte
**cu_list
,
530 offset_type
*cu_list_elements
,
531 const gdb_byte
**types_list
,
532 offset_type
*types_list_elements
)
534 const gdb_byte
*addr
= &buffer
[0];
535 offset_view
metadata (buffer
);
538 offset_type version
= metadata
[0];
539 /* Versions earlier than 3 emitted every copy of a psymbol. This
540 causes the index to behave very poorly for certain requests. Version 3
541 contained incomplete addrmap. So, it seems better to just ignore such
545 static int warning_printed
= 0;
546 if (!warning_printed
)
548 warning (_("Skipping obsolete .gdb_index section in %s."),
554 /* Index version 4 uses a different hash function than index version
557 Versions earlier than 6 did not emit psymbols for inlined
558 functions. Using these files will cause GDB not to be able to
559 set breakpoints on inlined functions by name, so we ignore these
560 indices unless the user has done
561 "set use-deprecated-index-sections on". */
562 if (version
< 6 && !deprecated_ok
)
564 static int warning_printed
= 0;
565 if (!warning_printed
)
568 Skipping deprecated .gdb_index section in %s.\n\
569 Do \"set use-deprecated-index-sections on\" before the file is read\n\
570 to use the section anyway."),
576 /* Version 7 indices generated by gold refer to the CU for a symbol instead
577 of the TU (for symbols coming from TUs),
578 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
579 Plus gold-generated indices can have duplicate entries for global symbols,
580 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
581 These are just performance bugs, and we can't distinguish gdb-generated
582 indices from gold-generated ones, so issue no warning here. */
584 /* Indexes with higher version than the one supported by GDB may be no
585 longer backward compatible. */
589 map
->version
= version
;
592 *cu_list
= addr
+ metadata
[i
];
593 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
596 *types_list
= addr
+ metadata
[i
];
597 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
600 const gdb_byte
*address_table
= addr
+ metadata
[i
];
601 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
603 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
606 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
607 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
609 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
613 map
->constant_pool
= buffer
.slice (metadata
[i
]);
615 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
617 /* An empty constant pool implies that all symbol table entries are
618 empty. Make map->symbol_table.empty () == true. */
620 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
627 /* A helper for create_cus_from_gdb_index that handles a given list of
631 create_cus_from_gdb_index_list (dwarf2_per_bfd
*per_bfd
,
632 const gdb_byte
*cu_list
, offset_type n_elements
,
633 struct dwarf2_section_info
*section
,
636 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
638 gdb_static_assert (sizeof (ULONGEST
) >= 8);
641 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
642 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
645 dwarf2_per_cu_data_up per_cu
646 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
648 per_bfd
->all_units
.push_back (std::move (per_cu
));
652 /* Read the CU list from the mapped index, and use it to create all
653 the CU objects for PER_BFD. */
656 create_cus_from_gdb_index (dwarf2_per_bfd
*per_bfd
,
657 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
658 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
660 gdb_assert (per_bfd
->all_units
.empty ());
661 per_bfd
->all_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
663 create_cus_from_gdb_index_list (per_bfd
, cu_list
, cu_list_elements
,
666 if (dwz_elements
== 0)
669 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
670 create_cus_from_gdb_index_list (per_bfd
, dwz_list
, dwz_elements
,
674 /* Create the signatured type hash table from the index. */
677 create_signatured_type_table_from_gdb_index
678 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
679 const gdb_byte
*bytes
, offset_type elements
)
681 htab_up sig_types_hash
= allocate_signatured_type_table ();
683 for (offset_type i
= 0; i
< elements
; i
+= 3)
685 signatured_type_up sig_type
;
688 cu_offset type_offset_in_tu
;
690 gdb_static_assert (sizeof (ULONGEST
) >= 8);
692 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
694 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
696 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
699 sig_type
= per_bfd
->allocate_signatured_type (signature
);
700 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
701 sig_type
->section
= section
;
702 sig_type
->sect_off
= sect_off
;
704 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
705 *slot
= sig_type
.get ();
707 per_bfd
->all_units
.emplace_back (sig_type
.release ());
710 per_bfd
->signatured_types
= std::move (sig_types_hash
);
713 /* Read the address map data from the mapped GDB index, and use it to
714 populate the index_addrmap. */
717 create_addrmap_from_gdb_index (dwarf2_per_objfile
*per_objfile
,
718 mapped_gdb_index
*index
)
720 struct objfile
*objfile
= per_objfile
->objfile
;
721 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
722 struct gdbarch
*gdbarch
= objfile
->arch ();
723 const gdb_byte
*iter
, *end
;
726 addrmap_mutable mutable_map
;
728 iter
= index
->address_table
.data ();
729 end
= iter
+ index
->address_table
.size ();
731 baseaddr
= objfile
->text_section_offset ();
735 ULONGEST hi
, lo
, cu_index
;
736 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
738 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
740 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
745 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
746 hex_string (lo
), hex_string (hi
));
750 if (cu_index
>= per_bfd
->all_units
.size ())
752 complaint (_(".gdb_index address table has invalid CU number %u"),
753 (unsigned) cu_index
);
757 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
758 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
759 mutable_map
.set_empty (lo
, hi
- 1, per_bfd
->get_cu (cu_index
));
762 per_bfd
->index_addrmap
763 = new (&per_bfd
->obstack
) addrmap_fixed (&per_bfd
->obstack
, &mutable_map
);
766 /* See read-gdb-index.h. */
769 dwarf2_read_gdb_index
770 (dwarf2_per_objfile
*per_objfile
,
771 get_gdb_index_contents_ftype get_gdb_index_contents
,
772 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
774 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
775 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
776 struct dwz_file
*dwz
;
777 struct objfile
*objfile
= per_objfile
->objfile
;
778 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
780 gdb::array_view
<const gdb_byte
> main_index_contents
781 = get_gdb_index_contents (objfile
, per_bfd
);
783 if (main_index_contents
.empty ())
786 std::unique_ptr
<mapped_gdb_index
> map (new mapped_gdb_index
);
787 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
788 use_deprecated_index_sections
,
789 main_index_contents
, map
.get (), &cu_list
,
790 &cu_list_elements
, &types_list
,
791 &types_list_elements
))
794 /* Don't use the index if it's empty. */
795 if (map
->symbol_table
.empty ())
798 /* If there is a .dwz file, read it so we can get its CU list as
800 dwz
= dwarf2_get_dwz_file (per_bfd
);
803 mapped_gdb_index dwz_map
;
804 const gdb_byte
*dwz_types_ignore
;
805 offset_type dwz_types_elements_ignore
;
807 gdb::array_view
<const gdb_byte
> dwz_index_content
808 = get_gdb_index_contents_dwz (objfile
, dwz
);
810 if (dwz_index_content
.empty ())
813 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
814 1, dwz_index_content
, &dwz_map
,
815 &dwz_list
, &dwz_list_elements
,
817 &dwz_types_elements_ignore
))
819 warning (_("could not read '.gdb_index' section from %s; skipping"),
820 bfd_get_filename (dwz
->dwz_bfd
.get ()));
825 create_cus_from_gdb_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
828 if (types_list_elements
)
830 /* We can only handle a single .debug_types when we have an
832 if (per_bfd
->types
.size () > 1)
834 per_bfd
->all_units
.clear ();
838 dwarf2_section_info
*section
839 = (per_bfd
->types
.size () == 1
843 create_signatured_type_table_from_gdb_index (per_bfd
, section
, types_list
,
844 types_list_elements
);
847 finalize_all_units (per_bfd
);
849 create_addrmap_from_gdb_index (per_objfile
, map
.get ());
851 per_bfd
->index_table
= std::move (map
);
852 per_bfd
->quick_file_names_table
=
853 create_quick_file_names_table (per_bfd
->all_units
.size ());
858 void _initialize_read_gdb_index ();
861 _initialize_read_gdb_index ()
863 add_setshow_boolean_cmd ("use-deprecated-index-sections",
864 no_class
, &use_deprecated_index_sections
, _("\
865 Set whether to use deprecated gdb_index sections."), _("\
866 Show whether to use deprecated gdb_index sections."), _("\
867 When enabled, deprecated .gdb_index sections are used anyway.\n\
868 Normally they are ignored either because of a missing feature or\n\
869 performance issue.\n\
870 Warning: This option must be enabled before gdb reads the file."),
873 &setlist
, &showlist
);