byebug 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -2
  3. data/CHANGELOG.md +15 -0
  4. data/GUIDE.md +17 -35
  5. data/Gemfile +8 -5
  6. data/LICENSE +1 -1
  7. data/README.md +10 -22
  8. data/Rakefile +1 -1
  9. data/ext/byebug/byebug.c +3 -2
  10. data/lib/byebug.rb +3 -38
  11. data/lib/byebug/commands/break.rb +83 -0
  12. data/lib/byebug/commands/catchpoint.rb +0 -1
  13. data/lib/byebug/commands/condition.rb +10 -6
  14. data/lib/byebug/commands/continue.rb +3 -6
  15. data/lib/byebug/commands/delete.rb +38 -0
  16. data/lib/byebug/commands/edit.rb +0 -2
  17. data/lib/byebug/commands/enable.rb +7 -8
  18. data/lib/byebug/commands/finish.rb +0 -2
  19. data/lib/byebug/commands/frame.rb +13 -15
  20. data/lib/byebug/commands/help.rb +1 -3
  21. data/lib/byebug/commands/history.rb +3 -3
  22. data/lib/byebug/commands/info.rb +4 -13
  23. data/lib/byebug/commands/interrupt.rb +25 -0
  24. data/lib/byebug/commands/kill.rb +0 -2
  25. data/lib/byebug/commands/list.rb +2 -4
  26. data/lib/byebug/commands/method.rb +2 -8
  27. data/lib/byebug/commands/quit.rb +0 -2
  28. data/lib/byebug/commands/reload.rb +2 -15
  29. data/lib/byebug/commands/repl.rb +0 -3
  30. data/lib/byebug/commands/{control.rb → restart.rb} +2 -26
  31. data/lib/byebug/commands/save.rb +0 -1
  32. data/lib/byebug/commands/set.rb +4 -7
  33. data/lib/byebug/commands/show.rb +0 -3
  34. data/lib/byebug/commands/source.rb +0 -3
  35. data/lib/byebug/commands/stepping.rb +3 -4
  36. data/lib/byebug/commands/trace.rb +0 -1
  37. data/lib/byebug/commands/variables.rb +3 -4
  38. data/lib/byebug/context.rb +0 -1
  39. data/lib/byebug/helper.rb +23 -0
  40. data/lib/byebug/interfaces/script_interface.rb +1 -1
  41. data/lib/byebug/processors/command_processor.rb +9 -9
  42. data/lib/byebug/remote.rb +2 -2
  43. data/lib/byebug/setting.rb +3 -1
  44. data/lib/byebug/settings/autoeval.rb +3 -1
  45. data/lib/byebug/settings/autoirb.rb +3 -1
  46. data/lib/byebug/settings/autolist.rb +3 -1
  47. data/lib/byebug/settings/autoreload.rb +1 -3
  48. data/lib/byebug/settings/autosave.rb +1 -3
  49. data/lib/byebug/settings/callstyle.rb +2 -4
  50. data/lib/byebug/settings/fullpath.rb +1 -3
  51. data/lib/byebug/settings/histfile.rb +1 -3
  52. data/lib/byebug/settings/histsize.rb +0 -4
  53. data/lib/byebug/settings/listsize.rb +1 -3
  54. data/lib/byebug/settings/post_mortem.rb +14 -1
  55. data/lib/byebug/settings/width.rb +1 -17
  56. data/lib/byebug/version.rb +1 -1
  57. data/test/break_test.rb +376 -0
  58. data/test/condition_test.rb +82 -0
  59. data/test/continue_test.rb +27 -30
  60. data/test/debugger_alias_test.rb +4 -4
  61. data/test/delete_test.rb +26 -0
  62. data/test/display_test.rb +80 -102
  63. data/test/edit_test.rb +28 -31
  64. data/test/eval_test.rb +50 -80
  65. data/test/finish_test.rb +23 -23
  66. data/test/frame_test.rb +172 -186
  67. data/test/help_test.rb +27 -37
  68. data/test/history_test.rb +32 -41
  69. data/test/info_test.rb +198 -230
  70. data/test/interrupt_test.rb +17 -36
  71. data/test/irb_test.rb +47 -0
  72. data/test/kill_test.rb +19 -19
  73. data/test/list_test.rb +126 -133
  74. data/test/method_test.rb +21 -54
  75. data/test/post_mortem_test.rb +44 -46
  76. data/test/pry_test.rb +42 -0
  77. data/test/quit_test.rb +17 -15
  78. data/test/reload_test.rb +23 -28
  79. data/test/restart_test.rb +35 -63
  80. data/test/save_test.rb +46 -62
  81. data/test/set_test.rb +93 -144
  82. data/test/show_test.rb +50 -71
  83. data/test/source_test.rb +23 -26
  84. data/test/stepping_test.rb +125 -153
  85. data/test/support/matchers.rb +1 -6
  86. data/test/support/test_interface.rb +1 -1
  87. data/test/support/{test_dsl.rb → utils.rb} +17 -64
  88. data/test/test_helper.rb +25 -7
  89. data/test/thread_test.rb +101 -89
  90. data/test/trace_test.rb +48 -85
  91. data/test/variables_test.rb +43 -80
  92. metadata +18 -13
  93. data/lib/byebug/commands/breakpoints.rb +0 -137
  94. data/lib/byebug/commands/skip.rb +0 -30
  95. data/test/breakpoints_test.rb +0 -474
  96. data/test/conditions_test.rb +0 -82
  97. data/test/repl_test.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 960dc1ecb2fe9ff5b35966884c7cee07438ea3c5
4
- data.tar.gz: 081117a82d94544eaa12479415886bb043e3835c
3
+ metadata.gz: b1a08f371a915d34451a323c3c74be79b4bf3f15
4
+ data.tar.gz: 2d30fea81a1d956f67c3e2035efbb4db570b2797
5
5
  SHA512:
6
- metadata.gz: a8f0ff414f1341bc137b5a08e1091bbc27e315cffee95f65a235e008973156d830c3fccb8441d6cc85357312d1e18405cc4fcb30c1068d30f0131df55e556d22
7
- data.tar.gz: c5034ade9a0708f284fc9ea0f4c32d27643052109acdcd9783987b4e7ff2009ee10b39d24f3382d96e0d322b63ed2ca8da49f37d7d6be1be1fb305f43fd99d06
6
+ metadata.gz: d3303c74e4cb9256df7376f0fcab58880c400cd52a9f73324c225706d89670f6406b9a5d7356e52a9dd70c84628f0720f9a671df7a4c3c60caee93e1ef8cd47b
7
+ data.tar.gz: 7c6e74528d1ab252dc5a30332476d156519bae2056c260c91a860494e05f345a7acf60a6ae1c85476966d253013efcbb57dbdf84f0ef3530d4c677d8112866df
@@ -1,9 +1,11 @@
1
1
  before_script: bundle exec rake compile
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
4
+ - 2.1
6
5
  - ruby-head
7
6
  matrix:
8
7
  allow_failures:
9
8
  - rvm: ruby-head
9
+ addons:
10
+ code_climate:
11
+ repo_token: 02530029b1e956220f05076c590b84b9ab078362c9083312eb2ad41cab138408
@@ -1,3 +1,18 @@
1
+ # 3.2.0
2
+
3
+ - Bugfixes
4
+ * Fix bug in remote debugging (#71), thanks @shuky19.
5
+ * Fix source command (#68), thanks @Olgagr.
6
+ * Fix bug #71 preventing the test suite from running against ruby-head.
7
+ * Remove warning reported in #77.
8
+
9
+ - Removals
10
+ * `post_mortem` activation through `Byebug.post_mortem` is no longer allowed.
11
+ Use `set post_mortem` instead.
12
+ * `info stack` command has been removed. Use `where`|`backtrace` instead.
13
+ * `method iv` command has been removed. Use `var instance` instead.
14
+
15
+
1
16
  # 3.1.2
2
17
 
3
18
  * Really fix starting `post_mortem` mode in bin/byebug
data/GUIDE.md CHANGED
@@ -31,7 +31,7 @@ has terminated normally, the string this position will be `(byebug:ctrl)`. The
31
31
  commands available change depending on the program's state.
32
32
 
33
33
  Byebug automatically lists 10 lines of code centered around the current line
34
- everytime it is stopped. The current line is marked with `=>`, so the range
34
+ every time it is stopped. The current line is marked with `=>`, so the range
35
35
  byebug would like to show is [-3..6]. However since there aren't 5 lines before
36
36
  the current line, the range is moved _up_ so we can actually display 10 lines
37
37
  of code.
@@ -173,7 +173,7 @@ $ byebug hanoi.rb
173
173
  (byebug)
174
174
  ```
175
175
 
176
- Recall in the first section iwe said that before the `def` is run, the method it
176
+ Recall in the first section it was stated that before the `def` is run, the method it
177
177
  names is undefined. Let's check that out. First let's see what private methods
178
178
  we can call before running `def hanoi`.
179
179
 
@@ -186,7 +186,7 @@ we can call before running `def hanoi`.
186
186
  byebug doesn't understand a command, it will evaluate it as if it was a Ruby
187
187
  command. If you don't want this behaviour, you can use `set autoeval off` or
188
188
  even drop it in your `.byebugrc` file if you want that behaviour permanently.
189
- The output of `private_methods`, thought, is unwieldy for our porpuse: check
189
+ The output of `private_methods`, thought, is unwieldy for our purpose: check
190
190
  whether `hanoi` method is in the list. Fortunately, byebug has nice formatting
191
191
  features: we can sort the output and put it into columns list using the print
192
192
  command `ps`.
@@ -440,7 +440,7 @@ same directory as `triangle.rb`.
440
440
  require 'minitest/autorun'
441
441
  require_relative 'triangle.rb'
442
442
 
443
- class TestTri < MiniTest::Unit::TestCase
443
+ class TestTri < Minitest::Unit::TestCase
444
444
  def test_basic
445
445
  solutions = []
446
446
  0.upto(5) do |i|
@@ -474,7 +474,7 @@ Run options: --seed 13073
474
474
  [2, 11] in test-triangle.rb
475
475
  2: require_relative 'triangle.rb'
476
476
  3:
477
- 4: class TestTri < MiniTest::Unit::TestCase
477
+ 4: class TestTri < Minitest::Unit::TestCase
478
478
  5: def test_basic
479
479
  6: byebug
480
480
  => 7: solutions = []
@@ -495,20 +495,20 @@ Now let's see where we are...
495
495
  Displaying frame's full file names is off.
496
496
  (byebug) bt
497
497
  --> #0 TestTri.test_basic at test-triangle.rb:7
498
- #1 MiniTest::Unit::TestCase.run(runner#MiniTest::Unit) at .../2.0.0/minitest/unit.rb:1301
499
- #2 MiniTest::Unit.block in _run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:919
498
+ #1 Minitest::Unit::TestCase.run(runner#Minitest::Unit) at .../2.0.0/minitest/unit.rb:1301
499
+ #2 Minitest::Unit.block in _run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:919
500
500
  +-- #3 Array.map at .../2.0.0/minitest/unit.rb:912
501
- #4 MiniTest::Unit._run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:912
502
- #5 MiniTest::Unit.block in _run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
501
+ #4 Minitest::Unit._run_suite(suite#Class, type#Symbol) at .../2.0.0/minitest/unit.rb:912
502
+ #5 Minitest::Unit.block in _run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
503
503
  +-- #6 Array.map at .../2.0.0/minitest/unit.rb:899
504
- #7 MiniTest::Unit._run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
505
- #8 MiniTest::Unit._run_anything(type#Symbol) at .../2.0.0/minitest/unit.rb:867
506
- #9 MiniTest::Unit.run_tests at .../2.0.0/minitest/unit.rb:1060
507
- #10 MiniTest::Unit.block in _run(args#Array) at .../2.0.0/minitest/unit.rb:1047
504
+ #7 Minitest::Unit._run_suites(suites#Array, type#Symbol) at .../2.0.0/minitest/unit.rb:899
505
+ #8 Minitest::Unit._run_anything(type#Symbol) at .../2.0.0/minitest/unit.rb:867
506
+ #9 Minitest::Unit.run_tests at .../2.0.0/minitest/unit.rb:1060
507
+ #10 Minitest::Unit.block in _run(args#Array) at .../2.0.0/minitest/unit.rb:1047
508
508
  +-- #11 Array.each at .../2.0.0/minitest/unit.rb:1046
509
- #12 MiniTest::Unit._run(args#Array) at .../2.0.0/minitest/unit.rb:1046
510
- #13 MiniTest::Unit.run(args#Array) at .../2.0.0/minitest/unit.rb:1035
511
- #14 #<Class:MiniTest::Unit>.block in autorun at .../2.0.0/minitest/unit.rb:789
509
+ #12 Minitest::Unit._run(args#Array) at .../2.0.0/minitest/unit.rb:1046
510
+ #13 Minitest::Unit.run(args#Array) at .../2.0.0/minitest/unit.rb:1035
511
+ #14 #<Class:Minitest::Unit>.block in autorun at .../2.0.0/minitest/unit.rb:789
512
512
  (byebug)
513
513
  ```
514
514
 
@@ -863,7 +863,7 @@ Running a program from byebug adds a bit of overhead and slows it down a little.
863
863
  Furthermore, by necessity, debuggers change the operation of the program they
864
864
  are debugging. And this can lead to unexpected and unwanted differences. It has
865
865
  happened so often that the term
866
- [Heisenbugs](http://en.wikipedia.org/wiki/Heisenbug}) was coined to describe the
866
+ [Heisenbugs](http://en.wikipedia.org/wiki/Heisenbug) was coined to describe the
867
867
  situation where using a debugger (among other possibilities) changes the
868
868
  behavior of the program so that the bug doesn't manifest itself anymore.
869
869
 
@@ -1032,7 +1032,6 @@ info line -- Line number and file name of current position in
1032
1032
  source file
1033
1033
  info locals -- Local variables of the current stack frame
1034
1034
  info program -- Execution status of the program
1035
- info stack -- Backtrace of the stack
1036
1035
  info variables -- Local and instance variables of the current stack
1037
1036
  frame
1038
1037
  ```
@@ -1284,23 +1283,6 @@ basically listing `<object>.instance_variables`.
1284
1283
  * `info variables`. Show local and instance variables of `self`.
1285
1284
  * `method instance <object>`. Show methods of `<object>`. Basically this is the
1286
1285
  same as running `ps <object>.instance_methods(false)`.
1287
- * `method iv <object>`. Show method instance variables of `object`. Basically
1288
- this is the same as running
1289
- ```
1290
- <object>.instance_variables.each do |v|
1291
- puts "%s = %s\n" % [v, <object>.instance_variable_get(v)]
1292
- end
1293
- ```
1294
- * `signature <object>`. Show signature of method `<object>`. _This command is
1295
- available only if the nodewrap gem is installed_.
1296
-
1297
- ```ruby
1298
- def mymethod(a, b=5, &bock)
1299
- end
1300
- (byebug) method sig mymethod
1301
- Mine#mymethod(a, b=5, &bock)
1302
- ```
1303
-
1304
1286
  * `method <class-or-module>`. Show methods of the class or module
1305
1287
  `<class-or-module>`. Basically this is the same as running
1306
1288
  `ps <class-or-module>.methods`.
data/Gemfile CHANGED
@@ -2,11 +2,14 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake', '~> 10.2'
5
+ gem 'rake', '~> 10.3'
6
6
 
7
- group :development, :test do
7
+ group :development do
8
8
  gem 'rake-compiler', '~> 0.9'
9
- gem 'mocha', '~> 1.0'
10
- gem 'minitest', '~> 5.3'
11
- gem 'coveralls', '~> 0.7'
9
+ gem 'mocha', '~> 1.1'
10
+ gem 'minitest', '~> 5.4'
11
+ end
12
+
13
+ group :test do
14
+ gem 'codeclimate-test-reporter', '~> 0.4', require: nil
12
15
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2014 David Rodríguez <deivid.rodriguez@gmail.com>
1
+ Copyright (C) David Rodríguez <deivid.rodriguez@gmail.com>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build][TravisBadge]][TravisURL]
4
4
  [![Climate][CodeClimateBadge]][CodeClimateURL]
5
5
  [![Dependencies][GemnasiumBadge]][GemnasiumURL]
6
- [![Coverage][CoverallsBadge]][CoverallsURL]
6
+ [![Coverage][CoverageBadge]][CoverageURL]
7
7
  [![Gittip][GittipBadge]][GittipURL]
8
8
 
9
9
  _Debugging in Ruby 2_
@@ -12,6 +12,8 @@ Byebug is a simple to use, feature rich debugger for Ruby 2. It uses the new
12
12
  TracePoint API for execution control and the new Debug Inspector API for call
13
13
  stack navigation, so it doesn't depend on internal core sources. It's developed
14
14
  as a C extension, so it's fast. And it has a full test suite so it's reliable.
15
+ Note that byebug works only for ruby 2.0.0 or newer. For debugging ruby 1.9.3 or
16
+ older, use [debugger](https://github.com/cldwalker/debugger).
15
17
 
16
18
  It allows you to see what is going on _inside_ a Ruby program while it executes
17
19
  and can do four main kinds of things to help you catch bugs in the act:
@@ -43,27 +45,13 @@ Former [debugger](https://github.com/cldwalker/debugger) or
43
45
  [ruby-debug](https://github.com/mark-moseley/ruby-debug) users, notice:
44
46
 
45
47
  * Some gems (rails, rspec) implement debugging flags (-d, --debugger) that early
46
- require and start the debugger. These flags are a performance penalty and Byebug
47
- doesn't need them anymore so my recommendation is not to use them.
48
+ require and start the debugger. These flags are a performance penalty and byebug
49
+ doesn't need them anymore so my recommendation is not to use them. In any case,
50
+ both rails and rspec have deprecated these flags in their latest versions.
48
51
  * The startup configuration file is now called `.byebugrc` instead of
49
52
  `.rdebugrc`.
50
53
 
51
54
 
52
- ## What's different from debugger
53
-
54
- * Works on Ruby 2.x but it doesn't on 1.9.x (you should probably upgrade
55
- anyways).
56
- * Has no MRI internal source code dependencies, just a clean API (no more `bump
57
- ruby_core_source dependency` entries in CHANGELOG, no more broken debugger's on
58
- ruby's releases).
59
- * Fixes a lot of debugger's issues, such as ruby 2.x support or post_mortem
60
- debugging. It also provides several enhancements, such as the fact the `byebug`
61
- can now be placed at the end of a block or method call.
62
- * Actively mantained.
63
- * Editor agnostic: no external editor built-in support.
64
- * Pry command is built-in. No need of external gem like debugger-pry.
65
-
66
-
67
55
  ## Byebug's commands
68
56
 
69
57
  Command | Aliases | Subcommands
@@ -83,11 +71,11 @@ can now be placed at the end of a block or method call.
83
71
  `frame` | |
84
72
  `help` | |
85
73
  `history` | |
86
- `info` | | `args` `breakpoints` `catch` `display` `file` `files` `global_variables` `instance_variables` `line` `locals` `program` `stack` `variables`
74
+ `info` | | `args` `breakpoints` `catch` `display` `file` `files` `global_variables` `instance_variables` `line` `locals` `program` `variables`
87
75
  `irb` | |
88
76
  `kill` | |
89
77
  `list` | |
90
- `method` | | `instance` `iv`
78
+ `method` | | `instance`
91
79
  `next` | |
92
80
  `p` | `eval` |
93
81
  `pp` | |
@@ -165,7 +153,7 @@ starting point of this.
165
153
  [CodeClimateURL]: https://codeclimate.com/github/deivid-rodriguez/byebug
166
154
  [GemnasiumBadge]: https://gemnasium.com/deivid-rodriguez/byebug.svg
167
155
  [GemnasiumURL]: https://gemnasium.com/deivid-rodriguez/byebug
168
- [CoverallsBadge]: http://img.shields.io/coveralls/deivid-rodriguez/byebug.svg
169
- [CoverallsURL]: https://coveralls.io/r/deivid-rodriguez/byebug
156
+ [CoverageBadge]: https://codeclimate.com/github/deivid-rodriguez/byebug/badges/coverage.svg
157
+ [CoverageURL]: https://codeclimate.com/github/deivid-rodriguez/byebug
170
158
  [GittipBadge]: http://img.shields.io/gittip/deivid-rodriguez.svg
171
159
  [GittipURL]: https://www.gittip.com/deivid-rodriguez
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ class Rake::TestTask
13
13
  end
14
14
  end
15
15
 
16
- desc "Run MiniTest suite"
16
+ desc 'Run the test suite'
17
17
  task :test do
18
18
  Rake::TestTask.new do |t|
19
19
  t.verbose = true
@@ -236,7 +236,7 @@ line_event(VALUE trace_point, void *data)
236
236
  static void
237
237
  call_event(VALUE trace_point, void *data)
238
238
  {
239
- VALUE breakpoint, klass, mid, binding, self, file, line;
239
+ VALUE breakpoint, klass, msym, mid, binding, self, file, line;
240
240
 
241
241
  EVENT_SETUP
242
242
 
@@ -249,7 +249,8 @@ call_event(VALUE trace_point, void *data)
249
249
 
250
250
  breakpoint = Qnil;
251
251
  klass = rb_tracearg_defined_class(trace_arg);
252
- mid = SYM2ID(rb_tracearg_method_id(trace_arg));
252
+ msym = rb_tracearg_method_id(trace_arg);
253
+ mid = NIL_P(msym) ? Qnil : SYM2ID(msym);
253
254
  binding = rb_tracearg_binding(trace_arg);
254
255
  self = rb_tracearg_self(trace_arg);
255
256
  file = rb_tracearg_path(trace_arg);
@@ -27,23 +27,9 @@ module Byebug
27
27
  Byebug.handler = CommandProcessor.new
28
28
 
29
29
  def source_reload
30
- Object.send(:remove_const, 'SCRIPT_LINES__') if
31
- Object.const_defined?('SCRIPT_LINES__')
32
- Object.const_set('SCRIPT_LINES__', {})
33
- end
34
-
35
- #
36
- # Get line +line_number+ from file named +filename+.
37
- #
38
- # @return "\n" if there was a problem. Leaking blanks are stripped off.
39
- #
40
- def line_at(filename, line_number)
41
- source_reload
42
-
43
- return "\n" unless File.exist?(filename)
44
- line = Tracer::Single.get_line(filename, line_number)
45
-
46
- return "#{line.gsub(/^\s+/, '').chomp}"
30
+ hsh = 'SCRIPT_LINES__'
31
+ Object.send(:remove_const, hsh) if Object.const_defined?(hsh)
32
+ Object.const_set(hsh, {})
47
33
  end
48
34
 
49
35
  #
@@ -102,27 +88,6 @@ module Byebug
102
88
  processor = ControlCommandProcessor.new(interface)
103
89
  processor.process_commands(verbose)
104
90
  end
105
-
106
- #
107
- # Activates the post-mortem mode.
108
- #
109
- # By calling Byebug.post_mortem method, you install an at_exit hook that
110
- # intercepts any exception not handled by your script and enables
111
- # post-mortem mode.
112
- #
113
- def post_mortem
114
- return if self.post_mortem?
115
- self.post_mortem = true
116
- at_exit { handle_post_mortem if post_mortem? }
117
- end
118
-
119
- def handle_post_mortem
120
- context = raised_exception.__bb_context
121
- file = raised_exception.__bb_file
122
- line = raised_exception.__bb_line
123
- handler.at_line(context, file, line)
124
- end
125
- private :handle_post_mortem
126
91
  end
127
92
  end
128
93
 
@@ -0,0 +1,83 @@
1
+ module Byebug
2
+ class BreakCommand < Command
3
+ self.allow_in_post_mortem = false
4
+ self.allow_in_control = true
5
+
6
+ def regexp
7
+ /^\s* b(?:reak)? (?:\s+ #{Position_regexp})? (?:\s+(.+))? \s*$/x
8
+ end
9
+
10
+ def execute
11
+ return print BreakCommand.help(nil) if BreakCommand.names.include?(@match[0])
12
+
13
+ if @match[1]
14
+ line, _, _, expr = @match.captures
15
+ else
16
+ _, file, line, expr = @match.captures
17
+ end
18
+
19
+ if expr && file.nil? && line.nil?
20
+ return errmsg "Invalid breakpoint location: #{expr}\n"
21
+ elsif expr && expr !~ /^\s*if\s+(.+)/
22
+ return errmsg "Expecting \"if\" in breakpoint condition, got: #{expr}\n"
23
+ else
24
+ expr = $1
25
+ end
26
+
27
+ if file.nil? && !@state.context
28
+ return errmsg "We are not in a state that has an associated file\n"
29
+ end
30
+
31
+ file = @state.file if file.nil?
32
+ line = @state.line.to_s if line.nil?
33
+
34
+ if line =~ /^\d+$/
35
+ path = CommandProcessor.canonic_file(file)
36
+ return errmsg "No file named #{path}\n" unless File.exist?(file)
37
+
38
+ line, n = line.to_i, File.foreach(file).count
39
+ return errmsg "There are only #{n} lines in file #{path}\n" if line > n
40
+
41
+ autoreload = Setting[:autoreload]
42
+ possible_lines = LineCache.trace_line_numbers(file, autoreload)
43
+ if !possible_lines.member?(line)
44
+ return errmsg \
45
+ "Line #{line} is not a valid breakpoint in file #{path}\n"
46
+ end
47
+
48
+ b = Byebug.add_breakpoint file, line, expr
49
+ print "Created breakpoint #{b.id} at #{path}:#{line}\n"
50
+
51
+ if !syntax_valid?(expr)
52
+ errmsg "Incorrect expression \"#{expr}\"; breakpoint disabled.\n"
53
+ b.enabled = false
54
+ end
55
+
56
+ else
57
+ klass = bb_warning_eval(file)
58
+ if klass && klass.kind_of?(Module)
59
+ class_name = klass.name
60
+ else
61
+ return errmsg "Unknown class #{file}\n"
62
+ end
63
+
64
+ method = line.intern
65
+ b = Byebug.add_breakpoint class_name, method, expr
66
+ print "Created breakpoint #{b.id} at #{class_name}::#{method}\n"
67
+ end
68
+ end
69
+
70
+ class << self
71
+ def names
72
+ %w(break)
73
+ end
74
+
75
+ def description
76
+ %{b[reak] file:line [if expr]
77
+ b[reak] class(.|#)method [if expr]
78
+
79
+ Set breakpoint to some position, (optionally) if expr == true}
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,5 +1,4 @@
1
1
  module Byebug
2
-
3
2
  class CatchCommand < Command
4
3
  self.allow_in_control = true
5
4
 
@@ -1,5 +1,4 @@
1
1
  module Byebug
2
-
3
2
  class ConditionCommand < Command
4
3
  self.allow_in_post_mortem = false
5
4
 
@@ -10,16 +9,22 @@ module Byebug
10
9
  def execute
11
10
  return print ConditionCommand.help(nil) unless @match[1]
12
11
 
13
- breakpoints = Byebug.breakpoints.sort_by{|b| b.id }
12
+ breakpoints = Byebug.breakpoints.sort_by { |b| b.id }
14
13
  largest = breakpoints.inject(0) do |tally, b|
15
14
  tally = b.id if b.id > tally
16
15
  end
17
16
 
18
- return print "No breakpoints have been set.\n" if 0 == largest
17
+ return errmsg "No breakpoints have been set\n" if 0 == largest
19
18
  return unless pos = get_int(@match[1], "Condition", 1, largest)
20
19
 
21
- breakpoint = breakpoints.select{ |b| b.id == pos }.first
22
- breakpoint.expr = @match[2] if breakpoint
20
+ breakpoint = breakpoints.select { |b| b.id == pos }.first
21
+
22
+ if syntax_valid?(@match[2])
23
+ breakpoint.expr = @match[2]
24
+ else
25
+ return errmsg "Incorrect expression \"#{@match[2]}\", " \
26
+ "breakpoint not changed\n"
27
+ end
23
28
  end
24
29
 
25
30
  class << self
@@ -37,5 +42,4 @@ module Byebug
37
42
  end
38
43
  end
39
44
  end
40
-
41
45
  end