ruby-breakpoint 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +56 -0
- data/GPL +340 -0
- data/Manifest +35 -0
- data/NEWS +18 -0
- data/README +43 -0
- data/TODO +31 -0
- data/bin/breakpoint_client +214 -0
- data/doc/classes/Binding.html +221 -0
- data/doc/classes/Breakpoint.html +540 -0
- data/doc/classes/Breakpoint/CommandBundle.html +207 -0
- data/doc/classes/Breakpoint/CommandBundle/Client.html +201 -0
- data/doc/classes/Breakpoint/FailedAssertError.html +118 -0
- data/doc/created.rid +1 -0
- data/doc/files/COPYING.html +163 -0
- data/doc/files/NEWS.html +135 -0
- data/doc/files/README.html +154 -0
- data/doc/files/TODO.html +162 -0
- data/doc/files/lib/binding_of_caller_rb.html +101 -0
- data/doc/files/lib/breakpoint_rb.html +202 -0
- data/doc/fr_class_index.html +31 -0
- data/doc/fr_file_index.html +32 -0
- data/doc/fr_method_index.html +38 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/binding_of_caller.rb +80 -0
- data/lib/breakpoint.rb +547 -0
- data/setup.rb +1360 -0
- metadata +82 -0
@@ -0,0 +1,540 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Breakpoint</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Breakpoint</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/breakpoint_rb.html">
|
59
|
+
lib/breakpoint.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
<div id="method-list">
|
80
|
+
<h3 class="section-bar">Methods</h3>
|
81
|
+
|
82
|
+
<div class="name-list">
|
83
|
+
<a href="#M000006">activate_drb</a>
|
84
|
+
<a href="#M000005">assert</a>
|
85
|
+
<a href="#M000004">breakpoint</a>
|
86
|
+
<a href="#M000007">deactivate_drb</a>
|
87
|
+
<a href="#M000008">use_drb?</a>
|
88
|
+
</div>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
|
94
|
+
<!-- if includes -->
|
95
|
+
|
96
|
+
<div id="section">
|
97
|
+
|
98
|
+
<div id="class-list">
|
99
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
100
|
+
|
101
|
+
Module <a href="Breakpoint/CommandBundle.html" class="link">Breakpoint::CommandBundle</a><br />
|
102
|
+
Class <a href="Breakpoint/FailedAssertError.html" class="link">Breakpoint::FailedAssertError</a><br />
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<div id="constants-list">
|
107
|
+
<h3 class="section-bar">Constants</h3>
|
108
|
+
|
109
|
+
<div class="name-list">
|
110
|
+
<table summary="Constants">
|
111
|
+
<tr class="top-aligned-row context-row">
|
112
|
+
<td class="context-item-name">Version</td>
|
113
|
+
<td>=</td>
|
114
|
+
<td class="context-item-value">current_version</td>
|
115
|
+
<td width="3em"> </td>
|
116
|
+
<td class="context-item-desc">
|
117
|
+
The Version of ruby-breakpoint you are using as String of the 1.2.3 form
|
118
|
+
where the digits stand for release, major and minor version respectively.
|
119
|
+
|
120
|
+
</td>
|
121
|
+
</tr>
|
122
|
+
</table>
|
123
|
+
</div>
|
124
|
+
</div>
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
<div id="attribute-list">
|
129
|
+
<h3 class="section-bar">Attributes</h3>
|
130
|
+
|
131
|
+
<div class="name-list">
|
132
|
+
<table>
|
133
|
+
<tr class="top-aligned-row context-row">
|
134
|
+
<td class="context-item-name">asserts_cause_exceptions</td>
|
135
|
+
<td class="context-item-value"> [RW] </td>
|
136
|
+
<td class="context-item-desc">
|
137
|
+
Whether an Exception should be raised on failed asserts in non-$DEBUG code
|
138
|
+
or not. By default this is disabled.
|
139
|
+
|
140
|
+
</td>
|
141
|
+
</tr>
|
142
|
+
<tr class="top-aligned-row context-row">
|
143
|
+
<td class="context-item-name">optimize_asserts</td>
|
144
|
+
<td class="context-item-value"> [RW] </td>
|
145
|
+
<td class="context-item-desc">
|
146
|
+
Whether asserts should be ignored if not in debug mode. Debug mode can be
|
147
|
+
enabled by running ruby with the -d switch or by setting $DEBUG to true.
|
148
|
+
|
149
|
+
</td>
|
150
|
+
</tr>
|
151
|
+
</table>
|
152
|
+
</div>
|
153
|
+
</div>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
<!-- if method_list -->
|
158
|
+
<div id="methods">
|
159
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
160
|
+
|
161
|
+
<div id="method-M000006" class="method-detail">
|
162
|
+
<a name="M000006"></a>
|
163
|
+
|
164
|
+
<div class="method-heading">
|
165
|
+
<a href="#M000006" class="method-signature">
|
166
|
+
<span class="method-name">activate_drb</span><span class="method-args">(uri = nil, allowed_hosts = ['localhost', '127.0.0.1', '::1'], ignore_collisions = false)</span>
|
167
|
+
</a>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div class="method-description">
|
171
|
+
<p>
|
172
|
+
Will run <a href="Breakpoint.html">Breakpoint</a> in DRb mode. This will
|
173
|
+
spawn a server that can be attached to via the breakpoint-client command
|
174
|
+
whenever a breakpoint is executed. This is useful when you are debugging
|
175
|
+
CGI applications or other applications where you can’t access debug
|
176
|
+
sessions via the standard input and output of your application.
|
177
|
+
</p>
|
178
|
+
<p>
|
179
|
+
You can specify an URI where the DRb server will run at. This way you can
|
180
|
+
specify the port the server runs on. The default URI is
|
181
|
+
druby://localhost:42531.
|
182
|
+
</p>
|
183
|
+
<p>
|
184
|
+
Please note that breakpoints will be skipped silently in case the DRb
|
185
|
+
server can not spawned. (This can happen if the port is already used by
|
186
|
+
another instance of your application on CGI or another application.)
|
187
|
+
</p>
|
188
|
+
<p>
|
189
|
+
Also note that by default this will only allow access from localhost. You
|
190
|
+
can however specify a list of allowed hosts or nil (to allow access from
|
191
|
+
everywhere). But that will still not protect you from somebody reading the
|
192
|
+
data as it goes through the net.
|
193
|
+
</p>
|
194
|
+
<p>
|
195
|
+
A good approach for getting security and remote access is setting up an SSH
|
196
|
+
tunnel between the DRb service and the client. This is usually done like
|
197
|
+
this:
|
198
|
+
</p>
|
199
|
+
<p>
|
200
|
+
$ ssh -L20000:127.0.0.1:20000 -R10000:127.0.0.1:10000 example.com (This
|
201
|
+
will connect port 20000 at the client side to port 20000 at the server
|
202
|
+
side, and port 10000 at the server side to port 10000 at the client side.)
|
203
|
+
</p>
|
204
|
+
<p>
|
205
|
+
After that do this on the server side: (the code being debugged) <a
|
206
|
+
href="Breakpoint.html#M000006">Breakpoint.activate_drb</a>("druby://127.0.0.1:20000",
|
207
|
+
"localhost")
|
208
|
+
</p>
|
209
|
+
<p>
|
210
|
+
And at the client side: ruby breakpoint_client.rb -c
|
211
|
+
druby://127.0.0.1:10000 -s druby://127.0.0.1:20000
|
212
|
+
</p>
|
213
|
+
<p>
|
214
|
+
Running through such a SSH proxy will also let you use breakpoint.rb in
|
215
|
+
case you are behind a firewall.
|
216
|
+
</p>
|
217
|
+
<p>
|
218
|
+
Detailed information about running DRb through firewalls is available at <a
|
219
|
+
href="http://www.rubygarden.org/ruby?DrbTutorial">www.rubygarden.org/ruby?DrbTutorial</a>
|
220
|
+
</p>
|
221
|
+
<h2>Security considerations</h2>
|
222
|
+
<p>
|
223
|
+
Usually you will be fine when using the default druby:// URI and the
|
224
|
+
default access control list. However, if you are sitting on a machine where
|
225
|
+
there are local users that you likely can not trust (this is the case for
|
226
|
+
example on most web hosts which have multiple users sitting on the same
|
227
|
+
physical machine) you will be better off by doing client/server
|
228
|
+
communication through a unix socket. This can be accomplished by calling
|
229
|
+
with a drbunix:/ style URI, e.g. <tt><a
|
230
|
+
href="Breakpoint.html#M000006">Breakpoint.activate_drb</a>(‘drbunix:/tmp/breakpoint_server’)</tt>.
|
231
|
+
This will only work on Unix based platforms.
|
232
|
+
</p>
|
233
|
+
<p><a class="source-toggle" href="#"
|
234
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
235
|
+
<div class="method-source-code" id="M000006-source">
|
236
|
+
<pre>
|
237
|
+
<span class="ruby-comment cmt"># File lib/breakpoint.rb, line 374</span>
|
238
|
+
374: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate_drb</span>(<span class="ruby-identifier">uri</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">allowed_hosts</span> = [<span class="ruby-value str">'localhost'</span>, <span class="ruby-value str">'127.0.0.1'</span>, <span class="ruby-value str">'::1'</span>],
|
239
|
+
375: <span class="ruby-identifier">ignore_collisions</span> = <span class="ruby-keyword kw">false</span>)
|
240
|
+
376:
|
241
|
+
377: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@use_drb</span>
|
242
|
+
378:
|
243
|
+
379: <span class="ruby-identifier">uri</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'druby://localhost:42531'</span>
|
244
|
+
380:
|
245
|
+
381: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">allowed_hosts</span> <span class="ruby-keyword kw">then</span>
|
246
|
+
382: <span class="ruby-identifier">acl</span> = [<span class="ruby-value str">"deny"</span>, <span class="ruby-value str">"all"</span>]
|
247
|
+
383:
|
248
|
+
384: <span class="ruby-constant">Array</span>(<span class="ruby-identifier">allowed_hosts</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">host</span><span class="ruby-operator">|</span>
|
249
|
+
385: <span class="ruby-identifier">acl</span> <span class="ruby-operator">+=</span> [<span class="ruby-value str">"allow"</span>, <span class="ruby-identifier">host</span>]
|
250
|
+
386: <span class="ruby-keyword kw">end</span>
|
251
|
+
387:
|
252
|
+
388: <span class="ruby-constant">DRb</span>.<span class="ruby-identifier">install_acl</span>(<span class="ruby-constant">ACL</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">acl</span>))
|
253
|
+
389: <span class="ruby-keyword kw">end</span>
|
254
|
+
390:
|
255
|
+
391: <span class="ruby-ivar">@use_drb</span> = <span class="ruby-keyword kw">true</span>
|
256
|
+
392: <span class="ruby-ivar">@drb_service</span> = <span class="ruby-constant">DRbService</span>.<span class="ruby-identifier">new</span>
|
257
|
+
393: <span class="ruby-identifier">did_collision</span> = <span class="ruby-keyword kw">false</span>
|
258
|
+
394: <span class="ruby-keyword kw">begin</span>
|
259
|
+
395: <span class="ruby-ivar">@service</span> = <span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-ivar">@drb_service</span>)
|
260
|
+
396: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span>
|
261
|
+
397: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ignore_collisions</span> <span class="ruby-keyword kw">then</span>
|
262
|
+
398: <span class="ruby-keyword kw">nil</span>
|
263
|
+
399: <span class="ruby-keyword kw">else</span>
|
264
|
+
400: <span class="ruby-comment cmt"># The port is already occupied by another</span>
|
265
|
+
401: <span class="ruby-comment cmt"># Breakpoint service. We will try to tell</span>
|
266
|
+
402: <span class="ruby-comment cmt"># the old service that we want its port.</span>
|
267
|
+
403: <span class="ruby-comment cmt"># It will then forward that request to the</span>
|
268
|
+
404: <span class="ruby-comment cmt"># user and retry.</span>
|
269
|
+
405: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">did_collision</span> <span class="ruby-keyword kw">then</span>
|
270
|
+
406: <span class="ruby-constant">DRbObject</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">uri</span>).<span class="ruby-identifier">collision</span>
|
271
|
+
407: <span class="ruby-identifier">did_collision</span> = <span class="ruby-keyword kw">true</span>
|
272
|
+
408: <span class="ruby-keyword kw">end</span>
|
273
|
+
409: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">10</span>)
|
274
|
+
410: <span class="ruby-keyword kw">retry</span>
|
275
|
+
411: <span class="ruby-keyword kw">end</span>
|
276
|
+
412: <span class="ruby-keyword kw">end</span>
|
277
|
+
413:
|
278
|
+
414: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
279
|
+
415: <span class="ruby-keyword kw">end</span>
|
280
|
+
</pre>
|
281
|
+
</div>
|
282
|
+
</div>
|
283
|
+
</div>
|
284
|
+
|
285
|
+
<div id="method-M000005" class="method-detail">
|
286
|
+
<a name="M000005"></a>
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
<a href="#M000005" class="method-signature">
|
290
|
+
<span class="method-name">assert</span><span class="method-args">(context = nil) {|| ...}</span>
|
291
|
+
</a>
|
292
|
+
</div>
|
293
|
+
|
294
|
+
<div class="method-description">
|
295
|
+
<p>
|
296
|
+
This asserts that the block evaluates to true. If it doesn’t evaluate
|
297
|
+
to true a breakpoint will automatically be created at that execution point.
|
298
|
+
</p>
|
299
|
+
<p>
|
300
|
+
You can disable assert checking in production code by setting
|
301
|
+
Breakpoint.optimize_asserts to true. (It will still be enabled when Ruby is
|
302
|
+
run via the -d argument.)
|
303
|
+
</p>
|
304
|
+
<p>
|
305
|
+
Example:
|
306
|
+
</p>
|
307
|
+
<pre>
|
308
|
+
person_name = "Foobar"
|
309
|
+
assert { not person_name.nil? }
|
310
|
+
</pre>
|
311
|
+
<p>
|
312
|
+
Note: If you want to use this method from an unit test, you will have to
|
313
|
+
call it by its full name, <a
|
314
|
+
href="Breakpoint.html#M000005">Breakpoint.assert</a>.
|
315
|
+
</p>
|
316
|
+
<p><a class="source-toggle" href="#"
|
317
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
318
|
+
<div class="method-source-code" id="M000005-source">
|
319
|
+
<pre>
|
320
|
+
<span class="ruby-comment cmt"># File lib/breakpoint.rb, line 248</span>
|
321
|
+
248: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert</span>(<span class="ruby-identifier">context</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">condition</span>)
|
322
|
+
249: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Breakpoint</span>.<span class="ruby-identifier">optimize_asserts</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">$DEBUG</span>
|
323
|
+
250: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">yield</span>
|
324
|
+
251:
|
325
|
+
252: <span class="ruby-identifier">callstack</span> = <span class="ruby-identifier">caller</span>
|
326
|
+
253: <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>, <span class="ruby-value">3</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">first</span>[<span class="ruby-value str">"assert"</span>]
|
327
|
+
254: <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span> = <span class="ruby-operator">*</span><span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^(.+?):(\d+)(?::in `(.*?)')?/</span>).<span class="ruby-identifier">captures</span>
|
328
|
+
255:
|
329
|
+
256: <span class="ruby-identifier">message</span> = <span class="ruby-node">"Assert failed at #{file}:#{line}#{" in `#{method}'" if method}."</span>
|
330
|
+
257:
|
331
|
+
258: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Breakpoint</span>.<span class="ruby-identifier">asserts_cause_exceptions</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">$DEBUG</span> <span class="ruby-keyword kw">then</span>
|
332
|
+
259: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">Breakpoint</span><span class="ruby-operator">::</span><span class="ruby-constant">FailedAssertError</span>, <span class="ruby-identifier">message</span>)
|
333
|
+
260: <span class="ruby-keyword kw">end</span>
|
334
|
+
261:
|
335
|
+
262: <span class="ruby-identifier">message</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">" Executing implicit breakpoint."</span>
|
336
|
+
263:
|
337
|
+
264: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span> <span class="ruby-keyword kw">then</span>
|
338
|
+
265: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">handle_breakpoint</span>(<span class="ruby-identifier">context</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>)
|
339
|
+
266: <span class="ruby-keyword kw">end</span>
|
340
|
+
267:
|
341
|
+
268: <span class="ruby-constant">Binding</span>.<span class="ruby-identifier">of_caller</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">context</span><span class="ruby-operator">|</span>
|
342
|
+
269: <span class="ruby-identifier">handle_breakpoint</span>(<span class="ruby-identifier">context</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>)
|
343
|
+
270: <span class="ruby-keyword kw">end</span>
|
344
|
+
271: <span class="ruby-keyword kw">end</span>
|
345
|
+
</pre>
|
346
|
+
</div>
|
347
|
+
</div>
|
348
|
+
</div>
|
349
|
+
|
350
|
+
<div id="method-M000004" class="method-detail">
|
351
|
+
<a name="M000004"></a>
|
352
|
+
|
353
|
+
<div class="method-heading">
|
354
|
+
<a href="#M000004" class="method-signature">
|
355
|
+
<span class="method-name">breakpoint</span><span class="method-args">(id = nil, context = nil, &block)</span>
|
356
|
+
</a>
|
357
|
+
</div>
|
358
|
+
|
359
|
+
<div class="method-description">
|
360
|
+
<p>
|
361
|
+
This will pop up an interactive ruby session at a pre-defined break point
|
362
|
+
in a Ruby application. In this session you can examine the environment of
|
363
|
+
the break point.
|
364
|
+
</p>
|
365
|
+
<p>
|
366
|
+
You can get a list of variables in the context using local_variables via
|
367
|
+
<tt>local_variables</tt>. You can then examine their values by typing their
|
368
|
+
names.
|
369
|
+
</p>
|
370
|
+
<p>
|
371
|
+
You can have a look at the call stack via <tt>caller</tt>.
|
372
|
+
</p>
|
373
|
+
<p>
|
374
|
+
The source code around the location where the breakpoint was executed can
|
375
|
+
be examined via <tt>source_lines</tt>. Its argument specifies how much
|
376
|
+
lines of context to display. The default amount of context is 5 lines. Note
|
377
|
+
that the call to <tt>source_lines</tt> can raise an exception when it
|
378
|
+
isn’t able to read in the source code.
|
379
|
+
</p>
|
380
|
+
<p>
|
381
|
+
breakpoints can also return a value. They will execute a supplied block for
|
382
|
+
getting a default return value. A custom value can be returned from the
|
383
|
+
session by doing +throw(:debug_return, value)+.
|
384
|
+
</p>
|
385
|
+
<p>
|
386
|
+
You can also give names to break points which will be used in the message
|
387
|
+
that is displayed upon execution of them.
|
388
|
+
</p>
|
389
|
+
<p>
|
390
|
+
Here’s a sample of how breakpoints should be placed:
|
391
|
+
</p>
|
392
|
+
<pre>
|
393
|
+
class Person
|
394
|
+
def initialize(name, age)
|
395
|
+
@name, @age = name, age
|
396
|
+
breakpoint("Person#initialize")
|
397
|
+
end
|
398
|
+
|
399
|
+
attr_reader :age
|
400
|
+
def name
|
401
|
+
breakpoint("Person#name") { @name }
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
person = Person.new("Random Person", 23)
|
406
|
+
puts "Name: #{person.name}"
|
407
|
+
</pre>
|
408
|
+
<p>
|
409
|
+
And here is a sample debug session:
|
410
|
+
</p>
|
411
|
+
<pre>
|
412
|
+
Executing break point "Person#initialize" at file.rb:4 in `initialize'
|
413
|
+
irb(#<Person:0x292fbe8>):001:0> local_variables
|
414
|
+
=> ["name", "age", "_", "__"]
|
415
|
+
irb(#<Person:0x292fbe8>):002:0> [name, age]
|
416
|
+
=> ["Random Person", 23]
|
417
|
+
irb(#<Person:0x292fbe8>):003:0> [@name, @age]
|
418
|
+
=> ["Random Person", 23]
|
419
|
+
irb(#<Person:0x292fbe8>):004:0> self
|
420
|
+
=> #<Person:0x292fbe8 @age=23, @name="Random Person">
|
421
|
+
irb(#<Person:0x292fbe8>):005:0> @age += 1; self
|
422
|
+
=> #<Person:0x292fbe8 @age=24, @name="Random Person">
|
423
|
+
irb(#<Person:0x292fbe8>):006:0> exit
|
424
|
+
Executing break point "Person#name" at file.rb:9 in `name'
|
425
|
+
irb(#<Person:0x292fbe8>):001:0> throw(:debug_return, "Overriden name")
|
426
|
+
Name: Overriden name
|
427
|
+
</pre>
|
428
|
+
<p>
|
429
|
+
<a href="Breakpoint.html">Breakpoint</a> sessions will automatically have a
|
430
|
+
few convenience methods available. See <a
|
431
|
+
href="Breakpoint/CommandBundle.html">Breakpoint::CommandBundle</a> for a
|
432
|
+
list of them.
|
433
|
+
</p>
|
434
|
+
<p>
|
435
|
+
Breakpoints can also be used remotely over sockets. This is implemented by
|
436
|
+
running part of the IRB session in the application and part of it in a
|
437
|
+
special client. You have to call <a
|
438
|
+
href="Breakpoint.html#M000006">Breakpoint.activate_drb</a> to enable
|
439
|
+
support for remote breakpoints and then run breakpoint_client.rb which is
|
440
|
+
distributed with this library. See the documentation of <a
|
441
|
+
href="Breakpoint.html#M000006">Breakpoint.activate_drb</a> for details.
|
442
|
+
</p>
|
443
|
+
<p><a class="source-toggle" href="#"
|
444
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
445
|
+
<div class="method-source-code" id="M000004-source">
|
446
|
+
<pre>
|
447
|
+
<span class="ruby-comment cmt"># File lib/breakpoint.rb, line 110</span>
|
448
|
+
110: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">breakpoint</span>(<span class="ruby-identifier">id</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">context</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
449
|
+
111: <span class="ruby-identifier">callstack</span> = <span class="ruby-identifier">caller</span>
|
450
|
+
112: <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>, <span class="ruby-value">3</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">first</span>[<span class="ruby-value str">"breakpoint"</span>]
|
451
|
+
113: <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span> = <span class="ruby-operator">*</span><span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^(.+?):(\d+)(?::in `(.*?)')?/</span>).<span class="ruby-identifier">captures</span>
|
452
|
+
114:
|
453
|
+
115: <span class="ruby-identifier">message</span> = <span class="ruby-value str">"Executing break point "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">id</span> <span class="ruby-value">? </span><span class="ruby-node">"#{id.inspect} "</span> <span class="ruby-operator">:</span> <span class="ruby-value str">""</span>) <span class="ruby-operator">+</span>
|
454
|
+
116: <span class="ruby-node">"at #{file}:#{line}"</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">method</span> <span class="ruby-value">? </span><span class="ruby-node">" in `#{method}'"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">""</span>)
|
455
|
+
117:
|
456
|
+
118: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">context</span> <span class="ruby-keyword kw">then</span>
|
457
|
+
119: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">handle_breakpoint</span>(<span class="ruby-identifier">context</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
458
|
+
120: <span class="ruby-keyword kw">end</span>
|
459
|
+
121:
|
460
|
+
122: <span class="ruby-constant">Binding</span>.<span class="ruby-identifier">of_caller</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">binding_context</span><span class="ruby-operator">|</span>
|
461
|
+
123: <span class="ruby-identifier">handle_breakpoint</span>(<span class="ruby-identifier">binding_context</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
462
|
+
124: <span class="ruby-keyword kw">end</span>
|
463
|
+
125: <span class="ruby-keyword kw">end</span>
|
464
|
+
</pre>
|
465
|
+
</div>
|
466
|
+
</div>
|
467
|
+
</div>
|
468
|
+
|
469
|
+
<div id="method-M000007" class="method-detail">
|
470
|
+
<a name="M000007"></a>
|
471
|
+
|
472
|
+
<div class="method-heading">
|
473
|
+
<a href="#M000007" class="method-signature">
|
474
|
+
<span class="method-name">deactivate_drb</span><span class="method-args">()</span>
|
475
|
+
</a>
|
476
|
+
</div>
|
477
|
+
|
478
|
+
<div class="method-description">
|
479
|
+
<p>
|
480
|
+
Deactivates a running <a href="Breakpoint.html">Breakpoint</a> service.
|
481
|
+
</p>
|
482
|
+
<p><a class="source-toggle" href="#"
|
483
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
484
|
+
<div class="method-source-code" id="M000007-source">
|
485
|
+
<pre>
|
486
|
+
<span class="ruby-comment cmt"># File lib/breakpoint.rb, line 418</span>
|
487
|
+
418: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deactivate_drb</span>
|
488
|
+
419: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">exclusive</span> <span class="ruby-keyword kw">do</span>
|
489
|
+
420: <span class="ruby-ivar">@service</span>.<span class="ruby-identifier">stop_service</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@service</span>.<span class="ruby-identifier">nil?</span>
|
490
|
+
421: <span class="ruby-ivar">@service</span> = <span class="ruby-keyword kw">nil</span>
|
491
|
+
422: <span class="ruby-ivar">@use_drb</span> = <span class="ruby-keyword kw">false</span>
|
492
|
+
423: <span class="ruby-ivar">@drb_service</span> = <span class="ruby-keyword kw">nil</span>
|
493
|
+
424: <span class="ruby-keyword kw">end</span>
|
494
|
+
425: <span class="ruby-keyword kw">end</span>
|
495
|
+
</pre>
|
496
|
+
</div>
|
497
|
+
</div>
|
498
|
+
</div>
|
499
|
+
|
500
|
+
<div id="method-M000008" class="method-detail">
|
501
|
+
<a name="M000008"></a>
|
502
|
+
|
503
|
+
<div class="method-heading">
|
504
|
+
<a href="#M000008" class="method-signature">
|
505
|
+
<span class="method-name">use_drb?</span><span class="method-args">()</span>
|
506
|
+
</a>
|
507
|
+
</div>
|
508
|
+
|
509
|
+
<div class="method-description">
|
510
|
+
<p>
|
511
|
+
Returns true when Breakpoints are used over DRb. <a
|
512
|
+
href="Breakpoint.html#M000006">Breakpoint.activate_drb</a> causes this to
|
513
|
+
be true.
|
514
|
+
</p>
|
515
|
+
<p><a class="source-toggle" href="#"
|
516
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
517
|
+
<div class="method-source-code" id="M000008-source">
|
518
|
+
<pre>
|
519
|
+
<span class="ruby-comment cmt"># File lib/breakpoint.rb, line 429</span>
|
520
|
+
429: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_drb?</span>
|
521
|
+
430: <span class="ruby-ivar">@use_drb</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
|
522
|
+
431: <span class="ruby-keyword kw">end</span>
|
523
|
+
</pre>
|
524
|
+
</div>
|
525
|
+
</div>
|
526
|
+
</div>
|
527
|
+
|
528
|
+
|
529
|
+
</div>
|
530
|
+
|
531
|
+
|
532
|
+
</div>
|
533
|
+
|
534
|
+
|
535
|
+
<div id="validator-badges">
|
536
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
537
|
+
</div>
|
538
|
+
|
539
|
+
</body>
|
540
|
+
</html>
|