Skip to content

Commit c007f2c

Browse files
committed
should be BccError so it works nicely in external
1 parent dba7048 commit c007f2c

File tree

16 files changed

+98
-97
lines changed

16 files changed

+98
-97
lines changed

examples/softirqs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use std::error::Error;
2+
use bcc::BccError;
13
use bcc::core::BPF;
24
use clap::{App, Arg};
3-
use failure::Error;
45

56
use core::sync::atomic::{AtomicBool, Ordering};
67
use std::sync::Arc;
@@ -73,7 +74,7 @@ impl fmt::Display for SoftIRQ {
7374
}
7475
}
7576

76-
fn do_main(runnable: Arc<AtomicBool>) -> Result<(), Error> {
77+
fn do_main(runnable: Arc<AtomicBool>) -> Result<(), BccError> {
7778
let matches = App::new("softirqs")
7879
.about("Reports time spent in IRQ Handlers")
7980
.arg(

src/core/kprobe/v0_4_0.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bcc_sys::bccapi::*;
44

55
use crate::core::make_alphanumeric;
66
use crate::types::MutPointer;
7-
use crate::Error;
7+
use crate::BccError;
88

99
use regex::Regex;
1010

@@ -23,7 +23,7 @@ pub struct Kprobe {
2323
}
2424

2525
impl Kprobe {
26-
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, Error> {
26+
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, BccError> {
2727
let cname = CString::new(name)?;
2828
let cfunction = CString::new(function)?;
2929
let (pid, cpu, group_fd) = (-1, 0, -1);
@@ -42,10 +42,10 @@ impl Kprobe {
4242
};
4343
if ptr.is_null() {
4444
match attach_type {
45-
BPF_PROBE_ENTRY => Err(Error::AttachKprobe {
45+
BPF_PROBE_ENTRY => Err(BccError::AttachKprobe {
4646
name: name.to_string(),
4747
}),
48-
BPF_PROBE_RETURN => Err(Error::AttachKretprobe {
48+
BPF_PROBE_RETURN => Err(BccError::AttachKretprobe {
4949
name: name.to_string(),
5050
}),
5151
_ => unreachable!(),
@@ -59,17 +59,17 @@ impl Kprobe {
5959
}
6060
}
6161

62-
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, Error> {
62+
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, BccError> {
6363
let name = format!("p_{}", &make_alphanumeric(function));
6464
Kprobe::new(&name, BPF_PROBE_ENTRY, function, code)
6565
}
6666

67-
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, Error> {
67+
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, BccError> {
6868
let name = format!("r_{}", &make_alphanumeric(function));
6969
Kprobe::new(&name, BPF_PROBE_RETURN, function, code)
7070
}
7171

72-
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, Error> {
72+
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, BccError> {
7373
let mut fns: Vec<String> = vec![];
7474

7575
enum Section {

src/core/kprobe/v0_6_0.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bcc_sys::bccapi::bpf_probe_attach_type_BPF_PROBE_RETURN as BPF_PROBE_RETURN;
33
use bcc_sys::bccapi::*;
44

55
use crate::core::make_alphanumeric;
6-
use crate::Error;
6+
use crate::BccError;
77

88
use regex::Regex;
99

@@ -21,7 +21,7 @@ pub struct Kprobe {
2121
}
2222

2323
impl Kprobe {
24-
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, Error> {
24+
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, BccError> {
2525
let cname = CString::new(name)?;
2626
let cfunction = CString::new(function)?;
2727
let ptr = unsafe {
@@ -35,10 +35,10 @@ impl Kprobe {
3535
};
3636
if ptr < 0 {
3737
match attach_type {
38-
BPF_PROBE_ENTRY => Err(Error::AttachKprobe {
38+
BPF_PROBE_ENTRY => Err(BccError::AttachKprobe {
3939
name: name.to_string(),
4040
}),
41-
BPF_PROBE_RETURN => Err(Error::AttachKretprobe {
41+
BPF_PROBE_RETURN => Err(BccError::AttachKretprobe {
4242
name: name.to_string(),
4343
}),
4444
_ => unreachable!(),
@@ -52,17 +52,17 @@ impl Kprobe {
5252
}
5353
}
5454

55-
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, Error> {
55+
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, BccError> {
5656
let name = format!("p_{}", &make_alphanumeric(function));
5757
Kprobe::new(&name, BPF_PROBE_ENTRY, function, code)
5858
}
5959

60-
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, Error> {
60+
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, BccError> {
6161
let name = format!("r_{}", &make_alphanumeric(function));
6262
Kprobe::new(&name, BPF_PROBE_RETURN, function, code)
6363
}
6464

65-
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, Error> {
65+
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, BccError> {
6666
let mut fns: Vec<String> = vec![];
6767

6868
enum Section {

src/core/kprobe/v0_9_0.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bcc_sys::bccapi::bpf_probe_attach_type_BPF_PROBE_RETURN as BPF_PROBE_RETURN;
33
use bcc_sys::bccapi::*;
44

55
use crate::core::make_alphanumeric;
6-
use crate::Error;
6+
use crate::BccError;
77

88
use regex::Regex;
99

@@ -21,7 +21,7 @@ pub struct Kprobe {
2121
}
2222

2323
impl Kprobe {
24-
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, Error> {
24+
fn new(name: &str, attach_type: u32, function: &str, code: File) -> Result<Self, BccError> {
2525
let cname = CString::new(name)?;
2626
let cfunction = CString::new(function)?;
2727
let ptr = unsafe {
@@ -36,10 +36,10 @@ impl Kprobe {
3636
};
3737
if ptr < 0 {
3838
match attach_type {
39-
BPF_PROBE_ENTRY => Err(Error::AttachKprobe {
39+
BPF_PROBE_ENTRY => Err(BccError::AttachKprobe {
4040
name: name.to_string(),
4141
}),
42-
BPF_PROBE_RETURN => Err(Error::AttachKretprobe {
42+
BPF_PROBE_RETURN => Err(BccError::AttachKretprobe {
4343
name: name.to_string(),
4444
}),
4545
_ => unreachable!(),
@@ -53,17 +53,17 @@ impl Kprobe {
5353
}
5454
}
5555

56-
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, Error> {
56+
pub fn attach_kprobe(function: &str, code: File) -> Result<Self, BccError> {
5757
let name = format!("p_{}", &make_alphanumeric(function));
5858
Kprobe::new(&name, BPF_PROBE_ENTRY, function, code)
5959
}
6060

61-
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, Error> {
61+
pub fn attach_kretprobe(function: &str, code: File) -> Result<Self, BccError> {
6262
let name = format!("r_{}", &make_alphanumeric(function));
6363
Kprobe::new(&name, BPF_PROBE_RETURN, function, code)
6464
}
6565

66-
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, Error> {
66+
pub fn get_kprobe_functions(event_re: &str) -> Result<Vec<String>, BccError> {
6767
let mut fns: Vec<String> = vec![];
6868

6969
enum Section {

src/core/mod.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use self::uprobe::Uprobe;
1212
use crate::perf::{self, PerfReader};
1313
use crate::symbol::SymbolCache;
1414
use crate::table::Table;
15-
use crate::Error;
15+
use crate::BccError;
1616

1717
use core::ffi::c_void;
1818
use core::sync::atomic::{AtomicPtr, Ordering};
@@ -59,11 +59,11 @@ impl BPF {
5959
feature = "v0_7_0",
6060
feature = "v0_8_0",
6161
))]
62-
pub fn new(code: &str) -> Result<BPF, Error> {
62+
pub fn new(code: &str) -> Result<BPF, BccError> {
6363
let cs = CString::new(code)?;
6464
let ptr = unsafe { bpf_module_create_c_from_string(cs.as_ptr(), 2, ptr::null_mut(), 0) };
6565
if ptr.is_null() {
66-
return Err(Error::Compilation);
66+
return Err(BccError::Compilation);
6767
}
6868

6969
Ok(BPF {
@@ -79,12 +79,12 @@ impl BPF {
7979

8080
// 0.9.0 changes the API for bpf_module_create_c_from_string()
8181
#[cfg(any(feature = "v0_9_0", feature = "v0_10_0",))]
82-
pub fn new(code: &str) -> Result<BPF, Error> {
82+
pub fn new(code: &str) -> Result<BPF, BccError> {
8383
let cs = CString::new(code)?;
8484
let ptr =
8585
unsafe { bpf_module_create_c_from_string(cs.as_ptr(), 2, ptr::null_mut(), 0, true) };
8686
if ptr.is_null() {
87-
return Err(Error::Compilation);
87+
return Err(BccError::Compilation);
8888
}
8989

9090
Ok(BPF {
@@ -105,7 +105,7 @@ impl BPF {
105105
feature = "v0_13_0",
106106
not(feature = "specific"),
107107
))]
108-
pub fn new(code: &str) -> Result<BPF, Error> {
108+
pub fn new(code: &str) -> Result<BPF, BccError> {
109109
let cs = CString::new(code)?;
110110
let ptr = unsafe {
111111
bpf_module_create_c_from_string(
@@ -118,7 +118,7 @@ impl BPF {
118118
)
119119
};
120120
if ptr.is_null() {
121-
return Err(Error::Compilation);
121+
return Err(BccError::Compilation);
122122
}
123123

124124
Ok(BPF {
@@ -143,20 +143,20 @@ impl BPF {
143143
Table::new(id, self.ptr())
144144
}
145145

146-
pub fn load_net(&mut self, name: &str) -> Result<File, Error> {
146+
pub fn load_net(&mut self, name: &str) -> Result<File, BccError> {
147147
self.load(name, bpf_prog_type_BPF_PROG_TYPE_SCHED_ACT, 0, 0)
148148
}
149149

150-
pub fn load_kprobe(&mut self, name: &str) -> Result<File, Error> {
150+
pub fn load_kprobe(&mut self, name: &str) -> Result<File, BccError> {
151151
self.load(name, bpf_prog_type_BPF_PROG_TYPE_KPROBE, 0, 0)
152152
}
153153

154-
pub fn load_uprobe(&mut self, name: &str) -> Result<File, Error> {
154+
pub fn load_uprobe(&mut self, name: &str) -> Result<File, BccError> {
155155
// it's BPF_PROG_TYPE_KPROBE even though it's a uprobe, it's weird
156156
self.load(name, bpf_prog_type_BPF_PROG_TYPE_KPROBE, 0, 0)
157157
}
158158

159-
pub fn load_tracepoint(&mut self, name: &str) -> Result<File, Error> {
159+
pub fn load_tracepoint(&mut self, name: &str) -> Result<File, BccError> {
160160
self.load(name, bpf_prog_type_BPF_PROG_TYPE_TRACEPOINT, 0, 0)
161161
}
162162

@@ -172,7 +172,7 @@ impl BPF {
172172
feature = "v0_13_0",
173173
not(feature = "specific"),
174174
))]
175-
pub fn load_raw_tracepoint(&mut self, name: &str) -> Result<File, Error> {
175+
pub fn load_raw_tracepoint(&mut self, name: &str) -> Result<File, BccError> {
176176
self.load(name, bpf_prog_type_BPF_PROG_TYPE_RAW_TRACEPOINT, 0, 0)
177177
}
178178

@@ -192,7 +192,7 @@ impl BPF {
192192
let license = bpf_module_license(self.ptr());
193193
let version = bpf_module_kern_version(self.ptr());
194194
if start.is_null() {
195-
return Err(Error::Loading {
195+
return Err(BccError::Loading {
196196
name: name.to_string(),
197197
});
198198
}
@@ -210,7 +210,7 @@ impl BPF {
210210
log_buf.capacity() as u32,
211211
);
212212
if fd < 0 {
213-
return Err(Error::Loading {
213+
return Err(BccError::Loading {
214214
name: name.to_string(),
215215
});
216216
}
@@ -240,7 +240,7 @@ impl BPF {
240240
let license = bpf_module_license(self.ptr());
241241
let version = bpf_module_kern_version(self.ptr());
242242
if start.is_null() {
243-
return Err(Error::Loading {
243+
return Err(BccError::Loading {
244244
name: name.to_string(),
245245
});
246246
}
@@ -260,7 +260,7 @@ impl BPF {
260260
log_buf.capacity() as u32,
261261
);
262262
if fd < 0 {
263-
return Err(Error::Loading {
263+
return Err(BccError::Loading {
264264
name: name.to_string(),
265265
});
266266
}
@@ -282,7 +282,7 @@ impl BPF {
282282
prog_type: u32,
283283
log_level: i32,
284284
log_size: u32,
285-
) -> Result<File, Error> {
285+
) -> Result<File, BccError> {
286286
let cname = CString::new(name).unwrap();
287287
unsafe {
288288
let start: *mut bpf_insn =
@@ -291,7 +291,7 @@ impl BPF {
291291
let license = bpf_module_license(self.ptr());
292292
let version = bpf_module_kern_version(self.ptr());
293293
if start.is_null() {
294-
return Err(Error::Loading {
294+
return Err(BccError::Loading {
295295
name: name.to_string(),
296296
});
297297
}
@@ -311,7 +311,7 @@ impl BPF {
311311
log_buf.capacity() as u32,
312312
);
313313
if fd < 0 {
314-
return Err(Error::Loading {
314+
return Err(BccError::Loading {
315315
name: name.to_string(),
316316
});
317317
}
@@ -325,25 +325,25 @@ impl BPF {
325325
symbol: &str,
326326
file: File,
327327
pid: pid_t,
328-
) -> Result<(), Error> {
328+
) -> Result<(), BccError> {
329329
let uprobe = Uprobe::attach_uretprobe(binary_path, symbol, file, pid)?;
330330
self.uprobes.insert(uprobe);
331331
Ok(())
332332
}
333333

334-
pub fn attach_kprobe(&mut self, function: &str, file: File) -> Result<(), Error> {
334+
pub fn attach_kprobe(&mut self, function: &str, file: File) -> Result<(), BccError> {
335335
let kprobe = Kprobe::attach_kprobe(function, file)?;
336336
self.kprobes.insert(kprobe);
337337
Ok(())
338338
}
339339

340-
pub fn attach_kretprobe(&mut self, function: &str, file: File) -> Result<(), Error> {
340+
pub fn attach_kretprobe(&mut self, function: &str, file: File) -> Result<(), BccError> {
341341
let kretprobe = Kprobe::attach_kretprobe(function, file)?;
342342
self.kprobes.insert(kretprobe);
343343
Ok(())
344344
}
345345

346-
pub fn get_kprobe_functions(&mut self, event_re: &str) -> Result<Vec<String>, Error> {
346+
pub fn get_kprobe_functions(&mut self, event_re: &str) -> Result<Vec<String>, BccError> {
347347
Kprobe::get_kprobe_functions(event_re)
348348
}
349349

@@ -353,13 +353,13 @@ impl BPF {
353353
symbol: &str,
354354
file: File,
355355
pid: pid_t,
356-
) -> Result<(), Error> {
356+
) -> Result<(), BccError> {
357357
let uprobe = Uprobe::attach_uprobe(binary_path, symbol, file, pid)?;
358358
self.uprobes.insert(uprobe);
359359
Ok(())
360360
}
361361

362-
pub fn attach_tracepoint(&mut self, subsys: &str, name: &str, file: File) -> Result<(), Error> {
362+
pub fn attach_tracepoint(&mut self, subsys: &str, name: &str, file: File) -> Result<(), BccError> {
363363
let tracepoint = Tracepoint::attach_tracepoint(subsys, name, file)?;
364364
self.tracepoints.insert(tracepoint);
365365
Ok(())
@@ -377,13 +377,13 @@ impl BPF {
377377
feature = "v0_13_0",
378378
not(feature = "specific"),
379379
))]
380-
pub fn attach_raw_tracepoint(&mut self, name: &str, file: File) -> Result<(), Error> {
380+
pub fn attach_raw_tracepoint(&mut self, name: &str, file: File) -> Result<(), BccError> {
381381
let raw_tracepoint = RawTracepoint::attach_raw_tracepoint(name, file)?;
382382
self.raw_tracepoints.insert(raw_tracepoint);
383383
Ok(())
384384
}
385385

386-
pub fn ksymname(&mut self, name: &str) -> Result<u64, Error> {
386+
pub fn ksymname(&mut self, name: &str) -> Result<u64, BccError> {
387387
self.sym_caches
388388
.entry(-1)
389389
.or_insert_with(|| SymbolCache::new(-1));
@@ -408,7 +408,7 @@ impl BPF {
408408
|| self.ksymname("bpf_get_raw_tracepoint").is_ok()
409409
}
410410

411-
pub fn init_perf_map<F>(&mut self, table: Table, cb: F) -> Result<(), Error>
411+
pub fn init_perf_map<F>(&mut self, table: Table, cb: F) -> Result<(), BccError>
412412
where
413413
F: Fn() -> Box<dyn FnMut(&[u8]) + Send>,
414414
{

0 commit comments

Comments
 (0)