Verified Commit 098d1f16 authored by jD91mZM2's avatar jD91mZM2

Support stdio

parent cb445e78
This diff is collapsed.
......@@ -6,13 +6,13 @@ edition = "2018"
[dependencies]
gdb-remote-protocol = { path = "rust-gdb-remote-protocol" }
structopt = "0.2.18"
memchr = "2.2.1"
structopt = "0.3.15"
memchr = "2.3.3"
env_logger = "0.7.1"
log = "0.4.8"
[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2.62"
libc = "0.2.71"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" }
strace = { git = "https://gitlab.redox-os.org/redox-os/strace-redox" }
use std::{
cmp::min,
borrow::Cow,
net::TcpListener,
cmp::min,
convert::TryFrom,
io::{self, prelude::*, BufReader, BufWriter},
net::TcpListener,
os::unix::net::UnixListener,
};
use gdb_remote_protocol::{
......@@ -26,6 +28,9 @@ struct Opt {
/// The address which to bind the server to
#[structopt(short = "a", long = "addr", default_value = "0.0.0.0:64126")]
addr: String,
/// The type of address specified
#[structopt(short = "t", long = "type", default_value = "tcp", possible_values = &["tcp", "unix", "stdio"])]
kind: String,
/// The program that should be debugged
program: String,
/// The arguments of the program
......@@ -160,12 +165,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut opt = Opt::from_args();
opt.args.insert(0, opt.program.clone());
let mut writer = {
let stdin = io::stdin();
let stdout = io::stdout();
let (mut reader, mut writer): (Box<dyn Read>, Box<dyn Write>) = if opt.kind == "unix" {
let listener = UnixListener::bind(opt.addr)?;
let (writer, _addr) = listener.accept()?;
(
Box::new(BufReader::new(writer.try_clone()?)),
Box::new(BufWriter::new(writer)),
)
} else if opt.kind == "stdio" {
(
Box::new(stdin.lock()),
Box::new(BufWriter::new(stdout.lock())),
)
} else {
assert_eq!(opt.kind, "tcp");
let listener = TcpListener::bind(opt.addr)?;
let (stream, _addr) = listener.accept()?;
stream
let (writer, _addr) = listener.accept()?;
(
Box::new(BufReader::new(writer.try_clone()?)),
Box::new(BufWriter::new(writer)),
)
};
let mut reader = writer.try_clone()?;
let tracee = Os::new(opt.program, opt.args)?;
......
......@@ -156,7 +156,7 @@ impl super::Target for Os {
}
fn pid(&self) -> u32 {
return self.pid as _;
self.pid as _
}
fn getregs(&self) -> Result<Registers> {
......
......@@ -48,7 +48,7 @@ pub trait Target: Sized {
{
loop {
let rip = self.step(None)?;
println!("{:X?}", rip);
//println!("{:X?}", rip);
if rip.map(|rip| !range.contains(&rip)).unwrap_or(true) {
break;
}
......
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