Files
cnmcdee a1645d34f3 debugger: fix 4 of the 8 documented C debugger bugs (c, d, e, f)
(c) step_out() in main() degraded to Continue instead of failing
with "finish not meaningful in the outermost frame."
(d) Stop on a GUI app in gtk_main: enable mi-async in spawn_gdb and
fall back through MI interrupt, SIGINT and SIGSTOP to the inferior
pid; kill_target() also tells gdb to drop a stopped inferior it never
reported dead (console kill), or -file-exec-and-symbols fails with
"Couldnt get registers".
(e) New restart_or_start(): same target+args restarts, otherwise kills
the stopped inferior and starts the new target (Run must honour the
Target field).
(f) Breakpoints gain a temporary flag: break-on-main bps are skipped
on re-apply, never saved, and never added twice.

Tests: step_out_in_main_degrades_to_continue,
break_on_main_no_duplicate_on_second_start,
break_on_main_no_duplicate_after_load, restart_or_start_switches_target,
gtk_interrupt_running_app (new gtkspin target); lib.rs documents all 8
bugs and the Rust port stance on each. (a)(b)(g)(h) are UI bugs and
there is no debugger UI in the Rust designer yet.
2026-12-02 10:02:57 +00:00

151 lines
4.2 KiB
Rust

// Shared helpers for the debugger integration tests (port of the
// harness utilities in tests/debugger/dbg_harness.cpp). The C++ test
// targets (console.cpp, spin.cpp, gtkapp.cpp) are vendored under
// tests/targets/ and compiled here with `g++ -g -O0` from their
// absolute paths, so the DWARF source paths match the file:line
// breakpoints the tests use.
use lightgui_debug::Variable;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::OnceLock;
#[allow(dead_code)]
pub struct Targets {
pub dir: PathBuf,
pub console: PathBuf,
pub console_src: PathBuf,
pub spin: PathBuf,
pub gtkapp: PathBuf,
pub gtkapp_src: PathBuf,
pub gtkspin: PathBuf,
pub gtkspin_src: PathBuf,
}
pub fn targets() -> &'static Targets {
static T: OnceLock<Targets> = OnceLock::new();
T.get_or_init(build_targets)
}
fn run_or_panic(mut cmd: Command, what: &str) {
let out = cmd
.output()
.unwrap_or_else(|e| panic!("failed to run {}: {}", what, e));
assert!(
out.status.success(),
"{} failed: {}\n{}",
what,
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
}
fn build_targets() -> Targets {
let dir = std::env::temp_dir().join("lightgui_dbg_targets");
let _ = std::fs::create_dir_all(&dir);
let src_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/targets");
let console_src = src_dir.join("console.cpp");
let spin_src = src_dir.join("spin.cpp");
let gtk_src = src_dir.join("gtkapp.cpp");
let gtkspin_src = src_dir.join("gtkspin.cpp");
let console = dir.join("console");
let spin = dir.join("spin");
let gtkapp = dir.join("gtkapp");
let gtkspin = dir.join("gtkspin");
run_or_panic(
{
let mut c = Command::new("g++");
c.args(["-g", "-O0", "-o"]);
c.arg(&console);
c.arg(&console_src);
c
},
"build console target",
);
run_or_panic(
{
let mut c = Command::new("g++");
c.args(["-g", "-O0", "-o"]);
c.arg(&spin);
c.arg(&spin_src);
c
},
"build spin target",
);
let pkg = Command::new("pkg-config")
.args(["--cflags", "--libs", "gtk+-3.0"])
.output()
.expect("pkg-config gtk+-3.0");
assert!(pkg.status.success(), "pkg-config gtk+-3.0 failed");
let flags: Vec<String> = String::from_utf8_lossy(&pkg.stdout)
.split_whitespace()
.map(|s| s.to_string())
.collect();
run_or_panic(
{
let mut c = Command::new("g++");
c.args(["-g", "-O0", "-o"]);
c.arg(&gtkapp);
c.arg(&gtk_src);
c.args(&flags);
c
},
"build gtkapp target",
);
run_or_panic(
{
let mut c = Command::new("g++");
c.args(["-g", "-O0", "-o"]);
c.arg(&gtkspin);
c.arg(&gtkspin_src);
c.args(&flags);
c
},
"build gtkspin target",
);
Targets {
dir,
console,
console_src,
spin,
gtkapp,
gtkapp_src: gtk_src,
gtkspin,
gtkspin_src,
}
}
/// 1-based line number of the first line containing `mark`, or -1.
pub fn mark_line(file: &PathBuf, mark: &str) -> i32 {
let text = std::fs::read_to_string(file).expect("read target source");
for (i, line) in text.lines().enumerate() {
if line.contains(mark) {
return (i + 1) as i32;
}
}
-1
}
pub fn loc(file: &Path, line: i32) -> String {
format!("{}:{}", file.to_string_lossy(), line)
}
pub fn has(vars: &[Variable], name: &str, value: &str) -> bool {
vars.iter().any(|v| v.name == name && v.value == value)
}
pub fn var_value(vars: &[Variable], name: &str) -> String {
vars.iter()
.find(|v| v.name == name)
.map(|v| v.value.clone())
.unwrap_or_else(|| "<missing>".to_string())
}
/// Unique scratch path for one test (parallel-safe).
#[allow(dead_code)]
pub fn tmp_path(name: &str) -> PathBuf {
std::env::temp_dir().join(format!("dbgtest_{}_{}", name, std::process::id()))
}