byebug 1.4.2 → 1.5.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/GUIDE.md +72 -187
- data/bin/byebug +0 -3
- data/byebug.gemspec +1 -1
- data/ext/byebug/byebug.c +22 -25
- data/ext/byebug/context.c +15 -7
- data/ext/byebug/extconf.rb +1 -1
- data/lib/byebug.rb +0 -41
- data/lib/byebug/commands/frame.rb +0 -46
- data/lib/byebug/context.rb +0 -1
- data/lib/byebug/processor.rb +1 -1
- data/lib/byebug/version.rb +1 -1
- data/old_doc/test-triangle.rb +2 -3
- data/test/examples/frame_deep.rb +20 -0
- data/test/frame_test.rb +38 -4
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4921997bbc597c75dbd51c1a5abde4fa366ce05
|
4
|
+
data.tar.gz: e56edf6e9529823d52edfe543ed9f450258bf893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d7c6ffe0e19f58695bc007a1b44b44e743cd669939a53b0c491d209d417f4f963ca18085d07c5b7ca5a9fe7820ca59455bd2ec269c9a6963d3bdfe0a75bffe
|
7
|
+
data.tar.gz: ce3049894fe8169c214ce6953dd468a3343caa1e45971f093d9a73e5f3c6b778d4fa51b0ecbdb3806094b776fb4adecb4965c77689e5470a2a7fed5503dc5fce
|
data/CHANGELOG.md
CHANGED
data/GUIDE.md
CHANGED
@@ -98,8 +98,8 @@ Okay, lets go on and talk about program arguments.
|
|
98
98
|
[]
|
99
99
|
```
|
100
100
|
|
101
|
-
Ooops. We forgot to specify any parameters to this program. Let's try again. We
|
102
|
-
use the `restart` command here.
|
101
|
+
Ooops. We forgot to specify any parameters to this program. Let's try again. We
|
102
|
+
can use the `restart` command here.
|
103
103
|
|
104
104
|
```
|
105
105
|
(byebug) restart 3
|
@@ -175,10 +175,8 @@ Stopped by breakpoint 1 at /home/davidr/Proyectos/byebug/old_doc/hanoi.rb:3
|
|
175
175
|
(byebug) set nofullpath
|
176
176
|
Displaying frame's full file names is off.
|
177
177
|
(byebug) where
|
178
|
-
--> #0 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol)
|
179
|
-
|
180
|
-
#1 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol)
|
181
|
-
at .../byebug/old_doc/hanoi.rb:8
|
178
|
+
--> #0 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at .../byebug/old_doc/hanoi.rb:4
|
179
|
+
#1 Object.hanoi(n#Fixnum, a#Symbol, b#Symbol, c#Symbol) at .../byebug/old_doc/hanoi.rb:8
|
182
180
|
#2 <top (required)> at .../byebug/old_doc/hanoi.rb:34
|
183
181
|
(byebug)
|
184
182
|
```
|
@@ -231,19 +229,12 @@ frame #3, the value of `i_args` can be shown. Also note that the value of
|
|
231
229
|
variable `n` is different.
|
232
230
|
|
233
231
|
|
234
|
-
###
|
232
|
+
### Attaching to a running program with `byebug`
|
235
233
|
|
236
|
-
In the previous sessions we've been calling byebug right at the outset, but
|
237
|
-
is
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
* Byebug just doesn't work when run at the outset. Any debugging changes the
|
242
|
-
behavior or the program in slight and subtle ways, and sometimes this can hinder
|
243
|
-
finding bugs.
|
244
|
-
* There's a lot of code that needs to be run before the part you want to
|
245
|
-
inspect. Running this code takes time and you don't want the overhead of
|
246
|
-
byebug.
|
234
|
+
In the previous sessions we've been calling byebug right at the outset, but
|
235
|
+
there is another mode of operation you might use. If there's a lot of code that
|
236
|
+
needs to be run before the part you want to inspect, it might not be efficient
|
237
|
+
or convenient to run byebug from the outset.
|
247
238
|
|
248
239
|
In this section we'll show how to enter the code in the middle of your program,
|
249
240
|
while delving more into byebug's operation. We will also use unit testing. Using
|
@@ -269,15 +260,15 @@ if __FILE__ == $0
|
|
269
260
|
end
|
270
261
|
```
|
271
262
|
|
272
|
-
Okay, we're now ready to write our unit test. We'll use `
|
263
|
+
Okay, we're now ready to write our unit test. We'll use `minitest` which comes
|
273
264
|
with the standard Ruby distribution. Here's the test code; it should be in the
|
274
265
|
same directory as `triangle.rb`.
|
275
266
|
|
276
267
|
```ruby
|
277
|
-
require '
|
268
|
+
require 'minitest/autorun'
|
278
269
|
require_relative 'triangle.rb'
|
279
270
|
|
280
|
-
class TestTri <
|
271
|
+
class TestTri < MiniTest::Unit::TestCase
|
281
272
|
def test_basic
|
282
273
|
solutions = []
|
283
274
|
0.upto(5) do |i|
|
@@ -295,145 +286,62 @@ add the following:
|
|
295
286
|
```ruby
|
296
287
|
...
|
297
288
|
def test_basic
|
298
|
-
require 'byebug'
|
299
289
|
byebug
|
300
290
|
solutions = []
|
301
291
|
...
|
302
292
|
```
|
303
293
|
|
304
|
-
Now we run the program
|
294
|
+
Now we run the program, requiring `byebug`
|
305
295
|
```
|
306
|
-
$ ruby test-triangle.rb
|
307
|
-
Run options:
|
296
|
+
$ ruby -rbyebug test-triangle.rb
|
297
|
+
Run options: --seed 13073
|
308
298
|
|
309
299
|
# Running tests:
|
310
300
|
|
311
|
-
[
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
=>
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
301
|
+
[2, 11] in test-triangle.rb
|
302
|
+
2: require_relative 'triangle.rb'
|
303
|
+
3:
|
304
|
+
4: class TestTri < MiniTest::Unit::TestCase
|
305
|
+
5: def test_basic
|
306
|
+
6: byebug
|
307
|
+
=> 7: solutions = []
|
308
|
+
8: 0.upto(5) do |i|
|
309
|
+
9: solutions << triangle(i)
|
310
|
+
10: end
|
311
|
+
11: assert_equal([0, 1, 3, 6, 10, 15], solutions,
|
322
312
|
(byebug)
|
323
313
|
```
|
324
314
|
|
325
|
-
and we see that we are stopped at line
|
315
|
+
and we see that we are stopped at line 7 just before the initialization of the
|
326
316
|
list `solutions`.
|
327
317
|
|
328
318
|
Now let's see where we are...
|
329
319
|
```
|
330
|
-
(byebug)
|
331
|
-
|
332
|
-
|
320
|
+
(byebug) set nofullpath
|
321
|
+
Displaying frame's full file names is off.
|
322
|
+
(byebug) bt
|
323
|
+
--> #0 TestTri.test_basic at test-triangle.rb:7
|
324
|
+
#1 MiniTest::Unit::TestCase.run(runner#MiniTest::Unit) at .../2.0.0/minitest/unit.rb:1301
|
325
|
+
#2 MiniTest::Unit.block in _run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:919
|
326
|
+
#3 Array.map(frame_no#Fixnum) at .../2.0.0/minitest/unit.rb:912
|
327
|
+
#4 MiniTest::Unit._run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:912
|
328
|
+
#5 MiniTest::Unit.block in _run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
|
329
|
+
#6 Array.map(frame_no#Fixnum) at .../2.0.0/minitest/unit.rb:899
|
330
|
+
#7 MiniTest::Unit._run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
|
331
|
+
#8 MiniTest::Unit._run_anything(type#Symbol) at .../2.0.0/minitest/unit.rb:867
|
332
|
+
#9 MiniTest::Unit.run_tests at .../2.0.0/minitest/unit.rb:1060
|
333
|
+
#10 MiniTest::Unit.block in _run(args#Array) at .../2.0.0/minitest/unit.rb:1047
|
334
|
+
#11 Array.each(frame_no#Fixnum) at .../2.0.0/minitest/unit.rb:1046
|
335
|
+
#12 MiniTest::Unit._run(args#Array) at .../2.0.0/minitest/unit.rb:1046
|
336
|
+
#13 MiniTest::Unit.run(args#Array) at .../2.0.0/minitest/unit.rb:1035
|
337
|
+
#14 #<Class:MiniTest::Unit>.block in autorun at .../2.0.0/minitest/unit.rb:789
|
333
338
|
(byebug)
|
334
339
|
```
|
335
340
|
|
336
|
-
|
337
|
-
`TestTri` in method `test_basic`. However we don't see the call to this like we
|
338
|
-
did in the last example when we used the `where` command. This is because byebug
|
339
|
-
really didn't spring into existence until after we already had entered that
|
340
|
-
method, and Ruby doesn't keep call stack information around in a way that would
|
341
|
-
give the information we show when running `where`.
|
342
|
-
|
343
|
-
If we want call stack information, we have to turn call-stack tracking on
|
344
|
-
_beforehand_. This is done by adding `Byebug.start`.
|
345
|
-
|
346
|
-
Here's what our test program looks like after we modify it to start tracking
|
347
|
-
calls from the outset
|
348
|
-
|
349
|
-
```ruby
|
350
|
-
require 'test/unit'
|
351
|
-
require_relative 'triangle.rb'
|
352
|
-
require 'byebug'
|
353
|
-
Byebug.start
|
354
|
-
|
355
|
-
class TestTri < Test::Unit::TestCase
|
356
|
-
def test_basic
|
357
|
-
byebug
|
358
|
-
solutions = []
|
359
|
-
0.upto(5) do |i|
|
360
|
-
solutions << triangle(i)
|
361
|
-
end
|
362
|
-
assert_equal([0, 1, 3, 6, 10, 15], solutions,
|
363
|
-
"Testing the first 5 triangle numbers")
|
364
|
-
end
|
365
|
-
end
|
366
|
-
```
|
341
|
+
We get the same result as if we had run byebug from the outset, just faster!
|
367
342
|
|
368
|
-
|
369
|
-
|
370
|
-
$ ruby test-triangle.rb
|
371
|
-
Run options:
|
372
|
-
|
373
|
-
# Running tests:
|
374
|
-
|
375
|
-
[1/1] TestTri#test_basic[5, 14] in test-triangle.rb
|
376
|
-
5:
|
377
|
-
6: class TestTri < Test::Unit::TestCase
|
378
|
-
7: def test_basic
|
379
|
-
8: require 'byebug'
|
380
|
-
9: byebug
|
381
|
-
=> 10: solutions = []
|
382
|
-
11: 0.upto(5) do |i|
|
383
|
-
12: solutions << triangle(i)
|
384
|
-
13: end
|
385
|
-
14: assert_equal([0, 1, 3, 6, 10, 15], solutions,
|
386
|
-
(byebug) where
|
387
|
-
--> #0 TestTri.test_basic at test-triangle.rb:10
|
388
|
-
#1 MiniTest::Unit::TestCase.run_test(name#String)
|
389
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:858
|
390
|
-
#2 MiniTest::Unit::TestCase.run(runner#Test::Unit::Runner)
|
391
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1301
|
392
|
-
#3 Test::Unit::TestCase.run(runner#Test::Unit::Runner)
|
393
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit/testcase.rb:17
|
394
|
-
#4 MiniTest::Unit._run_suite(suite#Class, type#Symbol)
|
395
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:919
|
396
|
-
#5 Array.map(suite#Class, type#Symbol)
|
397
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:912
|
398
|
-
#6 MiniTest::Unit._run_suite(suite#Class, type#Symbol)
|
399
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:912
|
400
|
-
#7 Test::Unit::Runner._run_suites(suites#Array, type#Symbol)
|
401
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:657
|
402
|
-
#8 Array.each(suites#Array, type#Symbol)
|
403
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:655
|
404
|
-
#9 Test::Unit::Runner._run_suites(suites#Array, type#Symbol)
|
405
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:655
|
406
|
-
#10 MiniTest::Unit._run_anything(type#Symbol)
|
407
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:867
|
408
|
-
#11 MiniTest::Unit.run_tests
|
409
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1060
|
410
|
-
#12 MiniTest::Unit._run(args#Array)
|
411
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1047
|
412
|
-
#13 Array.each(args#Array)
|
413
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1046
|
414
|
-
#14 MiniTest::Unit._run(args#Array)
|
415
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1046
|
416
|
-
#15 MiniTest::Unit._run(args#Array)
|
417
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1042
|
418
|
-
#16 MiniTest::Unit.run(args#Array)
|
419
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1035
|
420
|
-
#17 Test::Unit::RunCount.run(args#NilClass)
|
421
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:21
|
422
|
-
#18 Test::Unit::Runner.run(args#Array)
|
423
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:774
|
424
|
-
#19 #<Class:Test::Unit::Runner>.autorun
|
425
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:366
|
426
|
-
#20 Test::Unit::RunCount.run_once
|
427
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:27
|
428
|
-
#21 #<Class:Test::Unit::Runner>.autorun
|
429
|
-
at /home/davidr/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:367
|
430
|
-
#22 <main> at test-triangle.rb:6
|
431
|
-
(byebug)
|
432
|
-
```
|
433
|
-
|
434
|
-
Much better. But again let me emphasize that the parameter types are those of
|
435
|
-
the corresponding variables that _currently_ exist, and this might have changed
|
436
|
-
since the time when the call was made.
|
343
|
+
__NOTICE: In ruby-debug, debugger and older versions of byebug, this would not
|
344
|
+
work as expected. If you are having issues, please upgrade to byebug >= 1.5.0__
|
437
345
|
|
438
346
|
|
439
347
|
### Byebug.start with a block
|
@@ -461,12 +369,12 @@ For example, you can do this in `irb`:
|
|
461
369
|
```
|
462
370
|
$ irb
|
463
371
|
2.0.0p195 :001 > require 'byebug'
|
464
|
-
=> true
|
372
|
+
=> true
|
465
373
|
2.0.0p195 :002 > def foo
|
466
374
|
2.0.0p195 :003?> x=1
|
467
375
|
2.0.0p195 :004?> puts 'foo'
|
468
376
|
2.0.0p195 :005?> end
|
469
|
-
=> nil
|
377
|
+
=> nil
|
470
378
|
2.0.0p195 :006 > Byebug.start{byebug; foo}
|
471
379
|
(irb) @ 6
|
472
380
|
(byebug) s
|
@@ -477,8 +385,8 @@ $ irb
|
|
477
385
|
1
|
478
386
|
(byebug) s
|
479
387
|
foo
|
480
|
-
=> true
|
481
|
-
2.0.0p195 :007 >
|
388
|
+
=> true
|
389
|
+
2.0.0p195 :007 >
|
482
390
|
```
|
483
391
|
|
484
392
|
There is a counter inside of `Byebug.start` method to make sure that this works
|
@@ -486,6 +394,7 @@ when another `Byebug.start` method is called inside of the outer one. However,
|
|
486
394
|
if you are stopped inside byebug, issuing another `byebug` call will not have
|
487
395
|
any effect even if it is nested inside another `Byebug.start`.
|
488
396
|
|
397
|
+
|
489
398
|
### Debugging Oddities: How debugging Ruby may be different from other languages
|
490
399
|
|
491
400
|
If you are used to debugging in other languages like C, C++, Perl, Java or even
|
@@ -497,18 +406,12 @@ those other languages, writing a debugger has to also be a little different as
|
|
497
406
|
well if it is to be useful. In this respect, using byebug may help you
|
498
407
|
understand Ruby better.
|
499
408
|
|
500
|
-
We've already seen
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
this. In other languages call stack information is usually available without
|
507
|
-
asking assistance of the debugger (in C and C++, however, you generally have to
|
508
|
-
ask the compiler to add such information.).
|
509
|
-
|
510
|
-
In this section we'll consider some other things that might throw off new users
|
511
|
-
to Ruby who are familiar with other languages and debugging in them.
|
409
|
+
We've already seen one such difference: the fact that we stop on method
|
410
|
+
definitions or `def`'s and that is because these are in fact executable
|
411
|
+
statements. In other compiled languages this would not happen because that's
|
412
|
+
already been done when you compile the program (or in Perl when it scans in the
|
413
|
+
program). In this section we'll consider some other things that might throw off
|
414
|
+
new users to Ruby who are familiar with other languages and debugging in them.
|
512
415
|
|
513
416
|
* Bouncing Around in Blocks (iterators)
|
514
417
|
* No Parameter Values in a Call Stack
|
@@ -642,7 +545,7 @@ To be continued...
|
|
642
545
|
* line tracing and non-interactive tracing.
|
643
546
|
* mixing in Byebug.debug with byebug
|
644
547
|
* post-mortem debugging and setting up for that
|
645
|
-
|
548
|
+
|
646
549
|
|
647
550
|
## Getting in & out
|
648
551
|
|
@@ -751,7 +654,7 @@ Here are the default values in `options`
|
|
751
654
|
|
752
655
|
```ruby
|
753
656
|
#<OpenStruct annotate=nil, nx=false, quit=true, restart_script=nil, script=nil,
|
754
|
-
stop=true, tracing=false, verbose_long=false>
|
657
|
+
stop=true, tracing=false, verbose_long=false>
|
755
658
|
```
|
756
659
|
|
757
660
|
## Command Files
|
@@ -799,35 +702,17 @@ change the script and make an explicit call to byebug. Because byebug isn't
|
|
799
702
|
involved before the first call, there is no overhead and the script will run
|
800
703
|
at the same speed as if there were no byebug.
|
801
704
|
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
To tell byebug to start tracking things, do
|
814
|
-
|
815
|
-
```ruby
|
816
|
-
Byebug.start
|
817
|
-
```
|
818
|
-
|
819
|
-
There is also a `Byebug.stop` to turn off byebug tracking. If speed is crucial,
|
820
|
-
you may want to start and stop this around certain sections of code.
|
821
|
-
Alternatively, instead of issuing an explicit `Byebug.stop` you can add a block
|
822
|
-
to the `Byebug.start` and debugging is turned on for that block. If the block of
|
823
|
-
code raises an uncaught exception that would cause the block to terminate, the
|
824
|
-
`stop` will occur. See [here](Byebug.start with a block).
|
825
|
-
|
826
|
-
And finally to enter byebug
|
827
|
-
|
828
|
-
```ruby
|
829
|
-
byebug
|
830
|
-
```
|
705
|
+
To enter byebug this way, just drop `byebug` in whichever line you want to start
|
706
|
+
debugging at. You also have to require byebug somehow. If using bundler, it will
|
707
|
+
take care of that for you, otherwise you can use the ruby `-r` flag or add
|
708
|
+
`require 'byebug'` in the line previous to the `byebug` call.
|
709
|
+
|
710
|
+
If speed is crucial, you may want to start and stop this around certain sections
|
711
|
+
of code, using `Byebug.start` and `Byebug.stop`. Alternatively, instead of
|
712
|
+
issuing an explicit `Byebug.stop` you can add a block to the `Byebug.start` and
|
713
|
+
debugging is turned on for that block. If the block of code raises an uncaught
|
714
|
+
exception that would cause the block to terminate, the `stop` will occur. See
|
715
|
+
[Byebug.start with a block]().
|
831
716
|
|
832
717
|
When `byebug`is run, `.byebugrc` is read.
|
833
718
|
|
data/bin/byebug
CHANGED
@@ -76,9 +76,6 @@ def debug_program(options)
|
|
76
76
|
end
|
77
77
|
print "\032\032starting\n" if Byebug.annotate and Byebug.annotate > 2
|
78
78
|
|
79
|
-
# Record where we are we can know if the call stack has been truncated or not.
|
80
|
-
Byebug.start_sentinal = caller[0]
|
81
|
-
|
82
79
|
if bt = Byebug.debug_load(Byebug::PROG_SCRIPT, options.stop)
|
83
80
|
print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
84
81
|
print "Uncaught exception: #{bt}\n"
|
data/byebug.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency "columnize", "~> 0.3.6"
|
27
27
|
s.add_dependency "debugger-linecache", '~> 1.2.0'
|
28
28
|
|
29
|
-
s.add_development_dependency 'rake', '~> 10.0
|
29
|
+
s.add_development_dependency 'rake', '~> 10.1.0'
|
30
30
|
s.add_development_dependency 'rake-compiler', '~> 0.8.3'
|
31
31
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
32
32
|
end
|
data/ext/byebug/byebug.c
CHANGED
@@ -25,13 +25,13 @@ tp_inspect(rb_trace_arg_t *trace_arg) {
|
|
25
25
|
if (ID2SYM(rb_intern("line")) == event ||
|
26
26
|
ID2SYM(rb_intern("specified_line")) == event)
|
27
27
|
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
VALUE sym = rb_tracearg_method_id(trace_arg);
|
29
|
+
if (NIL_P(sym)) sym = rb_str_new_cstr("<main>");
|
30
|
+
return rb_sprintf("%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'",
|
31
|
+
rb_tracearg_event(trace_arg),
|
32
|
+
rb_tracearg_path(trace_arg),
|
33
|
+
FIX2INT(rb_tracearg_lineno(trace_arg)),
|
34
|
+
sym);
|
35
35
|
}
|
36
36
|
if (ID2SYM(rb_intern("call")) == event ||
|
37
37
|
ID2SYM(rb_intern("c_call")) == event ||
|
@@ -53,9 +53,6 @@ tp_inspect(rb_trace_arg_t *trace_arg) {
|
|
53
53
|
static VALUE
|
54
54
|
Byebug_context(VALUE self)
|
55
55
|
{
|
56
|
-
if (context == Qnil) {
|
57
|
-
context = context_create();
|
58
|
-
}
|
59
56
|
return context;
|
60
57
|
}
|
61
58
|
|
@@ -133,15 +130,17 @@ call_at_line_check(VALUE context_obj, debug_context_t *dc,
|
|
133
130
|
call_at_line(context_obj, dc, file, line);
|
134
131
|
}
|
135
132
|
|
133
|
+
#define BYEBUG_STARTED (catchpoints != Qnil)
|
134
|
+
|
136
135
|
#define EVENT_SETUP \
|
137
136
|
rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(trace_point); \
|
138
|
-
VALUE context_obj; \
|
139
137
|
debug_context_t *dc; \
|
140
|
-
|
141
|
-
|
138
|
+
if (!BYEBUG_STARTED) \
|
139
|
+
rb_raise(rb_eRuntimeError, "Byebug not started yet!"); \
|
140
|
+
Data_Get_Struct(context, debug_context_t, dc); \
|
142
141
|
if (debug == Qtrue) \
|
143
142
|
printf("%s (stack_size: %d)\n", \
|
144
|
-
|
143
|
+
RSTRING_PTR(tp_inspect(trace_arg)), dc->stack_size); \
|
145
144
|
|
146
145
|
#define EVENT_COMMON() \
|
147
146
|
if (trace_common(trace_arg, dc) == 0) { return; }
|
@@ -187,7 +186,7 @@ process_line_event(VALUE trace_point, void *data)
|
|
187
186
|
}
|
188
187
|
|
189
188
|
if (RTEST(tracing))
|
190
|
-
call_at_tracing(
|
189
|
+
call_at_tracing(context, dc, file, line);
|
191
190
|
|
192
191
|
if (moved || !CTX_FL_TEST(dc, CTX_FL_FORCE_MOVE))
|
193
192
|
{
|
@@ -204,7 +203,7 @@ process_line_event(VALUE trace_point, void *data)
|
|
204
203
|
(!NIL_P(
|
205
204
|
breakpoint = find_breakpoint_by_pos(breakpoints, file, line, binding)))))
|
206
205
|
{
|
207
|
-
call_at_line_check(
|
206
|
+
call_at_line_check(context, dc, breakpoint, file, line);
|
208
207
|
}
|
209
208
|
|
210
209
|
cleanup(dc);
|
@@ -265,8 +264,8 @@ process_call_event(VALUE trace_point, void *data)
|
|
265
264
|
find_breakpoint_by_method(breakpoints, klass, mid, binding, self);
|
266
265
|
if (breakpoint != Qnil)
|
267
266
|
{
|
268
|
-
call_at_breakpoint(
|
269
|
-
call_at_line(
|
267
|
+
call_at_breakpoint(context, dc, breakpoint);
|
268
|
+
call_at_line(context, dc, file, line);
|
270
269
|
}
|
271
270
|
|
272
271
|
cleanup(dc);
|
@@ -324,8 +323,8 @@ process_raise_event(VALUE trace_point, void *data)
|
|
324
323
|
if (hit_count != Qnil)
|
325
324
|
{
|
326
325
|
rb_hash_aset(catchpoints, mod_name, INT2FIX(FIX2INT(hit_count) + 1));
|
327
|
-
call_at_catchpoint(
|
328
|
-
call_at_line(
|
326
|
+
call_at_catchpoint(context, dc, err);
|
327
|
+
call_at_line(context, dc, path, lineno);
|
329
328
|
break;
|
330
329
|
}
|
331
330
|
}
|
@@ -340,6 +339,7 @@ Byebug_setup_tracepoints(VALUE self)
|
|
340
339
|
|
341
340
|
breakpoints = rb_ary_new();
|
342
341
|
catchpoints = rb_hash_new();
|
342
|
+
context = context_create();
|
343
343
|
|
344
344
|
tpLine = rb_tracepoint_new(Qnil,
|
345
345
|
RUBY_EVENT_LINE,
|
@@ -392,7 +392,6 @@ Byebug_remove_tracepoints(VALUE self)
|
|
392
392
|
return Qnil;
|
393
393
|
}
|
394
394
|
|
395
|
-
#define BYEBUG_STARTED (catchpoints != Qnil)
|
396
395
|
static VALUE
|
397
396
|
Byebug_started(VALUE self)
|
398
397
|
{
|
@@ -463,7 +462,7 @@ Byebug_load(int argc, VALUE *argv, VALUE self)
|
|
463
462
|
Data_Get_Struct(context_obj, debug_context_t, dc);
|
464
463
|
if (RTEST(stop)) dc->steps = 1;
|
465
464
|
|
466
|
-
/*
|
465
|
+
/* Reset stack size to ignore byebug's own frames */
|
467
466
|
dc->stack_size = 0;
|
468
467
|
|
469
468
|
/* Initializing $0 to the script's path */
|
@@ -545,8 +544,6 @@ Byebug_breakpoints(VALUE self)
|
|
545
544
|
static VALUE
|
546
545
|
Byebug_catchpoints(VALUE self)
|
547
546
|
{
|
548
|
-
if (catchpoints == Qnil)
|
549
|
-
rb_raise(rb_eRuntimeError, "Byebug.start is not called yet.");
|
550
547
|
return catchpoints;
|
551
548
|
}
|
552
549
|
|
@@ -595,7 +592,7 @@ Init_byebug()
|
|
595
592
|
|
596
593
|
Init_breakpoint(mByebug);
|
597
594
|
|
598
|
-
context
|
595
|
+
context = Qnil;
|
599
596
|
catchpoints = Qnil;
|
600
597
|
breakpoints = Qnil;
|
601
598
|
|
data/ext/byebug/context.c
CHANGED
@@ -42,6 +42,13 @@ context_free(void *data)
|
|
42
42
|
|
43
43
|
}
|
44
44
|
|
45
|
+
static int
|
46
|
+
real_stack_size()
|
47
|
+
{
|
48
|
+
VALUE locs = rb_funcall(rb_cObject, rb_intern("caller_locations"), 1, INT2FIX(0));
|
49
|
+
return (int)RARRAY_LEN(locs);
|
50
|
+
}
|
51
|
+
|
45
52
|
extern VALUE
|
46
53
|
context_create()
|
47
54
|
{
|
@@ -50,7 +57,7 @@ context_create()
|
|
50
57
|
context->last_file = Qnil;
|
51
58
|
context->last_line = Qnil;
|
52
59
|
context->flags = 0;
|
53
|
-
context->stack_size =
|
60
|
+
context->stack_size = real_stack_size();
|
54
61
|
reset_stepping_stop_points(context);
|
55
62
|
context->stop_reason = CTX_STOP_NONE;
|
56
63
|
context->backtrace = Qnil;
|
@@ -187,7 +194,7 @@ call_with_debug_inspector(struct call_with_inspection_data *data)
|
|
187
194
|
if (frame_n < 0 || frame_n >= context->stack_size) \
|
188
195
|
{ \
|
189
196
|
rb_raise(rb_eArgError, "Invalid frame number %d, stack (0...%d)", \
|
190
|
-
|
197
|
+
frame_n, context->stack_size - 1); \
|
191
198
|
} \
|
192
199
|
|
193
200
|
static VALUE
|
@@ -335,9 +342,9 @@ Context_step_into(int argc, VALUE *argv, VALUE self)
|
|
335
342
|
context->steps = FIX2INT(steps);
|
336
343
|
|
337
344
|
if (RTEST(force))
|
338
|
-
|
345
|
+
CTX_FL_SET(context, CTX_FL_FORCE_MOVE);
|
339
346
|
else
|
340
|
-
|
347
|
+
CTX_FL_UNSET(context, CTX_FL_FORCE_MOVE);
|
341
348
|
|
342
349
|
return steps;
|
343
350
|
}
|
@@ -349,13 +356,14 @@ Context_step_over(int argc, VALUE *argv, VALUE self)
|
|
349
356
|
debug_context_t *context;
|
350
357
|
|
351
358
|
Data_Get_Struct(self, debug_context_t, context);
|
359
|
+
|
352
360
|
if (context->stack_size == 0)
|
353
361
|
rb_raise(rb_eRuntimeError, "No frames collected.");
|
354
362
|
|
355
363
|
rb_scan_args(argc, argv, "12", &lines, &frame, &force);
|
356
364
|
context->lines = FIX2INT(lines);
|
357
365
|
|
358
|
-
if (FIX2INT(frame) < 0
|
366
|
+
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->stack_size)
|
359
367
|
rb_raise(rb_eRuntimeError, "Destination frame is out of range.");
|
360
368
|
context->dest_frame = context->stack_size - FIX2INT(frame);
|
361
369
|
|
@@ -371,9 +379,9 @@ static VALUE
|
|
371
379
|
Context_step_out(VALUE self, VALUE frame)
|
372
380
|
{
|
373
381
|
debug_context_t *context;
|
374
|
-
|
375
382
|
Data_Get_Struct(self, debug_context_t, context);
|
376
|
-
|
383
|
+
|
384
|
+
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->stack_size)
|
377
385
|
rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
|
378
386
|
|
379
387
|
context->stop_frame = context->stack_size - FIX2INT(frame);
|
data/ext/byebug/extconf.rb
CHANGED
data/lib/byebug.rb
CHANGED
@@ -36,9 +36,6 @@ module Byebug
|
|
36
36
|
# If in remote mode, wait for the remote connection
|
37
37
|
attr_accessor :wait_connection
|
38
38
|
|
39
|
-
# A string to look for in caller() to see if the call stack is truncated
|
40
|
-
attr_accessor :start_sentinal
|
41
|
-
|
42
39
|
def source_reload
|
43
40
|
Object.send(:remove_const, "SCRIPT_LINES__") if
|
44
41
|
Object.const_defined?("SCRIPT_LINES__")
|
@@ -111,7 +108,6 @@ module Byebug
|
|
111
108
|
Byebug.const_set('INITIAL_DIR', Dir.pwd) unless defined? Byebug::INITIAL_DIR
|
112
109
|
end
|
113
110
|
Byebug.tracing = options[:tracing] unless options[:tracing].nil?
|
114
|
-
Byebug.start_sentinal = caller[0]
|
115
111
|
if Byebug.started?
|
116
112
|
retval = block && block.call(self)
|
117
113
|
else
|
@@ -269,40 +265,3 @@ module Kernel
|
|
269
265
|
end
|
270
266
|
alias breakpoint byebug unless respond_to?(:breakpoint)
|
271
267
|
end
|
272
|
-
|
273
|
-
module Rails
|
274
|
-
module Rack
|
275
|
-
class Debugger
|
276
|
-
def initialize(app)
|
277
|
-
@app = app
|
278
|
-
|
279
|
-
# clear ARGV so that rails server options aren't passed to IRB
|
280
|
-
ARGV.clear
|
281
|
-
|
282
|
-
require 'byebug'
|
283
|
-
|
284
|
-
::Byebug.start
|
285
|
-
puts "=> Byebug enabled"
|
286
|
-
rescue LoadError
|
287
|
-
puts "You're missing the 'byebug' gem. Add it to your Gemfile, " \
|
288
|
-
"bundle it and try again."
|
289
|
-
exit
|
290
|
-
end
|
291
|
-
|
292
|
-
def call(env)
|
293
|
-
@app.call(env)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
class Console
|
299
|
-
def require_debugger
|
300
|
-
require 'byebug'
|
301
|
-
puts "=> Byebug enabled"
|
302
|
-
rescue LoadError
|
303
|
-
puts "You're missing the 'byebug' gem. Add it to your Gemfile, bundle, " \
|
304
|
-
"it and try again."
|
305
|
-
exit
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
@@ -115,48 +115,6 @@ module Byebug
|
|
115
115
|
|
116
116
|
print frame_str
|
117
117
|
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# Check if call stack is truncated. This can happen if Byebug.start is not
|
121
|
-
# called low enough in the call stack. An array of additional callstack
|
122
|
-
# lines from caller is returned if definitely truncated, false if not, and
|
123
|
-
# nil if we don't know.
|
124
|
-
#
|
125
|
-
# We determine truncation based on a passed in sentinal set via caller which
|
126
|
-
# can be nil.
|
127
|
-
#
|
128
|
-
# First we see if we can find our position in caller. If so, then we compare
|
129
|
-
# context position to that in caller using sentinal as a place to start
|
130
|
-
# ignoring additional caller entries. sentinal is set by byebug, but if it's
|
131
|
-
# nil then additional entries are presumably ones that we haven't recorded
|
132
|
-
# in context
|
133
|
-
def truncated_callstack?(sentinal=nil, cs=caller)
|
134
|
-
recorded_size = @state.context.stack_size
|
135
|
-
to_find_fl =
|
136
|
-
"#{@state.context.frame_file(0)}:#{@state.context.frame_line(0)}"
|
137
|
-
top_discard = false
|
138
|
-
cs.each_with_index do |fl, i|
|
139
|
-
fl.gsub!(/in `.*'$/, '')
|
140
|
-
fl.gsub!(/:$/, '')
|
141
|
-
if fl == to_find_fl
|
142
|
-
top_discard = i
|
143
|
-
break
|
144
|
-
end
|
145
|
-
end
|
146
|
-
if top_discard
|
147
|
-
cs = cs[top_discard..-1]
|
148
|
-
return false unless cs
|
149
|
-
return cs unless sentinal
|
150
|
-
if cs.size > recorded_size+2 && cs[recorded_size+2] != sentinal
|
151
|
-
# caller seems to truncate recursive calls and we don't.
|
152
|
-
# See if we can find sentinal in the first 0..recorded_size+1 entries
|
153
|
-
return false if cs[0..recorded_size+1].any?{ |f| f==sentinal }
|
154
|
-
return cs
|
155
|
-
end
|
156
|
-
return false
|
157
|
-
end
|
158
|
-
return nil
|
159
|
-
end
|
160
118
|
end
|
161
119
|
|
162
120
|
# Implements byebug "where" or "backtrace" command.
|
@@ -167,10 +125,6 @@ module Byebug
|
|
167
125
|
|
168
126
|
def execute
|
169
127
|
print_backtrace
|
170
|
-
if truncated_callstack?(Byebug.start_sentinal)
|
171
|
-
print \
|
172
|
-
"Warning: saved frames may be incomplete; compare with caller(0)\n"
|
173
|
-
end
|
174
128
|
end
|
175
129
|
|
176
130
|
class << self
|
data/lib/byebug/context.rb
CHANGED
data/lib/byebug/processor.rb
CHANGED
data/lib/byebug/version.rb
CHANGED
data/old_doc/test-triangle.rb
CHANGED
data/test/frame_test.rb
CHANGED
@@ -44,8 +44,8 @@ class TestFrame < TestDsl::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'must set frame to the last one' do
|
47
|
-
enter 'break 16', 'cont', 'frame -1'
|
48
|
-
debug_file('frame') { state.file.must_match /
|
47
|
+
enter 'break 16', 'cont', 'bt', 'frame -1'
|
48
|
+
debug_file('frame') { state.file.must_match /minitest\/unit.rb/ }
|
49
49
|
check_output_doesnt_include "at #{fullpath('frame')}:"
|
50
50
|
end
|
51
51
|
|
@@ -65,6 +65,38 @@ class TestFrame < TestDsl::TestCase
|
|
65
65
|
interface.error_queue
|
66
66
|
end
|
67
67
|
|
68
|
+
describe 'when byebug is started deep in the callstack' do
|
69
|
+
it 'must print backtrace' do
|
70
|
+
enter 'break 16', 'cont', 'where'
|
71
|
+
debug_file 'frame_deep'
|
72
|
+
check_output_includes \
|
73
|
+
/--> #0 A.d(e#String) at #{fullpath('frame_deep')}:16/x,
|
74
|
+
/#1 A.c at #{fullpath('frame_deep')}:13/x,
|
75
|
+
/#2 A.b at #{fullpath('frame_deep')}:8/x
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'must go up' do
|
79
|
+
enter 'break 16', 'cont', 'up'
|
80
|
+
debug_file('frame_deep') { state.line.must_equal 13 }
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'must go down' do
|
84
|
+
enter 'break 16', 'cont', 'up', 'down'
|
85
|
+
debug_file('frame_deep') { state.line.must_equal 16 }
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'must set frame' do
|
89
|
+
enter 'break 16', 'cont', 'frame 2'
|
90
|
+
debug_file('frame_deep') { state.line.must_equal 8 }
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'must eval properly when scaling the stack' do
|
94
|
+
enter 'break 16', 'cont', 'p z', 'up', 'p z', 'up', 'p z'
|
95
|
+
debug_file('frame_deep')
|
96
|
+
check_output_includes 'nil', '3', '2'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
68
100
|
describe 'fullpath' do
|
69
101
|
def short_path(fullpath)
|
70
102
|
separator = File::ALT_SEPARATOR || File::SEPARATOR
|
@@ -79,7 +111,8 @@ class TestFrame < TestDsl::TestCase
|
|
79
111
|
debug_file 'frame'
|
80
112
|
check_output_includes \
|
81
113
|
/--> #0 A.d(e#String) at #{fullpath('frame')}:16/x,
|
82
|
-
/#1 A.c at #{fullpath('frame')}:12/x
|
114
|
+
/#1 A.c at #{fullpath('frame')}:12/x,
|
115
|
+
/#2 A.b at #{fullpath('frame')}:8/x
|
83
116
|
end
|
84
117
|
end
|
85
118
|
|
@@ -91,7 +124,8 @@ class TestFrame < TestDsl::TestCase
|
|
91
124
|
debug_file 'frame'
|
92
125
|
check_output_includes \
|
93
126
|
/--> #0 A.d(e#String) at #{short_path(fullpath('frame'))}:16/x,
|
94
|
-
/#1 A.c at #{short_path(fullpath('frame'))}:12/x
|
127
|
+
/#1 A.c at #{short_path(fullpath('frame'))}:12/x,
|
128
|
+
/#2 A.b at #{short_path(fullpath('frame'))}:8/x
|
95
129
|
end
|
96
130
|
end
|
97
131
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: byebug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Rodríguez
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: columnize
|
@@ -46,14 +46,14 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 10.0
|
49
|
+
version: 10.1.0
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 10.0
|
56
|
+
version: 10.1.0
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rake-compiler
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- test/examples/eval.rb
|
173
173
|
- test/examples/finish.rb
|
174
174
|
- test/examples/frame.rb
|
175
|
+
- test/examples/frame_deep.rb
|
175
176
|
- test/examples/help.rb
|
176
177
|
- test/examples/info.rb
|
177
178
|
- test/examples/info2.rb
|
@@ -262,6 +263,7 @@ test_files:
|
|
262
263
|
- test/examples/eval.rb
|
263
264
|
- test/examples/finish.rb
|
264
265
|
- test/examples/frame.rb
|
266
|
+
- test/examples/frame_deep.rb
|
265
267
|
- test/examples/help.rb
|
266
268
|
- test/examples/info.rb
|
267
269
|
- test/examples/info2.rb
|