|
|
@ -3,6 +3,8 @@ use std::{
|
|
|
|
path::PathBuf,
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub const LE_GLOBAL_SYMBOL_DUPLICATE: u32 = 701;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
pub enum Error {
|
|
|
|
IOError(Box<dyn std::error::Error>),
|
|
|
|
IOError(Box<dyn std::error::Error>),
|
|
|
@ -11,19 +13,24 @@ pub enum Error {
|
|
|
|
InvalidSectionData,
|
|
|
|
InvalidSectionData,
|
|
|
|
ParseError(Box<dyn std::error::Error>),
|
|
|
|
ParseError(Box<dyn std::error::Error>),
|
|
|
|
TryFromIntError,
|
|
|
|
TryFromIntError,
|
|
|
|
LinkingError(Trace),
|
|
|
|
LinkingError(LinkError),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// "backtrace" for error origin
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct Trace {
|
|
|
|
pub struct Trace {
|
|
|
|
pub code: u32, // specific trace code, should be >= 700
|
|
|
|
|
|
|
|
pub message: &'static str,
|
|
|
|
|
|
|
|
pub origin: PathBuf,
|
|
|
|
pub origin: PathBuf,
|
|
|
|
pub offset: u64, // 0 indicates unknown/invalid
|
|
|
|
pub offset: u64, // 0 indicates unknown/invalid
|
|
|
|
pub source_info: Option<Box<dyn SourceInfo>>,
|
|
|
|
pub source_info: Option<Box<dyn SourceInfo>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// "backtrace" for error origin
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
|
|
|
|
pub struct LinkError {
|
|
|
|
|
|
|
|
pub code: u32, // specific trace code, should be >= 700
|
|
|
|
|
|
|
|
pub message: String,
|
|
|
|
|
|
|
|
pub traces: Vec<Trace>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
impl Error {
|
|
|
|
// used for programmatic input/output handling, IDE's etc.
|
|
|
|
// used for programmatic input/output handling, IDE's etc.
|
|
|
|
pub fn code(&self) -> u32 {
|
|
|
|
pub fn code(&self) -> u32 {
|
|
|
@ -34,7 +41,7 @@ impl Error {
|
|
|
|
Error::InvalidSectionData => 400,
|
|
|
|
Error::InvalidSectionData => 400,
|
|
|
|
Error::ParseError(_) => 500,
|
|
|
|
Error::ParseError(_) => 500,
|
|
|
|
Error::TryFromIntError => 600,
|
|
|
|
Error::TryFromIntError => 600,
|
|
|
|
Error::LinkingError(trace) => trace.code,
|
|
|
|
Error::LinkingError(le) => le.code,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,24 +80,26 @@ impl Display for Error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Display for Trace {
|
|
|
|
impl Display for LinkError {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let mut new_line = ""; // new line in case of previous info only
|
|
|
|
let mut new_line = ""; // new line in case of previous info only
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(origin) = self.origin.to_str() {
|
|
|
|
for trace in &self.traces {
|
|
|
|
|
|
|
|
if let Some(origin) = trace.origin.to_str() {
|
|
|
|
new_line = "\n";
|
|
|
|
new_line = "\n";
|
|
|
|
write!(f, "\n\t{}", origin)?;
|
|
|
|
write!(f, "\n\t{}", origin)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if self.offset > 0 {
|
|
|
|
if trace.offset > 0 {
|
|
|
|
new_line = "\n";
|
|
|
|
new_line = "\n";
|
|
|
|
write!(f, "\n@offset: {}", self.offset)?;
|
|
|
|
write!(f, "\n@offset: {}", trace.offset)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(si) = &self.source_info {
|
|
|
|
if let Some(si) = &trace.source_info {
|
|
|
|
new_line = "\n";
|
|
|
|
new_line = "\n";
|
|
|
|
write!(f, "\n{}", si)?;
|
|
|
|
write!(f, "\n{}", si)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
write!(f, "{}{}", new_line, self.message)
|
|
|
|
write!(f, "{}{}", new_line, self.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|