-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.go
138 lines (110 loc) · 2.79 KB
/
manage.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Manage list of established and pending breakpoints.
*/
package breakpoint
import (
"log"
"server/dbgp/message"
"strconv"
)
/**
* The DBGp protocol uses "enabled" to indicate that a breakpoint is currently
* in use.
*/
const BreakpointEnabledState = "enabled"
/**
* @see getNewId()
*/
var lastPendingBreakpointId int = 0
/**
* List both pending and established breakpoints.
*/
func ListAllBreakpoints() (breakpoints map[int]message.Breakpoint) {
breakpoints = make(map[int]message.Breakpoint)
for k, breakpointRecord := range pending {
breakpoints[k] = message.Breakpoint{
Filename: breakpointRecord.Filename,
LineNo: breakpointRecord.LineNo,
Type: Line_type_breakpoint,
Id: breakpointRecord.DBGpId,
}
}
for k, breakpointRecord := range established {
breakpoints[k] = message.Breakpoint{
Filename: breakpointRecord.Filename,
LineNo: breakpointRecord.LineNo,
Type: Line_type_breakpoint,
Id: breakpointRecord.DBGpId,
}
}
return breakpoints
}
/**
* Renew breakpoint list.
*
* Update our list of existing breakpoints maintained by the DBGp engine.
*/
func RenewList(breakpoints map[int]message.Breakpoint) {
established.Empty()
for _, v := range breakpoints {
add(v.Type, v.Filename, v.LineNo, v.Id, v.State)
}
}
/**
* Delete the given breakpoint record from *our list*.
*/
func Delete(breakpointId int) {
delete(established, breakpointId)
}
/**
* Add a *pending* breakpoint record.
*
* Only deals with line breakpoints at the moment.
*/
func Enqueue(breakpointType, arg0, arg1 string) {
if breakpointType == Line_type_breakpoint {
enqueueLine(arg0, arg1)
}
}
/**
* Create a new breakpoint record in *our list*.
*
* This record is for an existing breakpoint. Only deals with line breakpoints
* at the moment.
*/
func add(breakpointType, filename string, lineNo, id int, state string) {
breakpointState := (state == BreakpointEnabledState)
if breakpointType == Line_type_breakpoint {
established.AddLine(filename, lineNo, id, breakpointState)
}
}
/**
* Add a pending breakpoint record for a source code line.
*/
func enqueueLine(filename, lineNoArg string) {
lineNo, err := strconv.Atoi(lineNoArg)
if filename == "" || err != nil {
log.Println(err)
return
}
pendingBreakpointId := getNewId()
b := breakpoint{
Type: Line_type_breakpoint,
LineNo: lineNo,
Filename: filename,
DBGpId: pendingBreakpointId,
State: true,
}
pending.push(b)
}
/**
* Produce a new ID number for breakpoint records.
*
* This Breakpoint ID is different from the numbers assigned by the DBGp engine.
* These are for Footle's internal use as IDs for pending breakpoints. Numbers
* start at -1 and keeps going *down*: -2, -3,...
*/
func getNewId() int {
lastPendingBreakpointId -= 1
return lastPendingBreakpointId
}