Verified Commit cf91ce24 authored by jD91mZM2's avatar jD91mZM2

Basic debugging!!!

parent ddb2f9fe
/minimal-asm
/minimal-c
/*-asm
/*-c
all: minimal-asm minimal-c
all: minimal-asm redox-asm minimal-c
clean:
rm minimal-asm minimal-c
rm minimal-asm redox-asm minimal-c
minimal-asm.o: minimal.asm
nix-shell -p nasm --run "nasm -f elf64 minimal.asm -g -o minimal-asm.o"
minimal-asm: minimal-asm.o
ld minimal-asm.o -o minimal-asm
rm minimal-asm.o
%-asm.o: %.asm
nix-shell -p nasm --run "nasm -f elf64 $< -g -o $@"
%-c: %.c
nix-shell -p musl --run "musl-gcc -g -static $< -o $@"
minimal-c: minimal.c
nix-shell -p musl --run "musl-gcc -g -static minimal.c -o minimal-c"
%: %.o
ld "$<" -o "$@"
rm "$<"
......@@ -8,12 +8,12 @@ len: equ $-str
section .text
_start:
mov rax, 1
mov rdi, 1
mov rsi, str
mov rdx, len
mov rax, 1 ; write
mov rdi, 1 ; stdout
mov rsi, str ; buf
mov rdx, len ; len
syscall
mov rax, 60
xor rdi, rdi
mov rax, 60 ; exit
xor rdi, rdi ; status
syscall
global _start
section .data
str: db "Hello, world!", 0xA
len: equ $-str
section .text
_start:
mov rax, 0x2100_0004 ; write
mov rdi, 1 ; stdout
mov rsi, str ; buf
mov rdx, len ; len
syscall
mov rax, 1 ; exit
xor rdi, rdi ; status
syscall
Subproject commit ffe1d309efc92aae1b53d0a6b96a90b4d3d51c5b
Subproject commit 30a62316a98c4288287269717a28a558c97b8d82
......@@ -7,7 +7,6 @@ use std::{
io,
mem,
os::unix::ffi::OsStrExt,
path::PathBuf,
};
use gdb_remote_protocol::{Error, StopReason};
......@@ -107,7 +106,7 @@ impl super::Target for Os {
} else {
// Wait for tracee to stop
let mut status = 0;
e!(syscall::waitpid(pid, &mut status, WaitFlags::empty()));
e!(syscall::waitpid(pid, &mut status, WaitFlags::WUNTRACED));
// Attach tracer
let mut tracer = e!(Tracer::attach(pid));
......@@ -116,7 +115,11 @@ impl super::Target for Os {
e!(syscall::kill(pid, SIGCONT));
e!(tracer.next(strace::Flags::STOP_PRE_SYSCALL));
assert_eq!(e!(tracer.regs.get_int()).return_value(), syscall::SYS_FEXEC);
e!(tracer.next(strace::Flags::STOP_SINGLESTEP));
// TODO: Don't stop only on syscall, stop on first instruction.
// Single-stepping doesn't work across fexec yet for some reason.
// e!(tracer.next(strace::Flags::STOP_SINGLESTEP));
e!(tracer.next(strace::Flags::STOP_POST_SYSCALL));
Ok(Os {
pid,
......@@ -362,11 +365,14 @@ impl super::Target for Os {
}
fn path(&self, pid: usize) -> Result<Vec<u8>> {
let mut path = PathBuf::from("proc:");
path.push(pid.to_string());
path.push("/exe");
let mut path = e!(fs::read(format!("proc:{}/exe", pid)));
// Strip out "file:" so GDB doesn't interpret it as a URL.
if path.starts_with(&b"file:"[..]) {
path.drain(0..5);
}
Ok(e!(fs::read(path)))
Ok(path)
}
}
impl Drop for Os {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment