pub fn generate_debugger_script(
    debugger: &Debugger,
    test_definition: &TestDefinition,
    cargo_profile: &Arc<str>,
    phase: &PhaseConfig,
    mk_crashdump_path: &mut dyn FnMut(/* tag */ &str) -> PathBuf,
) -> String {
    let mut debugger_script = String::new();

    debugger.emit_script_prelude(&mut debugger_script);
    debugger.emit_breakpoints(test_definition, phase, &mut debugger_script);

    let mut script = test_definition.script.clone();
    debugger.assign_correlation_ids(&mut script, cargo_profile, phase);

    let evaluation_context = debugger.evaluation_context(cargo_profile, phase);

    // Emit commands
    let mut last_correlation_id = None;

    script.walk_applicable_leaves(&evaluation_context, &mut |statement| {
        // Emit new correlation id if necessary
        match statement {
            script::Statement::Exec(_, correlation_id, _)
            | script::Statement::GenerateCrashDump(_, correlation_id, _) => {
                if last_correlation_id != *correlation_id {
                    debugger.maybe_emit_correlation_id_command(
                        false,
                        last_correlation_id,
                        &mut debugger_script,
                    );
                    debugger.maybe_emit_correlation_id_command(
                        true,
                        *correlation_id,
                        &mut debugger_script,
                    );
                    last_correlation_id = *correlation_id;
                }
            }
            _ => {
                // Other statements don't produce output, so no correlation id for them
            }
        };

        // Emit the actual command
        match statement {
            script::Statement::Exec(command, _, _) => {
                writeln!(&mut debugger_script, "{}", command).unwrap();
            }
            script::Statement::GenerateCrashDump(tag, _, _) => {
                if *phase != PhaseConfig::Live {
                    warn!(
                        "Encountered {} command in crashdump phase. Ignoring.",
                        script::TOKEN_GENERATE_CRASHDUMP
                    );
                }

                let crashdump_path = mk_crashdump_path(tag);
                debugger.emit_crashdump_command(&crashdump_path, &mut debugger_script);
            }
            _ => {
                // other statements don't have an effect here
            }
        }

        true
    });

    debugger.maybe_emit_correlation_id_command(false, last_correlation_id, &mut debugger_script);

    debugger_script
}
/// Generates the debugger script for the given combination of test definition and debugger.
Generates the debugger script for the given combination of test definition and debugger.
Generates the debugger script for the given combination of test definition and debugger .
pub fn generate_debugger_script(
    debugger: &Debugger,
    test_definition: &TestDefinition,
    cargo_profile: &Arc<str>,
    phase: &PhaseConfig,
    mk_crashdump_path: &mut dyn FnMut(/* tag */ &str) -> PathBuf,
) -> String {
    let mut debugger_script = String::new();
    debugger.emit_script_prelude(&mut debugger_script);
    debugger.emit_breakpoints(test_definition, phase, &mut debugger_script);
    let mut script = test_definition.script.clone();
    debugger.assign_correlation_ids(&mut script, cargo_profile, phase);
    let evaluation_context = debugger.evaluation_context(cargo_profile, phase);
    // Emit commands
    let mut last_correlation_id = None;
    script.walk_applicable_leaves(&evaluation_context, &mut |statement| {
        // Emit new correlation id if necessary
        match statement {
            script::Statement::Exec(_, correlation_id, _)
            | script::Statement::GenerateCrashDump(_, correlation_id, _) => {
                if last_correlation_id != *correlation_id {
                    debugger.maybe_emit_correlation_id_command(
                        false,
                        last_correlation_id,
                        &mut debugger_script,
                    );
                    debugger.maybe_emit_correlation_id_command(
                        true,
                        *correlation_id,
                        &mut debugger_script,
                    );
                    last_correlation_id = *correlation_id;
                }
            }
            _ => {
                // Other statements don't produce output, so no correlation id for them
            }
        };
        // Emit the actual command
        match statement {
            script::Statement::Exec(command, _, _) => {
                writeln!(&mut debugger_script, "{}", command).unwrap();
            }
            script::Statement::GenerateCrashDump(tag, _, _) => {
                if *phase != PhaseConfig::Live {
                    warn!(
                        "Encountered {} command in crashdump phase. Ignoring.",
                        script::TOKEN_GENERATE_CRASHDUMP
                    );
                }
                let crashdump_path = mk_crashdump_path(tag);
                debugger.emit_crashdump_command(&crashdump_path, &mut debugger_script);
            }
            _ => {
                // other statements don't have an effect here
            }
        }
        true
    });
    debugger.maybe_emit_correlation_id_command(false, last_correlation_id, &mut debugger_script);
    debugger_script
}
pub fn generate_debugger_script ( debugger : & Debugger , test_definition : & TestDefinition , cargo_profile : & Arc < str > , phase : & PhaseConfig , mk_crashdump_path : & mut dyn FnMut ( /* tag */ & str ) -> PathBuf , ) -> String { let mut debugger_script = String :: new ( ) ; debugger . emit_script_prelude ( & mut debugger_script ) ; debugger . emit_breakpoints ( test_definition , phase , & mut debugger_script ) ; let mut script = test_definition . script . clone ( ) ; debugger . assign_correlation_ids ( & mut script , cargo_profile , phase ) ; let evaluation_context = debugger . evaluation_context ( cargo_profile , phase ) ; // Emit commands let mut last_correlation_id = None ; script . walk_applicable_leaves ( & evaluation_context , & mut | statement | { // Emit new correlation id if necessary match statement { script :: Statement :: Exec ( _ , correlation_id , _ ) | script :: Statement :: GenerateCrashDump ( _ , correlation_id , _ ) => { if last_correlation_id != * correlation_id { debugger . maybe_emit_correlation_id_command ( false , last_correlation_id , & mut debugger_script , ) ; debugger . maybe_emit_correlation_id_command ( true , * correlation_id , & mut debugger_script , ) ; last_correlation_id = * correlation_id ; } } _ => { // Other statements don't produce output, so no correlation id for them } } ; // Emit the actual command match statement { script :: Statement :: Exec ( command , _ , _ ) => { writeln ! ( mut debugger_script " " command ) . unwrap ( ) ; } script :: Statement :: GenerateCrashDump ( tag , _ , _ ) => { if * phase != PhaseConfig :: Live { warn ! ( " " script TOKEN_GENERATE_CRASHDUMP ) ; } let crashdump_path = mk_crashdump_path ( tag ) ; debugger . emit_crashdump_command ( & crashdump_path , & mut debugger_script ) ; } _ => { // other statements don't have an effect here } } true } ) ; debugger . maybe_emit_correlation_id_command ( false , last_correlation_id , & mut debugger_script ) ; debugger_script }
Generates the debugger script for the given combination of test definition and debugger.
Generates the debugger script for the given combination of test definition and debugger .
debugger
&Debugger
test_definition
&TestDefinition
cargo_profile
&Arc<str>
phase
&PhaseConfig
mk_crashdump_path
&mut dyn FnMut(/* tag */ &str) -> PathBuf
debugger
&Debugger
test_definition
&TestDefinition
cargo_profile
&Arc<str>
phase
&PhaseConfig
mk_crashdump_path
&mut dyn FnMut(/* tag */ &str) -> PathBuf