Cargo call-stack
A cargo sub-commond for spanning the call stack for a cortex-m
bare metal application.
Installing
cargo install --path <PATH_TO cargo-call-stack>
Usage
Assume we have have an existing cortex-m
bare metal application, e.g., ...
cargo call-stack --release --example hello1
Tech notes
Cargo sub-commands
Cargo allows third party sub-commands to be installed, giving extended functionality to the build system. The crate name for a sub command should be pre-fixed with "cargo-X", X being the command name, in this case "cargo-call-stack". For further information see, ...
Paths
Cargo uses the target
directory for storing build artifacts. In our case we are only interested in --release
builds, since we want to apply lto
optimization for obtaining a single file comprising the complete call-graph. So what remains to resolve is the concrete path for the generated elf
binary and the corresponding llvm-ir
. To that end, we parse the command line arguments to determine wether its an --example <name>
or a src
build. In the former case the generated llvm-ir
file has the path ../release/example/<name><hash>.ll
, while src
builds have llvm-ir
path ../release/deps/<crate>-<hash>.ll
. The elf
files have the paths ../release/example/<name>
and ../release/<crate>
correspondingly.
Hash suffix
Cargo identifies a build context by a unique hash in order to distinguish cashed compilation units between builds (under different configurations). To that end, we need to determine the current hash to determine the full path of the generated llvm ir (e.g. target/thumbv7m-none-eabi/release/examples/hello1-f3268774e62977a5.ll
, f3268774e62977a5
being the hash). While Cargo
can be accessed as a library, it does not (AFAIK) provide a stable API. A pragmatic solotion is to parse the actual invocation parameters to rustc
to determine the current hash (as identified by the extra-filename
option).