Skip to content

Commit

Permalink
lib/utils/debug: add settings for translation step
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Obst committed Jul 23, 2024
1 parent 9a7a8f3 commit b0172a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/caller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ use std::path::PathBuf;
pub enum CliDebugMode {
/// Result of the Pointer Inference computation.
Pi,
/// Earliest possible IR form of the program.
IrEarly,
/// IR after blocks within each function have been normal ordered.
IrFnBlksSorted,
/// IR after non-returning external functions have been marked.
IrNonRetExt,
/// IR after existing, referenced blocks have bee inlined into returning
/// functions.
IrInlined,
/// IR after subregister substitution pass.
IrSubSub,
/// IR after artificial sinks have been added.
IrCfPatched,
/// Unnormalized IR form of the program.
IrRaw,
/// Normalized IR form of the program.
Expand All @@ -39,6 +52,12 @@ impl From<&CliDebugMode> for debug::Stage {
use CliDebugMode::*;
match mode {
Pi => debug::Stage::Pi,
IrEarly => debug::Stage::Ir(debug::IrForm::Early),
IrFnBlksSorted => debug::Stage::Ir(debug::IrForm::FnBlksSorted),
IrNonRetExt => debug::Stage::Ir(debug::IrForm::NonRetExtFunctionsMarked),
IrInlined => debug::Stage::Ir(debug::IrForm::Inlined),
IrSubSub => debug::Stage::Ir(debug::IrForm::SubregistersSubstituted),
IrCfPatched => debug::Stage::Ir(debug::IrForm::CfPatched),
IrRaw => debug::Stage::Ir(debug::IrForm::Raw),
IrNorm => debug::Stage::Ir(debug::IrForm::Normalized),
IrOpt => debug::Stage::Ir(debug::IrForm::Optimized),
Expand Down
16 changes: 16 additions & 0 deletions src/cwe_checker_lib/src/utils/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,24 @@ pub enum Stage {
/// Substages of the IR generation that can be debugged separately.
#[non_exhaustive]
pub enum IrForm {
/// The very first IR representation of the program.
Early,
/// After blocks within a function have been normal ordered.
FnBlksSorted,
/// Non-returning external functions marked.
NonRetExtFunctionsMarked,
/// Existing, referenced blocks have blocks have been inlined into
/// returning functions.
Inlined,
/// After the subregister substitution pass.
SubregistersSubstituted,
/// All control flow transfers have a valid target.
CfPatched,
/// After all passes that require access to Pcode internals.
Raw,
/// After all normalization passes.
Normalized,
/// After all optimization passes.
Optimized,
}

Expand Down
5 changes: 3 additions & 2 deletions src/cwe_checker_lib/src/utils/ghidra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn get_project_from_ghidra(
debug::Stage::Pcode(debug::PcodeForm::Parsed),
);

parse_pcode_project_to_ir_project(pcode_project, binary, &bare_metal_config_opt)
parse_pcode_project_to_ir_project(pcode_project, binary, &bare_metal_config_opt, debug_settings)
}

/// Normalize the given P-Code project
Expand All @@ -67,11 +67,12 @@ pub fn parse_pcode_project_to_ir_project(
pcode_project: PcodeProject,
_binary: &[u8],
bare_metal_config_opt: &Option<BareMetalConfig>,
debug_settings: &debug::Settings,
) -> Result<(Project, Vec<LogMessage>), Error> {
let _bare_metal_base_address_opt = bare_metal_config_opt
.as_ref()
.map(|config| config.parse_binary_base_address());
let project = pcode_project.into_ir_project();
let project = pcode_project.into_ir_project(debug_settings);
let log_messages = vec![];

Ok((project, log_messages))
Expand Down

0 comments on commit b0172a0

Please sign in to comment.