debug 1.8.0 → 1.9.2
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 +77 -50
- data/debug.gemspec +3 -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 +28 -6
- data/lib/debug/console.rb +9 -30
- data/lib/debug/irb_integration.rb +37 -0
- data/lib/debug/prelude.rb +1 -1
- data/lib/debug/server.rb +5 -3
- data/lib/debug/server_cdp.rb +10 -11
- data/lib/debug/server_dap.rb +3 -1
- data/lib/debug/session.rb +56 -31
- data/lib/debug/source_repository.rb +1 -1
- data/lib/debug/thread_client.rb +19 -18
- data/lib/debug/version.rb +1 -1
- data/misc/README.md.erb +73 -49
- metadata +11 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c242bce58b031f61da73507f6b42a26f1ed8322679d1f0b3460d8fbc8c4b7a23
|
4
|
+
data.tar.gz: 543feb5e53a2c99ba04583edae4a13378667c97b13662f5a4d456dd6bacb17b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5f6c58f38114e3179c3d5c062294ac276b53533fc4a6543114a883198318b672a8506990064f1b40d9f9597d3e1a933cb7c2363ea4cdd4ba0e0571279a80c73
|
7
|
+
data.tar.gz: 142a78dcdc449df6e0148857f992500aa88375707af067f36f1e3391fe2adb7ac8ff0f66623806c5488e94292167a369ca901084475e97b8dc38e32257ccbba0
|
data/Gemfile
CHANGED
data/README.md
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,12 +13,12 @@ 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 | No
|
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 | No | [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
|
@@ -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).
|
@@ -180,7 +180,7 @@ DEBUGGER: Session start (pid: 7656)
|
|
180
180
|
#1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line)
|
181
181
|
```
|
182
182
|
|
183
|
-
You can see that two breakpoints are registered. Let's continue the program by `continue` command.
|
183
|
+
You can see that two breakpoints are registered. Let's continue the program by using the `continue` command.
|
184
184
|
|
185
185
|
```shell
|
186
186
|
(rdbg) continue
|
@@ -200,8 +200,8 @@ Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
|
|
200
200
|
```
|
201
201
|
|
202
202
|
You can see that we can stop at line 3.
|
203
|
-
Let's see the local variables with `info` command, and continue.
|
204
|
-
You can also confirm that the program will suspend at line 5 and you can use `info` command again.
|
203
|
+
Let's see the local variables with the `info` command, and continue.
|
204
|
+
You can also confirm that the program will suspend at line 5 and you can use the `info` command again.
|
205
205
|
|
206
206
|
```shell
|
207
207
|
(rdbg) info
|
@@ -238,14 +238,14 @@ d => 4
|
|
238
238
|
```
|
239
239
|
|
240
240
|
By the way, using `rdbg` command you can suspend your application with `C-c` (SIGINT) and enter the debug console.
|
241
|
-
It will help
|
241
|
+
It will help if you want to know what the program is doing.
|
242
242
|
|
243
243
|
### Use `rdbg` with commands written in Ruby
|
244
244
|
|
245
|
-
If you want to run a command written in Ruby like
|
245
|
+
If you want to run a command written in Ruby like `rake`, `rails`, `bundle`, `rspec`, and so on, you can use `rdbg -c` option.
|
246
246
|
|
247
247
|
* Without `-c` option, `rdbg <name>` means that `<name>` is Ruby script and invoke it like `ruby <name>` with the debugger.
|
248
|
-
* With `-c` option, `rdbg -c <name>` means that `<name>` is command in `PATH` and simply
|
248
|
+
* With `-c` option, `rdbg -c <name>` means that `<name>` is a command in `PATH` and simply invokes it with the debugger.
|
249
249
|
|
250
250
|
Examples:
|
251
251
|
* `rdbg -c -- rails server`
|
@@ -263,36 +263,36 @@ Like other languages, you can use this debugger on the VSCode.
|
|
263
263
|
|
264
264
|
1. Install [VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg)
|
265
265
|
2. Open `.rb` file (e.g. `target.rb`)
|
266
|
-
3. Register breakpoints with "Toggle breakpoint" in Run menu (or type F9 key)
|
266
|
+
3. Register breakpoints with "Toggle breakpoint" in the Run menu (or type F9 key)
|
267
267
|
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
|
268
|
+
5. You will see a dialog "Debug command line" and you can choose your favorite command line you want to run.
|
269
|
+
6. Chosen command line is invoked with `rdbg -c`, and VSCode shows the details at breakpoints.
|
270
270
|
|
271
|
-
Please refer [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode.
|
271
|
+
Please refer to [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode.
|
272
272
|
|
273
273
|
You can configure the extension in `.vscode/launch.json`.
|
274
274
|
Please see the extension page for more details.
|
275
275
|
|
276
276
|
## Remote debugging
|
277
277
|
|
278
|
-
You can use this debugger as a remote debugger. For example, it will help the following situations:
|
278
|
+
You can use this debugger as a remote debugger. For example, it will help in the following situations:
|
279
279
|
|
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.
|
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 a Docker container, and there is no TTY.
|
282
282
|
* Your application is running as a daemon.
|
283
283
|
* Your application uses pipe for STDIN or STDOUT.
|
284
284
|
* Your application is running as a daemon and you want to query the running status (checking a backtrace and so on).
|
285
285
|
|
286
|
-
You can run your application as a remote debuggee and the remote debugger console can attach to the debuggee anytime.
|
286
|
+
You can run your application as a remote debuggee, and the remote debugger console can attach to the debuggee anytime.
|
287
287
|
|
288
288
|
### Invoke as a remote debuggee
|
289
289
|
|
290
290
|
There are multiple ways to run your program as a debuggee:
|
291
291
|
|
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
|
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 | `rdbg --open` | `require "debug/open"` | `DEBUGGER__.open` |
|
295
|
+
| No | `rdbg --open --nonstop` | `require "debug/open_nonstop"` | `DEBUGGER__.open(nonstop: true)` |
|
296
296
|
|
297
297
|
#### `rdbg --open` (or `rdbg -O` for short)
|
298
298
|
|
@@ -305,7 +305,7 @@ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock
|
|
305
305
|
DEBUGGER: wait for debugger connection...
|
306
306
|
```
|
307
307
|
|
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).
|
308
|
+
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
309
|
|
310
310
|
You can connect to the debuggee with `rdbg --attach` command (`rdbg -A` for short).
|
311
311
|
|
@@ -324,11 +324,11 @@ $ rdbg -A
|
|
324
324
|
(rdbg:remote)
|
325
325
|
```
|
326
326
|
|
327
|
-
If there
|
327
|
+
If there are no other opening ports on the default directory, `rdbg --attach` command chooses the only one opening UNIX domain socket and connects to it. If there are more files, you need to specify the file.
|
328
328
|
|
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. When
|
329
|
+
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. When a debuggee program exits, the remote console will also terminate.
|
330
330
|
|
331
|
-
NOTE: If you use `quit` command, only remote console exits and the debuggee program continues to run (and you can connect it again). If you want to exit the debuggee program, use `kill` command.
|
331
|
+
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). If you want to exit the debuggee program, use `kill` command.
|
332
332
|
|
333
333
|
If you want to use TCP/IP for the remote debugging, you need to specify the port and host with `--port` like `rdbg --open --port 12345` and it binds to `localhost:12345`.
|
334
334
|
|
@@ -343,11 +343,11 @@ Note that all messages communicated between the debugger and the debuggee are *N
|
|
343
343
|
|
344
344
|
#### `require 'debug/open'` in a program
|
345
345
|
|
346
|
-
If you can modify the program, you can open debugging port by adding `require 'debug/open'` line in the program.
|
346
|
+
If you can modify the program, you can open the debugging port by adding `require 'debug/open'` line in the program.
|
347
347
|
|
348
348
|
If you don't want to stop the program at the beginning, you can also use `require 'debug/open_nonstop'`.
|
349
349
|
Using `debug/open_nonstop` is useful if you want to open a backdoor to the application.
|
350
|
-
However, it is also
|
350
|
+
However, it is also dangerous because it can become another vulnerability.
|
351
351
|
Please use it carefully.
|
352
352
|
|
353
353
|
By default, UNIX domain socket is used for the debugging port. To use TCP/IP, you can set the `RUBY_DEBUG_PORT` environment variable.
|
@@ -372,7 +372,7 @@ Also `open` command allows opening the debug port.
|
|
372
372
|
|
373
373
|
([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required)
|
374
374
|
|
375
|
-
If you don't run a debuggee Ruby process on VSCode, you can attach
|
375
|
+
If you don't run a debuggee Ruby process on VSCode, you can attach it to VSCode later with the following steps.
|
376
376
|
|
377
377
|
`rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command).
|
378
378
|
|
@@ -425,7 +425,7 @@ If your application is running on a SSH remote host, please try:
|
|
425
425
|
|
426
426
|
```
|
427
427
|
|
428
|
-
and try to use proposed commands.
|
428
|
+
and try to use the proposed commands.
|
429
429
|
|
430
430
|
Note that you can attach with `rdbg --attach` and continue REPL debugging.
|
431
431
|
|
@@ -443,7 +443,7 @@ DEBUGGER: With Chrome browser, type the following URL in the address-bar:
|
|
443
443
|
DEBUGGER: wait for debugger connection...
|
444
444
|
```
|
445
445
|
|
446
|
-
Type `devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=127.0.0.1:57231/b32a55cd-2eb5-4c5c-87d8-b3dfc59d80ef` in the address
|
446
|
+
Type `devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=127.0.0.1:57231/b32a55cd-2eb5-4c5c-87d8-b3dfc59d80ef` in the address bar on Chrome browser, and you can continue the debugging with chrome browser.
|
447
447
|
|
448
448
|
Also `open chrome` command works like `open vscode`.
|
449
449
|
|
@@ -456,7 +456,7 @@ When the debug session is started, initial scripts are loaded so you can put you
|
|
456
456
|
|
457
457
|
### Configuration list
|
458
458
|
|
459
|
-
You can configure debugger's behavior with environment variables and `config` command. Each configuration has environment variable and
|
459
|
+
You can configure the debugger's behavior with environment variables and `config` command. Each configuration has an environment variable and a name which can be specified by `config` command.
|
460
460
|
|
461
461
|
```
|
462
462
|
# configuration example
|
@@ -477,6 +477,7 @@ config set no_color true
|
|
477
477
|
* `RUBY_DEBUG_NO_RELINE` (`no_reline`): Do not use Reline library (default: false)
|
478
478
|
* `RUBY_DEBUG_NO_HINT` (`no_hint`): Do not show the hint on the REPL (default: false)
|
479
479
|
* `RUBY_DEBUG_NO_LINENO` (`no_lineno`): Do not show line numbers (default: false)
|
480
|
+
* `RUBY_DEBUG_IRB_CONSOLE` (`irb_console`): Use IRB as the console (default: false)
|
480
481
|
|
481
482
|
* CONTROL
|
482
483
|
* `RUBY_DEBUG_SKIP_PATH` (`skip_path`): Skip showing/entering frames for given paths
|
@@ -504,6 +505,7 @@ config set no_color true
|
|
504
505
|
* `RUBY_DEBUG_LOCAL_FS_MAP` (`local_fs_map`): Specify local fs map
|
505
506
|
* `RUBY_DEBUG_SKIP_BP` (`skip_bp`): Skip breakpoints if no clients are attached (default: false)
|
506
507
|
* `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation
|
508
|
+
* `RUBY_DEBUG_SESSION_NAME` (`session_name`): Session name for differentiating multiple sessions
|
507
509
|
* `RUBY_DEBUG_CHROME_PATH` (`chrome_path`): Platform dependent path of Chrome (For more information, See [here](https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64))
|
508
510
|
|
509
511
|
* OBSOLETE
|
@@ -513,7 +515,7 @@ There are other environment variables:
|
|
513
515
|
|
514
516
|
* `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/)).
|
515
517
|
* `RUBY_DEBUG_ENABLE`: If the value is `0`, do not enable debug.gem feature.
|
516
|
-
* `RUBY_DEBUG_ADDED_RUBYOPT`: Remove this value from `RUBYOPT` at first. This feature helps loading debug.gem with `RUBYOPT='-r debug/...'
|
518
|
+
* `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.
|
517
519
|
* `RUBY_DEBUG_EDITOR` or `EDITOR`: An editor used by `edit` debug command.
|
518
520
|
* `RUBY_DEBUG_BB`: Define `Kernel#bb` method which is alias of `Kernel#debugger`.
|
519
521
|
|
@@ -525,7 +527,7 @@ If there is `~/.rdbgrc`, the file is loaded as an initial script (which contains
|
|
525
527
|
* You can specify the initial script with `rdbg -x initial_script` (like gdb's `-x` option).
|
526
528
|
|
527
529
|
Initial scripts are useful to write your favorite configurations.
|
528
|
-
For example, you can set
|
530
|
+
For example, you can set breakpoints with `break file:123` in `~/.rdbgrc`.
|
529
531
|
|
530
532
|
If there are `~/.rdbgrc.rb` is available, it is also loaded as a ruby script at same timing.
|
531
533
|
|
@@ -535,16 +537,16 @@ On the debug console, you can use the following debug commands.
|
|
535
537
|
|
536
538
|
There are additional features:
|
537
539
|
|
538
|
-
* `<expr>` without debug command is almost same as `pp <expr>`.
|
539
|
-
* 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. So that the input `foo.bar` is same as `pp foo.bar`.
|
540
|
-
* If `<expr>` is recognized as a debug command, of course it is not evaluated as a Ruby expression
|
541
|
-
* So the author (Koichi Sasada) recommends
|
540
|
+
* `<expr>` without debug command is almost the same as `pp <expr>`.
|
541
|
+
* 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. So that the input `foo.bar` is the same as `pp foo.bar`.
|
542
|
+
* If `<expr>` is recognized as a debug command, of course, it is not evaluated as a Ruby expression but is executed as debug command. 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.
|
543
|
+
* So the author (Koichi Sasada) recommends using `p`, `pp` or `eval` command to evaluate the Ruby expression every time.
|
542
544
|
* `Enter` without any input repeats the last command (useful when repeating `step`s) for some commands.
|
543
545
|
* `Ctrl-D` is equal to `quit` command.
|
544
546
|
* [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
|
545
547
|
|
546
548
|
You can use the following debug commands. Each command should be written in 1 line.
|
547
|
-
The `[...]` notation means this part can be
|
549
|
+
The `[...]` notation means this part can be eliminated. For example, `s[tep]` means `s` or `step` is a valid command. `ste` is not valid.
|
548
550
|
The `<...>` notation means the argument.
|
549
551
|
|
550
552
|
### Control flow
|
@@ -711,7 +713,7 @@ The `<...>` notation means the argument.
|
|
711
713
|
* `eval <expr>`
|
712
714
|
* Evaluate `<expr>` on the current frame.
|
713
715
|
* `irb`
|
714
|
-
*
|
716
|
+
* Activate and switch to `irb:rdbg` console
|
715
717
|
|
716
718
|
### Trace
|
717
719
|
|
@@ -782,6 +784,30 @@ The `<...>` notation means the argument.
|
|
782
784
|
* Show help for the given command.
|
783
785
|
|
784
786
|
|
787
|
+
### Using IRB as the Debug Console
|
788
|
+
|
789
|
+
Starting from version `v1.9`, you can now use IRB as the debug console. This integration brings additional features such as:
|
790
|
+
|
791
|
+
* Autocompletion
|
792
|
+
* Support for multi-line input
|
793
|
+
* Access to commands not available in `debug`, like `show_source` or `show_doc`
|
794
|
+
* [Configurable command aliases](https://docs.ruby-lang.org/en/master/IRB.html#module-IRB-label-Command+Aliases)
|
795
|
+
|
796
|
+
To switch to the IRB console, simply use the `irb` command in the debug console.
|
797
|
+
|
798
|
+
Once activated, you'll notice the prompt changes to:
|
799
|
+
|
800
|
+
```txt
|
801
|
+
irb:rdbg(main):001>
|
802
|
+
```
|
803
|
+
|
804
|
+
If you want to make IRB the default console for all sessions, configure the `irb_console` setting by either:
|
805
|
+
|
806
|
+
* Setting the `RUBY_DEBUG_IRB_CONSOLE=true` environment variable
|
807
|
+
* Or adding `config set irb_console 1` to your `~/.rdbgrc`
|
808
|
+
|
809
|
+
To disable the IRB console in the current session, execute `config set irb_console 0` in the console.
|
810
|
+
|
785
811
|
## Debugger API
|
786
812
|
|
787
813
|
### Start debugging
|
@@ -814,7 +840,7 @@ Emacs support available.
|
|
814
840
|
|
815
841
|
#### Start by method
|
816
842
|
|
817
|
-
After loading `debug/session`, you can start debug session with the following methods. They are convenient if you want to specify debug configurations in your program.
|
843
|
+
After loading `debug/session`, you can start a debug session with the following methods. They are convenient if you want to specify debug configurations in your program.
|
818
844
|
|
819
845
|
* `DEBUGGER__.start(**kw)`: start debug session with local console.
|
820
846
|
* `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket)
|
@@ -833,9 +859,9 @@ DEBUGGER__.start(no_color: true, # disable colorize
|
|
833
859
|
|
834
860
|
### `binding.break` method
|
835
861
|
|
836
|
-
`binding.break` (or `binding.b`) set breakpoints at written line. It also has several keywords.
|
862
|
+
`binding.break` (or `binding.b`) set breakpoints at the written line. It also has several keywords.
|
837
863
|
|
838
|
-
If `do: 'command'` is specified, the debugger suspends the program
|
864
|
+
If `do: 'command'` is specified, the debugger suspends the program, runs the `command` as a debug command, and continues the program.
|
839
865
|
It is useful if you only want to call a debug command and don't want to stop there.
|
840
866
|
|
841
867
|
```
|
@@ -845,9 +871,9 @@ def initialize
|
|
845
871
|
end
|
846
872
|
```
|
847
873
|
|
848
|
-
|
874
|
+
In this case, execute the `info` command then register a watch breakpoint for `@a` and continue to run. You can also use `;;` instead of `\n` to separate your commands.
|
849
875
|
|
850
|
-
If `pre: 'command'` is specified, the debugger suspends the program and
|
876
|
+
If `pre: 'command'` is specified, the debugger suspends the program and runs the `command` as a debug command, and keeps suspended.
|
851
877
|
It is useful if you have operations before suspend.
|
852
878
|
|
853
879
|
```
|
@@ -857,7 +883,7 @@ def foo
|
|
857
883
|
end
|
858
884
|
```
|
859
885
|
|
860
|
-
|
886
|
+
In this case, you can see the result of `bar()` every time you stop there.
|
861
887
|
|
862
888
|
## rdbg command help
|
863
889
|
|
@@ -883,6 +909,7 @@ Debug console mode:
|
|
883
909
|
--port=PORT Listening TCP/IP port
|
884
910
|
--host=HOST Listening TCP/IP host
|
885
911
|
--cookie=COOKIE Set a cookie for connection
|
912
|
+
--session-name=NAME Session name
|
886
913
|
|
887
914
|
Debug console mode runs Ruby program with the debug console.
|
888
915
|
|
data/debug.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = %q{Debugging functionality for Ruby. This is completely rewritten debug.rb which was contained by the ancient Ruby versions.}
|
11
11
|
spec.homepage = "https://github.com/ruby/debug"
|
12
12
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
spec.extensions = ['ext/debug/extconf.rb']
|
29
29
|
|
30
|
-
spec.add_dependency "irb", "
|
31
|
-
spec.add_dependency "reline", ">= 0.3.
|
30
|
+
spec.add_dependency "irb", "~> 1.10" # for irb:debug integration
|
31
|
+
spec.add_dependency "reline", ">= 0.3.8"
|
32
32
|
end
|
data/ext/debug/debug.c
CHANGED
@@ -8,13 +8,13 @@ static VALUE rb_mDebugger;
|
|
8
8
|
|
9
9
|
// iseq
|
10
10
|
typedef struct rb_iseq_struct rb_iseq_t;
|
11
|
+
const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
|
11
12
|
VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
|
12
13
|
|
13
14
|
static VALUE
|
14
15
|
iseq_realpath(VALUE iseqw)
|
15
16
|
{
|
16
|
-
|
17
|
-
return rb_iseq_realpath(iseq);
|
17
|
+
return rb_iseq_realpath(rb_iseqw_to_iseq(iseqw));
|
18
18
|
}
|
19
19
|
|
20
20
|
static VALUE rb_cFrameInfo;
|
@@ -62,15 +62,23 @@ di_body(const rb_debug_inspector_t *dc, void *ptr)
|
|
62
62
|
long i;
|
63
63
|
|
64
64
|
for (i=1; i<len; i++) {
|
65
|
-
VALUE
|
65
|
+
VALUE e;
|
66
66
|
VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
|
67
|
+
VALUE loc = RARRAY_AREF(locs, i);
|
68
|
+
VALUE path;
|
67
69
|
|
68
70
|
if (!NIL_P(iseq)) {
|
69
|
-
|
70
|
-
|
71
|
+
path = iseq_realpath(iseq);
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
// C frame
|
75
|
+
path = rb_funcall(loc, rb_intern("path"), 0);
|
76
|
+
}
|
77
|
+
|
78
|
+
if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) {
|
79
|
+
continue;
|
71
80
|
}
|
72
81
|
|
73
|
-
loc = RARRAY_AREF(locs, i);
|
74
82
|
e = di_entry(loc,
|
75
83
|
rb_debug_inspector_frame_self_get(dc, i),
|
76
84
|
rb_debug_inspector_frame_binding_get(dc, i),
|
@@ -113,26 +121,26 @@ frame_depth(VALUE self)
|
|
113
121
|
|
114
122
|
// iseq
|
115
123
|
|
116
|
-
const
|
124
|
+
const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
|
117
125
|
|
118
126
|
#ifdef HAVE_RB_ISEQ_TYPE
|
119
|
-
VALUE rb_iseq_type(const
|
127
|
+
VALUE rb_iseq_type(const rb_iseq_t *);
|
120
128
|
|
121
129
|
static VALUE
|
122
130
|
iseq_type(VALUE iseqw)
|
123
131
|
{
|
124
|
-
const
|
132
|
+
const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
|
125
133
|
return rb_iseq_type(iseq);
|
126
134
|
}
|
127
135
|
#endif
|
128
136
|
|
129
137
|
#ifdef HAVE_RB_ISEQ_PARAMETERS
|
130
|
-
VALUE rb_iseq_parameters(const
|
138
|
+
VALUE rb_iseq_parameters(const rb_iseq_t *, int is_proc);
|
131
139
|
|
132
140
|
static VALUE
|
133
141
|
iseq_parameters_symbols(VALUE iseqw)
|
134
142
|
{
|
135
|
-
const
|
143
|
+
const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
|
136
144
|
VALUE params = rb_iseq_parameters(iseq, 0);
|
137
145
|
VALUE ary = rb_ary_new();
|
138
146
|
|
@@ -159,12 +167,12 @@ iseq_parameters_symbols(VALUE iseqw)
|
|
159
167
|
#endif
|
160
168
|
|
161
169
|
#ifdef HAVE_RB_ISEQ_CODE_LOCATION
|
162
|
-
void rb_iseq_code_location(const
|
170
|
+
void rb_iseq_code_location(const rb_iseq_t *, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
|
163
171
|
|
164
172
|
static VALUE
|
165
173
|
iseq_first_line(VALUE iseqw)
|
166
174
|
{
|
167
|
-
const
|
175
|
+
const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
|
168
176
|
int line;
|
169
177
|
rb_iseq_code_location(iseq, &line, NULL, NULL, NULL);
|
170
178
|
return INT2NUM(line);
|
@@ -173,20 +181,24 @@ iseq_first_line(VALUE iseqw)
|
|
173
181
|
static VALUE
|
174
182
|
iseq_last_line(VALUE iseqw)
|
175
183
|
{
|
176
|
-
const
|
184
|
+
const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
|
177
185
|
int line;
|
178
186
|
rb_iseq_code_location(iseq, NULL, NULL, &line, NULL);
|
179
187
|
return INT2NUM(line);
|
180
188
|
}
|
181
189
|
#endif
|
182
190
|
|
191
|
+
#ifdef HAVE_RB_ISEQ
|
183
192
|
void Init_iseq_collector(void);
|
193
|
+
#endif
|
184
194
|
|
185
195
|
void
|
186
196
|
Init_debug(void)
|
187
197
|
{
|
198
|
+
#ifdef HAVE_RB_ISEQ
|
188
199
|
VALUE rb_mRubyVM = rb_const_get(rb_cObject, rb_intern("RubyVM"));
|
189
200
|
VALUE rb_cISeq = rb_const_get(rb_mRubyVM, rb_intern("InstructionSequence"));
|
201
|
+
#endif
|
190
202
|
rb_mDebugger = rb_const_get(rb_cObject, rb_intern("DEBUGGER__"));
|
191
203
|
rb_cFrameInfo = rb_const_get(rb_mDebugger, rb_intern("FrameInfo"));
|
192
204
|
|
@@ -210,5 +222,7 @@ Init_debug(void)
|
|
210
222
|
rb_define_method(rb_cISeq, "last_line", iseq_last_line, 0);
|
211
223
|
#endif
|
212
224
|
|
225
|
+
#ifdef HAVE_RB_ISEQ
|
213
226
|
Init_iseq_collector();
|
227
|
+
#endif
|
214
228
|
}
|
data/ext/debug/extconf.rb
CHANGED
data/ext/debug/iseq_collector.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#include <ruby/ruby.h>
|
2
2
|
|
3
|
+
#ifdef HAVE_RB_ISEQ
|
3
4
|
VALUE rb_iseqw_new(VALUE v);
|
4
5
|
void rb_objspace_each_objects(
|
5
6
|
int (*callback)(void *start, void *end, size_t stride, void *data),
|
@@ -89,3 +90,4 @@ Init_iseq_collector(void)
|
|
89
90
|
rb_define_singleton_method(rb_mObjSpace, "each_iseq", each_iseq, 0);
|
90
91
|
rb_define_singleton_method(rb_mObjSpace, "count_iseq", count_iseq, 0);
|
91
92
|
}
|
93
|
+
#endif
|
data/lib/debug/client.rb
CHANGED
@@ -165,15 +165,16 @@ module DEBUGGER__
|
|
165
165
|
end
|
166
166
|
else
|
167
167
|
Client.cleanup_unix_domain_sockets
|
168
|
-
files = Client.list_connections
|
168
|
+
files = Client.list_connections
|
169
169
|
|
170
170
|
case files.size
|
171
171
|
when 0
|
172
172
|
$stderr.puts "No debug session is available."
|
173
173
|
exit
|
174
174
|
when 1
|
175
|
-
@s = Socket.unix(files.first
|
175
|
+
@s = Socket.unix(files.first)
|
176
176
|
else
|
177
|
+
files = Client.list_connections verbose: true
|
177
178
|
$stderr.puts "Please select a debug session:"
|
178
179
|
files.each{|(f, desc)|
|
179
180
|
$stderr.puts " #{File.basename(f)} (#{desc})"
|
data/lib/debug/config.rb
CHANGED
@@ -22,6 +22,7 @@ module DEBUGGER__
|
|
22
22
|
no_reline: ['RUBY_DEBUG_NO_RELINE', "UI: Do not use Reline library", :bool, "false"],
|
23
23
|
no_hint: ['RUBY_DEBUG_NO_HINT', "UI: Do not show the hint on the REPL", :bool, "false"],
|
24
24
|
no_lineno: ['RUBY_DEBUG_NO_LINENO', "UI: Do not show line numbers", :bool, "false"],
|
25
|
+
irb_console: ["RUBY_DEBUG_IRB_CONSOLE", "UI: Use IRB as the console", :bool, "false"],
|
25
26
|
|
26
27
|
# control setting
|
27
28
|
skip_path: ['RUBY_DEBUG_SKIP_PATH', "CONTROL: Skip showing/entering frames for given paths", :path],
|
@@ -49,6 +50,7 @@ module DEBUGGER__
|
|
49
50
|
local_fs_map: ['RUBY_DEBUG_LOCAL_FS_MAP', "REMOTE: Specify local fs map", :path_map],
|
50
51
|
skip_bp: ['RUBY_DEBUG_SKIP_BP', "REMOTE: Skip breakpoints if no clients are attached", :bool, 'false'],
|
51
52
|
cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"],
|
53
|
+
session_name: ['RUBY_DEBUG_SESSION_NAME', "REMOTE: Session name for differentiating multiple sessions"],
|
52
54
|
chrome_path: ['RUBY_DEBUG_CHROME_PATH', "REMOTE: Platform dependent path of Chrome (For more information, See [here](https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64))"],
|
53
55
|
|
54
56
|
# obsolete
|
@@ -156,6 +158,22 @@ module DEBUGGER__
|
|
156
158
|
SESSION.set_no_sigint_hook old, new
|
157
159
|
end
|
158
160
|
end
|
161
|
+
|
162
|
+
if_updated old_conf, conf, :irb_console do |old, new|
|
163
|
+
if defined?(SESSION) && SESSION.active?
|
164
|
+
# irb_console is switched from true to false
|
165
|
+
if old
|
166
|
+
SESSION.deactivate_irb_integration
|
167
|
+
# irb_console is switched from false to true
|
168
|
+
else
|
169
|
+
if CONFIG[:open]
|
170
|
+
SESSION.instance_variable_get(:@ui).puts "\nIRB is not supported on the remote console."
|
171
|
+
else
|
172
|
+
SESSION.activate_irb_integration
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
159
177
|
end
|
160
178
|
|
161
179
|
private def if_updated old_conf, new_conf, key
|
@@ -340,6 +358,9 @@ module DEBUGGER__
|
|
340
358
|
o.on('--cookie=COOKIE', 'Set a cookie for connection') do |c|
|
341
359
|
config[:cookie] = c
|
342
360
|
end
|
361
|
+
o.on('--session-name=NAME', 'Session name') do |name|
|
362
|
+
config[:session_name] = name
|
363
|
+
end
|
343
364
|
|
344
365
|
rdbg = 'rdbg'
|
345
366
|
|
@@ -411,7 +432,6 @@ module DEBUGGER__
|
|
411
432
|
if argv.empty?
|
412
433
|
case
|
413
434
|
when have_shown_version && config[:mode] == :start
|
414
|
-
pp config
|
415
435
|
exit
|
416
436
|
end
|
417
437
|
end
|
@@ -458,7 +478,7 @@ module DEBUGGER__
|
|
458
478
|
require 'tmpdir'
|
459
479
|
|
460
480
|
if tmpdir = Dir.tmpdir
|
461
|
-
path = File.join(tmpdir, "
|
481
|
+
path = File.join(tmpdir, "rdbg-#{Process.uid}")
|
462
482
|
|
463
483
|
unless File.exist?(path)
|
464
484
|
d = Dir.mktmpdir
|
@@ -471,7 +491,7 @@ module DEBUGGER__
|
|
471
491
|
|
472
492
|
def self.unix_domain_socket_homedir
|
473
493
|
if home = ENV['HOME']
|
474
|
-
path = File.join(home, '.
|
494
|
+
path = File.join(home, '.rdbg-sock')
|
475
495
|
|
476
496
|
unless File.exist?(path)
|
477
497
|
Dir.mkdir(path, 0700)
|
@@ -495,12 +515,14 @@ module DEBUGGER__
|
|
495
515
|
end
|
496
516
|
|
497
517
|
def self.create_unix_domain_socket_name_prefix(base_dir = unix_domain_socket_dir)
|
498
|
-
|
499
|
-
File.join(base_dir, "ruby-debug-#{user}")
|
518
|
+
File.join(base_dir, "rdbg")
|
500
519
|
end
|
501
520
|
|
502
521
|
def self.create_unix_domain_socket_name(base_dir = unix_domain_socket_dir)
|
503
|
-
|
522
|
+
suffix = "-#{Process.pid}"
|
523
|
+
name = CONFIG[:session_name]
|
524
|
+
suffix << "-#{name}" if name
|
525
|
+
create_unix_domain_socket_name_prefix(base_dir) + suffix
|
504
526
|
end
|
505
527
|
|
506
528
|
## Help
|