debug 1.0.0.beta1 → 1.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +3 -0
- data/CONTRIBUTING.md +336 -0
- data/Gemfile +2 -2
- data/README.md +121 -71
- data/TODO.md +33 -0
- data/bin/gentest +22 -0
- data/debug.gemspec +2 -0
- data/exe/rdbg +14 -11
- data/ext/debug/debug.c +10 -9
- data/ext/debug/extconf.rb +1 -1
- data/lib/debug.rb +4 -1
- data/lib/debug/breakpoint.rb +93 -28
- data/lib/debug/client.rb +54 -13
- data/lib/debug/color.rb +72 -0
- data/lib/debug/config.rb +105 -24
- data/lib/debug/console.rb +21 -1
- data/lib/debug/frame_info.rb +145 -0
- data/lib/debug/open.rb +3 -0
- data/lib/debug/run.rb +4 -1
- data/lib/debug/server.rb +103 -50
- data/lib/debug/server_dap.rb +607 -0
- data/lib/debug/session.rb +377 -150
- data/lib/debug/source_repository.rb +64 -12
- data/lib/debug/thread_client.rb +160 -112
- data/lib/debug/version.rb +3 -1
- data/misc/README.md.erb +73 -44
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fffc4898e989a76e77a9076407cc1ba6d31b13a531e739c8972afe71bf049285
|
4
|
+
data.tar.gz: 190c18099e1078e00786dde75819b0b793647cd9508b0577e88d93d6a06c045c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 647e6c227bded49c962b8d6934557a26930664f5f1ddd57fd596c6651b1c655c1c77e64d5cbba28d2125cdd8a27817e33dc94d465d01f6b43b7f0be61ee30a35
|
7
|
+
data.tar.gz: ceb4dbf7b9479dc54ff5af725e973985493650ca9aaebd16878c4669fa037ae2ee1ec9ddddf83eb25dd65dc2057d0419a74005ec5d74c98585d855eb918e53bb
|
@@ -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
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,336 @@
|
|
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
|
+
```
|
19
|
+
|
20
|
+
### Run specific test(s)
|
21
|
+
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ ruby test/debug/bp_test.rb # run all tests in the specified file
|
25
|
+
$ ruby test/debug/bp_test.rb -h # to see all the test options
|
26
|
+
```
|
27
|
+
|
28
|
+
## Generate Tests
|
29
|
+
There is a test generator in `debug.rb` project to make it easier to write tests.
|
30
|
+
### Quickstart
|
31
|
+
This section shows you how to create test file by test generator. For more advanced informations on creating tests, please take a look at [gentest options](#gentest-options). (You can also check by `$bin/gentest -h`)
|
32
|
+
#### 1. Create a target file for debuggee.
|
33
|
+
Let's say, we created `target.rb` which is located in top level directory of debugger.
|
34
|
+
```ruby
|
35
|
+
module Foo
|
36
|
+
class Bar
|
37
|
+
def self.a
|
38
|
+
"hello"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Bar.a
|
42
|
+
bar = Bar.new
|
43
|
+
end
|
44
|
+
```
|
45
|
+
#### 2. Run `gentest` as shown in the example below.
|
46
|
+
```shell
|
47
|
+
$ bin/gentest target.rb
|
48
|
+
```
|
49
|
+
#### 3. Debugger will be executed. You can type any debug commands.
|
50
|
+
```shell
|
51
|
+
$ bin/gentest target.rb
|
52
|
+
[1, 9] in ~/workspace/debug/target.rb
|
53
|
+
=> 1| module Foo
|
54
|
+
2| class Bar
|
55
|
+
3| def self.a
|
56
|
+
4| "hello"
|
57
|
+
5| end
|
58
|
+
6| end
|
59
|
+
7| Bar.a
|
60
|
+
8| bar = Bar.new
|
61
|
+
9| end
|
62
|
+
=>#0 <main> at ~/workspace/debug/target.rb:1
|
63
|
+
INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:1","line":1}
|
64
|
+
|
65
|
+
(rdbg)s
|
66
|
+
s
|
67
|
+
[1, 9] in ~/workspace/debug/target.rb
|
68
|
+
1| module Foo
|
69
|
+
=> 2| class Bar
|
70
|
+
3| def self.a
|
71
|
+
4| "hello"
|
72
|
+
5| end
|
73
|
+
6| end
|
74
|
+
7| Bar.a
|
75
|
+
8| bar = Bar.new
|
76
|
+
9| end
|
77
|
+
=>#0 <module:Foo> at ~/workspace/debug/target.rb:2
|
78
|
+
#1 <main> at ~/workspace/debug/target.rb:1
|
79
|
+
INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:2","line":2}
|
80
|
+
|
81
|
+
(rdbg)n
|
82
|
+
n
|
83
|
+
[1, 9] in ~/workspace/debug/target.rb
|
84
|
+
1| module Foo
|
85
|
+
2| class Bar
|
86
|
+
=> 3| def self.a
|
87
|
+
4| "hello"
|
88
|
+
5| end
|
89
|
+
6| end
|
90
|
+
7| Bar.a
|
91
|
+
8| bar = Bar.new
|
92
|
+
9| end
|
93
|
+
=>#0 <class:Bar> at ~/workspace/debug/target.rb:3
|
94
|
+
#1 <module:Foo> at ~/workspace/debug/target.rb:2
|
95
|
+
#2 <main> at ~/workspace/debug/target.rb:1
|
96
|
+
INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:3","line":3}
|
97
|
+
|
98
|
+
(rdbg)b 7
|
99
|
+
b 7
|
100
|
+
INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:3","line":3}
|
101
|
+
|
102
|
+
(rdbg)c
|
103
|
+
c
|
104
|
+
[2, 9] in ~/workspace/debug/target.rb
|
105
|
+
2| class Bar
|
106
|
+
3| def self.a
|
107
|
+
4| "hello"
|
108
|
+
5| end
|
109
|
+
6| end
|
110
|
+
=> 7| Bar.a
|
111
|
+
8| bar = Bar.new
|
112
|
+
9| end
|
113
|
+
=>#0 <module:Foo> at ~/workspace/debug/target.rb:7
|
114
|
+
#1 <main> at ~/workspace/debug/target.rb:1
|
115
|
+
|
116
|
+
Stop by #0 BP - Line /Users/naotto/workspace/debug/target.rb:7 (line)
|
117
|
+
INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:7","line":7}
|
118
|
+
|
119
|
+
(rdbg)q!
|
120
|
+
q!
|
121
|
+
```
|
122
|
+
#### 4. The test file will be created as `test/debug/foo_test.rb`.
|
123
|
+
If the file already exists, **only method** will be added to it.
|
124
|
+
```ruby
|
125
|
+
# frozen_string_literal: true
|
126
|
+
|
127
|
+
require_relative '../support/test_case'
|
128
|
+
|
129
|
+
module DEBUGGER__
|
130
|
+
class FooTest < TestCase
|
131
|
+
def program
|
132
|
+
<<~RUBY
|
133
|
+
1| module Foo
|
134
|
+
1| class Bar
|
135
|
+
2| def self.a
|
136
|
+
3| "hello"
|
137
|
+
4| end
|
138
|
+
5| end
|
139
|
+
6| Bar.a
|
140
|
+
7| bar = Bar.new
|
141
|
+
8| end
|
142
|
+
RUBY
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_foo
|
146
|
+
debug_code(program) do
|
147
|
+
type 's'
|
148
|
+
assert_line_num 2
|
149
|
+
assert_line_text([
|
150
|
+
/[1, 9] in .*/,
|
151
|
+
/ 1| module Foo/,
|
152
|
+
/=> 2| class Bar/,
|
153
|
+
/ 3| def self.a/,
|
154
|
+
/ 4| "hello"/,
|
155
|
+
/ 5| end/,
|
156
|
+
/ 6| end/,
|
157
|
+
/ 7| Bar.a/,
|
158
|
+
/ 8| bar = Bar.new/,
|
159
|
+
/ 9| end/,
|
160
|
+
/=>#0 <module:Foo> at .*/,
|
161
|
+
/ #1 <main> at .*/
|
162
|
+
])
|
163
|
+
type 'n'
|
164
|
+
assert_line_num 3
|
165
|
+
assert_line_text([
|
166
|
+
/[1, 9] in .*/,
|
167
|
+
/ 1| module Foo/,
|
168
|
+
/ 2| class Bar/,
|
169
|
+
/=> 3| def self.a/,
|
170
|
+
/ 4| "hello"/,
|
171
|
+
/ 5| end/,
|
172
|
+
/ 6| end/,
|
173
|
+
/ 7| Bar.a/,
|
174
|
+
/ 8| bar = Bar.new/,
|
175
|
+
/ 9| end/,
|
176
|
+
/=>#0 <class:Bar> at .*/,
|
177
|
+
/ #1 <module:Foo> at .*/,
|
178
|
+
/ #2 <main> at .*/
|
179
|
+
])
|
180
|
+
type 'b 7'
|
181
|
+
assert_line_text(//)
|
182
|
+
type 'c'
|
183
|
+
assert_line_num 7
|
184
|
+
assert_line_text([
|
185
|
+
/[2, 9] in .*/,
|
186
|
+
/ 2| class Bar/,
|
187
|
+
/ 3| def self.a/,
|
188
|
+
/ 4| "hello"/,
|
189
|
+
/ 5| end/,
|
190
|
+
/ 6| end/,
|
191
|
+
/=> 7| Bar.a/,
|
192
|
+
/ 8| bar = Bar.new/,
|
193
|
+
/ 9| end/,
|
194
|
+
/=>#0 <module:Foo> at .*/,
|
195
|
+
/ #1 <main> at .*/,
|
196
|
+
//,
|
197
|
+
/Stop by #0 BP - Line .*/
|
198
|
+
])
|
199
|
+
type 'q!'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
```
|
205
|
+
|
206
|
+
#### gentest options
|
207
|
+
You can get more information about `gentest` here.
|
208
|
+
|
209
|
+
The default method name is `test_foo` and the class name is `FooTest`. The file name will be `[Lowercase letters with "Test" removed from the class name]_test.rb`.
|
210
|
+
```shell
|
211
|
+
# run without any options(test method name will be `test_foo`, class name will be `FooTest`, file name will be `foo_test.rb`)
|
212
|
+
$ bin/gentest target.rb
|
213
|
+
# specify the class name(test method name will be `test_foo`, class name will be `StepTest`, file name will be `step_test.rb`)
|
214
|
+
$ bin/gentest target.rb -c StepTest
|
215
|
+
# specify the method name(test method name will be `test_step`, class name will be `FooTest`, file name will be `foo_test.rb`)
|
216
|
+
$ bin/gentest target.rb -m test_step
|
217
|
+
# specify class name and method name(test method name will be `test_step`, class name will be `StepTest`, file name will be `step_test.rb`.)
|
218
|
+
$ bin/gentest target.rb -c StepTest -m test_step
|
219
|
+
```
|
220
|
+
|
221
|
+
## To Update README
|
222
|
+
|
223
|
+
This project generates `README.md` from the template `misc/README.md.erb`
|
224
|
+
|
225
|
+
So **do not** directly update `README.md`. Instead, you should update the template's source and run
|
226
|
+
|
227
|
+
```bash
|
228
|
+
$ rake
|
229
|
+
```
|
230
|
+
|
231
|
+
to reflect the changes on `README.md`.
|
232
|
+
|
233
|
+
|
234
|
+
### When to re-generate `README.md`
|
235
|
+
|
236
|
+
- After updating `misc/README.md.erb`.
|
237
|
+
- After updating `rdbg` executable's options.
|
238
|
+
- After updating comments of debugger's commands.
|
239
|
+
|
240
|
+
## Manually Test Your Changes
|
241
|
+
|
242
|
+
You can manually test your changes with a simple Ruby script + a line of command. The following example will help you check:
|
243
|
+
|
244
|
+
- Breakpoint insertion.
|
245
|
+
- Resume from the breakpoint.
|
246
|
+
- Backtrace display.
|
247
|
+
- Information (local variables, ivars..etc.) display.
|
248
|
+
- Debugger exit.
|
249
|
+
|
250
|
+
|
251
|
+
### Script
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
# target.rb
|
255
|
+
class Foo
|
256
|
+
def first_call
|
257
|
+
second_call(20)
|
258
|
+
end
|
259
|
+
|
260
|
+
def second_call(num)
|
261
|
+
third_call_with_block do |ten|
|
262
|
+
forth_call(num, ten)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def third_call_with_block(&block)
|
267
|
+
@ivar1 = 10; @ivar2 = 20
|
268
|
+
|
269
|
+
yield(10)
|
270
|
+
end
|
271
|
+
|
272
|
+
def forth_call(num1, num2)
|
273
|
+
num1 + num2
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
Foo.new.first_call
|
278
|
+
```
|
279
|
+
|
280
|
+
### Command
|
281
|
+
|
282
|
+
```
|
283
|
+
$ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb
|
284
|
+
```
|
285
|
+
|
286
|
+
### Expect Result
|
287
|
+
|
288
|
+
```
|
289
|
+
❯ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb
|
290
|
+
[1, 10] in target.rb
|
291
|
+
=> 1| class Foo
|
292
|
+
2| def first_call
|
293
|
+
3| second_call(20)
|
294
|
+
4| end
|
295
|
+
5|
|
296
|
+
6| def second_call(num)
|
297
|
+
7| third_call_with_block do |ten|
|
298
|
+
8| forth_call(num, ten)
|
299
|
+
9| end
|
300
|
+
10| end
|
301
|
+
=>#0 <main> at target.rb:1
|
302
|
+
(rdbg:init) b 20
|
303
|
+
#1 line bp /PATH_TO_PROJECT/debug/target.rb:20 (return)
|
304
|
+
(rdbg:init) c
|
305
|
+
[15, 23] in target.rb
|
306
|
+
15| yield(10)
|
307
|
+
16| end
|
308
|
+
17|
|
309
|
+
18| def forth_call(num1, num2)
|
310
|
+
19| num1 + num2
|
311
|
+
=> 20| end
|
312
|
+
21| end
|
313
|
+
22|
|
314
|
+
23| Foo.new.first_call
|
315
|
+
=>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
|
316
|
+
#1 block{|ten=10|} in second_call at target.rb:8
|
317
|
+
# and 4 frames (use `bt' command for all frames)
|
318
|
+
|
319
|
+
Stop by #1 line bp /PATH_TO_PROJECT/debug/target.rb:20 (return)
|
320
|
+
(rdbg:init) bt
|
321
|
+
=>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
|
322
|
+
#1 block{|ten=10|} in second_call at target.rb:8
|
323
|
+
#2 Foo#third_call_with_block(block=#<Proc:0x00007f8bc32f0c28 target.rb:7>) at target.rb:15
|
324
|
+
#3 Foo#second_call(num=20) at target.rb:7
|
325
|
+
#4 first_call at target.rb:3
|
326
|
+
#5 <main> at target.rb:23
|
327
|
+
(rdbg:init) info
|
328
|
+
=>#0 Foo#forth_call(num1=20, num2=10) at target.rb:20 #=> 30
|
329
|
+
%self => #<Foo:0x00007f8bc32f0ed0>
|
330
|
+
%return => 30
|
331
|
+
num1 => 20
|
332
|
+
num2 => 10
|
333
|
+
@ivar1 => 10
|
334
|
+
@ivar2 => 20
|
335
|
+
(rdbg:init) q!
|
336
|
+
```
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
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
5
|
This library provides debugging functionality to Ruby.
|
@@ -9,7 +11,7 @@ New debug.rb has several advantages:
|
|
9
11
|
* Remote debugging: Support remote debugging natively.
|
10
12
|
* UNIX domain socket
|
11
13
|
* TCP/IP
|
12
|
-
* VSCode/DAP integration (
|
14
|
+
* VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
|
13
15
|
* Extensible: application can introduce debugging support with several methods
|
14
16
|
* By `rdbg` command
|
15
17
|
* By loading libraries with `-r` command line option
|
@@ -27,6 +29,16 @@ $ gem install debug --pre
|
|
27
29
|
|
28
30
|
or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
|
29
31
|
|
32
|
+
If you use Bundler, write the following line to your Gemfile. And use rdbg command with -c option.
|
33
|
+
|
34
|
+
```
|
35
|
+
gem "debug", ">= 1.0.0.beta"
|
36
|
+
```
|
37
|
+
|
38
|
+
```
|
39
|
+
$ rdbg -c bundle exec ruby target.rb
|
40
|
+
```
|
41
|
+
|
30
42
|
# How to use
|
31
43
|
|
32
44
|
## Invoke with debugger
|
@@ -49,32 +61,34 @@ To use debugging feature, you can have 3 ways.
|
|
49
61
|
|
50
62
|
### Local debug console
|
51
63
|
|
64
|
+
#### (1) Use `rdbg` command
|
65
|
+
|
52
66
|
```
|
53
|
-
# (1) Use `rdbg` command
|
54
67
|
$ rdbg target.rb
|
55
68
|
$ rdbg -- -r foo -e expr # -- is required to make clear rdbg options and ruby's options
|
69
|
+
```
|
56
70
|
|
57
|
-
|
71
|
+
#### (2) Use `-r debug/run` command line option
|
58
72
|
|
73
|
+
```
|
59
74
|
$ ruby -r debug/run target.rb
|
75
|
+
```
|
60
76
|
|
61
|
-
|
77
|
+
#### (3) Write `require 'debug...'` in .rb files
|
62
78
|
|
63
|
-
|
79
|
+
```ruby
|
80
|
+
# target.rb
|
64
81
|
require 'debug/run' # start the debug console
|
65
|
-
...
|
66
|
-
|
67
|
-
# or
|
68
82
|
|
69
|
-
|
70
|
-
|
71
|
-
DEBUGGER__.console # and start the debug console
|
83
|
+
# ... rest of program ...
|
84
|
+
```
|
72
85
|
|
86
|
+
```
|
73
87
|
$ ruby target.rb
|
74
88
|
```
|
75
89
|
|
76
90
|
When you run the program with the debug console, you will see the debug console prompt `(rdbg)`.
|
77
|
-
The debuggee program (`target.rb`) is suspended at the
|
91
|
+
The debuggee program (`target.rb`) is suspended at the beginning of `target.rb`.
|
78
92
|
|
79
93
|
You can type any debugger's command described bellow. "c" or "continue" resume the debuggee program.
|
80
94
|
You can suspend the debuggee program and show the debug console with `Ctrl-C`.
|
@@ -137,48 +151,51 @@ $ rdbg ~/src/rb/target.rb
|
|
137
151
|
b => 2
|
138
152
|
c => 3
|
139
153
|
|
140
|
-
(rdbg) c #
|
154
|
+
(rdbg) c # Continue the program ("c" is a short name of "continue")
|
141
155
|
[6]
|
142
156
|
```
|
143
157
|
|
144
158
|
### Remote debug (1) UNIX domain socket
|
145
159
|
|
160
|
+
#### (1) Use `rdbg` command
|
161
|
+
|
146
162
|
```
|
147
|
-
# (1) Use `rdbg` command
|
148
163
|
$ rdbg --open target.rb # or rdbg -O target.rb for shorthand
|
149
164
|
Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
|
150
|
-
|
165
|
+
```
|
151
166
|
|
152
|
-
|
167
|
+
#### (2) Use `-r debug/open` command line option
|
153
168
|
|
169
|
+
```
|
154
170
|
$ ruby -r debug/open target.rb
|
155
171
|
Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
|
156
|
-
|
172
|
+
```
|
173
|
+
|
174
|
+
#### (3) Write `require 'debug/open'` in .rb files
|
157
175
|
|
158
|
-
|
159
|
-
|
176
|
+
```ruby
|
177
|
+
# target.rb
|
160
178
|
require 'debug/open' # open the debugger entry point by UNIX domain socket.
|
161
|
-
...
|
162
179
|
|
163
180
|
# or
|
164
181
|
|
165
|
-
$ cat target.rb
|
166
182
|
require 'debug/server' # introduce remote debugging feature
|
167
183
|
DEBUGGER__.open # open the debugger entry point by UNIX domain socket.
|
168
184
|
# or DEBUGGER__.open_unix to specify UNIX domain socket.
|
185
|
+
```
|
169
186
|
|
187
|
+
```
|
170
188
|
$ ruby target.rb
|
171
189
|
Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
|
172
|
-
...
|
173
190
|
```
|
174
191
|
|
175
192
|
It runs target.rb and accept debugger connection within UNIX domain socket.
|
176
|
-
The debuggee process waits for debugger connection at the
|
193
|
+
The debuggee process waits for debugger connection at the beginning of `target.rb` like that:
|
177
194
|
|
178
195
|
```
|
179
196
|
$ rdbg -O ~/src/rb/target.rb
|
180
197
|
DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-29828)
|
181
|
-
DEBUGGER: wait for
|
198
|
+
DEBUGGER: wait for debugger connection...
|
182
199
|
```
|
183
200
|
|
184
201
|
You can attach the program with the following command:
|
@@ -204,7 +221,7 @@ and you can input any debug commands. `c` (or `continue`) continues the debuggee
|
|
204
221
|
You can detach the debugger from the debugger process with `quit` command.
|
205
222
|
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).
|
206
223
|
|
207
|
-
If you don't want to stop the debuggee process at the
|
224
|
+
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.
|
208
225
|
|
209
226
|
* Use `rdbg -n` option
|
210
227
|
* Set the environment variable `RUBY_DEBUG_NONSTOP=1`
|
@@ -233,40 +250,49 @@ The socket file is located at
|
|
233
250
|
|
234
251
|
You can open the TCP/IP port instead of using UNIX domain socket.
|
235
252
|
|
253
|
+
#### (1) Use `rdbg` command
|
254
|
+
|
236
255
|
```
|
237
|
-
# (1) Use `rdbg` command
|
238
256
|
$ rdbg -O --port=12345 target.rb
|
239
257
|
# or
|
240
258
|
$ rdbg --open --port=12345 target.rb
|
241
259
|
Debugger can attach via TCP/IP (localhost:12345)
|
242
|
-
|
260
|
+
```
|
261
|
+
|
262
|
+
#### (2) Use `-r debug/open` command line option
|
243
263
|
|
244
|
-
# (2) Use `-r debug/open` command line option
|
245
264
|
|
265
|
+
```
|
246
266
|
$ RUBY_DEBUG_PORT=12345 ruby -r debug/open target.rb
|
247
267
|
Debugger can attach via TCP/IP (localhost:12345)
|
248
|
-
|
268
|
+
```
|
269
|
+
|
270
|
+
#### (3) Write `require 'debug/open'` in .rb files
|
249
271
|
|
250
|
-
|
251
|
-
|
272
|
+
```ruby
|
273
|
+
# target.rb
|
252
274
|
require 'debug/open' # open the debugger entry point.
|
253
|
-
|
275
|
+
```
|
254
276
|
|
255
|
-
|
277
|
+
and run with environment variable RUBY_DEBUG_PORT
|
278
|
+
|
279
|
+
```
|
256
280
|
$ RUBY_DEBUG_PORT=12345 ruby target.rb
|
257
281
|
Debugger can attach via TCP/IP (localhost:12345)
|
258
|
-
|
282
|
+
```
|
259
283
|
|
260
|
-
|
284
|
+
or
|
261
285
|
|
262
|
-
|
286
|
+
```ruby
|
287
|
+
# target.rb
|
263
288
|
require 'debug/server' # introduce remote debugging feature
|
264
289
|
DEBUGGER__.open(port: 12345)
|
265
290
|
# or DEBUGGER__.open_tcp(port: 12345)
|
291
|
+
```
|
266
292
|
|
293
|
+
```
|
267
294
|
$ ruby target.rb
|
268
295
|
Debugger can attach via TCP/IP (localhost:12345)
|
269
|
-
...
|
270
296
|
```
|
271
297
|
|
272
298
|
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.
|
@@ -280,25 +306,23 @@ $ rdbg --attach hostname 12345
|
|
280
306
|
|
281
307
|
### Initial scripts
|
282
308
|
|
283
|
-
If there are
|
284
|
-
|
285
|
-
Initial scripts are evaluted at the first suspend timing (generally, it is the beggining of the target script). For example, you can set break points with `break file:123`.
|
309
|
+
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`.
|
286
310
|
|
287
|
-
If there are
|
311
|
+
If there are `~/.rdbgrc.rb` is available, it is loaded as a ruby script at same timing.
|
288
312
|
|
289
313
|
### Environment variables
|
290
314
|
|
291
315
|
You can control debuggee's behavior with environment variables:
|
292
316
|
|
293
|
-
* `RUBY_DEBUG_NONSTOP`: 1 for nonstop at the
|
317
|
+
* `RUBY_DEBUG_NONSTOP`: 1 for nonstop at the beginning of program.
|
294
318
|
* `RUBY_DEBUG_INIT_SCRIPT`: Initial script path loaded at the first stop.
|
295
319
|
* `RUBY_DEBUG_COMMANDS`: Debug commands invoked at the first stop. Commands should be separated by ';;'.
|
296
320
|
* `RUBY_DEBUG_SHOW_SRC_LINES`: Show n lines source code on breakpoint (default: 10 lines).
|
297
321
|
* `RUBY_DEBUG_SHOW_FRAMES`: Show n frames on breakpoint (default: 2 frames).
|
298
|
-
|
299
322
|
* Remote debugging
|
300
323
|
* `RUBY_DEBUG_PORT`: TCP/IP remote debugging: port to open.
|
301
324
|
* `RUBY_DEBUG_HOST`: TCP/IP remote debugging: host (localhost if not given) to open.
|
325
|
+
* `RUBY_DEBUG_SOCK_PATH`: UNIX Domain Socket remote debugging: socket path to open.
|
302
326
|
* `RUBY_DEBUG_SOCK_DIR`: UNIX Domain Socket remote debugging: socket directory to open.
|
303
327
|
|
304
328
|
## Debug command on the debug console
|
@@ -308,7 +332,7 @@ You can control debuggee's behavior with environment variables:
|
|
308
332
|
* [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
|
309
333
|
|
310
334
|
You can use the following debug commands. Each command should be written in 1 line.
|
311
|
-
The `[...]` notation means this part can be
|
335
|
+
The `[...]` notation means this part can be eliminate. For example, `s[tep]` means `s` or `step` are valid command. `ste` is not valid.
|
312
336
|
The `<...>` notation means the argument.
|
313
337
|
|
314
338
|
### Control flow
|
@@ -321,10 +345,14 @@ The `<...>` notation means the argument.
|
|
321
345
|
* Finish this frame. Resume the program until the current frame is finished.
|
322
346
|
* `c[ontinue]`
|
323
347
|
* Resume the program.
|
324
|
-
* `q[uit]` or
|
348
|
+
* `q[uit]` or `Ctrl-D`
|
325
349
|
* Finish debugger (with the debuggee process on non-remote debugging).
|
326
|
-
* `
|
327
|
-
*
|
350
|
+
* `q[uit]!`
|
351
|
+
* Same as q[uit] but without the confirmation prompt.
|
352
|
+
* `kill`
|
353
|
+
* Stop the debuggee process with `Kernal#exit!`.
|
354
|
+
* `kill!`
|
355
|
+
* Same as kill but without the confirmation prompt.
|
328
356
|
|
329
357
|
### Breakpoint
|
330
358
|
|
@@ -345,8 +373,8 @@ The `<...>` notation means the argument.
|
|
345
373
|
* Note that this feature is super slow.
|
346
374
|
* `catch <Error>`
|
347
375
|
* Set breakpoint on raising `<Error>`.
|
348
|
-
* `watch
|
349
|
-
* Stop the execution when the result of
|
376
|
+
* `watch @ivar`
|
377
|
+
* Stop the execution when the result of current scope's `@ivar` is changed.
|
350
378
|
* Note that this feature is super slow.
|
351
379
|
* `del[ete]`
|
352
380
|
* delete all breakpoints.
|
@@ -366,14 +394,14 @@ The `<...>` notation means the argument.
|
|
366
394
|
* Show current frame's source code from the line <start> to <end> if given.
|
367
395
|
* `edit`
|
368
396
|
* Open the current file on the editor (use `EDITOR` environment variable).
|
369
|
-
* Note that
|
397
|
+
* Note that edited file will not be reloaded.
|
370
398
|
* `edit <file>`
|
371
399
|
* Open <file> on the editor.
|
372
|
-
* `i[nfo]`
|
400
|
+
* `i[nfo]`, `i[nfo] l[ocal[s]]`
|
373
401
|
* Show information about the current frame (local variables)
|
374
402
|
* It includes `self` as `%self` and a return value as `%return`.
|
375
|
-
* `i[nfo]
|
376
|
-
* Show
|
403
|
+
* `i[nfo] th[read[s]]`
|
404
|
+
* Show all threads (same as `th[read]`).
|
377
405
|
* `display`
|
378
406
|
* Show display setting.
|
379
407
|
* `display <expr>`
|
@@ -388,13 +416,13 @@ The `<...>` notation means the argument.
|
|
388
416
|
### Frame control
|
389
417
|
|
390
418
|
* `f[rame]`
|
391
|
-
* Show current frame.
|
419
|
+
* Show the current frame.
|
392
420
|
* `f[rame] <framenum>`
|
393
|
-
* Specify frame. Evaluation are run on
|
421
|
+
* Specify a current frame. Evaluation are run on specified frame.
|
394
422
|
* `up`
|
395
|
-
* Specify upper frame.
|
423
|
+
* Specify the upper frame.
|
396
424
|
* `down`
|
397
|
-
* Specify
|
425
|
+
* Specify the lower frame.
|
398
426
|
|
399
427
|
### Evaluate
|
400
428
|
|
@@ -428,33 +456,50 @@ The `<...>` notation means the argument.
|
|
428
456
|
exe/rdbg [options] -- [debuggee options]
|
429
457
|
|
430
458
|
Debug console mode:
|
431
|
-
-n, --nonstop Do not stop at the
|
432
|
-
-e
|
433
|
-
-
|
459
|
+
-n, --nonstop Do not stop at the beginning of the script.
|
460
|
+
-e COMMAND Execute debug command at the beginning of the script.
|
461
|
+
-x, --init-script=FILE Execute debug command in the FILE.
|
462
|
+
--no-rc Ignore ~/.rdbgrc
|
463
|
+
--no-color Disable colorize
|
464
|
+
-c, --command Enable command mode.
|
465
|
+
The first argument should be a command name in $PATH.
|
466
|
+
Example: 'rdbg -c bundle exec rake test'
|
467
|
+
|
468
|
+
-O, --open Start remote debugging with opening the network port.
|
434
469
|
If TCP/IP options are not given,
|
435
470
|
a UNIX domain socket will be used.
|
436
|
-
--
|
437
|
-
--
|
471
|
+
--sock-path=SOCK_PATH UNIX Doman socket path
|
472
|
+
--port=PORT Listening TCP/IP port
|
473
|
+
--host=HOST Listening TCP/IP host
|
474
|
+
--cookie=COOKIE Set a cookie for connection
|
438
475
|
|
439
476
|
Debug console mode runs Ruby program with the debug console.
|
440
477
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
478
|
+
'rdbg target.rb foo bar' starts like 'ruby target.rb foo bar'.
|
479
|
+
'rdbg -- -r foo -e bar' starts like 'ruby -r foo -e bar'.
|
480
|
+
'rdbg -O target.rb foo bar' starts and accepts attaching with UNIX domain socket.
|
481
|
+
'rdbg -O --port 1234 target.rb foo bar' starts accepts attaching with TCP/IP localhost:1234.
|
482
|
+
'rdbg -O --port 1234 -- -r foo -e bar' starts accepts attaching with TCP/IP localhost:1234.
|
446
483
|
|
447
484
|
Attach mode:
|
448
485
|
-A, --attach Attach to debuggee process.
|
449
486
|
|
450
487
|
Attach mode attaches the remote debug console to the debuggee process.
|
451
488
|
|
452
|
-
'
|
489
|
+
'rdbg -A' tries to connect via UNIX domain socket.
|
453
490
|
If there are multiple processes are waiting for the
|
454
491
|
debugger connection, list possible debuggee names.
|
455
|
-
'
|
456
|
-
'
|
457
|
-
'
|
492
|
+
'rdbg -A path' tries to connect via UNIX domain socket with given path name.
|
493
|
+
'rdbg -A port' tries to connect to localhost:port via TCP/IP.
|
494
|
+
'rdbg -A host port' tries to connect to host:port via TCP/IP.
|
495
|
+
|
496
|
+
Other options:
|
497
|
+
-h, --help Print help
|
498
|
+
--util=NAME Utility mode (used by tools)
|
499
|
+
|
500
|
+
NOTE
|
501
|
+
All messages communicated between a debugger and a debuggee are *NOT* encrypted.
|
502
|
+
Please use the remote debugging feature carefully.
|
458
503
|
|
459
504
|
```
|
460
505
|
|
@@ -462,3 +507,8 @@ Attach mode:
|
|
462
507
|
|
463
508
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
|
464
509
|
|
510
|
+
Please also check the [contributing guideline](/CONTRIBUTING.md).
|
511
|
+
|
512
|
+
# Acknowledgement
|
513
|
+
|
514
|
+
* Some tests are based on [deivid-rodriguez/byebug: Debugging in Ruby 2](https://github.com/deivid-rodriguez/byebug)
|