aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/debug.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2021-04-29 11:47:18 -0400
committerThan McIntosh <thanm@google.com>2021-04-30 19:38:25 +0000
commitd19eece91f7825556eadfef08e7011e22a719ec0 (patch)
tree96eb94726ed249cb5e40a4d4835ecc70a58b264f /src/cmd/compile/internal/ssa/debug.go
parent162d4f9c92cb618e8b434e445a842351160fb84d (diff)
downloadgo-d19eece91f7825556eadfef08e7011e22a719ec0.tar.gz
go-d19eece91f7825556eadfef08e7011e22a719ec0.zip
cmd/compile: handle field padding for register-passed structs
When constructing multi-piece DWARF location expressions for struct-typed parameters using the register ABI, make sure that the location expressions generated properly reflect padding between elements (this is required by debuggers). Example: type small struct { x uint16 ; y uint8 ; z int32 } func ABC(p1 int, p2 small, f1 float32) { ... In the DWARF location expression for "p2" on entry to the routine, we need pieces for each field, but for debuggers (such as GDB) to work properly, we also need to describe the padding between elements. Thus instead of <rbx> DW_OP_piece 2 <rcx> DW_OP_piece 1 <rdi> DW_OP_piece 4 we need to emit <rbx> DW_OP_piece 2 <rcx> DW_OP_piece 1 DW_OP_piece 1 <rdi> DW_OP_piece 4 This patch adds a new helper routine in abiutils to compute the correct padding amounts for a struct type, a unit test for the helper, and updates the debug generation code to call the helper and insert apadding "piece" ops in the right spots. Updates #40724. Updates #45720. Change-Id: Ie208bee25776b9eb70642041869e65e4fa65a005 Reviewed-on: https://go-review.googlesource.com/c/go/+/315071 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/debug.go')
-rw-r--r--src/cmd/compile/internal/ssa/debug.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go
index 4401f56703..ee522f41ef 100644
--- a/src/cmd/compile/internal/ssa/debug.go
+++ b/src/cmd/compile/internal/ssa/debug.go
@@ -1391,6 +1391,8 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
continue
}
rtypes, _ := inp.RegisterTypesAndOffsets()
+ padding := make([]uint64, 0, 32)
+ padding = inp.ComputePadding(padding)
for k, r := range inp.Registers {
reg := ObjRegForAbiReg(r, f.Config)
dwreg := ctxt.Arch.DWARFRegisters[reg]
@@ -1404,6 +1406,10 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
list = append(list, dwarf.DW_OP_piece)
ts := rtypes[k].Width
list = dwarf.AppendUleb128(list, uint64(ts))
+ if padding[k] > 0 {
+ list = append(list, dwarf.DW_OP_piece)
+ list = dwarf.AppendUleb128(list, padding[k])
+ }
}
}
// fill in length of location expression element