dump the elf shared object into the debug output directory (#119)

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2024-11-21 21:48:42 +01:00
committed by GitHub
parent 89ddfb28c8
commit 87f2bcefb3
5 changed files with 26 additions and 9 deletions
@@ -15,6 +15,8 @@ pub enum IRType {
LLVM,
/// Whether to dump the assembly code.
Assembly,
/// Whether to dump the ELF shared object
SO,
/// Whether to jump JSON
#[cfg(debug_assertions)]
JSON,
@@ -31,6 +33,7 @@ impl IRType {
Self::Assembly => revive_common::EXTENSION_POLKAVM_ASSEMBLY,
#[cfg(debug_assertions)]
Self::JSON => revive_common::EXTENSION_JSON,
Self::SO => revive_common::EXTENSION_SHARED_OBJECT,
}
}
}
@@ -94,6 +94,16 @@ impl DebugConfig {
Ok(())
}
/// Dumps the code object.
pub fn dump_object(&self, contract_path: &str, code: &[u8]) -> anyhow::Result<()> {
let mut file_path = self.output_directory.to_owned();
let full_file_name = Self::full_file_name(contract_path, None, IRType::SO);
file_path.push(full_file_name);
std::fs::write(file_path, code)?;
Ok(())
}
/// Dumps the stage output as a json file suitable for use with --recursive-process
#[cfg(debug_assertions)]
pub fn dump_stage_output(
@@ -296,11 +296,17 @@ where
)
})?;
let bytecode = revive_linker::link(buffer.as_slice())?;
let shared_object = revive_linker::link(buffer.as_slice())?;
if let Some(ref debug_config) = self.debug_config {
debug_config.dump_object(contract_path, &shared_object)?;
}
let polkavm_bytecode = revive_linker::polkavm_linker(shared_object)?;
let build = match crate::polkavm::build_assembly_text(
contract_path,
&bytecode,
&polkavm_bytecode,
metadata_hash,
self.debug_config(),
) {