-
-
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.
- Loading branch information
Showing
21 changed files
with
328 additions
and
2 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,9 @@ | ||
use gdbstub::target; | ||
|
||
use crate::emu::Emu; | ||
|
||
impl target::ext::exec_file::ExecFile for Emu { | ||
fn get_exec_file(&self, _pid: Option<u64>) -> &[u8] { | ||
b"/test.elf" | ||
} | ||
} |
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 gdbstub::target; | ||
|
||
use crate::emu::Emu; | ||
|
||
use crate::TEST_PROGRAM_ELF; | ||
|
||
impl target::ext::host_io::HostIo for Emu { | ||
fn open(&self, filename: &[u8], _flags: u64, _mode: u64) -> i64 { | ||
if filename == b"/test.elf" { | ||
1 | ||
} else { | ||
-1 | ||
} | ||
} | ||
|
||
fn close(&self, fd: usize) -> i64 { | ||
if fd == 1 { | ||
0 | ||
} else { | ||
-1 | ||
} | ||
} | ||
|
||
fn pread(&self, fd: usize, count: usize, offset: usize) -> &[u8] { | ||
if fd == 1 { | ||
let len = TEST_PROGRAM_ELF.len(); | ||
&TEST_PROGRAM_ELF[offset.min(len)..(offset + count).min(len)] | ||
} else { | ||
b"" | ||
} | ||
} | ||
|
||
fn setfs(&self, _fd: usize) -> i64 { | ||
0 | ||
} | ||
} |
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,28 @@ | ||
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 filename = ops.get_exec_file(cmd.pid); | ||
res.write_binary_range(filename, cmd.offset, cmd.len)?; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use super::prelude::*; | ||
use crate::protocol::commands::ext::HostIo; | ||
|
||
impl<T: Target, C: Connection> GdbStubImpl<T, C> { | ||
pub(crate) fn handle_host_io( | ||
&mut self, | ||
res: &mut ResponseWriter<C>, | ||
target: &mut T, | ||
command: HostIo, | ||
) -> Result<HandlerStatus, Error<T::Error, C::Error>> { | ||
let ops = match target.host_io() { | ||
Some(ops) => ops, | ||
None => return Ok(HandlerStatus::Handled), | ||
}; | ||
|
||
crate::__dead_code_marker!("host_io", "impl"); | ||
|
||
let handler_status = match command { | ||
HostIo::vFileOpen(cmd) => { | ||
let ret = ops.open(cmd.filename, cmd.flags, cmd.mode); | ||
res.write_str("F")?; | ||
res.write_num(ret)?; | ||
HandlerStatus::Handled | ||
} | ||
HostIo::vFileClose(cmd) => { | ||
let ret = ops.close(cmd.fd); | ||
res.write_str("F")?; | ||
res.write_num(ret)?; | ||
HandlerStatus::Handled | ||
} | ||
HostIo::vFilePread(cmd) => { | ||
let data = ops.pread(cmd.fd, cmd.count, cmd.offset); | ||
res.write_str("F")?; | ||
res.write_num(data.len())?; | ||
res.write_str(";")?; | ||
res.write_binary(data)?; | ||
HandlerStatus::Handled | ||
} | ||
HostIo::vFileSetfs(cmd) => { | ||
let ret = ops.setfs(cmd.fd); | ||
res.write_str("F")?; | ||
res.write_num(ret)?; | ||
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,27 @@ | ||
use super::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct qXferExecFileRead { | ||
pub pid: Option<u64>, | ||
pub offset: usize, | ||
pub len: usize, | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for qXferExecFileRead { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let body = buf.into_body(); | ||
|
||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
let mut body = body.split(|b| *b == b':').skip(1); | ||
let pid = decode_hex::<u64>(body.next()?).ok(); | ||
|
||
let mut body = body.next()?.split(|b| *b == b','); | ||
let offset = decode_hex(body.next()?).ok()?; | ||
let len = decode_hex(body.next()?).ok()?; | ||
|
||
Some(qXferExecFileRead {pid, offset, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct vFileClose { | ||
pub fd: usize, | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for vFileClose { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let body = buf.into_body(); | ||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
match body { | ||
[b':', body @ ..] => { | ||
let fd = decode_hex(body).ok()?; | ||
Some(vFileClose{fd}) | ||
}, | ||
_ => None, | ||
} | ||
} | ||
} |
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,28 @@ | ||
use super::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct vFileOpen<'a> { | ||
pub filename: &'a [u8], | ||
pub flags: u64, | ||
pub mode: u64, | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for vFileOpen<'a> { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let body = buf.into_body(); | ||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
match body { | ||
[b':', body @ ..] => { | ||
let mut body = body.splitn_mut_no_panic(3, |b| *b == b','); | ||
let filename = decode_hex_buf(body.next()?).ok()?; | ||
let flags= decode_hex(body.next()?).ok()?; | ||
let mode= decode_hex(body.next()?).ok()?; | ||
Some(vFileOpen{filename, flags, mode}) | ||
}, | ||
_ => None, | ||
} | ||
} | ||
} |
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,28 @@ | ||
use super::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct vFilePread { | ||
pub fd: usize, | ||
pub count: usize, | ||
pub offset: usize, | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for vFilePread { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let body = buf.into_body(); | ||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
match body { | ||
[b':', body @ ..] => { | ||
let mut body = body.splitn_mut_no_panic(3, |b| *b == b','); | ||
let fd = decode_hex(body.next()?).ok()?; | ||
let count= decode_hex(body.next()?).ok()?; | ||
let offset= decode_hex(body.next()?).ok()?; | ||
Some(vFilePread{fd, count, offset}) | ||
}, | ||
_ => None, | ||
} | ||
} | ||
} |
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,23 @@ | ||
use super::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct vFileSetfs { | ||
pub fd: usize, | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for vFileSetfs { | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let body = buf.into_body(); | ||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
match body { | ||
[b':', body @ ..] => { | ||
let fd = decode_hex(body).ok()?; | ||
Some(vFileSetfs{fd}) | ||
}, | ||
_ => None, | ||
} | ||
} | ||
} |
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,11 @@ | ||
//! Provide exec-file path for the target. | ||
use crate::target::Target; | ||
|
||
/// Target Extension - Provide current exec-file. | ||
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<u64>) -> &[u8]; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Provide Host I/O operations for the target. | ||
use crate::target::Target; | ||
|
||
/// Target Extension - Perform I/O operations on host | ||
pub trait HostIo: Target { | ||
/// Open a file at filename and return a file descriptor for it, or return | ||
/// -1 if an error occurs. | ||
fn open(&self, filename: &[u8], flags: u64, mode: u64) -> i64; | ||
/// Close the open file corresponding to fd and return 0, or -1 if an error | ||
/// occurs. | ||
fn close(&self, fd: usize) -> i64; | ||
/// Read data from the open file corresponding to fd. | ||
fn pread(&self, fd: usize, count: usize, offset: usize) -> &[u8]; | ||
/// Select the filesystem on which vFile operations with filename arguments | ||
/// will operate. | ||
fn setfs(&self, fd: usize) -> i64; | ||
} | ||
|
||
define_ext!(HostIoOps, HostIo); |
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
Oops, something went wrong.