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_info` section.
103 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
104 pub struct DebugInfoOffset
<T
= usize>(pub T
);
106 /// An offset into the `.debug_line` section.
107 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
108 pub struct DebugLineOffset
<T
= usize>(pub T
);
110 /// An offset into the `.debug_line_str` section.
111 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
112 pub struct DebugLineStrOffset
<T
= usize>(pub T
);
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
);
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
);
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
);
127 /// An offset into the `.debug_macinfo` section.
128 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
129 pub struct DebugMacinfoOffset
<T
= usize>(pub T
);
131 /// An offset into the `.debug_macro` section.
132 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133 pub struct DebugMacroOffset
<T
= usize>(pub T
);
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
);
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
);
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
);
148 /// An offset into the `.debug_str` section.
149 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
150 pub struct DebugStrOffset
<T
= usize>(pub T
);
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
);
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
);
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
);
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);
168 /// An offset into the `.debug_frame` section.
169 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
170 pub struct DebugFrameOffset
<T
= usize>(pub T
);
172 impl<T
> From
<T
> for DebugFrameOffset
<T
> {
174 fn from(o
: T
) -> Self {
179 /// An offset into the `.eh_frame` section.
180 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
181 pub struct EhFrameOffset
<T
= usize>(pub T
);
183 impl<T
> From
<T
> for EhFrameOffset
<T
> {
185 fn from(o
: T
) -> Self {
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
>),
199 impl<T
> From
<DebugInfoOffset
<T
>> for UnitSectionOffset
<T
> {
200 fn from(offset
: DebugInfoOffset
<T
>) -> Self {
201 UnitSectionOffset
::DebugInfoOffset(offset
)
205 impl<T
> From
<DebugTypesOffset
<T
>> for UnitSectionOffset
<T
> {
206 fn from(offset
: DebugTypesOffset
<T
>) -> Self {
207 UnitSectionOffset
::DebugTypesOffset(offset
)
211 impl<T
> UnitSectionOffset
<T
>
215 /// Returns the `DebugInfoOffset` inside, or `None` otherwise.
216 pub fn as_debug_info_offset(&self) -> Option
<DebugInfoOffset
<T
>> {
218 UnitSectionOffset
::DebugInfoOffset(offset
) => Some(offset
.clone()),
219 UnitSectionOffset
::DebugTypesOffset(_
) => None
,
222 /// Returns the `DebugTypesOffset` inside, or `None` otherwise.
223 pub fn as_debug_types_offset(&self) -> Option
<DebugTypesOffset
<T
>> {
225 UnitSectionOffset
::DebugInfoOffset(_
) => None
,
226 UnitSectionOffset
::DebugTypesOffset(offset
) => Some(offset
.clone()),
231 /// An identifier for a DWARF section.
232 #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
234 /// The `.debug_abbrev` section.
236 /// The `.debug_addr` section.
238 /// The `.debug_aranges` section.
240 /// The `.debug_frame` section.
242 /// The `.eh_frame` section.
244 /// The `.eh_frame_hdr` section.
246 /// The `.debug_info` section.
248 /// The `.debug_line` section.
250 /// The `.debug_line_str` section.
252 /// The `.debug_loc` section.
254 /// The `.debug_loclists` section.
256 /// The `.debug_macinfo` section.
258 /// The `.debug_macro` section.
260 /// The `.debug_pubnames` section.
262 /// The `.debug_pubtypes` section.
264 /// The `.debug_ranges` section.
266 /// The `.debug_rnglists` section.
268 /// The `.debug_str` section.
270 /// The `.debug_str_offsets` section.
272 /// The `.debug_types` section.
277 /// Returns the ELF section name for this kind.
278 pub fn name(self) -> &'
static str {
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",
303 /// Returns the ELF section name for this kind, when found in a .dwo file.
304 pub fn dwo_name(self) -> Option
<&'
static str> {
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",
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);
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.
333 /// A .dwo split DWARF file.
335 // TODO: Supplementary files, .dwps?
338 impl Default
for DwarfFileType
{
339 fn default() -> Self {