forked from system-pclub/GCatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
109 lines (101 loc) · 3.32 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package C7A
import (
"fmt"
"github.com/system-pclub/GCatch/GFix/dispatcher/global"
"github.com/system-pclub/GCatch/GFix/dispatcher/output"
)
type bug_report struct {
ch *channel
send *ch_send
recv *ch_receive
}
func report(bug bug_report) {
for _, reported := range C7A_reported {
if reported.ch == bug.ch { // only report one bug for one channel
return
}
}
C7A_reported = append(C7A_reported, bug)
if bug.send == nil && bug.recv == nil {
return
}
global.Bug_index_mu.Lock()
global.Bug_index++
/*fmt.Print("----------Bug[")
fmt.Print(global.Bug_index)*/
global.Bug_index_mu.Unlock()
if bug.send != nil { //A local channel's send is definitely executed, but receive is not.
//print file, make line no, send line no, recv line no
/*if isGL1_new(bug) {
fmt.Printf("1, path=%s, make_lineno=%d, send_lineno=%d\n", // recv_lineno=%d\n",
getFileName(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.send.inst),
)
} else {
fmt.Printf("0, path=%s, make_lineno=%d, send_lineno=%d\n", // recv_lineno=%d\n",
getFileName(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.send.inst),
)
}*/
/*
lineno := getGL2PatchLineNo(bug)
if lineno != -1 {
fmt.Printf("2, path=%s, make_lineno=%d, defer_insert_lineno=%d, defer_remove_lineno=\n",
getFileName(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.ch.make_inst),
lineno,
)
} else {
}
*/
} else {
linenoIns, linenosRemove := getGL2PatchLineNo(bug)
fmt.Printf("2, path=%s, make_lineno=%d, defer_insert_lineno=%d, defer_remove_lineno=", //%d
getFileName(global.Prog.Fset, bug.ch.make_inst),
getLineNo(global.Prog.Fset, bug.ch.make_inst),
linenoIns,
)
for _, x := range linenosRemove {
fmt.Printf("%d ", x)
}
fmt.Println()
/* fmt.Print("]----------\n\tType: Goroutine Leak \tReason: A local channel's receive is definitely executed, but send is not.\n")
fmt.Print("\tLocation of make of channel:\n")
output.Print_inst_and_location(bug.ch.make_inst)
fmt.Print("\tLocation of receive of channel:\n")
output.Print_inst_and_location(bug.recv.inst)*/
}
return
}
func report_direct_usage(bug bug_report) {
for _, reported := range C7A_reported {
if reported.ch == bug.ch { // only report one bug for one channel
return
}
}
C7A_reported = append(C7A_reported, bug)
if bug.send == nil && bug.recv == nil {
return
}
global.Bug_index_mu.Lock()
global.Bug_index++
fmt.Print("----------Bug[")
fmt.Print(global.Bug_index)
global.Bug_index_mu.Unlock()
if bug.send != nil {
fmt.Print("]----------\n\tType: Goroutine Leak \tReason: A local unbuffered channel's send is directly used after creation.\n")
fmt.Print("\tLocation of make of channel:\n")
output.Print_inst_and_location(bug.ch.make_inst)
fmt.Print("\tLocation of send of channel:\n")
output.Print_inst_and_location(bug.send.inst)
} else {
fmt.Print("]----------\n\tType: Goroutine Leak \tReason: A local unbuffered channel's recv is directly used after creation.\n")
fmt.Print("\tLocation of make of channel:\n")
output.Print_inst_and_location(bug.ch.make_inst)
fmt.Print("\tLocation of receive of channel:\n")
output.Print_inst_and_location(bug.recv.inst)
}
return
}