cmd/cgo: run recordTypes for each of the debugs at the end of Translate

Save the debug information in a slice and then process all of them at
the end of the loop.

For #75167

Change-Id: I6a6a6964dffa784b0aa776334562333ecf247023
Reviewed-on: https://go-review.googlesource.com/c/go/+/699019
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Auto-Submit: Michael Matloob <matloob@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
matloob 2025-08-25 17:16:05 -04:00 committed by Gopher Robot
parent 5e6296f3f8
commit cf42b785b7

View file

@ -192,9 +192,7 @@ func (p *Package) Translate(f *File) {
cref.Name.C = cname(cref.Name.Go) cref.Name.C = cname(cref.Name.Go)
} }
var conv typeConv var debugs []*debug // debug data from iterations of gccDebug
conv.Init(p.PtrSize, p.IntSize)
ft := fileTypedefs{typedefs: make(map[string]bool)} ft := fileTypedefs{typedefs: make(map[string]bool)}
numTypedefs := -1 numTypedefs := -1
for len(ft.typedefs) > numTypedefs { for len(ft.typedefs) > numTypedefs {
@ -213,8 +211,7 @@ func (p *Package) Translate(f *File) {
} }
needType := p.guessKinds(f) needType := p.guessKinds(f)
if len(needType) > 0 { if len(needType) > 0 {
d := p.loadDWARF(f, &ft, needType) debugs = append(debugs, p.loadDWARF(f, &ft, needType))
p.recordTypes(f, d, &conv)
} }
// In godefs mode we're OK with the typedefs, which // In godefs mode we're OK with the typedefs, which
@ -224,6 +221,12 @@ func (p *Package) Translate(f *File) {
break break
} }
} }
var conv typeConv
conv.Init(p.PtrSize, p.IntSize)
for _, d := range debugs {
p.recordTypes(f, d, &conv)
}
p.prepareNames(f) p.prepareNames(f)
if p.rewriteCalls(f) { if p.rewriteCalls(f) {
// Add `import _cgo_unsafe "unsafe"` after the package statement. // Add `import _cgo_unsafe "unsafe"` after the package statement.