aboutsummaryrefslogtreecommitdiff
path: root/src/debug/dwarf/typeunit.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2015-03-05 15:07:00 -0500
committerAustin Clements <austin@google.com>2015-03-11 21:35:21 +0000
commit9dfbcd8facae22e2be8bc527e1877b1e23812073 (patch)
treee5c8d2c9bf218828bd1a55db0360d1b6d0845cba /src/debug/dwarf/typeunit.go
parentd533e3955db945072ab2dfcca1cab57099569260 (diff)
downloadgo-9dfbcd8facae22e2be8bc527e1877b1e23812073.tar.xz
debug/dwarf: factor parsing of unit lengths
Many headers in DWARF sections have a "unit length" that can be either 4 bytes or 12 bytes and indicates both the length of the unit and whether the unit is in 32-bit or 64-bit format. Currently, we implement unit length parsing in four different places. Add a "unitLength" method to buf that parses a unit length and use it in these four places. Change-Id: I7950b91caaa92aa5e19aa63debc8ae46178ecc4d Reviewed-on: https://go-review.googlesource.com/7281 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/debug/dwarf/typeunit.go')
-rw-r--r--src/debug/dwarf/typeunit.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/debug/dwarf/typeunit.go b/src/debug/dwarf/typeunit.go
index 3fd1c9973e..80971bbb90 100644
--- a/src/debug/dwarf/typeunit.go
+++ b/src/debug/dwarf/typeunit.go
@@ -27,16 +27,10 @@ func (d *Data) parseTypes(name string, types []byte) error {
b := makeBuf(d, unknownFormat{}, name, 0, types)
for len(b.data) > 0 {
base := b.off
- dwarf64 := false
- n := b.uint32()
- if n == 0xffffffff {
- n64 := b.uint64()
- if n64 != uint64(uint32(n64)) {
- b.error("type unit length overflow")
- return b.err
- }
- n = uint32(n64)
- dwarf64 = true
+ n, dwarf64 := b.unitLength()
+ if n != Offset(uint32(n)) {
+ b.error("type unit length overflow")
+ return b.err
}
hdroff := b.off
vers := b.uint16()
@@ -79,7 +73,7 @@ func (d *Data) parseTypes(name string, types []byte) error {
unit: unit{
base: base,
off: boff,
- data: b.bytes(int(Offset(n) - (b.off - hdroff))),
+ data: b.bytes(int(n - (b.off - hdroff))),
atable: atable,
asize: int(asize),
vers: int(vers),