|
| 1 | +#![allow(dead_code)] |
| 2 | + |
| 3 | +use anyhow::{bail, format_err, Result}; |
| 4 | +use filecheck::{CheckerBuilder, NO_VARIABLES}; |
| 5 | +use std::env; |
| 6 | +use std::io::Write; |
| 7 | +use std::process::Command; |
| 8 | +use tempfile::NamedTempFile; |
| 9 | + |
| 10 | +fn lldb_with_script(args: &[&str], script: &str) -> Result<String> { |
| 11 | + let lldb_path = env::var("LLDB").unwrap_or("lldb".to_string()); |
| 12 | + let mut cmd = Command::new(&lldb_path); |
| 13 | + |
| 14 | + cmd.arg("--batch"); |
| 15 | + if cfg!(target_os = "macos") { |
| 16 | + cmd.args(&["-o", "settings set plugin.jit-loader.gdb.enable on"]); |
| 17 | + } |
| 18 | + let mut script_file = NamedTempFile::new()?; |
| 19 | + script_file.write(script.as_bytes())?; |
| 20 | + let script_path = script_file.path().to_str().unwrap(); |
| 21 | + cmd.args(&["-s", &script_path]); |
| 22 | + |
| 23 | + let mut me = std::env::current_exe().expect("current_exe specified"); |
| 24 | + me.pop(); // chop off the file name |
| 25 | + me.pop(); // chop off `deps` |
| 26 | + me.push("wasmtime"); |
| 27 | + cmd.arg(me); |
| 28 | + |
| 29 | + cmd.arg("--"); |
| 30 | + cmd.args(args); |
| 31 | + |
| 32 | + let output = cmd.output().expect("success"); |
| 33 | + if !output.status.success() { |
| 34 | + bail!( |
| 35 | + "failed to execute {:?}: {}", |
| 36 | + cmd, |
| 37 | + String::from_utf8_lossy(&output.stderr), |
| 38 | + ); |
| 39 | + } |
| 40 | + Ok(String::from_utf8(output.stdout)?) |
| 41 | +} |
| 42 | + |
| 43 | +fn check_lldb_output(output: &str, directives: &str) -> Result<()> { |
| 44 | + let mut builder = CheckerBuilder::new(); |
| 45 | + builder |
| 46 | + .text(directives) |
| 47 | + .map_err(|e| format_err!("unable to build checker: {:?}", e))?; |
| 48 | + let checker = builder.finish(); |
| 49 | + let check = checker |
| 50 | + .explain(output, NO_VARIABLES) |
| 51 | + .map_err(|e| format_err!("{:?}", e))?; |
| 52 | + assert!(check.0, "didn't pass check {}", check.1); |
| 53 | + Ok(()) |
| 54 | +} |
| 55 | + |
| 56 | +#[test] |
| 57 | +#[ignore] |
| 58 | +#[cfg(all( |
| 59 | + any(target_os = "linux", target_os = "macos"), |
| 60 | + target_pointer_width = "64" |
| 61 | +))] |
| 62 | +pub fn test_debug_dwarf_lldb() -> Result<()> { |
| 63 | + let output = lldb_with_script( |
| 64 | + &[ |
| 65 | + "-g", |
| 66 | + "tests/debug/testsuite/fib-wasm.wasm", |
| 67 | + "--invoke", |
| 68 | + "fib", |
| 69 | + "3", |
| 70 | + ], |
| 71 | + r#"b fib |
| 72 | +r |
| 73 | +fr v |
| 74 | +c"#, |
| 75 | + )?; |
| 76 | + |
| 77 | + check_lldb_output( |
| 78 | + &output, |
| 79 | + r#" |
| 80 | +check: Breakpoint 1: no locations (pending) |
| 81 | +check: Unable to resolve breakpoint to any actual locations. |
| 82 | +check: 1 location added to breakpoint 1 |
| 83 | +check: stop reason = breakpoint 1.1 |
| 84 | +check: frame #0 |
| 85 | +sameln: JIT |
| 86 | +sameln: fib(n=3) |
| 87 | +check: n = 3 |
| 88 | +check: a = 0 |
| 89 | +check: resuming |
| 90 | +check: exited with status |
| 91 | +"#, |
| 92 | + )?; |
| 93 | + Ok(()) |
| 94 | +} |
0 commit comments