Path: blob/main/tests/all/native_debug/gdb.rs
2450 views
use anyhow::{Result, bail, format_err};1use filecheck::{CheckerBuilder, NO_VARIABLES};2use std::env;3use std::io::Write;4use std::process::Command;5use tempfile::NamedTempFile;67fn gdb_with_script(args: &[&str], script: &str) -> Result<String> {8let lldb_path = env::var("GDB").unwrap_or("gdb".to_string());9let mut cmd = Command::new(&lldb_path);1011cmd.arg("--batch");12let mut script_file = NamedTempFile::new()?;13script_file.write(script.as_bytes())?;14let script_path = script_file.path().to_str().unwrap();15cmd.args(&["-x", &script_path]);1617cmd.arg("--args");1819let mut me = std::env::current_exe().expect("current_exe specified");20me.pop(); // chop off the file name21me.pop(); // chop off `deps`22me.push("wasmtime");23cmd.arg(me);2425cmd.args(args);2627let output = cmd.output().expect("success");28if !output.status.success() {29bail!(30"failed to execute {:?}: {}",31cmd,32String::from_utf8_lossy(&output.stderr),33);34}35Ok(String::from_utf8(output.stdout)?)36}3738fn check_gdb_output(output: &str, directives: &str) -> Result<()> {39let mut builder = CheckerBuilder::new();40builder41.text(directives)42.map_err(|e| format_err!("unable to build checker: {e:?}"))?;43let checker = builder.finish();44let check = checker45.explain(output, NO_VARIABLES)46.map_err(|e| format_err!("{e:?}"))?;47assert!(check.0, "didn't pass check {}", check.1);48Ok(())49}5051#[test]52#[ignore]53fn test_debug_dwarf_gdb() -> Result<()> {54let output = gdb_with_script(55&[56"-Ccache=n",57"-Ddebug-info",58"-Oopt-level=0",59"--invoke",60"fib",61test_programs_artifacts::DWARF_FIB_WASM,62"3",63],64r#"set breakpoint pending on65b fib66r67info locals68c"#,69)?;7071check_gdb_output(72&output,73r#"74check: Breakpoint 1 (fib) pending75check: hit Breakpoint 176sameln: fib (n=3)77check: a = 078check: b = 079check: exited normally80"#,81)?;82Ok(())83}848586