]> git.proxmox.com Git - rustc.git/blob - vendor/gimli-0.23.0/src/common.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / vendor / gimli-0.23.0 / src / common.rs
1 /// Whether the format of a compilation unit is 32- or 64-bit.
2 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3 pub enum Format {
4 /// 64-bit DWARF
5 Dwarf64 = 8,
6 /// 32-bit DWARF
7 Dwarf32 = 4,
8 }
9
10 impl Format {
11 /// Return the serialized size of an initial length field for the format.
12 #[inline]
13 pub fn initial_length_size(self) -> u8 {
14 match self {
15 Format::Dwarf32 => 4,
16 Format::Dwarf64 => 12,
17 }
18 }
19
20 /// Return the natural word size for the format
21 #[inline]
22 pub fn word_size(self) -> u8 {
23 match self {
24 Format::Dwarf32 => 4,
25 Format::Dwarf64 => 8,
26 }
27 }
28 }
29
30 /// Encoding parameters that are commonly used for multiple DWARF sections.
31 ///
32 /// This is intended to be small enough to pass by value.
33 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
34 // `address_size` and `format` are used more often than `version`, so keep
35 // them first.
36 #[repr(C)]
37 pub struct Encoding {
38 /// The size of an address.
39 pub address_size: u8,
40
41 // The size of a segment selector.
42 // TODO: pub segment_size: u8,
43 /// Whether the DWARF format is 32- or 64-bit.
44 pub format: Format,
45
46 /// The DWARF version of the header.
47 pub version: u16,
48 }
49
50 /// Encoding parameters for a line number program.
51 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52 pub struct LineEncoding {
53 /// The size in bytes of the smallest target machine instruction.
54 pub minimum_instruction_length: u8,
55
56 /// The maximum number of individual operations that may be encoded in an
57 /// instruction.
58 pub maximum_operations_per_instruction: u8,
59
60 /// The initial value of the `is_stmt` register.
61 pub default_is_stmt: bool,
62
63 /// The minimum value which a special opcode can add to the line register.
64 pub line_base: i8,
65
66 /// The range of values which a special opcode can add to the line register.
67 pub line_range: u8,
68 }
69
70 impl Default for LineEncoding {
71 fn default() -> Self {
72 // Values from LLVM.
73 LineEncoding {
74 minimum_instruction_length: 1,
75 maximum_operations_per_instruction: 1,
76 default_is_stmt: true,
77 line_base: -5,
78 line_range: 14,
79 }
80 }
81 }
82
83 /// A DWARF register number.
84 ///
85 /// The meaning of this value is ABI dependent. This is generally encoded as
86 /// a ULEB128, but supported architectures need 16 bits at most.
87 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
88 pub struct Register(pub u16);
89
90 /// An offset into the `.debug_abbrev` section.
91 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92 pub struct DebugAbbrevOffset<T = usize>(pub T);
93
94 /// An offset to a set of entries in the `.debug_addr` section.
95 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
96 pub struct DebugAddrBase<T = usize>(pub T);
97
98 /// An index into a set of addresses in the `.debug_addr` section.
99 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
100 pub struct DebugAddrIndex<T = usize>(pub T);
101
102 /// An offset into the `.debug_info` section.
103 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
104 pub struct DebugInfoOffset<T = usize>(pub T);
105
106 /// An offset into the `.debug_line` section.
107 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
108 pub struct DebugLineOffset<T = usize>(pub T);
109
110 /// An offset into the `.debug_line_str` section.
111 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
112 pub struct DebugLineStrOffset<T = usize>(pub T);
113
114 /// An offset into either the `.debug_loc` section or the `.debug_loclists` section,
115 /// depending on the version of the unit the offset was contained in.
116 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
117 pub struct LocationListsOffset<T = usize>(pub T);
118
119 /// An offset to a set of location list offsets in the `.debug_loclists` section.
120 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
121 pub struct DebugLocListsBase<T = usize>(pub T);
122
123 /// An index into a set of location list offsets in the `.debug_loclists` section.
124 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
125 pub struct DebugLocListsIndex<T = usize>(pub T);
126
127 /// An offset into the `.debug_macinfo` section.
128 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
129 pub struct DebugMacinfoOffset<T = usize>(pub T);
130
131 /// An offset into the `.debug_macro` section.
132 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133 pub struct DebugMacroOffset<T = usize>(pub T);
134
135 /// An offset into either the `.debug_ranges` section or the `.debug_rnglists` section,
136 /// depending on the version of the unit the offset was contained in.
137 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
138 pub struct RangeListsOffset<T = usize>(pub T);
139
140 /// An offset to a set of range list offsets in the `.debug_rnglists` section.
141 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
142 pub struct DebugRngListsBase<T = usize>(pub T);
143
144 /// An index into a set of range list offsets in the `.debug_rnglists` section.
145 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
146 pub struct DebugRngListsIndex<T = usize>(pub T);
147
148 /// An offset into the `.debug_str` section.
149 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
150 pub struct DebugStrOffset<T = usize>(pub T);
151
152 /// An offset to a set of entries in the `.debug_str_offsets` section.
153 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
154 pub struct DebugStrOffsetsBase<T = usize>(pub T);
155
156 /// An index into a set of entries in the `.debug_str_offsets` section.
157 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
158 pub struct DebugStrOffsetsIndex<T = usize>(pub T);
159
160 /// An offset into the `.debug_types` section.
161 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
162 pub struct DebugTypesOffset<T = usize>(pub T);
163
164 /// A type signature as used in the `.debug_types` section.
165 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
166 pub struct DebugTypeSignature(pub u64);
167
168 /// An offset into the `.debug_frame` section.
169 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
170 pub struct DebugFrameOffset<T = usize>(pub T);
171
172 impl<T> From<T> for DebugFrameOffset<T> {
173 #[inline]
174 fn from(o: T) -> Self {
175 DebugFrameOffset(o)
176 }
177 }
178
179 /// An offset into the `.eh_frame` section.
180 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
181 pub struct EhFrameOffset<T = usize>(pub T);
182
183 impl<T> From<T> for EhFrameOffset<T> {
184 #[inline]
185 fn from(o: T) -> Self {
186 EhFrameOffset(o)
187 }
188 }
189
190 /// An offset into the `.debug_info` or `.debug_types` sections.
191 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
192 pub enum UnitSectionOffset<T = usize> {
193 /// An offset into the `.debug_info` section.
194 DebugInfoOffset(DebugInfoOffset<T>),
195 /// An offset into the `.debug_types` section.
196 DebugTypesOffset(DebugTypesOffset<T>),
197 }
198
199 impl<T> From<DebugInfoOffset<T>> for UnitSectionOffset<T> {
200 fn from(offset: DebugInfoOffset<T>) -> Self {
201 UnitSectionOffset::DebugInfoOffset(offset)
202 }
203 }
204
205 impl<T> From<DebugTypesOffset<T>> for UnitSectionOffset<T> {
206 fn from(offset: DebugTypesOffset<T>) -> Self {
207 UnitSectionOffset::DebugTypesOffset(offset)
208 }
209 }
210
211 impl<T> UnitSectionOffset<T>
212 where
213 T: Clone,
214 {
215 /// Returns the `DebugInfoOffset` inside, or `None` otherwise.
216 pub fn as_debug_info_offset(&self) -> Option<DebugInfoOffset<T>> {
217 match self {
218 UnitSectionOffset::DebugInfoOffset(offset) => Some(offset.clone()),
219 UnitSectionOffset::DebugTypesOffset(_) => None,
220 }
221 }
222 /// Returns the `DebugTypesOffset` inside, or `None` otherwise.
223 pub fn as_debug_types_offset(&self) -> Option<DebugTypesOffset<T>> {
224 match self {
225 UnitSectionOffset::DebugInfoOffset(_) => None,
226 UnitSectionOffset::DebugTypesOffset(offset) => Some(offset.clone()),
227 }
228 }
229 }
230
231 /// An identifier for a DWARF section.
232 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
233 pub enum SectionId {
234 /// The `.debug_abbrev` section.
235 DebugAbbrev,
236 /// The `.debug_addr` section.
237 DebugAddr,
238 /// The `.debug_aranges` section.
239 DebugAranges,
240 /// The `.debug_frame` section.
241 DebugFrame,
242 /// The `.eh_frame` section.
243 EhFrame,
244 /// The `.eh_frame_hdr` section.
245 EhFrameHdr,
246 /// The `.debug_info` section.
247 DebugInfo,
248 /// The `.debug_line` section.
249 DebugLine,
250 /// The `.debug_line_str` section.
251 DebugLineStr,
252 /// The `.debug_loc` section.
253 DebugLoc,
254 /// The `.debug_loclists` section.
255 DebugLocLists,
256 /// The `.debug_macinfo` section.
257 DebugMacinfo,
258 /// The `.debug_macro` section.
259 DebugMacro,
260 /// The `.debug_pubnames` section.
261 DebugPubNames,
262 /// The `.debug_pubtypes` section.
263 DebugPubTypes,
264 /// The `.debug_ranges` section.
265 DebugRanges,
266 /// The `.debug_rnglists` section.
267 DebugRngLists,
268 /// The `.debug_str` section.
269 DebugStr,
270 /// The `.debug_str_offsets` section.
271 DebugStrOffsets,
272 /// The `.debug_types` section.
273 DebugTypes,
274 }
275
276 impl SectionId {
277 /// Returns the ELF section name for this kind.
278 pub fn name(self) -> &'static str {
279 match self {
280 SectionId::DebugAbbrev => ".debug_abbrev",
281 SectionId::DebugAddr => ".debug_addr",
282 SectionId::DebugAranges => ".debug_aranges",
283 SectionId::DebugFrame => ".debug_frame",
284 SectionId::EhFrame => ".eh_frame",
285 SectionId::EhFrameHdr => ".eh_frame_hdr",
286 SectionId::DebugInfo => ".debug_info",
287 SectionId::DebugLine => ".debug_line",
288 SectionId::DebugLineStr => ".debug_line_str",
289 SectionId::DebugLoc => ".debug_loc",
290 SectionId::DebugLocLists => ".debug_loclists",
291 SectionId::DebugMacinfo => ".debug_macinfo",
292 SectionId::DebugMacro => ".debug_macro",
293 SectionId::DebugPubNames => ".debug_pubnames",
294 SectionId::DebugPubTypes => ".debug_pubtypes",
295 SectionId::DebugRanges => ".debug_ranges",
296 SectionId::DebugRngLists => ".debug_rnglists",
297 SectionId::DebugStr => ".debug_str",
298 SectionId::DebugStrOffsets => ".debug_str_offsets",
299 SectionId::DebugTypes => ".debug_types",
300 }
301 }
302
303 /// Returns the ELF section name for this kind, when found in a .dwo file.
304 pub fn dwo_name(self) -> Option<&'static str> {
305 Some(match self {
306 SectionId::DebugAbbrev => ".debug_abbrev.dwo",
307 SectionId::DebugInfo => ".debug_info.dwo",
308 SectionId::DebugLine => ".debug_line.dwo",
309 // The debug_loc section can be present in the dwo when using the
310 // GNU split-dwarf extension to DWARF4.
311 SectionId::DebugLoc => ".debug_loc.dwo",
312 SectionId::DebugLocLists => ".debug_loclists.dwo",
313 SectionId::DebugMacro => ".debug_macro.dwo",
314 SectionId::DebugRngLists => ".debug_rnglists.dwo",
315 SectionId::DebugStr => ".debug_str.dwo",
316 SectionId::DebugStrOffsets => ".debug_str_offsets.dwo",
317 _ => return None,
318 })
319 }
320 }
321
322 /// An optionally-provided implementation-defined compilation unit ID to enable
323 /// split DWARF and linking a split compilation unit back together.
324 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
325 pub struct DwoId(pub u64);
326
327 /// The "type" of file with DWARF debugging information. This determines, among other things,
328 /// which files DWARF sections should be loaded from.
329 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
330 pub enum DwarfFileType {
331 /// A normal executable or object file.
332 Main,
333 /// A .dwo split DWARF file.
334 Dwo,
335 // TODO: Supplementary files, .dwps?
336 }
337
338 impl Default for DwarfFileType {
339 fn default() -> Self {
340 DwarfFileType::Main
341 }
342 }