From baf98e42a3fc828207cb491c0720e7d12bfe6e4e Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Thu, 7 Dec 2023 19:02:07 +0330 Subject: [PATCH] Further improvement --- README.md | 28 ++++++++-------- misc/README.md.erb | 80 +++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 38b03a704..db6b7bdf1 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ DEBUGGER: Session start (pid: 7656) #1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line) ``` -You can see that two breakpoints are registered. Let's continue the program by `continue` command. +You can see that two breakpoints are registered. Let's continue the program by using the `continue` command. ```shell (rdbg) continue @@ -200,8 +200,8 @@ Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line) ``` You can see that we can stop at line 3. -Let's see the local variables with `info` command, and continue. -You can also confirm that the program will suspend at line 5 and you can use `info` command again. +Let's see the local variables with the `info` command, and continue. +You can also confirm that the program will suspend at line 5 and you can use the `info` command again. ```shell (rdbg) info @@ -245,7 +245,7 @@ It will help if you want to know what the program is doing. If you want to run a command written in Ruby like `rake`, `rails`, `bundle`, `rspec`, and so on, you can use `rdbg -c` option. * Without `-c` option, `rdbg ` means that `` is Ruby script and invoke it like `ruby ` with the debugger. -* With `-c` option, `rdbg -c ` means that `` is command in `PATH` and simply invoke it with the debugger. +* With `-c` option, `rdbg -c ` means that `` is a command in `PATH` and simply invokes it with the debugger. Examples: * `rdbg -c -- rails server` @@ -263,12 +263,12 @@ Like other languages, you can use this debugger on the VSCode. 1. Install [VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) 2. Open `.rb` file (e.g. `target.rb`) -3. Register breakpoints with "Toggle breakpoint" in Run menu (or type F9 key) +3. Register breakpoints with "Toggle breakpoint" in the Run menu (or type F9 key) 4. Choose "Start debugging" in "Run" menu (or type F5 key) 5. You will see a dialog "Debug command line" and you can choose your favorite command line you want to run. 6. Chosen command line is invoked with `rdbg -c`, and VSCode shows the details at breakpoints. -Please refer [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode. +Please refer to [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode. You can configure the extension in `.vscode/launch.json`. Please see the extension page for more details. @@ -283,7 +283,7 @@ You can use this debugger as a remote debugger. For example, it will help in the * Your application uses pipe for STDIN or STDOUT. * Your application is running as a daemon and you want to query the running status (checking a backtrace and so on). -You can run your application as a remote debugged, and the remote debugger console can attach to the debuggee anytime. +You can run your application as a remote debuggee, and the remote debugger console can attach to the debuggee anytime. ### Invoke as a remote debuggee @@ -305,7 +305,7 @@ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock DEBUGGER: wait for debugger connection... ``` -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). +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). You can connect to the debuggee with `rdbg --attach` command (`rdbg -A` for short). @@ -324,11 +324,11 @@ $ rdbg -A (rdbg:remote) ``` -If there is 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. +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. 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. -NOTE: If you use `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. +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. 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`. @@ -343,11 +343,11 @@ Note that all messages communicated between the debugger and the debuggee are *N #### `require 'debug/open'` in a program -If you can modify the program, you can open debugging port by adding `require 'debug/open'` line in the program. +If you can modify the program, you can open the debugging port by adding `require 'debug/open'` line in the program. If you don't want to stop the program at the beginning, you can also use `require 'debug/open_nonstop'`. Using `debug/open_nonstop` is useful if you want to open a backdoor to the application. -However, it is also danger because it can become another vulnerability. +However, it is also dangerous because it can become another vulnerability. Please use it carefully. 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. ([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required) -If you don't run a debuggee Ruby process on VSCode, you can attach to VSCode later with the following steps. +If you don't run a debuggee Ruby process on VSCode, you can attach it to VSCode later with the following steps. `rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command). @@ -816,7 +816,7 @@ Emacs support available. #### Start by method -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. +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. * `DEBUGGER__.start(**kw)`: start debug session with local console. * `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket) diff --git a/misc/README.md.erb b/misc/README.md.erb index ff800fabf..d591a2f2b 100644 --- a/misc/README.md.erb +++ b/misc/README.md.erb @@ -4,7 +4,7 @@ This library provides debugging functionality to Ruby (MRI) 2.7 and later. -This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by `set_trace_func`. +This debug.rb is the replacement of traditional lib/debug.rb standard library, which is implemented by `set_trace_func`. New debug.rb has several advantages: * Fast: No performance penalty on non-stepping mode and non-breakpoints. @@ -18,7 +18,7 @@ New debug.rb has several advantages: Connection | UDS, TCP/IP | UDS, TCP/IP | TCP/IP | Requirement | No | [vscode-rdbg](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) | Chrome | -* Extensible: application can introduce debugging support with several ways: +* Extensible: application can introduce debugging support in several ways: * By `rdbg` command * By loading libraries with `-r` command line option * By calling Ruby's method explicitly @@ -55,7 +55,7 @@ To use a debugger, roughly you will do the following steps: 4. Use debug commands. * [Evaluate Ruby expressions](#evaluate) (e.g. `p lvar` to see the local variable `lvar`). * [Query the program status](#information) (e.g. `info` to see information about the current frame). - * [Control program flow](#control-flow) (e.g. move to the another line with `step`, to the next line with `next`). + * [Control program flow](#control-flow) (e.g. move to another line with `step`, to the next line with `next`). * [Set another breakpoint](#breakpoint) (e.g. `catch Exception` to set a breakpoint that'll be triggered when `Exception` is raised). * [Activate tracing in your program](#trace) (e.g. `trace call` to trace method calls). * [Change the configuration](#configuration-1) (e.g. `config set no_color true` to disable coloring). @@ -180,7 +180,7 @@ DEBUGGER: Session start (pid: 7656) #1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line) ``` -You can see that two breakpoints are registered. Let's continue the program by `continue` command. +You can see that two breakpoints are registered. Let's continue the program by using the `continue` command. ```shell (rdbg) continue @@ -200,8 +200,8 @@ Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line) ``` You can see that we can stop at line 3. -Let's see the local variables with `info` command, and continue. -You can also confirm that the program will suspend at line 5 and you can use `info` command again. +Let's see the local variables with the `info` command, and continue. +You can also confirm that the program will suspend at line 5 and you can use the `info` command again. ```shell (rdbg) info @@ -238,14 +238,14 @@ d => 4 ``` By the way, using `rdbg` command you can suspend your application with `C-c` (SIGINT) and enter the debug console. -It will help that if you want to know what the program is doing. +It will help if you want to know what the program is doing. ### Use `rdbg` with commands written in Ruby -If you want to run a command written in Ruby like like `rake`, `rails`, `bundle`, `rspec` and so on, you can use `rdbg -c` option. +If you want to run a command written in Ruby like `rake`, `rails`, `bundle`, `rspec`, and so on, you can use `rdbg -c` option. * Without `-c` option, `rdbg ` means that `` is Ruby script and invoke it like `ruby ` with the debugger. -* With `-c` option, `rdbg -c ` means that `` is command in `PATH` and simply invoke it with the debugger. +* With `-c` option, `rdbg -c ` means that `` is a command in `PATH` and simply invokes it with the debugger. Examples: * `rdbg -c -- rails server` @@ -263,27 +263,27 @@ Like other languages, you can use this debugger on the VSCode. 1. Install [VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) 2. Open `.rb` file (e.g. `target.rb`) -3. Register breakpoints with "Toggle breakpoint" in Run menu (or type F9 key) +3. Register breakpoints with "Toggle breakpoint" in the Run menu (or type F9 key) 4. Choose "Start debugging" in "Run" menu (or type F5 key) -5. You will see a dialog "Debug command line" and you can choose your favorite command line your want to run. -6. Chosen command line is invoked with `rdbg -c` and VSCode shows the details at breakpoints. +5. You will see a dialog "Debug command line" and you can choose your favorite command line you want to run. +6. Chosen command line is invoked with `rdbg -c`, and VSCode shows the details at breakpoints. -Please refer [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode. +Please refer to [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode. You can configure the extension in `.vscode/launch.json`. Please see the extension page for more details. ## Remote debugging -You can use this debugger as a remote debugger. For example, it will help the following situations: +You can use this debugger as a remote debugger. For example, it will help in the following situations: -* Your application does not run on TTY and it is hard to use `binding.pry` or `binding.irb`. - * Your application is running on Docker container and there is no TTY. +* Your application does not run on TTY, and it is hard to use `binding.pry` or `binding.irb`. + * Your application is running on a Docker container, and there is no TTY. * Your application is running as a daemon. * Your application uses pipe for STDIN or STDOUT. * Your application is running as a daemon and you want to query the running status (checking a backtrace and so on). -You can run your application as a remote debuggee and the remote debugger console can attach to the debuggee anytime. +You can run your application as a remote debuggee, and the remote debugger console can attach to the debuggee anytime. ### Invoke as a remote debuggee @@ -305,7 +305,7 @@ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock DEBUGGER: wait for debugger connection... ``` -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). +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). You can connect to the debuggee with `rdbg --attach` command (`rdbg -A` for short). @@ -324,11 +324,11 @@ $ rdbg -A (rdbg:remote) ``` -If there is no other opening ports on the default directory, `rdbg --attach` command chooses the only one opening UNIX domain socket and connect to it. If there are more files, you need to specify the file. +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. -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 an debuggee program exits, the remote console will also terminate. +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. -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. +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. 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`. @@ -343,11 +343,11 @@ Note that all messages communicated between the debugger and the debuggee are *N #### `require 'debug/open'` in a program -If you can modify the program, you can open debugging port by adding `require 'debug/open'` line in the program. +If you can modify the program, you can open the debugging port by adding `require 'debug/open'` line in the program. If you don't want to stop the program at the beginning, you can also use `require 'debug/open_nonstop'`. Using `debug/open_nonstop` is useful if you want to open a backdoor to the application. -However, it is also danger because it can become another vulnerability. +However, it is also dangerous because it can become another vulnerability. Please use it carefully. 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. ([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required) -If you don't run a debuggee Ruby process on VSCode, you can attach with VSCode later with the following steps. +If you don't run a debuggee Ruby process on VSCode, you can attach it to VSCode later with the following steps. `rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command). @@ -425,7 +425,7 @@ If your application is running on a SSH remote host, please try: ``` -and try to use proposed commands. +and try to use the proposed commands. Note that you can attach with `rdbg --attach` and continue REPL debugging. @@ -443,7 +443,7 @@ DEBUGGER: With Chrome browser, type the following URL in the address-bar: DEBUGGER: wait for debugger connection... ``` -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. +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. Also `open chrome` command works like `open vscode`. @@ -456,7 +456,7 @@ When the debug session is started, initial scripts are loaded so you can put you ### Configuration list -You can configure debugger's behavior with environment variables and `config` command. Each configuration has environment variable and the name which can be specified by `config` command. +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. ``` # configuration example @@ -473,7 +473,7 @@ There are other environment variables: * `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/)). * `RUBY_DEBUG_ENABLE`: If the value is `0`, do not enable debug.gem feature. -* `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. +* `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. * `RUBY_DEBUG_EDITOR` or `EDITOR`: An editor used by `edit` debug command. * `RUBY_DEBUG_BB`: Define `Kernel#bb` method which is alias of `Kernel#debugger`. @@ -485,7 +485,7 @@ If there is `~/.rdbgrc`, the file is loaded as an initial script (which contains * You can specify the initial script with `rdbg -x initial_script` (like gdb's `-x` option). Initial scripts are useful to write your favorite configurations. -For example, you can set break points with `break file:123` in `~/.rdbgrc`. +For example, you can set breakpoints with `break file:123` in `~/.rdbgrc`. If there are `~/.rdbgrc.rb` is available, it is also loaded as a ruby script at same timing. @@ -495,16 +495,16 @@ On the debug console, you can use the following debug commands. There are additional features: -* `` without debug command is almost same as `pp `. - * If the input line `` does *NOT* start with any debug command, the line `` 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`. - * If `` 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. - * So the author (Koichi Sasada) recommends to use `p`, `pp` or `eval` command to evaluate the Ruby expression everytime. +* `` without debug command is almost the same as `pp `. + * If the input line `` does *NOT* start with any debug command, the line `` 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`. + * If `` 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. + * So the author (Koichi Sasada) recommends using `p`, `pp` or `eval` command to evaluate the Ruby expression every time. * `Enter` without any input repeats the last command (useful when repeating `step`s) for some commands. * `Ctrl-D` is equal to `quit` command. * [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing) You can use the following debug commands. Each command should be written in 1 line. -The `[...]` notation means this part can be eliminate. For example, `s[tep]` means `s` or `step` are valid command. `ste` is not valid. +The `[...]` notation means this part can be eliminated. For example, `s[tep]` means `s` or `step` is a valid command. `ste` is not valid. The `<...>` notation means the argument. <%= DEBUGGER__.help %> @@ -541,7 +541,7 @@ Emacs support available. #### Start by method -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. +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. * `DEBUGGER__.start(**kw)`: start debug session with local console. * `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket) @@ -560,9 +560,9 @@ DEBUGGER__.start(no_color: true, # disable colorize ### `binding.break` method -`binding.break` (or `binding.b`) set breakpoints at written line. It also has several keywords. +`binding.break` (or `binding.b`) set breakpoints at the written line. It also has several keywords. -If `do: 'command'` is specified, the debugger suspends the program and run the `command` as a debug command and continue the program. +If `do: 'command'` is specified, the debugger suspends the program, runs the `command` as a debug command, and continues the program. It is useful if you only want to call a debug command and don't want to stop there. ``` @@ -572,9 +572,9 @@ def initialize end ``` -On 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. +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. -If `pre: 'command'` is specified, the debugger suspends the program and run the `command` as a debug command, and keep suspend. +If `pre: 'command'` is specified, the debugger suspends the program and runs the `command` as a debug command, and keeps suspended. It is useful if you have operations before suspend. ``` @@ -584,7 +584,7 @@ def foo end ``` -On this case, you can see the result of `bar()` every time you stop there. +In this case, you can see the result of `bar()` every time you stop there. ## rdbg command help