@@ -551,3 +551,93 @@ check: exited with status = 0
551551 Ok ( ( ) )
552552 }
553553}
554+
555+ #[ cfg( all( feature = "stack-switching" , unix, target_arch = "x86_64" ) ) ]
556+ mod stack_switching {
557+ use super :: { check_lldb_output, lldb_with_script} ;
558+ use anyhow:: Result ;
559+
560+ /// Checks that we get backtraces including the entire continuation chain when
561+ /// using just FP walking.
562+ #[ test]
563+ #[ ignore]
564+ pub fn debug_info_disabled ( ) -> Result < ( ) > {
565+ let output = lldb_with_script (
566+ & [
567+ "-Ccache=n" ,
568+ "-Ddebug-info=n" ,
569+ "-Wstack-switching" ,
570+ "--invoke" ,
571+ "entry" ,
572+ "tests/all/debug/testsuite/stack_switch.wat" ,
573+ ] ,
574+ r#"r
575+ bt
576+ "# ,
577+ ) ?;
578+
579+ // We are running without debug-info enabled, so we will not get Wasm
580+ // function names in the output. Instead, we look for
581+ // wasmtime_continuation_start, the trampoline at the bottom of all
582+ // continuation stacks.
583+ //
584+ // This directive matches lines like this:
585+ // frame #12: 0x0000555558f18fc9 wasmtime`wasmtime_continuation_start + 9
586+ let check = r#"
587+ check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) wasmtime`wasmtime_continuation_start
588+ "# ;
589+
590+ // Our stack_switch.wat file traps inside 3 levels of nested continuations.
591+ // Thus, we must have 3 stack frames at function `wasmtime_continuation_start`.
592+ check_lldb_output ( & output, & check. repeat ( 3 ) ) ?;
593+
594+ Ok ( ( ) )
595+ }
596+
597+ /// Checks that we get backtraces including the entire continuation chain when
598+ /// using just FP walking.
599+ #[ test]
600+ #[ ignore]
601+ pub fn debug_info_enabled ( ) -> Result < ( ) > {
602+ let output = lldb_with_script (
603+ & [
604+ "-Ccache=n" ,
605+ "-Ddebug-info=y" ,
606+ "-Wstack-switching" ,
607+ "--invoke" ,
608+ "entry" ,
609+ "tests/all/debug/testsuite/stack_switch.wat" ,
610+ ] ,
611+ r#"r
612+ bt
613+ "# ,
614+ ) ?;
615+
616+ // We are running with debug-info enabled, so we get Wasm
617+ // function names in the backtrace.
618+ //
619+ // Creates directive matching lines like this:
620+ // frame #13: 0x00007ffff4e4a5be JIT(0x55555bc24b10)`c at <gen-0>.wasm:90
621+ // where the string is parameterised over the function name (c in the
622+ // example above).
623+ let check = |name : & str | {
624+ format ! (
625+ "check: frame #$(=[0-9]+): 0x$(=[0-9a-f]+) JIT(0x$(=[0-9a-f]+))`{name} at <gen-0>.wasm"
626+ )
627+ } ;
628+
629+ // Our stack_switch.wat file traps inside 3 levels of nested continuations.
630+ // Let's check that our backtrace contains all the functions, even those in
631+ // parent continuations.
632+ check_lldb_output (
633+ & output,
634+ & [ "f" , "e" , "d" , "c" , "b" , "a" , "entry" ]
635+ . into_iter ( )
636+ . map ( check)
637+ . collect :: < Vec < String > > ( )
638+ . join ( "\n " ) ,
639+ ) ?;
640+
641+ Ok ( ( ) )
642+ }
643+ }
0 commit comments