From: Alessandro Arzilli Date: Mon, 15 Nov 2021 09:14:04 +0000 (+0100) Subject: [release-branch.go1.17] debug/pe,debug/macho: add support for DWARF5 sections X-Git-Tag: go1.17.7~9 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1b867ce3efa427d8b4bb07f51b0f8a262f3a1227;p=gostls13.git [release-branch.go1.17] debug/pe,debug/macho: add support for DWARF5 sections Adds the same logic used in debug/elf to load DWARF5 sections. For #49590 Fixes #50722 Change-Id: Iee05b9927a6f521842b330eab8942ade3fc2bd86 Reviewed-on: https://go-review.googlesource.com/c/go/+/363895 Reviewed-by: Ian Lance Taylor Trust: Than McIntosh (cherry picked from commit 6c36c332fefdd433cfe6e6468a2542fc310e9f8a) Reviewed-on: https://go-review.googlesource.com/c/go/+/379914 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Alessandro Arzilli Reviewed-by: Emmanuel Odeke --- diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go index 73cfce3c76..cdc500e476 100644 --- a/src/debug/macho/file.go +++ b/src/debug/macho/file.go @@ -650,10 +650,14 @@ func (f *File) DWARF() (*dwarf.Data, error) { return nil, err } - // Look for DWARF4 .debug_types sections. + // Look for DWARF4 .debug_types sections and DWARF5 sections. for i, s := range f.Sections { suffix := dwarfSuffix(s) - if suffix != "types" { + if suffix == "" { + continue + } + if _, ok := dat[suffix]; ok { + // Already handled. continue } @@ -662,7 +666,11 @@ func (f *File) DWARF() (*dwarf.Data, error) { return nil, err } - err = d.AddTypes(fmt.Sprintf("types-%d", i), b) + if suffix == "types" { + err = d.AddTypes(fmt.Sprintf("types-%d", i), b) + } else { + err = d.AddSection(".debug_"+suffix, b) + } if err != nil { return nil, err } diff --git a/src/debug/pe/file.go b/src/debug/pe/file.go index e50229e5a3..ab00a48f5c 100644 --- a/src/debug/pe/file.go +++ b/src/debug/pe/file.go @@ -272,10 +272,14 @@ func (f *File) DWARF() (*dwarf.Data, error) { return nil, err } - // Look for DWARF4 .debug_types sections. + // Look for DWARF4 .debug_types sections and DWARF5 sections. for i, s := range f.Sections { suffix := dwarfSuffix(s) - if suffix != "types" { + if suffix == "" { + continue + } + if _, ok := dat[suffix]; ok { + // Already handled. continue } @@ -284,7 +288,11 @@ func (f *File) DWARF() (*dwarf.Data, error) { return nil, err } - err = d.AddTypes(fmt.Sprintf("types-%d", i), b) + if suffix == "types" { + err = d.AddTypes(fmt.Sprintf("types-%d", i), b) + } else { + err = d.AddSection(".debug_"+suffix, b) + } if err != nil { return nil, err }