提交 368cbeb0 编写于 作者: A aarzilli 提交者: Derek Parker

dwarf/line: remove foundFile "optimization" from LineToPC

There is no guarantee that files will end up stored contiguously in the
debug_line section which makes this optimization wrong in the general
case.
In particular with recent versions of go1.11 and a go.mod file present
the go compiler seems to sometimes produce executables that actually
violate this assumption.
上级 86120a3b
...@@ -264,10 +264,7 @@ func (lineInfo *DebugLineInfo) LineToPC(filename string, lineno int) uint64 { ...@@ -264,10 +264,7 @@ func (lineInfo *DebugLineInfo) LineToPC(filename string, lineno int) uint64 {
return 0 return 0
} }
var ( sm := newStateMachine(lineInfo, lineInfo.Instructions)
foundFile bool
sm = newStateMachine(lineInfo, lineInfo.Instructions)
)
// if no instruction marked is_stmt is found fallback to the first // if no instruction marked is_stmt is found fallback to the first
// instruction assigned to the filename:line. // instruction assigned to the filename:line.
...@@ -280,17 +277,11 @@ func (lineInfo *DebugLineInfo) LineToPC(filename string, lineno int) uint64 { ...@@ -280,17 +277,11 @@ func (lineInfo *DebugLineInfo) LineToPC(filename string, lineno int) uint64 {
} }
break break
} }
if foundFile && sm.file != filename { if sm.line == lineno && sm.file == filename && sm.valid {
break if sm.isStmt {
} return sm.address
if sm.line == lineno && sm.file == filename { } else if fallbackPC == 0 {
foundFile = true fallbackPC = sm.address
if sm.valid {
if sm.isStmt {
return sm.address
} else if fallbackPC == 0 {
fallbackPC = sm.address
}
} }
} }
} }
......
...@@ -640,7 +640,7 @@ func FirstPCAfterPrologue(p Process, fn *Function, sameline bool) (uint64, error ...@@ -640,7 +640,7 @@ func FirstPCAfterPrologue(p Process, fn *Function, sameline bool) (uint64, error
// breakpoint with file:line and with the function name always result on // breakpoint with file:line and with the function name always result on
// the same instruction being selected. // the same instruction being selected.
entryFile, entryLine := fn.cu.lineInfo.PCToLine(fn.Entry, fn.Entry) entryFile, entryLine := fn.cu.lineInfo.PCToLine(fn.Entry, fn.Entry)
if pc, _, err := p.BinInfo().LineToPC(entryFile, entryLine); err == nil { if pc, _, err := p.BinInfo().LineToPC(entryFile, entryLine); err == nil && pc >= fn.Entry && pc < fn.End {
return pc, nil return pc, nil
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册