]> Cypherpunks repositories - gostls13.git/commitdiff
debug/gosym: add pcHeader parsing helpers
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 22 Sep 2021 18:13:20 +0000 (11:13 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Sep 2021 22:19:43 +0000 (22:19 +0000)
A subsequent change will duplicate most of case ver116.
Make it easier to read.

Change-Id: I3a93181c7f094b12715b8a618e9efef7a1438a27
Reviewed-on: https://go-review.googlesource.com/c/go/+/351909
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/debug/gosym/pclntab.go

index a72f9847d7cc08f371e041d89959acd9171492f3..555add67e30d10007bbab12074723ce29e04add8 100644 (file)
@@ -225,21 +225,23 @@ func (t *LineTable) parsePclnTab() {
        t.quantum = uint32(t.Data[6])
        t.ptrsize = uint32(t.Data[7])
 
+       offset := func(word uint32) uint64 {
+               return t.uintptr(t.Data[8+word*t.ptrsize:])
+       }
+       data := func(word uint32) []byte {
+               return t.Data[offset(word):]
+       }
+
        switch possibleVersion {
        case ver116:
-               t.nfunctab = uint32(t.uintptr(t.Data[8:]))
-               t.nfiletab = uint32(t.uintptr(t.Data[8+t.ptrsize:]))
-               offset := t.uintptr(t.Data[8+2*t.ptrsize:])
-               t.funcnametab = t.Data[offset:]
-               offset = t.uintptr(t.Data[8+3*t.ptrsize:])
-               t.cutab = t.Data[offset:]
-               offset = t.uintptr(t.Data[8+4*t.ptrsize:])
-               t.filetab = t.Data[offset:]
-               offset = t.uintptr(t.Data[8+5*t.ptrsize:])
-               t.pctab = t.Data[offset:]
-               offset = t.uintptr(t.Data[8+6*t.ptrsize:])
-               t.funcdata = t.Data[offset:]
-               t.functab = t.Data[offset:]
+               t.nfunctab = uint32(offset(0))
+               t.nfiletab = uint32(offset(1))
+               t.funcnametab = data(2)
+               t.cutab = data(3)
+               t.filetab = data(4)
+               t.pctab = data(5)
+               t.funcdata = data(6)
+               t.functab = data(6)
                functabsize := t.nfunctab*2*t.ptrsize + t.ptrsize
                t.functab = t.functab[:functabsize]
        case ver12: