1 use super::prelude::*; 2 use crate::protocol::commands::ext::MonitorCmd; 3 use crate::protocol::ConsoleOutput; 4 5 impl<T: Target, C: Connection> GdbStubImpl<T, C> { handle_monitor_cmd( &mut self, res: &mut ResponseWriter<'_, C>, target: &mut T, command: MonitorCmd<'_>, ) -> Result<HandlerStatus, Error<T::Error, C::Error>>6 pub(crate) fn handle_monitor_cmd( 7 &mut self, 8 res: &mut ResponseWriter<'_, C>, 9 target: &mut T, 10 command: MonitorCmd<'_>, 11 ) -> Result<HandlerStatus, Error<T::Error, C::Error>> { 12 let ops = match target.support_monitor_cmd() { 13 Some(ops) => ops, 14 None => return Ok(HandlerStatus::Handled), 15 }; 16 17 crate::__dead_code_marker!("monitor_cmd", "impl"); 18 19 let handler_status = match command { 20 MonitorCmd::qRcmd(cmd) => { 21 let use_rle = ops.use_rle(); 22 23 let mut err: Result<_, Error<T::Error, C::Error>> = Ok(()); 24 let mut callback = |msg: &[u8]| { 25 // TODO: replace this with a try block (once stabilized) 26 let e = (|| { 27 let mut res = ResponseWriter::new(res.as_conn(), use_rle); 28 res.write_str("O")?; 29 res.write_hex_buf(msg)?; 30 res.flush()?; 31 Ok(()) 32 })(); 33 34 if let Err(e) = e { 35 err = Err(e) 36 } 37 }; 38 39 ops.handle_monitor_cmd(cmd.hex_cmd, ConsoleOutput::new(&mut callback)) 40 .map_err(Error::TargetError)?; 41 err?; 42 43 HandlerStatus::NeedsOk 44 } 45 }; 46 47 Ok(handler_status) 48 } 49 } 50