Skip to content

Commit 84f474f

Browse files
committed
debug/dwarf: Fail on reading incorrect offset due to skipped compilation unit
1 parent 44d4b69 commit 84f474f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/debug/dwarf/entry.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry
541541
} else if a.tag == TagCompileUnit {
542542
delay = append(delay, delayed{i, off, formAddrx})
543543
break
544+
} else {
545+
b.error("Can't adjust offset: compilation unit skipped")
544546
}
545547

546548
var err error
@@ -692,6 +694,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry
692694
} else if a.tag == TagCompileUnit {
693695
delay = append(delay, delayed{i, off, formStrx})
694696
break
697+
} else {
698+
b.error("Can't adjust offset: compilation unit skipped")
695699
}
696700

697701
val = resolveStrx(uint64(strBase), off)
@@ -752,6 +756,8 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry
752756
} else if a.tag == TagCompileUnit {
753757
delay = append(delay, delayed{i, off, formRnglistx})
754758
break
759+
} else {
760+
b.error("Can't adjust offset: compilation unit skipped")
755761
}
756762

757763
val = resolveRnglistx(uint64(rnglistsBase), off)
@@ -828,7 +834,7 @@ func (r *Reader) ByteOrder() binary.ByteOrder {
828834

829835
// Seek positions the [Reader] at offset off in the encoded entry stream.
830836
// Offset 0 can be used to denote the first entry.
831-
func (r *Reader) Seek(off Offset) {
837+
func (r *Reader) seekImpl(off Offset) {
832838
d := r.d
833839
r.err = nil
834840
r.lastChildren = false
@@ -856,6 +862,15 @@ func (r *Reader) Seek(off Offset) {
856862
r.b = makeBuf(r.d, u, "info", off, u.data[off-u.off:])
857863
}
858864

865+
// Seek positions the [Reader] at offset off in the encoded entry stream, and additionally sets the current
866+
// CU for the reader.
867+
func (r *Reader) Seek(off Offset) {
868+
cuIdx := r.d.offsetToUnit(off)
869+
r.seekImpl(r.d.unit[cuIdx].off)
870+
r.Next()
871+
r.seekImpl(off)
872+
}
873+
859874
// maybeNextUnit advances to the next unit if this one is finished.
860875
func (r *Reader) maybeNextUnit() {
861876
for len(r.b.data) == 0 && r.unit+1 < len(r.d.unit) {

0 commit comments

Comments
 (0)