1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2022 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/>. */
20 #ifndef DWARF2_LINE_HEADER_H
21 #define DWARF2_LINE_HEADER_H
25 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
27 typedef int dir_index
;
29 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
31 typedef int file_name_index
;
37 file_entry () = default;
39 file_entry (const char *name_
, dir_index d_index_
,
40 unsigned int mod_time_
, unsigned int length_
)
47 /* Return the include directory at D_INDEX stored in LH. Returns
48 NULL if D_INDEX is out of bounds. */
49 const char *include_dir (const line_header
*lh
) const;
51 /* The file name. Note this is an observing pointer. The memory is
52 owned by debug_line_buffer. */
55 /* The directory index (1-based). */
58 unsigned int mod_time
{};
60 unsigned int length
{};
62 /* The associated symbol table, if any. */
63 struct symtab
*symtab
{};
66 /* The line number information for a compilation unit (found in the
67 .debug_line section) begins with a "statement program header",
68 which contains the following information. */
75 /* Add an entry to the include directory table. */
76 void add_include_dir (const char *include_dir
);
78 /* Add an entry to the file name table. */
79 void add_file_name (const char *name
, dir_index d_index
,
80 unsigned int mod_time
, unsigned int length
);
82 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
83 Returns NULL if INDEX is out of bounds. */
84 const char *include_dir_at (dir_index index
) const
90 vec_index
= index
- 1;
91 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
93 return m_include_dirs
[vec_index
];
96 bool is_valid_file_index (int file_index
) const
99 return 0 <= file_index
&& file_index
< file_names_size ();
100 return 1 <= file_index
&& file_index
<= file_names_size ();
103 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
104 Returns NULL if INDEX is out of bounds. */
105 file_entry
*file_name_at (file_name_index index
)
111 vec_index
= index
- 1;
112 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
114 return &m_file_names
[vec_index
];
117 /* A const overload of the same. */
118 const file_entry
*file_name_at (file_name_index index
) const
120 line_header
*lh
= const_cast<line_header
*> (this);
121 return lh
->file_name_at (index
);
124 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
125 this method should only be used to iterate through all file entries in an
126 index-agnostic manner. */
127 std::vector
<file_entry
> &file_names ()
128 { return m_file_names
; }
129 /* A const overload of the same. */
130 const std::vector
<file_entry
> &file_names () const
131 { return m_file_names
; }
133 /* Offset of line number information in .debug_line section. */
134 sect_offset sect_off
{};
136 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
137 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
139 unsigned short version
{};
140 unsigned char minimum_instruction_length
{};
141 unsigned char maximum_ops_per_instruction
{};
142 unsigned char default_is_stmt
{};
144 unsigned char line_range
{};
145 unsigned char opcode_base
{};
147 /* standard_opcode_lengths[i] is the number of operands for the
148 standard opcode whose value is i. This means that
149 standard_opcode_lengths[0] is unused, and the last meaningful
150 element is standard_opcode_lengths[opcode_base - 1]. */
151 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
153 int file_names_size () const
154 { return m_file_names
.size(); }
156 /* The start and end of the statement program following this
157 header. These point into dwarf2_per_objfile->line_buffer. */
158 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
160 /* Return file name relative to the compilation directory of file
161 number FILE in this object's file name table. */
162 std::string
file_file_name (int file
) const;
165 /* The include_directories table. Note these are observing
166 pointers. The memory is owned by debug_line_buffer. */
167 std::vector
<const char *> m_include_dirs
;
169 /* The file_names table. This is private because the meaning of indexes
170 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
171 before, and is 0 in DWARF 5 and later). So the client should use
172 file_name_at method for access. */
173 std::vector
<file_entry
> m_file_names
;
176 typedef std::unique_ptr
<line_header
> line_header_up
;
179 file_entry::include_dir (const line_header
*lh
) const
181 return lh
->include_dir_at (d_index
);
184 /* Read the statement program header starting at SECT_OFF in SECTION.
185 Return line_header. Returns nullptr if there is a problem reading
186 the header, e.g., if it has a version we don't understand.
188 NOTE: the strings in the include directory and file name tables of
189 the returned object point into the dwarf line section buffer,
190 and must not be freed. */
192 extern line_header_up dwarf_decode_line_header
193 (sect_offset sect_off
, bool is_dwz
, dwarf2_per_objfile
*per_objfile
,
194 struct dwarf2_section_info
*section
, const struct comp_unit_head
*cu_header
);
196 #endif /* DWARF2_LINE_HEADER_H */