Create dwarf2/comp-unit.[ch]
[deliverable/binutils-gdb.git] / gdb / dwarf2 / comp-unit.h
1 /* Low-level DWARF 2 reading code
2
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
4
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support.
11
12 This file is part of GDB.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26
27 #ifndef GDB_DWARF2_COMP_UNIT_H
28 #define GDB_DWARF2_COMP_UNIT_H
29
30 #include "gdbtypes.h"
31
32 /* The data in a compilation unit header, after target2host
33 translation, looks like this. */
34 struct comp_unit_head
35 {
36 unsigned int length;
37 short version;
38 unsigned char addr_size;
39 unsigned char signed_addr_p;
40 sect_offset abbrev_sect_off;
41
42 /* Size of file offsets; either 4 or 8. */
43 unsigned int offset_size;
44
45 /* Size of the length field; either 4 or 12. */
46 unsigned int initial_length_size;
47
48 enum dwarf_unit_type unit_type;
49
50 /* Offset to the first byte of this compilation unit header in the
51 .debug_info section, for resolving relative reference dies. */
52 sect_offset sect_off;
53
54 /* Offset to first die in this cu from the start of the cu.
55 This will be the first byte following the compilation unit header. */
56 cu_offset first_die_cu_offset;
57
58
59 /* 64-bit signature of this unit. For type units, it denotes the signature of
60 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
61 Also used in DWARF 5, to denote the dwo id when the unit type is
62 DW_UT_skeleton or DW_UT_split_compile. */
63 ULONGEST signature;
64
65 /* For types, offset in the type's DIE of the type defined by this TU. */
66 cu_offset type_cu_offset_in_tu;
67
68 /* Return the total length of the CU described by this header. */
69 unsigned int get_length () const
70 {
71 return initial_length_size + length;
72 }
73
74 /* Return TRUE if OFF is within this CU. */
75 bool offset_in_cu_p (sect_offset off) const
76 {
77 sect_offset bottom = sect_off;
78 sect_offset top = sect_off + get_length ();
79 return off >= bottom && off < top;
80 }
81 };
82
83 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
84 enum class rcuh_kind { COMPILE, TYPE };
85
86 /* Read in the comp unit header information from the debug_info at info_ptr.
87 Use rcuh_kind::COMPILE as the default type if not known by the caller.
88 NOTE: This leaves members offset, first_die_offset to be filled in
89 by the caller. */
90 extern const gdb_byte *read_comp_unit_head
91 (struct comp_unit_head *cu_header,
92 const gdb_byte *info_ptr,
93 struct dwarf2_section_info *section,
94 rcuh_kind section_kind);
95
96 /* Read in a CU/TU header and perform some basic error checking.
97 The contents of the header are stored in HEADER.
98 The result is a pointer to the start of the first DIE. */
99 extern const gdb_byte *read_and_check_comp_unit_head
100 (struct dwarf2_per_objfile *dwarf2_per_objfile,
101 struct comp_unit_head *header,
102 struct dwarf2_section_info *section,
103 struct dwarf2_section_info *abbrev_section,
104 const gdb_byte *info_ptr,
105 rcuh_kind section_kind);
106
107 /* Read an offset from the data stream. The size of the offset is
108 given by cu_header->offset_size. */
109
110 extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
111 const struct comp_unit_head *cu_header,
112 unsigned int *bytes_read);
113
114 #endif /* GDB_DWARF2_COMP_UNIT_H */
This page took 0.033031 seconds and 5 git commands to generate.