• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Get section/segment relocation offsets from the target.
2 //!
3 //! For some targets, sections may be relocated from their base address. As
4 //! a result, the stub may need to tell GDB the final section addresses
5 //! to ensure that debug symbols are resolved correctly after relocation.
6 //!
7 //! _Note:_ This extension corresponds to the `qOffsets` command, which is
8 //! limited to reporting the offsets for code, data and bss, and is
9 //! generally considered a legacy feature.
10 //!
11 //! For targets where library offsets are maintained externally (e.g. Windows)
12 //! you should consider implementing the more flexible `qXfer:library:read`.
13 //! See issue [#20](https://github.com/daniel5151/gdbstub/issues/20) for more
14 //! info.
15 //!
16 //! For System-V architectures GDB is capable of extracting library offsets
17 //! from memory if it knows the base address of the dynamic linker. The base
18 //! address can be specified by either implementing this command or by including
19 //! a `AT_BASE` entry in the response to the more modern `qXfer:auxv:read`
20 //! command. See issue [#20](https://github.com/daniel5151/gdbstub/issues/20)
21 //! for more info.
22 
23 use crate::arch::Arch;
24 use crate::target::Target;
25 
26 /// Describes the offset the target loaded the image sections at, so the target
27 /// can notify GDB that it needs to adjust the addresses of symbols.
28 ///
29 /// GDB supports either section offsets, or segment addresses.
30 pub enum Offsets<U> {
31     /// Section offsets relative to their base addresses.
32     Sections {
33         /// The offset of the `.text` section.
34         text: U,
35         /// The offset of the `.data` section.
36         data: U,
37         /// The offset of the `.bss` section.
38         ///
39         /// _Note:_ GDB expects that `bss` is either `None` or equal to `data`.
40         bss: Option<U>,
41     },
42 
43     /// Absolute addresses of the first two segments.
44     ///
45     /// _Note:_ any extra segments will kept at fixed offsets relative to the
46     /// last relocated segment.
47     Segments {
48         /// The absolute address of the first segment which conventionally
49         /// contains program code.
50         text_seg: U,
51         /// The absolute address of the second segment which conventionally
52         /// contains modifiable data.
53         data_seg: Option<U>,
54     },
55 }
56 
57 /// Target Extension - Get section/segment relocation offsets from the target.
58 ///
59 /// Corresponds to the `qOffset` command. See the [section_offset module
60 /// documentation](index.html).
61 pub trait SectionOffsets: Target {
62     /// Return the target's current section (or segment) offsets.
get_section_offsets(&mut self) -> Result<Offsets<<Self::Arch as Arch>::Usize>, Self::Error>63     fn get_section_offsets(&mut self) -> Result<Offsets<<Self::Arch as Arch>::Usize>, Self::Error>;
64 }
65 
66 define_ext!(SectionOffsetsOps, SectionOffsets);
67