1 /// Whether the format of a compilation unit is 32- or 64-bit.
2 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11 /// Return the serialized size of an initial length field for the format.
13 pub fn initial_length_size(self) -> u8 {
16 Format
::Dwarf64
=> 12,
20 /// Return the natural word size for the format
22 pub fn word_size(self) -> u8 {
30 /// Encoding parameters that are commonly used for multiple DWARF sections.
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
38 /// The size of an address.
41 // The size of a segment selector.
42 // TODO: pub segment_size: u8,
43 /// Whether the DWARF format is 32- or 64-bit.
46 /// The DWARF version of the header.
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,
56 /// The maximum number of individual operations that may be encoded in an
58 pub maximum_operations_per_instruction
: u8,
60 /// The initial value of the `is_stmt` register.
61 pub default_is_stmt
: bool
,
63 /// The minimum value which a special opcode can add to the line register.
66 /// The range of values which a special opcode can add to the line register.
70 impl Default
for LineEncoding
{
71 fn default() -> Self {
74 minimum_instruction_length
: 1,
75 maximum_operations_per_instruction
: 1,
76 default_is_stmt
: true,
83 /// A DWARF register number.
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);
90 /// An offset into the `.debug_abbrev` section.
91 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92 pub struct DebugAbbrevOffset
<T
= usize>(pub T
);
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
);
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
);
102 /// An offset into the `.debug_aranges` section.
103 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
104 pub struct DebugArangesOffset
<T
= usize>(pub T
);
106 /// An offset into the `.debug_info` section.
107 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
108 pub struct DebugInfoOffset
<T
= usize>(pub T
);
110 /// An offset into the `.debug_line` section.
111 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
112 pub struct DebugLineOffset
<T
= usize>(pub T
);
114 /// An offset into the `.debug_line_str` section.
115 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
116 pub struct DebugLineStrOffset
<T
= usize>(pub T
);
118 /// An offset into either the `.debug_loc` section or the `.debug_loclists` section,
119 /// depending on the version of the unit the offset was contained in.
120 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
121 pub struct LocationListsOffset
<T
= usize>(pub T
);
123 /// An offset to a set of location list offsets in the `.debug_loclists` section.
124 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
125 pub struct DebugLocListsBase
<T
= usize>(pub T
);
127 /// An index into a set of location list offsets in the `.debug_loclists` section.
128 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
129 pub struct DebugLocListsIndex
<T
= usize>(pub T
);
131 /// An offset into the `.debug_macinfo` section.
132 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133 pub struct DebugMacinfoOffset
<T
= usize>(pub T
);
135 /// An offset into the `.debug_macro` section.
136 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
137 pub struct DebugMacroOffset
<T
= usize>(pub T
);
139 /// An offset into either the `.debug_ranges` section or the `.debug_rnglists` section,
140 /// depending on the version of the unit the offset was contained in.
142 /// If this is from a DWARF 4 DWO file, then it must additionally be offset by the
143 /// value of `DW_AT_GNU_ranges_base`. You can use `Dwarf::ranges_offset_from_raw` to do this.
144 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
145 pub struct RawRangeListsOffset
<T
= usize>(pub T
);
147 /// An offset into either the `.debug_ranges` section or the `.debug_rnglists` section,
148 /// depending on the version of the unit the offset was contained in.
149 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
150 pub struct RangeListsOffset
<T
= usize>(pub T
);
152 /// An offset to a set of range list offsets in the `.debug_rnglists` section.
153 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
154 pub struct DebugRngListsBase
<T
= usize>(pub T
);
156 /// An index into a set of range list offsets in the `.debug_rnglists` section.
157 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
158 pub struct DebugRngListsIndex
<T
= usize>(pub T
);
160 /// An offset into the `.debug_str` section.
161 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
162 pub struct DebugStrOffset
<T
= usize>(pub T
);
164 /// An offset to a set of entries in the `.debug_str_offsets` section.
165 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
166 pub struct DebugStrOffsetsBase
<T
= usize>(pub T
);
168 /// An index into a set of entries in the `.debug_str_offsets` section.
169 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
170 pub struct DebugStrOffsetsIndex
<T
= usize>(pub T
);
172 /// An offset into the `.debug_types` section.
173 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
174 pub struct DebugTypesOffset
<T
= usize>(pub T
);
176 /// A type signature as used in the `.debug_types` section.
177 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
178 pub struct DebugTypeSignature(pub u64);
180 /// An offset into the `.debug_frame` section.
181 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
182 pub struct DebugFrameOffset
<T
= usize>(pub T
);
184 impl<T
> From
<T
> for DebugFrameOffset
<T
> {
186 fn from(o
: T
) -> Self {
191 /// An offset into the `.eh_frame` section.
192 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
193 pub struct EhFrameOffset
<T
= usize>(pub T
);
195 impl<T
> From
<T
> for EhFrameOffset
<T
> {
197 fn from(o
: T
) -> Self {
202 /// An offset into the `.debug_info` or `.debug_types` sections.
203 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
204 pub enum UnitSectionOffset
<T
= usize> {
205 /// An offset into the `.debug_info` section.
206 DebugInfoOffset(DebugInfoOffset
<T
>),
207 /// An offset into the `.debug_types` section.
208 DebugTypesOffset(DebugTypesOffset
<T
>),
211 impl<T
> From
<DebugInfoOffset
<T
>> for UnitSectionOffset
<T
> {
212 fn from(offset
: DebugInfoOffset
<T
>) -> Self {
213 UnitSectionOffset
::DebugInfoOffset(offset
)
217 impl<T
> From
<DebugTypesOffset
<T
>> for UnitSectionOffset
<T
> {
218 fn from(offset
: DebugTypesOffset
<T
>) -> Self {
219 UnitSectionOffset
::DebugTypesOffset(offset
)
223 impl<T
> UnitSectionOffset
<T
>
227 /// Returns the `DebugInfoOffset` inside, or `None` otherwise.
228 pub fn as_debug_info_offset(&self) -> Option
<DebugInfoOffset
<T
>> {
230 UnitSectionOffset
::DebugInfoOffset(offset
) => Some(offset
.clone()),
231 UnitSectionOffset
::DebugTypesOffset(_
) => None
,
234 /// Returns the `DebugTypesOffset` inside, or `None` otherwise.
235 pub fn as_debug_types_offset(&self) -> Option
<DebugTypesOffset
<T
>> {
237 UnitSectionOffset
::DebugInfoOffset(_
) => None
,
238 UnitSectionOffset
::DebugTypesOffset(offset
) => Some(offset
.clone()),
243 /// An identifier for a DWARF section.
244 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
246 /// The `.debug_abbrev` section.
248 /// The `.debug_addr` section.
250 /// The `.debug_aranges` section.
252 /// The `.debug_cu_index` section.
254 /// The `.debug_frame` section.
256 /// The `.eh_frame` section.
258 /// The `.eh_frame_hdr` section.
260 /// The `.debug_info` section.
262 /// The `.debug_line` section.
264 /// The `.debug_line_str` section.
266 /// The `.debug_loc` section.
268 /// The `.debug_loclists` section.
270 /// The `.debug_macinfo` section.
272 /// The `.debug_macro` section.
274 /// The `.debug_pubnames` section.
276 /// The `.debug_pubtypes` section.
278 /// The `.debug_ranges` section.
280 /// The `.debug_rnglists` section.
282 /// The `.debug_str` section.
284 /// The `.debug_str_offsets` section.
286 /// The `.debug_tu_index` section.
288 /// The `.debug_types` section.
293 /// Returns the ELF section name for this kind.
294 pub fn name(self) -> &'
static str {
296 SectionId
::DebugAbbrev
=> ".debug_abbrev",
297 SectionId
::DebugAddr
=> ".debug_addr",
298 SectionId
::DebugAranges
=> ".debug_aranges",
299 SectionId
::DebugCuIndex
=> ".debug_cu_index",
300 SectionId
::DebugFrame
=> ".debug_frame",
301 SectionId
::EhFrame
=> ".eh_frame",
302 SectionId
::EhFrameHdr
=> ".eh_frame_hdr",
303 SectionId
::DebugInfo
=> ".debug_info",
304 SectionId
::DebugLine
=> ".debug_line",
305 SectionId
::DebugLineStr
=> ".debug_line_str",
306 SectionId
::DebugLoc
=> ".debug_loc",
307 SectionId
::DebugLocLists
=> ".debug_loclists",
308 SectionId
::DebugMacinfo
=> ".debug_macinfo",
309 SectionId
::DebugMacro
=> ".debug_macro",
310 SectionId
::DebugPubNames
=> ".debug_pubnames",
311 SectionId
::DebugPubTypes
=> ".debug_pubtypes",
312 SectionId
::DebugRanges
=> ".debug_ranges",
313 SectionId
::DebugRngLists
=> ".debug_rnglists",
314 SectionId
::DebugStr
=> ".debug_str",
315 SectionId
::DebugStrOffsets
=> ".debug_str_offsets",
316 SectionId
::DebugTuIndex
=> ".debug_tu_index",
317 SectionId
::DebugTypes
=> ".debug_types",
321 /// Returns the ELF section name for this kind, when found in a .dwo or .dwp file.
322 pub fn dwo_name(self) -> Option
<&'
static str> {
324 SectionId
::DebugAbbrev
=> ".debug_abbrev.dwo",
325 SectionId
::DebugCuIndex
=> ".debug_cu_index",
326 SectionId
::DebugInfo
=> ".debug_info.dwo",
327 SectionId
::DebugLine
=> ".debug_line.dwo",
328 // The debug_loc section can be present in the dwo when using the
329 // GNU split-dwarf extension to DWARF4.
330 SectionId
::DebugLoc
=> ".debug_loc.dwo",
331 SectionId
::DebugLocLists
=> ".debug_loclists.dwo",
332 SectionId
::DebugMacro
=> ".debug_macro.dwo",
333 SectionId
::DebugRngLists
=> ".debug_rnglists.dwo",
334 SectionId
::DebugStr
=> ".debug_str.dwo",
335 SectionId
::DebugStrOffsets
=> ".debug_str_offsets.dwo",
336 SectionId
::DebugTuIndex
=> ".debug_tu_index",
337 SectionId
::DebugTypes
=> ".debug_types.dwo",
343 /// An optionally-provided implementation-defined compilation unit ID to enable
344 /// split DWARF and linking a split compilation unit back together.
345 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
346 pub struct DwoId(pub u64);
348 /// The "type" of file with DWARF debugging information. This determines, among other things,
349 /// which files DWARF sections should be loaded from.
350 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
351 pub enum DwarfFileType
{
352 /// A normal executable or object file.
354 /// A .dwo split DWARF file.
356 // TODO: Supplementary files, .dwps?
359 impl Default
for DwarfFileType
{
360 fn default() -> Self {