mirror of
https://github.com/go-delve/delve.git
synced 2025-10-27 20:23:41 +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 {
|
||||
frame := fde.EstablishFrame(pc)
|
||||
|
||||
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
|
||||
// ctx.loc > ctx.addess (which is the address we
|
||||
// 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)
|
||||
}
|
||||
// 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) {
|
||||
|
||||
@ -511,9 +511,8 @@ func (thread *ThreadContext) executeStackProgram(instructions []byte) (int64, er
|
||||
}
|
||||
|
||||
fctx := fde.EstablishFrame(regs.PC())
|
||||
cfaOffset := fctx.CFAOffset() + int64(regs.SP())
|
||||
|
||||
address, err := op.ExecuteStackProgram(cfaOffset, instructions)
|
||||
cfa := fctx.CFAOffset() + int64(regs.SP())
|
||||
address, err := op.ExecuteStackProgram(cfa, instructions)
|
||||
if err != nil {
|
||||
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) {
|
||||
// deref the pointer to the string
|
||||
val, err := thread.readMemory(addr, uintptr(size))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// deref the pointer to the string
|
||||
addr = uintptr(binary.LittleEndian.Uint64(val))
|
||||
|
||||
val, err = thread.readMemory(addr, 16)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user