author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 07 Sep 2012 18:28:09 +0100 | |
branch | jv |
changeset 12287 | 400a99059170 |
parent 12265 | f1b3696cf042 |
child 12308 | 5d9291c0fc27 |
permissions | -rw-r--r-- |
9982 | 1 |
" |
10071 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
12262 | 3 |
All Rights Reserved |
9982 | 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 |
||
12265 | 30 |
Tools::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 |
12262 | 42 |
All Rights Reserved |
9982 | 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:[ |
|
12262 | 80 |
self updateBreakPointsFor:method. |
10208 | 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:[ |
|
12262 | 93 |
aMethod literalsDo:[:eachLiteral | |
94 |
eachLiteral class == Breakpoint ifTrue:[ |
|
95 |
methodsBreakPoints add:eachLiteral copy. |
|
96 |
]. |
|
97 |
]. |
|
10208 | 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 |
||
12262 | 108 |
buttonPress:button x:x y:y in:view |
12125 | 109 |
|lineNr| |
110 |
||
10182 | 111 |
codeView methodHolder value isNil ifTrue:[ |
12262 | 112 |
^ false |
10182 | 113 |
]. |
9982 | 114 |
view == gutterView ifTrue:[ |
12262 | 115 |
button == 1 ifTrue:[ |
116 |
lineNr := textView yVisibleToLineNr:y. |
|
117 |
lineNr notNil ifTrue:[ self setOrToggleBreakpointAtLine:lineNr ]. |
|
118 |
^ true. |
|
119 |
]. |
|
120 |
button == 3 ifTrue:[ |
|
121 |
^ true. |
|
122 |
] |
|
9982 | 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>" |
|
12125 | 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 |
||
12262 | 159 |
breakpointAtLine:line |
10182 | 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 |
|pos | |
|
171 |
||
172 |
breakpoints do:[:bpnt| |
|
12287 | 173 |
bpnt line >= line ifTrue:[ |
174 |
pos := textView characterPositionOfLine:bpnt line + delta col:1. |
|
175 |
bpnt position:pos line:(bpnt line + delta). |
|
176 |
] |
|
10226 | 177 |
]. |
178 |
||
179 |
"/gutterView redrawLinesFrom: line. |
|
180 |
||
181 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
182 |
"Created: / 06-07-2011 / 17:26:30 / jv" |
|
12287 | 183 |
"Modified: / 02-08-2012 / 09:27:10 / cg" |
10226 | 184 |
! |
185 |
||
10182 | 186 |
recompile |
187 |
"recompile the current method for changed breakpoints" |
|
188 |
||
12287 | 189 |
|oldMethod newMethod compiler class selector| |
10182 | 190 |
|
12287 | 191 |
oldMethod := codeView methodHolder value. |
192 |
(oldMethod notNil and:[oldMethod hasPrimitiveCode not]) ifTrue:[ |
|
193 |
"/ be careful: if the text has been edited/modified, do not compile |
|
194 |
textView modified ifTrue:[ |
|
195 |
self breakPoint: #cg. |
|
196 |
self breakPoint: #jv. |
|
197 |
^self. |
|
198 |
] ifFalse:[ |
|
199 |
"/ prepare to get reachable bpts |
|
200 |
breakpoints do:[:bp | bp isReached:false]. |
|
201 |
||
202 |
class := oldMethod mclass. |
|
203 |
class isNil ifTrue:[ |
|
204 |
class := codeView classHolder value. |
|
205 |
]. |
|
206 |
selector := oldMethod selector. |
|
10182 | 207 |
|
12287 | 208 |
Class withoutUpdatingChangesDo:[ |
209 |
compiler := ByteCodeCompilerWithBreakpointSupport new. |
|
210 |
compiler breakpoints:breakpoints. |
|
211 |
compiler methodClass:MethodWithBreakpoints. |
|
212 |
newMethod := compiler |
|
213 |
compile:oldMethod source |
|
214 |
forClass:class |
|
215 |
inCategory:oldMethod category |
|
216 |
notifying:nil |
|
217 |
install:false |
|
218 |
skipIfSame:false |
|
219 |
silent:true |
|
220 |
foldConstants:true |
|
221 |
ifFail:[ Transcript showCR:'failed to recompile for breakpoint' ]. |
|
222 |
newMethod originalMethod: oldMethod. |
|
12262 | 223 |
|
12287 | 224 |
selector isNil ifTrue:[ |
225 |
"/ May happen as the selector is not stored in the method but |
|
226 |
"/ searches through method's mclass methodDictionary. |
|
227 |
"/ Following should be save as breakpoint is not installed when |
|
228 |
"/ the code is modified... |
|
229 |
selector := compiler selector. |
|
230 |
]. |
|
231 |
||
232 |
(class primAddSelector: selector withMethod:newMethod) ifFalse:[ |
|
233 |
self breakPoint: #cg. |
|
234 |
self breakPoint: #jv. |
|
235 |
^ self |
|
236 |
]. |
|
237 |
codeView methodHolder value:newMethod. |
|
238 |
oldMethod mclass isNil ifTrue:[ |
|
239 |
oldMethod mclass:class. |
|
240 |
]. |
|
241 |
]. |
|
12261
b2a507f45d87
- Tools::ChangeSetBrowser2
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12255
diff
changeset
|
242 |
"/ self halt. |
12287 | 243 |
breakpoints := breakpoints |
244 |
select:[:bp | |
|
245 |
bp isReached ifFalse:[ Transcript show:'remove unreached:'; showCR:bp ]. |
|
246 |
bp isReached |
|
247 |
] |
|
248 |
] |
|
10182 | 249 |
] |
250 |
||
251 |
"Created: / 05-07-2011 / 21:33:13 / cg" |
|
12261
b2a507f45d87
- Tools::ChangeSetBrowser2
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12255
diff
changeset
|
252 |
"Modified: / 18-07-2012 / 10:53:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
12287 | 253 |
"Modified: / 02-08-2012 / 09:35:41 / cg" |
9982 | 254 |
! |
255 |
||
12262 | 256 |
setOrToggleBreakpointAtLine:line |
9982 | 257 |
|pos bpnt| |
258 |
||
259 |
pos := textView characterPositionOfLine:line col:1. |
|
260 |
bpnt := self breakpointAtLine:line. |
|
10182 | 261 |
bpnt isNil ifTrue:[ |
12287 | 262 |
(codeView topView class ~~ DebugView) ifTrue:[ |
263 |
breakpoints add:((bpnt := Breakpoint new) position:pos line:line). |
|
264 |
Display shiftDown ifTrue:[ |
|
265 |
"/ trace |
|
266 |
bpnt beTracepoint |
|
267 |
]. |
|
268 |
self recompile. |
|
269 |
]. |
|
10182 | 270 |
] ifFalse:[ |
12287 | 271 |
Display shiftDown ifTrue:[ |
272 |
bpnt toggleTracing |
|
273 |
] ifFalse:[ |
|
274 |
bpnt toggle. |
|
275 |
] |
|
10182 | 276 |
]. |
9982 | 277 |
gutterView redrawLine:line. |
278 |
||
279 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10411 | 280 |
"Modified: / 27-07-2011 / 13:27:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
12287 | 281 |
"Modified: / 02-08-2012 / 09:26:38 / cg" |
9982 | 282 |
! ! |
283 |
||
284 |
!BreakpointService methodsFor:'redrawing'! |
|
285 |
||
12262 | 286 |
drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg |
9982 | 287 |
"Called by both gutterView and textView (well, not yet) to |
288 |
allow services to draw custom things on text view. |
|
289 |
Ask JV what the args means if unsure (I'm lazy to document |
|
290 |
them, now it is just an experiment...)" |
|
12262 | 291 |
|
12261
b2a507f45d87
- Tools::ChangeSetBrowser2
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12255
diff
changeset
|
292 |
|bpnt icon dx dy| |
9982 | 293 |
|
10182 | 294 |
codeView methodHolder value isNil ifTrue:[ |
12262 | 295 |
^ self |
10182 | 296 |
]. |
297 |
view == gutterView ifTrue:[ |
|
12262 | 298 |
bpnt := self breakpointAtLine:lineNo. |
299 |
bpnt isNil ifTrue:[ |
|
300 |
^ self |
|
301 |
]. |
|
302 |
icon := bpnt icon. |
|
303 |
icon isNil ifTrue:[ |
|
304 |
^ self |
|
305 |
]. |
|
306 |
dx := ((w - icon width) / 2) rounded. |
|
307 |
dy := ((h - icon height) / 2) rounded. |
|
308 |
icon |
|
309 |
displayOn:view |
|
310 |
x:x + dx |
|
311 |
y:y - h + dy + 4. "TODO: Magic constant" |
|
9982 | 312 |
]. |
313 |
||
314 |
"Created: / 17-06-2011 / 13:52:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10182 | 315 |
"Modified (format): / 05-07-2011 / 22:14:33 / cg" |
9982 | 316 |
! ! |
317 |
||
318 |
!BreakpointService class methodsFor:'documentation'! |
|
319 |
||
12262 | 320 |
version_CVS |
12287 | 321 |
^ '§Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.16 2012/08/02 12:47:48 cg Exp §' |
12262 | 322 |
|
9982 | 323 |
! |
324 |
||
325 |
version_SVN |
|
12287 | 326 |
^ '$Id: Tools__BreakpointService.st 8048 2012-09-07 17:28:09Z vranyj1 $' |
12125 | 327 |
! ! |