Skip to content

Commit 2811105

Browse files
bet4itdaniel5151
andcommitted
Apply suggestions from code review
Co-authored-by: Daniel Prilik <[email protected]>
1 parent 3949c68 commit 2811105

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

examples/armv4t/gdb/exec_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl target::ext::exec_file::ExecFile for Emu {
1515
let filename = b"/test.elf";
1616
let len = filename.len();
1717
let data =
18-
&filename[(offset as usize).min(len) as usize..((offset + length) as usize).min(len)];
18+
&filename[offset.min(len)..(offset + length).min(len)];
1919
let buf = &mut buf[..data.len()];
2020
buf.copy_from_slice(data);
2121
Ok(data.len())

src/protocol/commands/_qXfer_exec_file.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ impl<'a> ParseCommand<'a> for qXferExecFileRead<'a> {
2121
}
2222

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

2629
let mut body = body.next()?.split(|b| *b == b',');
2730
let offset = decode_hex(body.next()?).ok()?;

src/target/ext/exec_file.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ use crate::common::Pid;
99
/// I/O Extensions`](crate::target::ext::host_io), which enables the GDB client
1010
/// to read the executable file directly from the target
1111
pub trait ExecFile: Target {
12-
/// Get full absolute name of the file that was executed to create
13-
/// process `pid` running on the remote system, or the filename
14-
/// corresponding to the currently executing process if no `pid` is
15-
/// provided.
16-
/// Store the name into `buf`, and return the length of name.
12+
/// Get full absolute path of the file that was executed to create
13+
/// process `pid` running on the remote system.
14+
///
15+
/// If `pid` is `None`, return the filename corresponding to the
16+
/// currently executing process.
17+
///
18+
/// Return the number of bytes written into `buf` (which may be less than `length`).
19+
///
20+
/// If `offset` is greater than the length of the underlying data, return `Ok(0)`.
1721
fn get_exec_file(
1822
&self,
1923
pid: Option<Pid>,

0 commit comments

Comments
 (0)