Skip to content

Commit

Permalink
Add support for qOffsets packet
Browse files Browse the repository at this point in the history
Adding support for this packet allows the stub to report section offsets
back to gdb so that debug symbols are resolved to the correct addresses if
the target performs any relocations
  • Loading branch information
mchesser committed Aug 27, 2020
1 parent 26dd30f commit db347e0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gdbstub_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
}
}
Command::vContQuestionMark(_) => res.write_str("vCont;c;s")?,
Command::qOffsets(_) => {
if let Some(sections) = target.get_section_offsets().maybe_missing_impl()? {
res.write_str("TextSeg=")?;
res.write_num(sections.text)?;
if let Some(data) = sections.data {
res.write_str(";DataSeg=")?;
res.write_num(data)?;
}
}
}
Command::qXferFeaturesRead(cmd) => {
assert_eq!(cmd.annex, "target.xml");
match T::Arch::target_description_xml() {
Expand Down
1 change: 1 addition & 0 deletions src/protocol/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ commands! {
"qRcmd" => _qRcmd::qRcmd<'a>,
"qsThreadInfo" => _qsThreadInfo::qsThreadInfo,
"qSupported" => _qSupported::qSupported<'a>,
"qOffsets" => _qOffsets::qOffsets,
"qXfer:features:read" => _qXfer_features_read::qXferFeaturesRead<'a>,
"s" => _s::s,
"T" => _t_upcase::T,
Expand Down
13 changes: 13 additions & 0 deletions src/protocol/commands/_qOffsets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::prelude::*;

#[derive(PartialEq, Eq, Debug)]
pub struct qOffsets;

impl<'a> ParseCommand<'a> for qOffsets {
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
if !buf.into_body().is_empty() {
return None;
}
Some(qOffsets)
}
}
23 changes: 23 additions & 0 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ pub trait Target {
})?;
Ok(found)
}

/// (optional) Get section offsets that the target used when relocating the
/// downloaded image.
fn get_section_offsets(
&mut self,
) -> OptResult<SectionOffsets<<Self::Arch as Arch>::Usize>, Self::Error> {
Err(MaybeUnimpl::no_impl())
}
}

/// The kind of watchpoint that should be set/removed.
Expand Down Expand Up @@ -359,6 +367,15 @@ impl Iterator for Actions<'_> {
}
}

/// Describes the offset the target loaded the image sections at so the target
/// can notify GDB that it needs to adjust the addresses of symbols
pub struct SectionOffsets<U> {
/// The offset of the .text section
pub text: U,
/// The offset of the the .data section
pub data: Option<U>,
}

macro_rules! impl_dyn_target {
($type:ty) => {
#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -454,6 +471,12 @@ macro_rules! impl_dyn_target {
fn is_thread_alive(&mut self, tid: Tid) -> OptResult<bool, Self::Error> {
(**self).is_thread_alive(tid)
}

fn get_section_offsets(
&mut self,
) -> OptResult<SectionOffsets<<Self::Arch as Arch>::Usize>, Self::Error> {
(**self).get_section_offsets()
}
}
};
}
Expand Down

0 comments on commit db347e0

Please sign in to comment.