diff --git a/ckb-debugger/src/main.rs b/ckb-debugger/src/main.rs index 932ad78..6b9c5d6 100644 --- a/ckb-debugger/src/main.rs +++ b/ckb-debugger/src/main.rs @@ -169,6 +169,13 @@ fn main() -> Result<(), Box> { .takes_value(true) .conflicts_with_all(&["bin", "tx-file"]), ) + .arg( + Arg::with_name("disable-overlapping-detection") + .long("disable-overlapping-detection") + .required(false) + .takes_value(false) + .help("Set to true to disable overlapping detection between stack and heap"), + ) .get_matches(); let matches_decode = matches.value_of_lossy("decode"); @@ -371,7 +378,11 @@ fn main() -> Result<(), Box> { }; if matches_mode == "full" { - let mut machine = PProfMachine::new(machine_init(), Profile::new(&verifier_program)?); + let mut machine = PProfMachine::new( + machine_init(), + Profile::new(&verifier_program)? + .set_disable_overlapping_detection(matches.is_present("disable-overlapping-detection")), + ); let bytes = machine.load_program(&verifier_program, &verifier_args_byte)?; let transferred_cycles = transferred_byte_cycles(bytes); machine.machine.add_cycles(transferred_cycles)?; @@ -405,6 +416,7 @@ fn main() -> Result<(), Box> { machine.profile.display_stacktrace(" ", &mut std::io::stdout()); println!("Error:"); println!(" {:?}", err); + println!("Machine: {}", machine.machine); } } return Ok(()); diff --git a/ckb-vm-pprof/src/lib.rs b/ckb-vm-pprof/src/lib.rs index 59b348f..4fe6499 100644 --- a/ckb-vm-pprof/src/lib.rs +++ b/ckb-vm-pprof/src/lib.rs @@ -129,6 +129,7 @@ pub struct Profile { cache_fun: HashMap, sbrk_addr: u64, sbrk_heap: u64, + disable_overlapping_detection: bool, } impl Profile { @@ -146,9 +147,15 @@ impl Profile { cache_fun: goblin_fun(&elf), sbrk_addr: goblin_get_sym(&elf, "_sbrk"), sbrk_heap: goblin_get_sym(&elf, "_end"), + disable_overlapping_detection: false, }) } + pub fn set_disable_overlapping_detection(mut self, disable_detection: bool) -> Self { + self.disable_overlapping_detection = disable_detection; + self + } + pub fn get_tag(&mut self, addr: u64) -> Tags { if let Some(data) = self.cache_tag.get(&addr) { return data.clone(); @@ -205,12 +212,14 @@ impl Profile { decoder: &mut Decoder, ) -> Result<(), Error> { let pc = machine.pc().to_u64(); - let sp = machine.registers()[SP].to_u64(); - if sp < self.sbrk_heap { - return Err(Error::External(format!( - "Heap and stack overlapping sp={} heap={}", - sp, self.sbrk_heap - ))); + if !self.disable_overlapping_detection { + let sp = machine.registers()[SP].to_u64(); + if sp < self.sbrk_heap { + return Err(Error::External(format!( + "Heap and stack overlapping sp={} heap={}", + sp, self.sbrk_heap + ))); + } } let inst = decoder.decode(machine.memory_mut(), pc)?; let opcode = ckb_vm::instructions::extract_opcode(inst);