Skip to main content

Module loose

Module loose 

Source
Expand description

“Loose” mode for anchor debugger — runs in any cargo workspace without requiring an Anchor.toml.

Anchor projects ship an Anchor.toml that maps program names to deployed pubkeys and pins the cargo test invocation. Bench / research workspaces are plain cargo workspaces that happen to use anchor-lang-v2 as a library — forcing them to author an Anchor.toml just to use the debugger would be friction for no payoff.

This module covers everything the Anchor.toml-driven path provides:

  • Workspace root — walk up from cwd looking for the nearest Cargo.toml declaring [workspace].
  • Current package — read <cwd>/Cargo.toml for the [package] name.
  • Test invocationcargo test --features profile -p <pkg> from the workspace root.
  • Program → ELF map — pair target/deploy/*.so with the matching *-keypair.json to recover the deployed pubkey.

Sanity checks fire as early as possible so the user gets actionable errors instead of opaque “no traces” messages later.

Structs§

LooseWorkspace
Discovered cargo workspace context.

Functions§

clear_profile_dir
Wipe the per-test trace dir before a fresh run so stale traces from a previous session don’t leak into the new picker. Idempotent — missing dir is fine.
discover_programs
Walk the workspace’s SBF build artifacts and return a base58 program-id → .so path map. Two location families are considered:
run_cargo_test
Run cargo build-sbf -p <pkg> from the workspace root. This produces the post-linked .so + sibling keypair under target/deploy/ that solana-sbpf can parse — the raw cargo build --target sbpf-solana-solana artifact in target/sbpf-solana-solana/release/ is missing relocation metadata our debugger needs.