Skip to content

Commit

Permalink
Support a standalone call-stack binary analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertescher committed Jun 16, 2023
1 parent 1fb185b commit 7c38395
Show file tree
Hide file tree
Showing 3 changed files with 1,390 additions and 1,305 deletions.
57 changes: 57 additions & 0 deletions src/bin/analyze-call-stack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Standalone version of cargo-call-stack

#![deny(warnings)]

use std::{process, path::PathBuf};
use clap::Parser;

use cargo_call_stack::OutputFormat;
use env_logger::{Builder, Env};

/// Generate a call graph and perform whole program stack usage analysis
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Target triple for which the code is compiled
#[arg(long, value_name = "TRIPLE")]
target: Option<String>,

/// Output format
#[arg(long, default_value = "dot")]
format: OutputFormat,

/// Path to the elf file
#[arg(long, value_name = "ELF_PATH")]
elf: Option<String>,

/// Path to the complier-builtins rlib file
#[arg(long, value_name = "COMPILER_BUILTINS_RLIB_PATH")]
compiler_builtins_rlib_path: Option<String>,

/// Path to the complier-builtins ll file
#[arg(long, value_name = "COMPILER_BUILTINS_LL_PATH")]
compiler_builtins_ll_path: Option<String>,
}

fn main() -> anyhow::Result<()> {
match run() {
Ok(ec) => process::exit(ec),
Err(e) => {
eprintln!("error: {}", e);
process::exit(1)
}
}
}

fn run() -> anyhow::Result<i32> {
Builder::from_env(Env::default().default_filter_or("warn")).init();
let args = Args::parse();

let path = PathBuf::from(args.elf.unwrap());
let compiler_builtins_rlib_path = args.compiler_builtins_rlib_path.unwrap();
let compiler_builtins_ll_path = args.compiler_builtins_ll_path.unwrap();
let target = args.target.unwrap();
let prefix = String::new();

cargo_call_stack::analyze(path, compiler_builtins_rlib_path, compiler_builtins_ll_path, &target, prefix, None, args.format)
}
Loading

0 comments on commit 7c38395

Please sign in to comment.