mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
Fix stack frame calculation bug
There were certain instances where the calculation of the stack frame was incorrect, causing for garbage to be returned by a print command.
This commit is contained in:
@ -50,7 +50,6 @@ func (fde *FrameDescriptionEntry) EstablishFrame(pc uint64) *FrameContext {
|
|||||||
|
|
||||||
func (fde *FrameDescriptionEntry) ReturnAddressOffset(pc uint64) int64 {
|
func (fde *FrameDescriptionEntry) ReturnAddressOffset(pc uint64) int64 {
|
||||||
frame := fde.EstablishFrame(pc)
|
frame := fde.EstablishFrame(pc)
|
||||||
|
|
||||||
return frame.cfa.offset + frame.regs[fde.CIE.ReturnAddressRegister].offset
|
return frame.cfa.offset + frame.regs[fde.CIE.ReturnAddressRegister].offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -157,15 +157,9 @@ func (frame *FrameContext) ExecuteUntilPC(instructions []byte) {
|
|||||||
// We only need to execute the instructions until
|
// We only need to execute the instructions until
|
||||||
// ctx.loc > ctx.addess (which is the address we
|
// ctx.loc > ctx.addess (which is the address we
|
||||||
// are currently at in the traced process).
|
// are currently at in the traced process).
|
||||||
for frame.address != frame.loc && frame.buf.Len() > 0 {
|
for frame.address > frame.loc && frame.buf.Len() > 0 {
|
||||||
executeDwarfInstruction(frame)
|
executeDwarfInstruction(frame)
|
||||||
}
|
}
|
||||||
// make sure we get the update cfa offset
|
|
||||||
cfa := frame.CFAOffset()
|
|
||||||
for ncfa := cfa; ncfa == cfa && frame.buf.Len() > 0; {
|
|
||||||
executeDwarfInstruction(frame)
|
|
||||||
ncfa = frame.CFAOffset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeDwarfInstruction(frame *FrameContext) {
|
func executeDwarfInstruction(frame *FrameContext) {
|
||||||
|
|||||||
@ -511,9 +511,8 @@ func (thread *ThreadContext) executeStackProgram(instructions []byte) (int64, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
fctx := fde.EstablishFrame(regs.PC())
|
fctx := fde.EstablishFrame(regs.PC())
|
||||||
cfaOffset := fctx.CFAOffset() + int64(regs.SP())
|
cfa := fctx.CFAOffset() + int64(regs.SP())
|
||||||
|
address, err := op.ExecuteStackProgram(cfa, instructions)
|
||||||
address, err := op.ExecuteStackProgram(cfaOffset, instructions)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -625,13 +624,13 @@ func (thread *ThreadContext) extractValue(instructions []byte, addr int64, typ i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (thread *ThreadContext) readString(addr uintptr, size int64) (string, error) {
|
func (thread *ThreadContext) readString(addr uintptr, size int64) (string, error) {
|
||||||
|
// deref the pointer to the string
|
||||||
val, err := thread.readMemory(addr, uintptr(size))
|
val, err := thread.readMemory(addr, uintptr(size))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// deref the pointer to the string
|
|
||||||
addr = uintptr(binary.LittleEndian.Uint64(val))
|
addr = uintptr(binary.LittleEndian.Uint64(val))
|
||||||
|
|
||||||
val, err = thread.readMemory(addr, 16)
|
val, err = thread.readMemory(addr, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user