Skip to content

Commit

Permalink
SingleRegisterAccess: Support unavailable regs
Browse files Browse the repository at this point in the history
Enable an implementation of SingleRegisterAccess to signal to gdbstub
that a read register is recognized (as per RegId::from_raw_id()) but
is unavailable by reporting a 0-byte read.

In that case, make gdbstub report to the GDB client the state of the
unavailable register by following the registers packet protocol:

> [...] the stub may also return a string of literal `x`s in place of
> the register data digits, to indicate that the corresponding register
> has not been collected, thus its value is unavailable.

Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
  • Loading branch information
ptosi committed Jul 20, 2022
1 parent 51c8ba9 commit 8346528
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/protocol/response_writer.rs
Expand Up @@ -212,6 +212,14 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
Ok(())
}

/// Marks data of 'size' bytes as unavailable.
pub fn write_x(&mut self, size: usize) -> Result<(), Error<C::Error>> {
for _ in 0..(size * 2) {
self.write(b'x')?;
}
Ok(())
}

/// Write a number as a big-endian hex string using the most compact
/// representation possible (i.e: trimming leading zeros).
pub fn write_num<D: BeBytes + PrimInt>(&mut self, digit: D) -> Result<(), Error<C::Error>> {
Expand Down
16 changes: 12 additions & 4 deletions src/stub/core_impl/single_register_access.rs
Expand Up @@ -33,14 +33,22 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {

let len = ops.read_register(id, reg_id, buf).handle_error()?;

if let Some(size) = reg_size {
if size.get() != len {
if len == 0 {
if let Some(size) = reg_size {
res.write_x(size.get())?;
} else {
return Err(Error::TargetMismatch);
}
} else {
buf = buf.get_mut(..len).ok_or(Error::PacketBufferOverflow)?;
if let Some(size) = reg_size {
if size.get() != len {
return Err(Error::TargetMismatch);
}
} else {
buf = buf.get_mut(..len).ok_or(Error::PacketBufferOverflow)?;
}
res.write_hex_buf(buf)?;
}
res.write_hex_buf(buf)?;
HandlerStatus::Handled
}
SingleRegisterAccess::P(p) => {
Expand Down

0 comments on commit 8346528

Please sign in to comment.