mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 18:57:18 +08:00 
			
		
		
		
	Refactor: Remove addrrange type
This commit is contained in:
		| @ -19,12 +19,8 @@ type CommonInformationEntry struct { | ||||
| 	InitialInstructions   []byte | ||||
| } | ||||
|  | ||||
| type addrange struct { | ||||
| 	begin, end uint64 | ||||
| } | ||||
|  | ||||
| func (fde *FrameDescriptionEntry) Cover(addr uint64) bool { | ||||
| 	if (addr - fde.AddressRange.begin) < fde.AddressRange.end { | ||||
| 	if (addr - fde.begin) < fde.end { | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| @ -36,8 +32,16 @@ func (fde *FrameDescriptionEntry) Cover(addr uint64) bool { | ||||
| type FrameDescriptionEntry struct { | ||||
| 	Length       uint32 | ||||
| 	CIE          *CommonInformationEntry | ||||
| 	AddressRange *addrange | ||||
| 	Instructions []byte | ||||
| 	begin, end   uint64 | ||||
| } | ||||
|  | ||||
| func (fde *FrameDescriptionEntry) Begin() uint64 { | ||||
| 	return fde.begin | ||||
| } | ||||
|  | ||||
| func (fde *FrameDescriptionEntry) End() uint64 { | ||||
| 	return fde.begin + fde.end | ||||
| } | ||||
|  | ||||
| func (fde *FrameDescriptionEntry) EstablishFrame(pc uint64) *FrameContext { | ||||
| @ -68,22 +72,21 @@ func (fdes *FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry | ||||
| } | ||||
|  | ||||
| func (frame *FrameDescriptionEntry) Less(item rbtree.Item) bool { | ||||
| 	return frame.AddressRange.begin < item.(*FrameDescriptionEntry).AddressRange.begin | ||||
| 	return frame.Begin() < item.(*FrameDescriptionEntry).Begin() | ||||
| } | ||||
|  | ||||
| func (frame *FrameDescriptionEntry) More(item rbtree.Item) bool { | ||||
| 	r := item.(*FrameDescriptionEntry).AddressRange | ||||
| 	fnr := frame.AddressRange | ||||
| 	return fnr.begin+fnr.end > r.begin+r.end | ||||
| 	f := item.(*FrameDescriptionEntry) | ||||
| 	return frame.End() > f.End() | ||||
| } | ||||
|  | ||||
| type Addr uint64 | ||||
|  | ||||
| func (a Addr) Less(item rbtree.Item) bool { | ||||
| 	return uint64(a) < item.(*FrameDescriptionEntry).AddressRange.begin | ||||
| 	return uint64(a) < item.(*FrameDescriptionEntry).Begin() | ||||
| } | ||||
|  | ||||
| func (a Addr) More(item rbtree.Item) bool { | ||||
| 	r := item.(*FrameDescriptionEntry).AddressRange | ||||
| 	return uint64(a) > r.begin+r.end | ||||
| 	f := item.(*FrameDescriptionEntry) | ||||
| 	return uint64(a) > f.End() | ||||
| } | ||||
|  | ||||
| @ -7,10 +7,10 @@ import ( | ||||
| ) | ||||
|  | ||||
| func TestFDEForPC(t *testing.T) { | ||||
| 	fde1 := &FrameDescriptionEntry{AddressRange: &addrange{begin: 100, end: 200}} | ||||
| 	fde2 := &FrameDescriptionEntry{AddressRange: &addrange{begin: 50, end: 99}} | ||||
| 	fde3 := &FrameDescriptionEntry{AddressRange: &addrange{begin: 0, end: 49}} | ||||
| 	fde4 := &FrameDescriptionEntry{AddressRange: &addrange{begin: 201, end: 245}} | ||||
| 	fde1 := &FrameDescriptionEntry{begin: 100, end: 200} | ||||
| 	fde2 := &FrameDescriptionEntry{begin: 50, end: 99} | ||||
| 	fde3 := &FrameDescriptionEntry{begin: 0, end: 49} | ||||
| 	fde4 := &FrameDescriptionEntry{begin: 201, end: 245} | ||||
|  | ||||
| 	tree := NewFrameIndex() | ||||
| 	tree.Put(fde1) | ||||
|  | ||||
| @ -50,15 +50,15 @@ func parseLength(ctx *parseContext) parsefunc { | ||||
| 		return parseCIE | ||||
| 	} | ||||
|  | ||||
| 	ctx.Frame = &FrameDescriptionEntry{Length: ctx.Length, CIE: ctx.Common, AddressRange: new(addrange)} | ||||
| 	ctx.Frame = &FrameDescriptionEntry{Length: ctx.Length, CIE: ctx.Common} | ||||
| 	return parseFDE | ||||
| } | ||||
|  | ||||
| func parseFDE(ctx *parseContext) parsefunc { | ||||
| 	r := ctx.Buf.Next(int(ctx.Length)) | ||||
|  | ||||
| 	ctx.Frame.AddressRange.begin = binary.LittleEndian.Uint64(r[:8]) | ||||
| 	ctx.Frame.AddressRange.end = binary.LittleEndian.Uint64(r[8:16]) | ||||
| 	ctx.Frame.begin = binary.LittleEndian.Uint64(r[:8]) | ||||
| 	ctx.Frame.end = binary.LittleEndian.Uint64(r[8:16]) | ||||
|  | ||||
| 	// Insert into the tree after setting address range begin | ||||
| 	// otherwise compares won't work. | ||||
|  | ||||
| @ -136,7 +136,7 @@ func executeCIEInstructions(cie *CommonInformationEntry) *FrameContext { | ||||
| // Unwind the stack to find the return address register. | ||||
| func executeDwarfProgramUntilPC(fde *FrameDescriptionEntry, pc uint64) *FrameContext { | ||||
| 	frame := executeCIEInstructions(fde.CIE) | ||||
| 	frame.loc = fde.AddressRange.begin | ||||
| 	frame.loc = fde.Begin() | ||||
| 	frame.address = pc | ||||
| 	frame.ExecuteUntilPC(fde.Instructions) | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Derek Parker
					Derek Parker