GDB (xrefs)
Loading...
Searching...
No Matches
read-gdb-index.c
Go to the documentation of this file.
1/* Reading code for .gdb_index
2
3 Copyright (C) 2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "read-gdb-index.h"
22
23#include "cli/cli-cmds.h"
24#include "complaints.h"
25#include "dwz.h"
26#include "gdb/gdb-index.h"
27#include "gdbsupport/gdb-checked-static-cast.h"
28#include "mapped-index.h"
29#include "read.h"
30
31/* When true, do not reject deprecated .gdb_index sections. */
33
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. */
37
39{
40public:
41 offset_view () = default;
42
43 explicit offset_view (gdb::array_view<const gdb_byte> bytes)
44 : m_bytes (bytes)
45 {
46 }
47
48 /* Extract the INDEXth offset_type from the array. */
49 offset_type operator[] (size_t index) const
50 {
51 const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)];
53 sizeof (offset_type),
54 BFD_ENDIAN_LITTLE);
55 }
56
57 /* Return the number of offset_types in this array. */
58 size_t size () const
59 {
60 return m_bytes.size () / sizeof (offset_type);
61 }
62
63 /* Return true if this view is empty. */
64 bool empty () const
65 {
66 return m_bytes.empty ();
67 }
68
69private:
70 /* The underlying bytes. */
71 gdb::array_view<const gdb_byte> m_bytes;
72};
73
74/* A description of .gdb_index index. The file format is described in
75 a comment by the code that writes the index. */
76
78{
79 /* Index data format version. */
80 int version = 0;
81
82 /* The address table data. */
83 gdb::array_view<const gdb_byte> address_table;
84
85 /* The symbol table, implemented as a hash table. */
87
88 /* A pointer to the constant pool. */
89 gdb::array_view<const gdb_byte> constant_pool;
90
91 /* Return the index into the constant pool of the name of the IDXth
92 symbol in the symbol table. */
94 {
95 return symbol_table[2 * idx];
96 }
97
98 /* Return the index into the constant pool of the CU vector of the
99 IDXth symbol in the symbol table. */
101 {
102 return symbol_table[2 * idx + 1];
103 }
104
105 bool symbol_name_slot_invalid (offset_type idx) const override
106 {
107 return (symbol_name_index (idx) == 0
108 && symbol_vec_index (idx) == 0);
109 }
110
111 /* Convenience method to get at the name of the symbol at IDX in the
112 symbol table. */
113 const char *symbol_name_at
114 (offset_type idx, dwarf2_per_objfile *per_objfile) const override
115 {
116 return (const char *) (this->constant_pool.data ()
117 + symbol_name_index (idx));
118 }
119
120 size_t symbol_name_count () const override
121 { return this->symbol_table.size () / 2; }
122
124
125 bool version_check () const override
126 {
127 return version >= 8;
128 }
129};
130
132{
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;
138
140 (struct objfile *,
141 const lookup_name_info &lookup_name,
142 domain_enum domain,
143 int global,
144 symbol_compare_ftype *ordered_compare) override;
145
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,
153 domain_enum domain,
154 enum search_domain kind) override;
155};
156
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. */
161
162void
164{
166
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);
170 gdb_printf ("\n");
171}
172
173/* Struct used to manage iterating over all CUs looking for a symbol. */
174
176{
177 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
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. */
188 int next;
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
194 indices. */
196};
197
198/* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
199
200static void
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)
206{
207 iter->per_objfile = per_objfile;
208 iter->block_index = block_index;
209 iter->domain = domain;
210 iter->next = 0;
211 iter->global_seen = 0;
212 iter->vec = {};
213 iter->length = 0;
214
215 gdb_assert (!index.symbol_name_slot_invalid (namei));
216 offset_type vec_idx = index.symbol_vec_index (namei);
217
218 iter->vec = offset_view (index.constant_pool.slice (vec_idx));
219 iter->length = iter->vec[0];
220}
221
222/* Return the next matching CU or NULL if there are no more. */
223
224static struct dwarf2_per_cu_data *
227{
228 dwarf2_per_objfile *per_objfile = iter->per_objfile;
229
230 for ( ; iter->next < iter->length; ++iter->next)
231 {
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
239 (gold does this). */
240 int attrs_valid = (index.version >= 7
241 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
242
243 /* Don't crash on bad data. */
244 if (cu_index >= per_objfile->per_bfd->all_units.size ())
245 {
246 complaint (_(".gdb_index entry has bad CU index"
247 " [in module %s]"), objfile_name (per_objfile->objfile));
248 continue;
249 }
250
251 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (cu_index);
252
253 /* Skip if already read in. */
254 if (per_objfile->symtab_set_p (per_cu))
255 continue;
256
257 /* Check static vs global. */
258 if (attrs_valid)
259 {
260 bool is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
261
262 if (iter->block_index.has_value ())
263 {
264 bool want_static = *iter->block_index == STATIC_BLOCK;
265
266 if (is_static != want_static)
267 continue;
268 }
269
270 /* Work around gold/15646. */
271 if (!is_static
272 && symbol_kind == GDB_INDEX_SYMBOL_KIND_TYPE)
273 {
274 if (iter->global_seen)
275 continue;
276
277 iter->global_seen = 1;
278 }
279 }
280
281 /* Only check the symbol's kind if it has one. */
282 if (attrs_valid)
283 {
284 switch (iter->domain)
285 {
286 case VAR_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)
291 continue;
292 break;
293 case STRUCT_DOMAIN:
294 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
295 continue;
296 break;
297 case LABEL_DOMAIN:
298 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
299 continue;
300 break;
301 case MODULE_DOMAIN:
302 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
303 continue;
304 break;
305 default:
306 break;
307 }
308 }
309
310 ++iter->next;
311 return per_cu;
312 }
313
314 return NULL;
315}
316
317void
319 (struct objfile *objfile,
320 const lookup_name_info &name, domain_enum domain,
321 int global,
322 symbol_compare_ftype *ordered_compare)
323{
324 /* Used for Ada. */
326
327 const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
328
329 mapped_gdb_index &index
330 = *(gdb::checked_static_cast<mapped_gdb_index *>
331 (per_objfile->per_bfd->index_table.get ()));
332
333 const char *match_name = name.ada ().lookup_name ().c_str ();
334 auto matcher = [&] (const char *symname)
335 {
336 if (ordered_compare == nullptr)
337 return true;
338 return ordered_compare (symname, match_name) == 0;
339 };
340
342 [&] (offset_type namei)
343 {
344 struct dw2_symtab_iterator iter;
345 struct dwarf2_per_cu_data *per_cu;
346
347 dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain, namei,
348 index);
349 while ((per_cu = dw2_symtab_iter_next (&iter, index)) != NULL)
350 dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
351 nullptr);
352 return true;
353 }, per_objfile);
354}
355
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. */
359
360static bool
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,
366 search_domain kind)
367{
368 offset_type vec_len, vec_idx;
369 bool global_seen = false;
371 = *(gdb::checked_static_cast<mapped_gdb_index *>
372 (per_objfile->per_bfd->index_table.get ()));
373
374 offset_view vec (index.constant_pool.slice (index.symbol_vec_index (idx)));
375 vec_len = vec[0];
376 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
377 {
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
387 (gold does this). */
388 int attrs_valid =
389 (index.version >= 7
390 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
391
392 /* Work around gold/15646. */
393 if (attrs_valid
394 && !is_static
395 && symbol_kind == GDB_INDEX_SYMBOL_KIND_TYPE)
396 {
397 if (global_seen)
398 continue;
399
400 global_seen = true;
401 }
402
403 /* Only check the symbol's kind if it has one. */
404 if (attrs_valid)
405 {
406 if (is_static)
407 {
408 if ((search_flags & SEARCH_STATIC_BLOCK) == 0)
409 continue;
410 }
411 else
412 {
413 if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0)
414 continue;
415 }
416
417 switch (kind)
418 {
419 case VARIABLES_DOMAIN:
420 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
421 continue;
422 break;
423 case FUNCTIONS_DOMAIN:
424 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
425 continue;
426 break;
427 case TYPES_DOMAIN:
428 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
429 continue;
430 break;
431 case MODULES_DOMAIN:
432 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
433 continue;
434 break;
435 default:
436 break;
437 }
438 }
439
440 /* Don't crash on bad data. */
441 if (cu_index >= per_objfile->per_bfd->all_units.size ())
442 {
443 complaint (_(".gdb_index entry has bad CU index"
444 " [in module %s]"), objfile_name (per_objfile->objfile));
445 continue;
446 }
447
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,
450 expansion_notify))
451 return false;
452 }
453
454 return true;
455}
456
457bool
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,
465 domain_enum domain,
466 enum search_domain kind)
467{
469
470 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
471
472 /* This invariant is documented in quick-functions.h. */
473 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
474 if (lookup_name == nullptr)
475 {
476 for (dwarf2_per_cu_data *per_cu
477 : all_units_range (per_objfile->per_bfd))
478 {
479 QUIT;
480
481 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
482 file_matcher,
483 expansion_notify))
484 return false;
485 }
486 return true;
487 }
488
489 mapped_gdb_index &index
490 = *(gdb::checked_static_cast<mapped_gdb_index *>
491 (per_objfile->per_bfd->index_table.get ()));
492
493 bool result
494 = dw2_expand_symtabs_matching_symbol (index, *lookup_name,
495 symbol_matcher,
496 [&] (offset_type idx)
497 {
498 if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
499 expansion_notify, search_flags, kind))
500 return false;
501 return true;
502 }, per_objfile);
503
504 return result;
505}
506
512
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.
517
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.
521
522 Returns true if all went well, false otherwise. */
523
524static bool
525read_gdb_index_from_buffer (const char *filename,
526 bool deprecated_ok,
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)
533{
534 const gdb_byte *addr = &buffer[0];
535 offset_view metadata (buffer);
536
537 /* Version check. */
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
542 indices. */
543 if (version < 4)
544 {
545 static int warning_printed = 0;
546 if (!warning_printed)
547 {
548 warning (_("Skipping obsolete .gdb_index section in %s."),
549 filename);
550 warning_printed = 1;
551 }
552 return 0;
553 }
554 /* Index version 4 uses a different hash function than index version
555 5 and later.
556
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)
563 {
564 static int warning_printed = 0;
565 if (!warning_printed)
566 {
567 warning (_("\
568Skipping deprecated .gdb_index section in %s.\n\
569Do \"set use-deprecated-index-sections on\" before the file is read\n\
570to use the section anyway."),
571 filename);
572 warning_printed = 1;
573 }
574 return 0;
575 }
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. */
583
584 /* Indexes with higher version than the one supported by GDB may be no
585 longer backward compatible. */
586 if (version > 8)
587 return 0;
588
589 map->version = version;
590
591 int i = 1;
592 *cu_list = addr + metadata[i];
593 *cu_list_elements = (metadata[i + 1] - metadata[i]) / 8;
594 ++i;
595
596 *types_list = addr + metadata[i];
597 *types_list_elements = (metadata[i + 1] - metadata[i]) / 8;
598 ++i;
599
600 const gdb_byte *address_table = addr + metadata[i];
601 const gdb_byte *address_table_end = addr + metadata[i + 1];
602 map->address_table
603 = gdb::array_view<const gdb_byte> (address_table, address_table_end);
604 ++i;
605
606 const gdb_byte *symbol_table = addr + metadata[i];
607 const gdb_byte *symbol_table_end = addr + metadata[i + 1];
608 map->symbol_table
609 = offset_view (gdb::array_view<const gdb_byte> (symbol_table,
610 symbol_table_end));
611
612 ++i;
613 map->constant_pool = buffer.slice (metadata[i]);
614
615 if (map->constant_pool.empty () && !map->symbol_table.empty ())
616 {
617 /* An empty constant pool implies that all symbol table entries are
618 empty. Make map->symbol_table.empty () == true. */
619 map->symbol_table
620 = offset_view (gdb::array_view<const gdb_byte> (symbol_table,
621 symbol_table));
622 }
623
624 return 1;
625}
626
627/* A helper for create_cus_from_gdb_index that handles a given list of
628 CUs. */
629
630static void
632 const gdb_byte *cu_list, offset_type n_elements,
634 int is_dwz)
635{
636 for (offset_type i = 0; i < n_elements; i += 2)
637 {
638 gdb_static_assert (sizeof (ULONGEST) >= 8);
639
640 sect_offset sect_off
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);
643 cu_list += 2 * 8;
644
647 length);
648 per_bfd->all_units.push_back (std::move (per_cu));
649 }
650}
651
652/* Read the CU list from the mapped index, and use it to create all
653 the CU objects for PER_BFD. */
654
655static void
657 const gdb_byte *cu_list, offset_type cu_list_elements,
658 const gdb_byte *dwz_list, offset_type dwz_elements)
659{
660 gdb_assert (per_bfd->all_units.empty ());
661 per_bfd->all_units.reserve ((cu_list_elements + dwz_elements) / 2);
662
663 create_cus_from_gdb_index_list (per_bfd, cu_list, cu_list_elements,
664 &per_bfd->info, 0);
665
666 if (dwz_elements == 0)
667 return;
668
670 create_cus_from_gdb_index_list (per_bfd, dwz_list, dwz_elements,
671 &dwz->info, 1);
672}
673
674/* Create the signatured type hash table from the index. */
675
676static void
679 const gdb_byte *bytes, offset_type elements)
680{
681 htab_up sig_types_hash = allocate_signatured_type_table ();
682
683 for (offset_type i = 0; i < elements; i += 3)
684 {
685 signatured_type_up sig_type;
686 ULONGEST signature;
687 void **slot;
688 cu_offset type_offset_in_tu;
689
690 gdb_static_assert (sizeof (ULONGEST) >= 8);
691 sect_offset sect_off
692 = (sect_offset) extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
693 type_offset_in_tu
694 = (cu_offset) extract_unsigned_integer (bytes + 8, 8,
695 BFD_ENDIAN_LITTLE);
696 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
697 bytes += 3 * 8;
698
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;
703
704 slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
705 *slot = sig_type.get ();
706
707 per_bfd->all_units.emplace_back (sig_type.release ());
708 }
709
710 per_bfd->signatured_types = std::move (sig_types_hash);
711}
712
713/* Read the address map data from the mapped GDB index, and use it to
714 populate the index_addrmap. */
715
716static void
719{
720 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
721 const gdb_byte *iter, *end;
722
723 addrmap_mutable mutable_map;
724
725 iter = index->address_table.data ();
726 end = iter + index->address_table.size ();
727
728 while (iter < end)
729 {
730 ULONGEST hi, lo, cu_index;
731 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
732 iter += 8;
733 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
734 iter += 8;
735 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
736 iter += 4;
737
738 if (lo > hi)
739 {
740 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
741 hex_string (lo), hex_string (hi));
742 continue;
743 }
744
745 if (cu_index >= per_bfd->all_units.size ())
746 {
747 complaint (_(".gdb_index address table has invalid CU number %u"),
748 (unsigned) cu_index);
749 continue;
750 }
751
752 lo = (ULONGEST) per_objfile->adjust ((unrelocated_addr) lo);
753 hi = (ULONGEST) per_objfile->adjust ((unrelocated_addr) hi);
754 mutable_map.set_empty (lo, hi - 1, per_bfd->get_cu (cu_index));
755 }
756
758 = new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack, &mutable_map);
759}
760
761/* See read-gdb-index.h. */
762
763int
765 (dwarf2_per_objfile *per_objfile,
766 get_gdb_index_contents_ftype get_gdb_index_contents,
767 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
768{
769 const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
770 offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
771 struct dwz_file *dwz;
772 struct objfile *objfile = per_objfile->objfile;
773 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
774
775 gdb::array_view<const gdb_byte> main_index_contents
776 = get_gdb_index_contents (objfile, per_bfd);
777
778 if (main_index_contents.empty ())
779 return 0;
780
781 auto map = gdb::make_unique<mapped_gdb_index> ();
784 main_index_contents, map.get (), &cu_list,
785 &cu_list_elements, &types_list,
786 &types_list_elements))
787 return 0;
788
789 /* Don't use the index if it's empty. */
790 if (map->symbol_table.empty ())
791 return 0;
792
793 /* If there is a .dwz file, read it so we can get its CU list as
794 well. */
796 if (dwz != NULL)
797 {
798 mapped_gdb_index dwz_map;
799 const gdb_byte *dwz_types_ignore;
800 offset_type dwz_types_elements_ignore;
801
802 gdb::array_view<const gdb_byte> dwz_index_content
803 = get_gdb_index_contents_dwz (objfile, dwz);
804
805 if (dwz_index_content.empty ())
806 return 0;
807
808 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz->dwz_bfd.get ()),
809 1, dwz_index_content, &dwz_map,
810 &dwz_list, &dwz_list_elements,
811 &dwz_types_ignore,
812 &dwz_types_elements_ignore))
813 {
814 warning (_("could not read '.gdb_index' section from %s; skipping"),
815 bfd_get_filename (dwz->dwz_bfd.get ()));
816 return 0;
817 }
818 }
819
820 create_cus_from_gdb_index (per_bfd, cu_list, cu_list_elements, dwz_list,
821 dwz_list_elements);
822
823 if (types_list_elements)
824 {
825 /* We can only handle a single .debug_types when we have an
826 index. */
827 if (per_bfd->types.size () > 1)
828 {
829 per_bfd->all_units.clear ();
830 return 0;
831 }
832
833 dwarf2_section_info *section
834 = (per_bfd->types.size () == 1
835 ? &per_bfd->types[0]
836 : &per_bfd->info);
837
839 types_list_elements);
840 }
841
843
844 create_addrmap_from_gdb_index (per_objfile, map.get ());
845
846 per_bfd->index_table = std::move (map);
847 per_bfd->quick_file_names_table =
848 create_quick_file_names_table (per_bfd->all_units.size ());
849
850 return 1;
851}
852
854
855void
857{
858 add_setshow_boolean_cmd ("use-deprecated-index-sections",
860Set whether to use deprecated gdb_index sections."), _("\
861Show whether to use deprecated gdb_index sections."), _("\
862When enabled, deprecated .gdb_index sections are used anyway.\n\
863Normally they are ignored either because of a missing feature or\n\
864performance issue.\n\
865Warning: This option must be enabled before gdb reads the file."),
866 NULL,
867 NULL,
868 &setlist, &showlist);
869}
const char *const name
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
offset_view()=default
offset_type operator[](size_t index) const
offset_view(gdb::array_view< const gdb_byte > bytes)
size_t size() const
bool empty() const
gdb::array_view< const gdb_byte > m_bytes
struct cmd_list_element * showlist
Definition cli-cmds.c:127
struct cmd_list_element * setlist
Definition cli-cmds.c:119
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
@ no_class
Definition command.h:53
#define complaint(FMT,...)
Definition complaints.h:47
block_enum
Definition defs.h:584
@ STATIC_BLOCK
Definition defs.h:586
@ GLOBAL_BLOCK
Definition defs.h:585
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
#define QUIT
Definition defs.h:187
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
Definition dwz.c:193
uint32_t offset_type
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
int symbol_compare_ftype(const char *string1, const char *string2)
@ SEARCH_GLOBAL_BLOCK
@ SEARCH_STATIC_BLOCK
std::unique_ptr< quick_symbol_functions > quick_symbol_functions_up
static void dw2_symtab_iter_init(struct dw2_symtab_iterator *iter, dwarf2_per_objfile *per_objfile, gdb::optional< block_enum > block_index, domain_enum domain, offset_type namei, mapped_gdb_index &index)
void _initialize_read_gdb_index()
static bool dw2_expand_marked_cus(dwarf2_per_objfile *per_objfile, offset_type idx, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, search_domain kind)
static void create_cus_from_gdb_index(dwarf2_per_bfd *per_bfd, const gdb_byte *cu_list, offset_type cu_list_elements, const gdb_byte *dwz_list, offset_type dwz_elements)
int dwarf2_read_gdb_index(dwarf2_per_objfile *per_objfile, get_gdb_index_contents_ftype get_gdb_index_contents, get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
static struct dwarf2_per_cu_data * dw2_symtab_iter_next(struct dw2_symtab_iterator *iter, mapped_gdb_index &index)
static void create_cus_from_gdb_index_list(dwarf2_per_bfd *per_bfd, const gdb_byte *cu_list, offset_type n_elements, struct dwarf2_section_info *section, int is_dwz)
static void create_addrmap_from_gdb_index(dwarf2_per_objfile *per_objfile, mapped_gdb_index *index)
static bool read_gdb_index_from_buffer(const char *filename, bool deprecated_ok, gdb::array_view< const gdb_byte > buffer, mapped_gdb_index *map, const gdb_byte **cu_list, offset_type *cu_list_elements, const gdb_byte **types_list, offset_type *types_list_elements)
static bool use_deprecated_index_sections
static void create_signatured_type_table_from_gdb_index(dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, const gdb_byte *bytes, offset_type elements)
gdb::function_view< gdb::array_view< const gdb_byte >(objfile *, dwz_file *) get_gdb_index_contents_dwz_ftype)
gdb::function_view< gdb::array_view< const gdb_byte >(objfile *, dwarf2_per_bfd *) get_gdb_index_contents_ftype)
htab_up create_quick_file_names_table(unsigned int nr_initial_entries)
Definition read.c:1710
bool dw2_expand_symtabs_matching_symbol(mapped_index_base &index, const lookup_name_info &lookup_name_in, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< bool(offset_type)> match_callback, dwarf2_per_objfile *per_objfile)
Definition read.c:2477
dwarf2_per_cu_data_up create_cu_from_index_list(dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, int is_dwz, sect_offset sect_off, ULONGEST length)
Definition read.c:1826
void finalize_all_units(dwarf2_per_bfd *per_bfd)
Definition read.c:5271
void dw_expand_symtabs_matching_file_matcher(dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher)
Definition read.c:3055
bool dw2_expand_symtabs_matching_one(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify)
Definition read.c:3032
htab_up allocate_signatured_type_table()
Definition read.c:3561
dwarf2_per_objfile * get_dwarf2_per_objfile(struct objfile *objfile)
Definition read.c:165
std::unique_ptr< signatured_type > signatured_type_up
Definition read.h:411
std::unique_ptr< dwarf2_per_cu_data, dwarf2_per_cu_data_deleter > dwarf2_per_cu_data_up
Definition read.h:94
void set_empty(CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) override
Definition addrmap.c:191
gdb::optional< block_enum > block_index
dwarf2_per_objfile * per_objfile
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
void dump(struct objfile *objfile) override
auto_obstack obstack
Definition read.h:467
struct addrmap * index_addrmap
Definition read.h:558
htab_up signatured_types
Definition read.h:505
dwarf2_per_cu_data * get_cu(int index) const
Definition read.h:434
std::unique_ptr< dwarf_scanner_base > index_table
Definition read.h:533
signatured_type_up allocate_signatured_type(ULONGEST signature)
Definition read.c:1813
dwarf2_section_info info
Definition read.h:469
std::vector< dwarf2_per_cu_data_up > all_units
Definition read.h:492
unsigned index
Definition read.h:192
struct dwarf2_section_info * section
Definition read.h:197
sect_offset sect_off
Definition read.h:120
unsigned int is_dwz
Definition read.h:135
dwarf2_per_bfd * per_bfd
Definition read.h:200
unsigned int length() const
Definition read.h:295
struct objfile * objfile
Definition read.h:724
unrelocated_addr adjust(unrelocated_addr addr)
Definition read.c:1208
struct dwarf2_per_bfd * per_bfd
Definition read.h:728
bool symtab_set_p(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1323
Definition dwz.h:32
gdb_bfd_ref_ptr dwz_bfd
Definition dwz.h:54
bool symbol_name_slot_invalid(offset_type idx) const override
gdb::array_view< const gdb_byte > address_table
quick_symbol_functions_up make_quick_functions() const override
offset_type symbol_vec_index(offset_type idx) const
gdb::array_view< const gdb_byte > constant_pool
const char * symbol_name_at(offset_type idx, dwarf2_per_objfile *per_objfile) const override
bool version_check() const override
size_t symbol_name_count() const override
offset_type symbol_name_index(offset_type idx) const
offset_view symbol_table
struct objfile_per_bfd_storage * per_bfd
Definition objfiles.h:744
search_domain
Definition symtab.h:945
@ VARIABLES_DOMAIN
Definition symtab.h:948
@ FUNCTIONS_DOMAIN
Definition symtab.h:951
@ TYPES_DOMAIN
Definition symtab.h:954
@ MODULES_DOMAIN
Definition symtab.h:957
domain_enum
Definition symtab.h:900
@ VAR_DOMAIN
Definition symtab.h:910
@ STRUCT_DOMAIN
Definition symtab.h:916
@ LABEL_DOMAIN
Definition symtab.h:924
@ MODULE_DOMAIN
Definition symtab.h:920
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
const char version[]
Definition version.c:2