Skip to content

Commit 2917a7a

Browse files
WangLeonardgopherbot
authored andcommitted
internal/gocore: use AttrGoKind to fix named slice type
Use AttrGoKind instead of the name matching to check the slice and string type. For golang/go#57447. Change-Id: I8765aa1a6315609b3476b8b84c27130629847235 Reviewed-on: https://go-review.googlesource.com/c/debug/+/593680 Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tim King <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent fbc6857 commit 2917a7a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

internal/gocore/dwarf.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"golang.org/x/debug/internal/core"
1616
)
1717

18+
const (
19+
AttrGoKind dwarf.Attr = 0x2900
20+
)
21+
1822
// read DWARF types from core dump.
1923
func (p *Process) readDWARFTypes() {
2024
d, _ := p.proc.DWARF()
@@ -34,6 +38,9 @@ func (p *Process) readDWARFTypes() {
3438
continue
3539
}
3640
t := &Type{Name: gocoreName(dt), Size: dwarfSize(dt, p.proc.PtrSize())}
41+
if goKind, ok := e.Val(AttrGoKind).(int64); ok {
42+
t.goKind = reflect.Kind(goKind)
43+
}
3744
p.dwarfMap[dt] = t
3845
types = append(types, t)
3946
}
@@ -112,13 +119,12 @@ func (p *Process) readDWARFTypes() {
112119
if t.Kind != KindStruct {
113120
continue
114121
}
115-
if t.Name == "string" { // TODO: also "struct runtime.stringStructDWARF" ?
122+
switch t.goKind {
123+
case reflect.String:
116124
t.Kind = KindString
117125
t.Elem = t.Fields[0].Type.Elem // TODO: check that it is always uint8.
118126
t.Fields = nil
119-
}
120-
if len(t.Name) >= 9 && t.Name[:9] == "struct []" ||
121-
len(t.Name) >= 2 && t.Name[:2] == "[]" {
127+
case reflect.Slice:
122128
t.Kind = KindSlice
123129
t.Elem = t.Fields[0].Type.Elem
124130
t.Fields = nil

internal/gocore/type.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package gocore
66

77
import (
88
"fmt"
9+
"reflect"
910
"regexp"
1011
"strings"
1112

@@ -18,7 +19,11 @@ import (
1819
type Type struct {
1920
Name string
2021
Size int64
21-
Kind Kind
22+
Kind Kind // common dwarf types.
23+
// go-specific types obtained from AttrGoKind, such as string and slice.
24+
// Kind and gokind are not correspond one to one, both need to be preserved now.
25+
// For example, slices are described in dwarf by a 3-field struct, so its Kind is Struct and its goKind is Slice.
26+
goKind reflect.Kind
2227

2328
// Fields only valid for a subset of kinds.
2429
Count int64 // for kind == KindArray

0 commit comments

Comments
 (0)