6
6
7
7
package base
8
8
9
- import (
10
- "fmt"
11
- "log"
12
- "os"
13
- "reflect"
14
- "strconv"
15
- "strings"
16
- )
17
-
18
9
// Debug holds the parsed debugging configuration values.
19
10
var Debug DebugFlags
20
11
@@ -26,7 +17,7 @@ var Debug DebugFlags
26
17
// Each setting is name=value; for ints, name is short for name=1.
27
18
type DebugFlags struct {
28
19
Append int `help:"print information about append compilation"`
29
- Checkptr int `help:"instrument unsafe pointer conversions"`
20
+ Checkptr int `help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation "`
30
21
Closure int `help:"print information about closure compilation"`
31
22
DclStack int `help:"run internal dclstack check"`
32
23
Defer int `help:"print information about defer compilation"`
@@ -40,7 +31,7 @@ type DebugFlags struct {
40
31
LocationLists int `help:"print information about DWARF location list creation"`
41
32
Nil int `help:"print information about nil checks"`
42
33
NoOpenDefer int `help:"disable open-coded defers"`
43
- PCTab string `help:"print named pc-value table"`
34
+ PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata "`
44
35
Panic int `help:"show all compiler panics"`
45
36
Slice int `help:"print information about slice compilation"`
46
37
SoftFloat int `help:"force compiler to emit soft-float code"`
@@ -52,141 +43,10 @@ type DebugFlags struct {
52
43
WB int `help:"print information about write barriers"`
53
44
ABIWrap int `help:"print information about ABI wrapper generation"`
54
45
55
- any bool // set when any of the values have been set
56
- }
57
-
58
- // Any reports whether any of the debug flags have been set.
59
- func (d * DebugFlags ) Any () bool { return d .any }
60
-
61
- type debugField struct {
62
- name string
63
- help string
64
- val interface {} // *int or *string
65
- }
66
-
67
- var debugTab []debugField
68
-
69
- func init () {
70
- v := reflect .ValueOf (& Debug ).Elem ()
71
- t := v .Type ()
72
- for i := 0 ; i < t .NumField (); i ++ {
73
- f := t .Field (i )
74
- if f .Name == "any" {
75
- continue
76
- }
77
- name := strings .ToLower (f .Name )
78
- help := f .Tag .Get ("help" )
79
- if help == "" {
80
- panic (fmt .Sprintf ("base.Debug.%s is missing help text" , f .Name ))
81
- }
82
- ptr := v .Field (i ).Addr ().Interface ()
83
- switch ptr .(type ) {
84
- default :
85
- panic (fmt .Sprintf ("base.Debug.%s has invalid type %v (must be int or string)" , f .Name , f .Type ))
86
- case * int , * string :
87
- // ok
88
- }
89
- debugTab = append (debugTab , debugField {name , help , ptr })
90
- }
46
+ Any bool // set when any of the debug flags have been set
91
47
}
92
48
93
49
// DebugSSA is called to set a -d ssa/... option.
94
50
// If nil, those options are reported as invalid options.
95
51
// If DebugSSA returns a non-empty string, that text is reported as a compiler error.
96
52
var DebugSSA func (phase , flag string , val int , valString string ) string
97
-
98
- // parseDebug parses the -d debug string argument.
99
- func parseDebug (debugstr string ) {
100
- // parse -d argument
101
- if debugstr == "" {
102
- return
103
- }
104
- Debug .any = true
105
- Split:
106
- for _ , name := range strings .Split (debugstr , "," ) {
107
- if name == "" {
108
- continue
109
- }
110
- // display help about the -d option itself and quit
111
- if name == "help" {
112
- fmt .Print (debugHelpHeader )
113
- maxLen := len ("ssa/help" )
114
- for _ , t := range debugTab {
115
- if len (t .name ) > maxLen {
116
- maxLen = len (t .name )
117
- }
118
- }
119
- for _ , t := range debugTab {
120
- fmt .Printf ("\t %-*s\t %s\n " , maxLen , t .name , t .help )
121
- }
122
- // ssa options have their own help
123
- fmt .Printf ("\t %-*s\t %s\n " , maxLen , "ssa/help" , "print help about SSA debugging" )
124
- fmt .Print (debugHelpFooter )
125
- os .Exit (0 )
126
- }
127
- val , valstring , haveInt := 1 , "" , true
128
- if i := strings .IndexAny (name , "=:" ); i >= 0 {
129
- var err error
130
- name , valstring = name [:i ], name [i + 1 :]
131
- val , err = strconv .Atoi (valstring )
132
- if err != nil {
133
- val , haveInt = 1 , false
134
- }
135
- }
136
- for _ , t := range debugTab {
137
- if t .name != name {
138
- continue
139
- }
140
- switch vp := t .val .(type ) {
141
- case nil :
142
- // Ignore
143
- case * string :
144
- * vp = valstring
145
- case * int :
146
- if ! haveInt {
147
- log .Fatalf ("invalid debug value %v" , name )
148
- }
149
- * vp = val
150
- default :
151
- panic ("bad debugtab type" )
152
- }
153
- continue Split
154
- }
155
- // special case for ssa for now
156
- if DebugSSA != nil && strings .HasPrefix (name , "ssa/" ) {
157
- // expect form ssa/phase/flag
158
- // e.g. -d=ssa/generic_cse/time
159
- // _ in phase name also matches space
160
- phase := name [4 :]
161
- flag := "debug" // default flag is debug
162
- if i := strings .Index (phase , "/" ); i >= 0 {
163
- flag = phase [i + 1 :]
164
- phase = phase [:i ]
165
- }
166
- err := DebugSSA (phase , flag , val , valstring )
167
- if err != "" {
168
- log .Fatalf (err )
169
- }
170
- continue Split
171
- }
172
- log .Fatalf ("unknown debug key -d %s\n " , name )
173
- }
174
- }
175
-
176
- const debugHelpHeader = `usage: -d arg[,arg]* and arg is <key>[=<value>]
177
-
178
- <key> is one of:
179
-
180
- `
181
-
182
- const debugHelpFooter = `
183
- <value> is key-specific.
184
-
185
- Key "checkptr" supports values:
186
- "0": instrumentation disabled
187
- "1": conversions involving unsafe.Pointer are instrumented
188
- "2": conversions to unsafe.Pointer force heap allocation
189
-
190
- Key "pctab" supports values:
191
- "pctospadj", "pctofile", "pctoline", "pctoinline", "pctopcdata"
192
- `
0 commit comments