Skip to content

Commit a18e5ed

Browse files
committed
Make hyperlight-wasm-aot take --debug command argument to enable debug info
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent d6832de commit a18e5ed

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

docs/wasm-modules-debugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ To facilitate debugging, it is recommended to compile your Wasm modules with deb
88
For example, when using `wasi-sdk/clang`, you can include the `-g` flag to generate debug information and `-O0` to disable optimizations.
99
You can find examples of native Wasm modules in the repository under the `rust_wasm_samples`, `wasm_samples` and `component_sample` directories.
1010

11-
Next, ensure that the pre-compiled Wasm modules are built with debug information as well. To do this, you can use the `hyperlight-wasm-aot` tool with the `--features gdb` flag:
11+
Next, ensure that the pre-compiled Wasm modules are built with debug information as well. To do this, you can use the `hyperlight-wasm-aot` tool with the `--debug` command argument:
1212

1313
```bash
14-
cargo run --features gdb -p hyperlight-wasm-aot compile input.wasm output.aot
14+
cargo run -p hyperlight-wasm-aot compile --debug input.wasm output.aot
1515
```
1616

1717

src/hyperlight_wasm_aot/src/main.rs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use std::path::Path;
1919
use cargo_metadata::{MetadataCommand, Package};
2020
use cargo_util_schemas::manifest::PackageName;
2121
use clap::{Arg, Command};
22-
#[cfg(feature = "gdb")]
23-
use wasmtime::OptLevel;
24-
use wasmtime::{Config, Engine, Module, Precompiled};
22+
use wasmtime::{Config, Engine, Module, OptLevel, Precompiled};
2523

2624
fn main() {
2725
let hyperlight_wasm_aot_version = env!("CARGO_PKG_VERSION");
@@ -49,6 +47,13 @@ fn main() {
4947
.required(false)
5048
.long("component")
5149
.action(clap::ArgAction::SetTrue),
50+
)
51+
.arg(
52+
Arg::new("debug")
53+
.help("Precompile with debug and disable optimizations")
54+
.required(false)
55+
.long("debug")
56+
.action(clap::ArgAction::SetTrue),
5257
),
5358
)
5459
.subcommand(
@@ -59,6 +64,13 @@ fn main() {
5964
.help("The aot compiled file to check")
6065
.required(true)
6166
.index(1),
67+
)
68+
.arg(
69+
Arg::new("debug")
70+
.help("Specifies if the module has been compiled with debug support")
71+
.required(false)
72+
.long("debug")
73+
.action(clap::ArgAction::SetTrue),
6274
),
6375
)
6476
.get_matches();
@@ -75,8 +87,16 @@ fn main() {
7587
path.to_str().unwrap().to_string().clone()
7688
}
7789
};
78-
println!("Aot Compiling {} to {}", infile, outfile);
79-
let config = get_config();
90+
let debug = args.get_flag("debug");
91+
if debug {
92+
println!(
93+
"Aot Compiling {} to {} with debug info and optimizations off",
94+
infile, outfile
95+
);
96+
} else {
97+
println!("Aot Compiling {} to {}", infile, outfile);
98+
}
99+
let config = get_config(debug);
80100
let engine = Engine::new(&config).unwrap();
81101
let bytes = std::fs::read(infile).unwrap();
82102
let serialized = if args.get_flag("component") {
@@ -99,11 +119,19 @@ fn main() {
99119
let args = matches
100120
.subcommand_matches("check-wasmtime-version")
101121
.unwrap();
122+
let debug = args.get_flag("debug");
102123
let file = args.get_one::<String>("file").unwrap();
103-
println!("Checking Wasmtime version used to compile file: {}", file);
124+
if debug {
125+
println!(
126+
"Checking Wasmtime version used to compile debug info enabled file: {}",
127+
file
128+
);
129+
} else {
130+
println!("Checking Wasmtime version used to compile file: {}", file);
131+
}
104132
// load the file into wasmtime, check that it is aot compiled and extract the version of wasmtime used to compile it from its metadata
105133
let bytes = std::fs::read(file).unwrap();
106-
let config = get_config();
134+
let config = get_config(debug);
107135
let engine = Engine::new(&config).unwrap();
108136
match Engine::detect_precompiled(&bytes) {
109137
Some(pre_compiled) => {
@@ -153,13 +181,12 @@ fn main() {
153181
}
154182

155183
/// Returns a new `Config` for the Wasmtime engine with additional settings for AOT compilation.
156-
fn get_config() -> Config {
184+
fn get_config(debug: bool) -> Config {
157185
let mut config = Config::new();
158186
config.target("x86_64-unknown-none").unwrap();
159187

160188
// Enable the default features for the Wasmtime engine.
161-
#[cfg(feature = "gdb")]
162-
{
189+
if debug {
163190
config.debug_info(true);
164191
config.cranelift_opt_level(OptLevel::None);
165192
}

0 commit comments

Comments
 (0)