delve/dwarf/frame/frame_entries.go

60 lines
1.3 KiB
Go
Raw Normal View History

package frame
import "fmt"
// Represents a Common Information Entry in
// the Dwarf .debug_frame section.
type CommonInformationEntry struct {
Length uint32
CIE_id uint32
Version uint8
Augmentation string
CodeAlignmentFactor uint64
DataAlignmentFactor int64
ReturnAddressRegister byte
InitialInstructions []byte
}
2014-06-29 16:52:30 +00:00
type addrange struct {
begin, end uint64
}
func (r *addrange) Cover(addr uint64) bool {
if (addr - r.begin) < r.end {
return true
}
return false
}
// Represents a Frame Descriptor Entry in the
// Dwarf .debug_frame section.
type FrameDescriptionEntry struct {
Length uint32
CIE *CommonInformationEntry
AddressRange *addrange
Instructions []byte
}
func (fde *FrameDescriptionEntry) EstablishFrame(pc uint64) *FrameContext {
return executeDwarfProgramUntilPC(fde, pc)
}
2014-06-29 16:52:30 +00:00
func (fde *FrameDescriptionEntry) ReturnAddressOffset(pc uint64) int64 {
frame := fde.EstablishFrame(pc)
return frame.cfa.offset + frame.regs[16].offset
}
2014-06-29 16:52:30 +00:00
type FrameDescriptionEntries []*FrameDescriptionEntry
2014-06-29 16:52:30 +00:00
func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry, error) {
for _, fde := range fdes {
if fde.AddressRange.Cover(pc) {
2014-06-29 16:52:30 +00:00
return fde, nil
}
}
2014-06-29 16:52:30 +00:00
return nil, fmt.Errorf("Could not find FDE for %#v", pc)
}