From 1441f46e62909fa4d4724f645b91ee4da40104eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 7 Oct 2024 18:12:39 +0200 Subject: [PATCH] WIP: debug prints --- src/elf.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/elf.rs b/src/elf.rs index cf5c66041..e8856f8af 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -377,6 +377,7 @@ impl Executable { let bytes = if is_memory_aligned(bytes.as_ptr() as usize, HOST_ALIGN) { bytes } else { + // debug_assert!(false); aligned = AlignedMemory::<{ HOST_ALIGN }>::from_slice(bytes); aligned.as_slice() }; @@ -405,6 +406,21 @@ impl Executable { bytes: &[u8], loader: Arc>, ) -> Result { + println!("{:X?}", elf.file_header()); + for header in elf.program_header_table().iter() { + println!("{:X?}", header); + } + for header in elf.section_header_table().iter() { + println!( + "{} {:X?}", + elf.section_name(header.sh_name) + .ok() + .and_then(|bytes| std::str::from_utf8(bytes).ok()) + .map(|str| str.to_string()) + .unwrap(), + header + ); + } const EXPECTED_PROGRAM_HEADERS: [(u32, u32, u64); 4] = [ (PT_LOAD, PF_R | PF_X, 0), // byte code (PT_LOAD, PF_R, ebpf::MM_PROGRAM_START), // read only data @@ -492,6 +508,15 @@ impl Executable { .saturating_sub(text_section.sh_addr) .checked_div(ebpf::INSN_SIZE as u64) .unwrap_or_default() as usize; + println!( + "{} {:X}", + elf.symbol_name(symbol.st_name as Elf64Word) + .ok() + .and_then(|bytes| std::str::from_utf8(bytes).ok()) + .map(|str| str.to_string()) + .unwrap(), + target_pc + ); function_registry .register_function( target_pc as u32,