pub fn new(target: &str, args: &Vec<String>, breakpoints: &Vec<usize>) -> Option<Inferior> {
        let mut cmd = Command::new(target);
        cmd.args(args);
        unsafe {
            cmd.pre_exec(child_traceme);
        }
        let child = cmd.spawn().expect("fail to spawn target programme");
        let mut inferior = Inferior {
            child,
            replaced_values: HashMap::new(),
        };
        match inferior.wait(None) {
            Ok(status) => match status {
                Status::Exited(exit_code) => {
                    println!("target programme exited prematurely (status {})", exit_code);
                    return None;
                }
                Status::Signaled(signal) => {
                    if signal.eq(&signal::Signal::SIGTRAP) {
                        println!("target programme killed by SIGTRAP");
                        return None;
                    }
                }
                Status::Stopped(signal, _) => {
                    if signal.eq(&signal::Signal::SIGTRAP) {
                        for addr in breakpoints.iter() {
                            // install breakpoints
                            match inferior.write_byte(*addr, 0xcc) {
                                Ok(_) => {}
                                Err(err) => println!(
                                    "failed to set breakpoint at position {:#x}, {}",
                                    *addr, err
                                ),
                            }
                        }
                        return Some(inferior);
                    }
                }
            },
            Err(err) => {
                println!("failed to stop target programme, {}", err);
                return None;
            }
        }
        println!("failed to create inferior");
        None
    }
/// Attempts to start a new inferior process. Returns Some(Inferior) if successful, or None if
/// an error is encountered.
Attempts to start a new inferior process. Returns Some(Inferior) if successful, or None if
an error is encountered.
Attempts to start a new inferior process . Returns Some ( Inferior ) if successful or None if an error is encountered .
pub fn new(target: &str, args: &Vec<String>, breakpoints: &Vec<usize>) -> Option<Inferior> {
        let mut cmd = Command::new(target);
        cmd.args(args);
        unsafe {
            cmd.pre_exec(child_traceme);
        }
        let child = cmd.spawn().expect("fail to spawn target programme");
        let mut inferior = Inferior {
            child,
            replaced_values: HashMap::new(),
        };
        match inferior.wait(None) {
            Ok(status) => match status {
                Status::Exited(exit_code) => {
                    println!("target programme exited prematurely (status {})", exit_code);
                    return None;
                }
                Status::Signaled(signal) => {
                    if signal.eq(&signal::Signal::SIGTRAP) {
                        println!("target programme killed by SIGTRAP");
                        return None;
                    }
                }
                Status::Stopped(signal, _) => {
                    if signal.eq(&signal::Signal::SIGTRAP) {
                        for addr in breakpoints.iter() {
                            // install breakpoints
                            match inferior.write_byte(*addr, 0xcc) {
                                Ok(_) => {}
                                Err(err) => println!(
                                    "failed to set breakpoint at position {:#x}, {}",
                                    *addr, err
                                ),
                            }
                        }
                        return Some(inferior);
                    }
                }
            },
            Err(err) => {
                println!("failed to stop target programme, {}", err);
                return None;
            }
        }
        println!("failed to create inferior");
        None
    }
pub fn new ( target : & str , args : & Vec < String > , breakpoints : & Vec < usize > ) -> Option < Inferior > { let mut cmd = Command :: new ( target ) ; cmd . args ( args ) ; unsafe { cmd . pre_exec ( child_traceme ) ; } let child = cmd . spawn ( ) . expect ( " " ) ; let mut inferior = Inferior { child , replaced_values : HashMap :: new ( ) , } ; match inferior . wait ( None ) { Ok ( status ) => match status { Status :: Exited ( exit_code ) => { println ! ( " " exit_code ) ; return None ; } Status :: Signaled ( signal ) => { if signal . eq ( & signal :: Signal :: SIGTRAP ) { println ! ( " " ) ; return None ; } } Status :: Stopped ( signal , _ ) => { if signal . eq ( & signal :: Signal :: SIGTRAP ) { for addr in breakpoints . iter ( ) { // install breakpoints match inferior . write_byte ( * addr , 0xcc ) { Ok ( _ ) => { } Err ( err ) => println ! ( " " addr err ) , } } return Some ( inferior ) ; } } } , Err ( err ) => { println ! ( " " err ) ; return None ; } } println ! ( " " ) ; None }
Attempts to start a new inferior process.
Attempts to start a new inferior process .
target
&str
args
&Vec<String>
breakpoints
&Vec<usize>
target
&str
args
&Vec<String>
breakpoints
&Vec<usize>