-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support read exec-file * Some small fixes * Try to pass buf as an argument of get_exec_file * Set type of offset and length to usize * Check return size * Apply suggestions from code review Co-authored-by: Daniel Prilik <[email protected]> * Lint * Change type of offset to u64 Co-authored-by: Daniel Prilik <[email protected]>
- Loading branch information
1 parent
9227dfd
commit c2ed3e4
Showing
16 changed files
with
213 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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>, | ||
offset: u64, | ||
length: usize, | ||
buf: &mut [u8], | ||
) -> TargetResult<usize, Self> { | ||
let filename = b"/test.elf"; | ||
let len = filename.len(); | ||
let data = &filename[len.min(offset as usize)..len.min(offset as usize + length)]; | ||
let buf = &mut buf[..data.len()]; | ||
buf.copy_from_slice(data); | ||
Ok(data.len()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
file test.elf | ||
target extended-remote :9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::prelude::*; | ||
use crate::protocol::commands::ext::ExecFile; | ||
|
||
impl<T: Target, C: Connection> GdbStubImpl<T, C> { | ||
pub(crate) fn handle_exec_file( | ||
&mut self, | ||
res: &mut ResponseWriter<C>, | ||
target: &mut T, | ||
command: ExecFile, | ||
) -> Result<HandlerStatus, Error<T::Error, C::Error>> { | ||
let ops = match target.exec_file() { | ||
Some(ops) => ops, | ||
None => return Ok(HandlerStatus::Handled), | ||
}; | ||
|
||
crate::__dead_code_marker!("exec_file", "impl"); | ||
|
||
let handler_status = match command { | ||
ExecFile::qXferExecFileRead(cmd) => { | ||
let ret = ops | ||
.get_exec_file(cmd.pid, cmd.offset, cmd.length, cmd.buf) | ||
.handle_error()?; | ||
if ret == 0 { | ||
res.write_str("l")?; | ||
} else { | ||
res.write_str("m")?; | ||
// TODO: add more specific error variant? | ||
res.write_binary(cmd.buf.get(..ret).ok_or(Error::PacketBufferOverflow)?)?; | ||
} | ||
HandlerStatus::Handled | ||
} | ||
}; | ||
|
||
Ok(handler_status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use super::prelude::*; | ||
|
||
use crate::common::Pid; | ||
|
||
#[derive(Debug)] | ||
pub struct qXferExecFileRead<'a> { | ||
pub pid: Option<Pid>, | ||
pub offset: u64, | ||
pub length: usize, | ||
|
||
pub buf: &'a mut [u8], | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for qXferExecFileRead<'a> { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let (buf, body_range) = buf.into_raw_buf(); | ||
let body = buf.get_mut(body_range.start..body_range.end)?; | ||
|
||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
let mut body = body.split(|b| *b == b':').skip(1); | ||
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()?; | ||
let length = decode_hex(body.next()?).ok()?; | ||
|
||
drop(body); | ||
|
||
Some(qXferExecFileRead {pid, offset, length, buf}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Provide exec-file path for the 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 { | ||
/// 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>, | ||
offset: u64, | ||
length: usize, | ||
buf: &mut [u8], | ||
) -> TargetResult<usize, Self>; | ||
} | ||
|
||
define_ext!(ExecFileOps, ExecFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters