diff --git a/aya-log/ebpf/Cargo.toml b/aya-log/ebpf/Cargo.toml index 4a122eef..d29c15e0 100644 --- a/aya-log/ebpf/Cargo.toml +++ b/aya-log/ebpf/Cargo.toml @@ -1,2 +1,12 @@ [workspace] -members = ["aya-log-ebpf", "aya-log-ebpf-macros"] +members = ["aya-log-ebpf", "aya-log-ebpf-macros", "example"] + + +[profile.dev] +panic = "abort" +debug = 1 +opt-level = 2 +overflow-checks = false + +[profile.release] +panic = "abort" diff --git a/aya-log/ebpf/aya-log-ebpf-macros/Cargo.toml b/aya-log/ebpf/aya-log-ebpf-macros/Cargo.toml index 8e0262b0..9247eb82 100644 --- a/aya-log/ebpf/aya-log-ebpf-macros/Cargo.toml +++ b/aya-log/ebpf/aya-log-ebpf-macros/Cargo.toml @@ -9,4 +9,4 @@ quote = "1.0" syn = "1.0" [lib] -proc-macro = true \ No newline at end of file +proc-macro = true diff --git a/aya-log/ebpf/aya-log-ebpf/Cargo.toml b/aya-log/ebpf/aya-log-ebpf/Cargo.toml index 9ee4e548..5b716747 100644 --- a/aya-log/ebpf/aya-log-ebpf/Cargo.toml +++ b/aya-log/ebpf/aya-log-ebpf/Cargo.toml @@ -10,12 +10,3 @@ aya-log-ebpf-macros = { path = "../aya-log-ebpf-macros" } [lib] path = "src/lib.rs" - -[profile.dev] -panic = "abort" -debug = 1 -opt-level = 2 -overflow-checks = false - -[profile.release] -panic = "abort" \ No newline at end of file diff --git a/aya-log/ebpf/aya-log-ebpf/src/lib.rs b/aya-log/ebpf/aya-log-ebpf/src/lib.rs index b0da7f7f..6faa949d 100644 --- a/aya-log/ebpf/aya-log-ebpf/src/lib.rs +++ b/aya-log/ebpf/aya-log-ebpf/src/lib.rs @@ -1,9 +1,11 @@ #![no_std] use aya_bpf::{ macros::map, - maps::{PerCpuArray, PerfEventByteArray} + maps::{PerCpuArray, PerfEventByteArray}, +}; +pub use aya_log_common::{ + write_record_header, write_record_message, Level, WriteToBuf, LOG_BUF_CAPACITY, }; -pub use aya_log_common::{Level, LOG_BUF_CAPACITY, write_record_header, write_record_message, WriteToBuf}; pub use aya_log_ebpf_macros::{debug, error, info, log, trace, warn}; #[doc(hidden)] diff --git a/aya-log/ebpf/example/Cargo.toml b/aya-log/ebpf/example/Cargo.toml new file mode 100644 index 00000000..e78d7049 --- /dev/null +++ b/aya-log/ebpf/example/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "example" +version = "0.1.0" +edition = "2018" +publish = false + +[dependencies] +aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" } +aya-log-ebpf = { path = "../aya-log-ebpf" } + +[[bin]] +name = "example" +path = "src/main.rs" diff --git a/aya-log/ebpf/example/src/main.rs b/aya-log/ebpf/example/src/main.rs new file mode 100644 index 00000000..b43b5364 --- /dev/null +++ b/aya-log/ebpf/example/src/main.rs @@ -0,0 +1,22 @@ +#![no_std] +#![no_main] + +use aya_bpf::{macros::tracepoint, programs::TracePointContext, BpfContext}; +use aya_log_ebpf::{debug, error, info, trace, warn}; + +#[tracepoint] +pub fn example(ctx: TracePointContext) -> u32 { + error!(&ctx, "this is an error message 🚨"); + warn!(&ctx, "this is a warning message ⚠ī¸"); + info!(&ctx, "this is an info message ℹī¸"); + debug!(&ctx, "this is a debug message ī¸đŸ"); + trace!(&ctx, "this is a trace message 🔍"); + let pid = ctx.pid(); + info!(&ctx, "a message with args PID: {}", pid); + 0 +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + unsafe { core::hint::unreachable_unchecked() } +}