Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling debug mode via ExecutionOptions #1316

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub struct ExecutionOptions {
max_cycles: u32,
expected_cycles: u32,
enable_tracing: bool,
enable_debugging: bool,
}

impl Default for ExecutionOptions {
Expand All @@ -159,6 +160,7 @@ impl Default for ExecutionOptions {
max_cycles: u32::MAX,
expected_cycles: MIN_TRACE_LEN as u32,
enable_tracing: false,
enable_debugging: false,
}
}
}
Expand Down Expand Up @@ -191,30 +193,51 @@ impl ExecutionOptions {
max_cycles,
expected_cycles,
enable_tracing,
enable_debugging: false,
})
}

/// Enables Host to handle the `tracing` instructions.
/// Enables execution of the `trace` instructions.
pub fn with_tracing(mut self) -> Self {
self.enable_tracing = true;
self
}

/// Enables execution of programs in debug mode.
///
/// In debug mode the VM does the following:
/// - Executes `debug` instructions (these are ignored in regular mode).
/// - Records additional info about program execution (e.g., keeps track of stack state at
/// every cycle of the VM) which enables stepping through the program forward and backward.
pub fn with_debugging(mut self) -> Self {
self.enable_debugging = true;
self
}

// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------

/// Returns maximum number of cycles
/// Returns maximum number of cycles a program is allowed to execute for.
pub fn max_cycles(&self) -> u32 {
self.max_cycles
}

/// Returns number of the expected cycles
/// Returns the number of cycles a program is expected to take.
///
/// This will serve as a hint to the VM for how much memory to allocate for a program's
/// execution trace and may result in performance improvements when the number of expected
/// cycles is equal to the number of actual cycles.
pub fn expected_cycles(&self) -> u32 {
self.expected_cycles
}

/// Returns a flag indicating whether the Host should handle `trace` instructions
/// Returns a flag indicating whether the VM should execute `trace` instructions.
pub fn enable_tracing(&self) -> bool {
self.enable_tracing
}

/// Returns a flag indicating whether the VM should execute a program in debug mode.
pub fn enable_debugging(&self) -> bool {
self.enable_debugging
}
}
2 changes: 1 addition & 1 deletion processor/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
/// Handles the event emitted from the VM.
fn on_event<S: ProcessState>(
&mut self,
process: &S,

Check warning on line 61 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `process`

Check warning on line 61 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `process`
event_id: u32,

Check warning on line 62 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `event_id`

Check warning on line 62 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `event_id`
) -> Result<HostResponse, ExecutionError> {
#[cfg(feature = "std")]
std::println!(
Expand All @@ -74,19 +74,19 @@
/// Handles the debug request from the VM.
fn on_debug<S: ProcessState>(
&mut self,
process: &S,

Check warning on line 77 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `process`

Check warning on line 77 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `process`
options: &DebugOptions,

Check warning on line 78 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `options`

Check warning on line 78 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `options`
) -> Result<HostResponse, ExecutionError> {
#[cfg(feature = "std")]
debug::print_debug_info(process, options);
Ok(HostResponse::None)
}

/// Handles the trace emmited from the VM.
/// Handles the trace emitted from the VM.
fn on_trace<S: ProcessState>(
&mut self,
process: &S,

Check warning on line 88 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `process`

Check warning on line 88 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `process`
trace_id: u32,

Check warning on line 89 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unused variable: `trace_id`

Check warning on line 89 in processor/src/host/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unused variable: `trace_id`
) -> Result<HostResponse, ExecutionError> {
#[cfg(feature = "std")]
std::println!(
Expand Down
7 changes: 3 additions & 4 deletions processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
host: H,
execution_options: ExecutionOptions,
) -> Self {
Self::initialize(kernel, stack_inputs, host, false, execution_options)
Self::initialize(kernel, stack_inputs, host, execution_options)
}

/// Creates a new process with provided inputs and debug options enabled.
Expand All @@ -193,18 +193,17 @@ where
kernel,
stack_inputs,
host,
true,
ExecutionOptions::default().with_tracing(),
ExecutionOptions::default().with_tracing().with_debugging(),
)
}

fn initialize(
kernel: Kernel,
stack: StackInputs,
host: H,
in_debug_mode: bool,
execution_options: ExecutionOptions,
) -> Self {
let in_debug_mode = execution_options.enable_debugging();
Self {
system: System::new(execution_options.expected_cycles() as usize),
decoder: Decoder::new(in_debug_mode),
Expand Down
Loading