debug 1.0.0.alpha1 → 1.0.0.beta5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/debug/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DEBUGGER__
2
- VERSION = "1.0.0.alpha1"
2
+ VERSION = "1.0.0.beta5"
3
3
  end
@@ -0,0 +1,350 @@
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
+
3
+ # debug.rb
4
+
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
25
+
26
+ ```
27
+ $ gem install debug --pre
28
+ ```
29
+
30
+ or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
31
+
32
+ # How to use
33
+
34
+ ## Invoke with debugger
35
+
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
55
+
56
+ ```
57
+ $ rdbg target.rb
58
+ $ rdbg -- -r foo -e expr # -- is required to make clear rdbg options and ruby's options
59
+ ```
60
+
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
72
+
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
+ ```
151
+
152
+ ### Remote debug (1) UNIX domain socket
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
+
163
+ ```
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)
184
+ ```
185
+
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:
188
+
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:
196
+
197
+ ```
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)
211
+ ```
212
+
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.
219
+
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:
224
+
225
+ ```
226
+ $ rdbg --attach
227
+ Please select a debug session:
228
+ ruby-debug-ko1-19638
229
+ ruby-debug-ko1-19603
230
+ ```
231
+
232
+ and you need to specify one (copy and paste the name):
233
+
234
+ ```
235
+ $ rdbg --attach ruby-debug-ko1-19638
236
+ ```
237
+
238
+ The socket file is located at
239
+ * `RUBY_DEBUG_SOCK_DIR` environment variable if available.
240
+ * `XDG_RUNTIME_DIR` environment variable if available.
241
+ * `$HOME/.ruby-debug-sock` if `$HOME` is available.
242
+
243
+ ### Remote debug (2) TCP/IP
244
+
245
+ You can open the TCP/IP port instead of using UNIX domain socket.
246
+
247
+ #### (1) Use `rdbg` command
248
+
249
+ ```
250
+ $ rdbg -O --port=12345 target.rb
251
+ # or
252
+ $ rdbg --open --port=12345 target.rb
253
+ Debugger can attach via TCP/IP (localhost:12345)
254
+ ```
255
+
256
+ #### (2) Use `-r debug/open` command line option
257
+
258
+
259
+ ```
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.
269
+ ```
270
+
271
+ and run with environment variable RUBY_DEBUG_PORT
272
+
273
+ ```
274
+ $ RUBY_DEBUG_PORT=12345 ruby target.rb
275
+ Debugger can attach via TCP/IP (localhost:12345)
276
+ ```
277
+
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
325
+
326
+ * `Enter` repeats the last command (useful when repeating `step`s).
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.
333
+
334
+ <%= DEBUGGER__.help %>
335
+
336
+ ## rdbg command help
337
+
338
+ ```
339
+ <%= `exe/rdbg --help` %>
340
+ ```
341
+
342
+ # Contributing
343
+
344
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
345
+
346
+ Please also check the [contributing guideline](/CONTRIBUTING.md).
347
+
348
+ # Acknowledgement
349
+
350
+ * Some tests are based on [deivid-rodriguez/byebug: Debugging in Ruby 2](https://github.com/deivid-rodriguez/byebug)
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha1
4
+ version: 1.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: debug_inspector
14
+ name: irb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -24,55 +24,56 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: iseq_collector
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- description: debug.rb
27
+ description: Debugging functionality for Ruby. This is completely rewritten debug.rb
28
+ which was contained by the encient Ruby versions.
42
29
  email:
43
30
  - ko1@atdot.net
44
31
  executables:
45
32
  - rdbg
46
- extensions: []
33
+ extensions:
34
+ - ext/debug/extconf.rb
47
35
  extra_rdoc_files: []
48
36
  files:
37
+ - ".github/workflows/ruby.yml"
49
38
  - ".gitignore"
39
+ - CONTRIBUTING.md
40
+ - Gemfile
50
41
  - LICENSE.txt
51
42
  - README.md
52
43
  - Rakefile
44
+ - TODO.md
53
45
  - bin/console
54
46
  - bin/setup
55
47
  - debug.gemspec
56
48
  - exe/rdbg
49
+ - ext/debug/debug.c
50
+ - ext/debug/extconf.rb
51
+ - ext/debug/iseq_collector.c
57
52
  - lib/debug.rb
58
53
  - lib/debug/bp.vim
59
54
  - lib/debug/breakpoint.rb
60
55
  - lib/debug/client.rb
56
+ - lib/debug/color.rb
61
57
  - lib/debug/config.rb
62
- - lib/debug/repl.rb
58
+ - lib/debug/console.rb
59
+ - lib/debug/frame_info.rb
60
+ - lib/debug/open.rb
61
+ - lib/debug/run.rb
63
62
  - lib/debug/server.rb
63
+ - lib/debug/server_dap.rb
64
64
  - lib/debug/session.rb
65
65
  - lib/debug/source_repository.rb
66
- - lib/debug/tcpserver.rb
66
+ - lib/debug/test_console.rb
67
67
  - lib/debug/thread_client.rb
68
- - lib/debug/unixserver.rb
69
68
  - lib/debug/version.rb
70
- homepage: https://github.com/ko1/debug
69
+ - misc/README.md.erb
70
+ homepage: https://github.com/ruby/debug
71
71
  licenses:
72
- - MIT
72
+ - Ruby
73
+ - BSD-2-Clause
73
74
  metadata:
74
- homepage_uri: https://github.com/ko1/debug
75
- source_code_uri: https://github.com/ko1/debug
75
+ homepage_uri: https://github.com/ruby/debug
76
+ source_code_uri: https://github.com/ruby/debug
76
77
  post_install_message:
77
78
  rdoc_options: []
78
79
  require_paths:
@@ -88,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  - !ruby/object:Gem::Version
89
90
  version: 1.3.1
90
91
  requirements: []
91
- rubygems_version: 3.1.4
92
+ rubygems_version: 3.1.6
92
93
  signing_key:
93
94
  specification_version: 4
94
- summary: debug.rb
95
+ summary: Debugging functionality for Ruby
95
96
  test_files: []