diff --git a/Cargo.lock b/Cargo.lock index 7ebdae6f0..82dbff4ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1607,6 +1607,7 @@ dependencies = [ "humility-cli", "humility-cmd", "humility-cmd-openocd", + "humility-core", "tempfile", ] diff --git a/cmd/gdb/Cargo.toml b/cmd/gdb/Cargo.toml index e9d988254..2f8ffd3ba 100644 --- a/cmd/gdb/Cargo.toml +++ b/cmd/gdb/Cargo.toml @@ -7,6 +7,7 @@ description = "Attach to a running system using GDB" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +humility = { workspace = true } humility-cmd = { workspace = true } humility-cli = { workspace = true } cmd-openocd = { workspace = true } diff --git a/cmd/gdb/src/lib.rs b/cmd/gdb/src/lib.rs index 32b4a7f02..ff229bd1d 100644 --- a/cmd/gdb/src/lib.rs +++ b/cmd/gdb/src/lib.rs @@ -47,6 +47,10 @@ struct GdbArgs { /// specifies the probe serial number to use with OpenOCD #[clap(long, requires = "run_openocd")] serial: Option, + + #[clap(long)] + /// Path to gdb script to run + gdb_script: Option, } fn gdb(context: &mut ExecutionContext) -> Result<()> { @@ -75,12 +79,26 @@ fn gdb(context: &mut ExecutionContext) -> Result<()> { &work_dir.path().join("openocd.gdb"), ) .context("GDB config missing. Is your Hubris build too old?")?; - hubris - .extract_file_to( - "debug/script.gdb", - &work_dir.path().join("script.gdb"), - ) - .context("GDB script missing. Is your Hubris build too old?")?; + + let gdb_script_path = work_dir.path().join("script.gdb"); + // We moved the gdb file out of the hubris archive because it was + // preventing reproducible builds. An extraction is non fatal + let r = hubris.extract_file_to("debug/script.gdb", &gdb_script_path); + + if let Some(path) = subargs.gdb_script { + // It's possible we overwrite the script in the old archive but + // that seems like behavior someone would want when actively + // passing in a path; print a warning to that effect + if r.is_ok() { + humility::warn!("--gdb_script is overriding GDB script in archive"); + } + std::fs::copy(path, &gdb_script_path)?; + } + + if !gdb_script_path.exists() { + bail!("GDB script missing; recent archives don't include it. Pass --gdb-script or use xtask gdb"); + } + hubris .extract_file_to("img/final.elf", &work_dir.path().join("final.elf"))?;