debug 1.0.0.beta7 → 1.0.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d545d212530685e0eaf7163bc0b2517befd0edfdc1b083c64ecab6bfcb6958b8
4
- data.tar.gz: 6662febf1dccfbc0e7e4ec785578fb5eac2a076fa488a4a3a814582f80fa940f
3
+ metadata.gz: df98b8b5fd353be1aad11534d3180e9ae4b753de6e7ca95c3568d79e952e4770
4
+ data.tar.gz: 600580327ace5a5feb37df85e3d0569d17ee55a118dab0d05513452745211b2a
5
5
  SHA512:
6
- metadata.gz: 3173551c5ada6fb2f7f71656a5762b6a6a6cc541d80d371532abfe1e03188f81ffb397df1a2c8d743c34983e27c5abe6e33ae8d8188502960501801af3aa9ea3
7
- data.tar.gz: 59c84ef76b01d8630b764784d68edb7b1e25e2c336cab56a74e23add5f606f14c3dfe2d6cdd9fe3779e328ca8873317d5d7b56a8e5a7951ecc3a081c20c309d8
6
+ metadata.gz: 3a8b1ba471ca0169bc243e7a97600160317d041c022452b00fc0c2729939bc5ea907f52293cfa62dcf5d3be95cbd3c89ed9ebe2d49221e228f5588834378abdd
7
+ data.tar.gz: ee7524b1fb4040472ca7e7d9c760f92200dfe0f94d034877c3d23ea0f940f2a8f9d67310a756fa287ecf6b80c60e7d221215d1b150798f49a3fc627c7b9635d7
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
  gem "rake"
6
6
  gem "rake-compiler"
7
7
  gem "test-unit", "~> 3.0"
8
+ gem "test-unit-rr"
data/README.md CHANGED
@@ -12,7 +12,7 @@ New debug.rb has several advantages:
12
12
  * UNIX domain socket
13
13
  * TCP/IP
14
14
  * VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
15
- * Extensible: application can introduce debugging support with several methods
15
+ * Extensible: application can introduce debugging support with several ways:
16
16
  * By `rdbg` command
17
17
  * By loading libraries with `-r` command line option
18
18
  * By calling Ruby's method explicitly
@@ -29,317 +29,327 @@ $ gem install debug --pre
29
29
 
30
30
  or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
31
31
 
32
- If you use Bundler, write the following line to your Gemfile. And use rdbg command with -c option.
32
+ If you use Bundler, write the following line to your Gemfile.
33
33
 
34
34
  ```
35
35
  gem "debug", ">= 1.0.0.beta"
36
36
  ```
37
37
 
38
- ```
39
- $ rdbg -c bundle exec ruby target.rb
40
- ```
41
-
42
- # How to use
43
-
44
- ## Invoke with debugger
45
-
46
- You can run ruby program on debugger with the local debug console or the remote debug console.
47
-
48
- * (a) Run a ruby program with the local debug console
49
- * (b) Run a ruby program with the remote debug console by opening a network port
50
- * (b-1) Open with UNIX domain socket
51
- * (b-2) Open with TCP/IP port
52
-
53
- (b-1) is useful when you want to use debugging features after running the program.
54
- (b-2) is also useful when you don't have a ssh access for the Ruby process.
55
-
56
- To use debugging feature, you can have 3 ways.
57
-
58
- * (1) Use `rdbg` command
59
- * (2) Use `ruby -r debug...` command line option
60
- * (3) Write `require 'debug...'` in .rb files
61
-
62
- ### Local debug console
63
-
64
- #### (1) Use `rdbg` command
65
-
66
- ```
67
- $ rdbg target.rb
68
- $ rdbg -- -r foo -e expr # -- is required to make clear rdbg options and ruby's options
69
- ```
70
-
71
- #### (2) Use `-r debug/run` command line option
72
-
73
- ```
74
- $ ruby -r debug/run target.rb
75
- ```
76
-
77
- #### (3) Write `require 'debug...'` in .rb files
78
-
79
- ```ruby
80
- # target.rb
81
- require 'debug/run' # start the debug console
82
-
83
- # ... rest of program ...
84
- ```
85
-
38
+ # HOW TO USE
39
+
40
+ To use a debugger, roughly you will do the following steps:
41
+
42
+ 1. Set breakpoints.
43
+ 2. Run a program with the debugger.
44
+ 3. At the breakpoint, enter the debugger console.
45
+ 4. Use debug commands.
46
+ * Query the prgram status (e.g. `p lvar` to see the local variable `lvar`).
47
+ * Control program flow (e.g. move to the another line with `step`, to the next line with `next`).
48
+ * Set another breakpoints (e.g. `catch Exception` to set the breakpoints when `Exception` is raiesd).
49
+ * Change the configuration (e.g. `config set no_color true` to disable coloring).
50
+ * Continue the program (`c` or `continue`) and goto 3.
51
+
52
+ ## Invoke with the debugger
53
+
54
+ There are several options for (1) and (2). Please choose your favorite way.
55
+
56
+ ### Modify source code as `binding.pry` and `binding.irb`
57
+
58
+ If you can modify the source code, you can use the debugger by adding `require 'debug'` line at the top of your program and putting `binding.break` method (`binding.b` for short) into lines where you want to stop as breakpoints like `binding.pry` and `binding.irb`.
59
+ After that, you run the program as usuall and you will enter the debug console at breakpoints you inserted.
60
+
61
+ The following example shows the demonstration of `binding.break`.
62
+
63
+ ```shell
64
+ $ cat target.rb # Sample prgram
65
+ require 'debug'
66
+
67
+ a = 1
68
+ b = 2
69
+ binding.break # Program will stop here
70
+ c = 3
71
+ d = 4
72
+ binding.break # Program will stop here
73
+ p [a, b, c, d]
74
+
75
+ $ ruby target.rb # Run the program normally.
76
+ DEBUGGER: Session start (pid: 7604)
77
+ [1, 10] in target.rb
78
+ 1| require 'debug'
79
+ 2|
80
+ 3| a = 1
81
+ 4| b = 2
82
+ => 5| binding.break # Now you can see it stops at this line
83
+ 6| c = 3
84
+ 7| d = 4
85
+ 8| binding.break
86
+ 9| p [a, b, c, d]
87
+ 10|
88
+ =>#0 <main> at target.rb:5
89
+
90
+ (rdbg) info locals # You can show local variables
91
+ =>#0 <main> at target.rb:5
92
+ %self => main
93
+ a => 1
94
+ b => 2
95
+ c => nil
96
+ d => nil
97
+
98
+ (rdbg) continue # Continue the execution
99
+ [3, 11] in target.rb
100
+ 3| a = 1
101
+ 4| b = 2
102
+ 5| binding.break
103
+ 6| c = 3
104
+ 7| d = 4
105
+ => 8| binding.break # Again the program stops at here
106
+ 9| p [a, b, c, d]
107
+ 10|
108
+ 11| __END__
109
+ =>#0 <main> at target.rb:8
110
+
111
+ (rdbg) info locals # And you can see the updated local variables
112
+ =>#0 <main> at target.rb:8
113
+ %self => main
114
+ a => 1
115
+ b => 2
116
+ c => 3
117
+ d => 4
118
+
119
+ (rdbg) continue
120
+ [1, 2, 3, 4]
121
+ ```
122
+
123
+ ### Invoke the prorgam from the debugger as a traditional debuggers
124
+
125
+ If you don't want to modify the source code, you can set breakpoints with a debug command `break` (`b` for short).
126
+ Using `rdbg` command to launch the program without any modifications, you can run the program with the debugger.
127
+
128
+ ```shell
129
+ $ cat target.rb # Sample prgram
130
+ a = 1
131
+ b = 2
132
+ c = 3
133
+ d = 4
134
+ p [a, b, c, d]
135
+
136
+ $ rdbg target.rb # run like `ruby target.rb`
137
+ DEBUGGER: Session start (pid: 7656)
138
+ [1, 7] in target.rb
139
+ => 1| a = 1
140
+ 2| b = 2
141
+ 3| c = 3
142
+ 4| d = 4
143
+ 5| p [a, b, c, d]
144
+ 6|
145
+ 7| __END__
146
+ =>#0 <main> at target.rb:1
86
147
 
87
- ```
88
- $ ruby target.rb
148
+ (rdbg)
89
149
  ```
90
150
 
91
- When you run the program with the debug console, you will see the debug console prompt `(rdbg)`.
92
- The debuggee program (`target.rb`) is suspended at the beginning of `target.rb`.
93
-
94
-
95
- Alternatively, start the debugger at a specific location in your program using `binding.break` (`binding.b` for short).
96
-
97
- ```ruby
98
- # target.rb
99
- require 'debug' # start the debugger
151
+ `rdbg` command suspends the program at the beginning of the given script (`target.rb` in this case) and you can use debug commands. `(rdbg)` is prompt. Let's set breakpoints on line 3 and line 5 with `break` command (`b` for short).
100
152
 
101
- # ... program ...
153
+ ```shell
154
+ (rdbg) break 3 # set breakpoint at line 3
155
+ #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
102
156
 
103
- binding.break # setup a breakpoint at this line
157
+ (rdbg) b 5 # set breakpoint at line 5
158
+ #1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line)
104
159
 
105
- # ... rest of program ...
160
+ (rdbg) break # show all registered breakpoints
161
+ #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
162
+ #1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line)
106
163
  ```
107
164
 
108
- ```
109
- $ ruby target.rb
110
- ```
165
+ You can see that two breakpoints are registered. Let's continue the program by `continue` command.
111
166
 
112
- You can type any debugger's command described bellow. "c" or "continue" resume the debuggee program.
113
- You can suspend the debuggee program and show the debug console with `Ctrl-C`.
167
+ ```shell
168
+ (rdbg) continue
169
+ [1, 7] in target.rb
170
+ 1| a = 1
171
+ 2| b = 2
172
+ => 3| c = 3
173
+ 4| d = 4
174
+ 5| p [a, b, c, d]
175
+ 6|
176
+ 7| __END__
177
+ =>#0 <main> at target.rb:3
114
178
 
115
- The following example shows simple usage of the debug console. You can show the all variables
179
+ Stop by #0 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:3 (line)
116
180
 
181
+ (rdbg)
117
182
  ```
118
- $ rdbg ~/src/rb/target.rb
119
-
120
- [1, 5] in /home/ko1/src/rb/target.rb
121
- => 1| a = 1
122
- 2| b = 2
123
- 3| c = 3
124
- 4| p [a + b + c]
125
- 5|
126
- --> #0 /home/ko1/src/rb/target.rb:1:in `<main>'
127
-
128
- (rdbg) info # Show all local variables
129
- %self => main
130
- a => nil
131
- b => nil
132
- c => nil
133
183
 
134
- (rdbg) p a # Same as p(a)
135
- => nil
184
+ You can see that we can stop at line 3.
185
+ Let's see the local variables with `info` command, and continue.
186
+ You can also confirm that the program will suspend at line 5 and you can use `info` command again.
136
187
 
137
- (rdbg) s # Step in ("s" is a short name of "step")
188
+ ```shell
189
+ (rdbg) info
190
+ =>#0 <main> at target.rb:3
191
+ %self => main
192
+ a => 1
193
+ b => 2
194
+ c => nil
195
+ d => nil
138
196
 
139
- [1, 5] in /home/ko1/src/rb/target.rb
197
+ (rdbg) continue
198
+ [1, 7] in target.rb
140
199
  1| a = 1
141
- => 2| b = 2
200
+ 2| b = 2
142
201
  3| c = 3
143
- 4| p [a + b + c]
144
- 5|
145
- --> #0 /home/ko1/src/rb/target.rb:2:in `<main>'
146
-
147
- (rdbg) <Enter> # Repeat the last command ("step")
202
+ 4| d = 4
203
+ => 5| p [a, b, c, d]
204
+ 6|
205
+ 7| __END__
206
+ =>#0 <main> at target.rb:5
148
207
 
149
- [1, 5] in /home/ko1/src/rb/target.rb
150
- 1| a = 1
151
- 2| b = 2
152
- => 3| c = 3
153
- 4| p [a + b + c]
154
- 5|
155
- --> #0 /home/ko1/src/rb/target.rb:3:in `<main>'
208
+ Stop by #1 BP - Line /mnt/c/ko1/src/rb/ruby-debug/target.rb:5 (line)
156
209
 
157
- (rdbg) # Repeat the last command ("step")
210
+ (rdbg) info
211
+ =>#0 <main> at target.rb:5
212
+ %self => main
213
+ a => 1
214
+ b => 2
215
+ c => 3
216
+ d => 4
158
217
 
159
- [1, 5] in /home/ko1/src/rb/target.rb
160
- 1| a = 1
161
- 2| b = 2
162
- 3| c = 3
163
- => 4| p [a + b + c]
164
- 5|
165
- --> #0 /home/ko1/src/rb/target.rb:4:in `<main>'
166
-
167
- (rdbg) info # Show all local variables
168
- %self => main
169
- a => 1
170
- b => 2
171
- c => 3
172
-
173
- (rdbg) c # Continue the program ("c" is a short name of "continue")
174
- [6]
218
+ (rdbg) continue
219
+ [1, 2, 3, 4]
175
220
  ```
176
221
 
177
- ### Remote debug (1) UNIX domain socket
222
+ By the way, using `rdbg` command you can suspend your application with `C-c` (SIGINT) and enter the debug console.
223
+ It will help that if you want to know what the program is doing.
178
224
 
179
- #### (1) Use `rdbg` command
225
+ ### Use `rdbg` with commands written in Ruby
180
226
 
181
- ```
182
- $ rdbg --open target.rb # or rdbg -O target.rb for shorthand
183
- Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
184
- ```
227
+ 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.
185
228
 
186
- #### (2) Use `-r debug/open` command line option
229
+ * Without `-c` option, `rdbg <name>` means that `<name>` is Ruby script and invoke it like `ruby <name>` with the debugger.
230
+ * With `-c` option, `rdbg -c <name>` means that `<name>` is command in `PATH` and simply invoke it with the debugger.
187
231
 
188
- ```
189
- $ ruby -r debug/open target.rb
190
- Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
191
- ```
232
+ Examples:
233
+ * `rdbg -c -- rails server`
234
+ * `rdbg -c -- bundle exec ruby foo.rb`
235
+ * `rdbg -c -- bundle exec rake test`
236
+ * `rdbg -c -- ruby target.rb` is same as `rdbg target.rb`
192
237
 
193
- #### (3) Write `require 'debug/open'` in .rb files
238
+ NOTE: `--` is needed to separate the command line options for `rdbg` and invoking command. For example, `rdbg -c rake -T` is recognized like `rdbg -c -T -- rake`. It should be `rdbg -c -- rake -T`.
194
239
 
195
- ```ruby
196
- # target.rb
197
- require 'debug/open' # open the debugger entry point by UNIX domain socket.
240
+ NOTE: If you want to use bundler (`bundle` command), you need to write `gem debug` line in your `Gemfile`.
198
241
 
199
- # or
242
+ ### Using VSCode
200
243
 
201
- require 'debug/server' # introduce remote debugging feature
202
- DEBUGGER__.open # open the debugger entry point by UNIX domain socket.
203
- # or DEBUGGER__.open_unix to specify UNIX domain socket.
204
- ```
244
+ Like other langauges, you can use this debugger on the VSCode.
205
245
 
206
- ```
207
- $ ruby target.rb
208
- Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
209
- ```
246
+ 1. Install [VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg)
247
+ 2. Open `.rb` file (e.g. `target.rb`)
248
+ 3. Register breakpoints with "Toggle breakpoint" in Run menu (or type F9 key)
249
+ 4. Choose "Start debugging" in "Run" menu (or type F5 key)
250
+ 5. You will see a dialog "Debug command line" and you can choose your favorite command line your want to run.
251
+ 6. Chosed command line is invoked with `rdbg -c` and VSCode shows the details at breakponts.
210
252
 
211
- It runs target.rb and accept debugger connection within UNIX domain socket.
212
- The debuggee process waits for debugger connection at the beginning of `target.rb` like that:
253
+ Plase refer [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) for operations on VSCode.
213
254
 
214
- ```
215
- $ rdbg -O ~/src/rb/target.rb
216
- DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-29828)
217
- DEBUGGER: wait for debugger connection...
218
- ```
255
+ You can configure the extension in `.vscode/launch.json`.
256
+ Please see the extension page for more details.
219
257
 
220
- You can attach the program with the following command:
258
+ ## Remote debugging
221
259
 
222
- ```
223
- $ rdbg --attach # or rdbg -A for shorthand
224
-
225
- [1, 4] in /home/ko1/src/rb/target.rb
226
- 1| (1..).each do |i|
227
- => 2| sleep 0.5
228
- 3| p i
229
- 4| end
230
- --> #0 [C] /home/ko1/src/rb/target.rb:2:in `sleep'
231
- #1 /home/ko1/src/rb/target.rb:2:in `block in <main>' {|i=17|}
232
- #2 [C] /home/ko1/src/rb/target.rb:1:in `each'
233
- # and 1 frames (use `bt' command for all frames)
234
-
235
- (rdb)
236
- ```
260
+ You can use this debugger as a remote debugger. For example, it will help the following situations:
237
261
 
238
- and you can input any debug commands. `c` (or `continue`) continues the debuggee process.
262
+ * Your application does not run on TTY and it is hard to use `binding.pry` or `binding.irb`.
263
+ * Your application is running on Docker container and there is no TTY.
264
+ * Your application is running as a daemon.
265
+ * Your application uses pipe for STDIN or STDOUT.
266
+ * Your application is running as a daemon and you want to query the running status (checking a backtrace and so on).
239
267
 
240
- You can detach the debugger from the debugger process with `quit` command.
241
- You can re-connect to the debuggee process by `rdbg -A` command again, and the debuggee process suspends the execution (and debugger can input any debug commands).
268
+ You can run your application as a remote debuggee and the remote debugger console can attach to the debugee anytime.
242
269
 
243
- If you don't want to stop the debuggee process at the beginning of debuggee process (`target.rb`), you can use the following to specify "non-stop" option.
270
+ ### Invoke as a remote debuggee
244
271
 
245
- * Use `rdbg -n` option
246
- * Set the environment variable `RUBY_DEBUG_NONSTOP=1`
272
+ There are two ways to invoke a script as remote debuggee: Use `rdbg --open` and require `debug/open` (or `debug/open_nonstop`).
247
273
 
248
- If you are running multiple debuggee processes, the attach command (`rdbg -A`) shows the options like that:
274
+ #### `rdbg --open` (or `rdbg -O` for short)
249
275
 
250
- ```
251
- $ rdbg --attach
252
- Please select a debug session:
253
- ruby-debug-ko1-19638
254
- ruby-debug-ko1-19603
255
- ```
276
+ You can run a script with `rdbg --open target.rb` command and run a `target.rb` as a debuggee program. It also opens the network port and suspends at the beginning of `target.rb`.
256
277
 
257
- and you need to specify one (copy and paste the name):
258
-
259
- ```
260
- $ rdbg --attach ruby-debug-ko1-19638
278
+ ```shell
279
+ $ exe/rdbg --open target.rb
280
+ DEBUGGER: Session start (pid: 7773)
281
+ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-7773)
282
+ DEBUGGER: wait for debuger connection...
261
283
  ```
262
284
 
263
- The socket file is located at
264
- * `RUBY_DEBUG_SOCK_DIR` environment variable if available.
265
- * `XDG_RUNTIME_DIR` environment variable if available.
266
- * `$HOME/.ruby-debug-sock` if `$HOME` is available.
285
+ By deafult, `rdbg --open` uses UNIX domain socket and generates path name automatically (`/home/ko1/.ruby-debug-sock/ruby-debug-ko1-7773` in this case).
267
286
 
268
- ### Remote debug (2) TCP/IP
287
+ You can connect to the debuggee with `rdbg --attach` command (`rdbg -A` for short).
269
288
 
270
- You can open the TCP/IP port instead of using UNIX domain socket.
271
-
272
- #### (1) Use `rdbg` command
289
+ ```shell
290
+ $ rdbg -A
291
+ [1, 7] in target.rb
292
+ => 1| a = 1
293
+ 2| b = 2
294
+ 3| c = 3
295
+ 4| d = 4
296
+ 5| p [a, b, c, d]
297
+ 6|
298
+ 7| __END__
299
+ =>#0 <main> at target.rb:1
273
300
 
301
+ (rdbg:remote)
274
302
  ```
275
- $ rdbg -O --port=12345 target.rb
276
- # or
277
- $ rdbg --open --port=12345 target.rb
278
- Debugger can attach via TCP/IP (localhost:12345)
279
- ```
280
-
281
- #### (2) Use `-r debug/open` command line option
282
303
 
304
+ 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.
283
305
 
284
- ```
285
- $ RUBY_DEBUG_PORT=12345 ruby -r debug/open target.rb
286
- Debugger can attach via TCP/IP (localhost:12345)
287
- ```
306
+ 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.
288
307
 
289
- #### (3) Write `require 'debug/open'` in .rb files
308
+ 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.
290
309
 
291
- ```ruby
292
- # target.rb
293
- require 'debug/open' # open the debugger entry point.
294
- ```
310
+ 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`.
295
311
 
296
- and run with environment variable RUBY_DEBUG_PORT
312
+ To connect to the debugeee, you need to specify the port.
297
313
 
298
- ```
299
- $ RUBY_DEBUG_PORT=12345 ruby target.rb
300
- Debugger can attach via TCP/IP (localhost:12345)
314
+ ```shell
315
+ $ rdbg --attach 12345
301
316
  ```
302
317
 
303
- or
318
+ If you want to choose the host to bind, you can use `--host` option.
319
+ Note that all messages communicated between the debugger and the debuggee are *NOT* encrypted so please use remote debugging carefully.
304
320
 
305
- ```ruby
306
- # target.rb
307
- require 'debug/server' # introduce remote debugging feature
308
- DEBUGGER__.open(port: 12345)
309
- # or DEBUGGER__.open_tcp(port: 12345)
310
- ```
321
+ #### `require 'debug/open'` in a program
311
322
 
312
- ```
313
- $ ruby target.rb
314
- Debugger can attach via TCP/IP (localhost:12345)
315
- ```
323
+ If you can modify the program, you can open debugging port by adding `require 'debug/open'` line in the program.
316
324
 
317
- You can also specify the host with the `RUBY_DEBUG_HOST` environment variable. And also `DEBUGGER__.open` method accepts a `host:` keyword parameter. If the host is not given, `localhost` will be used.
325
+ If you don't want to stop the program at the beginning, you can also use `require 'debug/open_nonstop'`.
326
+ Using `debug/open_nonstop` is useful if you want to open a backdoor to the application.
327
+ However, it is also danger because it can become antoher vulnerability.
328
+ Please use it carefully.
318
329
 
319
- To attach the debuggee process, specify the port number (and hostname if needed) for the `rdbg --attach` (or `rdbg -A`) command.
330
+ By default, UNIX domain socket is used for the debugging port. To use TCP/IP, you can set the `RUBY_DEBUG_PORT` environment variable.
320
331
 
332
+ ```shell
333
+ $ RUBY_DEBUG_PORT=12345 ruby target.rb
321
334
  ```
322
- $ rdbg --attach 12345
323
- $ rdbg --attach hostname 12345
324
- ```
325
-
326
- ### Initial scripts
327
335
 
328
- If there are `~/.rdbgrc`, the file is loaded as initial scripts which contains debugger commands at the beginning of debug session. `RUBY_DEBUG_INIT_SCRIPT` environment variable can specify the initial script file. You can write configurations in a file. For example, you can set break points with `break file:123` in `~/.rdbgrc`.
336
+ ## Configuration
329
337
 
330
- If there are `~/.rdbgrc.rb` is available, it is loaded as a ruby script at same timing.
338
+ You can configure the debugger's behavior with debug commands and environment variables.
339
+ When the debug session is started, initial scripts are loaded so you can put your favorite configurations in the intial scripts.
331
340
 
332
- ### Configurations
341
+ ### Configuration list
333
342
 
334
- You can configure debugger's setting with environment variables and `config` command.
335
- You can write any configuration into `~/.rdbgrc` like:
343
+ 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.
336
344
 
337
345
  ```
346
+ # configulation example
338
347
  config set log_level INFO
339
348
  config set no_color true
340
349
  ```
341
350
 
342
351
 
352
+
343
353
  * UI
344
354
  * `RUBY_DEBUG_LOG_LEVEL` (`log_level`): Log level same as Logger (default: WARN)
345
355
  * `RUBY_DEBUG_SHOW_SRC_LINES` (`show_src_lines`): Show n lines source code on breakpoint (default: 10 lines)
@@ -356,7 +366,6 @@ config set no_color true
356
366
  * `RUBY_DEBUG_INIT_SCRIPT` (`init_script`): debug command script path loaded at first stop
357
367
  * `RUBY_DEBUG_COMMANDS` (`commands`): debug commands invoked at first stop. commands should be separated by ';;'
358
368
  * `RUBY_DEBUG_NO_RC` (`no_rc`): ignore loading ~/.rdbgrc(.rb)
359
- * `RUBY_DEBUG_HISTORY` (`history`): save and load history file (default: ~/.rdbg_history)
360
369
 
361
370
  * REMOTE
362
371
  * `RUBY_DEBUG_PORT` (`port`): TCP/IP remote debugging: port
@@ -365,8 +374,22 @@ config set no_color true
365
374
  * `RUBY_DEBUG_SOCK_DIR` (`sock_dir`): UNIX Domain Socket remote debugging: socket directory
366
375
  * `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation
367
376
 
377
+ ### Initial scripts
378
+
379
+ If there is `~/.rdbgrc`, the file is loaded as an initial scripts which contains debug commands) when the debug session is started.
380
+
381
+ * `RUBY_DEBUG_INIT_SCRIPT` environment variable can specify the initial script file.
382
+ * You can specify the initial script with `rdbg -x initial_script` (like gdb's `-x` option).
383
+
384
+ Initial scripts are useful to write your favorite configurations.
385
+ For example, you can set break points with `break file:123` in `~/.rdbgrc`.
386
+
387
+ If there are `~/.rdbgrc.rb` is available, it is also loaded as a ruby script at same timing.
388
+
368
389
  ## Debug command on the debug console
369
390
 
391
+ On the debug console, you can use the following debug commands.
392
+
370
393
  * `Enter` repeats the last command (useful when repeating `step`s).
371
394
  * `Ctrl-D` is equal to `quit` command.
372
395
  * [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
@@ -460,8 +483,6 @@ The `<...>` notation means the argument.
460
483
  * Remove all display settings.
461
484
  * `undisplay <displaynum>`
462
485
  * Remove a specified display setting.
463
- * `trace [on|off]`
464
- * enable or disable line tracer.
465
486
 
466
487
  ### Frame control
467
488
 
@@ -513,6 +534,83 @@ The `<...>` notation means the argument.
513
534
  * Show help for the given command.
514
535
 
515
536
 
537
+ ## Debugger API
538
+
539
+ ### Start debugging
540
+
541
+ #### Start by requiring a library
542
+
543
+ You can start debugging without `rdbg` command by requiring the following libraries:
544
+
545
+ * `require 'debug'`: Same as `rdbg --nonstop --no-sigint-hook`.
546
+ * `require 'debug/start'`: Same as `rdbg`.
547
+ * `require 'debug/open'`: Same as `rdbg --open`.
548
+ * `require 'debug/open_nonstop'`: Same as `rdbg --open --nonstop`.
549
+
550
+ You need to require one of them at the very beginning of the application.
551
+ Using `ruby -r` (for example `ruby -r debug/start target.rb`) is another way to invoke with debugger.
552
+
553
+ NOTE: Until Ruby 3.0, there is old `lib/debug.rb` standard library. So that if this gem is not installed, or if `Gemfile` missed to list this gem and `bunde exec` is used, you will see the following output:
554
+
555
+ ```shell
556
+ $ ruby -r debug -e0
557
+ .../2.7.3/lib/ruby/2.7.0/x86_64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
558
+ Debug.rb
559
+ Emacs support available.
560
+
561
+ .../2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162: if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
562
+ (rdb:1)
563
+ ```
564
+
565
+ `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.
566
+
567
+ #### Start by method
568
+
569
+ After loading `debug/session`, you can start debug session with the following methods. They are convinient if you want to specifies debug configrations in your program.
570
+
571
+ * `DEBUGGER__.start(**kw)`: start debug session with local console.
572
+ * `DEBUGGER__.open(**kw)`: open debug port with configuration (without configurations open with UNIX domain socket)
573
+ * `DEBUGGER__.open_unix(**kw)`: open debug port with UNIX domain socket
574
+ * `DEBUGGER__.open_tcp(**kw)`: open debug port with TCP/IP
575
+
576
+ For example:
577
+
578
+ ```ruby
579
+ require 'debug/session'
580
+ DEBUGGER__.start(no_color: true, # disable colorize
581
+ log_level: 'INFO') # Change log_level to INFO
582
+
583
+ ... # your application code
584
+ ```
585
+
586
+ ### `binding.break` method
587
+
588
+ `binding.break` (or `binding.b`) set breakpoints at written line. It also has several keywords.
589
+
590
+ If `do: 'command'` is specified, the debugger suspends the program and run the `command` as a debug command and continue the program.
591
+ It is useful if you only want to call a debug command and don't want to stop there.
592
+
593
+ ```
594
+ def initialzie
595
+ @a = 1
596
+ binding.b do: 'watch @a'
597
+ end
598
+ ```
599
+
600
+ On this case, register a watch breakpont for `@a` and continue to run.
601
+
602
+ If `pre: 'command'` is specified, the debuger suspends the program and run the `command` as a debug command, and keep suspend.
603
+ It is useful if you have operations before suspend.
604
+
605
+ ```
606
+ def foo
607
+ binding.b pre: 'p bar()'
608
+ ...
609
+ end
610
+ ```
611
+
612
+ On this case, you can see the result of `bar()` everytime when you stops there.
613
+
516
614
  ## rdbg command help
517
615
 
518
616
  ```
@@ -524,6 +622,7 @@ Debug console mode:
524
622
  -x, --init-script=FILE Execute debug command in the FILE.
525
623
  --no-rc Ignore ~/.rdbgrc
526
624
  --no-color Disable colorize
625
+ --no-sigint-hook Disable to trap SIGINT
527
626
  -c, --command Enable command mode.
528
627
  The first argument should be a command name in $PATH.
529
628
  Example: 'rdbg -c bundle exec rake test'
@@ -572,6 +671,7 @@ NOTE
572
671
  # Contributing
573
672
 
574
673
  Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
674
+ This debugger is not mature so your feedback will help us.
575
675
 
576
676
  Please also check the [contributing guideline](/CONTRIBUTING.md).
577
677