byebug 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/byebug/command.rb +20 -34
- data/lib/byebug/commands/breakpoints.rb +1 -1
- data/lib/byebug/commands/catchpoint.rb +1 -1
- data/lib/byebug/commands/display.rb +1 -1
- data/lib/byebug/commands/enable.rb +24 -26
- data/lib/byebug/commands/eval.rb +20 -4
- data/lib/byebug/commands/info.rb +43 -42
- data/lib/byebug/commands/method.rb +2 -2
- data/lib/byebug/commands/set.rb +42 -44
- data/lib/byebug/commands/show.rb +42 -37
- data/lib/byebug/commands/trace.rb +1 -1
- data/lib/byebug/commands/variables.rb +7 -7
- data/lib/byebug/remote.rb +4 -0
- data/lib/byebug/version.rb +1 -1
- data/{old_doc → test/examples}/gcd.rb +0 -0
- data/{old_doc → test/examples}/hanoi.rb +0 -0
- data/{old_doc → test/examples}/primes.rb +0 -0
- data/{old_doc → test/examples}/test-triangle.rb +0 -0
- data/{old_doc → test/examples}/tri3.rb +0 -0
- data/{old_doc → test/examples}/triangle.rb +0 -0
- data/test/help_test.rb +2 -5
- metadata +15 -11
- data/old_doc/byebug.1 +0 -196
- data/old_doc/byebug.texi +0 -3259
data/old_doc/byebug.texi
DELETED
@@ -1,3259 +0,0 @@
|
|
1
|
-
\input texinfo
|
2
|
-
@setfilename byebug.info
|
3
|
-
|
4
|
-
@set BYEBUG_VERSION 1.8.2
|
5
|
-
@set UPDATED Aug-2013
|
6
|
-
|
7
|
-
@macro Example {}
|
8
|
-
@iftex
|
9
|
-
@cartouche
|
10
|
-
@end iftex
|
11
|
-
@smallexample
|
12
|
-
@end macro
|
13
|
-
|
14
|
-
@macro EndExample {}
|
15
|
-
@iftex
|
16
|
-
@end cartouche
|
17
|
-
@end iftex
|
18
|
-
@end smallexample
|
19
|
-
@end macro
|
20
|
-
|
21
|
-
@c How to show optional variables.
|
22
|
-
@macro ovar{varname}
|
23
|
-
@r{[}@var{\varname\}@r{]}
|
24
|
-
@end macro
|
25
|
-
|
26
|
-
@settitle Byebug
|
27
|
-
@setchapternewpage odd
|
28
|
-
@c %**end of header
|
29
|
-
|
30
|
-
@finalout
|
31
|
-
|
32
|
-
@c This is a dir.info fragment to support semi-automated addition of
|
33
|
-
@c manuals to an info tree.
|
34
|
-
@dircategory Programming & development tools.
|
35
|
-
@direntry
|
36
|
-
* byebug: (byebug). Ruby Byebug
|
37
|
-
@end direntry
|
38
|
-
|
39
|
-
@titlepage
|
40
|
-
@title Debugging with @code{byebug}
|
41
|
-
@sp 1
|
42
|
-
@subtitle @value{BYEBUG_VERSION} Edition
|
43
|
-
@subtitle @value{UPDATED-MONTH}
|
44
|
-
@author David Rodríguez, Rocky Bernstein, Kent Sibilev, and Mark Moseley
|
45
|
-
@page
|
46
|
-
@end titlepage
|
47
|
-
@page
|
48
|
-
|
49
|
-
@ifnottex
|
50
|
-
@node Top, Summary, (dir), (dir)
|
51
|
-
@top Debugging with byebug
|
52
|
-
|
53
|
-
This file describes Byebug, a Ruby 2.0 debugger, version @value{BYEBUG_VERSION}
|
54
|
-
|
55
|
-
Last updated: @value{UPDATED}
|
56
|
-
@c Copyleft (U+0254) 2013
|
57
|
-
|
58
|
-
@menu
|
59
|
-
* Summary:: Overview of Byebug with sample sessions
|
60
|
-
* Invocation:: Getting in and out
|
61
|
-
* Byebug Command Reference:: Byebug's commands
|
62
|
-
* Post-Mortem Debugging:: Debugging on an uncaught exception
|
63
|
-
* Byebug Module and Class:: Byebug's module and class
|
64
|
-
|
65
|
-
Appendix
|
66
|
-
* Contributing::
|
67
|
-
|
68
|
-
Indexes
|
69
|
-
* Class Module Method Index:: An item for each Class, Module and Method.
|
70
|
-
* Command Index:: An item for each command name.
|
71
|
-
* General Index:: An item for each concept.
|
72
|
-
@end menu
|
73
|
-
|
74
|
-
@end ifnottex
|
75
|
-
|
76
|
-
@contents
|
77
|
-
|
78
|
-
@node Summary
|
79
|
-
@chapter Summary of @code{byebug}
|
80
|
-
|
81
|
-
The purpose of a debugger such as @code{byebug} is to allow you to see what is
|
82
|
-
going on ``inside'' a Ruby program while it executes. @code{byebug} can do four
|
83
|
-
main kinds of things (plus other things in support of these) to help you catch
|
84
|
-
bugs in the act:
|
85
|
-
|
86
|
-
@itemize @bullet
|
87
|
-
@item
|
88
|
-
Start your script, specifying anything that might affect its behavior.
|
89
|
-
|
90
|
-
@item
|
91
|
-
Make your script stop on specified conditions.
|
92
|
-
|
93
|
-
@item
|
94
|
-
Examine what has happened, when your script has stopped.
|
95
|
-
|
96
|
-
@item
|
97
|
-
Change things in your script, so you can experiment with correcting the effects
|
98
|
-
of one bug and go on to learn about another.
|
99
|
-
@end itemize
|
100
|
-
|
101
|
-
Although you can use @code{byebug} to invoke your Ruby programs via a debugger
|
102
|
-
at the outset, there are other ways to use and enter the debugger.
|
103
|
-
|
104
|
-
@menu
|
105
|
-
* First Sample Session:: @code{display}, @code{print}, @code{quit}
|
106
|
-
* Second Sample Session:: @code{where}, @code{frame}, @code{restart}, @code{autoeval}, @code{break}, @code{ps}
|
107
|
-
* Unit Testing Session:: Using byebug in unit testing
|
108
|
-
* Byebug.start with a block:: Using the Byebug.start with a block
|
109
|
-
* Debugging Oddities:: How debugging Ruby may be different...
|
110
|
-
@end menu
|
111
|
-
|
112
|
-
@node First Sample Session
|
113
|
-
@section First Sample Session
|
114
|
-
|
115
|
-
You can use this manual at your leisure to read all about @code{byebug}.
|
116
|
-
However, a handful of commands are enough to get started using byebug. The
|
117
|
-
following sections illustrates these commands.
|
118
|
-
|
119
|
-
@iftex
|
120
|
-
In this sample session, we emphasize user input like this: @b{input}, to make it
|
121
|
-
easier to pick out from the surrounding output.
|
122
|
-
@end iftex
|
123
|
-
|
124
|
-
Below is Ruby code to compute a triangle number of a given length.
|
125
|
-
@footnote{There are of course shorter ways to define @code{triangle} such as:
|
126
|
-
@smallexample
|
127
|
-
def triangle(n) (n * (n+1)) / 2 end
|
128
|
-
@end smallexample
|
129
|
-
The code we use in this example and the next is more for pedagogical purposes
|
130
|
-
than how to write short Ruby code.}
|
131
|
-
|
132
|
-
@smallexample
|
133
|
-
$ @b{byebug triangle.rb}
|
134
|
-
[1, 10] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb
|
135
|
-
1 #!/usr/bin/env ruby
|
136
|
-
2 # Compute the n'th triangle number - the hard way
|
137
|
-
3 # triangle(n) == (n * (n+1)) / 2
|
138
|
-
=> 4 def triangle(n)
|
139
|
-
5 tri = 0
|
140
|
-
6 0.upto(n) do |i|
|
141
|
-
7 tri += i
|
142
|
-
8 end
|
143
|
-
9 tri
|
144
|
-
10 end
|
145
|
-
(byebug)
|
146
|
-
@end smallexample
|
147
|
-
|
148
|
-
@noindent
|
149
|
-
|
150
|
-
There are lots of command options, but we don't need them for now. See
|
151
|
-
@ref{byebug command-line options} for a full list of command options.
|
152
|
-
|
153
|
-
We are currently stopped before the first executable line of the program; this
|
154
|
-
is line 4 of @code{triangle.rb}. If you are used to less dynamic languages and
|
155
|
-
have used debuggers for more statically compiled languages like C, C++, or Java,
|
156
|
-
it may seem odd to be stopped before a function definition but in Ruby line 4 is
|
157
|
-
executed, the name @code{triangle} (probably) does not exist so issuing a method
|
158
|
-
call of @code{triangle} will raise a ``method not found'' error.
|
159
|
-
|
160
|
-
@code{byebug}'s prompt is @code{(byebug)}. If the program has died and you are
|
161
|
-
in post-mortem debugging @code{(byebug:post-mortem)} is used instead. If the
|
162
|
-
program has terminated normally, the string this position will be
|
163
|
-
@code{(byebug:ctrl)}. The commands which are available change depending on the
|
164
|
-
program's state.
|
165
|
-
|
166
|
-
Byebug automatically lists 10 lines of code centered around the current line
|
167
|
-
everytime it is stopped. The current line here is line 4 and is marked with
|
168
|
-
@code{=>}, so the range byebug would like to show is [-1..8]. However since
|
169
|
-
there aren't 5 lines before the current line, the range is moved ``up'' so we
|
170
|
-
can actually display 10 lines of code.
|
171
|
-
|
172
|
-
Now let us step through the program.
|
173
|
-
|
174
|
-
@smallexample
|
175
|
-
(byebug) @b{step}
|
176
|
-
[4, 13] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb
|
177
|
-
4 def triangle(n)
|
178
|
-
5 tri = 0
|
179
|
-
6 0.upto(n) do |i|
|
180
|
-
7 tri += i
|
181
|
-
8 end
|
182
|
-
9 tri
|
183
|
-
10 end
|
184
|
-
11
|
185
|
-
=> 12 t = triangle(3)
|
186
|
-
13 puts t
|
187
|
-
(byebug) @b{@key{<RET>}}
|
188
|
-
[1, 10] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb
|
189
|
-
1 #!/usr/bin/env ruby
|
190
|
-
2 # Compute the n'th triangle number - the hard way
|
191
|
-
3 # triangle(n) == (n * (n+1)) / 2
|
192
|
-
4 def triangle(n)
|
193
|
-
=> 5 tri = 0
|
194
|
-
6 0.upto(n) do |i|
|
195
|
-
7 tri += i
|
196
|
-
8 end
|
197
|
-
9 tri
|
198
|
-
10 end
|
199
|
-
(byebug) @b{p tri}
|
200
|
-
nil
|
201
|
-
(byebug) @b{step}
|
202
|
-
[1, 10] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb
|
203
|
-
1 #!/usr/bin/env ruby
|
204
|
-
2 # Compute the n'th triangle number - the hard way
|
205
|
-
3 # triangle(n) == (n * (n+1)) / 2
|
206
|
-
4 def triangle(n)
|
207
|
-
5 tri = 0
|
208
|
-
=> 6 0.upto(n) do |i|
|
209
|
-
7 tri += i
|
210
|
-
8 end
|
211
|
-
9 tri
|
212
|
-
10 end
|
213
|
-
(byebug) @b{p tri}
|
214
|
-
0
|
215
|
-
@end smallexample
|
216
|
-
|
217
|
-
The first @kbd{step} command (@pxref{Step}) runs the script one executable unit.
|
218
|
-
The second command we entered was just hitting the return key; @code{byebug}
|
219
|
-
remembers the last command you entered was @code{step}, so it runs that last
|
220
|
-
command again.
|
221
|
-
|
222
|
-
One way to print the values of variables uses @code{p} (of course, there are
|
223
|
-
lots of other ways). When we look at the value of @code{tri} the first time, we
|
224
|
-
see it is @code{nil}. Again we are stopped @emph{before} the assignment on line
|
225
|
-
5, and this variable hasn't been set previously. However after issuing another
|
226
|
-
@code{step} command we see that the value is 0 as expected. If every time we
|
227
|
-
stop we want to see the value of @code{tri} to see how things are going, there
|
228
|
-
is a better way by setting a display expression (@pxref{DisplayCommands}).
|
229
|
-
|
230
|
-
@smallexample
|
231
|
-
(byebug:1) @b{display tri}
|
232
|
-
1: tri = 0
|
233
|
-
@end smallexample
|
234
|
-
|
235
|
-
Now let us run the program until we return from the function. We'll want to see
|
236
|
-
which lines get run.
|
237
|
-
|
238
|
-
@smallexample
|
239
|
-
(byebug) @b{display i}
|
240
|
-
2: i =
|
241
|
-
(byebug) @b{set linetrace on}
|
242
|
-
line tracing is on.
|
243
|
-
(byebug) @b{finish}
|
244
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:7 tri += i
|
245
|
-
1: tri = 0
|
246
|
-
2: i = 0
|
247
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:7 tri += i
|
248
|
-
1: tri = 0
|
249
|
-
2: i = 1
|
250
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:7 tri += i
|
251
|
-
1: tri = 1
|
252
|
-
2: i = 2
|
253
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:7 tri += i
|
254
|
-
1: tri = 3
|
255
|
-
2: i = 3
|
256
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:9 tri
|
257
|
-
1: tri = 6
|
258
|
-
2: i =
|
259
|
-
Tracing: /home/davidr/Proyectos/byebug/old_doc/triangle.rb:13 puts t
|
260
|
-
1: tri =
|
261
|
-
2: i =
|
262
|
-
[4, 13] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb
|
263
|
-
4 def triangle(n)
|
264
|
-
5 tri = 0
|
265
|
-
6 0.upto(n) do |i|
|
266
|
-
7 tri += i
|
267
|
-
8 end
|
268
|
-
9 tri
|
269
|
-
10 end
|
270
|
-
11
|
271
|
-
12 t = triangle(3)
|
272
|
-
=> 13 puts t
|
273
|
-
1: tri =
|
274
|
-
2: i =
|
275
|
-
(byebug) @b{quit}
|
276
|
-
Really quit? (y/n) @b{y}
|
277
|
-
@end smallexample
|
278
|
-
|
279
|
-
So far, so good. As you can see from the above to get out of @code{byebug}, one
|
280
|
-
can issue a @code{quit} command (@code{q} and @code{exit} are just as good). If
|
281
|
-
you want to quit without being prompted, suffix the command with an exclamation
|
282
|
-
mark, e.g. @code{q!}.
|
283
|
-
|
284
|
-
@node Second Sample Session
|
285
|
-
@section Second Sample Session 2: Delving Deeper
|
286
|
-
|
287
|
-
In this section we'll introduce breakpoints, the call stack and restarting. So
|
288
|
-
far we've been doing pretty good in that we've not encountered a bug to fix.
|
289
|
-
Let's try another simple example. Okay here's the program.
|
290
|
-
|
291
|
-
Below we will debug a simple Ruby program to solve the classic Towers of Hanoi
|
292
|
-
puzzle. It is augmented by the bane of programming: some command-parameter
|
293
|
-
processing with error checking.
|
294
|
-
|
295
|
-
@smallexample
|
296
|
-
$ @b{byebug hanoi.rb}
|
297
|
-
hanoi.rb:3 def hanoi(n,a,b,c)
|
298
|
-
(byebug:1) @b{list 1,100}
|
299
|
-
[1, 100] in ./hanoi.rb
|
300
|
-
1 #!/usr/bin/ruby
|
301
|
-
2
|
302
|
-
=> 3 def hanoi(n,a,b,c)
|
303
|
-
4 if n-1 > 0
|
304
|
-
5 hanoi(n-1, a, c, b)
|
305
|
-
6 end
|
306
|
-
7 puts "Move disk %s to %s" % [a, b]
|
307
|
-
8 if n-1 > 0
|
308
|
-
9 hanoi(n-1, c, b, a)
|
309
|
-
10 end
|
310
|
-
11 end
|
311
|
-
12
|
312
|
-
13 i_args=ARGV.length
|
313
|
-
14 if i_args > 1
|
314
|
-
15 puts "*** Need number of disks or no parameter"
|
315
|
-
16 exit 1
|
316
|
-
17 end
|
317
|
-
18
|
318
|
-
19 n=3
|
319
|
-
20
|
320
|
-
21 if i_args > 0
|
321
|
-
22 begin
|
322
|
-
23 n = ARGV[0].to_i
|
323
|
-
24 rescue ValueError, msg
|
324
|
-
25 print "** Expecting an integer, got: %s" % ARGV[0].to_s
|
325
|
-
26 exit 2
|
326
|
-
27 end
|
327
|
-
28 end
|
328
|
-
29
|
329
|
-
30 if n < 1 or n > 100
|
330
|
-
31 puts "*** number of disks should be between 1 and 100"
|
331
|
-
32 exit 2
|
332
|
-
33 end
|
333
|
-
34
|
334
|
-
35 hanoi(n, :a, :b, :c)
|
335
|
-
(byebug:1)
|
336
|
-
@end smallexample
|
337
|
-
|
338
|
-
Recall in the first section I said that before the @code{def} is run
|
339
|
-
the method it names is undefined. Let's check that out. First let's
|
340
|
-
see what private methods we can call before running @code{def hanoi}
|
341
|
-
|
342
|
-
@smallexample
|
343
|
-
(byebug:1) @b{set autoeval on}
|
344
|
-
autoeval is on.
|
345
|
-
(byebug:1) @b{private_methods}
|
346
|
-
[:require_relative, :Digest, :default_src_encoding, :debug_program, ...
|
347
|
-
@end smallexample
|
348
|
-
|
349
|
-
The @code{set autoeval} (@pxref{Autoeval}) command causes any commands
|
350
|
-
that are not normally understood to be byebug commands to get
|
351
|
-
evaluated as though they were Ruby commands. I use this a lot, so I
|
352
|
-
set this by putting it the command file @code{.byebugrc},
|
353
|
-
@pxref{Command Files}, that gets read when @code{byebug} starts.
|
354
|
-
|
355
|
-
As showing the list output of @code{private_methods}, I find this kind
|
356
|
-
of list unwieldy. What you are supposed to notice here is that
|
357
|
-
method @code{hanoi} is not in this list. When you ask
|
358
|
-
@code{byebug} for a list of method names via @code{method
|
359
|
-
instance}, it doesn't show output in this way; @code{byebug} can
|
360
|
-
sort and put into columns lists like this using the print command, @code{ps}.
|
361
|
-
|
362
|
-
|
363
|
-
@smallexample
|
364
|
-
(byebug:1) @b{ps private_methods}
|
365
|
-
Array debug_program p spawn
|
366
|
-
Complex default_src_encoding pp sprintf
|
367
|
-
Digest eval print srand
|
368
|
-
Float exec printf syscall
|
369
|
-
Integer exit proc system
|
370
|
-
Pathname exit! process_options test
|
371
|
-
Rational fail putc throw
|
372
|
-
String fork puts trace_var
|
373
|
-
__callee__ format raise trap
|
374
|
-
__method__ gem rand untrace_var
|
375
|
-
` gets readline warn
|
376
|
-
abort global_variables readlines whence_file
|
377
|
-
at_exit initialize remove_instance_variable y
|
378
|
-
autoload initialize_copy require
|
379
|
-
autoload? iterator? require_relative
|
380
|
-
binding lambda select
|
381
|
-
block_given? load set_trace_func
|
382
|
-
caller local_variables singleton_method_added
|
383
|
-
catch loop singleton_method_removed
|
384
|
-
dbg_print method_missing singleton_method_undefined
|
385
|
-
dbg_puts open sleep
|
386
|
-
@end smallexample
|
387
|
-
|
388
|
-
Now let's see what happens after stepping:
|
389
|
-
|
390
|
-
@smallexample
|
391
|
-
(byebug:1) @b{private_methods.member?(:hanoi)}
|
392
|
-
false
|
393
|
-
(byebug:1) @b{step}
|
394
|
-
hanoi.rb:13
|
395
|
-
i_args=ARGV.length
|
396
|
-
(byebug:1) @b{private_methods.member?(:hanoi)}
|
397
|
-
true
|
398
|
-
(byebug:1)
|
399
|
-
@end smallexample
|
400
|
-
|
401
|
-
Okay, now where were we?
|
402
|
-
|
403
|
-
@smallexample
|
404
|
-
(byebug:1) @b{list}
|
405
|
-
[8, 17] in ./hanoi.rb
|
406
|
-
8 if n-1 > 0
|
407
|
-
9 hanoi(n-1, c, b, a)
|
408
|
-
10 end
|
409
|
-
11 end
|
410
|
-
12
|
411
|
-
=> 13 i_args=ARGV.length
|
412
|
-
14 if i_args > 1
|
413
|
-
15 puts "*** Need number of disks or no parameter"
|
414
|
-
16 exit 1
|
415
|
-
17 end
|
416
|
-
(byebug:1) @b{ARGV}
|
417
|
-
[]
|
418
|
-
@end smallexample
|
419
|
-
|
420
|
-
Ooops. We forgot to specify any parameters to this program. Let's try
|
421
|
-
again. We can use the @code{restart} command here.
|
422
|
-
|
423
|
-
@smallexample
|
424
|
-
(byebug:1) @b{restart 3}
|
425
|
-
Re exec'ing:
|
426
|
-
/usr/bin/byebug hanoi.rb 3
|
427
|
-
hanoi.rb:3
|
428
|
-
def hanoi(n,a,b,c)
|
429
|
-
(byebug:1) @b{break 4}
|
430
|
-
Breakpoint 1 file hanoi.rb, line 4
|
431
|
-
(byebug:1) @b{continue}
|
432
|
-
Breakpoint 1 at hanoi.rb:4
|
433
|
-
./hanoi.rb:4 if n-1 > 0
|
434
|
-
(byebug:1) @b{display n}
|
435
|
-
1: n = 3
|
436
|
-
(byebug:1) @b{display a}
|
437
|
-
2: a = a
|
438
|
-
(byebug:1) @b{undisplay 2}
|
439
|
-
(byebug:1) @b{display a.inspect}
|
440
|
-
3: a.inspect = :a
|
441
|
-
(byebug:1) @b{display b.inspect}
|
442
|
-
4: b.inspect = :b
|
443
|
-
(byebug:1) @b{continue}
|
444
|
-
Breakpoint 1 at hanoi.rb:4
|
445
|
-
1: n = 2
|
446
|
-
3: a.inspect = :a
|
447
|
-
4: b.inspect = :c
|
448
|
-
./hanoi.rb:4
|
449
|
-
if n-1 > 0
|
450
|
-
(byebug:1) @b{c}
|
451
|
-
Breakpoint 1 at hanoi.rb:4
|
452
|
-
1: n = 1
|
453
|
-
3: a.inspect = :a
|
454
|
-
4: b.inspect = :b
|
455
|
-
./hanoi.rb:4
|
456
|
-
if n-1 > 0
|
457
|
-
(byebug:1) @b{where}
|
458
|
-
--> #0 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at hanoi.rb:4
|
459
|
-
#1 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at hanoi.rb:5
|
460
|
-
#2 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at hanoi.rb:5
|
461
|
-
#3 at hanoi.rb:35
|
462
|
-
(byebug:1)
|
463
|
-
@end smallexample
|
464
|
-
|
465
|
-
In the above we added a new command, @code{break} (@pxref{Breakpoints}) which
|
466
|
-
indicates to go into byebug just before that line of code is run. And
|
467
|
-
@code{continue} resumes execution. Notice the difference between
|
468
|
-
@code{display a} and @code{display a.inspect}. An implied string conversion is
|
469
|
-
performed on the expression after it is evaluated. To remove a display
|
470
|
-
expression @code{undisplay} is used. If we give a display number, just that
|
471
|
-
display expression is removed.
|
472
|
-
|
473
|
-
Above we also used a new command @code{where} (@pxref{Backtrace} to show the
|
474
|
-
call stack. In the above situation, starting from the bottom line we see we
|
475
|
-
called the hanoi from line 35 of the file @code{hanoi.rb} and the hanoi method
|
476
|
-
called itself two more times at line 5.
|
477
|
-
|
478
|
-
In the call stack we show the file line position in the same format we use when
|
479
|
-
we stop at a line. Also we see the names of the parameters and the types that
|
480
|
-
those parameters @emph{currently} have. It's possible that when the program was
|
481
|
-
called the parameter had a different type, since the types of variables can
|
482
|
-
change dynamically. You can alter the style of what to show in the trace
|
483
|
-
(@pxref{Callstyle}).
|
484
|
-
|
485
|
-
Let's explore a little more. Now where were we?
|
486
|
-
@smallexample
|
487
|
-
(byebug:1) @b{list}
|
488
|
-
1 #!/usr/bin/ruby
|
489
|
-
2
|
490
|
-
3 def hanoi(n,a,b,c)
|
491
|
-
=> 4 if n-1 > 0
|
492
|
-
5 hanoi(n-1, a, c, b)
|
493
|
-
6 end
|
494
|
-
7 puts "Move disk %s to %s" % [a, b]
|
495
|
-
8 if n-1 > 0
|
496
|
-
(byebug:1) @b{undisplay}
|
497
|
-
Clear all expressions? (y/n) @b{y}
|
498
|
-
(byebug:1) @b{i_args}
|
499
|
-
NameError Exception: undefined local variable or method `i_args' for main:Object
|
500
|
-
(byebug:1) @b{frame -1}
|
501
|
-
#3 at hanoi.rb:35
|
502
|
-
(byebug:1) @b{i_args}
|
503
|
-
1
|
504
|
-
(byebug:1) @b{p n}
|
505
|
-
3
|
506
|
-
(byebug:1) @b{down 2}
|
507
|
-
#2 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at hanoi.rb:5
|
508
|
-
(byebug:1) @b{p n}
|
509
|
-
2
|
510
|
-
@end smallexample
|
511
|
-
|
512
|
-
Notice in the above to get the value of variable @code{n} I had to use a print
|
513
|
-
command like @code{p n}; If I entered just @code{n}, that would be taken to mean
|
514
|
-
byebug command ``next''. In the current scope, variable @code{i_args} is not
|
515
|
-
defined. However I can change to the top-most frame by using the @code{frame}
|
516
|
-
command. Just as with arrays, -1 means the last one. Alternatively using frame
|
517
|
-
number 3 would have been the same thing; so would issuing @code{up 3}.
|
518
|
-
|
519
|
-
Note that in the outside frame 3, the value of @code{i_args} can be shown. Also
|
520
|
-
note that the value of variable @code{n} is different.
|
521
|
-
|
522
|
-
@node Unit Testing Session
|
523
|
-
@section Using byebug in unit testing (@code{byebug}, @code{Byebug.start})
|
524
|
-
|
525
|
-
In the previous sessions we've been calling byebug right at the outset. I
|
526
|
-
confess that this mode of operation is usually not how I use byebug.
|
527
|
-
|
528
|
-
There are a number of situations where calling byebug at the outset is
|
529
|
-
impractical for a couple of reasons.
|
530
|
-
|
531
|
-
@enumerate
|
532
|
-
@item
|
533
|
-
byebug just doesn't work when run at the outset. By necessity any debugging
|
534
|
-
changes the behavior or the program in slight and subtle ways, and sometimes
|
535
|
-
this can hinder finding bugs.
|
536
|
-
@item
|
537
|
-
There's a lot of code that needs to be run before the part you want to inspect.
|
538
|
-
Running this code takes time and you don't want the overhead of byebug.
|
539
|
-
@end enumerate
|
540
|
-
|
541
|
-
In this section we'll show how to enter the code in the middle of your program,
|
542
|
-
while delving more into byebug's operation.
|
543
|
-
|
544
|
-
In this section we will also use unit testing. Using unit tests will greatly
|
545
|
-
reduce the amount of debugging needed, while at the same time, will increase the
|
546
|
-
quality of your program.
|
547
|
-
|
548
|
-
What we'll do is take the @code{triangle} code from the first session and write
|
549
|
-
a unit test for that. In a sense we did write a minitest for the program which
|
550
|
-
was basically the last line where we printed the value of triangle(3). This test
|
551
|
-
however wasn't automated: the implication is that someone would look at the
|
552
|
-
output and verify that what was printed is what was expected.
|
553
|
-
|
554
|
-
Before we can turn that into something that can be @code{required}, we probably
|
555
|
-
want to remove that output. However I like to keep in that line so that when I
|
556
|
-
look at the file, I have an example of how to run it. Therefore we will
|
557
|
-
conditionally run this line if that file is invoked directly, but skip it if it
|
558
|
-
is not@footnote{@code{byebug} resets @code{$0} to try to make things like this
|
559
|
-
work.}.
|
560
|
-
@smallexample
|
561
|
-
if __FILE__ == $0
|
562
|
-
t = triangle(3)
|
563
|
-
puts t
|
564
|
-
end
|
565
|
-
@end smallexample
|
566
|
-
|
567
|
-
Let's call this file @code{tri2.rb}.
|
568
|
-
|
569
|
-
Okay, we're now ready to write our unit test. We'll use @code{"test/unit"} which
|
570
|
-
comes with the standard Ruby distribution. Here's the test code; it should be
|
571
|
-
in the same directory as tri2.rb.
|
572
|
-
@smallexample
|
573
|
-
#!/usr/bin/env ruby
|
574
|
-
require 'test/unit'
|
575
|
-
require_relative './tri2.rb'
|
576
|
-
|
577
|
-
class TestTri < Test::Unit::TestCase
|
578
|
-
def test_basic
|
579
|
-
solutions = []
|
580
|
-
0.upto(5) do |i|
|
581
|
-
solutions << triangle(i)
|
582
|
-
end
|
583
|
-
assert_equal([0, 1, 3, 6, 10, 15], solutions,
|
584
|
-
'Testing the first 5 triangle numbers')
|
585
|
-
end
|
586
|
-
end
|
587
|
-
@end smallexample
|
588
|
-
|
589
|
-
If you run it, it will work. However if you run @code{byebug} initially, you
|
590
|
-
will not get into the test, because @code{test/unit} wants to be the main
|
591
|
-
program. So here is a situation where one may need to modify the program to add
|
592
|
-
an explicit @emph{entry} into byebug. @footnote{For some versions of rake and
|
593
|
-
@code{byebug} you can in fact set a breakpoint after running @code{byebug}
|
594
|
-
initially. Personally though I find it much simpler and more reliable to modify
|
595
|
-
the code as shown here.}
|
596
|
-
|
597
|
-
One way to do this is to add the following before the place you want to stop:
|
598
|
-
@smallexample
|
599
|
-
require 'byebug'
|
600
|
-
byebug
|
601
|
-
@end smallexample
|
602
|
-
|
603
|
-
Let's add this code just after entering @code{test_basic}:
|
604
|
-
@smallexample
|
605
|
-
...
|
606
|
-
def test_basic
|
607
|
-
@b{require "byebug"}
|
608
|
-
@b{byebug}
|
609
|
-
solutions = []
|
610
|
-
...
|
611
|
-
@end smallexample
|
612
|
-
|
613
|
-
Now we run the program..
|
614
|
-
@smallexample
|
615
|
-
$ @b{ruby test-tri.rb}
|
616
|
-
Loaded suite test-tri
|
617
|
-
Started
|
618
|
-
test-tri.rb:9
|
619
|
-
solutions = []
|
620
|
-
(byebug:1)
|
621
|
-
@end smallexample
|
622
|
-
and we see that we are stopped at line 9 just before the initialization of the
|
623
|
-
list @code{solutions}.
|
624
|
-
|
625
|
-
Now let's see where we are...
|
626
|
-
@smallexample
|
627
|
-
(byebug:1) @b{where}
|
628
|
-
--> #0 TestTri.test_basic at /home/rocky/ruby/test-tri.rb:9
|
629
|
-
(byebug:1)
|
630
|
-
@end smallexample
|
631
|
-
|
632
|
-
Something seems wrong here; @code{TestTri.test_basic} indicates that we are in
|
633
|
-
class @code{TestTri} in method @code{test_basic}. However we don't see the call
|
634
|
-
to this like we did in the last example when we used the @code{where} command.
|
635
|
-
This is because byebug really didn't spring into existence until after we
|
636
|
-
already had entered that method, and Ruby doesn't keep call stack information
|
637
|
-
around in a way that would give the information we show when running
|
638
|
-
@code{where}.
|
639
|
-
|
640
|
-
If we want call stack information, we have to turn call-stack tracking on
|
641
|
-
@emph{beforehand}. This is done by adding @code{Byebug.start}.
|
642
|
-
|
643
|
-
Here's what our test program looks like so after we modify it to start tracking
|
644
|
-
calls from the outset
|
645
|
-
@smallexample
|
646
|
-
#!/usr/bin/env ruby
|
647
|
-
require 'test/unit'
|
648
|
-
require 'tri2.rb'
|
649
|
-
require 'byebug'
|
650
|
-
@b{Byebug.start}
|
651
|
-
|
652
|
-
class TestTri < Test::Unit::TestCase
|
653
|
-
def test_basic
|
654
|
-
@b{byebug}
|
655
|
-
solutions = []
|
656
|
-
0.upto(5) do |i|
|
657
|
-
solutions << triangle(i)
|
658
|
-
end
|
659
|
-
assert_equal([0, 1, 3, 6, 10, 15], solutions,
|
660
|
-
"Testing the first 5 triangle numbers")
|
661
|
-
end
|
662
|
-
end
|
663
|
-
@end smallexample
|
664
|
-
|
665
|
-
Now when we run this:
|
666
|
-
@smallexample
|
667
|
-
$ @b{ruby test-tri2.rb}
|
668
|
-
Loaded suite test-tri2
|
669
|
-
Started
|
670
|
-
test-tri2.rb:11
|
671
|
-
solutions = []
|
672
|
-
(byebug:1) @b{where}
|
673
|
-
--> #0 TestTri.test_basic at test-tri2.rb:11
|
674
|
-
#1 MiniTest::Unit::TestCase.run(runner#MiniTest::Unit)
|
675
|
-
at /usr/local/lib/ruby/1.9.1/minitest/unit.rb:458
|
676
|
-
#2 MiniTest::Unit.run_test_suites
|
677
|
-
at /usr/local/lib/ruby/1.9.1/minitest/unit.rb:426
|
678
|
-
#3 MiniTest::Unit.run
|
679
|
-
at /usr/local/lib/ruby/1.9.1/minitest/unit.rb:393
|
680
|
-
#4 at /usr/local/lib/ruby/1.9.1/minitest/unit.rb:334
|
681
|
-
(byebug:1)
|
682
|
-
@end smallexample
|
683
|
-
|
684
|
-
Much better. But again let me emphasize that the parameter types are those of
|
685
|
-
the corresponding variables that @emph{currently} exist, and this might have
|
686
|
-
changed since the time when the call was made.
|
687
|
-
|
688
|
-
@node Byebug.start with a block
|
689
|
-
@section Using the @code{Byebug.start} with a block
|
690
|
-
|
691
|
-
We saw that @code{Byebug.start()} and @code{Byebug.stop()} allow fine-grain
|
692
|
-
control over where byebug tracking should occur.
|
693
|
-
|
694
|
-
Rather than use an explicit @code{stop()}, you can also pass a block to the
|
695
|
-
@code{start()} method. This causes @code{start()} to run and then @code{yield}
|
696
|
-
to that block. When the block is finished, @code{stop()} is run. In other words,
|
697
|
-
this wraps a @code{Byebug.start()} and @code{Byebug.stop()} around the block of
|
698
|
-
code. But it also has a side benefit of ensuring that in the presence of an
|
699
|
-
uncaught exception @code{stop} is run, without having to explicitly use
|
700
|
-
@code{begin} ... @code{ensure Byebug.stop() end}.
|
701
|
-
|
702
|
-
For example, in Ruby on Rails you might want to debug code in one of the
|
703
|
-
controllers without causing any slowdown to any other code. And this can be done
|
704
|
-
by wrapping the controller in a @code{start()} with a block; when the method
|
705
|
-
wrapped this way finishes, byebug is turned off and the application proceeds at
|
706
|
-
regular speed.
|
707
|
-
|
708
|
-
Of course, inside the block you will probably want to enter the byebug using
|
709
|
-
@code{Byebug.byebug()}, otherwise there would be little point in using the
|
710
|
-
@code{start}. For example, you can do this in @code{irb}:
|
711
|
-
@smallexample
|
712
|
-
$ @b{irb}
|
713
|
-
irb(main):001:0> @b{require 'byebug'}
|
714
|
-
=> true
|
715
|
-
irb(main):002:0> @b{def foo}
|
716
|
-
irb(main):003:1> @b{x=1}
|
717
|
-
irb(main):004:1> @b{puts 'foo'}
|
718
|
-
irb(main):005:1> @b{end}
|
719
|
-
=> nil
|
720
|
-
irb(main):006:0> @b{Byebug.start@{byebug; foo@}}
|
721
|
-
(irb):3
|
722
|
-
|
723
|
-
(byebug:1) @b{s}
|
724
|
-
(irb):4
|
725
|
-
|
726
|
-
(byebug:1) @b{p x}
|
727
|
-
1
|
728
|
-
(byebug:1) @b{s}
|
729
|
-
foo
|
730
|
-
=> true
|
731
|
-
irb(main):007:0>
|
732
|
-
@end smallexample
|
733
|
-
|
734
|
-
There is a counter inside of @code{Byebug.start} method to make sure that this
|
735
|
-
works when another @code{Byebug.start} method is called inside of the outer one.
|
736
|
-
However if you are stopped inside byebug, issuing another @code{byebug} call
|
737
|
-
will not have any effect even if it is nested inside another
|
738
|
-
@code{Byebug.start}.
|
739
|
-
|
740
|
-
@node Debugging Oddities
|
741
|
-
@section How debugging Ruby may be different from debugging other languages
|
742
|
-
|
743
|
-
If you are used to debugging in other languages like C, C++, Perl, Java or even
|
744
|
-
Bash@footnote{this is just an excuse to put in a shameless plug for this bash
|
745
|
-
debugger @url{http://bashdb.sf.net}}, there may be a number of things that seem
|
746
|
-
or feel a little bit different and may confuse you. A number of these things
|
747
|
-
aren't oddities of the debugger per se, so much as a difference in how Ruby
|
748
|
-
works compared to those other languages. Because Ruby works a little differently
|
749
|
-
from those other languages, writing a debugger has to also be a little
|
750
|
-
different as well if it is to be useful.
|
751
|
-
|
752
|
-
In this respect, using byebug may help you understand Ruby better.
|
753
|
-
|
754
|
-
We've already seen two examples of such differences. One difference is the fact
|
755
|
-
that we stop on method definitions or @code{def}'s and that is because these are
|
756
|
-
in fact executable statements. In other compiled languages this would not happen
|
757
|
-
because that's already been done when you compile the program (or in Perl when
|
758
|
-
it scans in the program). The other difference we saw was our inability to show
|
759
|
-
call stack parameter types without having made arrangements for byebug to track
|
760
|
-
this. In other languages call stack information is usually available without
|
761
|
-
asking assistance of the debugger@footnote{However in C and C++ you generally
|
762
|
-
have to ask the compiler to add such information.}.
|
763
|
-
|
764
|
-
In this section we'll consider some other things that might throw off new users
|
765
|
-
to Ruby who are familiar with other languages and debugging in them.
|
766
|
-
|
767
|
-
@menu
|
768
|
-
* Bouncing Around in Blocks (e.g. Iterators)::
|
769
|
-
* No Parameter Values in a Call Stack::
|
770
|
-
* Lines You Can Stop At::
|
771
|
-
@end menu
|
772
|
-
|
773
|
-
@node Bouncing Around in Blocks (e.g. Iterators)
|
774
|
-
@subsection Bouncing Around in Blocks (e.g.@: Iterators)
|
775
|
-
When debugging languages with coroutines like Python and Ruby, a method call may
|
776
|
-
not necessarily go to the first statement after the method header. It's possible
|
777
|
-
that the call will continue after a @code{yield} statement from a prior call.
|
778
|
-
|
779
|
-
@smallexample
|
780
|
-
1 #!/usr/bin/env ruby
|
781
|
-
2 # Enumerator for primes
|
782
|
-
3 class SievePrime
|
783
|
-
4 @@@@odd_primes = []
|
784
|
-
5 def self.next_prime(&block)
|
785
|
-
6 candidate = 2
|
786
|
-
7 yield candidate
|
787
|
-
8 not_prime = false
|
788
|
-
9 candidate += 1
|
789
|
-
10 while true do
|
790
|
-
11 @@@@odd_primes.each do |p|
|
791
|
-
12 not_prime = (0 == (candidate % p))
|
792
|
-
13 break if not_prime
|
793
|
-
14 end
|
794
|
-
15 unless not_prime
|
795
|
-
16 @@@@odd_primes << candidate
|
796
|
-
17 yield candidate
|
797
|
-
18 end
|
798
|
-
19 candidate += 2
|
799
|
-
20 end
|
800
|
-
21 end
|
801
|
-
22 end
|
802
|
-
23 SievePrime.next_prime do |prime|
|
803
|
-
24 puts prime
|
804
|
-
25 break if prime > 10
|
805
|
-
26 end
|
806
|
-
@end smallexample
|
807
|
-
|
808
|
-
@smallexample
|
809
|
-
$ @b{byebug primes.rb}
|
810
|
-
primes.rb:3
|
811
|
-
class SievePrime
|
812
|
-
(byebug:1) @b{set linetrace on}
|
813
|
-
line tracing is on.
|
814
|
-
(byebug:1) @b{step 9}
|
815
|
-
Tracing(1):primes.rb:4 @@odd_primes = []
|
816
|
-
Tracing(1):primes.rb:5 def self.next_prime(&block)
|
817
|
-
Tracing(1):primes.rb:23 SievePrime.next_prime do |prime|
|
818
|
-
Tracing(1):primes.rb:6 candidate = 2
|
819
|
-
Tracing(1):primes.rb:7 yield candidate
|
820
|
-
Tracing(1):primes.rb:24 puts prime
|
821
|
-
2
|
822
|
-
Tracing(1):primes.rb:25 break if prime > 10
|
823
|
-
Tracing(1):primes.rb:8 not_prime = false
|
824
|
-
Tracing(1):primes.rb:9 candidate += 1
|
825
|
-
primes.rb:9
|
826
|
-
candidate += 1
|
827
|
-
(byebug:1)
|
828
|
-
@end smallexample
|
829
|
-
|
830
|
-
The loop between lines 23--26 gets interleaved between those of
|
831
|
-
@code{Sieve::next_prime}, lines 6--19 above.
|
832
|
-
|
833
|
-
@node No Parameter Values in a Call Stack
|
834
|
-
@subsection No Parameter Values in a Call Stack
|
835
|
-
In traditional debuggers, in a call stack you can generally see the names of the
|
836
|
-
parameters and the values that were passed in.
|
837
|
-
|
838
|
-
Ruby is a very dynamic language and it tries to be efficient within the confines
|
839
|
-
of the language definition. Values generally aren't taken out of a variable or
|
840
|
-
expression and pushed onto a stack. Instead a new scope created and the
|
841
|
-
parameters are given initial values. Parameter passing is by @emph{reference},
|
842
|
-
not by value as it is say Algol, C, or Perl. During the execution of a method,
|
843
|
-
parameter values can change---and often do. In fact even the @emph{class} of the
|
844
|
-
object can change.
|
845
|
-
|
846
|
-
So at present, the name of the parameter shown. The call-style setting
|
847
|
-
@pxref{Callstyle} can be used to set whether the name is shown or the name and
|
848
|
-
the @emph{current} class of the object.
|
849
|
-
|
850
|
-
It has been contemplated that a style might be added which saves on call shorter
|
851
|
-
``scalar'' types of values and the class name.
|
852
|
-
|
853
|
-
@node Lines You Can Stop At
|
854
|
-
@subsection Lines You Can Stop At
|
855
|
-
As with the duplicate stops per control (e.g.@: @code{if} statement), until
|
856
|
-
tools like byebugs get more traction among core ruby developers there are going
|
857
|
-
to be weirdness. Here we describe the stopping locations which effects the
|
858
|
-
breakpoint line numbers you can stop at.
|
859
|
-
|
860
|
-
Consider the following little Ruby program.
|
861
|
-
@smallexample
|
862
|
-
'Yes it does' =~ /
|
863
|
-
(Yes) \s+
|
864
|
-
it \s+
|
865
|
-
does
|
866
|
-
/ix
|
867
|
-
puts $1
|
868
|
-
@end smallexample
|
869
|
-
|
870
|
-
The stopping points that Ruby records are the last two lines, lines 5 and 6.
|
871
|
-
|
872
|
-
Inside @code{byebug} you can get a list of stoppable lines for a file using the
|
873
|
-
@code{info file} command with the attribute @code{breakpoints}.
|
874
|
-
|
875
|
-
@ifset FINISHED
|
876
|
-
To be continued...
|
877
|
-
|
878
|
-
@itemize @bullet
|
879
|
-
@item more complex example with objects, pretty printing and irb.
|
880
|
-
@item line tracing and non-interactive tracing.
|
881
|
-
@item mixing in Byebug.debug with byebug
|
882
|
-
@item post-mortem debugging and setting up for that
|
883
|
-
@item references to videos
|
884
|
-
@end itemize
|
885
|
-
@end ifset
|
886
|
-
|
887
|
-
@node Invocation
|
888
|
-
@chapter Getting in & out
|
889
|
-
|
890
|
-
@menu
|
891
|
-
* Starting byebug:: How to enter byebug
|
892
|
-
* Command Files:: Command files
|
893
|
-
* Quitting byebug:: How to leave byebug (quit, kill)
|
894
|
-
* Calling from Program:: Calling byebug from inside your program
|
895
|
-
* Post-Mortem Debugging:: Enter byebug after an uncaught exception
|
896
|
-
@end menu
|
897
|
-
|
898
|
-
@node Starting byebug
|
899
|
-
@section Starting byebug
|
900
|
-
|
901
|
-
Probably the most familiar thing to do is invoke byebug from a command line. A
|
902
|
-
wrapper shell script called @code{byebug} basically @code{require}'s the gem
|
903
|
-
package @code{byebug} and then loads @code{byebug}.
|
904
|
-
|
905
|
-
@smallexample
|
906
|
-
byebug [byebug-options] [--] @var{ruby-script} @var{ruby-script-arguments...}
|
907
|
-
@end smallexample
|
908
|
-
|
909
|
-
If you don't need to pass dash options to your program which might get confused
|
910
|
-
with byebug options, then you don't need to add the @option{--}.
|
911
|
-
|
912
|
-
To get a brief list of options and descriptions, use the @code{--help} option.
|
913
|
-
|
914
|
-
@smallexample
|
915
|
-
$ @b{byebug --help}
|
916
|
-
byebug @value{BYEBUG_VERSION}
|
917
|
-
Usage: byebug [options] <script.rb> -- <script.rb parameters>
|
918
|
-
|
919
|
-
Options:
|
920
|
-
-d, --debug Set $DEBUG=true
|
921
|
-
-I, --include PATH Add PATH to $LOAD_PATH
|
922
|
-
-m, --post-mortem Activate post-mortem mode
|
923
|
-
--no-quit Do not quit when script finishes
|
924
|
-
--no-stop Do not stop when script is loaded
|
925
|
-
-nx Don't run any initialization files like .byebugrc
|
926
|
-
-r, --require SCRIPT Require the library, before executing your script
|
927
|
-
--restart-script FILE Name of the script file to run. Erased after read
|
928
|
-
--script FILE Name of the script file to run
|
929
|
-
-x, --trace Turn on line tracing
|
930
|
-
|
931
|
-
Common options:
|
932
|
-
--help Show this message
|
933
|
-
--version Print the version
|
934
|
-
-v Print version number, then turn on verbose mode
|
935
|
-
@end smallexample
|
936
|
-
|
937
|
-
Options for the @code{byebug} are shown in the following list.
|
938
|
-
|
939
|
-
@menu
|
940
|
-
* byebug command-line options:: Options you can pass to byebug
|
941
|
-
* byebug default options:: How to Set Default Command-Line Options
|
942
|
-
@end menu
|
943
|
-
|
944
|
-
@node byebug command-line options
|
945
|
-
@subsection Options you can pass to byebug
|
946
|
-
|
947
|
-
You can run @code{byebug} in various alternative modes, for example, as a
|
948
|
-
program that interacts directly with the program in the same process on the same
|
949
|
-
computer or via a socket to another process possibly on a different computer.
|
950
|
-
|
951
|
-
Many options appear as a long option name, such as @option{--help}, and a short
|
952
|
-
one letter option name, such as @option{-h}. A double dash (@option{--} is used
|
953
|
-
to separate options which go to @code{byebug} from options that are intended to
|
954
|
-
go to your Ruby script. Options (if any) to @code{byebug} should come first. If
|
955
|
-
there is no possibility of the Ruby script to be debugged getting confused with
|
956
|
-
@code{byebug}'s option, the double dash can be omitted.
|
957
|
-
|
958
|
-
@table @code
|
959
|
-
@item --help
|
960
|
-
@cindex @option{-h}
|
961
|
-
@cindex @option{--help}
|
962
|
-
This option causes @code{byebug} to print some basic help and exit.
|
963
|
-
|
964
|
-
@item -v | --version
|
965
|
-
@cindex @option{-v}
|
966
|
-
This option causes @code{byebug} to print its version number and exit.
|
967
|
-
|
968
|
-
@item --debug
|
969
|
-
@cindex @option{--debug}
|
970
|
-
Set @code{$DEBUG} to @code{true}. This option is compatible with Ruby's.
|
971
|
-
|
972
|
-
@item -I --include @var{PATH}
|
973
|
-
@cindex @option{-I} @var{PATH}
|
974
|
-
@cindex @option{--include} @var{PATH}
|
975
|
-
Add @var{PATH} to @code{$LOAD_PATH}
|
976
|
-
|
977
|
-
@item -m | --post-mortem
|
978
|
-
@cindex @option{-m}
|
979
|
-
@cindex @option{--post-mortem}
|
980
|
-
If your program raises an exception that isn't caught you can enter byebug for
|
981
|
-
inspection of what went wrong. You may also want to use this option in
|
982
|
-
conjunction with @option{--no-stop}. See also @ref{Post-Mortem Debugging}.
|
983
|
-
|
984
|
-
@item --no-quit
|
985
|
-
@cindex @option{--no-quit}
|
986
|
-
Restart byebug when your program terminates normally.
|
987
|
-
|
988
|
-
@item --no-stop
|
989
|
-
@cindex @option{--no-stop}
|
990
|
-
Normally the @code{byebug} stops before executing the first statement. If
|
991
|
-
instead you want it to start running initially and will perhaps break it later
|
992
|
-
in the running, use this options.
|
993
|
-
|
994
|
-
@item -r | --require @var{library}
|
995
|
-
@cindex @option{-r}
|
996
|
-
@cindex @option{--require}
|
997
|
-
Require the library, before executing your script. However if the library
|
998
|
-
happened to be @code{debug}, we'll just ignore the require (since we're already
|
999
|
-
a debugger). This option is compatible with Ruby's.
|
1000
|
-
|
1001
|
-
@item --script @var{file}
|
1002
|
-
@cindex @option{--script}
|
1003
|
-
Require the library, before executing your script. However if the library
|
1004
|
-
happend to be @code{debug}, we'll just ignore the require (since we're already a
|
1005
|
-
debugger). This option is compatible with Ruby's.
|
1006
|
-
|
1007
|
-
@item -x | --trace
|
1008
|
-
@cindex @option{-x}
|
1009
|
-
@cindex @option{--trace}
|
1010
|
-
Turn on line tracing. Running @command{byebug --trace @emph{rubyscript.rb}}
|
1011
|
-
is much like running: @command{ruby -rtracer @emph{rubyscript.rb}}
|
1012
|
-
|
1013
|
-
If all you want to do however is get a linetrace, @code{tracer} and not
|
1014
|
-
@code{byebug}, may be faster:
|
1015
|
-
|
1016
|
-
@smallexample
|
1017
|
-
$ @b{time ruby -rtracer gcd.rb 34 21 > /dev/null}
|
1018
|
-
|
1019
|
-
real 0m0.266s
|
1020
|
-
user 0m0.008s
|
1021
|
-
sys 0m0.000s
|
1022
|
-
$ @b{time byebug --trace gcd.rb 34 21 > /dev/null}
|
1023
|
-
|
1024
|
-
real 0m0.875s
|
1025
|
-
user 0m0.448s
|
1026
|
-
sys 0m0.056s
|
1027
|
-
$
|
1028
|
-
@end smallexample
|
1029
|
-
@end table
|
1030
|
-
|
1031
|
-
@node byebug default options
|
1032
|
-
@subsection How to Set Default Command-Line Options
|
1033
|
-
|
1034
|
-
@code{byebug} has many command-line options; it seems that some people want to
|
1035
|
-
set them differently from the defaults. For example, some people may want
|
1036
|
-
@option{--no-quit --no-control} to be the default behavior. One could write a
|
1037
|
-
wrapper script or set a shell alias to handle this. But @code{byebug} has
|
1038
|
-
another way to do this. Before processing command options, if the file
|
1039
|
-
@code{$HOME/.rdboptrc} is found, it is loaded. If you want to set the defaults
|
1040
|
-
in some other way, you can put Ruby code here and set variable @code{options}
|
1041
|
-
which is an OpenStruct. For example here's how you'd set @option{-no-quit} and
|
1042
|
-
change the default control port to 5000.
|
1043
|
-
|
1044
|
-
@smallexample
|
1045
|
-
# This file contains how you want the default options to byebug to be set. Any
|
1046
|
-
# Ruby code can be put here.
|
1047
|
-
#
|
1048
|
-
# byebug # Uncomment if you want to debug byebug!
|
1049
|
-
options.control = false
|
1050
|
-
options.port = 5000
|
1051
|
-
puts "rocky's rdboptrc run"
|
1052
|
-
@end smallexample
|
1053
|
-
|
1054
|
-
Here are the default values in @code{options}
|
1055
|
-
@smallexample
|
1056
|
-
#<OpenStruct server=false, client=false, frame_bind=false, cport=8990,
|
1057
|
-
tracing=false, nx=false, post_mortem=false, port=8989,
|
1058
|
-
control=true, restart_script=nil, quit=true, stop=true, script=nil,
|
1059
|
-
host=nil, wait=false>
|
1060
|
-
@end smallexample
|
1061
|
-
|
1062
|
-
@node Command Files
|
1063
|
-
@section Command files
|
1064
|
-
|
1065
|
-
@cindex command files
|
1066
|
-
A command file is a file of lines that are @code{byebug} commands. Comments
|
1067
|
-
(lines starting with @kbd{#}) may also be included. An empty line in a command
|
1068
|
-
file does nothing; it does not mean to repeat the last command, as it would from
|
1069
|
-
the terminal.
|
1070
|
-
|
1071
|
-
@cindex init file
|
1072
|
-
@cindex @file{.byebugrc}
|
1073
|
-
When you start @code{byebug}, it automatically executes commands from its
|
1074
|
-
@dfn{init files}, normally called @file{.byebugrc}. On some configurations of
|
1075
|
-
@code{byebug}, the init file may be known by a different name.
|
1076
|
-
|
1077
|
-
During startup, @code{byebug} does the following:
|
1078
|
-
|
1079
|
-
@enumerate
|
1080
|
-
@item
|
1081
|
-
Processes command line options and operands.
|
1082
|
-
|
1083
|
-
@item
|
1084
|
-
Reads the init file in your current directory, if any, and then checks your home
|
1085
|
-
directory. The home directory is the directory named in the @code{HOME} or
|
1086
|
-
@code{HOMEPATH} environment variable. Thus, you can have more than one init
|
1087
|
-
file, one generic in your home directory, and another, specific to the program
|
1088
|
-
you are debugging, in the directory where you invoke @code{byebug}.
|
1089
|
-
|
1090
|
-
@item
|
1091
|
-
Reads command files specified by the @samp{--script} option.
|
1092
|
-
@end enumerate
|
1093
|
-
|
1094
|
-
You can also request the execution of a command file with the @code{source}
|
1095
|
-
command, @pxref{Source}.
|
1096
|
-
|
1097
|
-
@node Quitting byebug
|
1098
|
-
@section Quitting byebug
|
1099
|
-
|
1100
|
-
Inside a byebug interpreter, use @code{quit} command (
|
1101
|
-
@pxref{Control, ,Quitting byebug}).
|
1102
|
-
|
1103
|
-
Another way to terminate byebug is to use the @code{kill} command. This does the
|
1104
|
-
more forceful @code{kill -9}. It can be used in cases where @code{quit} doesn't
|
1105
|
-
work.
|
1106
|
-
|
1107
|
-
@node Calling from Program
|
1108
|
-
@section Calling byebug from inside your Ruby program
|
1109
|
-
|
1110
|
-
Running a program from byebug adds a bit of overhead and slows down your program
|
1111
|
-
a little. Furthermore, by necessity, debuggers change the operation of the
|
1112
|
-
program they are debugging. And this can lead to unexpected and unwanted
|
1113
|
-
differences. It has happened so often that the term ``Heisenbugs'' (see
|
1114
|
-
@url{http://en.wikipedia.org/wiki/Heisenbug}) was coined to describe the
|
1115
|
-
situation where using a debugger (among other possibilities) changes the
|
1116
|
-
behavior of the program so that the bug doesn't manifest itself anymore.
|
1117
|
-
|
1118
|
-
There is another way to get into byebug which adds no overhead or slowdown until
|
1119
|
-
you reach the point at which you want to start debugging. However here you must
|
1120
|
-
change the script and make an explicit call to byebug. Because byebug isn't
|
1121
|
-
involved before the first call, there is no overhead and the script will run
|
1122
|
-
at the same speed as if there were no byebug.
|
1123
|
-
|
1124
|
-
There are three parts to calling byebug from inside the script, ``requiring''
|
1125
|
-
the gem, telling byebug to start tracking things and then making an explicit
|
1126
|
-
breakpoints.
|
1127
|
-
|
1128
|
-
To get byebug class accessible from your Ruby program:
|
1129
|
-
@smallexample
|
1130
|
-
require 'byebug'
|
1131
|
-
@end smallexample
|
1132
|
-
|
1133
|
-
After @code{require 'byebug'}, it's possible to set some of the byebug variables
|
1134
|
-
influence preferences. For example if you want to have @code{byebug} run a
|
1135
|
-
@code{list} command every time it stops you set the variable
|
1136
|
-
@code{Byebug.settings[:autolist]}. @pxref{Byebug.settings} has a list of
|
1137
|
-
variable settings and the default values. Byebug settings can also be set in
|
1138
|
-
@code{.byebugrc} as byebug commands. @pxref{Command Files}
|
1139
|
-
|
1140
|
-
To tell byebug to start tracking things:
|
1141
|
-
@smallexample
|
1142
|
-
Byebug.start
|
1143
|
-
@end smallexample
|
1144
|
-
|
1145
|
-
There is also a @code{Byebug.stop} to turn off byebug tracking. If speed is
|
1146
|
-
crucial, you may want to start and stop this around certain sections of code.
|
1147
|
-
Alternatively, instead of issuing an explicit @code{Byebug.stop} you can add a
|
1148
|
-
block to the @code{Byebug.start} and debugging is turned on for that block. If
|
1149
|
-
the block of code raises an uncaught exception that would cause the block to
|
1150
|
-
terminate, the @code{stop} will occur. See @ref{Byebug.start with a block}.
|
1151
|
-
|
1152
|
-
And finally to enter byebug:
|
1153
|
-
@smallexample
|
1154
|
-
byebug
|
1155
|
-
@end smallexample
|
1156
|
-
|
1157
|
-
As indicated above, when @code{byebug} is run a @code{.byebugrc} profile is read
|
1158
|
-
if that file exists.
|
1159
|
-
|
1160
|
-
You may want to enter byebug at several points in the program where there is a
|
1161
|
-
problem you want to investigate. And since @code{byebug} is just a method call
|
1162
|
-
it's possible enclose it in a conditional expression, for example:
|
1163
|
-
@smallexample
|
1164
|
-
byebug if 'bar' == foo and 20 == iter_count
|
1165
|
-
@end smallexample
|
1166
|
-
|
1167
|
-
Although each step does a very specific thing which offers great flexibility, in
|
1168
|
-
order to make getting into byebug easier the three steps have been rolled into
|
1169
|
-
one command:
|
1170
|
-
@smallexample
|
1171
|
-
require "byebug/byebug"
|
1172
|
-
@end smallexample
|
1173
|
-
|
1174
|
-
@node Byebug Command Reference
|
1175
|
-
@chapter @code{byebug} Command Reference
|
1176
|
-
|
1177
|
-
@menu
|
1178
|
-
* Command Interfaces:: The kinds of interface used to interact with byebug
|
1179
|
-
* Command Syntax:: How to give commands to byebug
|
1180
|
-
* Command Output:: How byebug presents its output
|
1181
|
-
* Help:: How to ask for help (help)
|
1182
|
-
* Control:: Controlling byebug (quit, restart)
|
1183
|
-
* DisplayCommands:: Executing expressions on stop (display, undisplay)
|
1184
|
-
* PrintCommands:: Evaluating and Printing Expressions (p, pp, ps, pp, irb)
|
1185
|
-
* PrintVars:: Printing Variables (var)
|
1186
|
-
* List:: Examining Program Source Files (list)
|
1187
|
-
* Edit:: Editing source files (edit)
|
1188
|
-
* FrameCommands:: Examining the stack frame (where, up, down, frame)
|
1189
|
-
* Stopping:: Stopping and continuing (break, watch, step, cont...)
|
1190
|
-
* byebug settings:: byebug-settings (set args, set autoeval, ...)
|
1191
|
-
* Program Information:: Program Status (info)
|
1192
|
-
@end menu
|
1193
|
-
|
1194
|
-
@node Command Interfaces
|
1195
|
-
@section Command Interfaces
|
1196
|
-
There are several ways one can talk to @code{byebug} and get results. The
|
1197
|
-
simplest way is via a command-line interface directly talking to byebug. This is
|
1198
|
-
referred to below as a ``Local Interface''. It's also possible to run byebug and
|
1199
|
-
set up a port by which some other process can connect and control the debug
|
1200
|
-
session. This is called a ``Remote Interface''. When you want to gain access to
|
1201
|
-
a remote interface you need to run @code{byebug} using a ``Control Interface''.
|
1202
|
-
This interface might not be the same process as the process running the debugged
|
1203
|
-
program and might not even be running on the same computer.
|
1204
|
-
|
1205
|
-
Other front-ends may use one of these and build on top and provide other
|
1206
|
-
(richer) interfaces. Although many of the commands are available on all
|
1207
|
-
interfaces some are not. Most of the time in this manual when we talk about
|
1208
|
-
issuing commands describing the responses elicited, we'll assume we are working
|
1209
|
-
with the local interface.
|
1210
|
-
|
1211
|
-
@node Command Syntax
|
1212
|
-
@section Command Syntax
|
1213
|
-
Usually a command is put on a single line. There is no limit on how long it can
|
1214
|
-
be. It starts with a command name, which is followed by arguments whose meaning
|
1215
|
-
depends on the command name. For example, the command @code{step} accepts an
|
1216
|
-
argument which is the number of times to step, as in @code{step 5}. You can also
|
1217
|
-
use the @code{step} command with no arguments. Some commands do not allow any
|
1218
|
-
arguments.
|
1219
|
-
|
1220
|
-
Multiple commands can be put on a line by separating each with a semicolon
|
1221
|
-
(@code{;}). You can disable the meaning of a semicolon to separate commands by
|
1222
|
-
escaping it with a backslash.
|
1223
|
-
|
1224
|
-
For example, if you have @code{autoeval} (@ref{Autoeval}) set, you might want to
|
1225
|
-
enter the following code to compute the 5th Fibonacci number:
|
1226
|
-
@smallexample
|
1227
|
-
# Compute the 5 Fibonaci number
|
1228
|
-
(byebug:1) set autoeval on
|
1229
|
-
(byebug:1) fib1=0; fib2=1; 5.times @{|temp| temp=fib1; fib1=fib2; fib2 += temp @}
|
1230
|
-
SyntaxError Exception: compile error
|
1231
|
-
/usr/bin/irb:10: syntax error, unexpected $end, expecting '@}'
|
1232
|
-
5.times @{|temp| temp=fib1
|
1233
|
-
^
|
1234
|
-
(byebug:1) fib1=0\; fib2=1\; 5.times @{|temp| temp=fib1\; fib1=fib2\; fib2 += temp @}
|
1235
|
-
5
|
1236
|
-
(byebug:1) fib2
|
1237
|
-
fib2
|
1238
|
-
8
|
1239
|
-
@end smallexample
|
1240
|
-
|
1241
|
-
You might also consider using the @code{irb} command, @ref{irb}, and then you
|
1242
|
-
won't have to escape semicolons.
|
1243
|
-
|
1244
|
-
A blank line as input (typing just @key{<RET>}) means to repeat the previous
|
1245
|
-
command.
|
1246
|
-
|
1247
|
-
In the ``local'' interface, the Ruby Readline module is used. It handles line
|
1248
|
-
editing and retrieval of previous commands. Up arrow, for example moves to the
|
1249
|
-
previous byebug command; down arrow moves to the next more recent command
|
1250
|
-
(provided you are not already at the last command). Command history is saved in
|
1251
|
-
file @code{.byebug_hist}. A limit is put on the history size. You can see this
|
1252
|
-
with the @code{show history size} command. See @ref{History} for history
|
1253
|
-
parameters.
|
1254
|
-
|
1255
|
-
@node Command Output
|
1256
|
-
@section Command Output
|
1257
|
-
In the command-line interface, when @code{byebug} is waiting for input it
|
1258
|
-
presents a prompt of the form @code{(byebug)}. If the program has terminated
|
1259
|
-
normally the prompt will be @code{(byebug:ctrl)} and in post-mortem debugging it
|
1260
|
-
will be @code{(byebug:post-mortem)}.
|
1261
|
-
|
1262
|
-
In the local interface, whenever @code{byebug} gives an error message such as
|
1263
|
-
for an invalid command, or an invalid location position, it will generally
|
1264
|
-
preface the message with @code{***}.
|
1265
|
-
|
1266
|
-
@node Help
|
1267
|
-
@section Getting help (@samp{help})
|
1268
|
-
@cindex on-line documentation
|
1269
|
-
@menu
|
1270
|
-
* Help for Subcommands::
|
1271
|
-
@end menu
|
1272
|
-
|
1273
|
-
Once inside @code{byebug} you can always ask it for information on its commands
|
1274
|
-
using the @code{help} command.
|
1275
|
-
|
1276
|
-
@table @code
|
1277
|
-
@kindex h @r{(@code{help})}
|
1278
|
-
@kindex help @ovar{command-name}
|
1279
|
-
@item help
|
1280
|
-
@itemx h
|
1281
|
-
You can use @code{help} (abbreviated @code{h}) with no arguments to display a
|
1282
|
-
short list of named classes of commands:
|
1283
|
-
|
1284
|
-
@flushleft
|
1285
|
-
@smallexample
|
1286
|
-
(byebug:1) @b{help}
|
1287
|
-
byebug help v@value{BYEBUG_VERSION}
|
1288
|
-
Type 'help <command-name>' for help on a specific command
|
1289
|
-
|
1290
|
-
Available commands:
|
1291
|
-
backtrace delete enable help method ps save step where
|
1292
|
-
break disable eval info next putl set trace
|
1293
|
-
catch display exit irb p quit show undisplay
|
1294
|
-
condition down finish kill pp reload skip up
|
1295
|
-
continue edit frame list pry restart source var
|
1296
|
-
@end smallexample
|
1297
|
-
@end flushleft
|
1298
|
-
@c the above line break eliminates huge line overfull...
|
1299
|
-
|
1300
|
-
@end table
|
1301
|
-
|
1302
|
-
@table @code
|
1303
|
-
@item help @var{command}
|
1304
|
-
With a command name as @code{help} argument, @code{byebug} displays short
|
1305
|
-
information on how to use that command.
|
1306
|
-
|
1307
|
-
@smallexample
|
1308
|
-
(byebug:1) @b{help list}
|
1309
|
-
byebug help v@value{BYEBUG_VERSION}
|
1310
|
-
l[ist] list forward
|
1311
|
-
l[ist] - list backward
|
1312
|
-
l[ist] = list current line
|
1313
|
-
l[ist] nn-mm list given lines
|
1314
|
-
* NOTE - to turn on autolist, use 'set autolist'
|
1315
|
-
(byebug:1)
|
1316
|
-
@end smallexample
|
1317
|
-
@end table
|
1318
|
-
|
1319
|
-
@node Help for Subcommands
|
1320
|
-
@subsection Help on Subcommands
|
1321
|
-
A number of commands have many sub-parameters or @emph{subcommands}. These
|
1322
|
-
include @code{info}, @code{set}, @code{show}, @code{enable} and @code{disable}.
|
1323
|
-
|
1324
|
-
When you ask for help for one of these commands, you will get help for all of
|
1325
|
-
the subcommands that that command offers. Sometimes you may want help that
|
1326
|
-
subcommand and to do this just follow the command with its subcommand name. For
|
1327
|
-
example @code{help info breakpoints} will just give help about the
|
1328
|
-
@code{info breakpoints} command. Furthermore it will give longer help than the
|
1329
|
-
summary information that appears when you ask for help. You don't need to list
|
1330
|
-
the full subcommand name, but just enough of the letters to make that subcommand
|
1331
|
-
distinct from others will do. For example, @code{help info b} is the same as
|
1332
|
-
@code{help info breakpoints}.
|
1333
|
-
|
1334
|
-
Some examples follow.
|
1335
|
-
@example
|
1336
|
-
(byebug:1) @b{help info}
|
1337
|
-
Generic command for showing things about the program being debugged.
|
1338
|
-
--
|
1339
|
-
List of info subcommands:
|
1340
|
-
--
|
1341
|
-
info args -- Argument variables of current stack frame
|
1342
|
-
info breakpoints -- Status of user-settable breakpoints
|
1343
|
-
info catch -- Exceptions that can be caught in the current stack frame
|
1344
|
-
info display -- Expressions to display when program stops
|
1345
|
-
info file -- Info about a particular file read in
|
1346
|
-
info files -- File names and timestamps of files read in
|
1347
|
-
info global_variables -- Global variables
|
1348
|
-
info instance_variables -- Instance variables of the current stack frame
|
1349
|
-
info line -- Line number and file name of current position in source file
|
1350
|
-
info locals -- Local variables of the current stack frame
|
1351
|
-
info program -- Execution status of the program
|
1352
|
-
info stack -- Backtrace of the stack
|
1353
|
-
info variables -- Local and instance variables of the current stack frame
|
1354
|
-
@end example
|
1355
|
-
|
1356
|
-
@example
|
1357
|
-
(byebug:1) @b{help info breakpoints}
|
1358
|
-
Status of user-settable breakpoints.
|
1359
|
-
Without argument, list info about all breakpoints.
|
1360
|
-
With an integer argument, list info on that breakpoint.
|
1361
|
-
@end example
|
1362
|
-
|
1363
|
-
@example
|
1364
|
-
(byebug:1) @b{help info br}
|
1365
|
-
Status of user-settable breakpoints.
|
1366
|
-
Without argument, list info about all breakpoints.
|
1367
|
-
With an integer argument, list info on that breakpoint.
|
1368
|
-
@end example
|
1369
|
-
|
1370
|
-
@node Control
|
1371
|
-
@section Controlling byebug (@samp{quit}, @samp{restart}, @samp{source})
|
1372
|
-
|
1373
|
-
@menu
|
1374
|
-
* Quit:: Quitting byebug (quit)
|
1375
|
-
* Restart:: Restarting script execution (restart)
|
1376
|
-
* Source:: Running Byebug commands (source)
|
1377
|
-
@end menu
|
1378
|
-
|
1379
|
-
@node Quit
|
1380
|
-
@subsection Quit (@samp{quit})
|
1381
|
-
|
1382
|
-
@table @code
|
1383
|
-
@kindex quit @r{[}unconditionally@r{]}
|
1384
|
-
@kindex q @r{(@code{quit})}
|
1385
|
-
@item quit @r{[}unconditionally@r{]}
|
1386
|
-
@item exit
|
1387
|
-
@itemx q
|
1388
|
-
|
1389
|
-
To exit @code{byebug}, use the @code{quit} command (abbreviated @code{q}), or
|
1390
|
-
alias @code{exit}.
|
1391
|
-
|
1392
|
-
Normally if you are in an interactive session, this command will prompt to ask
|
1393
|
-
if you really want to quit. If you don't want any questions asked, enter
|
1394
|
-
``unconditionally''.
|
1395
|
-
@end table
|
1396
|
-
|
1397
|
-
@node Restart
|
1398
|
-
@subsection Restarting script execution (@samp{restart})
|
1399
|
-
|
1400
|
-
@table @code
|
1401
|
-
@kindex restart @r{[}@var{program args}@r{]}
|
1402
|
-
@kindex R @r{(@code{restart})}
|
1403
|
-
@item restart
|
1404
|
-
@itemx R
|
1405
|
-
Restart the program. This is a re-exec - all byebug state is lost. If command
|
1406
|
-
arguments are passed those are used. Otherwise program arguments from the last
|
1407
|
-
invocation are used.
|
1408
|
-
|
1409
|
-
You won't be able to restart your program in all cases. First, the program
|
1410
|
-
should have been invoked at the outset rather than having been called from
|
1411
|
-
inside your program or invoked as a result of post-mortem handling.
|
1412
|
-
|
1413
|
-
Also, since this relies on the the OS @code{exec} call, this command is
|
1414
|
-
available only if your OS supports @code{exec}; OSX for example does not (yet).
|
1415
|
-
@end table
|
1416
|
-
|
1417
|
-
@node Source
|
1418
|
-
@subsection Running Byebug Commands (@samp{source})
|
1419
|
-
|
1420
|
-
@table @code
|
1421
|
-
@kindex source @var{filename}
|
1422
|
-
@item source @var{filename}
|
1423
|
-
Execute the command file @var{filename}.
|
1424
|
-
|
1425
|
-
The lines in a command file are executed sequentially. They are not printed as
|
1426
|
-
they are executed. If there is an error, execution proceeds to the next command
|
1427
|
-
in the file. For information about command files that get run automatically on
|
1428
|
-
startup, @pxref{Command Files}.
|
1429
|
-
@end table
|
1430
|
-
|
1431
|
-
@node DisplayCommands
|
1432
|
-
@section Executing expressions on stop (@samp{display}, @samp{undisplay})
|
1433
|
-
@cindex automatic display
|
1434
|
-
@cindex display of expressions
|
1435
|
-
|
1436
|
-
If you find that you want to print the value of an expression frequently (to see
|
1437
|
-
how it changes), you might want to add it to the @dfn{automatic display list} so
|
1438
|
-
that @code{byebug} evaluates a statement each time your program stops or the
|
1439
|
-
statement is shown in line tracing. Each expression added to the list is given a
|
1440
|
-
number to identify it; to remove an expression from the list, you specify that
|
1441
|
-
number. The automatic display looks like this:
|
1442
|
-
|
1443
|
-
@smallexample
|
1444
|
-
(byebug:1) display n
|
1445
|
-
1: n = 3
|
1446
|
-
@end smallexample
|
1447
|
-
|
1448
|
-
@noindent
|
1449
|
-
This display shows item numbers, expressions and their current values. If the
|
1450
|
-
expression is undefined or illegal the expression will be printed but no value
|
1451
|
-
will appear.
|
1452
|
-
|
1453
|
-
@smallexample
|
1454
|
-
(byebug:1) display undefined_variable
|
1455
|
-
2: undefined_variable =
|
1456
|
-
(byebug:1) display 1/0
|
1457
|
-
3: 1/0 =
|
1458
|
-
@end smallexample
|
1459
|
-
|
1460
|
-
Note: this command uses @code{to_s} in expressions; for example an array
|
1461
|
-
@code{[1, 2]} will appear as @code{12}. For some datatypes like an Array, you
|
1462
|
-
may want to call the @code{inspect} method, for example
|
1463
|
-
@code{display ARGV.inspect} rather than @code{display ARGV}.
|
1464
|
-
|
1465
|
-
@table @code
|
1466
|
-
@kindex display @ovar{expr}
|
1467
|
-
@item display @var{expr}
|
1468
|
-
Add the expression @var{expr} to the list of expressions to display each time
|
1469
|
-
your program stops or a line is printed when linetracing is on
|
1470
|
-
(@pxref{DisplayCommands}).
|
1471
|
-
|
1472
|
-
@item display
|
1473
|
-
Display the current values of the expressions on the list, just as is done when
|
1474
|
-
your program stops.
|
1475
|
-
|
1476
|
-
@kindex undisplay @ovar{num}
|
1477
|
-
@item undisplay @ovar{num}
|
1478
|
-
@itemx delete display @var{num}
|
1479
|
-
Remove item number @var{num} from the list of expressions to display.
|
1480
|
-
|
1481
|
-
@kindex info display
|
1482
|
-
@item info display
|
1483
|
-
Show all display expressions
|
1484
|
-
|
1485
|
-
@ifset GDB_COMPLETED
|
1486
|
-
@code{undisplay} does not repeat if you press @key{RET} after using it.
|
1487
|
-
(Otherwise you would just get the error @samp{No display number @dots{}}.)
|
1488
|
-
@end ifset
|
1489
|
-
|
1490
|
-
@kindex disable display
|
1491
|
-
@item disable display @var{dnums}@dots{}
|
1492
|
-
Disable the display of item numbers @var{dnums}. A disabled display item is not
|
1493
|
-
printed automatically, but is not forgotten. It may be enabled again later.
|
1494
|
-
|
1495
|
-
@kindex enable display
|
1496
|
-
@item enable display @var{dnums}@dots{}
|
1497
|
-
Enable display of item numbers @var{dnums}. It becomes effective once again in
|
1498
|
-
auto display of its expression, until you specify otherwise.
|
1499
|
-
|
1500
|
-
@end table
|
1501
|
-
|
1502
|
-
@node PrintCommands
|
1503
|
-
@section Evaluating and Printing Expressions (@samp{p}, @samp{pp}, @samp{putl}, @samp{ps}, @samp{irb})
|
1504
|
-
|
1505
|
-
One way to examine and change data in your script is with the @code{eval}
|
1506
|
-
command (abbreviated @code{p}). A similar command is @code{pp} which tries to
|
1507
|
-
pretty print the result. Finally @code{irb} is useful when you anticipate
|
1508
|
-
examining or changing a number of things and prefer not to have to preface each
|
1509
|
-
command, but rather work as one does in @code{irb}.
|
1510
|
-
|
1511
|
-
@menu
|
1512
|
-
* eval:: eval or print an expression (eval, p)
|
1513
|
-
* pp:: pretty print an expression (pp, ps, putl)
|
1514
|
-
* irb:: running irb using the current context
|
1515
|
-
@end menu
|
1516
|
-
|
1517
|
-
@node eval
|
1518
|
-
@subsection Printing an expression (@samp{eval}, @samp{p})
|
1519
|
-
@table @code
|
1520
|
-
@kindex eval @var{expr}
|
1521
|
-
@kindex p @r{(@code{eval})}
|
1522
|
-
@item eval @var{expr}
|
1523
|
-
@itemx p @var{expr}
|
1524
|
-
|
1525
|
-
Use @code{eval} or @code{p} to evaluate a Ruby expression, @var{expr}, same as
|
1526
|
-
you would if you were in @code{irb}. If there are many expressions you want to
|
1527
|
-
look at, you may want to go into irb from byebug.
|
1528
|
-
|
1529
|
-
@smallexample
|
1530
|
-
@group
|
1531
|
-
(byebug:p) p n
|
1532
|
-
3
|
1533
|
-
(byebug:1) p "the value of n is #@{n@}"
|
1534
|
-
"the value of n is 3"
|
1535
|
-
(byebug:1)
|
1536
|
-
@end group
|
1537
|
-
@end smallexample
|
1538
|
-
@end table
|
1539
|
-
|
1540
|
-
@node pp
|
1541
|
-
@subsection Pretty-Printing an expression (@samp{pp}, @samp{putl}, @samp{ps}))
|
1542
|
-
@table @code
|
1543
|
-
@item pp
|
1544
|
-
@kindex pp @var{expr}
|
1545
|
-
Evaluates and pretty-prints @var{expr}
|
1546
|
-
@smallexample
|
1547
|
-
@group
|
1548
|
-
(byebug:1) @b{p $LOAD_PATH}
|
1549
|
-
["/home/rocky/lib/ruby", "/usr/lib/ruby/site_ruby/1.8", "/usr/lib/ruby/site_ruby/1.8/i586-linux", "/usr/lib/ruby/1.8"]
|
1550
|
-
(byebug:1) @b{pp $LOAD_PATH}
|
1551
|
-
["/home/rocky/lib/ruby",
|
1552
|
-
"/usr/lib/ruby/site_ruby/1.8",
|
1553
|
-
"/usr/lib/ruby/site_ruby/1.8/i586-linux",
|
1554
|
-
"/usr/lib/ruby/1.8"]
|
1555
|
-
@end group
|
1556
|
-
@end smallexample
|
1557
|
-
|
1558
|
-
@kindex putl
|
1559
|
-
@item putl
|
1560
|
-
If the value you want to print is an array, sometimes a columnized list looks
|
1561
|
-
nicer:
|
1562
|
-
@smallexample
|
1563
|
-
@group
|
1564
|
-
(byebug:1) @b{putl $LOAD_PATH}
|
1565
|
-
/home/rocky/lib/ruby /usr/lib/ruby/site_ruby/1.8
|
1566
|
-
/usr/lib/ruby/site_ruby/1.8/i586-linux /usr/lib/ruby/1.8
|
1567
|
-
@end group
|
1568
|
-
@end smallexample
|
1569
|
-
|
1570
|
-
Note however that entries are sorted to run down first rather than across. So
|
1571
|
-
in the example above the second entry in the list is
|
1572
|
-
@code{/usr/lib/ruby/site_ruby/1.8/i586-linux} and the @emph{third} entry is
|
1573
|
-
@code{/usr/lib/ruby/site_ruby/1.8}.
|
1574
|
-
|
1575
|
-
If the value is not an array @code{putl} will just call pretty-print.
|
1576
|
-
|
1577
|
-
@kindex ps
|
1578
|
-
@item ps
|
1579
|
-
Sometimes you may want to print the array not only columnized, but sorted as
|
1580
|
-
well. The list of byebug help commands appears this way, and so does the output
|
1581
|
-
of the @code{method} commands.
|
1582
|
-
|
1583
|
-
@smallexample
|
1584
|
-
@group
|
1585
|
-
(byebug:1) ps Kernel.private_methods
|
1586
|
-
Digest initialize y
|
1587
|
-
Pathname initialize_copy
|
1588
|
-
Rational location_of_caller
|
1589
|
-
active_gem_with_options method_added
|
1590
|
-
alias_method method_removed
|
1591
|
-
append_features method_undefined
|
1592
|
-
attr module_function
|
1593
|
-
attr_accessor private
|
1594
|
-
attr_reader protected
|
1595
|
-
attr_writer public
|
1596
|
-
class_variable_get remove_class_variable
|
1597
|
-
class_variable_set remove_const
|
1598
|
-
define_method remove_instance_variable
|
1599
|
-
extend_object remove_method
|
1600
|
-
extended singleton_method_added
|
1601
|
-
gcd singleton_method_removed
|
1602
|
-
gem_original_require singleton_method_undefined
|
1603
|
-
include timeout
|
1604
|
-
included undef_method
|
1605
|
-
@end group
|
1606
|
-
@end smallexample
|
1607
|
-
|
1608
|
-
If the value is not an array, @code{ps} will just call pretty-print. See also
|
1609
|
-
the @code{methods}.
|
1610
|
-
@end table
|
1611
|
-
|
1612
|
-
@node irb
|
1613
|
-
@subsection Run irb (@samp{irb})
|
1614
|
-
@table @code
|
1615
|
-
@kindex irb
|
1616
|
-
@item irb
|
1617
|
-
Run an interactive ruby session (@code{irb}) with the bindings environment set
|
1618
|
-
to the state you are in the program.
|
1619
|
-
|
1620
|
-
When you leave irb and go back to byebug command prompt we show again the file,
|
1621
|
-
line and text position of the program in the same way as when entered byebug. If
|
1622
|
-
you issue a @command{list} without location information, the default location
|
1623
|
-
used is the current line rather than the position may have gotten updated via a
|
1624
|
-
prior @command{list} command.
|
1625
|
-
|
1626
|
-
@smallexample
|
1627
|
-
triangle.rb:4
|
1628
|
-
def triangle(n)
|
1629
|
-
(byebug:1) @b{list}
|
1630
|
-
[1, 8] in /home/rocky/ruby/triangle.rb
|
1631
|
-
1 #!/usr/bin/env ruby
|
1632
|
-
2 # Compute the n'th triangle number - the hard way
|
1633
|
-
3 # triangle(n) == (n * (n+1)) / 2
|
1634
|
-
=> 4 def triangle(n)
|
1635
|
-
5 tri = 0
|
1636
|
-
6 0.upto(n) do |i|
|
1637
|
-
7 tri += i
|
1638
|
-
8 end
|
1639
|
-
@b{irb}
|
1640
|
-
>> @b{(0..6).inject@{|sum, i| sum +=i@}}
|
1641
|
-
=> 21
|
1642
|
-
>> @b{exit}
|
1643
|
-
triangle.rb:4
|
1644
|
-
def triangle(n)
|
1645
|
-
(byebug:1) @b{list # Note we get the same line range as before going into irb}
|
1646
|
-
[1, 8] in /home/rocky/ruby/triangle.rb
|
1647
|
-
1 #!/usr/bin/env ruby
|
1648
|
-
2 # Compute the n'th triangle number - the hard way
|
1649
|
-
3 # triangle(n) == (n * (n+1)) / 2
|
1650
|
-
=> 4 def triangle(n)
|
1651
|
-
5 tri = 0
|
1652
|
-
6 0.upto(n) do |i|
|
1653
|
-
7 tri += i
|
1654
|
-
8 end
|
1655
|
-
@end smallexample
|
1656
|
-
|
1657
|
-
@end table
|
1658
|
-
|
1659
|
-
@node PrintVars
|
1660
|
-
@section Printing Variables (@samp{var}, @samp{method})
|
1661
|
-
|
1662
|
-
@table @code
|
1663
|
-
@item var const @var{object}
|
1664
|
-
@kindex var const @var{expr}
|
1665
|
-
Show the constants of @var{object}. This is basically listing
|
1666
|
-
variables and their values in @var{object}@code{.constant}.
|
1667
|
-
@item var instance @var{object}
|
1668
|
-
@kindex var instance @var{expr}
|
1669
|
-
Show the instance variables of @var{object}. This is basically listing
|
1670
|
-
@var{object}@code{.instance_variables}.
|
1671
|
-
@item info instance_variables
|
1672
|
-
@kindex info instance_variables
|
1673
|
-
Show instance_variables of @code{@@self}
|
1674
|
-
@item info locals
|
1675
|
-
@kindex info locals
|
1676
|
-
Show local variables
|
1677
|
-
@item info globals
|
1678
|
-
@kindex info globals
|
1679
|
-
Show global variables
|
1680
|
-
@item info variables
|
1681
|
-
@kindex info variables
|
1682
|
-
Show local and instance variables of @code{@@self}
|
1683
|
-
@item method instance @var{object}
|
1684
|
-
@kindex method instance @var{object}
|
1685
|
-
Show methods of @var{object}. Basically this is the same as running
|
1686
|
-
@code{ps object.instance_methods(false)} on @var{object}.
|
1687
|
-
@item method iv @var{object}
|
1688
|
-
@kindex method iv @var{object}
|
1689
|
-
Show method instance variables of @var{object}. Basically this is the same as
|
1690
|
-
running
|
1691
|
-
@smallexample
|
1692
|
-
obj.instance_variables.each do |v|
|
1693
|
-
puts "%s = %s\n" % [v, obj.instance_variable_get(v)]
|
1694
|
-
end
|
1695
|
-
@end smallexample
|
1696
|
-
on @var{object}.
|
1697
|
-
@item signature @var{object}
|
1698
|
-
@kindex method signature @var{object}
|
1699
|
-
Show procedure signature of method @var{object}.
|
1700
|
-
@emph{This command is available only if the nodewrap is installed.}
|
1701
|
-
@smallexample
|
1702
|
-
def mymethod(a, b=5, &bock)
|
1703
|
-
end
|
1704
|
-
(byebug:1) @b{method sig mymethod}
|
1705
|
-
Mine#mymethod(a, b=5, &bock)
|
1706
|
-
@end smallexample
|
1707
|
-
on @var{object}.
|
1708
|
-
@item method @var{class-or-module}
|
1709
|
-
@kindex method @var{class-or-module}
|
1710
|
-
Show methods of the class or module, @var{class-or-module}. Basically this is
|
1711
|
-
the same as running @code{ps object.methods} on @var{class-or-module}.
|
1712
|
-
@end table
|
1713
|
-
|
1714
|
-
@node List
|
1715
|
-
@section Examining Program Source Files (@samp{list})
|
1716
|
-
|
1717
|
-
@cindex current line
|
1718
|
-
@code{byebug} can print parts of your script's source. When your script stops,
|
1719
|
-
@code{byebug} spontaneously prints the line where it stopped and the text of
|
1720
|
-
that line. Likewise, when you select a stack frame (@pxref{Selection})
|
1721
|
-
@code{byebug} prints the line where execution in that frame has stopped.
|
1722
|
-
Implicitly there is a default line location. Each time a list command is run
|
1723
|
-
that implicit location is updated, so that running several list commands in
|
1724
|
-
succession shows a contiguous block of program text.
|
1725
|
-
|
1726
|
-
If you don't need code context displayed every time, you can issue the @code{set
|
1727
|
-
noautolist} command. Now whenever you want code listed, you can explicitly issue
|
1728
|
-
the @code{list} or it abbreviation @code{l}. Notice that a second listing is
|
1729
|
-
displayed, we continue listing from the place we last left off. The desired
|
1730
|
-
range of lines this time is lines 9 to 18; but since the program ends at line
|
1731
|
-
13, the range is moved down so 10 lines can be shown. You can set the
|
1732
|
-
@code{noautolist} option by default by dropping @code{set noautolist} in
|
1733
|
-
byebug's startup file @code{.byebugrc}.
|
1734
|
-
|
1735
|
-
If you want to set how many lines to print by default rather than use the
|
1736
|
-
initial number of lines, 10, use the @code{set listsize} command
|
1737
|
-
(@pxref{Listsize}). To see the entire program in one shot, we gave an explicit
|
1738
|
-
starting and ending line number.
|
1739
|
-
|
1740
|
-
You can print other portions of source files by giving an explicit position as a
|
1741
|
-
parameter to the list command.
|
1742
|
-
|
1743
|
-
@kindex list @ovar{line-number}
|
1744
|
-
@kindex l @r{(@code{list})}
|
1745
|
-
To print lines from a source file, use the @code{list} command
|
1746
|
-
(abbreviated @code{l}). By default, ten lines are printed. Fewer may
|
1747
|
-
appear if there fewer lines before or after the current line to center
|
1748
|
-
the listing around.
|
1749
|
-
|
1750
|
-
There are several ways to specify what part of the file you want to print.
|
1751
|
-
Here are the forms of the @code{list} command.
|
1752
|
-
|
1753
|
-
@table @code
|
1754
|
-
@item list @var{line-number}
|
1755
|
-
@itemx l @var{line-number}
|
1756
|
-
Print lines centered around line number @var{line-number} in the
|
1757
|
-
current source file.
|
1758
|
-
|
1759
|
-
@item list
|
1760
|
-
@itemx l
|
1761
|
-
Print more lines. If the last lines printed were printed with a
|
1762
|
-
@code{list} command, this prints lines following the last lines
|
1763
|
-
printed; however, if the last line printed was a solitary line printed
|
1764
|
-
as part of displaying a stack frame (@pxref{Frames}), this prints lines
|
1765
|
-
centered around that line.
|
1766
|
-
|
1767
|
-
@item list -
|
1768
|
-
@itemx l -
|
1769
|
-
Print lines just before the lines last printed.
|
1770
|
-
@item list @var{first}-@var{last}
|
1771
|
-
Print lines between @var{first} and @var{last} inclusive.
|
1772
|
-
|
1773
|
-
@item list =
|
1774
|
-
Print lines centered around where the script is stopped.
|
1775
|
-
@end table
|
1776
|
-
|
1777
|
-
Repeating a @code{list} command with @key{RET} discards the argument, so it is
|
1778
|
-
equivalent to typing just @code{list}. This is more useful than listing the
|
1779
|
-
same lines again. An exception is made for an argument of @samp{-}; that
|
1780
|
-
argument is preserved in repetition so that each repetition moves up in the
|
1781
|
-
source file.
|
1782
|
-
|
1783
|
-
@node Edit
|
1784
|
-
@section Editing Source files (@samp{edit})
|
1785
|
-
|
1786
|
-
To edit the lines in a source file, use the @code{edit} command. The editing
|
1787
|
-
program of your choice is invoked with the current line set to the active line
|
1788
|
-
in the program. Alternatively, you can give a line specification to specify
|
1789
|
-
what part of the file you want to print if you want to see other parts of the
|
1790
|
-
program.
|
1791
|
-
|
1792
|
-
You can customize to use any editor you want by using the @code{EDITOR}
|
1793
|
-
environment variable. The only restriction is that your editor (say @code{ex})
|
1794
|
-
recognizes the following command-line syntax:
|
1795
|
-
@smallexample
|
1796
|
-
ex +@var{number} file
|
1797
|
-
@end smallexample
|
1798
|
-
The optional numeric value +@var{number} specifies the number of the line in the
|
1799
|
-
file where to start editing. For example, to configure @code{byebug} to use the
|
1800
|
-
@code{vi} editor, you could use these commands with the @code{sh} shell:
|
1801
|
-
|
1802
|
-
@smallexample
|
1803
|
-
EDITOR=/usr/bin/vi
|
1804
|
-
export EDITOR
|
1805
|
-
gdb @dots{}
|
1806
|
-
@end smallexample
|
1807
|
-
or in the @code{csh} shell,
|
1808
|
-
@smallexample
|
1809
|
-
setenv EDITOR /usr/bin/vi
|
1810
|
-
gdb @dots{}
|
1811
|
-
@end smallexample
|
1812
|
-
|
1813
|
-
@table @code
|
1814
|
-
@kindex edit @ovar{line-specification}
|
1815
|
-
@item edit @ovar{line specification}
|
1816
|
-
Edit line specification using the editor specified by the @code{EDITOR}
|
1817
|
-
environment variable.
|
1818
|
-
@end table
|
1819
|
-
|
1820
|
-
@node FrameCommands
|
1821
|
-
@section Examining the Stack Frame (@samp{where}, @samp{up}, @samp{down}, @samp{frame})
|
1822
|
-
|
1823
|
-
When your script has stopped, one thing you'll probably want to know is where it
|
1824
|
-
stopped and some idea of how it got there.
|
1825
|
-
|
1826
|
-
@cindex call stack
|
1827
|
-
Each time your script performs a function or sends a message to a method, or
|
1828
|
-
enters a block, information about this action is saved. The frame stack then is
|
1829
|
-
a history of the blocks that got you to the point that you are currently stopped
|
1830
|
-
at.@footnote{More accurately we should call this a ``block stack''; but we'll
|
1831
|
-
use the name that is more commonly used. And internally in Ruby, there is
|
1832
|
-
``FRAME'' structure which is yet slightly different.}
|
1833
|
-
|
1834
|
-
@cindex selected block
|
1835
|
-
One entry in call stack is @dfn{selected} by @code{byebug} and many
|
1836
|
-
@code{byebug} commands refer implicitly to the selected block. In particular,
|
1837
|
-
whenever you ask @code{byebug} to list lines without giving a line number or
|
1838
|
-
location the value is found in the selected frame. There are special
|
1839
|
-
@code{byebug} commands to select whichever frame you are interested in.
|
1840
|
-
@xref{Selection, ,Selecting a frame}.
|
1841
|
-
|
1842
|
-
When your program stops, @code{byebug} automatically selects the currently
|
1843
|
-
executing frame and describes it briefly, similarly to the @code{frame} command.
|
1844
|
-
|
1845
|
-
After switching frames, when you issue a @code{list} command without any
|
1846
|
-
position information, the position used is the location in the frame that you
|
1847
|
-
just switched to, rather than a location that got updated via a prior
|
1848
|
-
@code{list} command.
|
1849
|
-
|
1850
|
-
@menu
|
1851
|
-
* Frames:: Stack frames
|
1852
|
-
* Backtrace:: Backtraces (where)
|
1853
|
-
* Selection:: Selecting a frame (up, down, frame)
|
1854
|
-
@end menu
|
1855
|
-
|
1856
|
-
@node Frames
|
1857
|
-
@subsection Stack frames
|
1858
|
-
|
1859
|
-
@cindex frame, definition
|
1860
|
-
@cindex stack frame
|
1861
|
-
The block stack is divided up into contiguous pieces called @dfn{stack frames},
|
1862
|
-
@dfn{frames}, or @dfn{blocks} for short; each frame/block has a scope associated
|
1863
|
-
with itr. It contains a line number and the source-file name that the line
|
1864
|
-
refers to. If the frame/block is the beginning of a method or function it also
|
1865
|
-
contains the function name.
|
1866
|
-
|
1867
|
-
@cindex initial frame
|
1868
|
-
@cindex outermost frame
|
1869
|
-
@cindex innermost frame
|
1870
|
-
When your script is started, the stack has only one frame, that of the function
|
1871
|
-
@code{main}. This is called the @dfn{initial} frame or the @dfn{outermost}
|
1872
|
-
frame. Each time a function is called, a new frame is made. Each time a function
|
1873
|
-
returns, the frame for that function invocation is eliminated. If a function is
|
1874
|
-
recursive, there can be many frames for the same function. The frame for the
|
1875
|
-
function in which execution is actually occurring is called the @dfn{innermost}
|
1876
|
-
frame. This is the most recently created of all the stack frames that still
|
1877
|
-
exist.
|
1878
|
-
|
1879
|
-
@cindex frame number
|
1880
|
-
@code{byebug} assigns numbers to all existing stack frames, starting with zero
|
1881
|
-
for the innermost frame, one for the frame that called it, and so on upward.
|
1882
|
-
These numbers do not really exist in your script; they are assigned by
|
1883
|
-
@code{byebug} to give you a way of designating stack frames inside commands.
|
1884
|
-
|
1885
|
-
@node Backtrace
|
1886
|
-
@subsection Backtraces (@samp{where})
|
1887
|
-
|
1888
|
-
@cindex backtraces
|
1889
|
-
@cindex tracebacks
|
1890
|
-
@cindex stack traces
|
1891
|
-
A backtrace is essentially the same as the call stack: a summary of how your
|
1892
|
-
script got where it is. It shows one line per frame, for many frames, starting
|
1893
|
-
with the place that you are stopped at (frame zero), followed by its caller
|
1894
|
-
(frame one), and on up the stack.
|
1895
|
-
|
1896
|
-
@table @code
|
1897
|
-
@kindex where
|
1898
|
-
@kindex w @r{(@code{where})}
|
1899
|
-
@itemx where
|
1900
|
-
Print the entire stack frame; @code{info stack} is an alias for this command.
|
1901
|
-
Each frame is numbered and can be referred to in the @code{frame} command;
|
1902
|
-
@code{up} and @code{down} add or subtract respectively to frame numbers shown. The position of the current frame is marked with
|
1903
|
-
@code{-->}.
|
1904
|
-
|
1905
|
-
@smallexample
|
1906
|
-
(byebug:1) where
|
1907
|
-
--> #0 Object.gcd(a#Fixnum, b#Fixnum) at /tmp/gcd.rb:6
|
1908
|
-
#1 at /tmp/gcd.rb:19
|
1909
|
-
@end smallexample
|
1910
|
-
|
1911
|
-
@ifset FINISHED
|
1912
|
-
@item backtrace @var{n}
|
1913
|
-
@itemx bt @var{n}
|
1914
|
-
@itemx where @var{n}
|
1915
|
-
@itemx T @var{n}
|
1916
|
-
Similar, but print only the innermost @var{n} frames.
|
1917
|
-
|
1918
|
-
@item backtrace -@var{n}
|
1919
|
-
@itemx bt -@var{n}
|
1920
|
-
@itemx where -@var{n}
|
1921
|
-
@itemx T -@var{n}
|
1922
|
-
Similar, but print only the outermost @var{n} frames.
|
1923
|
-
@end ifset
|
1924
|
-
@end table
|
1925
|
-
|
1926
|
-
@node Selection
|
1927
|
-
@subsection Selecting a frame (@samp{up}, @samp{down}, @samp{frame})
|
1928
|
-
Commands for listing source code in your script work on whichever stack frame is
|
1929
|
-
selected at the moment. Here are the commands for selecting a stack frame; all
|
1930
|
-
of them finish by printing a brief description of the stack frame just selected.
|
1931
|
-
|
1932
|
-
@table @code
|
1933
|
-
@kindex up @ovar{n}
|
1934
|
-
@item up @ovar{n}
|
1935
|
-
Move @var{n} frames up the stack. For positive numbers @var{n}, this advances
|
1936
|
-
toward the outermost frame, to higher frame numbers, to frames that have existed
|
1937
|
-
longer. Using a negative @var{n} is the same thing as issuing a @code{down}
|
1938
|
-
command of the absolute value of the @var{n}. Using zero for @var{n} does no
|
1939
|
-
frame adjustment, but since the current position is redisplayed, it may trigger
|
1940
|
-
a resynchronization if there is a front end also watching over things.
|
1941
|
-
|
1942
|
-
@var{n} defaults to one. You may abbreviate @code{up} as @code{u}.
|
1943
|
-
|
1944
|
-
@kindex down @ovar{n}
|
1945
|
-
@item down @ovar{n}
|
1946
|
-
Move @var{n} frames down the stack. For positive numbers @var{n}, this advances
|
1947
|
-
towards the innermost frame, to lower frame numbers, to frames that were created
|
1948
|
-
more recently. Using a negative @var{n} is the same as issuing a @code{up}
|
1949
|
-
command of the absolute value of the @var{n}. Using zero for @var{n} does no
|
1950
|
-
frame adjustment, but since the current position is redisplayed, it may trigger
|
1951
|
-
a resynchronization if there is a front end also watching over things.
|
1952
|
-
|
1953
|
-
@var{n} defaults to one.
|
1954
|
-
@end table
|
1955
|
-
|
1956
|
-
@table @code
|
1957
|
-
@kindex frame @r{[} @ovar{n}@r{]}
|
1958
|
-
@cindex current stack frame
|
1959
|
-
@item frame@r{[} @ovar{n}@r{]}
|
1960
|
-
The @code{frame} command allows you to move from one stack frame to another, and
|
1961
|
-
to print the stack frame you select. @var{n} is the the stack frame number or 0
|
1962
|
-
if no frame number is given; @code{frame 0} then will always show the current
|
1963
|
-
and most recent stack frame.
|
1964
|
-
|
1965
|
-
If a negative number is given, counting is from the other end of the stack
|
1966
|
-
frame, so @code{frame -1} shows the least-recent, outermost or most ``main''
|
1967
|
-
stack frame.
|
1968
|
-
|
1969
|
-
Without an argument, @code{frame} prints the current stack frame. Since the
|
1970
|
-
current position is redisplayed, it may trigger a resynchronization if there is
|
1971
|
-
a front end also watching over things.
|
1972
|
-
@end table
|
1973
|
-
|
1974
|
-
@node Stopping
|
1975
|
-
@section Stopping and Resuming Execution
|
1976
|
-
One important use of a debugger is to stop your program @emph{before} it
|
1977
|
-
terminates, so that if your script runs into trouble you can investigate and
|
1978
|
-
find out why. However should your script accidentally continue to termination,
|
1979
|
-
it can be arranged for @code{byebug} to not to leave byebug without your
|
1980
|
-
explicit instruction. That way, you can restart the program using the same
|
1981
|
-
command arguments.
|
1982
|
-
|
1983
|
-
Inside @code{byebug}, your script may stop for any of several reasons, such as a
|
1984
|
-
signal, a breakpoint, or reaching a new line after a @code{byebug} command such
|
1985
|
-
as @code{step}. You may then examine and change variables, set new breakpoints
|
1986
|
-
or remove old ones, and then continue execution.
|
1987
|
-
|
1988
|
-
@menu
|
1989
|
-
* Breakpoints:: Breakpoints (break, catch, delete)
|
1990
|
-
* Disabling:: Disabling breakpoints (disable, enable)
|
1991
|
-
* Conditions:: Break conditions (condition)
|
1992
|
-
* Resuming Execution:: Resuming execution (continue, step, next, finish)
|
1993
|
-
@end menu
|
1994
|
-
|
1995
|
-
@node Breakpoints
|
1996
|
-
@subsection Breakpoints (@samp{break}, @samp{catch}, @samp{delete})
|
1997
|
-
|
1998
|
-
@cindex breakpoints
|
1999
|
-
A @dfn{breakpoint} makes your script stop whenever a certain point in the
|
2000
|
-
program is reached. For each breakpoint, you can add conditions to control in
|
2001
|
-
finer detail whether your script stops. You specify the place where your script
|
2002
|
-
should stop with the @code{break} command and its variants.
|
2003
|
-
|
2004
|
-
@cindex breakpoint numbers
|
2005
|
-
@cindex numbers for breakpoints
|
2006
|
-
@code{byebug} assigns a number to each breakpoint when you create it; these
|
2007
|
-
numbers are successive integers starting with one. In many of the commands for
|
2008
|
-
controlling various features of breakpoints you use the breakpoint number to say
|
2009
|
-
which breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
|
2010
|
-
@dfn{disabled}; if disabled, it has no effect on your script until you enable it
|
2011
|
-
again.
|
2012
|
-
|
2013
|
-
|
2014
|
-
@table @code
|
2015
|
-
@kindex break @ovar{location}
|
2016
|
-
@kindex b @r{(@code{break})}
|
2017
|
-
@item break
|
2018
|
-
Set a breakpoint at the current line.
|
2019
|
-
|
2020
|
-
@item break @var{linenum}
|
2021
|
-
Set a breakpoint at line @var{linenum} in the current source file. The current
|
2022
|
-
source file is the last file whose source text was printed. The breakpoint will
|
2023
|
-
stop your script just before it executes any of the code on that line.
|
2024
|
-
|
2025
|
-
@item break @var{filename}:@var{linenum}
|
2026
|
-
Set a breakpoint at line @var{linenum} in source file @var{filename}.
|
2027
|
-
|
2028
|
-
What may be a little tricky when specifying the filename is getting the name
|
2029
|
-
recognized by @code{byebug}. If you get a message the message ``@code{No source
|
2030
|
-
file named ...}'', then you may need to qualify the name more fully. To see what
|
2031
|
-
files are loaded you can use the @code{info files} or @code{info file} commands.
|
2032
|
-
If you want the name @code{byebug} thinks of as the current file, use
|
2033
|
-
@code{info line}.
|
2034
|
-
|
2035
|
-
Here's an example:
|
2036
|
-
@example
|
2037
|
-
$ @b{byebug ~/ruby/gcd.rb 3 5}
|
2038
|
-
/home/rocky/ruby/gcd.rb:4 # Note this is the file name
|
2039
|
-
def gcd(a, b)
|
2040
|
-
(byebug:1) @b{break gcd.rb:6}
|
2041
|
-
*** No source file named gcd.rb
|
2042
|
-
(byebug:1) @b{info line}
|
2043
|
-
Line 4 of "/home/rocky/ruby/gcd.rb"
|
2044
|
-
(byebug:1) @b{break /home/rocky/ruby/gcd.rb:6}
|
2045
|
-
Breakpoint 1 file /home/rocky/ruby/gcd.rb, line 6
|
2046
|
-
(byebug:1) @b{break ~/ruby/gcd.rb:10} # tilde expansion also works
|
2047
|
-
Breakpoint 2 file /home/rocky/ruby/gcd.rb, line 10
|
2048
|
-
(byebug:1) @b{info file gcd.rb}
|
2049
|
-
File gcd.rb is not cached
|
2050
|
-
(byebug:1) @b{info file /home/rocky/ruby/gcd.rb}
|
2051
|
-
File /home/rocky/ruby/gcd.rb
|
2052
|
-
19 lines
|
2053
|
-
@end example
|
2054
|
-
|
2055
|
-
@item break @var{class}:@var{method}
|
2056
|
-
Set a breakpoint in class @var{class} method @var{method}. You can also use a
|
2057
|
-
period @code{.} instead of a colon @code{:}. Note that two colons @code{::} are
|
2058
|
-
not used. Also note a class @emph{must} be specified here. If the method you
|
2059
|
-
want to stop in is in the main class (i.e. the class that @code{self} belongs to
|
2060
|
-
at the start of the program), then use the name @code{Object}.
|
2061
|
-
|
2062
|
-
@kindex catch @ovar{exception} @r{[} on | 1 | off | 0 @r{]}
|
2063
|
-
@kindex cat @r{(@code{catch})}
|
2064
|
-
@item catch @ovar{exception} @r{[} on | 1 | off | 0 @r{]}
|
2065
|
-
Set catchpoint to an exception. Without an exception name show catchpoints.
|
2066
|
-
|
2067
|
-
With an ``on'' or ``off'' parameter, turn handling the exception on or off. To
|
2068
|
-
delete all exceptions type ``catch off''.
|
2069
|
-
|
2070
|
-
@cindex delete breakpoints
|
2071
|
-
@kindex delete @ovar{breakpoints}
|
2072
|
-
@kindex del @r{(@code{delete})}
|
2073
|
-
@item delete @ovar{breakpoints}
|
2074
|
-
Delete the breakpoints specified as arguments.
|
2075
|
-
|
2076
|
-
If no argument is specified, delete all breakpoints (@code{byebug} asks for
|
2077
|
-
confirmation. You can abbreviate this command as @code{del}).
|
2078
|
-
@kindex info breakpoints
|
2079
|
-
@cindex @code{$_} and @code{info breakpoints}
|
2080
|
-
@item info breakpoints @ovar{n}
|
2081
|
-
@itemx info break @ovar{n}
|
2082
|
-
Print a table of all breakpoints set and not deleted, with the following columns
|
2083
|
-
for each breakpoint:
|
2084
|
-
|
2085
|
-
@table @emph
|
2086
|
-
@item Breakpoint Numbers (@samp{Num})
|
2087
|
-
@item Enabled or Disabled (@samp{Enb})
|
2088
|
-
Enabled breakpoints are marked with @samp{1}. @samp{0} marks breakpoints that
|
2089
|
-
are disabled (not enabled).
|
2090
|
-
@item File and Line (@samp{file:line})
|
2091
|
-
The filename and line number inside that file where of breakpoint in the script.
|
2092
|
-
The file and line are separated with a colon.
|
2093
|
-
@item Condition
|
2094
|
-
A condition (an arithmetic expression) which when true causes the breakpoint to
|
2095
|
-
take effect.
|
2096
|
-
@end table
|
2097
|
-
@noindent
|
2098
|
-
If a breakpoint is conditional, @code{info break} shows the condition on the
|
2099
|
-
line following the affected breakpoint; breakpoint commands, if any, are listed
|
2100
|
-
after that.
|
2101
|
-
|
2102
|
-
@code{info break} with a breakpoint number @var{n} as argument lists only that
|
2103
|
-
breakpoint.
|
2104
|
-
|
2105
|
-
Examples:
|
2106
|
-
@example
|
2107
|
-
(byebug:1) @b{info break}
|
2108
|
-
Breakpoints at following places:
|
2109
|
-
Num Enb What
|
2110
|
-
1 y gcd.rb:3
|
2111
|
-
2 y gcb.rb:28 if n > 1
|
2112
|
-
(byebug:1) @b{info break 2}
|
2113
|
-
2 y gcb.rb:28 if n > 1
|
2114
|
-
@end example
|
2115
|
-
@end table
|
2116
|
-
|
2117
|
-
@node Disabling
|
2118
|
-
@subsection Disabling breakpoints (@samp{disable}, @samp{enable})
|
2119
|
-
|
2120
|
-
Rather than deleting a breakpoint, you might prefer to @dfn{disable} it. This
|
2121
|
-
makes the breakpoint inoperative as if it had been deleted, but remembers the
|
2122
|
-
information on the breakpoint so that you can @dfn{enable} it again later.
|
2123
|
-
|
2124
|
-
You disable and enable breakpoints and catchpoints with the @code{enable} and
|
2125
|
-
@code{disable} commands, optionally specifying one or more breakpoint numbers as
|
2126
|
-
arguments. Use @code{info break} to print a list of breakpoints and catchpoints
|
2127
|
-
if you do not know which numbers to use.
|
2128
|
-
|
2129
|
-
A breakpoint or catchpoint can have any different states of enablement:
|
2130
|
-
|
2131
|
-
@itemize @bullet
|
2132
|
-
@item
|
2133
|
-
Enabled. The breakpoint stops your program. A breakpoint set
|
2134
|
-
with the @code{break} command starts out in this state.
|
2135
|
-
@item
|
2136
|
-
Disabled. The breakpoint has no effect on your program.
|
2137
|
-
@end itemize
|
2138
|
-
|
2139
|
-
You can use the following commands to enable or disable breakpoints and
|
2140
|
-
catchpoints:
|
2141
|
-
|
2142
|
-
@table @code
|
2143
|
-
@kindex disable breakpoints
|
2144
|
-
@item disable @var{breakpoints}
|
2145
|
-
Disable the specified breakpoints or all breakpoints, if none are listed. A
|
2146
|
-
disabled breakpoint has no effect but it is not forgotten. All options such as
|
2147
|
-
ignore-counts, conditions and commands are remembered in case the breakpoint is
|
2148
|
-
enabled again later. You may abbreviate @code{disable} as @code{dis}.
|
2149
|
-
|
2150
|
-
@kindex enable breakpoints
|
2151
|
-
@item enable @var{breakpoints}
|
2152
|
-
Enable the specified breakpoints (or all defined breakpoints). They become
|
2153
|
-
effective once again in stopping your program.
|
2154
|
-
@end table
|
2155
|
-
|
2156
|
-
Breakpoints that you set are initially enabled; subsequently, they become
|
2157
|
-
disabled or enabled only when you use one of the commands above. (The command
|
2158
|
-
@code{until} can set and delete a breakpoint of its own, but it does not change
|
2159
|
-
the state of your other breakpoints; see @ref{Resuming Execution}.)
|
2160
|
-
|
2161
|
-
@node Conditions
|
2162
|
-
@subsection Break conditions (@samp{condition})
|
2163
|
-
@cindex conditional breakpoints
|
2164
|
-
@cindex breakpoint conditions
|
2165
|
-
|
2166
|
-
The simplest sort of breakpoint breaks every time your script reaches a
|
2167
|
-
specified place. You can also specify a @dfn{condition} for a breakpoint. A
|
2168
|
-
condition is just a Ruby expression.
|
2169
|
-
|
2170
|
-
Break conditions can be specified when a breakpoint is set, by using @samp{if}
|
2171
|
-
in the arguments to the @code{break} command. A breakpoint with a condition
|
2172
|
-
evaluates the expression each time your script reaches it, and your script stops
|
2173
|
-
only if the condition is @emph{true}. They can also be changed at any time with
|
2174
|
-
the @code{condition} command.
|
2175
|
-
|
2176
|
-
@ifset FINISHED
|
2177
|
-
You can also use the @code{if} keyword with the @code{watch} command. The
|
2178
|
-
@code{catch} command does not recognize the @code{if} keyword; @code{condition}
|
2179
|
-
is the only way to impose a further condition on a catchpoint.
|
2180
|
-
@end ifset
|
2181
|
-
|
2182
|
-
@table @code
|
2183
|
-
@kindex condition
|
2184
|
-
@item condition @var{bnum} @var{expression}
|
2185
|
-
Specify @var{expression} as the break condition for breakpoint @var{bnum}. After
|
2186
|
-
you set a condition, breakpoint @var{bnum} stops your program only if the value
|
2187
|
-
of @var{expression} is true (nonzero).
|
2188
|
-
|
2189
|
-
@item condition @var{bnum}
|
2190
|
-
Remove the condition from breakpoint number @var{bnum}. It becomes an ordinary
|
2191
|
-
unconditional breakpoint.
|
2192
|
-
@end table
|
2193
|
-
|
2194
|
-
@ifset FINISHED
|
2195
|
-
When you use @code{condition}, @code{byebug} checks @var{expression} immediately
|
2196
|
-
for syntactic correctness, and to determine whether symbols in it have referents
|
2197
|
-
in the context of your breakpoint. If @var{expression} uses symbols not
|
2198
|
-
referenced in the context of the breakpoint, @code{byebug} prints an error
|
2199
|
-
message:
|
2200
|
-
|
2201
|
-
@example
|
2202
|
-
No symbol "foo" in current context.
|
2203
|
-
@end example
|
2204
|
-
@end ifset
|
2205
|
-
|
2206
|
-
@noindent
|
2207
|
-
The debugger does not actually evaluate @var{expression} at the time the
|
2208
|
-
@code{condition} command (or a command that sets a breakpoint with a condition,
|
2209
|
-
like @code{break if @dots{}}) is given, however.
|
2210
|
-
|
2211
|
-
Examples;
|
2212
|
-
@example
|
2213
|
-
condition 1 x>5 # Stop on breakpoint 0 only if x>5 is true.
|
2214
|
-
condition 1 # Change that! Unconditionally stop on breakpoint 1.
|
2215
|
-
@end example
|
2216
|
-
|
2217
|
-
@node Resuming Execution
|
2218
|
-
@subsection Resuming Execution (@samp{step}, @samp{next}, @samp{finish}, @samp{continue})
|
2219
|
-
|
2220
|
-
A typical technique for using stepping is to set a breakpoint
|
2221
|
-
(@pxref{Breakpoints}) at the beginning of the function or the section of your
|
2222
|
-
script where a problem is believed to lie, run your script until it stops at
|
2223
|
-
that breakpoint, and then step through the suspect area, examining the variables
|
2224
|
-
that are interesting, until you see the problem happen.
|
2225
|
-
|
2226
|
-
@cindex stepping
|
2227
|
-
@cindex continuing
|
2228
|
-
@cindex resuming execution
|
2229
|
-
@dfn{Continuing} means resuming program execution until your script completes
|
2230
|
-
normally. In contrast, @dfn{stepping} means executing just one more ``step'' of
|
2231
|
-
your script, where ``step'' may mean one line of source code. Either when
|
2232
|
-
continuing or when stepping, your script may stop even sooner, due to a
|
2233
|
-
breakpoint or a signal.
|
2234
|
-
|
2235
|
-
@menu
|
2236
|
-
* Step:: running the next statement (step)
|
2237
|
-
* Next:: running the next statement skipping over functions (next)
|
2238
|
-
* Finish:: running until the return of a function or ``source'' (finish)
|
2239
|
-
* Continue:: continuing execution (continue)
|
2240
|
-
@end menu
|
2241
|
-
|
2242
|
-
@node Step
|
2243
|
-
@subsubsection Step (@samp{step})
|
2244
|
-
|
2245
|
-
@table @code
|
2246
|
-
@kindex step @r{[}+@r{]} @ovar{count}
|
2247
|
-
@kindex s @r{(@code{step})}
|
2248
|
-
@item step @r{[}+-@r{]} @ovar{count}
|
2249
|
-
Continue running your program until the next logical stopping point and return
|
2250
|
-
control to @code{byebug}. This command is abbreviated @code{s}.
|
2251
|
-
|
2252
|
-
Just like int the programming language Lisp, Ruby tends to be implemented in a
|
2253
|
-
highly expression-oriented manner. Therefore things that in other languages may
|
2254
|
-
appear to be a single statement are implemented in Ruby as several expressions.
|
2255
|
-
For example, in an ``if'' statement or loop statement a stop is made after the
|
2256
|
-
expression is evaluated but before the test on the expression is made.
|
2257
|
-
|
2258
|
-
So it is common that some lines in the program will have several stopping points
|
2259
|
-
whereas in other debuggers of other languages there would be only one. Or you
|
2260
|
-
may have several statements listed on a single line.
|
2261
|
-
|
2262
|
-
When stepping it is not uncommon to want to go to a different line on each step.
|
2263
|
-
If you want to make sure that on a step you go to a @emph{different} position,
|
2264
|
-
add a plus sign (@samp{+}).
|
2265
|
-
|
2266
|
-
@emph{Note: step+ with a number count is not the same as issuing count step+
|
2267
|
-
commands. Instead it uses count-1 step commands followed by a step+ command. For
|
2268
|
-
example, @code{step+ 3} is the same as @code{step; step; step+}, not
|
2269
|
-
@code{step+; step+; step+}}
|
2270
|
-
|
2271
|
-
If you find yourself generally wanting to use @code{step+} rather than
|
2272
|
-
@code{step}, you may want to consider using @code{set forcestep},
|
2273
|
-
(@pxref{Forcestep}).
|
2274
|
-
|
2275
|
-
If you have @code{forcestep} set on but want to temporarily disable it for the
|
2276
|
-
next step command, append a minus, or @code{step-}.
|
2277
|
-
|
2278
|
-
With a count, @code{step} will continue running as normal, but do so @var{count}
|
2279
|
-
times. If a breakpoint is reached, or a signal not related to stepping occurs
|
2280
|
-
before @var{count} steps, stepping stops right away.
|
2281
|
-
@end table
|
2282
|
-
|
2283
|
-
@node Next
|
2284
|
-
@subsubsection Next (@samp{next})
|
2285
|
-
@table @code
|
2286
|
-
@kindex next @r{[}+-@r{]} @ovar{count}
|
2287
|
-
@kindex n @r{(@code{next})}
|
2288
|
-
@item next @r{[}+@r{]} @ovar{count}
|
2289
|
-
This is similar to @code{step}, but function or method calls that appear within
|
2290
|
-
the line of code are executed without stopping. As with step, if you want to
|
2291
|
-
make sure that on a step you go to a @emph{different} position, add a plus sign
|
2292
|
-
(@samp{+}). Similarly, appending a minus disables a @code{forcestep}
|
2293
|
-
temporarily, and an argument @var{count} is a repeat count, as for @code{step}.
|
2294
|
-
@end table
|
2295
|
-
|
2296
|
-
@node Finish
|
2297
|
-
@subsubsection Finish (@samp{finish})
|
2298
|
-
@table @code
|
2299
|
-
@kindex finish @ovar{frame-number}
|
2300
|
-
@item finish @ovar{frame-number}
|
2301
|
-
Execute until selected stack frame returns. If no frame number is given, we run
|
2302
|
-
until the currently selected frame returns. The currently selected frame starts
|
2303
|
-
out the most-recent frame or 0 if no frame positioning (e.g@: @code{up},
|
2304
|
-
@code{down} or @code{frame}) has been performed. If a frame number is given we
|
2305
|
-
run until @var{frame} frames returns.
|
2306
|
-
|
2307
|
-
If you want instead to terminate the program and byebug entirely, use
|
2308
|
-
@code{quit} (@pxref{Quitting byebug, ,Quitting byebug}).
|
2309
|
-
|
2310
|
-
@end table
|
2311
|
-
|
2312
|
-
@node Continue
|
2313
|
-
@subsubsection Continue (@samp{continue})
|
2314
|
-
@table @code
|
2315
|
-
@kindex continue @ovar{line-specification}
|
2316
|
-
@kindex c @r{(@code{continue})}
|
2317
|
-
@item continue @ovar{line-specification}
|
2318
|
-
@itemx c @ovar{line-specification}
|
2319
|
-
Resume program execution, at the address where your script last
|
2320
|
-
stopped; any breakpoints set at that address are bypassed.
|
2321
|
-
|
2322
|
-
The optional argument @var{line-specification} allows you to specify a
|
2323
|
-
line number to set a one-time breakpoint which is deleted when that
|
2324
|
-
breakpoint is reached.
|
2325
|
-
|
2326
|
-
Should the program stop before that breakpoint is reached, for
|
2327
|
-
example, perhaps another breakpoint is reached first, in
|
2328
|
-
a listing of the breakpoints you won't see this entry in the list of
|
2329
|
-
breakpoints.
|
2330
|
-
@end table
|
2331
|
-
|
2332
|
-
@node byebug settings
|
2333
|
-
@section byebug settings (@samp{set args}, @samp{set autoeval}..)
|
2334
|
-
|
2335
|
-
You can alter the way byebug interacts with you using @code{set}
|
2336
|
-
commands.
|
2337
|
-
|
2338
|
-
The various parameters to @code{set} are given below. Each parameter
|
2339
|
-
name needs to to be only enough to make it unique. For example
|
2340
|
-
@code{set force} is a suitable abbreviation for @code{set forcestep}.
|
2341
|
-
The letter case is not important, so @code{set FORCE} or @code{set
|
2342
|
-
Force} are also suitable abbreviations.
|
2343
|
-
|
2344
|
-
Many @code{set} commands are either ``on'' or ``off'', and you can
|
2345
|
-
indicate which way you want set by supplying the corresponding
|
2346
|
-
word. The number 1 can be used for ``on'' and 0 for ``off''. If none
|
2347
|
-
of these is given, we will assume ``on''. A deprecated way of turning
|
2348
|
-
something off is by prefacing it with ``no''.
|
2349
|
-
|
2350
|
-
Each @code{set} command has a corresponding @code{show} command which
|
2351
|
-
allows you to see the current value.
|
2352
|
-
|
2353
|
-
@menu
|
2354
|
-
* Args:: Annotation Level
|
2355
|
-
* Autoeval:: Evaluate unrecognized commands
|
2356
|
-
* Autolist:: Execute ``list'' command on every breakpoint
|
2357
|
-
* Autoirb:: Invoke IRB on every stop
|
2358
|
-
* Autoreload:: Reload source code when changed
|
2359
|
-
* Basename:: Report file basename only showing file names
|
2360
|
-
* Callstyle:: Show Report file basename only showing file names
|
2361
|
-
* Forcestep:: Make sure 'next/step' commands always move to a new line
|
2362
|
-
* Fullpath:: Display full file names in frames
|
2363
|
-
* History:: Generic command for showing command history parameters.
|
2364
|
-
* Keepframebindings:: Save frame binding on each call
|
2365
|
-
* Linetrace:: line execution tracing
|
2366
|
-
* Linetrace+:: line tracing style
|
2367
|
-
* Listsize:: Number of lines to try to show in a 'list' command
|
2368
|
-
* Post-mortem:: Whether post-mortem handling is in effect.
|
2369
|
-
* Trace:: Display stack trace when 'eval' raises exception
|
2370
|
-
* Width:: Number of characters byebug thinks are in a line
|
2371
|
-
@end menu
|
2372
|
-
|
2373
|
-
@node Args
|
2374
|
-
@subsection Set/Show args
|
2375
|
-
|
2376
|
-
@table @code
|
2377
|
-
@kindex set args @ovar{parameters}
|
2378
|
-
@item set args @ovar{parameters}
|
2379
|
-
Specify the arguments to be used if your program is rerun. If
|
2380
|
-
@code{set args} has no arguments, @code{restart} executes your program
|
2381
|
-
with no arguments. Once you have run your program with arguments,
|
2382
|
-
using @code{set args} before the next @code{restart} is the only way to run
|
2383
|
-
it again without arguments.
|
2384
|
-
|
2385
|
-
@kindex show args
|
2386
|
-
@item show args
|
2387
|
-
Show the arguments to give your program when it is started.
|
2388
|
-
@end table
|
2389
|
-
|
2390
|
-
@node Autoeval
|
2391
|
-
@subsection Set/Show auto-eval
|
2392
|
-
|
2393
|
-
@table @code
|
2394
|
-
@kindex set autoeval @r{[} on | 1 | off | 0 @r{]}
|
2395
|
-
@item set autoeval @r{[} on | 1 | off | 0 @r{]}
|
2396
|
-
Specify that byebug input that isn't recognized as a command should
|
2397
|
-
be passed to Ruby for evaluation (using the current debugged program
|
2398
|
-
namespace). Note however that we @emph{first} check input to see if it
|
2399
|
-
is a byebug command and @emph{only} if it is not do we consider it
|
2400
|
-
as Ruby code. This means for example that if you have variable called
|
2401
|
-
@code{n} and you want to see its value, you could use @code{p n},
|
2402
|
-
because just entering @code{n} will be interpreted as byebug
|
2403
|
-
``next'' command.
|
2404
|
-
|
2405
|
-
See also @ref{irb} and @ref{Autoirb}.
|
2406
|
-
|
2407
|
-
When autoeval is set on, you'll get a different error message when you
|
2408
|
-
invalid commands are encountered. Here's a session fragment to show
|
2409
|
-
the difference
|
2410
|
-
@smallexample
|
2411
|
-
(byebug:1) @b{stepp}
|
2412
|
-
Unknown command
|
2413
|
-
(byebug:1) @b{set autoeval on}
|
2414
|
-
autoeval is on.
|
2415
|
-
(byebug:1) @b{stepp}
|
2416
|
-
NameError Exception: undefined local variable or method `stepp' for ...
|
2417
|
-
@end smallexample
|
2418
|
-
|
2419
|
-
@kindex show autoeval
|
2420
|
-
@item show args
|
2421
|
-
Shows whether Ruby evaluation of byebug input should occur or not.
|
2422
|
-
@end table
|
2423
|
-
|
2424
|
-
@node Autolist
|
2425
|
-
@subsection Execute ``list'' command on every breakpoint
|
2426
|
-
|
2427
|
-
@node Autoirb
|
2428
|
-
@subsection Set/Show auto-irb
|
2429
|
-
|
2430
|
-
@table @code
|
2431
|
-
@kindex set autoirb @r{[} on | 1 | off | 0 @r{]}
|
2432
|
-
@item set autoirb @r{[} on | 1 | off | 0 @r{]}
|
2433
|
-
|
2434
|
-
When your program stops, normally you go into a byebug command loop
|
2435
|
-
looking for byebug commands. If instead you would like to directly
|
2436
|
-
go into an irb shell, set this on. See also @ref{Autoeval} or
|
2437
|
-
@ref{irb} if you tend to use byebug commands but still want Ruby
|
2438
|
-
evaluation occasionally.
|
2439
|
-
|
2440
|
-
@kindex show autoirb
|
2441
|
-
@item show autoirb
|
2442
|
-
Shows whether byebug will go into irb on stop or not.
|
2443
|
-
@end table
|
2444
|
-
|
2445
|
-
@node Autoreload
|
2446
|
-
@subsection Set/Show auto-reload
|
2447
|
-
@table @code
|
2448
|
-
@kindex set autoreload @r{[} on | 1 | off | 0 @r{]}
|
2449
|
-
Set this on if byebug should check to see if the source has
|
2450
|
-
changed since the last time it reread in the file if it has.
|
2451
|
-
@end table
|
2452
|
-
|
2453
|
-
@node Basename
|
2454
|
-
@subsection Set/Show basename
|
2455
|
-
|
2456
|
-
@table @code
|
2457
|
-
@kindex set basename @r{[} on | 1 | off | 0 @r{]}
|
2458
|
-
@item set basename @r{[} on | 1 | off | 0 @r{]}
|
2459
|
-
Source filenames are shown as the shorter ``basename''
|
2460
|
-
only. (Directory paths are omitted). This is useful in running the
|
2461
|
-
regression tests and may useful in showing byebug examples as in
|
2462
|
-
this text. You may also just want less verbose filename display.
|
2463
|
-
|
2464
|
-
By default filenames are shown as with their full path.
|
2465
|
-
|
2466
|
-
@kindex show basename
|
2467
|
-
@item show basename
|
2468
|
-
Shows the whether filename display shows just the file basename or not.
|
2469
|
-
@end table
|
2470
|
-
|
2471
|
-
@node Callstyle
|
2472
|
-
@subsection Set/Show call style
|
2473
|
-
|
2474
|
-
@table @code
|
2475
|
-
@ifset FINISHED
|
2476
|
-
@kindex set callstyle @r{[} short | long @r{]}
|
2477
|
-
@item set callstyle @r{[} short | long @r{]}
|
2478
|
-
@else
|
2479
|
-
@kindex set callstyle @r{[} short | long
|
2480
|
-
@item set callstyle @r{[} short | long
|
2481
|
-
@end ifset
|
2482
|
-
|
2483
|
-
Sets how you want call parameters displayed
|
2484
|
-
|
2485
|
-
@code{short} shows current method and parameter names.
|
2486
|
-
@code{long} shows current class, current method, parameter names and the class
|
2487
|
-
of each parameter as it currently exist. Note the type could have changed
|
2488
|
-
since the call was made.
|
2489
|
-
@end table
|
2490
|
-
|
2491
|
-
@node Forcestep
|
2492
|
-
@subsection Set/Show Forces Different Line Step/Next
|
2493
|
-
|
2494
|
-
@table @code
|
2495
|
-
@kindex set forcestep @r{[} on | 1 | off | 0 @r{]}
|
2496
|
-
@item set forcestep @r{[} on | 1 | off | 0 @r{]}
|
2497
|
-
|
2498
|
-
Due to the interpretive, expression-oriented nature of the Ruby
|
2499
|
-
Language and implementation, each line often contains many possible
|
2500
|
-
stopping points, while in a byebug it is often desired to treat each
|
2501
|
-
line as an individual stepping unit.
|
2502
|
-
|
2503
|
-
Setting forcestep on will cause each @code{step} or @code{next}
|
2504
|
-
command to stop at a different line number. See also @ref{Step} and
|
2505
|
-
@ref{Next}.
|
2506
|
-
|
2507
|
-
@kindex show forcestep
|
2508
|
-
@item show forcestep
|
2509
|
-
Shows whether forcestep is in effect or not.
|
2510
|
-
@end table
|
2511
|
-
|
2512
|
-
@node Fullpath
|
2513
|
-
@subsection Set/Show Frame full path
|
2514
|
-
|
2515
|
-
@node History
|
2516
|
-
@subsection Command History Parameters
|
2517
|
-
@table @code
|
2518
|
-
@item show commands
|
2519
|
-
@kindex show commands
|
2520
|
-
Display the last ten commands in the command history.
|
2521
|
-
|
2522
|
-
@item show commands @var{n}
|
2523
|
-
@kindex show commands @var{n}
|
2524
|
-
Print ten commands centered on command number @var{n}.
|
2525
|
-
|
2526
|
-
@item show history filename
|
2527
|
-
@kindex show history filename
|
2528
|
-
Show the filename in which to record the command history
|
2529
|
-
(the list of previous commands of which a record is kept).
|
2530
|
-
|
2531
|
-
@item set history save @r{[} on | 1 | off | 0 @r{]}
|
2532
|
-
@kindex set history save @r{[} on | 1 | off | 0 @r{]}
|
2533
|
-
Set whether to save the history on exit.
|
2534
|
-
|
2535
|
-
@item show history save
|
2536
|
-
@kindex show history save
|
2537
|
-
Show saving of the history record on exit.
|
2538
|
-
|
2539
|
-
@item set history size @var{number}
|
2540
|
-
@kindex set history size @var{number}
|
2541
|
-
Set the maximum number of commands to save in the history.
|
2542
|
-
|
2543
|
-
@item show history size
|
2544
|
-
@kindex show history size
|
2545
|
-
Show the size of the command history, i.e. the number of previous
|
2546
|
-
commands to keep a record of.
|
2547
|
-
@end table
|
2548
|
-
|
2549
|
-
@node Keepframebindings
|
2550
|
-
@subsection Save frame binding on each call
|
2551
|
-
|
2552
|
-
@node Linetrace
|
2553
|
-
@subsection Set/Show Line tracing
|
2554
|
-
|
2555
|
-
@table @code
|
2556
|
-
@kindex set linetrace @r{[} on | 1 | off | 0 @r{]}
|
2557
|
-
@item set linetrace @r{[} on | 1 | off | 0 @r{]}
|
2558
|
-
|
2559
|
-
Setting linetrace on will cause lines to be shown before run.
|
2560
|
-
|
2561
|
-
@kindex show linetrace
|
2562
|
-
@item show linetrace
|
2563
|
-
Shows whether line tracing is in effect or not.
|
2564
|
-
@end table
|
2565
|
-
|
2566
|
-
@node Linetrace+
|
2567
|
-
@subsection Set/Show Line tracing style
|
2568
|
-
|
2569
|
-
@table @code
|
2570
|
-
@kindex set linetrace_plus @r{[} on | 1 | off | 0 @r{]}
|
2571
|
-
@item set linetrace_plus @r{[} on | 1 | off | 0 @r{]}
|
2572
|
-
|
2573
|
-
Setting linetrace_plus on will cause every trace line to be printed, even if
|
2574
|
-
it's a duplicate of the preceding trace line. Note however that this setting
|
2575
|
-
doesn't by itself turn on or off line tracing.
|
2576
|
-
|
2577
|
-
@kindex show linetrace_plus
|
2578
|
-
@item show linetrace_plus
|
2579
|
-
Shows whether the line tracing style is to show all lines or remove duplicates
|
2580
|
-
linetrace lines when it is a repeat of the previous line.
|
2581
|
-
@end table
|
2582
|
-
|
2583
|
-
@node Listsize
|
2584
|
-
@subsection Set/Show lines in a List command
|
2585
|
-
|
2586
|
-
@table @code
|
2587
|
-
@kindex set listsize @var{number-of-lines}
|
2588
|
-
@item set listsize @var{number-of-lines}
|
2589
|
-
Set number of lines to try to show in a @code{list} command.
|
2590
|
-
@kindex show listsize
|
2591
|
-
@item show listsize
|
2592
|
-
Shows the list-size setting.
|
2593
|
-
@end table
|
2594
|
-
|
2595
|
-
@node Post-mortem
|
2596
|
-
@subsection Show Post-mortem handling
|
2597
|
-
@table @code
|
2598
|
-
@kindex show post-mortem
|
2599
|
-
Shows wither post-mortem debugging is in effect. Right now we don't have the
|
2600
|
-
ability to change that state inside byebug.
|
2601
|
-
@end table
|
2602
|
-
|
2603
|
-
@node Trace
|
2604
|
-
@subsection Display stack trace when 'eval' raises exception
|
2605
|
-
|
2606
|
-
@node Width
|
2607
|
-
@subsection Set/Show Line width
|
2608
|
-
|
2609
|
-
@table @code
|
2610
|
-
@kindex set width @var{column-width}
|
2611
|
-
@item set width @var{column-width}
|
2612
|
-
Set number of characters per line of byebug output. By default it is the number
|
2613
|
-
of columns in the current terminal.
|
2614
|
-
@kindex show width
|
2615
|
-
@item show width
|
2616
|
-
Shows the current width setting.
|
2617
|
-
@end table
|
2618
|
-
|
2619
|
-
@node Program Information
|
2620
|
-
@section Program Information (@samp{info})
|
2621
|
-
|
2622
|
-
This @code{info} command (abbreviated @code{i}) is for describing the state of
|
2623
|
-
your program. For example, you can list the current parameters with
|
2624
|
-
@code{info args} or list the breakpoints you have set with
|
2625
|
-
@code{info breakpoints} or @code{info watchpoints}. You can get a complete list
|
2626
|
-
of @code{info} sub-commands with @w{@code{help info}}.
|
2627
|
-
|
2628
|
-
@table @code
|
2629
|
-
@kindex info args
|
2630
|
-
@item info args
|
2631
|
-
Method arguments of the current stack frame.
|
2632
|
-
|
2633
|
-
@kindex info breakpoints
|
2634
|
-
@item info breakpoints
|
2635
|
-
Status of user-settable breakpoints
|
2636
|
-
|
2637
|
-
@kindex info display
|
2638
|
-
@item info display
|
2639
|
-
All display expressions.
|
2640
|
-
|
2641
|
-
@kindex info files
|
2642
|
-
@item info files
|
2643
|
-
Source files in the program.
|
2644
|
-
|
2645
|
-
@kindex info file
|
2646
|
-
@item info file @var{filename} @ovar{all|basic|path|lines|mtime|sha1}
|
2647
|
-
Information about a specific file. Parameter @code{path} gives the full path
|
2648
|
-
name of the file. Parameter @code{lines} gives the number of lines in the file,
|
2649
|
-
@code{mtime} shows the modification time of the file (if available), @code{sha1}
|
2650
|
-
computes a SHA1 hash of the data in the file. @code{all} gives all of the above
|
2651
|
-
information and @code{basic} is equivalent to @code{path} and @code{lines}.
|
2652
|
-
|
2653
|
-
@kindex info line
|
2654
|
-
@item info line
|
2655
|
-
Line number and file name of current position in source.
|
2656
|
-
|
2657
|
-
@kindex info locals
|
2658
|
-
@item info locals
|
2659
|
-
Local variables of the current stack frame.
|
2660
|
-
|
2661
|
-
@kindex info program
|
2662
|
-
@item info program
|
2663
|
-
Display information about the status of your program: whether it is running or
|
2664
|
-
not and why it stopped. If an unhandled exception occurred, the exception class
|
2665
|
-
and @code{to_s} method is called.
|
2666
|
-
|
2667
|
-
@kindex info stack
|
2668
|
-
@item info stack
|
2669
|
-
Backtrace of the stack. An alias for @code{where}. @xref{Backtrace}.
|
2670
|
-
|
2671
|
-
@kindex info variables
|
2672
|
-
@item info variables
|
2673
|
-
Local and instance variables.
|
2674
|
-
@end table
|
2675
|
-
|
2676
|
-
@node Post-Mortem Debugging
|
2677
|
-
@chapter Post-Mortem Debugging
|
2678
|
-
@cindex post-mortem debugging
|
2679
|
-
|
2680
|
-
It is also to possible enter byebug when you have an uncaught exception that is
|
2681
|
-
about to terminate our program. This is called @emph{post-mortem debugging}. In
|
2682
|
-
this state many byebug commands for examining variables and moving around the
|
2683
|
-
stack still work. However some commands, such as those implying a continuation
|
2684
|
-
of running code, no longer work.
|
2685
|
-
|
2686
|
-
The most reliable way to set up post-mortem debugging is to use the
|
2687
|
-
@option{--post-mortem} option in invoking @code{byebug}. See @ref{byebug
|
2688
|
-
command-line options}. This traps/wraps at byebug ``load'' of your Ruby script.
|
2689
|
-
When this is done, your program is stopped after the exception takes place, but
|
2690
|
-
before the stack has been unraveled. (Alas, it would be nice to if one could
|
2691
|
-
allow resetting the exception and continuing...)
|
2692
|
-
|
2693
|
-
If however you haven't invoked @code{byebug} at the outset, but instead call
|
2694
|
-
@code{byebug} from inside your program, to set up post-mortem debugging set the
|
2695
|
-
@code{post_mortem} key in @code{Byebug.start}. Here's an example:
|
2696
|
-
|
2697
|
-
@smallexample
|
2698
|
-
$ @b{cat t.rb }
|
2699
|
-
require 'rubygems'
|
2700
|
-
require 'byebug' ; Byebug.start(post_mortem: true)
|
2701
|
-
|
2702
|
-
def t1
|
2703
|
-
raise 'test'
|
2704
|
-
end
|
2705
|
-
def t2
|
2706
|
-
t1
|
2707
|
-
end
|
2708
|
-
t2
|
2709
|
-
|
2710
|
-
$ @b{ruby t.rb }
|
2711
|
-
t.rb:8: raise 'test'
|
2712
|
-
(byebug:post-mortem) @b{l=}
|
2713
|
-
[3, 12] in t.rb
|
2714
|
-
3
|
2715
|
-
4 Byebug.start
|
2716
|
-
5 Byebug.post_mortem
|
2717
|
-
6
|
2718
|
-
7 def t1
|
2719
|
-
=> 8 raise 'test'
|
2720
|
-
9 end
|
2721
|
-
10 def t2
|
2722
|
-
11 t1
|
2723
|
-
12 end
|
2724
|
-
(byebug:post-mortem)
|
2725
|
-
@end smallexample
|
2726
|
-
|
2727
|
-
Alternatively you can call @code{Byebug.post_mortem()} after byebug has
|
2728
|
-
been started. The @code{post_mortem()} method can be called in two
|
2729
|
-
ways. Called without a block, it installs a global @code{at_exit()} hook
|
2730
|
-
that intercepts exceptions not handled by your Ruby script. In
|
2731
|
-
contrast to using the @option{--post-mortem} option, when this hook
|
2732
|
-
occurs after the call stack has been rolled back. (I'm not sure if
|
2733
|
-
this in fact makes any difference operationally; I'm just stating it
|
2734
|
-
because that's how it works.)
|
2735
|
-
|
2736
|
-
If you know that a particular block of code raises an exception you
|
2737
|
-
can enable post-mortem mode by wrapping this block inside a
|
2738
|
-
@code{Byebug.post_mortem} block
|
2739
|
-
|
2740
|
-
@smallexample
|
2741
|
-
def offender
|
2742
|
-
1/0
|
2743
|
-
end
|
2744
|
-
...
|
2745
|
-
require "ruby-gems"
|
2746
|
-
require "byebug"
|
2747
|
-
Byebug.post_mortem do
|
2748
|
-
...
|
2749
|
-
offender
|
2750
|
-
...
|
2751
|
-
end
|
2752
|
-
@end smallexample
|
2753
|
-
|
2754
|
-
Once inside byebug in post-mortem debugging, the prompt should
|
2755
|
-
be @code{(byebug:post-mortem)}.
|
2756
|
-
|
2757
|
-
@node Byebug Module and Class
|
2758
|
-
@chapter The Byebug Module and Class
|
2759
|
-
|
2760
|
-
@menu
|
2761
|
-
* Byebug Module:: byebug's Byebug module
|
2762
|
-
* Byebug Class:: Byebug class
|
2763
|
-
* Kernel routines:: Routines added to Kernel
|
2764
|
-
@end menu
|
2765
|
-
|
2766
|
-
@node Byebug Module
|
2767
|
-
@section The Byebug Module
|
2768
|
-
|
2769
|
-
@menu
|
2770
|
-
* Byebug.run::
|
2771
|
-
@ifset LATER
|
2772
|
-
* Byebug.post-mortem::
|
2773
|
-
@end ifset
|
2774
|
-
* Byebug.context::
|
2775
|
-
* Byebug.settings::
|
2776
|
-
@end menu
|
2777
|
-
|
2778
|
-
@node Byebug.run
|
2779
|
-
@subsection @code{Byebug.start}, @code{Byebug.started?}, @code{Byebug.stop}, @code{Byebug.run_script}
|
2780
|
-
|
2781
|
-
In order to provide better debugging information regarding the stack frame(s),
|
2782
|
-
byebug has to intercept each call, save some information and on return remove
|
2783
|
-
it. Therefore one has to issue a call to indicate byebug to start saving
|
2784
|
-
information and another call to stop. Of course, if you call byebug from the
|
2785
|
-
outset via @code{byebug} this is done for you.
|
2786
|
-
|
2787
|
-
@table @code
|
2788
|
-
@item Byebug.start(@ovar{options}) @ovar{block}
|
2789
|
-
@vindex @code{Byebug.start(options)}
|
2790
|
-
@vindex @code{Byebug.start(block)}
|
2791
|
-
Turn on add additional instrumentation code to facilitate debugging. A
|
2792
|
-
system even table hook is installed and some variables are set up.
|
2793
|
-
|
2794
|
-
This needs to be done before entering byebug; therefore a call
|
2795
|
-
to byebug issue a @code{Byebug.start} call if necessary.
|
2796
|
-
|
2797
|
-
If called without a block, @code{Byebug.start} returns @code{true} if
|
2798
|
-
byebug was already started. But if you want to know if the
|
2799
|
-
byebug has already been started @code{Byebug.started?} can tell
|
2800
|
-
you.
|
2801
|
-
|
2802
|
-
If a block is given, byebug is started and @code{yields} to
|
2803
|
-
block. When the block is finished executing, byebug stopped with
|
2804
|
-
the @code{Byebug.stop method}. You will probably want to put a call
|
2805
|
-
to @code{byebug} somwhere inside that block
|
2806
|
-
|
2807
|
-
But if you want to completely stop byebug, you must call
|
2808
|
-
@code{Byebug.stop} as many times as you called Byebug.start
|
2809
|
-
method.
|
2810
|
-
|
2811
|
-
The first time Byebug.start is called there is also some additional
|
2812
|
-
setup to make the @code{restart} command work. In particular, @code{$0} and
|
2813
|
-
@code{ARGV} are used to set internal byebug variables.
|
2814
|
-
|
2815
|
-
Therefore you should make try to make sure that when
|
2816
|
-
@code{Byebug.start} is called neither of these variables has been
|
2817
|
-
modified. If instead you don't want this behavior you can pass an
|
2818
|
-
options has and set the @code{:init} key to @code{false}. That is
|
2819
|
-
@smallexample
|
2820
|
-
Byebug.start(:init => false) # or Byebug.start(@{:init => false@})
|
2821
|
-
@end smallexample
|
2822
|
-
|
2823
|
-
If you want post-mortem debugging, you can also supply
|
2824
|
-
@code{:post_mortem => true} in @code{Byebug.start}.
|
2825
|
-
|
2826
|
-
@item Byebug.started?
|
2827
|
-
@vindex @code{Byebug.started?}
|
2828
|
-
Boolean. Return @code{true} if byebug has been started.
|
2829
|
-
|
2830
|
-
@item Byebug.stop
|
2831
|
-
@vindex @code{Byebug.stop}
|
2832
|
-
Turn off instrumentation to allow debugging. Return @code{true} is returned
|
2833
|
-
if byebug is disabled, otherwise it returns @code{false}.
|
2834
|
-
@emph{Note that if you want to stop byebug, you must call Byebug.stop
|
2835
|
-
as many times as you called the @code{Byebug.start} method.}
|
2836
|
-
|
2837
|
-
@item Byebug.run_script(@var{byebug-command-file}, out = handler.interface)
|
2838
|
-
@vindex @code{Byebug.run_script}
|
2839
|
-
Reads/runs the given file containing byebug commands. @code{.byebugrc} is run this way.
|
2840
|
-
|
2841
|
-
@item Byebug.last_exception
|
2842
|
-
@vindex @code{Byebug.last_exception}
|
2843
|
-
If not @code{nil}, this contains @code{$!} from the last exception.
|
2844
|
-
|
2845
|
-
@end table
|
2846
|
-
|
2847
|
-
@node Byebug.context
|
2848
|
-
@subsection @code{Byebug.context}
|
2849
|
-
As mentioned previously, @code{Byebug.start} instruments additional
|
2850
|
-
information to be obtained about the current block/frame stack. Here
|
2851
|
-
we describe these additional @code{Byebug.context} methods.
|
2852
|
-
|
2853
|
-
Were a frame position is indicated, it is optional. The top or current frame
|
2854
|
-
position (position zero) is used if none is given.
|
2855
|
-
|
2856
|
-
@table @code
|
2857
|
-
@item Byebug.context.frame_args @ovar{frame-position=0}
|
2858
|
-
@vindex @code{Byebug.context.frame_args}
|
2859
|
-
If track_frame_args? is true, return information saved about call
|
2860
|
-
arguments (if any saved) for the given frame position.
|
2861
|
-
|
2862
|
-
@item Byebug.context.frame_args_info @ovar{frame-position=0}
|
2863
|
-
@vindex @code{Byebug.context.frame_args_info}
|
2864
|
-
|
2865
|
-
@item Byebug.context.frame_class @ovar{frame-position=0}
|
2866
|
-
@vindex @code{Byebug.context.frame_args_info}
|
2867
|
-
Return the class of the current frame stack.
|
2868
|
-
|
2869
|
-
@item Byebug.context.frame_file @ovar{frame-position=0}
|
2870
|
-
@vindex @code{Byebug.context.frame_file}
|
2871
|
-
Return the filename of the location of the indicated frame position.
|
2872
|
-
|
2873
|
-
@item Byebug.context.frame_id @ovar{frame-position=0}
|
2874
|
-
@vindex @code{Byebug.context.frame_id}
|
2875
|
-
Same as @code{Byebug.context.method}.
|
2876
|
-
|
2877
|
-
@item Byebug.context.frame_line @ovar{frame-position=0}
|
2878
|
-
@vindex @code{Byebug.context.frame_line}
|
2879
|
-
Return the filename of the location of the indicated frame position.
|
2880
|
-
|
2881
|
-
@item Byebug.context.frame_method @ovar{frame-position=0}
|
2882
|
-
@vindex @code{Byebug.context.frame_method}
|
2883
|
-
Symbol of the method name of the indicated frame position.
|
2884
|
-
|
2885
|
-
@item Byebug.context.calced_stack_size
|
2886
|
-
@vindex @code{Byebug.context.calced_stack_size}
|
2887
|
-
Returns the stack size calculated by byebug. This is initialized when byebug is
|
2888
|
-
started and after that is kept up-to-date using the TracePoint API events.
|
2889
|
-
@end table
|
2890
|
-
|
2891
|
-
@node Byebug.settings
|
2892
|
-
@subsection @code{Byebug.settings}
|
2893
|
-
@vindex @code{Byebug.settings}
|
2894
|
-
Symbols listed here are keys into the Array @code{Byebug.settings}.
|
2895
|
-
These can be set any time after the @code{byebug} is loaded. For example:
|
2896
|
-
@smallexample
|
2897
|
-
require "byebug/byebug"
|
2898
|
-
Byebug.settings[:autoeval] = true # try eval on unknown byebug commands
|
2899
|
-
Byebug.listsize = 20 # Show 20 lines in a list command
|
2900
|
-
@end smallexample
|
2901
|
-
|
2902
|
-
@table @code
|
2903
|
-
@item :argv
|
2904
|
-
Array of String. @code{argv[0]} is the debugged program name and
|
2905
|
-
@code{argv[1..-1]} are the command arguments to it.
|
2906
|
-
@item :autoeval
|
2907
|
-
Boolean. True if auto autoeval on. @xref{Autoeval}.
|
2908
|
-
@item :autoirb
|
2909
|
-
Fixnum: 1 if on or 0 if off. @xref{Autoirb}.
|
2910
|
-
@item :autolist
|
2911
|
-
Fixnum: 1 if on or 0 if off.
|
2912
|
-
@item :basename
|
2913
|
-
Boolean. True if basename on. @xref{Basename}.
|
2914
|
-
@item :callstyle
|
2915
|
-
Symbol: @code{:short} or @code{:long}. @xref{Callstyle}.
|
2916
|
-
@item :testing
|
2917
|
-
Boolean. True if currently testing byebug.
|
2918
|
-
@item :forcestep
|
2919
|
-
Boolean. True if stepping should go to a line different from the last
|
2920
|
-
step. @xref{Forcestep}.
|
2921
|
-
@item :fullpath
|
2922
|
-
Boolean. @xref{Fullpath}.
|
2923
|
-
@item :listsize
|
2924
|
-
Fixnum. Number of lines to show in a @code{list} command. @xref{Listsize}.
|
2925
|
-
@item :autoreload
|
2926
|
-
Boolean. True if we should reread the source every time it changes. @xref{Autoreload}.
|
2927
|
-
@item :stack_on_error
|
2928
|
-
Boolean. True if we should produce a stack trace on eval errors. @xref{Trace}.
|
2929
|
-
@item :width
|
2930
|
-
Fixnum. Number of characters byebug thinks are in a line. @xref{Width}.
|
2931
|
-
@end table
|
2932
|
-
|
2933
|
-
@node Byebug Class
|
2934
|
-
@section The @code{Byebug} Class
|
2935
|
-
@menu
|
2936
|
-
* Byebug.Breakpoint:: Byebug::Breakpoint
|
2937
|
-
* Byebug.Context:: Byebug::Context
|
2938
|
-
* Byebug.Command:: Byebug::Command
|
2939
|
-
@end menu
|
2940
|
-
|
2941
|
-
@table @code
|
2942
|
-
@item add_breakpoint(file, line, expr)
|
2943
|
-
@vindex @code{Byebug.add_breakpoint}
|
2944
|
-
Adds a breakpoint in file @var{file}, at line @var{line}. If @var{expr} is not
|
2945
|
-
nil, it is evaluated and a breakpoint takes effect at the indicated position
|
2946
|
-
when that expression is true. You should verify that @var{expr} is syntactically
|
2947
|
-
valid or a @code{SyntaxError} exception, and unless your code handles this the
|
2948
|
-
debugged program may terminate.
|
2949
|
-
|
2950
|
-
@item remove_breakpoint(bpnum)
|
2951
|
-
@vindex @code{Byebug.remove_breakpoint}
|
2952
|
-
When a breakpoint is added, it is assigned a number as a way to uniquely
|
2953
|
-
identify it. (There can be more than one breakpoint on a given line.) To remove
|
2954
|
-
a breakpoint, use @code{remove_breakpoint} with breakpoint number @var{bpnum}.
|
2955
|
-
|
2956
|
-
@item breakpoints
|
2957
|
-
@vindex @code{Byebug.breakpoints}
|
2958
|
-
Return a list of the breakpoints that have been added but not removed.
|
2959
|
-
@end table
|
2960
|
-
|
2961
|
-
@node Byebug.Breakpoint
|
2962
|
-
@subsection The @code{Byebug::Breakpoint} Class
|
2963
|
-
Breakpoints are objects in the @code{Byebug::Breakpoint} class.
|
2964
|
-
@table @code
|
2965
|
-
@item enabled?
|
2966
|
-
@vindex @code{Byebug::Breakpoints.enabled?}
|
2967
|
-
Returns whether breakpoint is enabled or not.
|
2968
|
-
|
2969
|
-
@item enabled=
|
2970
|
-
@vindex @code{Byebug::Breakpoints.enabled=}
|
2971
|
-
Sets a breakpoint as enabled or not.
|
2972
|
-
|
2973
|
-
@item expr
|
2974
|
-
@vindex @code{Byebug::Breakpoints.expr}
|
2975
|
-
Returns an expression which has to be true at the point where the breakpoint is
|
2976
|
-
set before we stop.
|
2977
|
-
|
2978
|
-
@item expr=
|
2979
|
-
@vindex @code{Byebug::Breakpoints.expr=}
|
2980
|
-
Sets an expression which has to be true at the point where the breakpoint is set
|
2981
|
-
before we stop.
|
2982
|
-
|
2983
|
-
@item hit_condition
|
2984
|
-
@item hit_condition=
|
2985
|
-
@vindex @code{Byebug::Breakpoints.condition}
|
2986
|
-
@vindex @code{Byebug::Breakpoints.condition=}
|
2987
|
-
|
2988
|
-
@item hit_count
|
2989
|
-
@vindex @code{Byebug::Breakpoints.hit_count}
|
2990
|
-
Returns the hit count of the breakpoint.
|
2991
|
-
|
2992
|
-
@item hit_value
|
2993
|
-
@vindex @code{Byebug::Breakpoints.hit_value}
|
2994
|
-
Returns the hit value of the breakpoint.
|
2995
|
-
|
2996
|
-
@item hit_value=
|
2997
|
-
@vindex @code{Byebug::Breakpoints.hit_value=}
|
2998
|
-
Sets the hit value of the breakpoint.
|
2999
|
-
|
3000
|
-
@item id
|
3001
|
-
@cindex @code{Byebug::Breakpoints.id}
|
3002
|
-
A numeric name for the breakpoint which is used in listing breakpoints and
|
3003
|
-
removing, enabling or disabling the breakpoint.
|
3004
|
-
|
3005
|
-
@item pos
|
3006
|
-
@vindex @code{Byebug::Breakpoints.pos=}
|
3007
|
-
Returns the line number of this breakpoint.
|
3008
|
-
@item pos=
|
3009
|
-
@vindex @code{Byebug::Breakpoints.pos=}
|
3010
|
-
Sets the line number of this breakpoint.
|
3011
|
-
|
3012
|
-
@item source
|
3013
|
-
@vindex @code{Byebug::Breakpoints.source}
|
3014
|
-
Returns the file name in which the breakpoint occurs.
|
3015
|
-
|
3016
|
-
@item source=
|
3017
|
-
@vindex @code{Byebug::Breakpoints.source=}
|
3018
|
-
Sets the file name in which the breakpoint occurs.
|
3019
|
-
@end table
|
3020
|
-
|
3021
|
-
@node Byebug.Context
|
3022
|
-
@subsection The @code{Byebug::Context} Class
|
3023
|
-
Callbacks in @code{Byebug:Context} get called when a stopping point or an event
|
3024
|
-
is reached. It has information about the suspended program which enable byebug
|
3025
|
-
to inspect the frame stack, evaluate variables from the perspective of the
|
3026
|
-
debugged program, and contains information about the place the debugged program
|
3027
|
-
is stopped.
|
3028
|
-
|
3029
|
-
@table @code
|
3030
|
-
@item at_line(@var{file}, @var{line})
|
3031
|
-
@vindex Byebug::Context::at_line(@var{file}, @var{line})
|
3032
|
-
This routine is called when byebug encounters a ``line'' event for which it has
|
3033
|
-
been indicated we want to stop at, such as by hitting a breakpoint or by some
|
3034
|
-
sort of stepping.
|
3035
|
-
|
3036
|
-
@item at_return(@var{file}, @var{line})
|
3037
|
-
@vindex Byebug::Context::at_return(@var{file}, @var{line})
|
3038
|
-
This routine is called when byebug encounters a ``return'' event for which it
|
3039
|
-
has been indicated we want to stop at, such as by hitting a @code{finish}
|
3040
|
-
statement.
|
3041
|
-
|
3042
|
-
@item debug_load(@var{file}, @var{stop-initially})
|
3043
|
-
@vindex Byebug::Context::debug_load(@var{file}, @var{stop-initially})
|
3044
|
-
This method should be used to debug a file. If the file terminates normally,
|
3045
|
-
@code{nil} is returned. If not a backtrace is returned.
|
3046
|
-
|
3047
|
-
The @var{stop-initially} parameter indicates whether the program should stop
|
3048
|
-
after loading. If an explicit call to byebug is in the debugged program, you may
|
3049
|
-
want to set this @code{false}.
|
3050
|
-
@end table
|
3051
|
-
|
3052
|
-
@node Byebug.Command
|
3053
|
-
@subsection The @code{Byebug::Command} Class
|
3054
|
-
Each command you run is in fact its own class. Should you want to extend byebug,
|
3055
|
-
it's pretty easy to do since after all byebug is Ruby.
|
3056
|
-
|
3057
|
-
Each @code{Byebug#Command} class should have a @code{regexp} method. This method
|
3058
|
-
returns regular expression for command-line strings that match your command.
|
3059
|
-
It's up to you to make sure this regular expression doesn't conflict with
|
3060
|
-
another one. If it does, it's undefined which one will get matched and run.
|
3061
|
-
|
3062
|
-
In addition the instance needs these methods:
|
3063
|
-
@table @code
|
3064
|
-
@item execute
|
3065
|
-
Code which gets run when you type a command (string) that matches the command's
|
3066
|
-
regular expression.
|
3067
|
-
@item description
|
3068
|
-
A string which gets displayed when folks ask for help on that command.
|
3069
|
-
@item names
|
3070
|
-
Names and aliases of the command as an array of strings.
|
3071
|
-
@end table
|
3072
|
-
|
3073
|
-
Here's a small example of a new command:
|
3074
|
-
@smallexample
|
3075
|
-
module Byebug
|
3076
|
-
class MyCommand < Command
|
3077
|
-
def regexp
|
3078
|
-
/^\s*me$/ # Regexp that will match your command
|
3079
|
-
end
|
3080
|
-
|
3081
|
-
def execute
|
3082
|
-
puts "hi" # What you want to happen when your command runs
|
3083
|
-
end
|
3084
|
-
class << self
|
3085
|
-
def names
|
3086
|
-
%w(me)
|
3087
|
-
end
|
3088
|
-
def description
|
3089
|
-
%@{This does whatever it is I want to do@}
|
3090
|
-
end
|
3091
|
-
end
|
3092
|
-
end
|
3093
|
-
@end smallexample
|
3094
|
-
|
3095
|
-
Now here's an example of how you can load/use it:
|
3096
|
-
@smallexample
|
3097
|
-
require 'rubygems'
|
3098
|
-
require 'byebug'
|
3099
|
-
require '/tmp/mycmd.rb' # or wherever
|
3100
|
-
Byebug.start
|
3101
|
-
x=1
|
3102
|
-
byebug
|
3103
|
-
y=2
|
3104
|
-
@end smallexample
|
3105
|
-
|
3106
|
-
And now an example of invoking it:
|
3107
|
-
@smallexample
|
3108
|
-
ruby /tmp/testit.rb:
|
3109
|
-
/tmp/testit.rb:7
|
3110
|
-
y=2
|
3111
|
-
(byebug:1) help
|
3112
|
-
byebug help v1.1.0
|
3113
|
-
Type 'help <command-name>' for help on a specific command
|
3114
|
-
Available commands:
|
3115
|
-
backtrace delete enable help method putl set trace
|
3116
|
-
break disable eval info next quit show undisplay
|
3117
|
-
catch display exit irb p reload source up
|
3118
|
-
condition down finish list pp restart step var
|
3119
|
-
continue edit frame me ps save where
|
3120
|
-
^^ This is you
|
3121
|
-
|
3122
|
-
(byebug:1) help me
|
3123
|
-
This does whatever it is I want to do
|
3124
|
-
(byebug:1) me
|
3125
|
-
hi
|
3126
|
-
(byebug:1)
|
3127
|
-
@end smallexample
|
3128
|
-
|
3129
|
-
@node Kernel routines
|
3130
|
-
@section Additions to @code{Kernel}
|
3131
|
-
|
3132
|
-
@table @code
|
3133
|
-
|
3134
|
-
@item byebug @ovar{steps=1}
|
3135
|
-
@vindex @code{Kernel::byebug}
|
3136
|
-
Enters byebug after @var{steps} line-event steps. Before entering byebug, the
|
3137
|
-
startup script is read.
|
3138
|
-
|
3139
|
-
Setting @var{steps} to 0 will cause a break in byebug subroutine and not wait
|
3140
|
-
for any line event to occur. This could be useful you want to stop right after
|
3141
|
-
the last statement in some scope.
|
3142
|
-
|
3143
|
-
Consider this example:
|
3144
|
-
@smallexample
|
3145
|
-
$ cat scope-test.rb
|
3146
|
-
require 'byebug' ; Byebug.start
|
3147
|
-
1.times do
|
3148
|
-
a = 1
|
3149
|
-
byebug # implied steps=1
|
3150
|
-
end
|
3151
|
-
y = 1
|
3152
|
-
|
3153
|
-
$ ruby scope-test.rb
|
3154
|
-
y = 1
|
3155
|
-
(byebug:1) p a
|
3156
|
-
NameError Exception: undefined local variable or method `a' for main:Object
|
3157
|
-
(byebug:1)
|
3158
|
-
@end smallexample
|
3159
|
-
|
3160
|
-
Byebug will stop at the line event which follows @samp{a=1}. This is outside the
|
3161
|
-
@code{do} block scope where @var{a} is defined. If instead you want to stop
|
3162
|
-
before leaving the @code{do} loop it is possible to stop right inside
|
3163
|
-
@code{byebug}; call byebug with 0 zero parameter:
|
3164
|
-
|
3165
|
-
@smallexample
|
3166
|
-
$ cat scope-test.rb
|
3167
|
-
require 'byebug' ; Byebug.start
|
3168
|
-
1.times do
|
3169
|
-
a = 1
|
3170
|
-
byebug(0)
|
3171
|
-
end
|
3172
|
-
y = 1
|
3173
|
-
|
3174
|
-
$ ruby scope-test.rb
|
3175
|
-
../lib/byebug.rb:386
|
3176
|
-
Byebug.context.after_frame = 0
|
3177
|
-
(byebug:1) where
|
3178
|
-
--> #0 Kernel.byebug(steps#Fixnum) at ../lib/byebug-base.rb:386
|
3179
|
-
#1 at scope-test.rb:4
|
3180
|
-
#2 at scope-test.rb:2
|
3181
|
-
(byebug:1) up
|
3182
|
-
#1 at scope-test.rb:4
|
3183
|
-
(byebug:1) p a
|
3184
|
-
1
|
3185
|
-
(byebug:1)
|
3186
|
-
@end smallexample
|
3187
|
-
|
3188
|
-
As seen above you will have to position the frame up one to be back in your
|
3189
|
-
debugged program rather than in byebug.
|
3190
|
-
|
3191
|
-
@item breakpoint @ovar{steps=1}
|
3192
|
-
@vindex @code{Kernel::breakpoint}
|
3193
|
-
An alias for byebug.
|
3194
|
-
|
3195
|
-
@item binding_n @ovar{n=0}
|
3196
|
-
@vindex @code{Kernel::binding_n}
|
3197
|
-
Returns a @samp{binding()} for the @var{n}-th call frame. Note however that you
|
3198
|
-
need to first call @samp{Byebug.start} before issuing this call.
|
3199
|
-
|
3200
|
-
@end table
|
3201
|
-
|
3202
|
-
@node Contributing
|
3203
|
-
@appendix Guidelines for contributing
|
3204
|
-
|
3205
|
-
@menu
|
3206
|
-
* Testing Byebug:: Running Regression Tests
|
3207
|
-
@end menu
|
3208
|
-
|
3209
|
-
@node Testing Byebug
|
3210
|
-
@section Testing Byebug
|
3211
|
-
|
3212
|
-
We've put together some basic tests to make sure byebug is doing
|
3213
|
-
what we think it should do. To run these (from @code{trunk}):
|
3214
|
-
|
3215
|
-
@smallexample
|
3216
|
-
rake test
|
3217
|
-
@end smallexample
|
3218
|
-
|
3219
|
-
If you didn't build byebug shared library and skipped step 2,
|
3220
|
-
don't worry @code{rake test} will do step 2 for you. You should see a
|
3221
|
-
line that ends something like:
|
3222
|
-
|
3223
|
-
@smallexample
|
3224
|
-
Finished tests in 2.358177s, 155.2046 tests/s, 172.1669 assertions/s.
|
3225
|
-
|
3226
|
-
366 tests, 406 assertions, 0 failures, 0 errors, 17 skips
|
3227
|
-
@end smallexample
|
3228
|
-
|
3229
|
-
The number of seconds, tests, and assertions may be different from the above.
|
3230
|
-
However you @emph{should} see exactly ``0 failures, 0 errors.''
|
3231
|
-
|
3232
|
-
@node Class Module Method Index
|
3233
|
-
@unnumbered Class, Module and Method Index
|
3234
|
-
@printindex vr
|
3235
|
-
|
3236
|
-
@node Command Index
|
3237
|
-
@unnumbered Command Index
|
3238
|
-
@printindex ky
|
3239
|
-
|
3240
|
-
@node General Index
|
3241
|
-
@unnumbered General Index
|
3242
|
-
@printindex cp
|
3243
|
-
|
3244
|
-
@tex
|
3245
|
-
% I think something like @colophon should be in texinfo. In the meantime:
|
3246
|
-
\long\def\colophon{\hbox to0pt{}\vfill
|
3247
|
-
\centerline{The body of this manual is set in}
|
3248
|
-
\centerline{\fontname\tenrm,}
|
3249
|
-
\centerline{with headings in {\bf\fontname\tenbf}}
|
3250
|
-
\centerline{and examples in {\tt\fontname\tentt}.}
|
3251
|
-
\centerline{{\it\fontname\tenit\/},}
|
3252
|
-
\centerline{{\bf\fontname\tenbf}, and}
|
3253
|
-
\centerline{{\sl\fontname\tensl\/}}
|
3254
|
-
\centerline{are used for emphasis.}\vfill}
|
3255
|
-
\page\colophon
|
3256
|
-
% Blame: doc@cygnus.com, 1991.
|
3257
|
-
@end tex
|
3258
|
-
|
3259
|
-
@bye
|