Skip to content

Commit 01e83cf

Browse files
committed
Some small fixes
1 parent 8f0aa74 commit 01e83cf

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

examples/armv4t/gdb/exec_file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use gdbstub::common::Pid;
22
use gdbstub::target;
3+
use gdbstub::target::TargetResult;
34

45
use crate::emu::Emu;
56

67
impl target::ext::exec_file::ExecFile for Emu {
7-
fn get_exec_file(&self, _pid: Option<Pid>) -> &[u8] {
8-
b"/test.elf"
8+
fn get_exec_file(&self, _pid: Option<Pid>) -> TargetResult<&[u8], Self> {
9+
Ok(b"/test.elf")
910
}
1011
}

examples/armv4t/gdb/host_io.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::io::{Read, Seek, Write};
22

3-
use crate::TEST_PROGRAM_ELF;
43
use gdbstub::target;
54
use gdbstub::target::ext::host_io::{
65
FsKind, HostIoErrno, HostIoError, HostIoOpenFlags, HostIoOpenMode, HostIoOutput, HostIoResult,
76
HostIoStat, HostIoToken,
87
};
98

109
use crate::emu::Emu;
10+
use crate::TEST_PROGRAM_ELF;
1111

1212
const FD_RESERVED: u32 = 1;
1313

@@ -64,6 +64,10 @@ impl target::ext::host_io::HostIoOpen for Emu {
6464
return Err(HostIoError::Errno(HostIoErrno::ENOENT));
6565
}
6666

67+
// In this example, the test binary is compiled into the binary itself as the
68+
// `TEST_PROGRAM_ELF` array using `include_bytes!`. As such, we must "spoof" the
69+
// existence of a real file, which will actually be backed by the in-binary
70+
// `TEST_PROGRAM_ELF` array.
6771
if filename == b"/test.elf" {
6872
return Ok(0);
6973
}

src/gdbstub_impl/ext/exec_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
1717

1818
let handler_status = match command {
1919
ExecFile::qXferExecFileRead(cmd) => {
20-
let filename = ops.get_exec_file(cmd.pid);
20+
let filename = ops.get_exec_file(cmd.pid).handle_error()?;
2121
res.write_binary_range(filename, cmd.offset, cmd.len)?;
2222
HandlerStatus::Handled
2323
}

src/target/ext/exec_file.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
//! Provide exec-file path for the target.
2-
use crate::target::Target;
2+
use crate::target::{Target, TargetResult};
33

44
use crate::common::Pid;
55

66
/// Target Extension - Provide current exec-file.
7+
///
8+
/// NOTE: this extension is primarily intended to be used alongside the [`Host
9+
/// I/O Extensions`](crate::target::ext::host_io), which enables the GDB client
10+
/// to read the executable file directly from the target
711
pub trait ExecFile: Target {
812
/// Return the full absolute name of the file that was executed to create a
913
/// process running on the remote system.
10-
fn get_exec_file(&self, pid: Option<Pid>) -> &[u8];
14+
/// If no `pid` is provided, return the filename corresponding to the
15+
/// currently executing process.
16+
fn get_exec_file(&self, pid: Option<Pid>) -> TargetResult<&[u8], Self>;
1117
}
1218

1319
define_ext!(ExecFileOps, ExecFile);

0 commit comments

Comments
 (0)