Skip to content

Commit

Permalink
base: Introduce .write_x() for unavailable data
Browse files Browse the repository at this point in the history
Introduce a method that can be used when the stub needs to send back
data that is unavailable to the GDB client. In that case, the GDB
protocol expects literal `'x'` characters to be sent (one per nibble).

Note: no functional change intended.

Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
  • Loading branch information
ptosi committed Jul 22, 2022
1 parent 51c8ba9 commit 902951c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion src/stub/core_impl/base.rs
Expand Up @@ -202,7 +202,7 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
regs.gdb_serialize(|val| {
let res = match val {
Some(b) => res.write_hex_buf(&[b]),
None => res.write_str("xx"),
None => res.write_x(std::mem::size_of::<u8>()),
};
if let Err(e) = res {
err = Err(e);
Expand Down

0 comments on commit 902951c

Please sign in to comment.