Skip to content

Commit

Permalink
minor tweaks, notes, and docs
Browse files Browse the repository at this point in the history
just a few things that I noticed while rummaging around in the codebase.
they don't really merit individial commits...
  • Loading branch information
daniel5151 committed Sep 9, 2020
1 parent eea548b commit 27a950f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
mod impls;

/// A trait to perform bytewise I/O over a serial transport layer.
///
/// When the `std` feature is enabled, this trait is automatically implemented
/// for [`TcpStream`](https://doc.rust-lang.org/std/net/struct.TcpStream.html)
/// and [`UnixStream`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixStream.html)
/// (on unix systems).
pub trait Connection {
/// Transport-specific error type.
type Error;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/commands/_qSupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> Features<'a> {
b'+' => FeatureSupported::Yes,
b'-' => FeatureSupported::No,
b'?' => FeatureSupported::Maybe,
_ => unreachable!(),
_ => return Err("invalid feature flag (must be +, -, or ?)"),
},
}),
Some(_) => {
Expand Down
8 changes: 4 additions & 4 deletions src/protocol/console_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Drop for ConsoleOutput<'_> {
macro_rules! output {
($console_output:expr, $($args:tt)*) => {{
use std::fmt::Write;
writeln!($console_output, $($args)*).unwrap();
let _ = writeln!($console_output, $($args)*);
}};
}

Expand All @@ -85,14 +85,14 @@ macro_rules! output {
#[macro_export]
macro_rules! outputln {
($console_output:expr) => {{
use std::fmt::Write;
use core::fmt::Write;
let _ = writeln!($console_output);
}};
($console_output:expr,) => {
outputln!($console_output)
};
($console_output:expr, $($args:tt)*) => {{
use std::fmt::Write;
writeln!($console_output, $($args)*).unwrap();
use core::fmt::Write;
let _ = writeln!($console_output, $($args)*);
}};
}
15 changes: 10 additions & 5 deletions src/protocol/response_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::internal::BeBytes;
use crate::protocol::{IdKind, ThreadId};
use crate::Connection;

#[cfg(feature = "alloc")]
use alloc::string::String;

/// Newtype around a Connection error. Having a newtype allows implementing a
/// `From<ResponseWriterError<C>> for crate::Error<T, C>`, which greatly
/// simplifies some of the error handling in the main gdbstub.
Expand All @@ -14,8 +17,10 @@ pub struct ResponseWriter<'a, C: Connection + 'a> {
inner: &'a mut C,
started: bool,
checksum: u8,
// buffer outgoing message, for logging purposes
#[cfg(feature = "std")]
// buffer outgoing message
// TODO: add `write_all` method to Connection, and allow user to optionally pass outgoing
// packet buffer? This could improve performance (instead of writing a single byte at a time)
#[cfg(feature = "alloc")]
msg: String,
}

Expand All @@ -26,7 +31,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
inner,
started: false,
checksum: 0,
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
msg: String::new(),
}
}
Expand All @@ -36,7 +41,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
// don't include '#' in checksum calculation
let checksum = self.checksum;

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
trace!("--> ${}#{:02x?}", self.msg, checksum);

self.write(b'#')?;
Expand All @@ -52,7 +57,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {

/// Write a single byte.
pub fn write(&mut self, byte: u8) -> Result<(), Error<C::Error>> {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
self.msg.push(byte as char);

if !self.started {
Expand Down

0 comments on commit 27a950f

Please sign in to comment.