Skip to content

Commit

Permalink
debug/dwarf: Fail on reading incorrect offset due to skipped compilat…
Browse files Browse the repository at this point in the history
…ion unit
  • Loading branch information
danipozo committed Dec 29, 2024
1 parent 44d4b69 commit 84f474f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/debug/dwarf/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -828,7 +834,7 @@ func (r *Reader) ByteOrder() binary.ByteOrder {

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

// Seek positions the [Reader] at offset off in the encoded entry stream, and additionally sets the current
// CU for the reader.
func (r *Reader) Seek(off Offset) {
cuIdx := r.d.offsetToUnit(off)
r.seekImpl(r.d.unit[cuIdx].off)
r.Next()
r.seekImpl(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) {
Expand Down

0 comments on commit 84f474f

Please sign in to comment.