Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Prilik <[email protected]>
  • Loading branch information
bet4it and daniel5151 authored Sep 12, 2021
1 parent 3949c68 commit 3a5c666
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/armv4t/gdb/exec_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl target::ext::exec_file::ExecFile for Emu {
let filename = b"/test.elf";
let len = filename.len();
let data =
&filename[(offset as usize).min(len) as usize..((offset + length) as usize).min(len)];
&filename[offset.min(len)..(offset + length).min(len)];
let buf = &mut buf[..data.len()];
buf.copy_from_slice(data);
Ok(data.len())
Expand Down
5 changes: 4 additions & 1 deletion src/protocol/commands/_qXfer_exec_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl<'a> ParseCommand<'a> for qXferExecFileRead<'a> {
}

let mut body = body.split(|b| *b == b':').skip(1);
let pid = decode_hex(body.next()?).ok().and_then(Pid::new);
let pid = match body.next()? {
[] => None,
buf => Some(Pid::new(decode_hex(buf).ok()?)?)
}

let mut body = body.next()?.split(|b| *b == b',');
let offset = decode_hex(body.next()?).ok()?;
Expand Down
14 changes: 9 additions & 5 deletions src/target/ext/exec_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ use crate::common::Pid;
/// I/O Extensions`](crate::target::ext::host_io), which enables the GDB client
/// to read the executable file directly from the target
pub trait ExecFile: Target {
/// Get full absolute name of the file that was executed to create
/// process `pid` running on the remote system, or the filename
/// corresponding to the currently executing process if no `pid` is
/// provided.
/// Store the name into `buf`, and return the length of name.
/// Get full absolute path of the file that was executed to create
/// process `pid` running on the remote system.
///
/// If `pid` is `None`, return the filename corresponding to the
/// currently executing process.
///
/// Return the number of bytes written into `buf` (which may be less than `length`).
///
/// If `offset` is greater than the length of the underlying data, return `Ok(0)`.
fn get_exec_file(
&self,
pid: Option<Pid>,
Expand Down

0 comments on commit 3a5c666

Please sign in to comment.