1 use super::dump::{DwarfDumpSection, get_dwarfdump}; 2 use super::obj::compile_cranelift; 3 use filecheck::{CheckerBuilder, NO_VARIABLES}; 4 use tempfile::NamedTempFile; 5 use wasmtime::{Result, format_err}; 6 use wat::parse_str; 7 8 #[allow(dead_code, reason = "used by conditionally-defined tests below")] 9 fn check_wat(wat: &str) -> Result<()> { 10 let wasm = parse_str(wat)?; 11 let obj_file = NamedTempFile::new()?; 12 let obj_path = obj_file.path().to_str().unwrap(); 13 compile_cranelift(&wasm, None, None, obj_path)?; 14 let dump = get_dwarfdump(obj_path, DwarfDumpSection::DebugInfo)?; 15 let mut builder = CheckerBuilder::new(); 16 builder 17 .text(wat) 18 .map_err(|e| format_err!("unable to build checker: {e:?}"))?; 19 let checker = builder.finish(); 20 let check = checker 21 .explain(&dump, NO_VARIABLES) 22 .map_err(|e| format_err!("{e:?}"))?; 23 assert!(check.0, "didn't pass check {}", check.1); 24 Ok(()) 25 } 26 27 #[test] 28 #[ignore] 29 #[cfg(all( 30 any(target_os = "linux", target_os = "macos"), 31 target_pointer_width = "64" 32 ))] 33 fn test_debug_dwarf_simulate_simple_x86_64() -> Result<()> { 34 check_wat( 35 r#" 36 ;; check: DW_TAG_compile_unit 37 (module 38 ;; check: DW_TAG_subprogram 39 ;; check: DW_AT_name ("wasm-function[0]") 40 ;; check: DW_TAG_formal_parameter 41 ;; check: DW_AT_name ("var0") 42 ;; check: DW_AT_type 43 ;; sameln: "i32" 44 ;; check: DW_TAG_variable 45 ;; check: DW_AT_name ("var1") 46 ;; check: DW_AT_type 47 ;; sameln: "i32" 48 (func (param i32) (result i32) 49 (local i32) 50 local.get 0 51 local.set 1 52 local.get 1 53 ) 54 )"#, 55 ) 56 } 57 58 #[test] 59 #[ignore] 60 #[cfg(all( 61 any(target_os = "linux", target_os = "macos"), 62 target_pointer_width = "64" 63 ))] 64 fn test_debug_dwarf_simulate_with_imports_x86_64() -> Result<()> { 65 check_wat( 66 r#" 67 ;; check: DW_TAG_compile_unit 68 (module 69 ;; check: DW_TAG_subprogram 70 ;; check: DW_AT_name ("func1") 71 (import "foo" "bar" (func $import1) ) 72 (func $func1 (result i32) 73 i32.const 1 74 ) 75 )"#, 76 ) 77 } 78 79 #[test] 80 #[ignore] 81 #[cfg(all( 82 any(target_os = "linux", target_os = "macos"), 83 target_pointer_width = "64" 84 ))] 85 fn test_debug_dwarf_simulate_with_invalid_name_x86_64() -> Result<()> { 86 check_wat( 87 r#" 88 ;; check: DW_TAG_compile_unit 89 (module (@name "\00") 90 ;; check: DW_TAG_subprogram 91 ;; check: DW_AT_name ("wasm-function[1]") 92 (import "foo" "bar" (func $import1) ) 93 (func (@name "\00f") (result i32) 94 (local (@name "l\00") i32) 95 i32.const 1 96 ) 97 )"#, 98 ) 99 } 100