Skip to content

Commit

Permalink
proc: simplify logic of (*stackIterator).newStackframe (go-delve#1513)
Browse files Browse the repository at this point in the history
The lookup at it.pc-1 is only ever done if fn is not nil and pc !=
fn.entry. Also when it happens only the File and Line fields are
allowed to change.
  • Loading branch information
aarzilli authored and derekparker committed Mar 18, 2019
1 parent 2a02e46 commit 903ec65
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions pkg/proc/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,36 +375,21 @@ func (it *stackIterator) newStackframe(ret, retaddr uint64) Stackframe {
it.regs.FrameBase = it.frameBase(fn)
}
r := Stackframe{Current: Location{PC: it.pc, File: f, Line: l, Fn: fn}, Regs: it.regs, Ret: ret, addrret: retaddr, stackHi: it.stackhi, SystemStack: it.systemstack, lastpc: it.pc}
if !it.top {
fnname := ""
if r.Current.Fn != nil {
fnname = r.Current.Fn.Name
}
switch fnname {
r.Call = r.Current
if !it.top && r.Current.Fn != nil && it.pc != r.Current.Fn.Entry {
// if the return address is the entry point of the function that
// contains it then this is some kind of fake return frame (for example
// runtime.sigreturn) that didn't actually call the current frame,
// attempting to get the location of the CALL instruction would just
// obfuscate what's going on, since there is no CALL instruction.
switch r.Current.Fn.Name {
case "runtime.mstart", "runtime.systemstack_switch":
// these frames are inserted by runtime.systemstack and there is no CALL
// instruction to look for at pc - 1
r.Call = r.Current
default:
if r.Current.Fn != nil && it.pc == r.Current.Fn.Entry {
// if the return address is the entry point of the function that
// contains it then this is some kind of fake return frame (for example
// runtime.sigreturn) that didn't actually call the current frame,
// attempting to get the location of the CALL instruction would just
// obfuscate what's going on, since there is no CALL instruction.
r.Call = r.Current
} else {
r.lastpc = it.pc - 1
r.Call.File, r.Call.Line, r.Call.Fn = it.bi.PCToLine(it.pc - 1)
if r.Call.Fn == nil {
r.Call.File = "?"
r.Call.Line = -1
}
r.Call.PC = r.Current.PC
}
r.lastpc = it.pc - 1
r.Call.File, r.Call.Line = r.Current.Fn.cu.lineInfo.PCToLine(r.Current.Fn.Entry, it.pc-1)
}
} else {
r.Call = r.Current
}
return r
}
Expand Down

0 comments on commit 903ec65

Please sign in to comment.