byebug 4.0.5 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -34
  3. data/CONTRIBUTING.md +26 -31
  4. data/README.md +3 -3
  5. data/lib/byebug/breakpoint.rb +2 -1
  6. data/lib/byebug/command.rb +27 -49
  7. data/lib/byebug/commands/break.rb +21 -15
  8. data/lib/byebug/commands/catch.rb +9 -15
  9. data/lib/byebug/commands/condition.rb +12 -15
  10. data/lib/byebug/commands/continue.rb +8 -11
  11. data/lib/byebug/commands/delete.rb +9 -12
  12. data/lib/byebug/commands/disable.rb +32 -0
  13. data/lib/byebug/commands/disable/breakpoints.rb +38 -0
  14. data/lib/byebug/commands/disable/display.rb +39 -0
  15. data/lib/byebug/commands/display.rb +18 -51
  16. data/lib/byebug/commands/down.rb +39 -0
  17. data/lib/byebug/commands/edit.rb +8 -14
  18. data/lib/byebug/commands/enable.rb +25 -0
  19. data/lib/byebug/commands/enable/breakpoints.rb +38 -0
  20. data/lib/byebug/commands/enable/display.rb +39 -0
  21. data/lib/byebug/commands/eval.rb +10 -192
  22. data/lib/byebug/commands/finish.rb +11 -12
  23. data/lib/byebug/commands/frame.rb +17 -182
  24. data/lib/byebug/commands/help.rb +18 -18
  25. data/lib/byebug/commands/history.rb +9 -10
  26. data/lib/byebug/commands/info.rb +17 -190
  27. data/lib/byebug/commands/info/args.rb +39 -0
  28. data/lib/byebug/commands/info/breakpoints.rb +59 -0
  29. data/lib/byebug/commands/info/catch.rb +39 -0
  30. data/lib/byebug/commands/info/display.rb +42 -0
  31. data/lib/byebug/commands/info/file.rb +81 -0
  32. data/lib/byebug/commands/info/line.rb +31 -0
  33. data/lib/byebug/commands/info/program.rb +51 -0
  34. data/lib/byebug/commands/interrupt.rb +5 -9
  35. data/lib/byebug/commands/irb.rb +5 -9
  36. data/lib/byebug/commands/kill.rb +6 -12
  37. data/lib/byebug/commands/list.rb +47 -19
  38. data/lib/byebug/commands/method.rb +8 -14
  39. data/lib/byebug/commands/next.rb +36 -0
  40. data/lib/byebug/commands/pp.rb +41 -0
  41. data/lib/byebug/commands/pry.rb +5 -9
  42. data/lib/byebug/commands/ps.rb +44 -0
  43. data/lib/byebug/commands/putl.rb +43 -0
  44. data/lib/byebug/commands/quit.rb +8 -12
  45. data/lib/byebug/commands/restart.rb +6 -12
  46. data/lib/byebug/commands/save.rb +30 -39
  47. data/lib/byebug/commands/set.rb +19 -21
  48. data/lib/byebug/commands/show.rb +10 -16
  49. data/lib/byebug/commands/source.rb +6 -12
  50. data/lib/byebug/commands/step.rb +36 -0
  51. data/lib/byebug/commands/thread.rb +13 -130
  52. data/lib/byebug/commands/thread/current.rb +35 -0
  53. data/lib/byebug/commands/thread/list.rb +41 -0
  54. data/lib/byebug/commands/thread/resume.rb +45 -0
  55. data/lib/byebug/commands/thread/stop.rb +41 -0
  56. data/lib/byebug/commands/thread/switch.rb +43 -0
  57. data/lib/byebug/commands/tracevar.rb +8 -14
  58. data/lib/byebug/commands/undisplay.rb +12 -15
  59. data/lib/byebug/commands/untracevar.rb +5 -11
  60. data/lib/byebug/commands/up.rb +39 -0
  61. data/lib/byebug/commands/var.rb +15 -94
  62. data/lib/byebug/commands/var/all.rb +37 -0
  63. data/lib/byebug/commands/var/const.rb +38 -0
  64. data/lib/byebug/commands/var/global.rb +33 -0
  65. data/lib/byebug/commands/var/instance.rb +35 -0
  66. data/lib/byebug/commands/var/local.rb +35 -0
  67. data/lib/byebug/commands/where.rb +47 -0
  68. data/lib/byebug/core.rb +10 -0
  69. data/lib/byebug/helpers/eval.rb +47 -0
  70. data/lib/byebug/helpers/file.rb +46 -0
  71. data/lib/byebug/helpers/frame.rb +76 -0
  72. data/lib/byebug/helpers/parse.rb +74 -0
  73. data/lib/byebug/helpers/string.rb +24 -0
  74. data/lib/byebug/helpers/thread.rb +53 -0
  75. data/lib/byebug/helpers/toggle.rb +56 -0
  76. data/lib/byebug/helpers/var.rb +45 -0
  77. data/lib/byebug/history.rb +2 -4
  78. data/lib/byebug/interface.rb +5 -3
  79. data/lib/byebug/interfaces/local_interface.rb +3 -1
  80. data/lib/byebug/interfaces/remote_interface.rb +3 -1
  81. data/lib/byebug/interfaces/test_interface.rb +6 -2
  82. data/lib/byebug/printers/plain.rb +1 -1
  83. data/lib/byebug/processors/command_processor.rb +9 -11
  84. data/lib/byebug/processors/control_command_processor.rb +1 -1
  85. data/lib/byebug/remote.rb +3 -0
  86. data/lib/byebug/runner.rb +5 -3
  87. data/lib/byebug/setting.rb +2 -18
  88. data/lib/byebug/settings/savefile.rb +21 -0
  89. data/lib/byebug/states/regular_state.rb +15 -6
  90. data/lib/byebug/subcommand_list.rb +33 -0
  91. data/lib/byebug/subcommands.rb +53 -0
  92. data/lib/byebug/version.rb +1 -1
  93. metadata +45 -6
  94. data/lib/byebug/commands/enable_disable.rb +0 -132
  95. data/lib/byebug/commands/stepping.rb +0 -75
  96. data/lib/byebug/helper.rb +0 -131
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86c24793f077ce32dceea91c8bde07dce922a274
4
- data.tar.gz: f166af0f5a9b01024978ebf2ebb5d9b7103d8a7b
3
+ metadata.gz: 96c7056e0b0872cdba9ffbc43941b6c804ee5db8
4
+ data.tar.gz: c06eaaf13304aca7e289301fa61a7c0735f16647
5
5
  SHA512:
6
- metadata.gz: 19d9a87a1f69496bdb00574437c3913b167d2da92d1b1b35c64412a70adfc8309f2bc78bdac5233bea310bd46543af2966b762453318e450ff6d73092626b16d
7
- data.tar.gz: cfe46396685e6cec68816f38b70183317cf7585e1bbec594de6e670962151a5cd1eb4e1eb2483c0aafe43e94d741589c595c8d8e5a4cecb5124200b617c04b05
6
+ metadata.gz: 1fbf5703563d4b88ec8b5b843704a51b78d4f47f5f9e6735942fc1a75c881f440ff4569220e0c6c4f101bda57e1ec16f3089cf26fa3b068c32b97246ee60fd7e
7
+ data.tar.gz: 0ddec536c7c8ae53485105eaf226946d1fcc3510cd1b0a3220f446d18fbbe2433068de2e922ce44192dc5c559ad5fb74d9a76264327f273be3f127b6f32201f0
@@ -1,12 +1,34 @@
1
+ ## 5.0.0
2
+ ### Fixed
3
+ * [#136](https://github.com/deivid-rodriguez/byebug/issues/136). `frame`
4
+ command not working with negative numbers (thanks @ark6).
5
+
6
+ ### Added
7
+ * IDE support and a new command/subcommand API for plugins.
8
+ * Add a "savefile" setting holding the file where "save" command saves current
9
+ debugger's state.
10
+
11
+ ### Changed
12
+ * `disable` no longer disable all breakpoints, it just shows command's help
13
+ instead. To disable all breakpoints now you need to do `disable breakpoints`
14
+ (or `dis b`). Similarly, you can't no longer use `dis 1 2 3` but need to do
15
+ `dis b 1 2 3` to disable specific breakpoints. The same applies to the `enable`
16
+ command.
17
+
18
+ ### Removed
19
+ * `help set <setting>` no longer works. `help set` includes that same output and
20
+ it's not verbose enough so that this is a problem. Same with `help show
21
+ <setting>`.
22
+
1
23
  ## 4.0.5 - 2015-04-02
2
24
  ### Fixed
3
- * #131
25
+ * [#131](https://github.com/deivid-rodriguez/byebug/issues/131)
4
26
  * Thread commands help format should be consistent with the rest of the help
5
27
  system now.
6
28
 
7
29
  ## 4.0.4 - 2015-03-27
8
30
  ### Fixed
9
- * #127
31
+ * [#127](https://github.com/deivid-rodriguez/byebug/issues/127)
10
32
 
11
33
  ## 4.0.3 - 2015-03-19
12
34
  ### Fixed
@@ -14,13 +36,15 @@ system now.
14
36
 
15
37
  ## 4.0.2 - 2015-03-16
16
38
  ### Fixed
17
- * Removed `rb-readline` as a dependency and show a help message whenever
18
- requiring readline fails instead (#118)
39
+ * [#118](https://github.com/deivid-rodriguez/byebug/issues/118). Remove
40
+ `rb-readline` as a dependency and show a help message whenever requiring
41
+ `readline` fails instead.
19
42
 
20
43
  ## 4.0.1 - 2015-03-13
21
44
  ### Fixed
22
45
  * .yml files needed for printers support were missing from the release... :S
23
- * Add `rb-readline` as a dependency (#118)
46
+ * [#118](https://github.com/deivid-rodriguez/byebug/issues/118). Add `readline`
47
+ as a dependency.
24
48
 
25
49
  ## 4.0.0 - 2015-03-13
26
50
  ### Added
@@ -35,9 +59,10 @@ requiring readline fails instead (#118)
35
59
  ### Changed
36
60
  - A lot of internal refactoring.
37
61
  - `tracevar` now requires the full global variable name (with "$").
38
- - `catch` command is not allowed in post_mortem mode anymore. It was not
39
- working anyways (#92).
40
- - `step` is now more user friendly when used in combination with `up` (see #85).
62
+ - [#92](https://github.com/deivid-rodriguez/byebug/issues/92). The `catch`
63
+ command is not allowed in post_mortem mode anymore. It was not working anyways.
64
+ - [#85](https://github.com/deivid-rodriguez/byebug/issues/85). `step` is now
65
+ more user friendly when used in combination with `up`.
41
66
  - `var const` can now be called without an argument and will show constants in
42
67
  the current scope.
43
68
  - `break` with a class name now creates breakpoints regardless of class not
@@ -48,17 +73,21 @@ created anyways.
48
73
  - Code reloading issues.
49
74
  - `set fullpath` was not showing fullpaths. Now it is.
50
75
  - `up`, `down` and `frame` commands now work in post_mortem mode (#93).
51
- - Fixes in rc file (.byebugrc): invalid commands are just ignored instead of
76
+ - rc file (`.byebugrc`) loading: invalid commands are just ignored instead of
52
77
  aborting, global (home) rc file is now properly loaded before project's file.
53
- - Backtraces not working in `post_mortem` mode (#93).
78
+ - [#93](https://github.com/deivid-rodriguez/byebug/issues/93). Backtraces not
79
+ working in `post_mortem` mode.
54
80
  - 'cmd1 ; cmd2 ; ...; cmdN' syntax which allows running several commands
55
81
  sequentially.
56
- - Finish command not stopping at the correct line (#101).
57
- - `break` with namespaced class, like `break A::B#c` should now work (#106).
82
+ - [#101](https://github.com/deivid-rodriguez/byebug/issues/101). `finish`
83
+ command not stopping at the correct line.
84
+ - [#106](https://github.com/deivid-rodriguez/byebug/issues/106). `break` with
85
+ namespaced class, like `break A::B#c` should now work.
58
86
  - Command history is now persisted before exiting byebug.
59
87
  - Setting breakpoint in a method would stop not only at the beginning of the
60
88
  method but also at the beginning of every block inside the method.
61
- - Setting breakpoints on module methods (#122, @x-yuri).
89
+ - [#122](https://github.com/deivid-rodriguez/byebug/issues/122). Setting
90
+ breakpoints on module methods (@x-yuri).
62
91
 
63
92
  ### Removed
64
93
  - `autoreload` setting as it's not necessary anymore. Code should always be up
@@ -82,12 +111,14 @@ autoevaluate it.
82
111
 
83
112
  ## 3.5.1 - 2014-09-29
84
113
  ### Fixed
85
- - Windows installation (#79).
114
+ - [#79](https://github.com/deivid-rodriguez/byebug/issues/79). Windows
115
+ installation.
86
116
  - `condition` command not properly detecting invalid breakpoint ids.
87
117
 
88
118
  ## 3.5.0 - 2014-09-28
89
119
  ### Fixed
90
- - Byebug's history messing other programs using Readline (#81).
120
+ - [#81](https://github.com/deivid-rodriguez/byebug/issues/81). Byebug's history
121
+ messing up other programs using Readline.
91
122
  - Readline's history not being properly saved and inmediately available.
92
123
  - User not being notified when trying to debug a non existent script.
93
124
 
@@ -98,14 +129,14 @@ autoevaluate it.
98
129
 
99
130
  ## 3.4.2 - 2014-09-26
100
131
  ### Fixed
101
- - Debugging commands invoked by ruby exectuable (#67), as in `byebug --
102
- ruby -Itest test/controllers/posts_controller_test.rb -n
103
- test_should_get_index`.
104
-
132
+ - [#67](https://github.com/deivid-rodriguez/byebug/issues/67). Debugging
133
+ commands invoked by ruby executable, as in `byebug -- ruby -Itest a_test.rb
134
+ -n test_something`.
105
135
 
106
136
  ## 3.4.1 - 2014-09-25
107
137
  ### Fixed
108
- - Use of threads inside `eval` command (#54).
138
+ - [#54](https://github.com/deivid-rodriguez/byebug/issues/54). Use of threads
139
+ inside `eval` command.
109
140
  - `list` command not listing backwards after reaching the end of the file.
110
141
 
111
142
  ## 3.4.0 - 2014-09-01
@@ -138,16 +169,17 @@ default behaviour though.
138
169
 
139
170
  ## 3.2.0 - 2014-08-02
140
171
  ### Fixed
141
- - Remote debugging (#71), thanks @shuky19.
142
- - `source` command (#68), thanks @Olgagr.
143
- - `ruby-head` support (#71).
172
+ - [#71](https://github.com/deivid-rodriguez/byebug/issues/71). Remote debugging
173
+ (thanks @shuky19).
174
+ - [#69](https://github.com/deivid-rodriguez/byebug/issues/69). `source` command
175
+ (thanks @Olgagr).
144
176
 
145
177
  ### Removed
146
178
  - `post_mortem` activation through `Byebug.post_mortem`. Use `set post_mortem`
147
179
  instead.
148
180
  - `info stack` command. Use `where` instead.
149
181
  - `method iv` command. Use `var instance` instead.
150
- - Warning reported in #77.
182
+ - [#77](https://github.com/deivid-rodriguez/byebug/issues/77). Warning.
151
183
 
152
184
  ## 3.1.2 - 2014-04-23
153
185
  ### Fixed
@@ -179,8 +211,8 @@ global variable tracing.
179
211
  - Plain `byebug` not working when `pry-byebug` installed.
180
212
  - `post_mortem` mode.
181
213
  - Command history not being saved after regular program termination.
182
- - (Again) Calling `Byebug.start` with `Timeout.timeout` (#54), thanks
183
- @zmoazeni!
214
+ - [#54](https://github.com/deivid-rodriguez/byebug/issues/54). (Again) calling
215
+ `Byebug.start` with `Timeout.timeout` (thanks @zmoazeni).
184
216
 
185
217
  ### Added
186
218
  - Allow disabling `post_mortem` mode.
@@ -191,7 +223,7 @@ like shell's `history` command.
191
223
  - `show/set history filename` is now `show/set histfile`
192
224
  - `show/set history size` is now `show/set histsize`
193
225
  - `show/set history save` is now `show/set autosave`
194
- - `finish` semantic, see
226
+ - `finish` semantics, see
195
227
  [61f9b4d](https://github.com/deivid-rodriguez/byebug/commit/61f9b4d).
196
228
  - Use `per project` history file by default.
197
229
 
@@ -200,8 +232,12 @@ like shell's `history` command.
200
232
  command work is always saved now.
201
233
 
202
234
  ## 2.7.0 - 2014-02-24
203
- - `IGNORED_FILES` slowing down startup (#52).
204
- - Calling `Byebug.start` with `Timeout.timeout` (#53, #54).
235
+ ### Fixed
236
+ - [#52](https://github.com/deivid-rodriguez/byebug/issues/52). `IGNORED_FILES`
237
+ slowing down startup.
238
+ - [#53](https://github.com/deivid-rodriguez/byebug/issues/53) and
239
+ [#54](https://github.com/deivid-rodriguez/byebug/issues/54). Calling
240
+ `Byebug.start` with `Timeout.timeout`.
205
241
 
206
242
  ## 2.6.0 - 2014-02-08
207
243
  ### Fixed
@@ -213,13 +249,14 @@ command work is always saved now.
213
249
 
214
250
  ## 2.4.1 - 2013-12-05
215
251
  ### Fixed
216
- - Installation error in Mac OSX (#40), thanks @luislavena.
252
+ - [#40](https://github.com/deivid-rodriguez/byebug/issues/40). Installation
253
+ error in Mac OSX (thanks @luislavena).
217
254
 
218
255
  ## 2.4.0 - 2013-12-02
219
256
  ### Fixed
220
257
  - `thread list` showing too many threads.
221
- - Fix setting post mortem mode with "set post_mortem". Now this is the only
222
- post mortem functionality available as specifying "Byebug.post_mortem" with a
258
+ - Fix setting post mortem mode with `set post_mortem`. Now this is the only
259
+ post mortem functionality available as specifying `Byebug.post_mortem` with a
223
260
  block has been removed in this version.
224
261
 
225
262
  ### Added
@@ -250,7 +287,8 @@ library (thanks @nobu).
250
287
 
251
288
  ## 2.2.1 - 2013-09-24
252
289
  ### Fixed
253
- - Compilation issue introduced in 2.2.0 (#26).
290
+ - [#26](https://github.com/deivid-rodriguez/byebug/issues/26). Compilation issue
291
+ introduced in `2.2.0`.
254
292
 
255
293
  ### Changed
256
294
  - `show/set stack_trace_on_error` is now `show/set stack_on_error`.
@@ -289,7 +327,7 @@ library (thanks @nobu).
289
327
  - `jump` command. It had never worked.
290
328
 
291
329
  ### Changed
292
- - Varoius internal refactorings.
330
+ - Several internal refactorings.
293
331
 
294
332
  ## 1.8.2 - 2013-08-16
295
333
  ### Fixed
@@ -1,3 +1,29 @@
1
+ ## Getting started
2
+
3
+ The following steps should help you getting started:
4
+
5
+ * `Byebug` depends on the TracePoint API provided by `ruby-core`. This is a
6
+ young API and a lot of bugs have been recently corrected, so make sure you
7
+ always have the lastest patch level release installed.
8
+ * Get a local clone of `byebug`'s source code.
9
+ * Run `bundle install` to get development & test dependencies installed.
10
+ * Install the [overcommit][] hooks using `bundle exec overcommit --install`.
11
+ They will review your changes before they are committed, checking they are
12
+ consistent with the project's code style. If you're changing C files, make sure
13
+ you have the GNU indent utility installed in your system. `sudo apt-get install
14
+ indent` for linux or `brew install gnu-indent --with-default-names` should do
15
+ the job.
16
+ * Make sure you compile the C-extension using `bundle exec rake compile`.
17
+ Otherwise you won't be able to use `byebug`.
18
+ * Run the test suite using the default rake task (`bundle exec rake`). This
19
+ task is composed of 2 subtasks: `bundle exec rake compile` && `bundle exec rake
20
+ test`.
21
+
22
+ After having done this, just read the code and improve it! Your contribution is
23
+ appreciated a lot!
24
+
25
+ [overcommit]: https://github.com/brigade/overcommit/
26
+
1
27
  ## Byebug as a C-extension
2
28
 
3
29
  Byebug is a gem developed as a C-extension. The debugger internal's
@@ -8,34 +34,3 @@ or the feature you are willing to add. You can learn more about C-extensions
8
34
  [here](http://tenderlovemaking.com/2009/12/18/writing-ruby-c-extensions-part-1.html)
9
35
  or
10
36
  [here](http://tenderlovemaking.com/2010/12/11/writing-ruby-c-extensions-part-2.html).
11
-
12
-
13
- ## Prerequisites
14
-
15
- `Byebug` depends on the TracePoint API provided by `ruby-core`. This is a young
16
- API and a lot of bugs have been recently corrected. Without this fixes,
17
- `byebug` will fail to work properly, so make sure you have always the last
18
- patch level releases of Ruby installed.
19
-
20
- Also, if you are developing on linux, make sure you have the GNU indent utility
21
- installed for automatic check of code style in C files. If you're developing in
22
- MacOSX, just make sure you keep a consistent style if you edit the C-extension
23
- files. Travis CI will do the automatic check anyways.
24
-
25
-
26
- ## Getting started
27
-
28
- Once you have a local clone of `byebug`, you can start digging in the source
29
- code. First run `bundle install` to get development & test dependencies
30
- installed. Also make sure you compile the C-extension using `bundle exec rake
31
- compile`, otherwise you won't be able to use your local clone. You can also run
32
- the test suite as the default rake task (`bundle exec rake`). This task is
33
- composed of 4 subtasks:
34
-
35
- bundle exec rake compile # compiles the C-extension
36
- bundle exec rake test # Run the test suite
37
- bundle exec rake rubocop # Run RuboCop's checks on the Ruby files
38
- bundle exec rake ccop # Run `indent`'s checks on the C files
39
-
40
- After having done this, just read the code and improve it! Your contribution is
41
- appreciated a lot!
data/README.md CHANGED
@@ -97,7 +97,7 @@ are debugging rails, start the server and once the execution gets to your
97
97
  `frame` | |
98
98
  `help` | |
99
99
  `history` | |
100
- `info` | | `args` `breakpoints` `catch` `display` `file` `files` `line` `program`
100
+ `info` | | `args` `breakpoints` `catch` `display` `file` `line` `program`
101
101
  `irb` | |
102
102
  `kill` | |
103
103
  `list` | |
@@ -110,8 +110,8 @@ are debugging rails, start the server and once the execution gets to your
110
110
  `quit` | `exit` |
111
111
  `restart` | |
112
112
  `save` | |
113
- `set` | | `autoeval` `autoirb` `autolist` `autosave` `basename` `callstyle` `fullpath` `histfile` `histsize` `linetrace` `listsize` `post_mortem` `stack_on_error` `verbose` `width`
114
- `show` | | `autoeval` `autoirb` `autolist` `autosave` `basename` `callstyle` `fullpath` `histfile` `histsize` `linetrace` `listsize` `post_mortem` `stack_on_error` `verbose` `width`
113
+ `set` | | `autoeval` `autoirb` `autolist` `autosave` `basename` `callstyle` `fullpath` `histfile` `histsize` `linetrace` `listsize` `post_mortem` `savefile` `stack_on_error` `verbose` `width`
114
+ `show` | | `autoeval` `autoirb` `autolist` `autosave` `basename` `callstyle` `fullpath` `histfile` `histsize` `linetrace` `listsize` `post_mortem` `savefile` `stack_on_error` `verbose` `width`
115
115
  `source` | |
116
116
  `step` | |
117
117
  `thread` | | `current` `list` `resume` `stop` `switch`
@@ -48,7 +48,8 @@ module Byebug
48
48
  # @param filename [String] File name to inspect for possible breakpoints
49
49
  #
50
50
  def self.potential_lines(filename)
51
- name, lines = "#{Time.new.to_i}_#{rand(2**31)}", {}
51
+ name = "#{Time.new.to_i}_#{rand(2**31)}"
52
+ lines = {}
52
53
  iseq = RubyVM::InstructionSequence.compile(File.read(filename), name)
53
54
 
54
55
  iseq.disasm.each_line do |line|
@@ -1,29 +1,36 @@
1
1
  require 'columnize'
2
2
  require 'forwardable'
3
- require 'byebug/helper'
3
+ require 'byebug/helpers/string'
4
4
 
5
5
  module Byebug
6
6
  #
7
7
  # Parent class of all byebug commands.
8
8
  #
9
- # Subclasses need to implement a `regexp` and an `execute` command.
9
+ # Subclasses need to implement a `regexp` method and an `execute` method.
10
10
  #
11
11
  class Command
12
12
  extend Forwardable
13
13
 
14
- include ParseFunctions
15
- include FileFunctions
16
-
17
- Subcmd = Struct.new(:name, :min, :help)
14
+ include Helpers::StringHelper
18
15
 
19
16
  def initialize(state)
20
- @match, @state = nil, state
17
+ @match = nil
18
+ @state = state
21
19
  end
22
20
 
23
21
  def match(input)
24
22
  @match = regexp.match(input)
25
23
  end
26
24
 
25
+ def_delegators :'self.class', :to_name, :description
26
+
27
+ #
28
+ # Default help text for a command.
29
+ #
30
+ def help
31
+ prettify(description)
32
+ end
33
+
27
34
  def_delegator :"Byebug.printer", :print, :pr
28
35
  def_delegator :"Byebug.printer", :print_collection, :prc
29
36
  def_delegator :"Byebug.printer", :print_variables, :prv
@@ -65,8 +72,6 @@ module Byebug
65
72
  end
66
73
 
67
74
  class << self
68
- include StringFunctions
69
-
70
75
  attr_accessor :allow_in_control
71
76
  attr_writer :allow_in_post_mortem, :always_run
72
77
 
@@ -78,49 +83,22 @@ module Byebug
78
83
  @always_run ||= 0
79
84
  end
80
85
 
81
- def help(subcmd = nil)
82
- return format_subcmd(subcmd) if subcmd
83
-
84
- output = description
85
- output += format_subcmds if defined? self::Subcommands
86
- output
86
+ #
87
+ # Name of the command, as executed by the user.
88
+ #
89
+ def to_name
90
+ name.gsub(/^Byebug::/, '').gsub(/Command$/, '').downcase
87
91
  end
88
92
 
89
- def find(subcmds, str)
90
- str.downcase!
91
- subcmds.each do |subcmd|
92
- if (str.size >= subcmd.min) && (subcmd.name[0..str.size - 1] == str)
93
- return subcmd
94
- end
95
- end
96
-
97
- nil
98
- end
99
-
100
- def format_subcmd(subcmd_name)
101
- subcmd = find(self::Subcommands, subcmd_name)
102
- return "Invalid \"#{names.join('|')}\" " \
103
- "subcommand \"#{args[1]}\"." unless subcmd
104
-
105
- "\n #{subcmd.help}.\n\n"
106
- end
107
-
108
- def format_subcmds
109
- header = names.join('|')
110
- s = " List of \"#{header}\" subcommands:\n --\n"
111
- w = self::Subcommands.map(&:name).max_by(&:size).size
112
- self::Subcommands.each do |subcmd|
113
- s += format(" %s %-#{w}s -- %s\n", header, subcmd.name, subcmd.help)
114
- end
115
- s + "\n"
116
- end
117
-
118
- def commands
119
- @commands ||= []
120
- end
93
+ #
94
+ # Available subcommands for the current command
95
+ #
96
+ # A subcommand is any class defined inside the parent's command class
97
+ #
98
+ def subcommands
99
+ const_list = constants(false).map { |const| const_get(const, false) }
121
100
 
122
- def inherited(klass)
123
- commands << klass
101
+ const_list.select { |c| c.is_a?(Class) }
124
102
  end
125
103
  end
126
104
  end
@@ -1,10 +1,15 @@
1
1
  require 'byebug/command'
2
+ require 'byebug/helpers/file'
3
+ require 'byebug/helpers/parse'
2
4
 
3
5
  module Byebug
4
6
  #
5
7
  # Implements breakpoint functionality
6
8
  #
7
9
  class BreakCommand < Command
10
+ include Helpers::FileHelper
11
+ include Helpers::ParseHelper
12
+
8
13
  self.allow_in_post_mortem = false
9
14
  self.allow_in_control = true
10
15
 
@@ -13,7 +18,7 @@ module Byebug
13
18
  end
14
19
 
15
20
  def execute
16
- return puts(self.class.help) unless @match[1]
21
+ return puts(help) unless @match[1]
17
22
 
18
23
  b = line_breakpoint(@match[1]) || method_breakpoint(@match[1])
19
24
 
@@ -27,25 +32,24 @@ module Byebug
27
32
  errmsg(e.message)
28
33
  end
29
34
 
30
- class << self
31
- def names
32
- %w(break)
33
- end
35
+ def short_description
36
+ 'Set breakpoint to some position, (optionally) if expr == true'
37
+ end
34
38
 
35
- def description
36
- prettify <<-EOD
37
- b[reak] [file:]line [if expr]
38
- b[reak] [module::...]class(.|#)method [if expr]
39
+ def description
40
+ <<-EOD
41
+ b[reak] [file:]line [if expr]
42
+ b[reak] [module::...]class(.|#)method [if expr]
39
43
 
40
- Set breakpoint to some position, (optionally) if expr == true
41
- EOD
42
- end
44
+ #{short_description}
45
+ EOD
43
46
  end
44
47
 
45
48
  private
46
49
 
47
50
  def line_breakpoint(loc)
48
- line, file_line = loc.match(/^(\d+)$/), loc.match(/^([^:]+):(\d+)$/)
51
+ line = loc.match(/^(\d+)$/)
52
+ file_line = loc.match(/^([^:]+):(\d+)$/)
49
53
  return nil unless line || file_line
50
54
 
51
55
  f, l = line ? [@state.file, line[1]] : [file_line[1], file_line[2]]
@@ -57,7 +61,8 @@ module Byebug
57
61
 
58
62
  def method_breakpoint(location)
59
63
  location.match(/([^.#]+)[.#](.+)/) do |match|
60
- k, m = bb_warning_eval(match[1]), match[2]
64
+ k = bb_warning_eval(match[1])
65
+ m = match[2]
61
66
 
62
67
  klass = k && k.is_a?(Module) ? k.name : match[1]
63
68
  method = m.intern
@@ -67,7 +72,8 @@ module Byebug
67
72
  end
68
73
 
69
74
  def check_errors(file, line)
70
- path, deco_path = File.expand_path(file), normalize(file)
75
+ path = File.expand_path(file)
76
+ deco_path = normalize(file)
71
77
 
72
78
  fail(pr('break.errors.source', file: deco_path)) unless File.exist?(path)
73
79