From 902951cf3c55fc8645618492618404800afbaa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Fri, 22 Jul 2022 08:47:41 +0100 Subject: [PATCH] base: Introduce .write_x() for unavailable data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/protocol/response_writer.rs | 8 ++++++++ src/stub/core_impl/base.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/protocol/response_writer.rs b/src/protocol/response_writer.rs index 3dea22a..1ef43ea 100644 --- a/src/protocol/response_writer.rs +++ b/src/protocol/response_writer.rs @@ -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> { + 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(&mut self, digit: D) -> Result<(), Error> { diff --git a/src/stub/core_impl/base.rs b/src/stub/core_impl/base.rs index a87483b..c194bbf 100644 --- a/src/stub/core_impl/base.rs +++ b/src/stub/core_impl/base.rs @@ -202,7 +202,7 @@ impl GdbStubImpl { 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::()), }; if let Err(e) = res { err = Err(e);