From 9c58cf36c81fc419c838a73cbbf88e2f44b5618d Mon Sep 17 00:00:00 2001 From: Dani Pozo Date: Sun, 17 Nov 2024 19:28:18 +0100 Subject: [PATCH] debug/dwarf: Fail on reading incorrect offset due to skipped compilation unit --- src/debug/dwarf/entry.go | 15 +++++++++++++++ src/go.mod | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/debug/dwarf/entry.go b/src/debug/dwarf/entry.go index 4541d74d4db408..23c5ca41a33ac4 100644 --- a/src/debug/dwarf/entry.go +++ b/src/debug/dwarf/entry.go @@ -541,6 +541,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry } else if a.tag == TagCompileUnit { delay = append(delay, delayed{i, off, formAddrx}) break + } else { + b.error("Can't adjust offset: compilation unit skipped") } var err error @@ -692,6 +694,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry } else if a.tag == TagCompileUnit { delay = append(delay, delayed{i, off, formStrx}) break + } else { + b.error("Can't adjust offset: compilation unit skipped") } val = resolveStrx(uint64(strBase), off) @@ -752,6 +756,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry } else if a.tag == TagCompileUnit { delay = append(delay, delayed{i, off, formRnglistx}) break + } else { + b.error("Can't adjust offset: compilation unit skipped") } val = resolveRnglistx(uint64(rnglistsBase), off) @@ -856,6 +862,15 @@ func (r *Reader) Seek(off Offset) { r.b = makeBuf(r.d, u, "info", off, u.data[off-u.off:]) } +// SeekAndSetCU positions the [Reader] at offset off in the encoded entry stream, and additionally sets the current +// CU for the reader. +func (r *Reader) SeekAndSetCU(off Offset) { + cuIdx := r.d.offsetToUnit(off) + r.Seek(r.d.unit[cuIdx].off) + r.Next() + r.Seek(off) +} + // maybeNextUnit advances to the next unit if this one is finished. func (r *Reader) maybeNextUnit() { for len(r.b.data) == 0 && r.unit+1 < len(r.d.unit) { diff --git a/src/go.mod b/src/go.mod index 7a7b99150fc297..1d11593946bdbc 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,6 +1,6 @@ module std -go 1.24 +go 1.22 require ( golang.org/x/crypto v0.25.1-0.20240722173533-bb80217080b0