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

fix(cast/call): remove --verbose, fix --debug #6939

Merged
merged 1 commit into from
Jan 29, 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
25 changes: 7 additions & 18 deletions crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,18 @@ pub struct CallArgs {
#[clap(long, default_value_t = false)]
trace: bool,

/// Can only be used with "--trace"
///
/// opens an interactive debugger
/// Opens an interactive debugger.
/// Can only be used with `--trace`.
#[clap(long, requires = "trace")]
debug: bool,

/// Can only be used with "--trace"
///
/// prints a more verbose trace
#[clap(long, requires = "trace")]
verbose: bool,

/// Can only be used with "--trace"
/// Labels to apply to the traces.
///
/// Format: `address:label`
/// Labels to apply to the traces; format: `address:label`.
/// Can only be used with `--trace`.
#[clap(long, requires = "trace")]
labels: Vec<String>,

/// Can only be used with "--trace"
///
/// The EVM Version to use.
/// Can only be used with `--trace`.
#[clap(long, requires = "trace")]
evm_version: Option<EvmVersion>,

Expand Down Expand Up @@ -121,7 +111,6 @@ impl CallArgs {
trace,
evm_version,
debug,
verbose,
labels,
} = self;

Expand Down Expand Up @@ -165,7 +154,7 @@ impl CallArgs {
Err(evm_err) => TraceResult::try_from(evm_err)?,
};

handle_traces(trace, &config, chain, labels, verbose).await?;
handle_traces(trace, &config, chain, labels, debug).await?;

return Ok(());
}
Expand Down Expand Up @@ -199,7 +188,7 @@ impl CallArgs {
tx.value().copied().unwrap_or_default().to_alloy(),
)?);

handle_traces(trace, &config, chain, labels, verbose).await?;
handle_traces(trace, &config, chain, labels, debug).await?;

return Ok(());
}
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub fn read_constructor_args_file(constructor_args_path: PathBuf) -> Result<Vec<
}

/// A slimmed down return from the executor used for returning minimal trace + gas metering info
#[derive(Debug)]
pub struct TraceResult {
pub success: bool,
pub traces: Traces,
Expand Down
30 changes: 18 additions & 12 deletions crates/debugger/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ impl Debugger {

/// Starts the debugger TUI.
pub fn try_run(&mut self) -> Result<ExitReason> {
eyre::ensure!(!self.debug_arena.is_empty(), "debug arena is empty");

let backend = CrosstermBackend::new(io::stdout());
let mut terminal = Terminal::new(backend)?;
TerminalGuard::with(&mut terminal, |terminal| self.try_run_real(terminal))
let terminal = Terminal::new(backend)?;
TerminalGuard::with(terminal, |terminal| self.try_run_real(terminal))
}

#[instrument(target = "debugger", name = "run", skip_all, ret)]
fn try_run_real(&mut self, terminal: &mut DebuggerTerminal) -> Result<ExitReason> {
// Create the context.
let mut cx = DebuggerContext::new(self);

cx.init();

// Create an event listener in a different thread.
Expand All @@ -115,8 +118,6 @@ impl Debugger {
.spawn(move || Self::event_listener(tx))
.expect("failed to spawn thread");

eyre::ensure!(!cx.debug_arena().is_empty(), "debug arena is empty");

// Draw the initial state.
cx.draw(terminal)?;

Expand Down Expand Up @@ -158,16 +159,16 @@ type PanicHandler = Box<dyn Fn(&std::panic::PanicInfo<'_>) + 'static + Sync + Se

/// Handles terminal state.
#[must_use]
struct TerminalGuard<'a, B: Backend + io::Write> {
terminal: &'a mut Terminal<B>,
struct TerminalGuard<B: Backend + io::Write> {
terminal: Terminal<B>,
hook: Option<Arc<PanicHandler>>,
}

impl<'a, B: Backend + io::Write> TerminalGuard<'a, B> {
fn with<T>(terminal: &'a mut Terminal<B>, mut f: impl FnMut(&mut Terminal<B>) -> T) -> T {
impl<B: Backend + io::Write> TerminalGuard<B> {
fn with<T>(terminal: Terminal<B>, mut f: impl FnMut(&mut Terminal<B>) -> T) -> T {
let mut guard = Self { terminal, hook: None };
guard.setup();
f(guard.terminal)
f(&mut guard.terminal)
}

fn setup(&mut self) {
Expand All @@ -188,16 +189,21 @@ impl<'a, B: Backend + io::Write> TerminalGuard<'a, B> {

fn restore(&mut self) {
if !std::thread::panicking() {
// Drop the current hook to guarantee that `self.hook` is the only reference to it.
let _ = std::panic::take_hook();
// Restore the previous panic hook.
let prev = self.hook.take().unwrap();
let prev = match Arc::try_unwrap(prev) {
Ok(prev) => prev,
Err(_) => unreachable!(),
Err(_) => unreachable!("`self.hook` is not the only reference to the panic hook"),
};
std::panic::set_hook(prev);

// NOTE: Our panic handler calls this function, so we only have to call it here if we're
// not panicking.
Self::half_restore(self.terminal.backend_mut());
}

Self::half_restore(self.terminal.backend_mut());
let _ = self.terminal.show_cursor();
}

Expand All @@ -207,7 +213,7 @@ impl<'a, B: Backend + io::Write> TerminalGuard<'a, B> {
}
}

impl<B: Backend + io::Write> Drop for TerminalGuard<'_, B> {
impl<B: Backend + io::Write> Drop for TerminalGuard<B> {
#[inline]
fn drop(&mut self) {
self.restore();
Expand Down
Loading