From 0ac48c2e0b42f6d8d914c741d3c1a2613800a7a8 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Wed, 7 Apr 2021 13:35:29 +0200 Subject: [PATCH] llmp debug added --- libafl/Cargo.toml | 3 +++ libafl/src/bolts/llmp.rs | 41 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index 72aafb481c..1da0da2f44 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -35,6 +35,7 @@ std = [] # print, sharedmap, ... support anymapdbg = ["serde_json"] # uses serde_json to Debug the anymap trait. Disable for smaller footprint. derive = ["libafl_derive"] # provide derive(SerdeAny) macro. llmp_small_maps = [] # reduces initial map size for llmp +llmp_debug = [] # Enables debug output for LLMP [[example]] name = "llmp_test" @@ -56,6 +57,8 @@ serde_json = { version = "1.0", optional = true, default-features = false, featu #TODO: for llmp brotli = { version = "3.3.0", default-features = false } # brotli compression num_enum = "0.5.1" +backtrace = "0.3" # for llmp_debug + [target.'cfg(unix)'.dependencies] libc = "0.2" # For (*nix) libc nix = "0.20.0" diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index f99823e5f0..cafaa589a2 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -86,6 +86,9 @@ use std::os::unix::{ {io::AsRawFd, prelude::RawFd}, }; +#[cfg(feature = "llmp_debug")] +use backtrace::Backtrace; + #[cfg(all(unix, feature = "std"))] use uds::{UnixListenerExt, UnixSocketAddr, UnixStreamExt}; @@ -785,6 +788,18 @@ where /// listener about it using a EOP message. unsafe fn handle_out_eop(&mut self) -> Result<(), Error> { + #[cfg(feature = "llmp_debug")] + { + let bt = Backtrace::new(); + let shm = self.out_maps.last().unwrap(); + println!( + "LLMP_DEBUG: End of page reached for map {} with len {}, sending EOP, bt: {:?}", + shm.shmem.shm_str(), + shm.shmem.map().len(), + bt + ); + } + let old_map = self.out_maps.last_mut().unwrap().page_mut(); // Create a new shard page. @@ -1024,8 +1039,12 @@ where // Mark the new page save to unmap also (it's mapped by us, the broker now) ptr::write_volatile(&mut (*page).save_to_unmap, 1); - #[cfg(feature = "std")] - dbg!("Got a new recv map", self.current_recv_map.shmem.shm_str()); + #[cfg(feature = "llmp_debug")] + println!( + "LLMP_DEBUG: Got a new recv map {} with len {:?}", + self.current_recv_map.shmem.shm_str(), + self.current_recv_map.shmem.map().len() + ); // After we mapped the new page, return the next message, if available return self.recv(); } @@ -1135,6 +1154,13 @@ where { /// Creates a new page, initializing the passed shared mem struct pub fn new(sender: u32, mut new_map: SH) -> Self { + #[cfg(feature = "llmp_debug")] + println!( + "LLMP_DEBUG: Initializing map on {} with size {}", + new_map.shm_str(), + new_map.map().len() + ); + unsafe { _llmp_page_init(&mut new_map, sender, false); } @@ -1143,6 +1169,17 @@ where /// Maps and wraps an existing pub fn existing(existing_map: SH) -> Self { + #[cfg(feature = "llmp_debug")] + { + let bt = Backtrace::new(); + println!( + "LLMP_DEBUG: Using existing map {} with size {}, bt: {:?}", + existing_map.shm_str(), + existing_map.map().len(), + bt + ); + } + let ret = Self { shmem: existing_map, };