]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: ensure first instruction of function is stmt
authorDavid Chase <drchase@google.com>
Thu, 5 Apr 2018 15:11:39 +0000 (11:11 -0400)
committerDavid Chase <drchase@google.com>
Fri, 6 Apr 2018 16:05:42 +0000 (16:05 +0000)
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: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/ssa.go

index fcb6223528e88cdfb8c13773a5d2a51458facf59..c6a6c275bb3eee5c40ef28d0822dcf040ca31ecf 100644 (file)
@@ -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)
                        }