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 DebugAddrOffset<T = usize>(pub T);
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108pub struct DebugAddrBase<T = usize>(pub T);
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq)]
112pub struct DebugAddrIndex<T = usize>(pub T);
113
114#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116pub struct DebugArangesOffset<T = usize>(pub T);
117
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
120pub struct DebugInfoOffset<T = usize>(pub T);
121
122#[derive(Debug, Clone, Copy, PartialEq, Eq)]
124pub struct DebugLineOffset<T = usize>(pub T);
125
126#[derive(Debug, Clone, Copy, PartialEq, Eq)]
128pub struct DebugLineStrOffset<T = usize>(pub T);
129
130#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133pub struct LocationListsOffset<T = usize>(pub T);
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
137pub struct DebugLocListsBase<T = usize>(pub T);
138
139#[derive(Debug, Clone, Copy, PartialEq, Eq)]
141pub struct DebugLocListsIndex<T = usize>(pub T);
142
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
145pub struct DebugMacinfoOffset<T = usize>(pub T);
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
149pub struct DebugMacroOffset<T = usize>(pub T);
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
157pub struct RawRangeListsOffset<T = usize>(pub T);
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
162pub struct RangeListsOffset<T = usize>(pub T);
163
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166pub struct DebugRngListsBase<T = usize>(pub T);
167
168#[derive(Debug, Clone, Copy, PartialEq, Eq)]
170pub struct DebugRngListsIndex<T = usize>(pub T);
171
172#[derive(Debug, Clone, Copy, PartialEq, Eq)]
174pub struct DebugStrOffset<T = usize>(pub T);
175
176#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178pub struct DebugStrOffsetsBase<T = usize>(pub T);
179
180#[derive(Debug, Clone, Copy, PartialEq, Eq)]
182pub struct DebugStrOffsetsIndex<T = usize>(pub T);
183
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
186pub struct DebugTypesOffset<T = usize>(pub T);
187
188#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
190pub struct DebugTypeSignature(pub u64);
191
192#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
194pub struct DebugFrameOffset<T = usize>(pub T);
195
196impl<T> From<T> for DebugFrameOffset<T> {
197 #[inline]
198 fn from(o: T) -> Self {
199 DebugFrameOffset(o)
200 }
201}
202
203#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
205pub struct EhFrameOffset<T = usize>(pub T);
206
207impl<T> From<T> for EhFrameOffset<T> {
208 #[inline]
209 fn from(o: T) -> Self {
210 EhFrameOffset(o)
211 }
212}
213
214#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
216pub enum UnitSectionOffset<T = usize> {
217 DebugInfoOffset(DebugInfoOffset<T>),
219 DebugTypesOffset(DebugTypesOffset<T>),
221}
222
223impl<T> From<DebugInfoOffset<T>> for UnitSectionOffset<T> {
224 fn from(offset: DebugInfoOffset<T>) -> Self {
225 UnitSectionOffset::DebugInfoOffset(offset)
226 }
227}
228
229impl<T> From<DebugTypesOffset<T>> for UnitSectionOffset<T> {
230 fn from(offset: DebugTypesOffset<T>) -> Self {
231 UnitSectionOffset::DebugTypesOffset(offset)
232 }
233}
234
235impl<T> PartialEq<DebugInfoOffset<T>> for UnitSectionOffset<T>
236where
237 T: PartialEq,
238{
239 fn eq(&self, other: &DebugInfoOffset<T>) -> bool {
240 match self {
241 UnitSectionOffset::DebugInfoOffset(o) => o.eq(other),
242 UnitSectionOffset::DebugTypesOffset(_) => false,
243 }
244 }
245}
246
247impl<T> PartialEq<DebugTypesOffset<T>> for UnitSectionOffset<T>
248where
249 T: PartialEq,
250{
251 fn eq(&self, other: &DebugTypesOffset<T>) -> bool {
252 match self {
253 UnitSectionOffset::DebugInfoOffset(_) => false,
254 UnitSectionOffset::DebugTypesOffset(o) => o.eq(other),
255 }
256 }
257}
258
259impl<T> UnitSectionOffset<T>
260where
261 T: Clone,
262{
263 pub fn as_debug_info_offset(&self) -> Option<DebugInfoOffset<T>> {
265 match self {
266 UnitSectionOffset::DebugInfoOffset(offset) => Some(offset.clone()),
267 UnitSectionOffset::DebugTypesOffset(_) => None,
268 }
269 }
270 pub fn as_debug_types_offset(&self) -> Option<DebugTypesOffset<T>> {
272 match self {
273 UnitSectionOffset::DebugInfoOffset(_) => None,
274 UnitSectionOffset::DebugTypesOffset(offset) => Some(offset.clone()),
275 }
276 }
277}
278
279#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
281pub enum SectionId {
282 DebugAbbrev,
284 DebugAddr,
286 DebugAranges,
288 DebugCuIndex,
290 DebugFrame,
292 EhFrame,
294 EhFrameHdr,
296 DebugInfo,
298 DebugLine,
300 DebugLineStr,
302 DebugLoc,
304 DebugLocLists,
306 DebugMacinfo,
308 DebugMacro,
310 DebugPubNames,
312 DebugPubTypes,
314 DebugRanges,
316 DebugRngLists,
318 DebugStr,
320 DebugStrOffsets,
322 DebugTuIndex,
324 DebugTypes,
326}
327
328impl SectionId {
329 pub fn name(self) -> &'static str {
331 match self {
332 SectionId::DebugAbbrev => ".debug_abbrev",
333 SectionId::DebugAddr => ".debug_addr",
334 SectionId::DebugAranges => ".debug_aranges",
335 SectionId::DebugCuIndex => ".debug_cu_index",
336 SectionId::DebugFrame => ".debug_frame",
337 SectionId::EhFrame => ".eh_frame",
338 SectionId::EhFrameHdr => ".eh_frame_hdr",
339 SectionId::DebugInfo => ".debug_info",
340 SectionId::DebugLine => ".debug_line",
341 SectionId::DebugLineStr => ".debug_line_str",
342 SectionId::DebugLoc => ".debug_loc",
343 SectionId::DebugLocLists => ".debug_loclists",
344 SectionId::DebugMacinfo => ".debug_macinfo",
345 SectionId::DebugMacro => ".debug_macro",
346 SectionId::DebugPubNames => ".debug_pubnames",
347 SectionId::DebugPubTypes => ".debug_pubtypes",
348 SectionId::DebugRanges => ".debug_ranges",
349 SectionId::DebugRngLists => ".debug_rnglists",
350 SectionId::DebugStr => ".debug_str",
351 SectionId::DebugStrOffsets => ".debug_str_offsets",
352 SectionId::DebugTuIndex => ".debug_tu_index",
353 SectionId::DebugTypes => ".debug_types",
354 }
355 }
356
357 pub fn dwo_name(self) -> Option<&'static str> {
359 Some(match self {
360 SectionId::DebugAbbrev => ".debug_abbrev.dwo",
361 SectionId::DebugCuIndex => ".debug_cu_index",
362 SectionId::DebugInfo => ".debug_info.dwo",
363 SectionId::DebugLine => ".debug_line.dwo",
364 SectionId::DebugLoc => ".debug_loc.dwo",
367 SectionId::DebugLocLists => ".debug_loclists.dwo",
368 SectionId::DebugMacinfo => ".debug_macinfo.dwo",
369 SectionId::DebugMacro => ".debug_macro.dwo",
370 SectionId::DebugRngLists => ".debug_rnglists.dwo",
371 SectionId::DebugStr => ".debug_str.dwo",
372 SectionId::DebugStrOffsets => ".debug_str_offsets.dwo",
373 SectionId::DebugTuIndex => ".debug_tu_index",
374 SectionId::DebugTypes => ".debug_types.dwo",
375 _ => return None,
376 })
377 }
378
379 pub fn xcoff_name(self) -> Option<&'static str> {
381 Some(match self {
382 SectionId::DebugAbbrev => ".dwabrev",
383 SectionId::DebugAranges => ".dwarnge",
384 SectionId::DebugFrame => ".dwframe",
385 SectionId::DebugInfo => ".dwinfo",
386 SectionId::DebugLine => ".dwline",
387 SectionId::DebugLoc => ".dwloc",
388 SectionId::DebugMacinfo => ".dwmac",
389 SectionId::DebugPubNames => ".dwpbnms",
390 SectionId::DebugPubTypes => ".dwpbtyp",
391 SectionId::DebugRanges => ".dwrnges",
392 SectionId::DebugStr => ".dwstr",
393 _ => return None,
394 })
395 }
396
397 pub fn is_string(self) -> bool {
401 matches!(self, SectionId::DebugStr | SectionId::DebugLineStr)
402 }
403}
404
405#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
408pub struct DwoId(pub u64);
409
410#[derive(Debug, Clone, Copy, PartialEq, Eq)]
413pub enum DwarfFileType {
414 Main,
416 Dwo,
418 }
420
421impl Default for DwarfFileType {
422 fn default() -> Self {
423 DwarfFileType::Main
424 }
425}