debug 1.0.0.alpha1 → 1.0.0.beta5

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: c921a03e7629b04e9629e77c5c6dac3adfa4acb33f4f72d325315a358d07058c
4
- data.tar.gz: eac06881f18621e16ac00f7ce628ff64c5aa7b60d99b725cdc30528e4c41b399
3
+ metadata.gz: '039bd2cbfdb3a67bbd91603b077a4f4784235fb0c7b48721a4b9f27b493231c6'
4
+ data.tar.gz: f9605d076dff9d8571e70245baa5c2e97c2377cc7f92ee627cbc1f051361217b
5
5
  SHA512:
6
- metadata.gz: 299218c5bbfa513df144365e8172ae270a681b3e8e0ab6b7953834d99454947c1a31ce2f6f9aa85b3ae798ac501ea8e4f8892deabf96ca835cb35112fd26a54b
7
- data.tar.gz: cac005fa02d12e187f586b2718d27d0c1463d03219a050102c9767540692cd609666cd6ea65db83a3bda54471c4a5ff10f06e1305b8ec013d5735b2633a2eebe
6
+ metadata.gz: f222a8b1ec58fd6f5264e61ee8613e6ed229c9ebff73c6b4904c4c6c2bded0d625b776fb510b23dec57636cf576a68d471f0b91d7b01d36f8baad741ff64fd38
7
+ data.tar.gz: 152431ba38203334bbf1c7449ff36a6d49f5116aaa78c017ca5ffa6d695ca87be06bc011822d0bbd325e15c46504385adf4ef94e74ebd37f97468f049da910e8
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0', 'head', 'debug']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: Run tests
34
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -6,3 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.bundle
10
+ /Gemfile.lock
11
+ /lib/debug/debug.so
12
+ .ruby-version
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,145 @@
1
+ ## Set Up a Development Environment
2
+
3
+ 1. `$ git clone git@github.com:ruby/debug.git`
4
+ 2. `$ bundle install`
5
+ 3. `$ rake` - this will
6
+ - Compile the C extension locally (which can also be done solely with `rake compile`).
7
+ - Run tests.
8
+ - Re-generate `README.md`.
9
+
10
+ If you spot any problem, please open an issue.
11
+
12
+ ## Run Tests
13
+
14
+ ### Run all tests
15
+
16
+ ```bash
17
+ $ rake test
18
+ # or
19
+ $ ruby bin/test-unit.rb
20
+ ```
21
+
22
+ ### Run specific test(s)
23
+
24
+
25
+ ```bash
26
+ $ ruby test/debug/bp_test.rb # run all tests in the specified file
27
+ $ ruby test/debug/bp_test.rb -h # to see all the test options
28
+ ```
29
+
30
+ ## To Update README
31
+
32
+ This project generates `README.md` from the template `misc/README.md.erb`
33
+
34
+ So **do not** directly update `README.md`. Instead, you should update the template's source and run
35
+
36
+ ```bash
37
+ $ rake
38
+ ```
39
+
40
+ to reflect the changes on `README.md`.
41
+
42
+
43
+ ### When to re-generate `README.md`
44
+
45
+ - After updating `misc/README.md.erb`.
46
+ - After updating `rdbg` executable's options.
47
+ - After updating comments of debugger's commands.
48
+
49
+ ## Manually Test Your Changes
50
+
51
+ You can manually test your changes with a simple Ruby script + a line of command. The following example will help you check:
52
+
53
+ - Breakpoint insertion.
54
+ - Resume from the breakpoint.
55
+ - Backtrace display.
56
+ - Information (local variables, ivars..etc.) display.
57
+ - Debugger exit.
58
+
59
+
60
+ ### Script
61
+
62
+ ```ruby
63
+ # target.rb
64
+ class Foo
65
+ def first_call
66
+ second_call(20)
67
+ end
68
+
69
+ def second_call(num)
70
+ third_call_with_block do |ten|
71
+ forth_call(num, ten)
72
+ end
73
+ end
74
+
75
+ def third_call_with_block(&block)
76
+ @ivar1 = 10; @ivar2 = 20
77
+
78
+ yield(10)
79
+ end
80
+
81
+ def forth_call(num1, num2)
82
+ num1 + num2
83
+ end
84
+ end
85
+
86
+ Foo.new.first_call
87
+ ```
88
+
89
+ ### Command
90
+
91
+ ```
92
+ $ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb
93
+ ```
94
+
95
+ ### Expect Result
96
+
97
+ ```
98
+ ❯ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb
99
+ [1, 10] in target.rb
100
+ => 1| class Foo
101
+ 2| def first_call
102
+ 3| second_call(20)
103
+ 4| end
104
+ 5|
105
+ 6| def second_call(num)
106
+ 7| third_call_with_block do |ten|
107
+ 8| forth_call(num, ten)
108
+ 9| end
109
+ 10| end
110
+ =>#0 <main> at target.rb:1
111
+ (rdbg:init) b 20
112
+ #1 line bp /PATH_TO_PROJECT/debug/target.rb:20 (return)
113
+ (rdbg:init) c
114
+ [15, 23] in target.rb
115
+ 15| yield(10)
116
+ 16| end
117
+ 17|
118
+ 18| def forth_call(num1, num2)
119
+ 19| num1 + num2
120
+ => 20| end
121
+ 21| end
122
+ 22|
123
+ 23| Foo.new.first_call
124
+ =>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
125
+ #1 block{|ten=10|} in second_call at target.rb:8
126
+ # and 4 frames (use `bt' command for all frames)
127
+
128
+ Stop by #1 line bp /PATH_TO_PROJECT/debug/target.rb:20 (return)
129
+ (rdbg:init) bt
130
+ =>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
131
+ #1 block{|ten=10|} in second_call at target.rb:8
132
+ #2 Foo#third_call_with_block(block=#<Proc:0x00007f8bc32f0c28 target.rb:7>) at target.rb:15
133
+ #3 Foo#second_call(num=20) at target.rb:7
134
+ #4 first_call at target.rb:3
135
+ #5 <main> at target.rb:23
136
+ (rdbg:init) info
137
+ =>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
138
+ %self => #<Foo:0x00007f8bc32f0ed0>
139
+ %return => 30
140
+ num1 => 20
141
+ num2 => 10
142
+ @ivar1 => 10
143
+ @ivar2 => 20
144
+ (rdbg:init) q!
145
+ ```
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "rake-compiler"
7
+ gem "test-unit", "~> 3.0"
data/LICENSE.txt CHANGED
@@ -1,21 +1,22 @@
1
- The MIT License (MIT)
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
2
 
3
- Copyright (c) 2021 Koichi Sasada
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
4
11
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/README.md CHANGED
@@ -1,86 +1,335 @@
1
+ [![Ruby](https://github.com/ruby/debug/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/ruby/debug/actions/workflows/ruby.yml?query=branch%3Amaster)
2
+
1
3
  # debug.rb
2
4
 
3
- ## How to install
5
+ This library provides debugging functionality to Ruby.
6
+
7
+ This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by `set_trace_func`.
8
+ New debug.rb has several advantages:
9
+
10
+ * Fast: No performance penalty on non-stepping mode and non-breakpoints.
11
+ * Remote debugging: Support remote debugging natively.
12
+ * UNIX domain socket
13
+ * TCP/IP
14
+ * VSCode/DAP integration (TODO)
15
+ * Extensible: application can introduce debugging support with several methods
16
+ * By `rdbg` command
17
+ * By loading libraries with `-r` command line option
18
+ * By calling Ruby's method explicitly
19
+ * Misc
20
+ * Support threads (almost done) and ractors (TODO).
21
+ * Support suspending and entering to the console debugging with `Ctrl-C` at most of timing.
22
+ * Show parameters on backtrace command.
23
+
24
+ # Installation
4
25
 
5
26
  ```
6
- $ gem install debug
27
+ $ gem install debug --pre
7
28
  ```
8
29
 
9
- or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line options for development.
30
+ or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
10
31
 
11
32
  # How to use
12
33
 
13
34
  ## Invoke with debugger
14
35
 
15
- ### REPL debug
36
+ You can run ruby program on debugger with the local debug console or the remote debug console.
37
+
38
+ * (a) Run a ruby program with the local debug console
39
+ * (b) Run a ruby program with the remote debug console by opening a network port
40
+ * (b-1) Open with UNIX domain socket
41
+ * (b-2) Open with TCP/IP port
42
+
43
+ (b-1) is useful when you want to use debugging features after running the program.
44
+ (b-2) is also useful when you don't have a ssh access for the Ruby process.
45
+
46
+ To use debugging feature, you can have 3 ways.
47
+
48
+ * (1) Use `rdbg` command
49
+ * (2) Use `ruby -r debug...` command line option
50
+ * (3) Write `require 'debug...'` in .rb files
51
+
52
+ ### Local debug console
53
+
54
+ #### (1) Use `rdbg` command
16
55
 
17
56
  ```
18
- $ ruby -r debug/repl target.rb
57
+ $ rdbg target.rb
58
+ $ rdbg -- -r foo -e expr # -- is required to make clear rdbg options and ruby's options
19
59
  ```
20
60
 
21
- and you can see the debugger prompt. The program was suspended at the beggining of target.rb. To continue the program, type `c` (or `continue`). See other debug commands below.
61
+ #### (2) Use `-r debug/run` command line option
62
+
63
+ ```
64
+ $ ruby -r debug/run target.rb
65
+ ```
66
+
67
+ #### (3) Write `require 'debug...'` in .rb files
68
+
69
+ ```ruby
70
+ # target.rb
71
+ require 'debug/run' # start the debug console
22
72
 
23
- You can re-enable debug command mode by `Ctrl-C`.
73
+ # or
74
+
75
+ require 'debug/session' # introduce the functionality
76
+ DEBUGGER__.console # and start the debug console
77
+ # ... rest of program ...
78
+ ```
79
+
80
+ ```
81
+ $ ruby target.rb
82
+ ```
83
+
84
+ When you run the program with the debug console, you will see the debug console prompt `(rdbg)`.
85
+ The debuggee program (`target.rb`) is suspended at the beginning of `target.rb`.
86
+
87
+ You can type any debugger's command described bellow. "c" or "continue" resume the debuggee program.
88
+ You can suspend the debuggee program and show the debug console with `Ctrl-C`.
89
+
90
+ The following example shows simple usage of the debug console. You can show the all variables
91
+
92
+ ```
93
+ $ rdbg ~/src/rb/target.rb
94
+
95
+ [1, 5] in /home/ko1/src/rb/target.rb
96
+ => 1| a = 1
97
+ 2| b = 2
98
+ 3| c = 3
99
+ 4| p [a + b + c]
100
+ 5|
101
+ --> #0 /home/ko1/src/rb/target.rb:1:in `<main>'
102
+
103
+ (rdbg) info # Show all local variables
104
+ %self => main
105
+ a => nil
106
+ b => nil
107
+ c => nil
108
+
109
+ (rdbg) p a # Same as p(a)
110
+ => nil
111
+
112
+ (rdbg) s # Step in ("s" is a short name of "step")
113
+
114
+ [1, 5] in /home/ko1/src/rb/target.rb
115
+ 1| a = 1
116
+ => 2| b = 2
117
+ 3| c = 3
118
+ 4| p [a + b + c]
119
+ 5|
120
+ --> #0 /home/ko1/src/rb/target.rb:2:in `<main>'
121
+
122
+ (rdbg) <Enter> # Repeat the last command ("step")
123
+
124
+ [1, 5] in /home/ko1/src/rb/target.rb
125
+ 1| a = 1
126
+ 2| b = 2
127
+ => 3| c = 3
128
+ 4| p [a + b + c]
129
+ 5|
130
+ --> #0 /home/ko1/src/rb/target.rb:3:in `<main>'
131
+
132
+ (rdbg) # Repeat the last command ("step")
133
+
134
+ [1, 5] in /home/ko1/src/rb/target.rb
135
+ 1| a = 1
136
+ 2| b = 2
137
+ 3| c = 3
138
+ => 4| p [a + b + c]
139
+ 5|
140
+ --> #0 /home/ko1/src/rb/target.rb:4:in `<main>'
141
+
142
+ (rdbg) info # Show all local variables
143
+ %self => main
144
+ a => 1
145
+ b => 2
146
+ c => 3
147
+
148
+ (rdbg) c # Continue the program ("c" is a short name of "continue")
149
+ [6]
150
+ ```
24
151
 
25
152
  ### Remote debug (1) UNIX domain socket
26
153
 
154
+ #### (1) Use `rdbg` command
155
+
156
+ ```
157
+ $ rdbg --open target.rb # or rdbg -O target.rb for shorthand
158
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
159
+ ```
160
+
161
+ #### (2) Use `-r debug/open` command line option
162
+
27
163
  ```
28
- $ ruby -r debug/unixserver target.rb
164
+ $ ruby -r debug/open target.rb
165
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
166
+ ```
167
+
168
+ #### (3) Write `require 'debug/open'` in .rb files
169
+
170
+ ```ruby
171
+ # target.rb
172
+ require 'debug/open' # open the debugger entry point by UNIX domain socket.
173
+
174
+ # or
175
+
176
+ require 'debug/server' # introduce remote debugging feature
177
+ DEBUGGER__.open # open the debugger entry point by UNIX domain socket.
178
+ # or DEBUGGER__.open_unix to specify UNIX domain socket.
179
+ ```
180
+
181
+ ```
182
+ $ ruby target.rb
183
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
29
184
  ```
30
185
 
31
186
  It runs target.rb and accept debugger connection within UNIX domain socket.
187
+ The debuggee process waits for debugger connection at the beginning of `target.rb` like that:
32
188
 
33
- You can attach the program with the folliowing command:
189
+ ```
190
+ $ rdbg -O ~/src/rb/target.rb
191
+ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-29828)
192
+ DEBUGGER: wait for debugger connection...
193
+ ```
194
+
195
+ You can attach the program with the following command:
34
196
 
35
197
  ```
36
- $ ruby -r debug/client -e connect
37
- Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-20642)
38
- ...
198
+ $ rdbg --attach # or rdbg -A for shorthand
199
+
200
+ [1, 4] in /home/ko1/src/rb/target.rb
201
+ 1| (1..).each do |i|
202
+ => 2| sleep 0.5
203
+ 3| p i
204
+ 4| end
205
+ --> #0 [C] /home/ko1/src/rb/target.rb:2:in `sleep'
206
+ #1 /home/ko1/src/rb/target.rb:2:in `block in <main>' {|i=17|}
207
+ #2 [C] /home/ko1/src/rb/target.rb:1:in `each'
208
+ # and 1 frames (use `bt' command for all frames)
209
+
210
+ (rdb)
39
211
  ```
40
212
 
41
- The debugee process will be suspended and wait for the debug command.
213
+ and you can input any debug commands. `c` (or `continue`) continues the debuggee process.
214
+
215
+ You can detach the debugger from the debugger process with `quit` command.
216
+ 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).
217
+
218
+ 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.
42
219
 
43
- If you are running multiple debuggee processes, this command shows the selection like that:
220
+ * Use `rdbg -n` option
221
+ * Set the environment variable `RUBY_DEBUG_NONSTOP=1`
222
+
223
+ If you are running multiple debuggee processes, the attach command (`rdbg -A`) shows the options like that:
44
224
 
45
225
  ```
46
- $ ruby -r debug/client -e connect
226
+ $ rdbg --attach
47
227
  Please select a debug session:
48
228
  ruby-debug-ko1-19638
49
229
  ruby-debug-ko1-19603
50
230
  ```
51
231
 
52
- and you need to specify one:
232
+ and you need to specify one (copy and paste the name):
53
233
 
54
234
  ```
55
- $ ruby -r debug/client -e connect ruby-debug-ko1-19638
235
+ $ rdbg --attach ruby-debug-ko1-19638
56
236
  ```
57
237
 
58
238
  The socket file is located at
59
239
  * `RUBY_DEBUG_SOCK_DIR` environment variable if available.
60
240
  * `XDG_RUNTIME_DIR` environment variable if available.
61
- * `$HOME/ruby-debug-sock` if `$HOME` is available.
241
+ * `$HOME/.ruby-debug-sock` if `$HOME` is available.
62
242
 
63
243
  ### Remote debug (2) TCP/IP
64
244
 
245
+ You can open the TCP/IP port instead of using UNIX domain socket.
246
+
247
+ #### (1) Use `rdbg` command
248
+
65
249
  ```
66
- $ RUBY_DEBUG_PORT=12345 RUBY_DEBUG_HOST=localhost ruby -r debug/tcpserver target.rb
250
+ $ rdbg -O --port=12345 target.rb
251
+ # or
252
+ $ rdbg --open --port=12345 target.rb
67
253
  Debugger can attach via TCP/IP (localhost:12345)
68
- ...
69
254
  ```
70
255
 
71
- This command invoke target.rb with TCP/IP attach server with given port and host. If host is not given, `localhost` will be used.
256
+ #### (2) Use `-r debug/open` command line option
257
+
72
258
 
73
259
  ```
74
- $ ruby -r debug/client -e connect localhost 12345
260
+ $ RUBY_DEBUG_PORT=12345 ruby -r debug/open target.rb
261
+ Debugger can attach via TCP/IP (localhost:12345)
262
+ ```
263
+
264
+ #### (3) Write `require 'debug/open'` in .rb files
265
+
266
+ ```ruby
267
+ # target.rb
268
+ require 'debug/open' # open the debugger entry point.
75
269
  ```
76
270
 
77
- tries to connect with given host (`localhost`) and port (`12345`). You can eliminate host part and `localhost` will be used.
271
+ and run with environment variable RUBY_DEBUG_PORT
78
272
 
273
+ ```
274
+ $ RUBY_DEBUG_PORT=12345 ruby target.rb
275
+ Debugger can attach via TCP/IP (localhost:12345)
276
+ ```
79
277
 
80
- ## Debug command
278
+ or
279
+
280
+ ```ruby
281
+ # target.rb
282
+ require 'debug/server' # introduce remote debugging feature
283
+ DEBUGGER__.open(port: 12345)
284
+ # or DEBUGGER__.open_tcp(port: 12345)
285
+ ```
286
+
287
+ ```
288
+ $ ruby target.rb
289
+ Debugger can attach via TCP/IP (localhost:12345)
290
+ ```
291
+
292
+ 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.
293
+
294
+ To attach the debuggee process, specify the port number (and hostname if needed) for the `rdbg --attach` (or `rdbg -A`) command.
295
+
296
+ ```
297
+ $ rdbg --attach 12345
298
+ $ rdbg --attach hostname 12345
299
+ ```
300
+
301
+ ### Initial scripts
302
+
303
+ If there are `.rdbgrc` files are there at the current directory and the home directory, files are loaded as initial scripts which contains debugger commands. `RUBY_DEBUG_INIT_SCRIPT` environment variable can specify the initial script file.
304
+
305
+ Initial scripts are evaluated at the first suspend timing (generally, it is the beginning of the target script). For example, you can set break points with `break file:123`.
306
+
307
+ If there are `.rdbgrc.rb` files at the current directory and the home directory, files are loaded as a ruby script at the initializing timing.
308
+
309
+ ### Environment variables
310
+
311
+ You can control debuggee's behavior with environment variables:
312
+
313
+ * `RUBY_DEBUG_NONSTOP`: 1 for nonstop at the beginning of program.
314
+ * `RUBY_DEBUG_INIT_SCRIPT`: Initial script path loaded at the first stop.
315
+ * `RUBY_DEBUG_COMMANDS`: Debug commands invoked at the first stop. Commands should be separated by ';;'.
316
+ * `RUBY_DEBUG_SHOW_SRC_LINES`: Show n lines source code on breakpoint (default: 10 lines).
317
+ * `RUBY_DEBUG_SHOW_FRAMES`: Show n frames on breakpoint (default: 2 frames).
318
+ * Remote debugging
319
+ * `RUBY_DEBUG_PORT`: TCP/IP remote debugging: port to open.
320
+ * `RUBY_DEBUG_HOST`: TCP/IP remote debugging: host (localhost if not given) to open.
321
+ * `RUBY_DEBUG_SOCK_PATH`: UNIX Domain Socket remote debugging: socket path to open.
322
+ * `RUBY_DEBUG_SOCK_DIR`: UNIX Domain Socket remote debugging: socket directory to open.
323
+
324
+ ## Debug command on the debug console
81
325
 
82
326
  * `Enter` repeats the last command (useful when repeating `step`s).
83
327
  * `Ctrl-D` is equal to `quit` command.
328
+ * [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
329
+
330
+ You can use the following debug commands. Each command should be written in 1 line.
331
+ The `[...]` notation means this part can be eliminate. For example, `s[tep]` means `s` or `step` are valid command. `ste` is not valid.
332
+ The `<...>` notation means the argument.
84
333
 
85
334
  ### Control flow
86
335
 
@@ -93,9 +342,13 @@ tries to connect with given host (`localhost`) and port (`12345`). You can elimi
93
342
  * `c[ontinue]`
94
343
  * Resume the program.
95
344
  * `q[uit]` or `Ctrl-D`
96
- * Finish debugger (with a process, if not remote debugging).
345
+ * Finish debugger (with the debuggee process on non-remote debugging).
346
+ * `q[uit]!`
347
+ * Same as q[uit] but without the confirmation prompt.
97
348
  * `kill`
98
- * Stop the debuggee program.
349
+ * Stop the debuggee process with `Kernal#exit!`.
350
+ * `kill!`
351
+ * Same as kill but without the confirmation prompt.
99
352
 
100
353
  ### Breakpoint
101
354
 
@@ -103,27 +356,69 @@ tries to connect with given host (`localhost`) and port (`12345`). You can elimi
103
356
  * Show all breakpoints.
104
357
  * `b[reak] <line>`
105
358
  * Set breakpoint on `<line>` at the current frame's file.
106
- * `b[reak] <file>:<line>`
359
+ * `b[reak] <file>:<line>` or `<file> <line>`
107
360
  * Set breakpoint on `<file>:<line>`.
361
+ * `b[reak] <class>#<name>`
362
+ * Set breakpoint on the method `<class>#<name>`.
363
+ * `b[reak] <expr>.<name>`
364
+ * Set breakpoint on the method `<expr>.<name>`.
365
+ * `b[reak] ... if <expr>`
366
+ * break if `<expr>` is true at specified location.
367
+ * `b[reak] if <expr>`
368
+ * break if `<expr>` is true at any lines.
369
+ * Note that this feature is super slow.
108
370
  * `catch <Error>`
109
371
  * Set breakpoint on raising `<Error>`.
372
+ * `watch @ivar`
373
+ * Stop the execution when the result of current scope's `@ivar` is changed.
374
+ * Note that this feature is super slow.
110
375
  * `del[ete]`
111
376
  * delete all breakpoints.
112
377
  * `del[ete] <bpnum>`
113
378
  * delete specified breakpoint.
114
379
 
115
- ### Frame control
380
+ ### Information
116
381
 
117
382
  * `bt` or `backtrace`
118
- * Show backtrace information.
383
+ * Show backtrace (frame) information.
384
+ * `l[ist]`
385
+ * Show current frame's source code.
386
+ * Next `list` command shows the successor lines.
387
+ * `l[ist] -`
388
+ * Show predecessor lines as opposed to the `list` command.
389
+ * `l[ist] <start>` or `l[ist] <start>-<end>`
390
+ * Show current frame's source code from the line <start> to <end> if given.
391
+ * `edit`
392
+ * Open the current file on the editor (use `EDITOR` environment variable).
393
+ * Note that edited file will not be reloaded.
394
+ * `edit <file>`
395
+ * Open <file> on the editor.
396
+ * `i[nfo]`, `i[nfo] l[ocal[s]]`
397
+ * Show information about the current frame (local variables)
398
+ * It includes `self` as `%self` and a return value as `%return`.
399
+ * `i[nfo] th[read[s]]`
400
+ * Show all threads (same as `th[read]`).
401
+ * `display`
402
+ * Show display setting.
403
+ * `display <expr>`
404
+ * Show the result of `<expr>` at every suspended timing.
405
+ * `undisplay`
406
+ * Remove all display settings.
407
+ * `undisplay <displaynum>`
408
+ * Remove a specified display setting.
409
+ * `trace [on|off]`
410
+ * enable or disable line tracer.
411
+
412
+ ### Frame control
413
+
119
414
  * `f[rame]`
120
- * Show current frame.
415
+ * Show the current frame.
121
416
  * `f[rame] <framenum>`
122
- * Specify frame. Evaluation are run on this frame environement.
417
+ * Specify a current frame. Evaluation are run on specified frame.
123
418
  * `up`
124
- * Specify upper frame.
419
+ * Specify the upper frame.
125
420
  * `down`
126
- * Specify down frame.
421
+ * Specify the lower frame.
127
422
 
128
423
  ### Evaluate
129
424
 
@@ -133,30 +428,79 @@ tries to connect with given host (`localhost`) and port (`12345`). You can elimi
133
428
  * Evaluate like `pp <expr>` on the current frame.
134
429
  * `e[val] <expr>`
135
430
  * Evaluate `<expr>` on the current frame.
136
-
137
- ### Information
138
-
139
- * `list`
140
- * Show current frame's source code.
141
- * `info l[ocal[s]]`
142
- * Show current frame's local variables. It includes `self` as `%self` and a return value as `%return`.
143
- * `info i[nstance]` or `info ivars`
144
- * Show current frame's insntance variables.
145
- * `display`
146
- * Show display setting.
147
- * `display <expr>`
148
- * Add `<expr>` at suspended timing.
149
- * `undisplay`
150
- * Remove all display settings.
151
- * `undisplay <displaynum>`
152
- * Remove a specified display setting.
153
- * `trace [on|off]`
154
- * enable or disable line tracer.
431
+ * `irb`
432
+ * Invoke `irb` on the current frame.
155
433
 
156
434
  ### Thread control
157
435
 
158
- * `th[read] [l[ist]]`
436
+ * `th[read]`
159
437
  * Show all threads.
160
438
  * `th[read] <thnum>`
161
- * Switch thread specified by `<thnum>`
439
+ * Switch thread specified by `<thnum>`.
440
+
441
+ ### Help
442
+
443
+ * `h[elp]`
444
+ * Show help for all commands.
445
+ * `h[elp] <command>`
446
+ * Show help for the given command.
447
+
448
+
449
+ ## rdbg command help
450
+
451
+ ```
452
+ exe/rdbg [options] -- [debuggee options]
453
+
454
+ Debug console mode:
455
+ -n, --nonstop Do not stop at the beginning of the script.
456
+ -e COMMAND execute debug command at the beginning of the script.
457
+ -x, --init-script=FILE execute debug command in the FILE.
458
+
459
+ -O, --open Start remote debugging with opening the network port.
460
+ If TCP/IP options are not given,
461
+ a UNIX domain socket will be used.
462
+ --sock-path=SOCK_PATH UNIX Doman socket path
463
+ --port=PORT Listening TCP/IP port
464
+ --host=HOST Listening TCP/IP host
465
+ --cookie=COOKIE Set a cookie for connection
466
+
467
+ Debug console mode runs Ruby program with the debug console.
468
+
469
+ 'rdbg target.rb foo bar' starts like 'ruby target.rb foo bar'.
470
+ 'rdbg -- -r foo -e bar' starts like 'ruby -r foo -e bar'.
471
+ 'rdbg -O target.rb foo bar' starts and accepts attaching with UNIX domain socket.
472
+ 'rdbg -O --port 1234 target.rb foo bar' starts accepts attaching with TCP/IP localhost:1234.
473
+ 'rdbg -O --port 1234 -- -r foo -e bar' starts accepts attaching with TCP/IP localhost:1234.
474
+
475
+ Attach mode:
476
+ -A, --attach Attach to debuggee process.
477
+
478
+ Attach mode attaches the remote debug console to the debuggee process.
479
+
480
+ 'rdbg -A' tries to connect via UNIX domain socket.
481
+ If there are multiple processes are waiting for the
482
+ debugger connection, list possible debuggee names.
483
+ 'rdbg -A path' tries to connect via UNIX domain socket with given path name.
484
+ 'rdbg -A port' tries to connect to localhost:port via TCP/IP.
485
+ 'rdbg -A host port' tries to connect to host:port via TCP/IP.
486
+
487
+ Other options:
488
+ -h, --help Print help
489
+ -c, --command Command mode (first argument is command name)
490
+ --util=NAME Utility mode (used by tools)
491
+
492
+ NOTE
493
+ All messages communicated between a debugger and a debuggee are *NOT* encrypted.
494
+ Please use the remote debugging feature carefully.
495
+
496
+ ```
497
+
498
+ # Contributing
499
+
500
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
501
+
502
+ Please also check the [contributing guideline](/CONTRIBUTING.md).
503
+
504
+ # Acknowledgement
162
505
 
506
+ * Some tests are based on [deivid-rodriguez/byebug: Debugging in Ruby 2](https://github.com/deivid-rodriguez/byebug)