/
read.c
24960 lines (21279 loc) · 763 KB
/
read.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* DWARF 2 debugging format support for GDB.
Copyright (C) 1994-2021 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
with the Ada Joint Program Office), and Silicon Graphics, Inc.
Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
based on Fred Fish's (Cygnus Support) implementation of DWARF 1
support.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* FIXME: Various die-reading functions need to be more careful with
reading off the end of the section.
E.g., load_partial_dies, read_partial_die. */
#include "defs.h"
#include "dwarf2/read.h"
#include "dwarf2/abbrev.h"
#include "dwarf2/attribute.h"
#include "dwarf2/comp-unit-head.h"
#include "dwarf2/cu.h"
#include "dwarf2/index-cache.h"
#include "dwarf2/index-common.h"
#include "dwarf2/leb.h"
#include "dwarf2/line-header.h"
#include "dwarf2/dwz.h"
#include "dwarf2/macro.h"
#include "dwarf2/die.h"
#include "dwarf2/sect-names.h"
#include "dwarf2/stringify.h"
#include "dwarf2/public.h"
#include "bfd.h"
#include "elf-bfd.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "objfiles.h"
#include "dwarf2.h"
#include "demangle.h"
#include "gdb-demangle.h"
#include "filenames.h" /* for DOSish file names */
#include "language.h"
#include "complaints.h"
#include "dwarf2/expr.h"
#include "dwarf2/loc.h"
#include "cp-support.h"
#include "hashtab.h"
#include "command.h"
#include "gdbcmd.h"
#include "block.h"
#include "addrmap.h"
#include "typeprint.h"
#include "psympriv.h"
#include "c-lang.h"
#include "go-lang.h"
#include "valprint.h"
#include "gdbcore.h" /* for gnutarget */
#include "gdb/gdb-index.h"
#include "gdb_bfd.h"
#include "f-lang.h"
#include "source.h"
#include "build-id.h"
#include "namespace.h"
#include "gdbsupport/function-view.h"
#include "gdbsupport/gdb_optional.h"
#include "gdbsupport/underlying.h"
#include "gdbsupport/hash_enum.h"
#include "filename-seen-cache.h"
#include "producer.h"
#include <fcntl.h>
#include <algorithm>
#include <unordered_map>
#include "gdbsupport/selftest.h"
#include "rust-lang.h"
#include "gdbsupport/pathstuff.h"
#include "count-one-bits.h"
#include <unordered_set>
/* When == 1, print basic high level tracing messages.
When > 1, be more verbose.
This is in contrast to the low level DIE reading of dwarf_die_debug. */
static unsigned int dwarf_read_debug = 0;
/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
#define dwarf_read_debug_printf(fmt, ...) \
debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
##__VA_ARGS__)
/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
#define dwarf_read_debug_printf_v(fmt, ...) \
debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
##__VA_ARGS__)
/* When non-zero, dump DIEs after they are read in. */
static unsigned int dwarf_die_debug = 0;
/* When non-zero, dump line number entries as they are read in. */
unsigned int dwarf_line_debug = 0;
/* When true, cross-check physname against demangler. */
static bool check_physname = false;
/* When true, do not reject deprecated .gdb_index sections. */
static bool use_deprecated_index_sections = false;
/* This is used to store the data that is always per objfile. */
static const objfile_key<dwarf2_per_objfile> dwarf2_objfile_data_key;
/* These are used to store the dwarf2_per_bfd objects.
objfiles having the same BFD, which doesn't require relocations, are going to
share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
Other objfiles are not going to share a dwarf2_per_bfd with any other
objfiles, so they'll have their own version kept in the _objfile_data_key
version. */
static const struct bfd_key<dwarf2_per_bfd> dwarf2_per_bfd_bfd_data_key;
static const struct objfile_key<dwarf2_per_bfd> dwarf2_per_bfd_objfile_data_key;
/* The "aclass" indices for various kinds of computed DWARF symbols. */
static int dwarf2_locexpr_index;
static int dwarf2_loclist_index;
static int dwarf2_locexpr_block_index;
static int dwarf2_loclist_block_index;
/* Size of .debug_loclists section header for 32-bit DWARF format. */
#define LOCLIST_HEADER_SIZE32 12
/* Size of .debug_loclists section header for 64-bit DWARF format. */
#define LOCLIST_HEADER_SIZE64 20
/* Size of .debug_rnglists section header for 32-bit DWARF format. */
#define RNGLIST_HEADER_SIZE32 12
/* Size of .debug_rnglists section header for 64-bit DWARF format. */
#define RNGLIST_HEADER_SIZE64 20
/* An index into a (C++) symbol name component in a symbol name as
recorded in the mapped_index's symbol table. For each C++ symbol
in the symbol table, we record one entry for the start of each
component in the symbol in a table of name components, and then
sort the table, in order to be able to binary search symbol names,
ignoring leading namespaces, both completion and regular look up.
For example, for symbol "A::B::C", we'll have an entry that points
to "A::B::C", another that points to "B::C", and another for "C".
Note that function symbols in GDB index have no parameter
information, just the function/method names. You can convert a
name_component to a "const char *" using the
'mapped_index::symbol_name_at(offset_type)' method. */
struct name_component
{
/* Offset in the symbol name where the component starts. Stored as
a (32-bit) offset instead of a pointer to save memory and improve
locality on 64-bit architectures. */
offset_type name_offset;
/* The symbol's index in the symbol and constant pool tables of a
mapped_index. */
offset_type idx;
};
/* Base class containing bits shared by both .gdb_index and
.debug_name indexes. */
struct mapped_index_base
{
mapped_index_base () = default;
DISABLE_COPY_AND_ASSIGN (mapped_index_base);
/* The name_component table (a sorted vector). See name_component's
description above. */
std::vector<name_component> name_components;
/* How NAME_COMPONENTS is sorted. */
enum case_sensitivity name_components_casing;
/* Return the number of names in the symbol table. */
virtual size_t symbol_name_count () const = 0;
/* Get the name of the symbol at IDX in the symbol table. */
virtual const char *symbol_name_at
(offset_type idx, dwarf2_per_objfile *per_objfile) const = 0;
/* Return whether the name at IDX in the symbol table should be
ignored. */
virtual bool symbol_name_slot_invalid (offset_type idx) const
{
return false;
}
/* Build the symbol name component sorted vector, if we haven't
yet. */
void build_name_components (dwarf2_per_objfile *per_objfile);
/* Returns the lower (inclusive) and upper (exclusive) bounds of the
possible matches for LN_NO_PARAMS in the name component
vector. */
std::pair<std::vector<name_component>::const_iterator,
std::vector<name_component>::const_iterator>
find_name_components_bounds (const lookup_name_info &ln_no_params,
enum language lang,
dwarf2_per_objfile *per_objfile) const;
/* Prevent deleting/destroying via a base class pointer. */
protected:
~mapped_index_base() = default;
};
/* This is a view into the index that converts from bytes to an
offset_type, and allows indexing. Unaligned bytes are specifically
allowed here, and handled via unpacking. */
class offset_view
{
public:
offset_view () = default;
explicit offset_view (gdb::array_view<const gdb_byte> bytes)
: m_bytes (bytes)
{
}
/* Extract the INDEXth offset_type from the array. */
offset_type operator[] (size_t index) const
{
const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)];
return (offset_type) extract_unsigned_integer (bytes,
sizeof (offset_type),
BFD_ENDIAN_LITTLE);
}
/* Return the number of offset_types in this array. */
size_t size () const
{
return m_bytes.size () / sizeof (offset_type);
}
/* Return true if this view is empty. */
bool empty () const
{
return m_bytes.empty ();
}
private:
/* The underlying bytes. */
gdb::array_view<const gdb_byte> m_bytes;
};
/* A description of the mapped index. The file format is described in
a comment by the code that writes the index. */
struct mapped_index final : public mapped_index_base
{
/* Index data format version. */
int version = 0;
/* The address table data. */
gdb::array_view<const gdb_byte> address_table;
/* The symbol table, implemented as a hash table. */
offset_view symbol_table;
/* A pointer to the constant pool. */
gdb::array_view<const gdb_byte> constant_pool;
/* Return the index into the constant pool of the name of the IDXth
symbol in the symbol table. */
offset_type symbol_name_index (offset_type idx) const
{
return symbol_table[2 * idx];
}
/* Return the index into the constant pool of the CU vector of the
IDXth symbol in the symbol table. */
offset_type symbol_vec_index (offset_type idx) const
{
return symbol_table[2 * idx + 1];
}
bool symbol_name_slot_invalid (offset_type idx) const override
{
return (symbol_name_index (idx) == 0
&& symbol_vec_index (idx) == 0);
}
/* Convenience method to get at the name of the symbol at IDX in the
symbol table. */
const char *symbol_name_at
(offset_type idx, dwarf2_per_objfile *per_objfile) const override
{
return (const char *) (this->constant_pool.data ()
+ symbol_name_index (idx));
}
size_t symbol_name_count () const override
{ return this->symbol_table.size () / 2; }
};
/* A description of the mapped .debug_names.
Uninitialized map has CU_COUNT 0. */
struct mapped_debug_names final : public mapped_index_base
{
bfd_endian dwarf5_byte_order;
bool dwarf5_is_dwarf64;
bool augmentation_is_gdb;
uint8_t offset_size;
uint32_t cu_count = 0;
uint32_t tu_count, bucket_count, name_count;
const gdb_byte *cu_table_reordered, *tu_table_reordered;
const uint32_t *bucket_table_reordered, *hash_table_reordered;
const gdb_byte *name_table_string_offs_reordered;
const gdb_byte *name_table_entry_offs_reordered;
const gdb_byte *entry_pool;
struct index_val
{
ULONGEST dwarf_tag;
struct attr
{
/* Attribute name DW_IDX_*. */
ULONGEST dw_idx;
/* Attribute form DW_FORM_*. */
ULONGEST form;
/* Value if FORM is DW_FORM_implicit_const. */
LONGEST implicit_const;
};
std::vector<attr> attr_vec;
};
std::unordered_map<ULONGEST, index_val> abbrev_map;
const char *namei_to_name
(uint32_t namei, dwarf2_per_objfile *per_objfile) const;
/* Implementation of the mapped_index_base virtual interface, for
the name_components cache. */
const char *symbol_name_at
(offset_type idx, dwarf2_per_objfile *per_objfile) const override
{ return namei_to_name (idx, per_objfile); }
size_t symbol_name_count () const override
{ return this->name_count; }
};
/* See dwarf2read.h. */
dwarf2_per_objfile *
get_dwarf2_per_objfile (struct objfile *objfile)
{
return dwarf2_objfile_data_key.get (objfile);
}
/* Default names of the debugging sections. */
/* Note that if the debugging section has been compressed, it might
have a name like .zdebug_info. */
const struct dwarf2_debug_sections dwarf2_elf_names =
{
{ ".debug_info", ".zdebug_info" },
{ ".debug_abbrev", ".zdebug_abbrev" },
{ ".debug_line", ".zdebug_line" },
{ ".debug_loc", ".zdebug_loc" },
{ ".debug_loclists", ".zdebug_loclists" },
{ ".debug_macinfo", ".zdebug_macinfo" },
{ ".debug_macro", ".zdebug_macro" },
{ ".debug_str", ".zdebug_str" },
{ ".debug_str_offsets", ".zdebug_str_offsets" },
{ ".debug_line_str", ".zdebug_line_str" },
{ ".debug_ranges", ".zdebug_ranges" },
{ ".debug_rnglists", ".zdebug_rnglists" },
{ ".debug_types", ".zdebug_types" },
{ ".debug_addr", ".zdebug_addr" },
{ ".debug_frame", ".zdebug_frame" },
{ ".eh_frame", NULL },
{ ".gdb_index", ".zgdb_index" },
{ ".debug_names", ".zdebug_names" },
{ ".debug_aranges", ".zdebug_aranges" },
23
};
/* List of DWO/DWP sections. */
static const struct dwop_section_names
{
struct dwarf2_section_names abbrev_dwo;
struct dwarf2_section_names info_dwo;
struct dwarf2_section_names line_dwo;
struct dwarf2_section_names loc_dwo;
struct dwarf2_section_names loclists_dwo;
struct dwarf2_section_names macinfo_dwo;
struct dwarf2_section_names macro_dwo;
struct dwarf2_section_names rnglists_dwo;
struct dwarf2_section_names str_dwo;
struct dwarf2_section_names str_offsets_dwo;
struct dwarf2_section_names types_dwo;
struct dwarf2_section_names cu_index;
struct dwarf2_section_names tu_index;
}
dwop_section_names =
{
{ ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
{ ".debug_info.dwo", ".zdebug_info.dwo" },
{ ".debug_line.dwo", ".zdebug_line.dwo" },
{ ".debug_loc.dwo", ".zdebug_loc.dwo" },
{ ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
{ ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
{ ".debug_macro.dwo", ".zdebug_macro.dwo" },
{ ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
{ ".debug_str.dwo", ".zdebug_str.dwo" },
{ ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
{ ".debug_types.dwo", ".zdebug_types.dwo" },
{ ".debug_cu_index", ".zdebug_cu_index" },
{ ".debug_tu_index", ".zdebug_tu_index" },
};
/* local data types */
/* The location list and range list sections (.debug_loclists & .debug_rnglists)
begin with a header, which contains the following information. */
struct loclists_rnglists_header
{
/* A 4-byte or 12-byte length containing the length of the
set of entries for this compilation unit, not including the
length field itself. */
unsigned int length;
/* A 2-byte version identifier. */
short version;
/* A 1-byte unsigned integer containing the size in bytes of an address on
the target system. */
unsigned char addr_size;
/* A 1-byte unsigned integer containing the size in bytes of a segment selector
on the target system. */
unsigned char segment_collector_size;
/* A 4-byte count of the number of offsets that follow the header. */
unsigned int offset_entry_count;
};
/* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
This includes type_unit_group and quick_file_names. */
struct stmt_list_hash
{
/* The DWO unit this table is from or NULL if there is none. */
struct dwo_unit *dwo_unit;
/* Offset in .debug_line or .debug_line.dwo. */
sect_offset line_sect_off;
};
/* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
an object of this type. This contains elements of type unit groups
that can be shared across objfiles. The non-shareable parts are in
type_unit_group_unshareable. */
struct type_unit_group : public dwarf2_per_cu_data
{
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
std::vector<signatured_type *> *tus = nullptr;
/* The data used to construct the hash key. */
struct stmt_list_hash hash {};
};
/* These sections are what may appear in a (real or virtual) DWO file. */
struct dwo_sections
{
struct dwarf2_section_info abbrev;
struct dwarf2_section_info line;
struct dwarf2_section_info loc;
struct dwarf2_section_info loclists;
struct dwarf2_section_info macinfo;
struct dwarf2_section_info macro;
struct dwarf2_section_info rnglists;
struct dwarf2_section_info str;
struct dwarf2_section_info str_offsets;
/* In the case of a virtual DWO file, these two are unused. */
struct dwarf2_section_info info;
std::vector<dwarf2_section_info> types;
};
/* CUs/TUs in DWP/DWO files. */
struct dwo_unit
{
/* Backlink to the containing struct dwo_file. */
struct dwo_file *dwo_file;
/* The "id" that distinguishes this CU/TU.
.debug_info calls this "dwo_id", .debug_types calls this "signature".
Since signatures came first, we stick with it for consistency. */
ULONGEST signature;
/* The section this CU/TU lives in, in the DWO file. */
struct dwarf2_section_info *section;
/* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
sect_offset sect_off;
unsigned int length;
/* For types, offset in the type's DIE of the type defined by this TU. */
cu_offset type_offset_in_tu;
};
/* include/dwarf2.h defines the DWP section codes.
It defines a max value but it doesn't define a min value, which we
use for error checking, so provide one. */
enum dwp_v2_section_ids
{
DW_SECT_MIN = 1
};
/* Data for one DWO file.
This includes virtual DWO files (a virtual DWO file is a DWO file as it
appears in a DWP file). DWP files don't really have DWO files per se -
comdat folding of types "loses" the DWO file they came from, and from
a high level view DWP files appear to contain a mass of random types.
However, to maintain consistency with the non-DWP case we pretend DWP
files contain virtual DWO files, and we assign each TU with one virtual
DWO file (generally based on the line and abbrev section offsets -
a heuristic that seems to work in practice). */
struct dwo_file
{
dwo_file () = default;
DISABLE_COPY_AND_ASSIGN (dwo_file);
/* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
For virtual DWO files the name is constructed from the section offsets
of abbrev,line,loc,str_offsets so that we combine virtual DWO files
from related CU+TUs. */
const char *dwo_name = nullptr;
/* The DW_AT_comp_dir attribute. */
const char *comp_dir = nullptr;
/* The bfd, when the file is open. Otherwise this is NULL.
This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
gdb_bfd_ref_ptr dbfd;
/* The sections that make up this DWO file.
Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
sections (for lack of a better name). */
struct dwo_sections sections {};
/* The CUs in the file.
Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
an extension to handle LLVM's Link Time Optimization output (where
multiple source files may be compiled into a single object/dwo pair). */
htab_up cus;
/* Table of TUs in the file.
Each element is a struct dwo_unit. */
htab_up tus;
};
/* These sections are what may appear in a DWP file. */
struct dwp_sections
{
/* These are used by all DWP versions (1, 2 and 5). */
struct dwarf2_section_info str;
struct dwarf2_section_info cu_index;
struct dwarf2_section_info tu_index;
/* These are only used by DWP version 2 and version 5 files.
In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
sections are referenced by section number, and are not recorded here.
In DWP version 2 or 5 there is at most one copy of all these sections,
each section being (effectively) comprised of the concatenation of all of
the individual sections that exist in the version 1 format.
To keep the code simple we treat each of these concatenated pieces as a
section itself (a virtual section?). */
struct dwarf2_section_info abbrev;
struct dwarf2_section_info info;
struct dwarf2_section_info line;
struct dwarf2_section_info loc;
struct dwarf2_section_info loclists;
struct dwarf2_section_info macinfo;
struct dwarf2_section_info macro;
struct dwarf2_section_info rnglists;
struct dwarf2_section_info str_offsets;
struct dwarf2_section_info types;
};
/* These sections are what may appear in a virtual DWO file in DWP version 1.
A virtual DWO file is a DWO file as it appears in a DWP file. */
struct virtual_v1_dwo_sections
{
struct dwarf2_section_info abbrev;
struct dwarf2_section_info line;
struct dwarf2_section_info loc;
struct dwarf2_section_info macinfo;
struct dwarf2_section_info macro;
struct dwarf2_section_info str_offsets;
/* Each DWP hash table entry records one CU or one TU.
That is recorded here, and copied to dwo_unit.section. */
struct dwarf2_section_info info_or_types;
};
/* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
In version 2, the sections of the DWO files are concatenated together
and stored in one section of that name. Thus each ELF section contains
several "virtual" sections. */
struct virtual_v2_or_v5_dwo_sections
{
bfd_size_type abbrev_offset;
bfd_size_type abbrev_size;
bfd_size_type line_offset;
bfd_size_type line_size;
bfd_size_type loc_offset;
bfd_size_type loc_size;
bfd_size_type loclists_offset;
bfd_size_type loclists_size;
bfd_size_type macinfo_offset;
bfd_size_type macinfo_size;
bfd_size_type macro_offset;
bfd_size_type macro_size;
bfd_size_type rnglists_offset;
bfd_size_type rnglists_size;
bfd_size_type str_offsets_offset;
bfd_size_type str_offsets_size;
/* Each DWP hash table entry records one CU or one TU.
That is recorded here, and copied to dwo_unit.section. */
bfd_size_type info_or_types_offset;
bfd_size_type info_or_types_size;
};
/* Contents of DWP hash tables. */
struct dwp_hash_table
{
uint32_t version, nr_columns;
uint32_t nr_units, nr_slots;
const gdb_byte *hash_table, *unit_table;
union
{
struct
{
const gdb_byte *indices;
} v1;
struct
{
/* This is indexed by column number and gives the id of the section
in that column. */
#define MAX_NR_V2_DWO_SECTIONS \
(1 /* .debug_info or .debug_types */ \
+ 1 /* .debug_abbrev */ \
+ 1 /* .debug_line */ \
+ 1 /* .debug_loc */ \
+ 1 /* .debug_str_offsets */ \
+ 1 /* .debug_macro or .debug_macinfo */)
int section_ids[MAX_NR_V2_DWO_SECTIONS];
const gdb_byte *offsets;
const gdb_byte *sizes;
} v2;
struct
{
/* This is indexed by column number and gives the id of the section
in that column. */
#define MAX_NR_V5_DWO_SECTIONS \
(1 /* .debug_info */ \
+ 1 /* .debug_abbrev */ \
+ 1 /* .debug_line */ \
+ 1 /* .debug_loclists */ \
+ 1 /* .debug_str_offsets */ \
+ 1 /* .debug_macro */ \
+ 1 /* .debug_rnglists */)
int section_ids[MAX_NR_V5_DWO_SECTIONS];
const gdb_byte *offsets;
const gdb_byte *sizes;
} v5;
} section_pool;
};
/* Data for one DWP file. */
struct dwp_file
{
dwp_file (const char *name_, gdb_bfd_ref_ptr &&abfd)
: name (name_),
dbfd (std::move (abfd))
{
}
/* Name of the file. */
const char *name;
/* File format version. */
int version = 0;
/* The bfd. */
gdb_bfd_ref_ptr dbfd;
/* Section info for this file. */
struct dwp_sections sections {};
/* Table of CUs in the file. */
const struct dwp_hash_table *cus = nullptr;
/* Table of TUs in the file. */
const struct dwp_hash_table *tus = nullptr;
/* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
htab_up loaded_cus;
htab_up loaded_tus;
/* Table to map ELF section numbers to their sections.
This is only needed for the DWP V1 file format. */
unsigned int num_sections = 0;
asection **elf_sections = nullptr;
};
/* Struct used to pass misc. parameters to read_die_and_children, et
al. which are used for both .debug_info and .debug_types dies.
All parameters here are unchanging for the life of the call. This
struct exists to abstract away the constant parameters of die reading. */
struct die_reader_specs
{
/* The bfd of die_section. */
bfd *abfd;
/* The CU of the DIE we are parsing. */
struct dwarf2_cu *cu;
/* Non-NULL if reading a DWO file (including one packaged into a DWP). */
struct dwo_file *dwo_file;
/* The section the die comes from.
This is either .debug_info or .debug_types, or the .dwo variants. */
struct dwarf2_section_info *die_section;
/* die_section->buffer. */
const gdb_byte *buffer;
/* The end of the buffer. */
const gdb_byte *buffer_end;
/* The abbreviation table to use when reading the DIEs. */
struct abbrev_table *abbrev_table;
};
/* A subclass of die_reader_specs that holds storage and has complex
constructor and destructor behavior. */
class cutu_reader : public die_reader_specs
{
public:
cutu_reader (dwarf2_per_cu_data *this_cu,
dwarf2_per_objfile *per_objfile,
struct abbrev_table *abbrev_table,
dwarf2_cu *existing_cu,
bool skip_partial);
explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
dwarf2_per_objfile *per_objfile,
struct dwarf2_cu *parent_cu = nullptr,
struct dwo_file *dwo_file = nullptr);
DISABLE_COPY_AND_ASSIGN (cutu_reader);
const gdb_byte *info_ptr = nullptr;
struct die_info *comp_unit_die = nullptr;
bool dummy_p = false;
/* Release the new CU, putting it on the chain. This cannot be done
for dummy CUs. */
void keep ();
private:
void init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
dwarf2_per_objfile *per_objfile,
dwarf2_cu *existing_cu);
struct dwarf2_per_cu_data *m_this_cu;
std::unique_ptr<dwarf2_cu> m_new_cu;
/* The ordinary abbreviation table. */
abbrev_table_up m_abbrev_table_holder;
/* The DWO abbreviation table. */
abbrev_table_up m_dwo_abbrev_table;
};
/* When we construct a partial symbol table entry we only
need this much information. */
struct partial_die_info : public allocate_on_obstack
{
partial_die_info (sect_offset sect_off, const struct abbrev_info *abbrev);
/* Disable assign but still keep copy ctor, which is needed
load_partial_dies. */
partial_die_info& operator=(const partial_die_info& rhs) = delete;
partial_die_info (const partial_die_info &) = default;
/* Adjust the partial die before generating a symbol for it. This
function may set the is_external flag or change the DIE's
name. */
void fixup (struct dwarf2_cu *cu);
/* Read a minimal amount of information into the minimal die
structure. */
const gdb_byte *read (const struct die_reader_specs *reader,
const struct abbrev_info &abbrev,
const gdb_byte *info_ptr);
/* Compute the name of this partial DIE. This memoizes the
result, so it is safe to call multiple times. */
const char *name (dwarf2_cu *cu);
/* Offset of this DIE. */
const sect_offset sect_off;
/* DWARF-2 tag for this DIE. */
const ENUM_BITFIELD(dwarf_tag) tag : 16;
/* Assorted flags describing the data found in this DIE. */
const unsigned int has_children : 1;
unsigned int is_external : 1;
unsigned int is_declaration : 1;
unsigned int has_type : 1;
unsigned int has_specification : 1;
unsigned int has_pc_info : 1;
unsigned int has_range_info : 1;
unsigned int may_be_inlined : 1;
/* This DIE has been marked DW_AT_main_subprogram. */
unsigned int main_subprogram : 1;
/* Flag set if the SCOPE field of this structure has been
computed. */
unsigned int scope_set : 1;
/* Flag set if the DIE has a byte_size attribute. */
unsigned int has_byte_size : 1;
/* Flag set if the DIE has a DW_AT_const_value attribute. */
unsigned int has_const_value : 1;
/* Flag set if any of the DIE's children are template arguments. */
unsigned int has_template_arguments : 1;
/* Flag set if fixup has been called on this die. */
unsigned int fixup_called : 1;
/* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
unsigned int is_dwz : 1;
/* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
unsigned int spec_is_dwz : 1;
unsigned int canonical_name : 1;
/* The name of this DIE. Normally the value of DW_AT_name, but
sometimes a default name for unnamed DIEs. */
const char *raw_name = nullptr;
/* The linkage name, if present. */
const char *linkage_name = nullptr;
/* The scope to prepend to our children. This is generally
allocated on the comp_unit_obstack, so will disappear
when this compilation unit leaves the cache. */
const char *scope = nullptr;
/* Some data associated with the partial DIE. The tag determines
which field is live. */
union
{
/* The location description associated with this DIE, if any. */
struct dwarf_block *locdesc;
/* The offset of an import, for DW_TAG_imported_unit. */
sect_offset sect_off;
} d {};
union
{
/* If HAS_PC_INFO, the PC range associated with this DIE. */
struct
{
CORE_ADDR lowpc;
CORE_ADDR highpc;
};
/* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
ULONGEST ranges_offset;
};
/* Pointer into the info_buffer (or types_buffer) pointing at the target of
DW_AT_sibling, if any. */
/* NOTE: This member isn't strictly necessary, partial_die_info::read
could return DW_AT_sibling values to its caller load_partial_dies. */
const gdb_byte *sibling = nullptr;
/* If HAS_SPECIFICATION, the offset of the DIE referred to by
DW_AT_specification (or DW_AT_abstract_origin or
DW_AT_extension). */
sect_offset spec_offset {};
/* Pointers to this DIE's parent, first child, and next sibling,
if any. */
struct partial_die_info *die_parent = nullptr;
struct partial_die_info *die_child = nullptr;
struct partial_die_info *die_sibling = nullptr;
friend struct partial_die_info *
dwarf2_cu::find_partial_die (sect_offset sect_off);
private:
/* Only need to do look up in dwarf2_cu::find_partial_die. */
partial_die_info (sect_offset sect_off)
: partial_die_info (sect_off, DW_TAG_padding, 0)
{
}
partial_die_info (sect_offset sect_off_, enum dwarf_tag tag_,
int has_children_)
: sect_off (sect_off_), tag (tag_), has_children (has_children_)
{
is_external = 0;
is_declaration = 0;
has_type = 0;
has_specification = 0;
has_pc_info = 0;
has_range_info = 0;
may_be_inlined = 0;
main_subprogram = 0;
scope_set = 0;
has_byte_size = 0;
has_const_value = 0;
has_template_arguments = 0;
fixup_called = 0;
is_dwz = 0;
spec_is_dwz = 0;
canonical_name = 0;
/* Don't set these using NSDMI (Non-static data member initialisation),
because g++-4.8 will error out. */
lowpc = 0;
highpc = 0;
}
};
/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
but this would require a corresponding change in unpack_field_as_long
and friends. */
static int bits_per_byte = 8;
struct variant_part_builder;
/* When reading a variant, we track a bit more information about the
field, and store it in an object of this type. */
struct variant_field
{
int first_field = -1;
int last_field = -1;
/* A variant can contain other variant parts. */
std::vector<variant_part_builder> variant_parts;