diff --git a/src/bpf.rs b/src/bpf.rs
index 04364540..0573cca1 100644
--- a/src/bpf.rs
+++ b/src/bpf.rs
@@ -2,13 +2,15 @@ use std::{
cell::{Ref, RefCell, RefMut},
collections::HashMap,
convert::TryFrom,
+ io,
};
use thiserror::Error;
use crate::{
maps::{Map, MapError},
- obj::{BtfRelocationError, Object, ParseError, RelocationError},
+ obj::btf::RelocationError as BtfRelocationError,
+ obj::{btf::BtfError, Object, ParseError, RelocationError},
programs::{KProbe, Program, ProgramData, ProgramError, SocketFilter, TracePoint, UProbe, Xdp},
syscalls::bpf_map_update_elem_ptr,
};
@@ -141,17 +143,24 @@ impl Bpf {
#[derive(Debug, Error)]
pub enum BpfError {
+ #[error("IO error: {0}")]
+ IO(#[from] io::Error),
+
#[error("error parsing BPF object: {0}")]
ParseError(#[from] ParseError),
+
+ #[error("BTF error: {0}")]
+ BtfError(#[from] BtfError),
+
#[error("error relocating BPF object: {0}")]
RelocationError(#[from] RelocationError),
- #[error("BTF error: {error}")]
- BtfRelocationError {
- #[from]
- error: BtfRelocationError,
- },
+
+ #[error(transparent)]
+ BtfRelocationError(#[from] BtfRelocationError),
+
#[error("map error: {0}")]
MapError(#[from] MapError),
+
#[error("program error: {0}")]
ProgramError(#[from] ProgramError),
}
diff --git a/src/maps/perf_map.rs b/src/maps/perf_map.rs
index 26628bea..48a3f60f 100644
--- a/src/maps/perf_map.rs
+++ b/src/maps/perf_map.rs
@@ -261,17 +261,11 @@ pub enum PerfMapError {
#[error("invalid cpu {cpu_id}")]
InvalidCpu { cpu_id: u32 },
- #[error("map error: {map_error}")]
- MapError {
- #[from]
- map_error: MapError,
- },
+ #[error("map error: {0}")]
+ MapError(#[from] MapError),
- #[error("perf buffer error: {buf_error}")]
- PerfBufferError {
- #[from]
- buf_error: PerfBufferError,
- },
+ #[error("perf buffer error: {0}")]
+ PerfBufferError(#[from] PerfBufferError),
#[error("bpf_map_update_elem failed: {io_error}")]
UpdateElementFailed {
diff --git a/src/obj/btf/relocation.rs b/src/obj/btf/relocation.rs
index 12e355b6..4ab2fb10 100644
--- a/src/obj/btf/relocation.rs
+++ b/src/obj/btf/relocation.rs
@@ -19,26 +19,18 @@ use crate::{
},
Btf, BtfError, Object, Program,
},
+ BpfError,
};
#[derive(Error, Debug)]
pub enum RelocationError {
- #[error("{error}")]
- BtfError {
- #[from]
- error: BtfError,
- },
-
- #[error("{error}")]
- IOError {
- #[from]
- error: io::Error,
- },
+ #[error(transparent)]
+ IOError(#[from] io::Error),
#[error("section `{name}` not found")]
SectionNotFound { name: String },
- #[error("invalid BTF relocation access string {access_str}")]
+ #[error("invalid relocation access string {access_str}")]
InvalidAccessString { access_str: String },
#[error("invalid instruction index #{index} referenced by relocation #{relocation_number} in section `{section_name}`")]
@@ -161,7 +153,7 @@ impl Relocation {
}
impl Object {
- pub fn relocate_btf(&mut self) -> Result<(), RelocationError> {
+ pub fn relocate_btf(&mut self) -> Result<(), BpfError> {
let (local_btf, btf_ext) = match (&self.btf, &self.btf_ext) {
(Some(btf), Some(btf_ext)) => (btf, btf_ext),
_ => return Ok(()),
@@ -203,7 +195,7 @@ impl Object {
num_instructions: instructions.len(),
section_name: section_name.to_string(),
relocation_number: rel.number,
- });
+ })?;
}
let local_ty = local_btf.type_by_id(rel.type_id)?;
@@ -262,7 +254,7 @@ impl Object {
return Err(RelocationError::ConflictingCandidates {
type_name: local_name.to_string(),
candidates: conflicts,
- });
+ })?;
}
target_comp_rel
} else {
@@ -314,7 +306,7 @@ fn find_candidates<'target>(
fn match_candidate<'target>(
local_spec: &AccessSpec,
candidate: &'target Candidate,
-) -> Result