debug 1.8.0 → 1.11.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +177 -120
- data/debug.gemspec +4 -3
- data/ext/debug/debug.c +28 -14
- data/ext/debug/extconf.rb +1 -0
- data/ext/debug/iseq_collector.c +2 -0
- data/lib/debug/client.rb +3 -2
- data/lib/debug/config.rb +67 -39
- data/lib/debug/console.rb +31 -41
- data/lib/debug/frame_info.rb +3 -1
- data/lib/debug/irb_integration.rb +37 -0
- data/lib/debug/prelude.rb +1 -1
- data/lib/debug/server.rb +15 -4
- data/lib/debug/server_cdp.rb +11 -12
- data/lib/debug/server_dap.rb +4 -2
- data/lib/debug/session.rb +71 -38
- data/lib/debug/source_repository.rb +1 -1
- data/lib/debug/thread_client.rb +25 -22
- data/lib/debug/version.rb +1 -1
- data/misc/README.md.erb +168 -118
- metadata +12 -13
data/misc/README.md.erb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# debug.rb
|
4
4
|
|
5
|
-
This library provides debugging functionality to Ruby (MRI) 2.
|
5
|
+
This library provides debugging functionality to Ruby (MRI) 2.7 and later.
|
6
6
|
|
7
|
-
This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by `set_trace_func`.
|
7
|
+
This debug.rb is the replacement of traditional lib/debug.rb standard library, which is implemented by `set_trace_func`.
|
8
8
|
New debug.rb has several advantages:
|
9
9
|
|
10
10
|
* Fast: No performance penalty on non-stepping mode and non-breakpoints.
|
@@ -13,41 +13,41 @@ New debug.rb has several advantages:
|
|
13
13
|
* TCP/IP
|
14
14
|
* Integration with rich debugger frontends
|
15
15
|
|
16
|
-
Frontend
|
17
|
-
|
18
|
-
Connection
|
19
|
-
Requirement |
|
16
|
+
| Frontend | [Console](https://github.com/ruby/debug#invoke-as-a-remote-debuggee) | [VSCode](https://github.com/ruby/debug#vscode-integration) | [Chrome DevTool](#chrome-devtool-integration) |
|
17
|
+
| ----------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------- |
|
18
|
+
| Connection | UDS, TCP/IP | UDS, TCP/IP | TCP/IP |
|
19
|
+
| Requirement | None | [vscode-rdbg](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) | Chrome |
|
20
20
|
|
21
|
-
* Extensible: application can introduce debugging support
|
21
|
+
* Extensible: application can introduce debugging support in several ways:
|
22
22
|
* By `rdbg` command
|
23
23
|
* By loading libraries with `-r` command line option
|
24
24
|
* By calling Ruby's method explicitly
|
25
25
|
* Misc
|
26
|
-
* Support threads (almost done) and
|
27
|
-
* Support suspending and entering
|
26
|
+
* Support threads (almost done) and Ractors (TODO).
|
27
|
+
* Support suspending and entering the debug console with `Ctrl-C` at most of timing.
|
28
28
|
* Show parameters on backtrace command.
|
29
|
-
* Support recording
|
29
|
+
* Support recording and replay debugging.
|
30
30
|
|
31
31
|
# Installation
|
32
32
|
|
33
|
-
```
|
33
|
+
```console
|
34
34
|
$ gem install debug
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
Alternatively, specify `-Ipath/to/debug/lib` in `RUBYOPT`, or as a Ruby command-line option
|
38
|
+
This is especially useful for debugging this gem during development.
|
38
39
|
|
39
|
-
If
|
40
|
+
If using Bundler, add the following to your Gemfile:
|
40
41
|
|
41
|
-
```
|
42
|
+
```ruby
|
42
43
|
gem "debug", ">= 1.0.0"
|
43
44
|
```
|
44
45
|
|
45
|
-
(The version constraint is important; `debug < 1.0.0` is an older,
|
46
|
-
abandoned gem that is completely different from this product.)
|
46
|
+
(The version constraint is important; `debug < 1.0.0` is an older, abandoned gem that is completely different from this product.)
|
47
47
|
|
48
48
|
# HOW TO USE
|
49
49
|
|
50
|
-
To use
|
50
|
+
To use the debugger, you will do roughly the following steps:
|
51
51
|
|
52
52
|
1. Set breakpoints.
|
53
53
|
2. Run a program with the debugger.
|
@@ -55,7 +55,7 @@ To use a debugger, roughly you will do the following steps:
|
|
55
55
|
4. Use debug commands.
|
56
56
|
* [Evaluate Ruby expressions](#evaluate) (e.g. `p lvar` to see the local variable `lvar`).
|
57
57
|
* [Query the program status](#information) (e.g. `info` to see information about the current frame).
|
58
|
-
* [Control program flow](#control-flow) (e.g. move to
|
58
|
+
* [Control program flow](#control-flow) (e.g. move to another line with `step`, to the next line with `next`).
|
59
59
|
* [Set another breakpoint](#breakpoint) (e.g. `catch Exception` to set a breakpoint that'll be triggered when `Exception` is raised).
|
60
60
|
* [Activate tracing in your program](#trace) (e.g. `trace call` to trace method calls).
|
61
61
|
* [Change the configuration](#configuration-1) (e.g. `config set no_color true` to disable coloring).
|
@@ -63,22 +63,23 @@ To use a debugger, roughly you will do the following steps:
|
|
63
63
|
|
64
64
|
## Invoke with the debugger
|
65
65
|
|
66
|
-
There are several
|
66
|
+
There are several ways to invoke the debugger, depending on your needs, preferences, and the environment.
|
67
67
|
|
68
68
|
### Modify source code with [`binding.break`](#bindingbreak-method) (similar to `binding.pry` or `binding.irb`)
|
69
69
|
|
70
|
-
If you can modify the source code, you can use the debugger by adding `require 'debug'` at the top of your program and putting [`binding.break`](#bindingbreak-method) method into lines where you want to stop as breakpoints
|
70
|
+
If you can modify the source code, you can use the debugger by adding `require 'debug'` at the top of your program and putting [`binding.break`](#bindingbreak-method) method into lines where you want to stop as breakpoints.
|
71
|
+
This is similar to how `binding.pry` and `binding.irb` work.
|
71
72
|
|
72
|
-
|
73
|
+
`binding.break` has two aliases which do the same thing:
|
73
74
|
|
74
75
|
- `binding.b`
|
75
76
|
- `debugger`
|
76
77
|
|
77
78
|
After that, run the program as usual and you will enter the debug console at breakpoints you inserted.
|
78
79
|
|
79
|
-
The following example
|
80
|
+
The following is an example of the [`binding.break`](#bindingbreak-method) method.
|
80
81
|
|
81
|
-
```
|
82
|
+
```console
|
82
83
|
$ cat target.rb # Sample program
|
83
84
|
require 'debug'
|
84
85
|
|
@@ -140,10 +141,11 @@ d => 4
|
|
140
141
|
|
141
142
|
### Invoke the program from the debugger as a traditional debuggers
|
142
143
|
|
143
|
-
If you don't want to modify the source code, you can
|
144
|
-
|
144
|
+
If you don't want to modify the source code, you can use the `rdbg` command (or `bundle exec rdbg`) to run the program with the debugger.
|
145
|
+
This is similar to how you'd launch a program with `ruby program.rb`.
|
146
|
+
Then you can set breakpoints with the debug command `break` (`b` for short).
|
145
147
|
|
146
|
-
```
|
148
|
+
```console
|
147
149
|
$ cat target.rb # Sample program
|
148
150
|
a = 1
|
149
151
|
b = 2
|
@@ -166,9 +168,11 @@ DEBUGGER: Session start (pid: 7656)
|
|
166
168
|
(rdbg)
|
167
169
|
```
|
168
170
|
|
169
|
-
`rdbg` command suspends the program at the beginning of the given script (`target.rb` in this case) and you can use debug commands
|
171
|
+
The `rdbg` command suspends the program at the beginning of the given script (`target.rb` in this case) and you can use debug commands to control execution from there.
|
172
|
+
`(rdbg)` is the console prompt.
|
173
|
+
Let's set breakpoints on line 3 and line 5 with `break` command (`b` for short).
|
170
174
|
|
171
|
-
```
|
175
|
+
```console
|
172
176
|
(rdbg) break 3 # set breakpoint at line 3
|
173
177
|
#0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
|
174
178
|
|
@@ -180,9 +184,10 @@ DEBUGGER: Session start (pid: 7656)
|
|
180
184
|
#1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line)
|
181
185
|
```
|
182
186
|
|
183
|
-
You can see that two breakpoints are registered.
|
187
|
+
You can see that two breakpoints are registered.
|
188
|
+
Let's continue the program by using the `continue` command.
|
184
189
|
|
185
|
-
```
|
190
|
+
```console
|
186
191
|
(rdbg) continue
|
187
192
|
[1, 7] in target.rb
|
188
193
|
1| a = 1
|
@@ -199,11 +204,11 @@ Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
|
|
199
204
|
(rdbg)
|
200
205
|
```
|
201
206
|
|
202
|
-
You can see that we
|
203
|
-
Let's see the local variables with `info` command, and continue
|
204
|
-
|
207
|
+
You can see that we stopped at line 3.
|
208
|
+
Let's see the local variables with the `info` command, and continue execution with the `continue`.
|
209
|
+
The program will then suspend at line 5 and you can use the `info` command again.
|
205
210
|
|
206
|
-
```
|
211
|
+
```console
|
207
212
|
(rdbg) info
|
208
213
|
=>#0 <main> at target.rb:3
|
209
214
|
%self => main
|
@@ -237,25 +242,28 @@ d => 4
|
|
237
242
|
[1, 2, 3, 4]
|
238
243
|
```
|
239
244
|
|
240
|
-
|
241
|
-
It will help
|
245
|
+
NOTE: When using `rdbg` you can suspend your application with `C-c` (SIGINT) and enter the debug console.
|
246
|
+
It will help if you want to know what the program is doing.
|
242
247
|
|
243
248
|
### Use `rdbg` with commands written in Ruby
|
244
249
|
|
245
|
-
If you want to run
|
250
|
+
If you want to run an executable written in Ruby like `rake`, `rails`, `bundle`, `rspec`, and so on, you can use `rdbg -c` option.
|
246
251
|
|
247
|
-
* Without `-c` option, `rdbg <name>` means that `<name>` is Ruby script and
|
248
|
-
* With `-c` option, `rdbg -c <name>` means that `<name>` is
|
252
|
+
* Without the `-c` option, `rdbg <name>` means that `<name>` is a Ruby script and it is invoked like `ruby <name>` with the debugger.
|
253
|
+
* With the `-c` option, `rdbg -c <name>` means that `<name>` is an executable in `PATH` and simply invokes it with the debugger.
|
249
254
|
|
250
255
|
Examples:
|
256
|
+
|
251
257
|
* `rdbg -c -- rails server`
|
252
258
|
* `rdbg -c -- bundle exec ruby foo.rb`
|
253
259
|
* `rdbg -c -- bundle exec rake test`
|
254
|
-
* `rdbg -c -- ruby target.rb` is same as `rdbg target.rb`
|
260
|
+
* `rdbg -c -- ruby target.rb` is the same as `rdbg target.rb`
|
255
261
|
|
256
|
-
NOTE: `--` is needed to separate the command line options for `rdbg`
|
262
|
+
NOTE: `--` is needed to separate the command line options for `rdbg` from the executable being invoked, and its options.
|
263
|
+
For example, `rdbg -c rake -T` would be parsed as `rdbg -c -T -- rake`, which is incorrect.
|
264
|
+
It should be `rdbg -c -- rake -T`.
|
257
265
|
|
258
|
-
NOTE: If you want to use
|
266
|
+
NOTE: If you want to use Bundler (`bundle` executable), you need to add `gem 'debug'` to your `Gemfile`.
|
259
267
|
|
260
268
|
### Using VSCode
|
261
269
|
|
@@ -263,53 +271,55 @@ Like other languages, you can use this debugger on the VSCode.
|
|
263
271
|
|
264
272
|
1. Install [VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg)
|
265
273
|
2. Open `.rb` file (e.g. `target.rb`)
|
266
|
-
3. Register breakpoints with "Toggle breakpoint" in Run menu (or type F9 key)
|
274
|
+
3. Register breakpoints with "Toggle breakpoint" in the Run menu (or type F9 key)
|
267
275
|
4. Choose "Start debugging" in "Run" menu (or type F5 key)
|
268
|
-
5. You will see a dialog "Debug command line" and you can choose your favorite command line
|
269
|
-
6. Chosen command line is invoked with `rdbg -c
|
276
|
+
5. You will see a dialog "Debug command line" and you can choose your favorite command line you want to run.
|
277
|
+
6. Chosen command line is invoked with `rdbg -c`, and VSCode shows the details at breakpoints.
|
270
278
|
|
271
|
-
Please refer [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode.
|
279
|
+
Please refer to [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode.
|
272
280
|
|
273
281
|
You can configure the extension in `.vscode/launch.json`.
|
274
282
|
Please see the extension page for more details.
|
275
283
|
|
276
284
|
## Remote debugging
|
277
285
|
|
278
|
-
You can use this debugger as a remote debugger.
|
286
|
+
You can use this debugger as a remote debugger.
|
287
|
+
For example, it will help in the following situations:
|
279
288
|
|
280
|
-
* Your application does not run on TTY and it is hard to use `binding.pry` or `binding.irb`.
|
281
|
-
* Your application is running on Docker container and there is no TTY.
|
289
|
+
* Your application does not run on TTY, and it is hard to use `binding.pry` or `binding.irb`.
|
290
|
+
* Your application is running on a Docker container, and there is no TTY.
|
282
291
|
* Your application is running as a daemon.
|
283
|
-
* Your application uses pipe for STDIN or STDOUT
|
292
|
+
* Your application uses pipe for `STDIN` or `STDOUT`.
|
284
293
|
* Your application is running as a daemon and you want to query the running status (checking a backtrace and so on).
|
285
294
|
|
286
|
-
You can run your application as a remote debuggee and the remote debugger console can attach to the debuggee anytime.
|
295
|
+
You can run your application as a remote debuggee, and the remote debugger console can attach to the debuggee anytime.
|
287
296
|
|
288
297
|
### Invoke as a remote debuggee
|
289
298
|
|
290
299
|
There are multiple ways to run your program as a debuggee:
|
291
300
|
|
292
|
-
Stop at program start | [`rdbg` option](https://github.com/ruby/debug#rdbg---open-or-rdbg--o-for-short) | [require](https://github.com/ruby/debug#require-debugopen-in-a-program) | [debugger API](https://github.com/ruby/debug#start-by-method)
|
293
|
-
|
294
|
-
Yes
|
295
|
-
No
|
301
|
+
| Stop at program start | [`rdbg` option](https://github.com/ruby/debug#rdbg---open-or-rdbg--o-for-short) | [require](https://github.com/ruby/debug#require-debugopen-in-a-program) | [debugger API](https://github.com/ruby/debug#start-by-method) |
|
302
|
+
| --------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------- |
|
303
|
+
| Yes | `rdbg --open` | `require "debug/open"` | `DEBUGGER__.open` |
|
304
|
+
| No | `rdbg --open --nonstop` | `require "debug/open_nonstop"` | `DEBUGGER__.open(nonstop: true)` |
|
296
305
|
|
297
306
|
#### `rdbg --open` (or `rdbg -O` for short)
|
298
307
|
|
299
|
-
|
308
|
+
Launch a script with `rdbg --open target.rb` to run `target.rb` as a debuggee program.
|
309
|
+
It also opens the network port and suspends at the beginning of `target.rb`.
|
300
310
|
|
301
|
-
```
|
302
|
-
$
|
311
|
+
```console
|
312
|
+
$ rdbg --open target.rb
|
303
313
|
DEBUGGER: Session start (pid: 7773)
|
304
314
|
DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-7773)
|
305
315
|
DEBUGGER: wait for debugger connection...
|
306
316
|
```
|
307
317
|
|
308
|
-
By default, `rdbg --open` uses UNIX domain socket and generates path name automatically (`/home/ko1/.ruby-debug-sock/ruby-debug-ko1-7773` in this case).
|
318
|
+
By default, `rdbg --open` uses UNIX domain socket and generates the path name automatically (`/home/ko1/.ruby-debug-sock/ruby-debug-ko1-7773` in this case).
|
309
319
|
|
310
320
|
You can connect to the debuggee with `rdbg --attach` command (`rdbg -A` for short).
|
311
321
|
|
312
|
-
```
|
322
|
+
```console
|
313
323
|
$ rdbg -A
|
314
324
|
[1, 7] in target.rb
|
315
325
|
=> 1| a = 1
|
@@ -324,35 +334,41 @@ $ rdbg -A
|
|
324
334
|
(rdbg:remote)
|
325
335
|
```
|
326
336
|
|
327
|
-
If there
|
337
|
+
If there are no other files in the default directory, `rdbg --attach` will automatically connect to the UNIX domain socket listed.
|
338
|
+
If there are multiple files, you need to specify which to use.
|
328
339
|
|
329
|
-
When `rdbg --attach` connects to the debuggee, you can use any debug commands (set breakpoints, continue the program and so on) like local debug console.
|
340
|
+
When `rdbg --attach` connects to the debuggee, you can use any debug commands (set breakpoints, continue the program, and so on) like the local debug console.
|
341
|
+
When a debuggee program exits, the remote console will also terminate.
|
330
342
|
|
331
|
-
NOTE: If you use `quit` command, only remote console exits and the debuggee program continues to run (and you can connect it again).
|
343
|
+
NOTE: If you use the `quit` command, only the remote console exits and the debuggee program continues to run (and you can connect it again).
|
344
|
+
If you want to exit the debuggee program, use `kill` command.
|
332
345
|
|
333
|
-
If you want to use TCP/IP for
|
346
|
+
If you want to use TCP/IP for remote debugging, you need to specify the port and host with `--port` like `rdbg --open --port 12345` and it binds to `localhost:12345`.
|
347
|
+
You can add an optional `--port_range` to try multiple ports in a reliable way.
|
348
|
+
For example, `rdbg --open --port 12345 --port_range 10` will try to bind to 12345, 12346, 12347,… until it finds an available port.
|
334
349
|
|
335
350
|
To connect to the debuggee, you need to specify the port.
|
336
351
|
|
337
|
-
```
|
352
|
+
```console
|
338
353
|
$ rdbg --attach 12345
|
339
354
|
```
|
340
355
|
|
341
356
|
If you want to choose the host to bind, you can use `--host` option.
|
342
|
-
|
357
|
+
Messages communicated between the debugger and the debuggee are *NOT* encrypted so please use remote debugging carefully.
|
343
358
|
|
344
359
|
#### `require 'debug/open'` in a program
|
345
360
|
|
346
|
-
If you can modify the program, you can open debugging port by adding `require 'debug/open'`
|
361
|
+
If you can modify the program, you can open the debugging port by adding `require 'debug/open'` in the program.
|
347
362
|
|
348
363
|
If you don't want to stop the program at the beginning, you can also use `require 'debug/open_nonstop'`.
|
349
364
|
Using `debug/open_nonstop` is useful if you want to open a backdoor to the application.
|
350
|
-
However, it is also
|
365
|
+
However, it is also dangerous because it can become another vulnerability.
|
351
366
|
Please use it carefully.
|
352
367
|
|
353
|
-
By default, UNIX domain socket is used for the debugging port.
|
368
|
+
By default, UNIX domain socket is used for the debugging port.
|
369
|
+
To use TCP/IP, you can set the `RUBY_DEBUG_PORT` environment variable.
|
354
370
|
|
355
|
-
```
|
371
|
+
```console
|
356
372
|
$ RUBY_DEBUG_PORT=12345 ruby target.rb
|
357
373
|
```
|
358
374
|
|
@@ -364,19 +380,17 @@ You can attach with external debugger frontend with VSCode and Chrome.
|
|
364
380
|
$ rdbg --open=[frontend] target.rb
|
365
381
|
```
|
366
382
|
|
367
|
-
will open a debug port and `[frontend]` can attach to the port.
|
368
|
-
|
369
|
-
Also `open` command allows opening the debug port.
|
383
|
+
This will open a debug port and the `[frontend]` can attach to the port.
|
370
384
|
|
371
385
|
#### VSCode integration
|
372
386
|
|
373
387
|
([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required)
|
374
388
|
|
375
|
-
If you don't run a debuggee Ruby process on VSCode, you can attach
|
389
|
+
If you don't run a debuggee Ruby process on VSCode, you can attach it to VSCode later with the following steps.
|
376
390
|
|
377
|
-
`rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code`
|
391
|
+
`rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` executable).
|
378
392
|
|
379
|
-
```
|
393
|
+
```console
|
380
394
|
$ rdbg --open=vscode target.rb
|
381
395
|
DEBUGGER: Debugger can attach via UNIX domain socket (/tmp/ruby-debug-sock-1000/ruby-debug-ko1-27706)
|
382
396
|
DEBUGGER: wait for debugger connection...
|
@@ -384,11 +398,11 @@ Launching: code /tmp/ruby-debug-vscode-20211014-27706-gd7e85/ /tmp/ruby-debug-vs
|
|
384
398
|
DEBUGGER: Connected.
|
385
399
|
```
|
386
400
|
|
387
|
-
|
401
|
+
It tries to invoke the new VSCode window and VSCode will attach to the debuggee Ruby program automatically.
|
388
402
|
|
389
|
-
You can also use `open vscode`
|
403
|
+
You can also use `open vscode` in a REPL.
|
390
404
|
|
391
|
-
```
|
405
|
+
```console
|
392
406
|
$ rdbg target.rb
|
393
407
|
[1, 8] in target.rb
|
394
408
|
1|
|
@@ -407,9 +421,9 @@ Launching: code /tmp/ruby-debug-vscode-20211014-28337-kg9dm/ /tmp/ruby-debug-vsc
|
|
407
421
|
DEBUGGER: Connected.
|
408
422
|
```
|
409
423
|
|
410
|
-
If the machine which runs the Ruby process doesn't have a `code`
|
424
|
+
If the machine which runs the Ruby process doesn't have a `code` executable on `$PATH`, the following message will be shown:
|
411
425
|
|
412
|
-
```
|
426
|
+
```console
|
413
427
|
(rdbg) open vscode
|
414
428
|
DEBUGGER: wait for debugger connection...
|
415
429
|
DEBUGGER: Debugger can attach via UNIX domain socket (/tmp/ruby-debug-sock-1000/ruby-debug-ko1-455)
|
@@ -425,15 +439,13 @@ If your application is running on a SSH remote host, please try:
|
|
425
439
|
|
426
440
|
```
|
427
441
|
|
428
|
-
and try to use proposed commands.
|
429
|
-
|
430
442
|
Note that you can attach with `rdbg --attach` and continue REPL debugging.
|
431
443
|
|
432
444
|
#### Chrome DevTool integration
|
433
445
|
|
434
|
-
|
446
|
+
Using `rdbg --open=chrome` will show the following message:
|
435
447
|
|
436
|
-
```
|
448
|
+
```console
|
437
449
|
$ rdbg target.rb --open=chrome
|
438
450
|
DEBUGGER: Debugger can attach via TCP/IP (127.0.0.1:43633)
|
439
451
|
DEBUGGER: With Chrome browser, type the following URL in the address-bar:
|
@@ -443,20 +455,25 @@ DEBUGGER: With Chrome browser, type the following URL in the address-bar:
|
|
443
455
|
DEBUGGER: wait for debugger connection...
|
444
456
|
```
|
445
457
|
|
446
|
-
Type
|
458
|
+
Type the following in the address bar on Chrome browser, and you can continue the debugging with chrome browser:
|
459
|
+
|
460
|
+
```txt
|
461
|
+
devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=127.0.0.1:57231/b32a55cd-2eb5-4c5c-87d8-b3dfc59d80ef`
|
462
|
+
```
|
447
463
|
|
448
|
-
|
464
|
+
Similar to VSCode, you can use `open chrome` to open the debugger in Chrome.
|
449
465
|
|
450
|
-
For more information about how to use Chrome debugging,
|
466
|
+
For more information about how to use Chrome debugging, [see the devtools docs](https://developer.chrome.com/docs/devtools/).
|
451
467
|
|
452
468
|
## Configuration
|
453
469
|
|
454
470
|
You can configure the debugger's behavior with debug commands and environment variables.
|
455
|
-
When the debug session is started,
|
471
|
+
When the debug session is started, some [initialization scripts](#initial-scripts) (e.g., `~/.rdbgrc`) are loaded, allowing you to configure the debugger's behavior to your needs and preferences.
|
456
472
|
|
457
473
|
### Configuration list
|
458
474
|
|
459
|
-
You can configure debugger's behavior with environment variables and `config` command.
|
475
|
+
You can configure the debugger's behavior with environment variables and `config` command.
|
476
|
+
Each configuration has an environment variable and a name which can be specified by `config` command.
|
460
477
|
|
461
478
|
```
|
462
479
|
# configuration example
|
@@ -473,21 +490,21 @@ There are other environment variables:
|
|
473
490
|
|
474
491
|
* `NO_COLOR`: If the value is set, set `RUBY_DEBUG_NO_COLOR` ([NO_COLOR: disabling ANSI color output in various Unix commands](https://no-color.org/)).
|
475
492
|
* `RUBY_DEBUG_ENABLE`: If the value is `0`, do not enable debug.gem feature.
|
476
|
-
* `RUBY_DEBUG_ADDED_RUBYOPT`: Remove this value from `RUBYOPT` at first. This feature helps loading debug.gem with `RUBYOPT='-r debug/...'
|
493
|
+
* `RUBY_DEBUG_ADDED_RUBYOPT`: Remove this value from `RUBYOPT` at first. This feature helps loading debug.gem with `RUBYOPT='-r debug/...'`, and you don't want to derive it to child processes. In this case, you can set `RUBY_DEBUG_ADDED_RUBYOPT='-r debug/...'` (same value), and this string will be deleted from `RUBYOPT` at first.
|
477
494
|
* `RUBY_DEBUG_EDITOR` or `EDITOR`: An editor used by `edit` debug command.
|
478
495
|
* `RUBY_DEBUG_BB`: Define `Kernel#bb` method which is alias of `Kernel#debugger`.
|
479
496
|
|
480
497
|
### Initial scripts
|
481
498
|
|
482
|
-
If there is `~/.rdbgrc
|
499
|
+
If there is a `~/.rdbgrc` file it is loaded as an initialization script (which contains debug commands) when the debug session is started.
|
483
500
|
|
484
501
|
* `RUBY_DEBUG_INIT_SCRIPT` environment variable can specify the initial script file.
|
485
502
|
* You can specify the initial script with `rdbg -x initial_script` (like gdb's `-x` option).
|
486
503
|
|
487
504
|
Initial scripts are useful to write your favorite configurations.
|
488
|
-
For example, you can set
|
505
|
+
For example, you can set breakpoints with `break file:123` in `~/.rdbgrc`.
|
489
506
|
|
490
|
-
If there
|
507
|
+
If there is a `~/.rdbgrc.rb` file it is also loaded as a Ruby script when the debug session is started.
|
491
508
|
|
492
509
|
## Debug command on the debug console
|
493
510
|
|
@@ -495,20 +512,47 @@ On the debug console, you can use the following debug commands.
|
|
495
512
|
|
496
513
|
There are additional features:
|
497
514
|
|
498
|
-
* `<expr>` without debug command is almost same as `pp <expr>`.
|
499
|
-
* If the input line `<expr>` does *NOT* start with any debug command, the line `<expr>` will be evaluated as a Ruby expression and the result will be printed with `pp` method.
|
500
|
-
|
501
|
-
*
|
515
|
+
* `<expr>` without debug command is almost the same as `pp <expr>`.
|
516
|
+
* If the input line `<expr>` does *NOT* start with any debug command, the line `<expr>` will be evaluated as a Ruby expression, and the result will be printed with `pp` method.
|
517
|
+
So that the input `foo.bar` is the same as `pp foo.bar`.
|
518
|
+
* If `<expr>` is recognized as a debug command, of course, it is not evaluated as a Ruby expression but is executed as debug command.
|
519
|
+
For example, you can not evaluate such single-letter local variables `i`, `b`, `n`, `c` because they are single-letter debug commands. Use `p i` instead.
|
520
|
+
* For consistency, the author (Koichi Sasada) recommends using the `p`, `pp`, or `eval` command to evaluate the Ruby expression every time.
|
502
521
|
* `Enter` without any input repeats the last command (useful when repeating `step`s) for some commands.
|
503
522
|
* `Ctrl-D` is equal to `quit` command.
|
504
523
|
* [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
|
505
524
|
|
506
|
-
You can use the following debug commands.
|
507
|
-
|
508
|
-
The
|
525
|
+
You can use the following debug commands.
|
526
|
+
Each command should be written in 1 line.
|
527
|
+
The `[…]` notation means this part can be eliminated. For example, `s[tep]` means `s` or `step` is a valid command. `ste` is not valid.
|
528
|
+
The `<…>` notation means the argument.
|
509
529
|
|
510
530
|
<%= DEBUGGER__.help %>
|
511
531
|
|
532
|
+
### Using IRB as the Debug Console
|
533
|
+
|
534
|
+
Starting from version `v1.9`, you can now use IRB as the debug console. This integration brings additional features such as:
|
535
|
+
|
536
|
+
* Autocompletion
|
537
|
+
* Support for multi-line input
|
538
|
+
* Access to commands not available in `debug`, like `show_source` or `show_doc`
|
539
|
+
* [Configurable command aliases](https://docs.ruby-lang.org/en/master/IRB.html#module-IRB-label-Command+Aliases)
|
540
|
+
|
541
|
+
To switch to the IRB console, simply use the `irb` command in the debug console.
|
542
|
+
|
543
|
+
Once activated, you'll notice the prompt changes to:
|
544
|
+
|
545
|
+
```console
|
546
|
+
irb:rdbg(main):001>
|
547
|
+
```
|
548
|
+
|
549
|
+
If you want to make IRB the default console for all sessions, configure the `irb_console` setting by either:
|
550
|
+
|
551
|
+
* Setting the `RUBY_DEBUG_IRB_CONSOLE=true` environment variable
|
552
|
+
* Or adding `config set irb_console 1` to your `~/.rdbgrc`
|
553
|
+
|
554
|
+
To disable the IRB console in the current session, execute `config set irb_console 0` in the console.
|
555
|
+
|
512
556
|
## Debugger API
|
513
557
|
|
514
558
|
### Start debugging
|
@@ -525,9 +569,12 @@ You can start debugging without `rdbg` command by requiring the following librar
|
|
525
569
|
You need to require one of them at the very beginning of the application.
|
526
570
|
Using `ruby -r` (for example `ruby -r debug/start target.rb`) is another way to invoke with debugger.
|
527
571
|
|
528
|
-
NOTE: Until Ruby 3.0, there is old `lib/debug.rb` standard library.
|
572
|
+
NOTE: Until Ruby 3.0, there is old `lib/debug.rb` in the standard library.
|
573
|
+
`lib/debug.rb` was not maintained well in recent years, and the purpose of this library is to rewrite old `lib/debug.rb` with recent techniques.
|
574
|
+
|
575
|
+
So, if this gem is not installed, or if the `Gemfile` doesn't include this gem and `bundle exec` is used, you will see the following output:
|
529
576
|
|
530
|
-
```
|
577
|
+
```console
|
531
578
|
$ ruby -r debug -e0
|
532
579
|
.../2.7.3/lib/ruby/2.7.0/x86_64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
|
533
580
|
Debug.rb
|
@@ -537,16 +584,15 @@ Emacs support available.
|
|
537
584
|
(rdb:1)
|
538
585
|
```
|
539
586
|
|
540
|
-
`lib/debug.rb` was not maintained well in recent years, and the purpose of this library is to rewrite old `lib/debug.rb` with recent techniques.
|
541
|
-
|
542
587
|
#### Start by method
|
543
588
|
|
544
|
-
After loading `debug/session`, you can start debug session with the following methods.
|
589
|
+
After loading `debug/session`, you can start a debug session with the following methods.
|
590
|
+
They are convenient if you want to specify debug configurations in your program.
|
545
591
|
|
546
592
|
* `DEBUGGER__.start(**kw)`: start debug session with local console.
|
547
|
-
* `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket)
|
548
|
-
* `DEBUGGER__.open_unix(**kw)`: open debug port with UNIX domain socket
|
549
|
-
* `DEBUGGER__.open_tcp(**kw)`: open debug port with TCP/IP
|
593
|
+
* `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket).
|
594
|
+
* `DEBUGGER__.open_unix(**kw)`: open debug port with UNIX domain socket.
|
595
|
+
* `DEBUGGER__.open_tcp(**kw)`: open debug port with TCP/IP.
|
550
596
|
|
551
597
|
For example:
|
552
598
|
|
@@ -560,35 +606,39 @@ DEBUGGER__.start(no_color: true, # disable colorize
|
|
560
606
|
|
561
607
|
### `binding.break` method
|
562
608
|
|
563
|
-
`binding.break` (or `binding.b`)
|
609
|
+
`binding.break` (or `binding.b`) sets a breakpoint at that line.
|
610
|
+
It also has several keywords.
|
564
611
|
|
565
|
-
If `do: 'command'` is specified, the debugger suspends the program
|
612
|
+
If `do: 'command'` is specified, the debugger suspends the program, runs the `command` as a debug command, and continues the program.
|
566
613
|
It is useful if you only want to call a debug command and don't want to stop there.
|
614
|
+
For example:
|
567
615
|
|
568
|
-
```
|
616
|
+
```ruby
|
569
617
|
def initialize
|
570
618
|
@a = 1
|
571
619
|
binding.b do: 'info \n watch @a'
|
572
620
|
end
|
573
621
|
```
|
574
622
|
|
575
|
-
|
623
|
+
In this case, execute the `info` command, then register a watch breakpoint for `@a` and continue to run.
|
624
|
+
You can also use `;;` instead of `\n` to separate your commands.
|
576
625
|
|
577
|
-
If `pre: 'command'` is specified, the debugger suspends the program and
|
626
|
+
If `pre: 'command'` is specified, the debugger suspends the program and runs the `command` as a debug command, and keeps suspended.
|
578
627
|
It is useful if you have operations before suspend.
|
628
|
+
For example:
|
579
629
|
|
580
|
-
```
|
630
|
+
```ruby
|
581
631
|
def foo
|
582
632
|
binding.b pre: 'p bar()'
|
583
633
|
...
|
584
634
|
end
|
585
635
|
```
|
586
636
|
|
587
|
-
|
637
|
+
In this case, you can see the result of `bar()` every time you stop there.
|
588
638
|
|
589
639
|
## rdbg command help
|
590
640
|
|
591
|
-
```
|
641
|
+
```console
|
592
642
|
<%= `exe/rdbg --help` %>
|
593
643
|
```
|
594
644
|
|
@@ -599,7 +649,7 @@ On this case, you can see the result of `bar()` every time you stop there.
|
|
599
649
|
|
600
650
|
# Contributing
|
601
651
|
|
602
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
|
652
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/ruby/debug]().
|
603
653
|
This debugger is not mature so your feedback will help us.
|
604
654
|
|
605
655
|
Please also check the [contributing guideline](/CONTRIBUTING.md).
|