Skip to content

Commit

Permalink
Allow Target to override Arch's target description
Browse files Browse the repository at this point in the history
  • Loading branch information
DrChat committed Mar 16, 2021
1 parent cd5d04b commit 13e8f1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gdbstub_impl/mod.rs
Expand Up @@ -303,7 +303,9 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
// TODO: implement conditional breakpoint support (since that's kool).
// res.write_str("ConditionalBreakpoints+;")?;

if T::Arch::target_description_xml().is_some() {
// FIXME: `description_xml` returns an owned String, so this is not a very
// efficient way to check if it will return a custom description.
if target.description_xml().is_some() {
res.write_str(";qXfer:features:read+")?;
}

Expand All @@ -314,7 +316,7 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
HandlerStatus::NeedsOK
}
ext::Base::qXferFeaturesRead(cmd) => {
match T::Arch::target_description_xml() {
match target.description_xml() {
Some(xml) => {
let xml = xml.trim();
if cmd.offset >= xml.len() {
Expand Down
10 changes: 10 additions & 0 deletions src/target/mod.rs
Expand Up @@ -239,6 +239,16 @@ pub trait Target {
fn section_offsets(&mut self) -> Option<ext::section_offsets::SectionOffsetsOps<Self>> {
None
}

/// Get the target description in XML.
/// In most cases you will not need to implement this method, and can simply
/// rely on the one defined in [`Arch`].
///
/// Please refer to [`Arch::target_description_xml`] for further
/// documentation.
fn description_xml(&self) -> Option<&'static str> {
Self::Arch::target_description_xml()
}
}

macro_rules! impl_dyn_target {
Expand Down

0 comments on commit 13e8f1e

Please sign in to comment.