Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a stub for the arch (currently only works with a local branch). Add the result of my observation to the README. Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
- Loading branch information
Showing
5 changed files
with
117 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ edition = "2018" | |
[features] | ||
default = [] | ||
|
||
stub_aarch64 = [] | ||
stub_arm = [] | ||
stub_x86 = [] | ||
stub_mips = [] | ||
|
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,108 @@ | ||
use gdbstub::arch::{Arch, SingleStepGdbBehavior}; | ||
use gdbstub::common::Signal; | ||
use gdbstub::target; | ||
use gdbstub::target::ext::base::singlethread::{SingleThreadBase, SingleThreadResume}; | ||
use gdbstub::target::{Target, TargetResult}; | ||
|
||
use crate::emu::{Emu, ExecMode}; | ||
|
||
impl Target for Emu<u64> { | ||
type Arch = gdbstub_arch::aarch64::AArch64; | ||
type Error = &'static str; | ||
|
||
#[inline(always)] | ||
fn base_ops(&mut self) -> target::ext::base::BaseOps<Self::Arch, Self::Error> { | ||
target::ext::base::BaseOps::SingleThread(self) | ||
} | ||
|
||
#[inline(always)] | ||
fn guard_rail_implicit_sw_breakpoints(&self) -> bool { | ||
true | ||
} | ||
|
||
#[inline(always)] | ||
fn guard_rail_single_step_gdb_behavior(&self) -> SingleStepGdbBehavior { | ||
if !self.with_guard_rail { | ||
SingleStepGdbBehavior::Optional | ||
} else { | ||
Self::Arch::single_step_gdb_behavior() | ||
} | ||
} | ||
} | ||
|
||
impl SingleThreadResume for Emu<u64> { | ||
fn resume(&mut self, signal: Option<Signal>) -> Result<(), Self::Error> { | ||
if signal.is_some() { | ||
return Err("no support for continuing with signal"); | ||
} | ||
|
||
self.exec_mode = ExecMode::Continue; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[inline(always)] | ||
fn support_single_step( | ||
&mut self, | ||
) -> Option<target::ext::base::singlethread::SingleThreadSingleStepOps<Self>> { | ||
if self.with_single_step { | ||
Some(self) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
impl SingleThreadBase for Emu<u64> { | ||
fn read_registers( | ||
&mut self, | ||
regs: &mut gdbstub_arch::aarch64::reg::AArch64CoreRegs, | ||
) -> TargetResult<(), Self> { | ||
log::debug!("read_registers"); | ||
|
||
for (i, reg) in regs.x.iter_mut().enumerate() { | ||
*reg = i as u64; | ||
} | ||
regs.pc = 0x5555_0000; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn write_registers( | ||
&mut self, | ||
regs: &gdbstub_arch::aarch64::reg::AArch64CoreRegs, | ||
) -> TargetResult<(), Self> { | ||
log::debug!("write_registers: {:#x?}", regs); | ||
Ok(()) | ||
} | ||
|
||
fn read_addrs(&mut self, start_addr: u64, data: &mut [u8]) -> TargetResult<(), Self> { | ||
log::debug!("read_addrs: {:#x?},{}", start_addr, data.len()); | ||
data.fill(0x00); // nop | ||
Ok(()) | ||
} | ||
|
||
fn write_addrs(&mut self, start_addr: u64, data: &[u8]) -> TargetResult<(), Self> { | ||
log::debug!("write_addrs: {:#x?},{:x?}", start_addr, data); | ||
Ok(()) | ||
} | ||
|
||
#[inline(always)] | ||
fn support_resume( | ||
&mut self, | ||
) -> Option<target::ext::base::singlethread::SingleThreadResumeOps<'_, Self>> { | ||
Some(self) | ||
} | ||
} | ||
|
||
impl target::ext::base::singlethread::SingleThreadSingleStep for Emu<u64> { | ||
fn step(&mut self, signal: Option<Signal>) -> Result<(), Self::Error> { | ||
if signal.is_some() { | ||
return Err("no support for stepping with signal"); | ||
} | ||
|
||
self.exec_mode = ExecMode::Step; | ||
|
||
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