try frame

This commit is contained in:
nora 2023-06-13 14:49:51 +02:00
parent 4baab43e17
commit 764239958f
2 changed files with 25 additions and 17 deletions

View file

@ -10,4 +10,7 @@ pub use divination::{dwarf_info, DwarfInfo};
pub fn uwutables(dwarf_info: DwarfInfo) { pub fn uwutables(dwarf_info: DwarfInfo) {
trace!("getting uwutables from {:p}", dwarf_info.dwarf); trace!("getting uwutables from {:p}", dwarf_info.dwarf);
unsafe {
parse::parse_cie(dwarf_info.dwarf);
}
} }

View file

@ -70,16 +70,16 @@ impl ILeb128 {
} }
/// Common Information Entry /// Common Information Entry
struct Cie<'a> { pub struct Cie<'a> {
/// A constant that gives the number of bytes of the CIE structure, not including /// A constant that gives the number of bytes of the CIE structure, not including
/// the length field itself (see Section 7.2.2 on page 184). The size of the length /// the length field itself (see Section 7.2.2 on page 184). The size of the length
/// field plus the value of length must be an integral multiple of the address size. /// field plus the value of length must be an integral multiple of the address size.
length: usize, pub length: usize,
/// A constant that is used to distinguish CIEs from FDEs. /// A constant that is used to distinguish CIEs from FDEs.
cie_id: Id, pub cie_id: Id,
/// A version number (see Section 7.24 on page 238). This number is specific to /// A version number (see Section 7.24 on page 238). This number is specific to
/// the call frame information and is independent of the DWARF version number. /// the call frame information and is independent of the DWARF version number.
version: u8, pub version: u8,
/// A null-terminated UTF-8 string that identifies the augmentation to this CIE or /// A null-terminated UTF-8 string that identifies the augmentation to this CIE or
/// to the FDEs that use it. If a reader encounters an augmentation string that is /// to the FDEs that use it. If a reader encounters an augmentation string that is
/// unexpected, then only the following fields can be read: /// unexpected, then only the following fields can be read:
@ -95,52 +95,52 @@ struct Cie<'a> {
/// ///
/// Because the .debug_frame section is useful independently of any .debug_info /// Because the .debug_frame section is useful independently of any .debug_info
/// section, the augmentation string always uses UTF-8 encoding. /// section, the augmentation string always uses UTF-8 encoding.
augmentation: &'a str, pub augmentation: &'a str,
/// The size of a target address in this CIE and any FDEs that use it, in bytes. If a /// The size of a target address in this CIE and any FDEs that use it, in bytes. If a
/// compilation unit exists for this frame, its address size must match the address /// compilation unit exists for this frame, its address size must match the address
/// size here. /// size here.
address_size: u8, pub address_size: u8,
/// The size of a segment selector in this CIE and any FDEs that use it, in bytes. /// The size of a segment selector in this CIE and any FDEs that use it, in bytes.
segment_selector_size: u8, pub segment_selector_size: u8,
/// A constant that is factored out of all advance location instructions (see /// A constant that is factored out of all advance location instructions (see
/// Section 6.4.2.1 on page 177). The resulting value is /// Section 6.4.2.1 on page 177). The resulting value is
/// (operand * code_alignment_factor). /// (operand * code_alignment_factor).
code_alignment_factor: ULeb128, pub code_alignment_factor: ULeb128,
/// A constant that is factored out of certain offset instructions (see /// A constant that is factored out of certain offset instructions (see
/// Sections 6.4.2.2 on page 177 and 6.4.2.3 on page 179). The resulting value is /// Sections 6.4.2.2 on page 177 and 6.4.2.3 on page 179). The resulting value is
/// (operand * data_alignment_factor). /// (operand * data_alignment_factor).
data_alignment_factor: ILeb128, pub data_alignment_factor: ILeb128,
/// An unsigned LEB128 constant that indicates which column in the rule table /// An unsigned LEB128 constant that indicates which column in the rule table
/// represents the return address of the function. Note that this column might not /// represents the return address of the function. Note that this column might not
/// correspond to an actual machine register. /// correspond to an actual machine register.
return_address_register: ULeb128, pub return_address_register: ULeb128,
/// A sequence of rules that are interpreted to create the initial setting of each /// A sequence of rules that are interpreted to create the initial setting of each
/// column in the table. /// column in the table.
/// The default rule for all columns before interpretation of the initial instructions /// The default rule for all columns before interpretation of the initial instructions
/// is the undefined rule. However, an ABI authoring body or a compilation /// is the undefined rule. However, an ABI authoring body or a compilation
/// system authoring body may specify an alternate default value for any or all /// system authoring body may specify an alternate default value for any or all
/// columns. /// columns.
initial_instructions: &'a [u8], pub initial_instructions: &'a [u8],
} }
/// Frame Description Entry /// Frame Description Entry
struct Fde<'a> { pub struct Fde<'a> {
/// A constant that gives the number of bytes of the header and instruction /// A constant that gives the number of bytes of the header and instruction
/// stream for this function, not including the length field itself (see Section 7.2.2 /// stream for this function, not including the length field itself (see Section 7.2.2
/// on page 184). The size of the length field plus the value of length must be an /// on page 184). The size of the length field plus the value of length must be an
/// integral multiple of the address size. /// integral multiple of the address size.
length: usize, pub length: usize,
/// A constant offset into the .debug_frame section that denotes the CIE that is /// A constant offset into the .debug_frame section that denotes the CIE that is
/// associated with this FDE. /// associated with this FDE.
cie_pointer: Id, pub cie_pointer: Id,
/// The address of the first location associated with this table entry. If the /// The address of the first location associated with this table entry. If the
/// segment_selector_size field of this FDEs CIE is non-zero, the initial /// segment_selector_size field of this FDEs CIE is non-zero, the initial
/// location is preceded by a segment selector of the given length. /// location is preceded by a segment selector of the given length.
initial_location: usize, pub initial_location: usize,
/// The number of bytes of program instructions described by this entry. /// The number of bytes of program instructions described by this entry.
address_range: usize, pub address_range: usize,
/// A sequence of table defining instructions that are described in Section 6.4.2. /// A sequence of table defining instructions that are described in Section 6.4.2.
instructions: &'a [u8], pub instructions: &'a [u8],
} }
#[derive(Debug)] #[derive(Debug)]
@ -323,6 +323,11 @@ pub enum Instruction {
Nop, Nop,
} }
pub unsafe fn parse_cie(ptr: *const u8) {
let len = *ptr.cast::<u32>();
trace!("{:x}", len);
}
pub(super) struct InstrIter { pub(super) struct InstrIter {
data: *const u8, data: *const u8,
} }