Skip to content

Commit

Permalink
Parse the H packet
Browse files Browse the repository at this point in the history
This is the simplest fix for bug luser#19.
  • Loading branch information
tromey committed Dec 20, 2017
1 parent efaa64b commit b9242ef
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ enum Command<'a> {
PingThread(ThreadId),
CtrlC,
UnknownVCommand,
/// Set the current thread for future commands, such as `ReadRegister`.
SetCurrentThread(ThreadId),
}

named!(gdbfeature<Known>, map!(map_res!(is_not_s!(";="), str::from_utf8), |s| {
Expand Down Expand Up @@ -235,6 +237,10 @@ fn v_command<'a>(i: &'a [u8]) -> IResult<&'a [u8], Command<'a>> {
|_| Command::UnknownVCommand
})
}
/// Parse the H packet. Only `Hg` is needed, as the other forms are
/// obsoleted by `vCont`.
named!(parse_h_packet<&[u8], ThreadId>,
preceded!(tag!("Hg"), parse_thread_id));

fn command<'a>(i: &'a [u8]) -> IResult<&'a [u8], Command<'a>> {
alt!(i,
Expand All @@ -248,7 +254,7 @@ fn command<'a>(i: &'a [u8]) -> IResult<&'a [u8], Command<'a>> {
// F RC,EE,CF;XX’
| tag!("g") => { |_| Command::ReadGeneralRegisters }
// G XX...
// H op thread-id
| parse_h_packet => { |thread_id| Command::SetCurrentThread(thread_id) }
// i [addr[,nnn]]
| tag!("k") => { |_| Command::Kill(None) }
| read_memory => { |(addr, length)| Command::ReadMemory(addr, length) }
Expand Down Expand Up @@ -302,6 +308,10 @@ pub trait Handler {
fn read_register(&self, _register: u64) -> Result<Vec<u8>, SimpleError> {
Err(SimpleError::Error(NOT_IMPLEMENTED))
}

fn set_current_thread(&self, _id: ThreadId) -> Result<(), SimpleError> {
Err(SimpleError::Error(NOT_IMPLEMENTED))
}
}

fn compute_checksum_incremental(bytes: &[u8], init: u8) -> u8 {
Expand Down Expand Up @@ -386,6 +396,12 @@ fn handle_packet<H, W>(data: &[u8],
Result::Err(SimpleError::Error(val)) => Response::Error(val),
}
},
Command::SetCurrentThread(thread_id) => {
match handler.set_current_thread(thread_id) {
Result::Ok(_) => Response::String("OK"),
Result::Err(SimpleError::Error(val)) => Response::Error(val),
}
},
Command::Query(Query::SupportedFeatures(features)) =>
handle_supported_features(handler, &features),
Command::Query(Query::StartNoAckMode) => {
Expand Down

0 comments on commit b9242ef

Please sign in to comment.