Skip to content

Commit

Permalink
gocore: the name of a type changed to varint in Go 1.17.
Browse files Browse the repository at this point in the history
refer: golang/go@2870259

Change-Id: I019e881db37a83a3ddcebb75143fbcb4414e8d6b
GitHub-Last-Rev: ea77671
GitHub-Pull-Request: #10
Reviewed-on: https://go-review.googlesource.com/c/debug/+/419016
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
  • Loading branch information
doujiang24 authored and hyangah committed Aug 1, 2022
1 parent dd944dc commit 2c5b507
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions internal/gocore/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func (p *Process) DynamicType(t *Type, a core.Address) *Type {
}
}

// return the number of bytes of the variable int and its value,
// which means the length of a name.
func readNameLen(p *Process, a core.Address) (int64, int64) {
if p.minorVersion >= 17 {
v := 0
for i := 0; ; i++ {
x := p.proc.ReadUint8(a.Add(int64(i + 1)))
v += int(x&0x7f) << (7 * i)
if x&0x80 == 0 {
return int64(i + 1), int64(v)
}
}
} else {
n1 := p.proc.ReadUint8(a.Add(1))
n2 := p.proc.ReadUint8(a.Add(2))
n := uint16(n1)<<8 + uint16(n2)
return 2, int64(n)
}
}

// Convert the address of a runtime._type to a *Type.
// Guaranteed to return a non-nil *Type.
func (p *Process) runtimeType2Type(a core.Address) *Type {
Expand All @@ -134,9 +154,9 @@ func (p *Process) runtimeType2Type(a core.Address) *Type {
var name string
if m != nil {
x := m.types.Add(int64(r.Field("str").Int32()))
n := uint16(p.proc.ReadUint8(x.Add(1)))<<8 + uint16(p.proc.ReadUint8(x.Add(2)))
i, n := readNameLen(p, x)
b := make([]byte, n)
p.proc.ReadAt(b, x.Add(3))
p.proc.ReadAt(b, x.Add(i+1))
name = string(b)
if r.Field("tflag").Uint8()&uint8(p.rtConstants["tflagExtraStar"]) != 0 {
name = name[1:]
Expand Down

0 comments on commit 2c5b507

Please sign in to comment.