This commit is contained in:
2026-06-04 20:35:01 -04:00
parent 978bac88ed
commit 0ac7c5cc02
4 changed files with 41 additions and 13 deletions
+27 -11
View File
@@ -1,7 +1,7 @@
use crate::backend::{
program::{UnlinkedFunction, UnlinkedProgram},
symbol::Symbol,
x86_64::{instr::*, reg::*},
x86_64::{Instr, instr::*, reg::*},
};
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, process::Command};
@@ -10,20 +10,20 @@ pub fn test_x86_64() {
let program = UnlinkedProgram {
fns: vec![UnlinkedFunction {
instrs: vec![
mov(eax, 4),
mov(ebx, 1),
lea(ecx, Symbol::raw(1)),
mov(edx, s.len() as u64),
int(0x80),
mov(eax, 1),
mov(ebx, 39),
int(0x80),
mov(rax, 1),
mov(rdi, 1),
lea(rsi, Symbol::raw(1)),
mov(rdx, s.len() as u64),
Instr::Syscall,
mov(rax, 0x3c),
mov(rdi, 39),
Instr::Syscall,
],
sym: Symbol::raw(0),
locations: Default::default(),
}],
ro_data: vec![(s.to_vec(), Symbol::raw(1))],
sym_count: 3,
sym_count: 2,
start: Some(Symbol::raw(0)),
};
let Ok(linked) = program.link() else {
@@ -42,7 +42,23 @@ pub fn test_x86_64() {
file.sync_all().expect("Failed to sync file");
drop(file);
println!("running...");
let mut proc = Command::new(path).spawn().expect("failed to run");
let gdb = false;
let mut proc = if gdb {
let mut cmd = Command::new("gdb");
#[rustfmt::skip]
cmd.args([
"-q",
"-ex", "starti",
"-ex", "layout asm",
"-ex", "focus next",
"x86_64_test",
]);
cmd
} else {
Command::new(path)
}
.spawn()
.expect("failed to run");
let status = proc.wait().expect("failed to wait");
if let Some(code) = status.code() {
std::process::exit(code);