milestone2
This commit is contained in:
parent
82de943a75
commit
ec51b69948
@ -28,10 +28,25 @@ impl Debugger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn _try_kill(&mut self) {
|
||||||
|
if self.inferior.is_some() {
|
||||||
|
let kill_result = self.inferior.as_mut().unwrap().kill();
|
||||||
|
if let Ok(_) = kill_result {
|
||||||
|
println!(
|
||||||
|
"Killing running inferior (pid {})",
|
||||||
|
self.inferior.as_ref().unwrap().pid()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
eprintln!("Error killing running inferior");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
loop {
|
loop {
|
||||||
match self.get_next_command() {
|
match self.get_next_command() {
|
||||||
DebuggerCommand::Run(args) => {
|
DebuggerCommand::Run(args) => {
|
||||||
|
self._try_kill();
|
||||||
if let Some(inferior) = Inferior::new(&self.target, &args) {
|
if let Some(inferior) = Inferior::new(&self.target, &args) {
|
||||||
// Create the inferior
|
// Create the inferior
|
||||||
self.inferior = Some(inferior);
|
self.inferior = Some(inferior);
|
||||||
@ -41,10 +56,13 @@ impl Debugger {
|
|||||||
if let Ok(res) = res {
|
if let Ok(res) = res {
|
||||||
match res {
|
match res {
|
||||||
Status::Exited(exit_status) => {
|
Status::Exited(exit_status) => {
|
||||||
println!("Child exited (statuss {})", exit_status);
|
println!("Child exited (status {})", exit_status);
|
||||||
},
|
self.inferior = None
|
||||||
|
}
|
||||||
Status::Signaled(_) => (),
|
Status::Signaled(_) => (),
|
||||||
Status::Stopped(_, _) => (),
|
Status::Stopped(_signal, _) => {
|
||||||
|
println!("Child stopped (signal {})", _signal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error running(continue) subprocess");
|
eprintln!("Error running(continue) subprocess");
|
||||||
@ -54,8 +72,32 @@ impl Debugger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DebuggerCommand::Quit => {
|
DebuggerCommand::Quit => {
|
||||||
|
self._try_kill();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DebuggerCommand::Continue => {
|
||||||
|
let instance = self.inferior.as_mut();
|
||||||
|
if instance.is_none() {
|
||||||
|
eprintln!("No inferior process running");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let instance = instance.unwrap();
|
||||||
|
let res = instance.cont();
|
||||||
|
if let Ok(res) = res {
|
||||||
|
match res {
|
||||||
|
Status::Exited(exit_status) => {
|
||||||
|
println!("Child exited (status {})", exit_status);
|
||||||
|
self.inferior = None
|
||||||
|
}
|
||||||
|
Status::Signaled(_) => (),
|
||||||
|
Status::Stopped(_signal, _) => {
|
||||||
|
println!("Child stopped (signal {})", _signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error running(continue) subprocess");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
pub enum DebuggerCommand {
|
pub enum DebuggerCommand {
|
||||||
Quit,
|
Quit,
|
||||||
Run(Vec<String>),
|
Run(Vec<String>),
|
||||||
|
Continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebuggerCommand {
|
impl DebuggerCommand {
|
||||||
@ -13,6 +14,9 @@ impl DebuggerCommand {
|
|||||||
args.iter().map(|s| s.to_string()).collect(),
|
args.iter().map(|s| s.to_string()).collect(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
"c" | "cont" | "continue" => {
|
||||||
|
Some(DebuggerCommand::Continue)
|
||||||
|
}
|
||||||
// Default case:
|
// Default case:
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use nix::unistd::Pid;
|
|||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::process::Child;
|
use std::process::Child;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
/// Indicates inferior stopped. Contains the signal that stopped the process, as well as the
|
/// Indicates inferior stopped. Contains the signal that stopped the process, as well as the
|
||||||
/// current instruction pointer that it is stopped at.
|
/// current instruction pointer that it is stopped at.
|
||||||
@ -87,4 +87,10 @@ impl Inferior {
|
|||||||
ptrace::cont(self.pid(), None)?;
|
ptrace::cont(self.pid(), None)?;
|
||||||
self.wait(None)
|
self.wait(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn kill(&mut self) -> Result<Status, nix::Error> {
|
||||||
|
let _pid = self.pid();
|
||||||
|
self.child.kill().expect("Failed to kill subprocess");
|
||||||
|
self.wait(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user