2014-06-25 19:14:29 +00:00
|
|
|
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
|
|
|
|
}
|
2014-06-25 19:14:29 +00:00
|
|
|
|
|
|
|
// Represents a Frame Descriptor Entry in the
|
|
|
|
// Dwarf .debug_frame section.
|
|
|
|
type FrameDescriptionEntry struct {
|
|
|
|
Length uint32
|
|
|
|
CIE *CommonInformationEntry
|
|
|
|
AddressRange *addrange
|
|
|
|
Instructions []byte
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:52:21 +00:00
|
|
|
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 {
|
2014-06-29 16:52:21 +00:00
|
|
|
frame := fde.EstablishFrame(pc)
|
2014-07-10 23:07:39 +00:00
|
|
|
|
|
|
|
return frame.cfa.offset + frame.regs[16].offset
|
2014-06-25 19:14:29 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:52:30 +00:00
|
|
|
type FrameDescriptionEntries []*FrameDescriptionEntry
|
2014-06-25 19:14:29 +00:00
|
|
|
|
2014-06-29 16:52:30 +00:00
|
|
|
func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry, error) {
|
2014-06-25 19:14:29 +00:00
|
|
|
for _, fde := range fdes {
|
|
|
|
if fde.AddressRange.Cover(pc) {
|
2014-06-29 16:52:30 +00:00
|
|
|
return fde, nil
|
2014-06-25 19:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:52:30 +00:00
|
|
|
return nil, fmt.Errorf("Could not find FDE for %#v", pc)
|
2014-06-25 19:14:29 +00:00
|
|
|
}
|