Skip to content

Commit be9cde2

Browse files
committed
stack: refactor Arg
Precalculate IsPtr. It's not costly to precalculate and it makes the code simpler.
1 parent a3a00fc commit be9cde2

5 files changed

Lines changed: 78 additions & 69 deletions

File tree

stack/bucket_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestAggregateNotAggressive(t *testing.T) {
4141
Calls: []Call{
4242
newCall(
4343
"main.func·001",
44-
Args{Values: []Arg{{Value: 0x11000000}, {Value: 2}}},
44+
Args{Values: []Arg{{Value: 0x11000000, IsPtr: true}, {Value: 2}}},
4545
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
4646
72),
4747
},
@@ -57,7 +57,7 @@ func TestAggregateNotAggressive(t *testing.T) {
5757
Calls: []Call{
5858
newCall(
5959
"main.func·001",
60-
Args{Values: []Arg{{Value: 0x21000000, Name: "#1"}, {Value: 2}}},
60+
Args{Values: []Arg{{Value: 0x21000000, Name: "#1", IsPtr: true}, {Value: 2}}},
6161
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
6262
72),
6363
},
@@ -125,15 +125,15 @@ func TestAggregateAggressive(t *testing.T) {
125125
"panic: runtime error: index out of range",
126126
"",
127127
"goroutine 6 [chan receive, 10 minutes]:",
128-
"main.func·001(0x11000000, 2)",
128+
"main.func·001(0x21000000, 2)",
129129
" /gopath/src/github.com/maruel/panicparse/stack/stack.go:72 +0x49",
130130
"",
131131
"goroutine 7 [chan receive, 50 minutes]:",
132-
"main.func·001(0x21000000, 2)",
132+
"main.func·001(0x31000000, 2)",
133133
" /gopath/src/github.com/maruel/panicparse/stack/stack.go:72 +0x49",
134134
"",
135135
"goroutine 8 [chan receive, 100 minutes]:",
136-
"main.func·001(0x21000000, 2)",
136+
"main.func·001(0x41000000, 2)",
137137
" /gopath/src/github.com/maruel/panicparse/stack/stack.go:72 +0x49",
138138
"",
139139
}
@@ -151,7 +151,7 @@ func TestAggregateAggressive(t *testing.T) {
151151
Calls: []Call{
152152
newCall(
153153
"main.func·001",
154-
Args{Values: []Arg{{Value: 0x11000000, Name: "*"}, {Value: 2}}},
154+
Args{Values: []Arg{{Value: 0x21000000, Name: "*", IsPtr: true}, {Value: 2}}},
155155
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
156156
72),
157157
},

stack/context.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,9 @@ func parseFunc(c *Call, line string) (bool, error) {
724724
if c.Args.Values == nil {
725725
c.Args.Values = make([]Arg, 0, 4)
726726
}
727-
c.Args.Values = append(c.Args.Values, Arg{Value: v})
727+
// Assume the stack was generated with the same bitness (32 vs 64) than
728+
// the code processing it.
729+
c.Args.Values = append(c.Args.Values, Arg{Value: v, IsPtr: v > pointerFloor && v < pointerCeiling})
728730
}
729731
return true, nil
730732
}

stack/context_test.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ func TestParseDump1(t *testing.T) {
109109
Args{}, "??", 0),
110110
newCall(
111111
"gopkg.in/yaml%2ev2.handleErr",
112-
Args{Values: []Arg{{Value: 0x433b20}}},
112+
Args{Values: []Arg{{Value: 0x433b20, IsPtr: true}}},
113113
"/gopath/src/gopkg.in/yaml.v2/yaml.go",
114114
153),
115115
newCall(
116116
"reflect.Value.assignTo",
117-
Args{Values: []Arg{{Value: 0x570860}, {Value: 0xc20803f3e0}, {Value: 0x15}}},
117+
Args{Values: []Arg{{Value: 0x570860, IsPtr: true}, {Value: 0xc20803f3e0, IsPtr: true}, {Value: 0x15}}},
118118
"/goroot/src/reflect/value.go",
119119
2125),
120120
newCall(
@@ -170,7 +170,7 @@ func TestParseDumpLongWait(t *testing.T) {
170170
Calls: []Call{
171171
newCall(
172172
"gopkg.in/yaml%2ev2.handleErr",
173-
Args{Values: []Arg{{Value: 0x433b20}}},
173+
Args{Values: []Arg{{Value: 0x433b20, IsPtr: true}}},
174174
"/gopath/src/gopkg.in/yaml.v2/yaml.go",
175175
153),
176176
},
@@ -187,7 +187,7 @@ func TestParseDumpLongWait(t *testing.T) {
187187
Calls: []Call{
188188
newCall(
189189
"gopkg.in/yaml%2ev2.handleErr",
190-
Args{Values: []Arg{{Value: 0x8033b21, Name: "#1"}}},
190+
Args{Values: []Arg{{Value: 0x8033b21, Name: "#1", IsPtr: true}}},
191191
"/gopath/src/gopkg.in/yaml.v2/yaml.go",
192192
153),
193193
},
@@ -204,7 +204,7 @@ func TestParseDumpLongWait(t *testing.T) {
204204
Calls: []Call{
205205
newCall(
206206
"gopkg.in/yaml%2ev2.handleErr",
207-
Args{Values: []Arg{{Value: 0x8033b22, Name: "#2"}}},
207+
Args{Values: []Arg{{Value: 0x8033b22, Name: "#2", IsPtr: true}}},
208208
"/gopath/src/gopkg.in/yaml.v2/yaml.go",
209209
153),
210210
},
@@ -484,11 +484,11 @@ func TestParseDumpElided(t *testing.T) {
484484
"github.com/maruel/panicparse/stack/stack.recurseType",
485485
Args{
486486
Values: []Arg{
487-
{Value: 0x7f4fa9a3ec70},
488-
{Value: 0xc208062580},
489-
{Value: 0x7f4fa9a3e818},
490-
{Value: 0x50a820},
491-
{Value: 0xc20803a8a0},
487+
{Value: 0x7f4fa9a3ec70, IsPtr: true},
488+
{Value: 0xc208062580, IsPtr: true},
489+
{Value: 0x7f4fa9a3e818, IsPtr: true},
490+
{Value: 0x50a820, IsPtr: true},
491+
{Value: 0xc20803a8a0, IsPtr: true},
492492
},
493493
},
494494
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
@@ -543,7 +543,7 @@ func TestParseDumpSysCall(t *testing.T) {
543543
"runtime.notetsleepg",
544544
Args{
545545
Values: []Arg{
546-
{Value: 0x918100},
546+
{Value: 0x918100, IsPtr: true},
547547
{Value: 0xffffffffffffffff},
548548
{Value: 0x1},
549549
},
@@ -887,7 +887,7 @@ func TestParseDumpCCode(t *testing.T) {
887887
Args{
888888
Values: []Arg{
889889
{Value: 0x4},
890-
{Value: 0x7fff671c7118},
890+
{Value: 0x7fff671c7118, IsPtr: true},
891891
{Value: 0xffffffff00000080},
892892
{},
893893
{Value: 0xffffffff0028c1be},
@@ -903,23 +903,23 @@ func TestParseDumpCCode(t *testing.T) {
903903
400),
904904
newCall(
905905
"runtime.netpoll",
906-
Args{Values: []Arg{{Value: 0x901b01}, {}}},
906+
Args{Values: []Arg{{Value: 0x901b01, IsPtr: true}, {}}},
907907
"/goroot/src/runtime/netpoll_epoll.go",
908908
68),
909909
newCall(
910910
"findrunnable",
911-
Args{Values: []Arg{{Value: 0xc208012000}}},
911+
Args{Values: []Arg{{Value: 0xc208012000, IsPtr: true}}},
912912
"/goroot/src/runtime/proc.c",
913913
1472),
914914
newCall("schedule", Args{}, "/goroot/src/runtime/proc.c", 1575),
915915
newCall(
916916
"runtime.park_m",
917-
Args{Values: []Arg{{Value: 0xc2080017a0}}},
917+
Args{Values: []Arg{{Value: 0xc2080017a0, IsPtr: true}}},
918918
"/goroot/src/runtime/proc.c",
919919
1654),
920920
newCall(
921921
"runtime.mcall",
922-
Args{Values: []Arg{{Value: 0x432684}}},
922+
Args{Values: []Arg{{Value: 0x432684, IsPtr: true}}},
923923
"/goroot/src/runtime/asm_amd64.s",
924924
186),
925925
},
@@ -964,12 +964,12 @@ func TestParseDumpWithCarriageReturn(t *testing.T) {
964964
0),
965965
newCall(
966966
"gopkg.in/yaml%2ev2.handleErr",
967-
Args{Values: []Arg{{Value: 0x433b20}}},
967+
Args{Values: []Arg{{Value: 0x433b20, IsPtr: true}}},
968968
"/gopath/src/gopkg.in/yaml.v2/yaml.go",
969969
153),
970970
newCall(
971971
"reflect.Value.assignTo",
972-
Args{Values: []Arg{{Value: 0x570860}, {Value: 0xc20803f3e0}, {Value: 0x15}}},
972+
Args{Values: []Arg{{Value: 0x570860, IsPtr: true}, {Value: 0xc20803f3e0, IsPtr: true}, {Value: 0x15}}},
973973
"/goroot/src/reflect/value.go",
974974
2125),
975975
newCall(
@@ -1034,12 +1034,12 @@ func TestParseDumpIndented(t *testing.T) {
10341034
209),
10351035
newCall(
10361036
"foo/bar.TestArchiveFail",
1037-
Args{Values: []Arg{{Value: 0x3382000, Name: "#1"}}},
1037+
Args{Values: []Arg{{Value: 0x3382000, Name: "#1", IsPtr: true}}},
10381038
"/home/maruel/go/src/foo/bar_test.go",
10391039
155),
10401040
newCall(
10411041
"testing.tRunner",
1042-
Args{Values: []Arg{{Value: 0x3382000, Name: "#1"}, {Value: 0x1615bf8}}},
1042+
Args{Values: []Arg{{Value: 0x3382000, Name: "#1", IsPtr: true}, {Value: 0x1615bf8, IsPtr: true}}},
10431043
"/home/maruel/golang/go/src/testing/testing.go",
10441044
865),
10451045
},
@@ -1341,7 +1341,7 @@ func testPanicStr(t *testing.T, c *Context, b *bytes.Buffer, ppDir string) {
13411341
Calls: []Call{
13421342
newCallLocal(
13431343
"main.panicstr",
1344-
Args{Values: []Arg{{Value: 0x123456}, {Value: 4}}},
1344+
Args{Values: []Arg{{Value: 0x123456, IsPtr: true}, {Value: 4}}},
13451345
pathJoin(ppDir, "main.go"),
13461346
50),
13471347
newCallLocal("main.glob..func17", Args{}, pathJoin(ppDir, "main.go"), 307),
@@ -1378,7 +1378,7 @@ func testPanicUTF8(t *testing.T, c *Context, b *bytes.Buffer, ppDir string) {
13781378
// runtime stack generator. The path is escaped, but symbols are
13791379
// not.
13801380
"github.com/maruel/panicparse"+ver+"/cmd/panic/internal/%c3%b9tf8.(*Strùct).Pànic",
1381-
Args{Values: []Arg{{Value: 0xc0000b2e48}}},
1381+
Args{Values: []Arg{{Value: 0xc0000b2e48, IsPtr: true}}},
13821382
// See TestCallUTF8 in stack_test.go for exercising the methods on
13831383
// Call in this situation.
13841384
pathJoin(ppDir, "internal", "ùtf8", "ùtf8.go"),
@@ -1667,6 +1667,7 @@ func identifyPanicwebSignature(t *testing.T, b *Bucket, pwebDir string) panicweb
16671667
for j := range b.Signature.Stack.Calls[i].Args.Values {
16681668
b.Signature.Stack.Calls[i].Args.Values[j].Value = 0
16691669
b.Signature.Stack.Calls[i].Args.Values[j].Name = ""
1670+
b.Signature.Stack.Calls[i].Args.Values[j].IsPtr = false
16701671
}
16711672
}
16721673
similarSignatures(t, &want, &b.Signature)
@@ -1727,7 +1728,7 @@ func identifyPanicwebSignature(t *testing.T, b *Bucket, pwebDir string) panicweb
17271728
newCallLocal("main.sysHang", Args{}, pathJoin(pwebDir, mainOS), 12),
17281729
newCallLocal(
17291730
"main.main.func2",
1730-
Args{Values: []Arg{{Value: 0xc000140720, Name: "#135"}}},
1731+
Args{Values: []Arg{{Value: 0xc000140720, Name: "#135", IsPtr: true}}},
17311732
pathJoin(pwebDir, "main.go"),
17321733
65),
17331734
}

stack/source_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestAugment(t *testing.T) {
4646
Calls: []Call{
4747
newCall(
4848
"main.f",
49-
Args{Values: []Arg{{Value: pointer}, {Value: 2}}},
49+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 2}}},
5050
"main.go",
5151
10),
5252
newCall("main.main", Args{}, "main.go", 3),
@@ -66,7 +66,7 @@ func TestAugment(t *testing.T) {
6666
Calls: []Call{
6767
newCall(
6868
"main.f",
69-
Args{Values: []Arg{{Value: pointer}}},
69+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
7070
"main.go",
7171
6),
7272
newCall("main.main", Args{}, "main.go", 3),
@@ -86,7 +86,7 @@ func TestAugment(t *testing.T) {
8686
Calls: []Call{
8787
newCall(
8888
"main.f",
89-
Args{Values: []Arg{{Value: pointer}, {Value: 1}, {Value: 1}}},
89+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 1}, {Value: 1}}},
9090
"main.go",
9191
6),
9292
newCall("main.main", Args{}, "main.go", 3),
@@ -106,7 +106,7 @@ func TestAugment(t *testing.T) {
106106
Calls: []Call{
107107
newCall(
108108
"main.f",
109-
Args{Values: []Arg{{Value: pointer}, {Value: 5}, {Value: 7}}},
109+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 5}, {Value: 7}}},
110110
"main.go",
111111
6),
112112
newCall("main.main", Args{}, "main.go", 3),
@@ -126,7 +126,7 @@ func TestAugment(t *testing.T) {
126126
Calls: []Call{
127127
newCall(
128128
"main.f",
129-
Args{Values: []Arg{{Value: pointer}, {Value: 5}, {Value: 7}}},
129+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 5}, {Value: 7}}},
130130
"main.go",
131131
6),
132132
newCall("main.main", Args{}, "main.go", 3),
@@ -146,7 +146,7 @@ func TestAugment(t *testing.T) {
146146
Calls: []Call{
147147
newCall(
148148
"main.f",
149-
Args{Values: []Arg{{Value: pointer}, {Value: 1}, {Value: 1}}},
149+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 1}, {Value: 1}}},
150150
"main.go",
151151
6),
152152
newCall("main.main", Args{}, "main.go", 3),
@@ -166,7 +166,7 @@ func TestAugment(t *testing.T) {
166166
Calls: []Call{
167167
newCall(
168168
"main.f",
169-
Args{Values: []Arg{{Value: pointer}}},
169+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
170170
"main.go",
171171
6),
172172
newCall("main.main", Args{}, "main.go", 3),
@@ -186,7 +186,7 @@ func TestAugment(t *testing.T) {
186186
Calls: []Call{
187187
newCall(
188188
"main.f",
189-
Args{Values: []Arg{{Value: pointer}}},
189+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
190190
"main.go",
191191
6),
192192
newCall("main.main", Args{}, "main.go", 3),
@@ -206,7 +206,7 @@ func TestAugment(t *testing.T) {
206206
Calls: []Call{
207207
newCall(
208208
"main.f",
209-
Args{Values: []Arg{{Value: pointer}}},
209+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
210210
"main.go",
211211
6),
212212
newCall("main.main", Args{}, "main.go", 3),
@@ -226,7 +226,7 @@ func TestAugment(t *testing.T) {
226226
Calls: []Call{
227227
newCall(
228228
"main.f",
229-
Args{Values: []Arg{{Value: pointer}}},
229+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
230230
"main.go",
231231
6),
232232
newCall("main.main", Args{}, "main.go", 3),
@@ -270,7 +270,7 @@ func TestAugment(t *testing.T) {
270270
Calls: []Call{
271271
newCall(
272272
"main.(*S).f",
273-
Args{Values: []Arg{{Value: pointer}}},
273+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
274274
"main.go",
275275
8),
276276
newCall("main.main", Args{}, "main.go", 4),
@@ -290,7 +290,7 @@ func TestAugment(t *testing.T) {
290290
Calls: []Call{
291291
newCall(
292292
"main.f",
293-
Args{Values: []Arg{{Value: pointer}, {Value: 3}}},
293+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 3}}},
294294
"main.go",
295295
6),
296296
newCall("main.main", Args{}, "main.go", 3),
@@ -310,7 +310,7 @@ func TestAugment(t *testing.T) {
310310
Calls: []Call{
311311
newCall(
312312
"main.f",
313-
Args{Values: []Arg{{Value: pointer}, {Value: 3}, {Value: 42}}},
313+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: 3}, {Value: 42}}},
314314
"main.go",
315315
6),
316316
newCall("main.main", Args{}, "main.go", 3),
@@ -356,7 +356,7 @@ func TestAugment(t *testing.T) {
356356
Calls: []Call{
357357
newCall(
358358
"main.f",
359-
Args{Values: []Arg{{Value: pointer}, {Value: pointer}}},
359+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: pointer, IsPtr: true}}},
360360
"main.go",
361361
7),
362362
newCall("main.main", Args{}, "main.go", 4),
@@ -377,7 +377,7 @@ func TestAugment(t *testing.T) {
377377
Calls: []Call{
378378
newCall(
379379
"main.f",
380-
Args{Values: []Arg{{Value: pointer}, {Value: pointer}}},
380+
Args{Values: []Arg{{Value: pointer, IsPtr: true}, {Value: pointer, IsPtr: true}}},
381381
"main.go",
382382
7),
383383
newCall("main.main", Args{}, "main.go", 4),
@@ -399,7 +399,7 @@ func TestAugment(t *testing.T) {
399399
"main.f",
400400
// The value is NOT a pointer but floating point encoding is not
401401
// deterministic.
402-
Args{Values: []Arg{{Value: pointer}}},
402+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
403403
"main.go",
404404
6),
405405
newCall("main.main", Args{}, "main.go", 3),
@@ -421,7 +421,7 @@ func TestAugment(t *testing.T) {
421421
"main.f",
422422
// The value is NOT a pointer but floating point encoding is not
423423
// deterministic.
424-
Args{Values: []Arg{{Value: pointer}}},
424+
Args{Values: []Arg{{Value: pointer, IsPtr: true}}},
425425
"main.go",
426426
6),
427427
newCall("main.main", Args{}, "main.go", 3),

0 commit comments

Comments
 (0)