File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ import (
15
15
"golang.org/x/debug/internal/core"
16
16
)
17
17
18
+ const (
19
+ AttrGoKind dwarf.Attr = 0x2900
20
+ )
21
+
18
22
// read DWARF types from core dump.
19
23
func (p * Process ) readDWARFTypes () {
20
24
d , _ := p .proc .DWARF ()
@@ -34,6 +38,9 @@ func (p *Process) readDWARFTypes() {
34
38
continue
35
39
}
36
40
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
+ }
37
44
p .dwarfMap [dt ] = t
38
45
types = append (types , t )
39
46
}
@@ -112,13 +119,12 @@ func (p *Process) readDWARFTypes() {
112
119
if t .Kind != KindStruct {
113
120
continue
114
121
}
115
- if t .Name == "string" { // TODO: also "struct runtime.stringStructDWARF" ?
122
+ switch t .goKind {
123
+ case reflect .String :
116
124
t .Kind = KindString
117
125
t .Elem = t .Fields [0 ].Type .Elem // TODO: check that it is always uint8.
118
126
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 :
122
128
t .Kind = KindSlice
123
129
t .Elem = t .Fields [0 ].Type .Elem
124
130
t .Fields = nil
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package gocore
6
6
7
7
import (
8
8
"fmt"
9
+ "reflect"
9
10
"regexp"
10
11
"strings"
11
12
@@ -18,7 +19,11 @@ import (
18
19
type Type struct {
19
20
Name string
20
21
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
22
27
23
28
// Fields only valid for a subset of kinds.
24
29
Count int64 // for kind == KindArray
You can’t perform that action at this time.
0 commit comments