frame

package
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

nolint:stylecheck,deadcode,varcheck

nolint:stylecheck

Package frame contains data structures and related functions for parsing and searching through DWARF .debug_frame data.

Index

Constants

View Source
const (
	DW_OP_addr  = 0x03
	DW_OP_deref = 0x06
)

Operation opcodes.

View Source
const (
	DW_OP_const1u = iota + 0x08
	DW_OP_const1s
	DW_OP_const2u
	DW_OP_const2s
	DW_OP_const4u
	DW_OP_const4s
	DW_OP_const8u
	DW_OP_const8s
	DW_OP_constu
	DW_OP_consts
	DW_OP_dup
	DW_OP_drop
	DW_OP_over
	DW_OP_pick
	DW_OP_swap
	DW_OP_rot
	DW_OP_xderef
	DW_OP_abs
	DW_OP_and
	DW_OP_div
	DW_OP_minus
	DW_OP_mod
	DW_OP_mul
	DW_OP_neg
	DW_OP_not
	DW_OP_or
	DW_OP_plus
	DW_OP_plus_uconst
	DW_OP_shl
	DW_OP_shr
	DW_OP_shra
	DW_OP_xor
	DW_OP_bra
	DW_OP_eq
	DW_OP_ge
	DW_OP_gt
	DW_OP_le
	DW_OP_lt
	DW_OP_ne
	DW_OP_skip
)
View Source
const (
	DW_OP_lit0 = iota + 0x30
	DW_OP_lit1
	DW_OP_lit2
	DW_OP_lit3
	DW_OP_lit4
	DW_OP_lit5
	DW_OP_lit6
	DW_OP_lit7
	DW_OP_lit8
	DW_OP_lit9
	DW_OP_lit10
	DW_OP_lit11
	DW_OP_lit12
	DW_OP_lit13
	DW_OP_lit14
	DW_OP_lit15
	DW_OP_lit16
	DW_OP_lit17
	DW_OP_lit18
	DW_OP_lit19
	DW_OP_lit20
	DW_OP_lit21
	DW_OP_lit22
	DW_OP_lit23
	DW_OP_lit24
	DW_OP_lit25
	DW_OP_lit26
	DW_OP_lit27
	DW_OP_lit28
	DW_OP_lit29
	DW_OP_lit30
	DW_OP_lit31
	DW_OP_reg0
	DW_OP_reg1
	DW_OP_reg2
	DW_OP_reg3
	DW_OP_reg4
	DW_OP_reg5
	DW_OP_reg6
	DW_OP_reg7
	DW_OP_reg8
	DW_OP_reg9
	DW_OP_reg10
	DW_OP_reg11
	DW_OP_reg12
	DW_OP_reg13
	DW_OP_reg14
	DW_OP_reg15
	DW_OP_reg16
	DW_OP_reg17
	DW_OP_reg18
	DW_OP_reg19
	DW_OP_reg20
	DW_OP_reg21
	DW_OP_reg22
	DW_OP_reg23
	DW_OP_reg24
	DW_OP_reg25
	DW_OP_reg26
	DW_OP_reg27
	DW_OP_reg28
	DW_OP_reg29
	DW_OP_reg30
	DW_OP_reg31
	DW_OP_breg0
	DW_OP_breg1
	DW_OP_breg2
	DW_OP_breg3
	DW_OP_breg4
	DW_OP_breg5
	DW_OP_breg6
	DW_OP_breg7
	DW_OP_breg8
	DW_OP_breg9
	DW_OP_breg10
	DW_OP_breg11
	DW_OP_breg12
	DW_OP_breg13
	DW_OP_breg14
	DW_OP_breg15
	DW_OP_breg16
	DW_OP_breg17
	DW_OP_breg18
	DW_OP_breg19
	DW_OP_breg20
	DW_OP_breg21
	DW_OP_breg22
	DW_OP_breg23
	DW_OP_breg24
	DW_OP_breg25
	DW_OP_breg26
	DW_OP_breg27
	DW_OP_breg28
	DW_OP_breg29
	DW_OP_breg30
	DW_OP_breg31
	DW_OP_regx
	DW_OP_fbreg
	DW_OP_bregx
	DW_OP_piece
	DW_OP_deref_size
	DW_OP_xderef_size
	DW_OP_nop
	DW_OP_push_object_address
	DW_OP_call2
	DW_OP_call4
	DW_OP_call_ref
	DW_OP_form_tls_address
	DW_OP_call_frame_cfa
	DW_OP_bit_piece
	DW_OP_lo_user = 0xe0
	DW_OP_hi_user = 0xff
)
View Source
const (
	X86_64FramePointer = 6  // $rbp
	X86_64StackPointer = 7  // $rsp
	Arm64FramePointer  = 29 // $fp // assumption: frame pointers are not stripped
	Arm64StackPointer  = 31 // $sp or $r31
	Arm64LinkRegister  = 30 // $x30 or $lr

)

NOTE: Each register in arm64 or x86 has a DWARF Register Number mapped to its architecture specific Register Name defined in its respective spec. The register numbers are not arbitrary constants but obtained from the spec linked below for each architecture.

From 3.4.1 Initial Stack and Register State for x86_64 https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf From 4.1 DWARF Register Names for Aarch64/Arm64 https://github.com/ARM-software/abi-aa/blob/2023q1-release/aadwarf64/aadwarf64.rst#dwarf-register-names

View Source
const (
	DW_CFA_nop                = 0x0        // No ops
	DW_CFA_set_loc            = 0x01       // op1: address
	DW_CFA_advance_loc1       = iota       // op1: 1-bytes delta
	DW_CFA_advance_loc2                    // op1: 2-byte delta
	DW_CFA_advance_loc4                    // op1: 4-byte delta
	DW_CFA_offset_extended                 // op1: ULEB128 register, op2: ULEB128 offset
	DW_CFA_restore_extended                // op1: ULEB128 register
	DW_CFA_undefined                       // op1: ULEB128 register
	DW_CFA_same_value                      // op1: ULEB128 register
	DW_CFA_register                        // op1: ULEB128 register, op2: ULEB128 register
	DW_CFA_remember_state                  // No ops
	DW_CFA_restore_state                   // No ops
	DW_CFA_def_cfa                         // op1: ULEB128 register, op2: ULEB128 offset
	DW_CFA_def_cfa_register                // op1: ULEB128 register
	DW_CFA_def_cfa_offset                  // op1: ULEB128 offset
	DW_CFA_def_cfa_expression              // op1: BLOCK
	DW_CFA_expression                      // op1: ULEB128 register, op2: BLOCK
	DW_CFA_offset_extended_sf              // op1: ULEB128 register, op2: SLEB128 BLOCK
	DW_CFA_def_cfa_sf                      // op1: ULEB128 register, op2: SLEB128 offset
	DW_CFA_def_cfa_offset_sf               // op1: SLEB128 offset
	DW_CFA_val_offset                      // op1: ULEB128, op2: ULEB128
	DW_CFA_val_offset_sf                   // op1: ULEB128, op2: SLEB128
	DW_CFA_val_expression                  // op1: ULEB128, op2: BLOCK
	DW_CFA_lo_user            = 0x1c       // op1: BLOCK
	DW_CFA_hi_user            = 0x3f       // op1: ULEB128 register, op2: BLOCK
	DW_CFA_advance_loc        = (0x1 << 6) // High 2 bits: 0x1, low 6: delta
	DW_CFA_offset             = (0x2 << 6) // High 2 bits: 0x2, low 6: register
	DW_CFA_restore            = (0x3 << 6) // High 2 bits: 0x3, low 6: register
	// TODO(kakkoyun): Find corresponding values in the spec.
	DW_CFA_MIPS_advance_loc8            = 0x1d
	DW_CFA_GNU_window_save              = 0x2d // DW_CFA_AARCH64_negate_ra_state shares this value too.
	DW_CFA_GNU_args_size                = 0x2e
	DW_CFA_GNU_negative_offset_extended = 0x2f
)

Instructions used to recreate the table from the .debug_frame data.

Variables

This section is empty.

Functions

func CFAString

func CFAString(b byte) string

func DWARFEndian added in v0.28.0

func DWARFEndian(infoSec []byte) binary.ByteOrder

DWARFEndian determines the endianness of the DWARF by using the version number field in the debug_info section Trick borrowed from "debug/dwarf".New().

Types

type CommonInformationEntry

type CommonInformationEntry struct {
	Length                uint32
	CIE_id                uint32
	Version               uint8
	Augmentation          string
	CodeAlignmentFactor   uint64
	DataAlignmentFactor   int64
	ReturnAddressRegister uint64
	InitialInstructions   []byte
	// contains filtered or unexported fields
}

CommonInformationEntry represents a Common Information Entry in the DWARF .debug_frame section.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context represents a function.

func NewContext added in v0.11.0

func NewContext() *Context

func (*Context) Execute

func (ctx *Context) Execute(instructions []byte) *InstructionContextIterator

Execute execute dwarf instructions.

type DWRule

type DWRule struct {
	Rule       Rule
	Offset     int64
	Reg        uint64
	Expression []byte
}

DWRule wrapper of rule defined for register values.

type ErrNoFDEForPCError

type ErrNoFDEForPCError struct {
	PC uint64
}

ErrNoFDEForPCError FDE for PC not found error.

func (*ErrNoFDEForPCError) Error

func (err *ErrNoFDEForPCError) Error() string

type FrameDescriptionEntries

type FrameDescriptionEntries []*FrameDescriptionEntry

func Parse

func Parse(data []byte, order binary.ByteOrder, staticBase uint64, ptrSize int, ehFrameAddr uint64) (FrameDescriptionEntries, error)

Parse takes in data (a byte slice) and returns FrameDescriptionEntries, which is a slice of FrameDescriptionEntry. Each FrameDescriptionEntry has a pointer to CommonInformationEntry. If ehFrameAddr is not zero the .eh_frame format will be used, a minor variant of DWARF described at https://www.airs.com/blog/archives/460. The value of ehFrameAddr will be used as the address at which eh_frame will be mapped into memory.

func (FrameDescriptionEntries) Append

Append appends otherFDEs to fdes and returns the result.

func (FrameDescriptionEntries) FDEForPC

FDEForPC returns the Frame Description Entry for the given PC.

func (FrameDescriptionEntries) Len added in v0.12.0

func (t FrameDescriptionEntries) Len() int

func (FrameDescriptionEntries) Less added in v0.12.0

func (t FrameDescriptionEntries) Less(i, j int) bool

func (FrameDescriptionEntries) Swap added in v0.12.0

func (t FrameDescriptionEntries) Swap(i, j int)

type FrameDescriptionEntry

type FrameDescriptionEntry struct {
	Length       uint32
	CIE          *CommonInformationEntry
	Instructions []byte
	// contains filtered or unexported fields
}

FrameDescriptionEntry represents a Frame Descriptor Entry in the DWARF .debug_frame section.

func (*FrameDescriptionEntry) Begin

func (fde *FrameDescriptionEntry) Begin() uint64

Begin returns address of first location for this frame.

func (*FrameDescriptionEntry) Cover

func (fde *FrameDescriptionEntry) Cover(addr uint64) bool

Cover returns whether or not the given address is within the bounds of this frame.

func (*FrameDescriptionEntry) End

func (fde *FrameDescriptionEntry) End() uint64

End returns address of last location for this frame.

func (*FrameDescriptionEntry) Translate

func (fde *FrameDescriptionEntry) Translate(delta uint64)

Translate moves the beginning of fde forward by delta.

type InstructionContext

type InstructionContext struct {
	CFA  DWRule
	Regs UnwindRegisters

	RetAddrReg uint64
	// contains filtered or unexported fields
}

InstructionContext represents each object code instruction that we have unwind information for.

func (*InstructionContext) Loc

func (instructionContext *InstructionContext) Loc() uint64

type InstructionContextIterator added in v0.11.0

type InstructionContextIterator struct {
	// contains filtered or unexported fields
}

func ExecuteDWARFProgram added in v0.28.0

func ExecuteDWARFProgram(fde *FrameDescriptionEntry, context *Context) (*InstructionContextIterator, error)

ExecuteDWARFProgram evaluates the unwind opcodes for a function.

func (*InstructionContextIterator) HasNext added in v0.11.0

func (ici *InstructionContextIterator) HasNext() bool

func (*InstructionContextIterator) Next added in v0.11.0

type RowState

type RowState struct {
	// contains filtered or unexported fields
}

RowState is a stack where `DW_CFA_remember_state` pushes its CFA and registers state and `DW_CFA_restore_state` pops them.

type Rule

type Rule byte

Rule rule defined for register values.

const (
	RuleUnknown Rule = iota
	RuleUndefined
	RuleSameVal
	RuleOffset
	RuleValOffset
	RuleRegister
	RuleExpression
	RuleValExpression
	RuleCFA // Value is rule.Reg + rule.Offset
)

type StateStack

type StateStack struct {
	// contains filtered or unexported fields
}

type UnwindRegisters added in v0.11.0

type UnwindRegisters struct {
	StackPointer DWRule
	FramePointer DWRule
	SavedReturn  DWRule // save LinkRegister in here TODO(sylfrena)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL