-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,34 @@ | ||
use std::io::prelude::*; | ||
use std::io::{Read, Result, Write}; | ||
use std::net::TcpStream; | ||
|
||
/// A connection to a GDB server over the GDB Remote Serial Protocol. This is the client. | ||
/// | ||
/// See https://sourceware.org/gdb/current/onlinedocs/gdb.html/Remote-Protocol.html | ||
pub struct Gdb { | ||
stream: TcpStream, | ||
} | ||
|
||
// For an example of a GDB server, see https://github.com/ares-emulator/ares/tree/master/nall/gdb | ||
|
||
impl Gdb { | ||
pub fn new(address: &str) -> Result<Self> { | ||
let stream = TcpStream::connect(address)?; | ||
Ok(Self { stream }) | ||
} | ||
|
||
// https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html | ||
pub fn write_packet(&mut self, packet: &[u8]) -> Result<()> { | ||
let checksum = packet | ||
.iter() | ||
.fold(0, |acc: u8, &byte| acc.wrapping_add(byte)); | ||
|
||
self.stream.write_all(b"$")?; | ||
self.stream.write_all(packet)?; | ||
self.stream.write_all(b"#")?; | ||
self.stream | ||
.write_all(format!("{:02}", checksum).as_bytes())?; | ||
|
||
Ok(()) | ||
} | ||
} |
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,33 @@ | ||
use crate::diff::Diff; | ||
use crate::gdb::Gdb; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
#[error("not supported, restart the emulator")] | ||
NotSupported, | ||
} | ||
|
||
/// Apply a diff to a process. | ||
pub fn apply(gdb: &mut Gdb, diff: &[Diff<'_, '_>]) -> Result<(), Error> { | ||
for change in diff { | ||
match change { | ||
Diff::Add(_) => return Err(Error::NotSupported), | ||
Diff::Remove(_) => return Err(Error::NotSupported), | ||
Diff::Change(old_item, new_item) => { | ||
if old_item.size != new_item.size { | ||
// TODO resizes | ||
return Err(Error::NotSupported); | ||
} | ||
|
||
if old_item.ram_addr != new_item.ram_addr { | ||
// TODO moves | ||
return Err(Error::NotSupported); | ||
} | ||
|
||
// TODO | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} |
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