Coverage Report

Created: 2026-03-26 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/gimli-0.32.3/src/common.rs
Line
Count
Source
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
0
    pub fn initial_length_size(self) -> u8 {
14
0
        match self {
15
0
            Format::Dwarf32 => 4,
16
0
            Format::Dwarf64 => 12,
17
        }
18
0
    }
19
20
    /// Return the natural word size for the format
21
    #[inline]
22
0
    pub fn word_size(self) -> u8 {
23
0
        match self {
24
0
            Format::Dwarf32 => 4,
25
0
            Format::Dwarf64 => 8,
26
        }
27
0
    }
28
}
29
30
/// Which vendor extensions to support.
31
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32
#[non_exhaustive]
33
pub enum Vendor {
34
    /// A default set of extensions, including some common GNU extensions.
35
    Default,
36
    /// AAarch64 extensions.
37
    AArch64,
38
}
39
40
/// Encoding parameters that are commonly used for multiple DWARF sections.
41
///
42
/// This is intended to be small enough to pass by value.
43
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44
// `address_size` and `format` are used more often than `version`, so keep
45
// them first.
46
#[repr(C)]
47
pub struct Encoding {
48
    /// The size of an address.
49
    pub address_size: u8,
50
51
    /// Whether the DWARF format is 32- or 64-bit.
52
    pub format: Format,
53
54
    /// The DWARF version of the header.
55
    pub version: u16,
56
}
57
58
/// Encoding parameters for a line number program.
59
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
60
pub struct LineEncoding {
61
    /// The size in bytes of the smallest target machine instruction.
62
    pub minimum_instruction_length: u8,
63
64
    /// The maximum number of individual operations that may be encoded in an
65
    /// instruction.
66
    pub maximum_operations_per_instruction: u8,
67
68
    /// The initial value of the `is_stmt` register.
69
    pub default_is_stmt: bool,
70
71
    /// The minimum value which a special opcode can add to the line register.
72
    pub line_base: i8,
73
74
    /// The range of values which a special opcode can add to the line register.
75
    pub line_range: u8,
76
}
77
78
impl Default for LineEncoding {
79
0
    fn default() -> Self {
80
        // Values from LLVM.
81
0
        LineEncoding {
82
0
            minimum_instruction_length: 1,
83
0
            maximum_operations_per_instruction: 1,
84
0
            default_is_stmt: true,
85
0
            line_base: -5,
86
0
            line_range: 14,
87
0
        }
88
0
    }
89
}
90
91
/// A DWARF register number.
92
///
93
/// The meaning of this value is ABI dependent. This is generally encoded as
94
/// a ULEB128, but supported architectures need 16 bits at most.
95
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
96
pub struct Register(pub u16);
97
98
/// An offset into the `.debug_abbrev` section.
99
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
100
pub struct DebugAbbrevOffset<T = usize>(pub T);
101
102
/// An offset into the `.debug_addr` section.
103
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104
pub struct DebugAddrOffset<T = usize>(pub T);
105
106
/// An offset to a set of entries in the `.debug_addr` section.
107
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108
pub struct DebugAddrBase<T = usize>(pub T);
109
110
/// An index into a set of addresses in the `.debug_addr` section.
111
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
112
pub struct DebugAddrIndex<T = usize>(pub T);
113
114
/// An offset into the `.debug_aranges` section.
115
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116
pub struct DebugArangesOffset<T = usize>(pub T);
117
118
/// An offset into the `.debug_info` section.
119
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
120
pub struct DebugInfoOffset<T = usize>(pub T);
121
122
/// An offset into the `.debug_line` section.
123
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
124
pub struct DebugLineOffset<T = usize>(pub T);
125
126
/// An offset into the `.debug_line_str` section.
127
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
128
pub struct DebugLineStrOffset<T = usize>(pub T);
129
130
/// An offset into either the `.debug_loc` section or the `.debug_loclists` section,
131
/// depending on the version of the unit the offset was contained in.
132
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133
pub struct LocationListsOffset<T = usize>(pub T);
134
135
/// An offset to a set of location list offsets in the `.debug_loclists` section.
136
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
137
pub struct DebugLocListsBase<T = usize>(pub T);
138
139
/// An index into a set of location list offsets in the `.debug_loclists` section.
140
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
141
pub struct DebugLocListsIndex<T = usize>(pub T);
142
143
/// An offset into the `.debug_macinfo` section.
144
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
145
pub struct DebugMacinfoOffset<T = usize>(pub T);
146
147
/// An offset into the `.debug_macro` section.
148
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
149
pub struct DebugMacroOffset<T = usize>(pub T);
150
151
/// An offset into either the `.debug_ranges` section or the `.debug_rnglists` section,
152
/// depending on the version of the unit the offset was contained in.
153
///
154
/// If this is from a DWARF 4 DWO file, then it must additionally be offset by the
155
/// value of `DW_AT_GNU_ranges_base`. You can use `Dwarf::ranges_offset_from_raw` to do this.
156
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
157
pub struct RawRangeListsOffset<T = usize>(pub T);
158
159
/// An offset into either the `.debug_ranges` section or the `.debug_rnglists` section,
160
/// depending on the version of the unit the offset was contained in.
161
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
162
pub struct RangeListsOffset<T = usize>(pub T);
163
164
/// An offset to a set of range list offsets in the `.debug_rnglists` section.
165
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166
pub struct DebugRngListsBase<T = usize>(pub T);
167
168
/// An index into a set of range list offsets in the `.debug_rnglists` section.
169
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
170
pub struct DebugRngListsIndex<T = usize>(pub T);
171
172
/// An offset into the `.debug_str` section.
173
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
174
pub struct DebugStrOffset<T = usize>(pub T);
175
176
/// An offset to a set of entries in the `.debug_str_offsets` section.
177
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178
pub struct DebugStrOffsetsBase<T = usize>(pub T);
179
180
/// An index into a set of entries in the `.debug_str_offsets` section.
181
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
182
pub struct DebugStrOffsetsIndex<T = usize>(pub T);
183
184
/// An offset into the `.debug_types` section.
185
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
186
pub struct DebugTypesOffset<T = usize>(pub T);
187
188
/// A type signature as used in the `.debug_types` section.
189
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
190
pub struct DebugTypeSignature(pub u64);
191
192
/// An offset into the `.debug_frame` section.
193
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
194
pub struct DebugFrameOffset<T = usize>(pub T);
195
196
impl<T> From<T> for DebugFrameOffset<T> {
197
    #[inline]
198
0
    fn from(o: T) -> Self {
199
0
        DebugFrameOffset(o)
200
0
    }
201
}
202
203
/// An offset into the `.eh_frame` section.
204
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
205
pub struct EhFrameOffset<T = usize>(pub T);
206
207
impl<T> From<T> for EhFrameOffset<T> {
208
    #[inline]
209
0
    fn from(o: T) -> Self {
210
0
        EhFrameOffset(o)
211
0
    }
212
}
213
214
/// An offset into the `.debug_info` or `.debug_types` sections.
215
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
216
pub enum UnitSectionOffset<T = usize> {
217
    /// An offset into the `.debug_info` section.
218
    DebugInfoOffset(DebugInfoOffset<T>),
219
    /// An offset into the `.debug_types` section.
220
    DebugTypesOffset(DebugTypesOffset<T>),
221
}
222
223
impl<T> From<DebugInfoOffset<T>> for UnitSectionOffset<T> {
224
0
    fn from(offset: DebugInfoOffset<T>) -> Self {
225
0
        UnitSectionOffset::DebugInfoOffset(offset)
226
0
    }
Unexecuted instantiation: <gimli::common::UnitSectionOffset as core::convert::From<gimli::common::DebugInfoOffset>>::from
Unexecuted instantiation: <gimli::common::UnitSectionOffset<_> as core::convert::From<gimli::common::DebugInfoOffset<_>>>::from
227
}
228
229
impl<T> From<DebugTypesOffset<T>> for UnitSectionOffset<T> {
230
0
    fn from(offset: DebugTypesOffset<T>) -> Self {
231
0
        UnitSectionOffset::DebugTypesOffset(offset)
232
0
    }
233
}
234
235
impl<T> UnitSectionOffset<T>
236
where
237
    T: Clone,
238
{
239
    /// Returns the `DebugInfoOffset` inside, or `None` otherwise.
240
0
    pub fn as_debug_info_offset(&self) -> Option<DebugInfoOffset<T>> {
241
0
        match self {
242
0
            UnitSectionOffset::DebugInfoOffset(offset) => Some(offset.clone()),
243
0
            UnitSectionOffset::DebugTypesOffset(_) => None,
244
        }
245
0
    }
Unexecuted instantiation: <gimli::common::UnitSectionOffset>::as_debug_info_offset
Unexecuted instantiation: <gimli::common::UnitSectionOffset<_>>::as_debug_info_offset
246
    /// Returns the `DebugTypesOffset` inside, or `None` otherwise.
247
0
    pub fn as_debug_types_offset(&self) -> Option<DebugTypesOffset<T>> {
248
0
        match self {
249
0
            UnitSectionOffset::DebugInfoOffset(_) => None,
250
0
            UnitSectionOffset::DebugTypesOffset(offset) => Some(offset.clone()),
251
        }
252
0
    }
253
}
254
255
/// An identifier for a DWARF section.
256
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
257
pub enum SectionId {
258
    /// The `.debug_abbrev` section.
259
    DebugAbbrev,
260
    /// The `.debug_addr` section.
261
    DebugAddr,
262
    /// The `.debug_aranges` section.
263
    DebugAranges,
264
    /// The `.debug_cu_index` section.
265
    DebugCuIndex,
266
    /// The `.debug_frame` section.
267
    DebugFrame,
268
    /// The `.eh_frame` section.
269
    EhFrame,
270
    /// The `.eh_frame_hdr` section.
271
    EhFrameHdr,
272
    /// The `.debug_info` section.
273
    DebugInfo,
274
    /// The `.debug_line` section.
275
    DebugLine,
276
    /// The `.debug_line_str` section.
277
    DebugLineStr,
278
    /// The `.debug_loc` section.
279
    DebugLoc,
280
    /// The `.debug_loclists` section.
281
    DebugLocLists,
282
    /// The `.debug_macinfo` section.
283
    DebugMacinfo,
284
    /// The `.debug_macro` section.
285
    DebugMacro,
286
    /// The `.debug_pubnames` section.
287
    DebugPubNames,
288
    /// The `.debug_pubtypes` section.
289
    DebugPubTypes,
290
    /// The `.debug_ranges` section.
291
    DebugRanges,
292
    /// The `.debug_rnglists` section.
293
    DebugRngLists,
294
    /// The `.debug_str` section.
295
    DebugStr,
296
    /// The `.debug_str_offsets` section.
297
    DebugStrOffsets,
298
    /// The `.debug_tu_index` section.
299
    DebugTuIndex,
300
    /// The `.debug_types` section.
301
    DebugTypes,
302
}
303
304
impl SectionId {
305
    /// Returns the ELF section name for this kind.
306
0
    pub fn name(self) -> &'static str {
307
0
        match self {
308
0
            SectionId::DebugAbbrev => ".debug_abbrev",
309
0
            SectionId::DebugAddr => ".debug_addr",
310
0
            SectionId::DebugAranges => ".debug_aranges",
311
0
            SectionId::DebugCuIndex => ".debug_cu_index",
312
0
            SectionId::DebugFrame => ".debug_frame",
313
0
            SectionId::EhFrame => ".eh_frame",
314
0
            SectionId::EhFrameHdr => ".eh_frame_hdr",
315
0
            SectionId::DebugInfo => ".debug_info",
316
0
            SectionId::DebugLine => ".debug_line",
317
0
            SectionId::DebugLineStr => ".debug_line_str",
318
0
            SectionId::DebugLoc => ".debug_loc",
319
0
            SectionId::DebugLocLists => ".debug_loclists",
320
0
            SectionId::DebugMacinfo => ".debug_macinfo",
321
0
            SectionId::DebugMacro => ".debug_macro",
322
0
            SectionId::DebugPubNames => ".debug_pubnames",
323
0
            SectionId::DebugPubTypes => ".debug_pubtypes",
324
0
            SectionId::DebugRanges => ".debug_ranges",
325
0
            SectionId::DebugRngLists => ".debug_rnglists",
326
0
            SectionId::DebugStr => ".debug_str",
327
0
            SectionId::DebugStrOffsets => ".debug_str_offsets",
328
0
            SectionId::DebugTuIndex => ".debug_tu_index",
329
0
            SectionId::DebugTypes => ".debug_types",
330
        }
331
0
    }
332
333
    /// Returns the ELF section name for this kind, when found in a .dwo or .dwp file.
334
0
    pub fn dwo_name(self) -> Option<&'static str> {
335
0
        Some(match self {
336
0
            SectionId::DebugAbbrev => ".debug_abbrev.dwo",
337
0
            SectionId::DebugCuIndex => ".debug_cu_index",
338
0
            SectionId::DebugInfo => ".debug_info.dwo",
339
0
            SectionId::DebugLine => ".debug_line.dwo",
340
            // The debug_loc section can be present in the dwo when using the
341
            // GNU split-dwarf extension to DWARF4.
342
0
            SectionId::DebugLoc => ".debug_loc.dwo",
343
0
            SectionId::DebugLocLists => ".debug_loclists.dwo",
344
0
            SectionId::DebugMacinfo => ".debug_macinfo.dwo",
345
0
            SectionId::DebugMacro => ".debug_macro.dwo",
346
0
            SectionId::DebugRngLists => ".debug_rnglists.dwo",
347
0
            SectionId::DebugStr => ".debug_str.dwo",
348
0
            SectionId::DebugStrOffsets => ".debug_str_offsets.dwo",
349
0
            SectionId::DebugTuIndex => ".debug_tu_index",
350
0
            SectionId::DebugTypes => ".debug_types.dwo",
351
0
            _ => return None,
352
        })
353
0
    }
354
355
    /// Returns the XCOFF section name for this kind.
356
0
    pub fn xcoff_name(self) -> Option<&'static str> {
357
0
        Some(match self {
358
0
            SectionId::DebugAbbrev => ".dwabrev",
359
0
            SectionId::DebugAranges => ".dwarnge",
360
0
            SectionId::DebugFrame => ".dwframe",
361
0
            SectionId::DebugInfo => ".dwinfo",
362
0
            SectionId::DebugLine => ".dwline",
363
0
            SectionId::DebugLoc => ".dwloc",
364
0
            SectionId::DebugMacinfo => ".dwmac",
365
0
            SectionId::DebugPubNames => ".dwpbnms",
366
0
            SectionId::DebugPubTypes => ".dwpbtyp",
367
0
            SectionId::DebugRanges => ".dwrnges",
368
0
            SectionId::DebugStr => ".dwstr",
369
0
            _ => return None,
370
        })
371
0
    }
372
373
    /// Returns true if this is a mergeable string section.
374
    ///
375
    /// This is useful for determining the correct section flags.
376
0
    pub fn is_string(self) -> bool {
377
0
        matches!(self, SectionId::DebugStr | SectionId::DebugLineStr)
378
0
    }
379
}
380
381
/// An optionally-provided implementation-defined compilation unit ID to enable
382
/// split DWARF and linking a split compilation unit back together.
383
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
384
pub struct DwoId(pub u64);
385
386
/// The "type" of file with DWARF debugging information. This determines, among other things,
387
/// which files DWARF sections should be loaded from.
388
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
389
pub enum DwarfFileType {
390
    /// A normal executable or object file.
391
    Main,
392
    /// A .dwo split DWARF file.
393
    Dwo,
394
    // TODO: Supplementary files, .dwps?
395
}
396
397
impl Default for DwarfFileType {
398
0
    fn default() -> Self {
399
0
        DwarfFileType::Main
400
0
    }
401
}