Skip to content

Commit

Permalink
debug/pe,debug/macho: add support for DWARF5 sections
Browse files Browse the repository at this point in the history
Adds the same logic used in debug/elf to load DWARF5 sections.

Fixes #49590

Change-Id: Iee05b9927a6f521842b330eab8942ade3fc2bd86
Reviewed-on: https://go-review.googlesource.com/c/go/+/363895
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
  • Loading branch information
aarzilli authored and thanm committed Nov 16, 2021
1 parent 40effca commit 6c36c33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/debug/macho/file.go
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
14 changes: 11 additions & 3 deletions src/debug/pe/file.go
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down

0 comments on commit 6c36c33

Please sign in to comment.