1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum Format {
4    Dwarf64 = 8,
6    Dwarf32 = 4,
8}
9
10impl Format {
11    #[inline]
13    pub fn initial_length_size(self) -> u8 {
14        match self {
15            Format::Dwarf32 => 4,
16            Format::Dwarf64 => 12,
17        }
18    }
19
20    #[inline]
22    pub fn word_size(self) -> u8 {
23        match self {
24            Format::Dwarf32 => 4,
25            Format::Dwarf64 => 8,
26        }
27    }
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32#[non_exhaustive]
33pub enum Vendor {
34    Default,
36    AArch64,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44#[repr(C)]
47pub struct Encoding {
48    pub address_size: u8,
50
51    pub format: Format,
53
54    pub version: u16,
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
60pub struct LineEncoding {
61    pub minimum_instruction_length: u8,
63
64    pub maximum_operations_per_instruction: u8,
67
68    pub default_is_stmt: bool,
70
71    pub line_base: i8,
73
74    pub line_range: u8,
76}
77
78impl Default for LineEncoding {
79    fn default() -> Self {
80        LineEncoding {
82            minimum_instruction_length: 1,
83            maximum_operations_per_instruction: 1,
84            default_is_stmt: true,
85            line_base: -5,
86            line_range: 14,
87        }
88    }
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
96pub struct Register(pub u16);
97
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
100pub struct DebugAbbrevOffset<T = usize>(pub T);
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub struct DebugAddrBase<T = usize>(pub T);
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108pub struct DebugAddrIndex<T = usize>(pub T);
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq)]
112pub struct DebugArangesOffset<T = usize>(pub T);
113
114#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
116pub struct DebugInfoOffset<T = usize>(pub T);
117
118#[derive(Debug, Clone, Copy, PartialEq, Eq)]
120pub struct DebugLineOffset<T = usize>(pub T);
121
122#[derive(Debug, Clone, Copy, PartialEq, Eq)]
124pub struct DebugLineStrOffset<T = usize>(pub T);
125
126#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
129pub struct LocationListsOffset<T = usize>(pub T);
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq)]
133pub struct DebugLocListsBase<T = usize>(pub T);
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
137pub struct DebugLocListsIndex<T = usize>(pub T);
138
139#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
141pub struct DebugMacinfoOffset<T = usize>(pub T);
142
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
145pub struct DebugMacroOffset<T = usize>(pub T);
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
153pub struct RawRangeListsOffset<T = usize>(pub T);
154
155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
158pub struct RangeListsOffset<T = usize>(pub T);
159
160#[derive(Debug, Clone, Copy, PartialEq, Eq)]
162pub struct DebugRngListsBase<T = usize>(pub T);
163
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166pub struct DebugRngListsIndex<T = usize>(pub T);
167
168#[derive(Debug, Clone, Copy, PartialEq, Eq)]
170pub struct DebugStrOffset<T = usize>(pub T);
171
172#[derive(Debug, Clone, Copy, PartialEq, Eq)]
174pub struct DebugStrOffsetsBase<T = usize>(pub T);
175
176#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178pub struct DebugStrOffsetsIndex<T = usize>(pub T);
179
180#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
182pub struct DebugTypesOffset<T = usize>(pub T);
183
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
186pub struct DebugTypeSignature(pub u64);
187
188#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
190pub struct DebugFrameOffset<T = usize>(pub T);
191
192impl<T> From<T> for DebugFrameOffset<T> {
193    #[inline]
194    fn from(o: T) -> Self {
195        DebugFrameOffset(o)
196    }
197}
198
199#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
201pub struct EhFrameOffset<T = usize>(pub T);
202
203impl<T> From<T> for EhFrameOffset<T> {
204    #[inline]
205    fn from(o: T) -> Self {
206        EhFrameOffset(o)
207    }
208}
209
210#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
212pub enum UnitSectionOffset<T = usize> {
213    DebugInfoOffset(DebugInfoOffset<T>),
215    DebugTypesOffset(DebugTypesOffset<T>),
217}
218
219impl<T> From<DebugInfoOffset<T>> for UnitSectionOffset<T> {
220    fn from(offset: DebugInfoOffset<T>) -> Self {
221        UnitSectionOffset::DebugInfoOffset(offset)
222    }
223}
224
225impl<T> From<DebugTypesOffset<T>> for UnitSectionOffset<T> {
226    fn from(offset: DebugTypesOffset<T>) -> Self {
227        UnitSectionOffset::DebugTypesOffset(offset)
228    }
229}
230
231impl<T> UnitSectionOffset<T>
232where
233    T: Clone,
234{
235    pub fn as_debug_info_offset(&self) -> Option<DebugInfoOffset<T>> {
237        match self {
238            UnitSectionOffset::DebugInfoOffset(offset) => Some(offset.clone()),
239            UnitSectionOffset::DebugTypesOffset(_) => None,
240        }
241    }
242    pub fn as_debug_types_offset(&self) -> Option<DebugTypesOffset<T>> {
244        match self {
245            UnitSectionOffset::DebugInfoOffset(_) => None,
246            UnitSectionOffset::DebugTypesOffset(offset) => Some(offset.clone()),
247        }
248    }
249}
250
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
253pub enum SectionId {
254    DebugAbbrev,
256    DebugAddr,
258    DebugAranges,
260    DebugCuIndex,
262    DebugFrame,
264    EhFrame,
266    EhFrameHdr,
268    DebugInfo,
270    DebugLine,
272    DebugLineStr,
274    DebugLoc,
276    DebugLocLists,
278    DebugMacinfo,
280    DebugMacro,
282    DebugPubNames,
284    DebugPubTypes,
286    DebugRanges,
288    DebugRngLists,
290    DebugStr,
292    DebugStrOffsets,
294    DebugTuIndex,
296    DebugTypes,
298}
299
300impl SectionId {
301    pub fn name(self) -> &'static str {
303        match self {
304            SectionId::DebugAbbrev => ".debug_abbrev",
305            SectionId::DebugAddr => ".debug_addr",
306            SectionId::DebugAranges => ".debug_aranges",
307            SectionId::DebugCuIndex => ".debug_cu_index",
308            SectionId::DebugFrame => ".debug_frame",
309            SectionId::EhFrame => ".eh_frame",
310            SectionId::EhFrameHdr => ".eh_frame_hdr",
311            SectionId::DebugInfo => ".debug_info",
312            SectionId::DebugLine => ".debug_line",
313            SectionId::DebugLineStr => ".debug_line_str",
314            SectionId::DebugLoc => ".debug_loc",
315            SectionId::DebugLocLists => ".debug_loclists",
316            SectionId::DebugMacinfo => ".debug_macinfo",
317            SectionId::DebugMacro => ".debug_macro",
318            SectionId::DebugPubNames => ".debug_pubnames",
319            SectionId::DebugPubTypes => ".debug_pubtypes",
320            SectionId::DebugRanges => ".debug_ranges",
321            SectionId::DebugRngLists => ".debug_rnglists",
322            SectionId::DebugStr => ".debug_str",
323            SectionId::DebugStrOffsets => ".debug_str_offsets",
324            SectionId::DebugTuIndex => ".debug_tu_index",
325            SectionId::DebugTypes => ".debug_types",
326        }
327    }
328
329    pub fn dwo_name(self) -> Option<&'static str> {
331        Some(match self {
332            SectionId::DebugAbbrev => ".debug_abbrev.dwo",
333            SectionId::DebugCuIndex => ".debug_cu_index",
334            SectionId::DebugInfo => ".debug_info.dwo",
335            SectionId::DebugLine => ".debug_line.dwo",
336            SectionId::DebugLoc => ".debug_loc.dwo",
339            SectionId::DebugLocLists => ".debug_loclists.dwo",
340            SectionId::DebugMacinfo => ".debug_macinfo.dwo",
341            SectionId::DebugMacro => ".debug_macro.dwo",
342            SectionId::DebugRngLists => ".debug_rnglists.dwo",
343            SectionId::DebugStr => ".debug_str.dwo",
344            SectionId::DebugStrOffsets => ".debug_str_offsets.dwo",
345            SectionId::DebugTuIndex => ".debug_tu_index",
346            SectionId::DebugTypes => ".debug_types.dwo",
347            _ => return None,
348        })
349    }
350
351    pub fn xcoff_name(self) -> Option<&'static str> {
353        Some(match self {
354            SectionId::DebugAbbrev => ".dwabrev",
355            SectionId::DebugAranges => ".dwarnge",
356            SectionId::DebugFrame => ".dwframe",
357            SectionId::DebugInfo => ".dwinfo",
358            SectionId::DebugLine => ".dwline",
359            SectionId::DebugLoc => ".dwloc",
360            SectionId::DebugMacinfo => ".dwmac",
361            SectionId::DebugPubNames => ".dwpbnms",
362            SectionId::DebugPubTypes => ".dwpbtyp",
363            SectionId::DebugRanges => ".dwrnges",
364            SectionId::DebugStr => ".dwstr",
365            _ => return None,
366        })
367    }
368
369    pub fn is_string(self) -> bool {
373        matches!(self, SectionId::DebugStr | SectionId::DebugLineStr)
374    }
375}
376
377#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
380pub struct DwoId(pub u64);
381
382#[derive(Debug, Clone, Copy, PartialEq, Eq)]
385pub enum DwarfFileType {
386    Main,
388    Dwo,
390    }
392
393impl Default for DwarfFileType {
394    fn default() -> Self {
395        DwarfFileType::Main
396    }
397}