author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 29 Jan 2012 12:53:39 +0000 | |
branch | jv |
changeset 12123 | 4bde08cebd48 |
parent 11221 | a0108d5a0d1b |
child 12125 | 0c49a3b13e43 |
permissions | -rw-r--r-- |
9982 | 1 |
" |
10071 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
9982 | 3 |
All Rights Reserved |
4 |
||
10071 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9982 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
"{ NameSpace: Tools }" |
|
29 |
||
30 |
CodeViewService subclass:#BreakpointService |
|
10208 | 31 |
instanceVariableNames:'breakpoints currentMethod' |
9982 | 32 |
classVariableNames:'' |
33 |
poolDictionaries:'' |
|
34 |
category:'Interface-CodeView' |
|
35 |
! |
|
36 |
||
37 |
!BreakpointService class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
10071 | 41 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
9982 | 42 |
All Rights Reserved |
43 |
||
10071 | 44 |
Permission is hereby granted, free of charge, to any person |
45 |
obtaining a copy of this software and associated documentation |
|
46 |
files (the 'Software'), to deal in the Software without |
|
47 |
restriction, including without limitation the rights to use, |
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
49 |
copies of the Software, and to permit persons to whom the |
|
50 |
Software is furnished to do so, subject to the following |
|
51 |
conditions: |
|
52 |
||
53 |
The above copyright notice and this permission notice shall be |
|
54 |
included in all copies or substantial portions of the Software. |
|
55 |
||
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
63 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9982 | 64 |
" |
65 |
! ! |
|
66 |
||
10226 | 67 |
!BreakpointService methodsFor:'accessing'! |
68 |
||
69 |
breakpoints |
|
70 |
^ breakpoints |
|
71 |
! ! |
|
72 |
||
10208 | 73 |
!BreakpointService methodsFor:'change & update'! |
74 |
||
75 |
update: aspect with: param from: sender |
|
76 |
|method| |
|
77 |
||
78 |
method := codeView methodHolder value. |
|
79 |
method ~~ currentMethod ifTrue:[ |
|
80 |
self updateBreakPointsFor:method. |
|
81 |
]. |
|
82 |
||
83 |
super update: aspect with: param from: sender |
|
84 |
||
85 |
"Created: / 06-07-2011 / 15:21:08 / cg" |
|
86 |
! |
|
87 |
||
88 |
updateBreakPointsFor:aMethod |
|
89 |
|methodsBreakPoints| |
|
90 |
||
91 |
methodsBreakPoints := OrderedCollection new. |
|
92 |
aMethod notNil ifTrue:[ |
|
93 |
aMethod literalsDo:[:eachLiteral | |
|
94 |
eachLiteral class == Breakpoint ifTrue:[ |
|
10226 | 95 |
methodsBreakPoints add:eachLiteral copy. |
10208 | 96 |
]. |
97 |
]. |
|
98 |
]. |
|
99 |
breakpoints := methodsBreakPoints. |
|
100 |
currentMethod := aMethod. |
|
101 |
||
102 |
"Created: / 06-07-2011 / 15:24:09 / cg" |
|
10226 | 103 |
"Modified: / 06-07-2011 / 17:32:54 / jv" |
10208 | 104 |
! ! |
105 |
||
9982 | 106 |
!BreakpointService methodsFor:'event handling'! |
107 |
||
10182 | 108 |
buttonPress:button x:x y:y in:view |
109 |
codeView methodHolder value isNil ifTrue:[ |
|
110 |
^ false |
|
111 |
]. |
|
9982 | 112 |
view == gutterView ifTrue:[ |
113 |
button == 1 ifTrue:[ |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
114 |
self setOrToggleBreakpointAtLine:(textView yVisibleToLineNr:y). |
10182 | 115 |
^ true. |
9982 | 116 |
]. |
117 |
button == 3 ifTrue:[ |
|
10182 | 118 |
^ true. |
9982 | 119 |
] |
120 |
]. |
|
10182 | 121 |
^ false |
9982 | 122 |
|
123 |
"Created: / 17-06-2011 / 13:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
124 |
"Modified: / 28-06-2011 / 08:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
125 |
"Modified (format): / 05-07-2011 / 21:33:29 / cg" |
10226 | 126 |
! |
127 |
||
128 |
linesDeletedFrom: start to: end |
|
129 |
||
130 |
breakpoints isEmptyOrNil ifTrue:[^self]. |
|
131 |
self moveBreakpointsAfterLine: start - 1 by: (end - start + 1) negated |
|
132 |
||
133 |
"Created: / 06-07-2011 / 17:16:27 / jv" |
|
134 |
! |
|
135 |
||
136 |
linesInsertedFrom: start to: end |
|
137 |
||
138 |
breakpoints isEmptyOrNil ifTrue:[^self]. |
|
139 |
self moveBreakpointsAfterLine: start - 1 by: (end - start + 1) |
|
140 |
||
141 |
"Created: / 06-07-2011 / 17:16:36 / jv" |
|
9982 | 142 |
! ! |
143 |
||
144 |
!BreakpointService methodsFor:'initialization'! |
|
145 |
||
146 |
initialize |
|
147 |
||
148 |
super initialize. |
|
149 |
breakpoints := OrderedCollection new. |
|
150 |
||
151 |
"Created: / 17-06-2011 / 13:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
152 |
! ! |
|
153 |
||
154 |
!BreakpointService methodsFor:'private'! |
|
155 |
||
10182 | 156 |
breakpointAtLine:line |
157 |
|pos| |
|
9982 | 158 |
|
159 |
pos := textView characterPositionOfLine:line col:1. |
|
160 |
^ breakpoints ? #() detect:[:each | each position = pos ] ifNone:[ nil ] |
|
161 |
||
162 |
"Modified: / 17-06-2011 / 13:59:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10182 | 163 |
"Modified (format): / 05-07-2011 / 21:33:23 / cg" |
164 |
! |
|
165 |
||
10226 | 166 |
moveBreakpointsAfterLine:line by: delta |
167 |
||
168 |
|pos | |
|
169 |
||
170 |
||
171 |
breakpoints do:[:bpnt| |
|
172 |
bpnt line >= line ifTrue:[ |
|
173 |
pos := textView characterPositionOfLine:bpnt line + delta col:1. |
|
174 |
bpnt line: bpnt line + delta; position: pos |
|
175 |
] |
|
176 |
]. |
|
177 |
||
178 |
"/gutterView redrawLinesFrom: line. |
|
179 |
||
180 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
181 |
"Modified: / 05-07-2011 / 21:32:49 / cg" |
|
182 |
"Created: / 06-07-2011 / 17:26:30 / jv" |
|
183 |
! |
|
184 |
||
10182 | 185 |
recompile |
186 |
"recompile the current method for changed breakpoints" |
|
187 |
||
188 |
|method| |
|
189 |
||
190 |
method := codeView methodHolder value. |
|
191 |
(method notNil and:[method hasPrimitiveCode not]) ifTrue:[ |
|
192 |
"/ be careful: if the text has been edited/modified, do not compile |
|
193 |
textView modified ifTrue:[ |
|
194 |
self halt |
|
195 |
] ifFalse:[ |
|
196 |
"/ prepare to get reachable bpts |
|
197 |
breakpoints do:[:bp | bp isReached:false]. |
|
198 |
||
10209 | 199 |
Class withoutUpdatingChangesDo:[ |
200 |
ByteCodeCompilerWithBreakpointSupport new |
|
201 |
breakpoints:breakpoints; |
|
10182 | 202 |
|
10209 | 203 |
compile:method source |
204 |
forClass:method mclass |
|
205 |
inCategory:method category |
|
206 |
notifying:nil |
|
207 |
install:true |
|
208 |
skipIfSame:false |
|
209 |
silent:true |
|
210 |
foldConstants:true |
|
211 |
ifFail:[ self halt ]. |
|
212 |
]. |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
213 |
breakpoints := breakpoints select:[:bp | bp isReached] |
10182 | 214 |
] |
215 |
] |
|
216 |
||
217 |
"Created: / 05-07-2011 / 21:33:13 / cg" |
|
9982 | 218 |
! |
219 |
||
220 |
setOrToggleBreakpointAtLine:line |
|
221 |
|pos bpnt| |
|
222 |
||
223 |
pos := textView characterPositionOfLine:line col:1. |
|
224 |
bpnt := self breakpointAtLine:line. |
|
10182 | 225 |
bpnt isNil ifTrue:[ |
10411 | 226 |
(codeView topView class ~~ DebugView) ifTrue:[ |
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
227 |
breakpoints add:((Breakpoint new) |
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
228 |
position:pos; |
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
229 |
line:line). |
10411 | 230 |
self recompile. |
231 |
]. |
|
10182 | 232 |
] ifFalse:[ |
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
233 |
bpnt toggle. |
10182 | 234 |
]. |
9982 | 235 |
gutterView redrawLine:line. |
236 |
||
237 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
238 |
"Modified: / 05-07-2011 / 21:32:49 / cg" |
10411 | 239 |
"Modified: / 27-07-2011 / 13:27:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9982 | 240 |
! ! |
241 |
||
242 |
!BreakpointService methodsFor:'redrawing'! |
|
243 |
||
10182 | 244 |
drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg |
9982 | 245 |
"Called by both gutterView and textView (well, not yet) to |
246 |
allow services to draw custom things on text view. |
|
247 |
Ask JV what the args means if unsure (I'm lazy to document |
|
248 |
them, now it is just an experiment...)" |
|
10182 | 249 |
|
250 |
|bpnt icon dx dy| |
|
9982 | 251 |
|
10182 | 252 |
codeView methodHolder value isNil ifTrue:[ |
253 |
^ self |
|
254 |
]. |
|
255 |
view == gutterView ifTrue:[ |
|
256 |
bpnt := self breakpointAtLine:lineNo. |
|
257 |
bpnt isNil ifTrue:[ |
|
258 |
^ self |
|
259 |
]. |
|
260 |
icon := bpnt icon. |
|
261 |
icon isNil ifTrue:[ |
|
262 |
^ self |
|
263 |
]. |
|
264 |
dx := ((w - icon width) / 2) rounded. |
|
265 |
dy := ((h - icon height) / 2) rounded. |
|
266 |
icon |
|
267 |
displayOn:view |
|
268 |
x:x + dx |
|
269 |
y:y - h + dy + 4. "TODO: Magic constant" |
|
9982 | 270 |
]. |
271 |
||
272 |
"Created: / 17-06-2011 / 13:52:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10182 | 273 |
"Modified (format): / 05-07-2011 / 22:14:33 / cg" |
9982 | 274 |
! ! |
275 |
||
276 |
!BreakpointService class methodsFor:'documentation'! |
|
277 |
||
278 |
version_CVS |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
279 |
^ '§Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.7 2011/07/27 12:33:11 vrany Exp §' |
9982 | 280 |
! |
281 |
||
282 |
version_SVN |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
283 |
^ '$Id$' |
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
11221
diff
changeset
|
284 |
! ! |