Skip to content

Commit 759115b

Browse files
authored
dwarf/godwarf: fix regression debugging DWARFv5 on macOS (go-delve#4315)
The change introduced to fix go-delve#4302 happens to conflict with a similar workaround in debug/macho I forgot exists. The telemetry report was probably from a binary that legitimately did not have a debug_line_str section (but referenced it) and we just misidentified the cause, the fix however is still worth keeping since there are versions of Go without the workaround that could be affected. Fixes go-delve#4311
1 parent 29aa227 commit 759115b

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/dwarf/godwarf/sections.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func GetDebugSectionMacho(f *macho.File, name string) ([]byte, error) {
9292
// Because of what the valid names of DWARFv5 sections are (appendix B)
9393
// there are no risks of collision.
9494
func getDebugSectionMachoHelper(f *macho.File, name string) *macho.Section {
95+
sec := f.Section(name)
96+
if sec != nil {
97+
return sec
98+
}
9599
if len(name) > 16 {
96100
name = name[:16]
97101
}

pkg/dwarf/line/line_parser.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,12 @@ func parseFileEntries5(info *DebugLineInfo, buf *bytes.Buffer) bool {
312312
case _DW_FORM_string:
313313
p = fileEntryFormReader.str
314314
case _DW_FORM_line_strp:
315-
buf := bytes.NewBuffer(info.debugLineStr[fileEntryFormReader.u64:])
316-
p, _ = dwarf.ReadString(buf)
315+
if info.debugLineStr == nil {
316+
p = "<DW_FORM_line_strp without debug_line_str section>"
317+
} else {
318+
buf := bytes.NewBuffer(info.debugLineStr[fileEntryFormReader.u64:])
319+
p, _ = dwarf.ReadString(buf)
320+
}
317321
default:
318322
info.Logf("unsupported string form %#x", fileEntryFormReader.formCode)
319323
}

0 commit comments

Comments
 (0)