Commit eda22a06 authored by David Chase's avatar David Chase

cmd/compile: ensure first instruction of function is stmt

In gdb, "b f" gets confused if the first instruction of "f"
is not marked as a statement in the DWARF line table.

To ensure gdb is not confused, move the first statement
marker in "f" to its first instruction.

The screwy-looking conditional for "what's the first
instruction with a statement marker" will become simpler in
the future.

Fixes #24695.

Change-Id: I2eef81676b64d1bd9bff5da03b89b9dc0c18f44f
Reviewed-on: https://go-review.googlesource.com/104955
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarCherry Zhang <cherryyz@google.com>
parent 33eaf75a
......@@ -4666,6 +4666,16 @@ func genssa(f *ssa.Func, pp *Progs) {
}
}
// If the very first instruction is not tagged as a statement,
// debuggers may attribute it to previous function in program.
firstPos := src.NoXPos
for _, v := range f.Entry.Values {
if v.Op != ssa.OpArg && v.Op != ssa.OpVarDef && v.Pos.IsStmt() != src.PosNotStmt { // TODO will be == src.PosIsStmt in pending CL, more accurate
firstPos = v.Pos.WithIsStmt()
break
}
}
// Emit basic blocks
for i, b := range f.Blocks {
s.bstart[b.ID] = s.pp.next
......@@ -4709,6 +4719,11 @@ func genssa(f *ssa.Func, pp *Progs) {
CheckLoweredPhi(v)
default:
// let the backend handle it
// Special case for first line in function; move it to the start.
if firstPos != src.NoXPos {
s.SetPos(firstPos)
firstPos = src.NoXPos
}
thearch.SSAGenValue(&s, v)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment