Skip to main content

miden_objtool/
dump.rs

1mod debuginfo;
2
3use clap::{Subcommand, ValueEnum};
4use miden_mast_package::PackageDebugInfoError;
5
6/// Dump useful information from assembled Miden packages
7#[derive(Debug, Subcommand)]
8#[command(name = "debuginfo", rename_all = "kebab-case")]
9pub enum Dump {
10    /// Dump debug information encoded in a .masp file
11    DebugInfo(debuginfo::Config),
12}
13
14/// The set of known sections that we've added dump support for
15#[derive(Debug, Clone, Copy, ValueEnum)]
16pub enum Section {
17    /// Show string table
18    Strings,
19    /// Show type information
20    Types,
21    /// Show source file information
22    Files,
23    /// Show function debug information
24    Functions,
25    /// Show variable information within functions
26    Variables,
27    /// Show variable location decorators from MAST (similar to DWARF .debug_loc)
28    Locations,
29}
30
31#[derive(Debug, thiserror::Error)]
32pub enum DumpError {
33    #[error("failed to read file: {0}")]
34    Io(#[from] std::io::Error),
35    #[error("failed to parse package: {0}")]
36    Parse(String),
37    #[error("no debug_info section found in package")]
38    NoDebugInfo,
39    #[error(transparent)]
40    InvalidDebugInfo(#[from] PackageDebugInfoError),
41}
42
43impl From<miden_core::serde::DeserializationError> for DumpError {
44    #[inline]
45    fn from(err: miden_core::serde::DeserializationError) -> Self {
46        Self::Parse(err.to_string())
47    }
48}
49
50pub fn run(command: &Dump) -> Result<(), DumpError> {
51    match command {
52        Dump::DebugInfo(config) => debuginfo::dump(config),
53    }
54}