1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
use std::error::Error as StdError;
use std::fmt;
pub(crate) type Result<T> = std::result::Result<T, Error>;
pub trait AsDynError<'a> {
fn as_dyn_error(&self) -> &(dyn StdError + 'a);
}
impl<'a, T: StdError + 'a> AsDynError<'a> for T {
#[inline]
fn as_dyn_error(&self) -> &(dyn StdError + 'a) {
self
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
ReadInput(std::io::Error),
ParseFileKind(object::Error),
ParseObjectFile(object::Error),
ParseArchiveFile(object::Error),
ParseArchiveMember(object::Error),
InvalidInputKind,
DecompressData(object::Error),
NamelessSection(object::Error, usize),
RelocationWithInvalidSymbol(String, usize),
MultipleRelocations(String, usize),
UnsupportedRelocation(String, usize),
MissingDwoName(u64),
NoCompilationUnits,
NoDie,
TopLevelDieNotUnit,
MissingRequiredSection(&'static str),
ParseUnitAbbreviations(gimli::read::Error),
ParseUnitAttribute(gimli::read::Error),
ParseUnitHeader(gimli::read::Error),
ParseUnit(gimli::read::Error),
IncompatibleIndexVersion(String, u16, u16),
OffsetAtIndex(gimli::read::Error, u64),
StrAtOffset(gimli::read::Error, usize),
ParseIndex(gimli::read::Error, String),
UnitNotInIndex(u64),
RowNotInIndex(gimli::read::Error, u32),
SectionNotInRow,
EmptyUnit(u64),
MultipleDebugInfoSection,
MultipleDebugTypesSection,
NotSplitUnit,
DuplicateUnit(u64),
MissingReferencedUnit(u64),
NoOutputObjectCreated,
MixedInputEncodings,
Io(std::io::Error),
ObjectRead(object::Error),
ObjectWrite(object::write::Error),
GimliRead(gimli::read::Error),
GimliWrite(gimli::write::Error),
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::ReadInput(source) => Some(source.as_dyn_error()),
Error::ParseFileKind(source) => Some(source.as_dyn_error()),
Error::ParseObjectFile(source) => Some(source.as_dyn_error()),
Error::ParseArchiveFile(source) => Some(source.as_dyn_error()),
Error::ParseArchiveMember(source) => Some(source.as_dyn_error()),
Error::InvalidInputKind => None,
Error::DecompressData(source) => Some(source.as_dyn_error()),
Error::NamelessSection(source, _) => Some(source.as_dyn_error()),
Error::RelocationWithInvalidSymbol(_, _) => None,
Error::MultipleRelocations(_, _) => None,
Error::UnsupportedRelocation(_, _) => None,
Error::MissingDwoName(_) => None,
Error::NoCompilationUnits => None,
Error::NoDie => None,
Error::TopLevelDieNotUnit => None,
Error::MissingRequiredSection(_) => None,
Error::ParseUnitAbbreviations(source) => Some(source.as_dyn_error()),
Error::ParseUnitAttribute(source) => Some(source.as_dyn_error()),
Error::ParseUnitHeader(source) => Some(source.as_dyn_error()),
Error::ParseUnit(source) => Some(source.as_dyn_error()),
Error::IncompatibleIndexVersion(_, _, _) => None,
Error::OffsetAtIndex(source, _) => Some(source.as_dyn_error()),
Error::StrAtOffset(source, _) => Some(source.as_dyn_error()),
Error::ParseIndex(source, _) => Some(source.as_dyn_error()),
Error::UnitNotInIndex(_) => None,
Error::RowNotInIndex(source, _) => Some(source.as_dyn_error()),
Error::SectionNotInRow => None,
Error::EmptyUnit(_) => None,
Error::MultipleDebugInfoSection => None,
Error::MultipleDebugTypesSection => None,
Error::NotSplitUnit => None,
Error::DuplicateUnit(_) => None,
Error::MissingReferencedUnit(_) => None,
Error::NoOutputObjectCreated => None,
Error::MixedInputEncodings => None,
Error::Io(transparent) => StdError::source(transparent.as_dyn_error()),
Error::ObjectRead(transparent) => StdError::source(transparent.as_dyn_error()),
Error::ObjectWrite(transparent) => StdError::source(transparent.as_dyn_error()),
Error::GimliRead(transparent) => StdError::source(transparent.as_dyn_error()),
Error::GimliWrite(transparent) => StdError::source(transparent.as_dyn_error()),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::ReadInput(_) => write!(f, "Failed to read input file"),
Error::ParseFileKind(_) => write!(f, "Failed to parse input file kind"),
Error::ParseObjectFile(_) => write!(f, "Failed to parse input object file"),
Error::ParseArchiveFile(_) => write!(f, "Failed to parse input archive file"),
Error::ParseArchiveMember(_) => write!(f, "Failed to parse archive member"),
Error::InvalidInputKind => write!(f, "Input is not an archive or elf object"),
Error::DecompressData(_) => write!(f, "Failed to decompress compressed section"),
Error::NamelessSection(_, offset) => {
write!(f, "Section without name at offset 0x{:08x}", offset)
}
Error::RelocationWithInvalidSymbol(section, offset) => write!(
f,
"Relocation with invalid symbol for section `{}` at offset 0x{:08x}",
section, offset
),
Error::MultipleRelocations(section, offset) => write!(
f,
"Multiple relocations for section `{}` at offset 0x{:08x}",
section, offset
),
Error::UnsupportedRelocation(section, offset) => write!(
f,
"Unsupported relocation for section {} at offset 0x{:08x}",
section, offset
),
Error::MissingDwoName(id) => {
write!(f, "Missing path attribute to DWARF object (0x{:08x})", id)
}
Error::NoCompilationUnits => {
write!(f, "Input object has no compilation units")
}
Error::NoDie => {
write!(f, "No top-level debugging information entry in compilation/type unit")
}
Error::TopLevelDieNotUnit => {
write!(f, "Top-level debugging information entry is not a compilation/type unit")
}
Error::MissingRequiredSection(section) => {
write!(f, "Input object missing required section `{}`", section)
}
Error::ParseUnitAbbreviations(_) => write!(f, "Failed to parse unit abbreviations"),
Error::ParseUnitAttribute(_) => write!(f, "Failed to parse unit attribute"),
Error::ParseUnitHeader(_) => write!(f, "Failed to parse unit header"),
Error::ParseUnit(_) => write!(f, "Failed to parse unit"),
Error::IncompatibleIndexVersion(section, format, actual) => {
write!(
f,
"Incompatible `{}` index version: found version {}, expected version {}",
section, actual, format
)
}
Error::OffsetAtIndex(_, index) => {
write!(f, "Read offset at index {} of `.debug_str_offsets.dwo` section", index)
}
Error::StrAtOffset(_, offset) => {
write!(f, "Read string at offset 0x{:08x} of `.debug_str.dwo` section", offset)
}
Error::ParseIndex(_, section) => {
write!(f, "Failed to parse `{}` index section", section)
}
Error::UnitNotInIndex(unit) => {
write!(f, "Unit 0x{0:08x} from input package is not in its index", unit)
}
Error::RowNotInIndex(_, row) => {
write!(f, "Row {0} found in index's hash table not present in index", row)
}
Error::SectionNotInRow => write!(f, "Section not found in unit's row in index"),
Error::EmptyUnit(unit) => {
write!(f, "Unit 0x{:08x} in input DWARF object with no data", unit)
}
Error::MultipleDebugInfoSection => {
write!(f, "Multiple `.debug_info.dwo` sections")
}
Error::MultipleDebugTypesSection => {
write!(f, "Multiple `.debug_types.dwo` sections in a package")
}
Error::NotSplitUnit => {
write!(f, "Regular compilation unit in object (missing dwo identifier)")
}
Error::DuplicateUnit(unit) => {
write!(f, "Duplicate split compilation unit (0x{:08x})", unit)
}
Error::MissingReferencedUnit(unit) => {
write!(f, "Unit 0x{:08x} referenced by executable was not found", unit)
}
Error::NoOutputObjectCreated => write!(f, "No output object was created from inputs"),
Error::MixedInputEncodings => write!(f, "Input objects haved mixed encodings"),
Error::Io(e) => fmt::Display::fmt(e, f),
Error::ObjectRead(e) => fmt::Display::fmt(e, f),
Error::ObjectWrite(e) => fmt::Display::fmt(e, f),
Error::GimliRead(e) => fmt::Display::fmt(e, f),
Error::GimliWrite(e) => fmt::Display::fmt(e, f),
}
}
}
impl From<std::io::Error> for Error {
fn from(source: std::io::Error) -> Self {
Error::Io(source)
}
}
impl From<object::Error> for Error {
fn from(source: object::Error) -> Self {
Error::ObjectRead(source)
}
}
impl From<object::write::Error> for Error {
fn from(source: object::write::Error) -> Self {
Error::ObjectWrite(source)
}
}
impl From<gimli::read::Error> for Error {
fn from(source: gimli::read::Error) -> Self {
Error::GimliRead(source)
}
}
impl From<gimli::write::Error> for Error {
fn from(source: gimli::write::Error) -> Self {
Error::GimliWrite(source)
}
}