author | Claus Gittinger <cg@exept.de> |
Fri, 08 Jun 2012 09:38:21 +0200 | |
changeset 11569 | 39989f33ca9d |
parent 11463 | 8a36754c05b5 |
child 11601 | 6500e91de9e8 |
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 |
10714
3399fb50f42e
changed: #buttonPress:x:y:in:
Claus Gittinger <cg@exept.de>
parents:
10411
diff
changeset
|
109 |
|lineNr| |
3399fb50f42e
changed: #buttonPress:x:y:in:
Claus Gittinger <cg@exept.de>
parents:
10411
diff
changeset
|
110 |
|
10182 | 111 |
codeView methodHolder value isNil ifTrue:[ |
112 |
^ false |
|
113 |
]. |
|
9982 | 114 |
view == gutterView ifTrue:[ |
115 |
button == 1 ifTrue:[ |
|
10714
3399fb50f42e
changed: #buttonPress:x:y:in:
Claus Gittinger <cg@exept.de>
parents:
10411
diff
changeset
|
116 |
lineNr := textView yVisibleToLineNr:y. |
3399fb50f42e
changed: #buttonPress:x:y:in:
Claus Gittinger <cg@exept.de>
parents:
10411
diff
changeset
|
117 |
lineNr notNil ifTrue:[ self setOrToggleBreakpointAtLine:lineNr ]. |
10182 | 118 |
^ true. |
9982 | 119 |
]. |
120 |
button == 3 ifTrue:[ |
|
10182 | 121 |
^ true. |
9982 | 122 |
] |
123 |
]. |
|
10182 | 124 |
^ false |
9982 | 125 |
|
126 |
"Created: / 17-06-2011 / 13:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
127 |
"Modified: / 28-06-2011 / 08:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10714
3399fb50f42e
changed: #buttonPress:x:y:in:
Claus Gittinger <cg@exept.de>
parents:
10411
diff
changeset
|
128 |
"Modified: / 19-09-2011 / 14:41:00 / cg" |
10226 | 129 |
! |
130 |
||
131 |
linesDeletedFrom: start to: end |
|
132 |
||
133 |
breakpoints isEmptyOrNil ifTrue:[^self]. |
|
134 |
self moveBreakpointsAfterLine: start - 1 by: (end - start + 1) negated |
|
135 |
||
136 |
"Created: / 06-07-2011 / 17:16:27 / jv" |
|
137 |
! |
|
138 |
||
139 |
linesInsertedFrom: start to: end |
|
140 |
||
141 |
breakpoints isEmptyOrNil ifTrue:[^self]. |
|
142 |
self moveBreakpointsAfterLine: start - 1 by: (end - start + 1) |
|
143 |
||
144 |
"Created: / 06-07-2011 / 17:16:36 / jv" |
|
9982 | 145 |
! ! |
146 |
||
147 |
!BreakpointService methodsFor:'initialization'! |
|
148 |
||
149 |
initialize |
|
150 |
||
151 |
super initialize. |
|
152 |
breakpoints := OrderedCollection new. |
|
153 |
||
154 |
"Created: / 17-06-2011 / 13:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
155 |
! ! |
|
156 |
||
157 |
!BreakpointService methodsFor:'private'! |
|
158 |
||
10182 | 159 |
breakpointAtLine:line |
160 |
|pos| |
|
9982 | 161 |
|
162 |
pos := textView characterPositionOfLine:line col:1. |
|
163 |
^ breakpoints ? #() detect:[:each | each position = pos ] ifNone:[ nil ] |
|
164 |
||
165 |
"Modified: / 17-06-2011 / 13:59:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10182 | 166 |
"Modified (format): / 05-07-2011 / 21:33:23 / cg" |
167 |
! |
|
168 |
||
10226 | 169 |
moveBreakpointsAfterLine:line by: delta |
170 |
||
171 |
|pos | |
|
172 |
||
173 |
||
174 |
breakpoints do:[:bpnt| |
|
175 |
bpnt line >= line ifTrue:[ |
|
176 |
pos := textView characterPositionOfLine:bpnt line + delta col:1. |
|
177 |
bpnt line: bpnt line + delta; position: pos |
|
178 |
] |
|
179 |
]. |
|
180 |
||
181 |
"/gutterView redrawLinesFrom: line. |
|
182 |
||
183 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
184 |
"Modified: / 05-07-2011 / 21:32:49 / cg" |
|
185 |
"Created: / 06-07-2011 / 17:26:30 / jv" |
|
186 |
! |
|
187 |
||
10182 | 188 |
recompile |
189 |
"recompile the current method for changed breakpoints" |
|
190 |
||
11569 | 191 |
|method newMethod compiler class selector| |
10182 | 192 |
|
193 |
method := codeView methodHolder value. |
|
194 |
(method notNil and:[method hasPrimitiveCode not]) ifTrue:[ |
|
195 |
"/ be careful: if the text has been edited/modified, do not compile |
|
196 |
textView modified ifTrue:[ |
|
197 |
self halt |
|
198 |
] ifFalse:[ |
|
199 |
"/ prepare to get reachable bpts |
|
200 |
breakpoints do:[:bp | bp isReached:false]. |
|
201 |
||
11569 | 202 |
class := method mclass. |
203 |
selector := method selector. |
|
10209 | 204 |
Class withoutUpdatingChangesDo:[ |
11463 | 205 |
compiler := ByteCodeCompilerWithBreakpointSupport new. |
206 |
compiler breakpoints:breakpoints. |
|
207 |
newMethod := compiler |
|
208 |
compile:method source |
|
11569 | 209 |
forClass:class |
11463 | 210 |
inCategory:method category |
211 |
notifying:nil |
|
212 |
install:false |
|
213 |
skipIfSame:false |
|
214 |
silent:true |
|
215 |
foldConstants:true |
|
216 |
ifFail:[ self halt ]. |
|
10182 | 217 |
|
11569 | 218 |
(class primAddSelector:selector withMethod:newMethod) ifFalse:[ |
11463 | 219 |
self halt. |
220 |
^ self |
|
221 |
]. |
|
11569 | 222 |
codeView methodHolder value:newMethod. |
223 |
method mclass isNil ifTrue:[ |
|
224 |
method mclass:class. |
|
225 |
]. |
|
10209 | 226 |
]. |
10899 | 227 |
"/ self halt. |
10894 | 228 |
breakpoints := breakpoints |
229 |
select:[:bp | |
|
230 |
bp isReached ifFalse:[ Transcript show:'remove unreached:'; showCR:bp ]. |
|
231 |
bp isReached |
|
232 |
] |
|
10182 | 233 |
] |
234 |
] |
|
235 |
||
236 |
"Created: / 05-07-2011 / 21:33:13 / cg" |
|
9982 | 237 |
! |
238 |
||
239 |
setOrToggleBreakpointAtLine:line |
|
240 |
|pos bpnt| |
|
241 |
||
242 |
pos := textView characterPositionOfLine:line col:1. |
|
243 |
bpnt := self breakpointAtLine:line. |
|
10182 | 244 |
bpnt isNil ifTrue:[ |
10411 | 245 |
(codeView topView class ~~ DebugView) ifTrue:[ |
11221
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
246 |
breakpoints add:((bpnt := Breakpoint new) |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
247 |
position:pos; |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
248 |
line:line). |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
249 |
Display shiftDown ifTrue:[ |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
250 |
"/ trace |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
251 |
bpnt beTracepoint |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
252 |
]. |
10411 | 253 |
self recompile. |
254 |
]. |
|
10182 | 255 |
] ifFalse:[ |
11221
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
256 |
Display shiftDown ifTrue:[ |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
257 |
bpnt toggleTracing |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
258 |
] ifFalse:[ |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
259 |
bpnt toggle. |
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
260 |
] |
10182 | 261 |
]. |
9982 | 262 |
gutterView redrawLine:line. |
263 |
||
264 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10411 | 265 |
"Modified: / 27-07-2011 / 13:27:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
11221
a0108d5a0d1b
changed: #setOrToggleBreakpointAtLine:
Claus Gittinger <cg@exept.de>
parents:
10899
diff
changeset
|
266 |
"Modified: / 27-01-2012 / 13:55:12 / cg" |
9982 | 267 |
! ! |
268 |
||
269 |
!BreakpointService methodsFor:'redrawing'! |
|
270 |
||
10182 | 271 |
drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg |
9982 | 272 |
"Called by both gutterView and textView (well, not yet) to |
273 |
allow services to draw custom things on text view. |
|
274 |
Ask JV what the args means if unsure (I'm lazy to document |
|
275 |
them, now it is just an experiment...)" |
|
10182 | 276 |
|
277 |
|bpnt icon dx dy| |
|
9982 | 278 |
|
10182 | 279 |
codeView methodHolder value isNil ifTrue:[ |
280 |
^ self |
|
281 |
]. |
|
282 |
view == gutterView ifTrue:[ |
|
283 |
bpnt := self breakpointAtLine:lineNo. |
|
284 |
bpnt isNil ifTrue:[ |
|
285 |
^ self |
|
286 |
]. |
|
287 |
icon := bpnt icon. |
|
288 |
icon isNil ifTrue:[ |
|
289 |
^ self |
|
290 |
]. |
|
291 |
dx := ((w - icon width) / 2) rounded. |
|
292 |
dy := ((h - icon height) / 2) rounded. |
|
293 |
icon |
|
294 |
displayOn:view |
|
295 |
x:x + dx |
|
296 |
y:y - h + dy + 4. "TODO: Magic constant" |
|
9982 | 297 |
]. |
298 |
||
299 |
"Created: / 17-06-2011 / 13:52:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10182 | 300 |
"Modified (format): / 05-07-2011 / 22:14:33 / cg" |
9982 | 301 |
! ! |
302 |
||
303 |
!BreakpointService class methodsFor:'documentation'! |
|
304 |
||
305 |
version_CVS |
|
11569 | 306 |
^ '$Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.13 2012-06-08 07:38:21 cg Exp $' |
9982 | 307 |
! |
308 |
||
309 |
version_SVN |
|
310 |
^ '§Id§' |
|
311 |
! ! |