Skip to content

Commit

Permalink
Some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bet4it committed Aug 24, 2021
1 parent 8f0aa74 commit 01e83cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions examples/armv4t/gdb/exec_file.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use gdbstub::common::Pid;
use gdbstub::target;
use gdbstub::target::TargetResult;

use crate::emu::Emu;

impl target::ext::exec_file::ExecFile for Emu {
fn get_exec_file(&self, _pid: Option<Pid>) -> &[u8] {
b"/test.elf"
fn get_exec_file(&self, _pid: Option<Pid>) -> TargetResult<&[u8], Self> {
Ok(b"/test.elf")
}
}
6 changes: 5 additions & 1 deletion examples/armv4t/gdb/host_io.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::io::{Read, Seek, Write};

use crate::TEST_PROGRAM_ELF;
use gdbstub::target;
use gdbstub::target::ext::host_io::{
FsKind, HostIoErrno, HostIoError, HostIoOpenFlags, HostIoOpenMode, HostIoOutput, HostIoResult,
HostIoStat, HostIoToken,
};

use crate::emu::Emu;
use crate::TEST_PROGRAM_ELF;

const FD_RESERVED: u32 = 1;

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

// In this example, the test binary is compiled into the binary itself as the
// `TEST_PROGRAM_ELF` array using `include_bytes!`. As such, we must "spoof" the
// existence of a real file, which will actually be backed by the in-binary
// `TEST_PROGRAM_ELF` array.
if filename == b"/test.elf" {
return Ok(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gdbstub_impl/ext/exec_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {

let handler_status = match command {
ExecFile::qXferExecFileRead(cmd) => {
let filename = ops.get_exec_file(cmd.pid);
let filename = ops.get_exec_file(cmd.pid).handle_error()?;
res.write_binary_range(filename, cmd.offset, cmd.len)?;
HandlerStatus::Handled
}
Expand Down
10 changes: 8 additions & 2 deletions src/target/ext/exec_file.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
//! Provide exec-file path for the target.
use crate::target::Target;
use crate::target::{Target, TargetResult};

use crate::common::Pid;

/// Target Extension - Provide current exec-file.
///
/// NOTE: this extension is primarily intended to be used alongside the [`Host
/// 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 {
/// Return the full absolute name of the file that was executed to create a
/// process running on the remote system.
fn get_exec_file(&self, pid: Option<Pid>) -> &[u8];
/// If no `pid` is provided, return the filename corresponding to the
/// currently executing process.
fn get_exec_file(&self, pid: Option<Pid>) -> TargetResult<&[u8], Self>;
}

define_ext!(ExecFileOps, ExecFile);

0 comments on commit 01e83cf

Please sign in to comment.