From eda22a06fb507d3ce6a2684bb5e6dbb3cbb57e15 Mon Sep 17 00:00:00 2001 From: David Chase Date: Thu, 5 Apr 2018 11:11:39 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/ssa.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index fcb6223528..c6a6c275bb 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -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) }