| 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 "dwarf2/leb.h" |
| 31 | #include "gdbtypes.h" |
| 32 | |
| 33 | /* The data in a compilation unit header, after target2host |
| 34 | translation, looks like this. */ |
| 35 | struct comp_unit_head |
| 36 | { |
| 37 | unsigned int length; |
| 38 | short version; |
| 39 | unsigned char addr_size; |
| 40 | unsigned char signed_addr_p; |
| 41 | sect_offset abbrev_sect_off; |
| 42 | |
| 43 | /* Size of file offsets; either 4 or 8. */ |
| 44 | unsigned int offset_size; |
| 45 | |
| 46 | /* Size of the length field; either 4 or 12. */ |
| 47 | unsigned int initial_length_size; |
| 48 | |
| 49 | enum dwarf_unit_type unit_type; |
| 50 | |
| 51 | /* Offset to the first byte of this compilation unit header in the |
| 52 | .debug_info section, for resolving relative reference dies. */ |
| 53 | sect_offset sect_off; |
| 54 | |
| 55 | /* Offset to first die in this cu from the start of the cu. |
| 56 | This will be the first byte following the compilation unit header. */ |
| 57 | cu_offset first_die_cu_offset; |
| 58 | |
| 59 | |
| 60 | /* 64-bit signature of this unit. For type units, it denotes the signature of |
| 61 | the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5). |
| 62 | Also used in DWARF 5, to denote the dwo id when the unit type is |
| 63 | DW_UT_skeleton or DW_UT_split_compile. */ |
| 64 | ULONGEST signature; |
| 65 | |
| 66 | /* For types, offset in the type's DIE of the type defined by this TU. */ |
| 67 | cu_offset type_cu_offset_in_tu; |
| 68 | |
| 69 | /* Return the total length of the CU described by this header. */ |
| 70 | unsigned int get_length () const |
| 71 | { |
| 72 | return initial_length_size + length; |
| 73 | } |
| 74 | |
| 75 | /* Return TRUE if OFF is within this CU. */ |
| 76 | bool offset_in_cu_p (sect_offset off) const |
| 77 | { |
| 78 | sect_offset bottom = sect_off; |
| 79 | sect_offset top = sect_off + get_length (); |
| 80 | return off >= bottom && off < top; |
| 81 | } |
| 82 | |
| 83 | /* Read an offset from the data stream. The size of the offset is |
| 84 | given by cu_header->offset_size. */ |
| 85 | LONGEST read_offset (bfd *abfd, const gdb_byte *buf, |
| 86 | unsigned int *bytes_read) const |
| 87 | { |
| 88 | LONGEST offset = ::read_offset (abfd, buf, offset_size); |
| 89 | *bytes_read = offset_size; |
| 90 | return offset; |
| 91 | } |
| 92 | |
| 93 | /* Read an address from BUF. BYTES_READ is updated. */ |
| 94 | CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf, |
| 95 | unsigned int *bytes_read) const; |
| 96 | }; |
| 97 | |
| 98 | /* Expected enum dwarf_unit_type for read_comp_unit_head. */ |
| 99 | enum class rcuh_kind { COMPILE, TYPE }; |
| 100 | |
| 101 | /* Read in the comp unit header information from the debug_info at info_ptr. |
| 102 | Use rcuh_kind::COMPILE as the default type if not known by the caller. |
| 103 | NOTE: This leaves members offset, first_die_offset to be filled in |
| 104 | by the caller. */ |
| 105 | extern const gdb_byte *read_comp_unit_head |
| 106 | (struct comp_unit_head *cu_header, |
| 107 | const gdb_byte *info_ptr, |
| 108 | struct dwarf2_section_info *section, |
| 109 | rcuh_kind section_kind); |
| 110 | |
| 111 | /* Read in a CU/TU header and perform some basic error checking. |
| 112 | The contents of the header are stored in HEADER. |
| 113 | The result is a pointer to the start of the first DIE. */ |
| 114 | extern const gdb_byte *read_and_check_comp_unit_head |
| 115 | (dwarf2_per_objfile *per_objfile, |
| 116 | struct comp_unit_head *header, |
| 117 | struct dwarf2_section_info *section, |
| 118 | struct dwarf2_section_info *abbrev_section, |
| 119 | const gdb_byte *info_ptr, |
| 120 | rcuh_kind section_kind); |
| 121 | |
| 122 | #endif /* GDB_DWARF2_COMP_UNIT_H */ |