debug 1.0.0.alpha1 → 1.0.0.beta1

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.beta1"
3
3
  end
@@ -0,0 +1,325 @@
1
+ # debug.rb
2
+
3
+ This library provides debugging functionality to Ruby.
4
+
5
+ This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by `set_trace_func`.
6
+ New debug.rb has several advantages:
7
+
8
+ * Fast: No performance penalty on non-stepping mode and non-breakpoints.
9
+ * Remote debugging: Support remote debugging natively.
10
+ * UNIX domain socket
11
+ * TCP/IP
12
+ * VSCode/DAP integration (TODO)
13
+ * Extensible: application can introduce debugging support with several methods
14
+ * By `rdbg` command
15
+ * By loading libraries with `-r` command line option
16
+ * By calling Ruby's method explicitly
17
+ * Misc
18
+ * Support threads (almost done) and ractors (TODO).
19
+ * Support suspending and entering to the console debugging with `Ctrl-C` at most of timing.
20
+ * Show parameters on backtrace command.
21
+
22
+ # Installation
23
+
24
+ ```
25
+ $ gem install debug --pre
26
+ ```
27
+
28
+ or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
29
+
30
+ # How to use
31
+
32
+ ## Invoke with debugger
33
+
34
+ You can run ruby program on debugger with the local debug console or the remote debug console.
35
+
36
+ * (a) Run a ruby program with the local debug console
37
+ * (b) Run a ruby program with the remote debug console by opening a network port
38
+ * (b-1) Open with UNIX domain socket
39
+ * (b-2) Open with TCP/IP port
40
+
41
+ (b-1) is useful when you want to use debugging features after running the program.
42
+ (b-2) is also useful when you don't have a ssh access for the Ruby process.
43
+
44
+ To use debugging feature, you can have 3 ways.
45
+
46
+ * (1) Use `rdbg` command
47
+ * (2) Use `ruby -r debug...` command line option
48
+ * (3) Write `require 'debug...'` in .rb files
49
+
50
+ ### Local debug console
51
+
52
+ ```
53
+ # (1) Use `rdbg` command
54
+ $ rdbg target.rb
55
+ $ rdbg -- -r foo -e expr # -- is required to make clear rdbg options and ruby's options
56
+
57
+ # (2) Use `-r debug/run` command line option
58
+
59
+ $ ruby -r debug/run target.rb
60
+
61
+ # (3) Write `require 'debug...' in .rb files
62
+
63
+ $ cat target.rb
64
+ require 'debug/run' # start the debug console
65
+ ...
66
+
67
+ # or
68
+
69
+ $ cat target.rb
70
+ require 'debug/session' # introduce the functionality
71
+ DEBUGGER__.console # and start the debug console
72
+
73
+ $ ruby target.rb
74
+ ```
75
+
76
+ 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 beggining of `target.rb`.
78
+
79
+ You can type any debugger's command described bellow. "c" or "continue" resume the debuggee program.
80
+ You can suspend the debuggee program and show the debug console with `Ctrl-C`.
81
+
82
+ The following example shows simple usage of the debug console. You can show the all variables
83
+
84
+ ```
85
+ $ rdbg ~/src/rb/target.rb
86
+
87
+ [1, 5] in /home/ko1/src/rb/target.rb
88
+ => 1| a = 1
89
+ 2| b = 2
90
+ 3| c = 3
91
+ 4| p [a + b + c]
92
+ 5|
93
+ --> #0 /home/ko1/src/rb/target.rb:1:in `<main>'
94
+
95
+ (rdbg) info # Show all local variables
96
+ %self => main
97
+ a => nil
98
+ b => nil
99
+ c => nil
100
+
101
+ (rdbg) p a # Same as p(a)
102
+ => nil
103
+
104
+ (rdbg) s # Step in ("s" is a short name of "step")
105
+
106
+ [1, 5] in /home/ko1/src/rb/target.rb
107
+ 1| a = 1
108
+ => 2| b = 2
109
+ 3| c = 3
110
+ 4| p [a + b + c]
111
+ 5|
112
+ --> #0 /home/ko1/src/rb/target.rb:2:in `<main>'
113
+
114
+ (rdbg) <Enter> # Repeat the last command ("step")
115
+
116
+ [1, 5] in /home/ko1/src/rb/target.rb
117
+ 1| a = 1
118
+ 2| b = 2
119
+ => 3| c = 3
120
+ 4| p [a + b + c]
121
+ 5|
122
+ --> #0 /home/ko1/src/rb/target.rb:3:in `<main>'
123
+
124
+ (rdbg) # Repeat the last command ("step")
125
+
126
+ [1, 5] in /home/ko1/src/rb/target.rb
127
+ 1| a = 1
128
+ 2| b = 2
129
+ 3| c = 3
130
+ => 4| p [a + b + c]
131
+ 5|
132
+ --> #0 /home/ko1/src/rb/target.rb:4:in `<main>'
133
+
134
+ (rdbg) info # Show all local variables
135
+ %self => main
136
+ a => 1
137
+ b => 2
138
+ c => 3
139
+
140
+ (rdbg) c # Contineu the program ("c" is a short name of "continue")
141
+ [6]
142
+ ```
143
+
144
+ ### Remote debug (1) UNIX domain socket
145
+
146
+ ```
147
+ # (1) Use `rdbg` command
148
+ $ rdbg --open target.rb # or rdbg -O target.rb for shorthand
149
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
150
+ ...
151
+
152
+ # (2) Use `-r debug/open` command line option
153
+
154
+ $ ruby -r debug/open target.rb
155
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
156
+ ...
157
+
158
+ # (3) Write `require 'debug/open' in .rb files
159
+ $ cat target.rb
160
+ require 'debug/open' # open the debugger entry point by UNIX domain socket.
161
+ ...
162
+
163
+ # or
164
+
165
+ $ cat target.rb
166
+ require 'debug/server' # introduce remote debugging feature
167
+ DEBUGGER__.open # open the debugger entry point by UNIX domain socket.
168
+ # or DEBUGGER__.open_unix to specify UNIX domain socket.
169
+
170
+ $ ruby target.rb
171
+ Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-5042)
172
+ ...
173
+ ```
174
+
175
+ It runs target.rb and accept debugger connection within UNIX domain socket.
176
+ The debuggee process waits for debugger connection at the beggining of `target.rb` like that:
177
+
178
+ ```
179
+ $ rdbg -O ~/src/rb/target.rb
180
+ DEBUGGER: Debugger can attach via UNIX domain socket (/home/ko1/.ruby-debug-sock/ruby-debug-ko1-29828)
181
+ DEBUGGER: wait for debuger connection...
182
+ ```
183
+
184
+ You can attach the program with the following command:
185
+
186
+ ```
187
+ $ rdbg --attach # or rdbg -A for shorthand
188
+
189
+ [1, 4] in /home/ko1/src/rb/target.rb
190
+ 1| (1..).each do |i|
191
+ => 2| sleep 0.5
192
+ 3| p i
193
+ 4| end
194
+ --> #0 [C] /home/ko1/src/rb/target.rb:2:in `sleep'
195
+ #1 /home/ko1/src/rb/target.rb:2:in `block in <main>' {|i=17|}
196
+ #2 [C] /home/ko1/src/rb/target.rb:1:in `each'
197
+ # and 1 frames (use `bt' command for all frames)
198
+
199
+ (rdb)
200
+ ```
201
+
202
+ and you can input any debug commands. `c` (or `continue`) continues the debuggee process.
203
+
204
+ You can detach the debugger from the debugger process with `quit` command.
205
+ 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
+
207
+ If you don't want to stop the debuggee process at the beggining of debuggee process (`target.rb`), you can use the fowllowings to specify "non-stop" option.
208
+
209
+ * Use `rdbg -n` option
210
+ * Set the environment variable `RUBY_DEBUG_NONSTOP=1`
211
+
212
+ If you are running multiple debuggee processes, the attach command (`rdbg -A`) shows the options like that:
213
+
214
+ ```
215
+ $ rdbg --attach
216
+ Please select a debug session:
217
+ ruby-debug-ko1-19638
218
+ ruby-debug-ko1-19603
219
+ ```
220
+
221
+ and you need to specify one (copy and paste the name):
222
+
223
+ ```
224
+ $ rdbg --attach ruby-debug-ko1-19638
225
+ ```
226
+
227
+ The socket file is located at
228
+ * `RUBY_DEBUG_SOCK_DIR` environment variable if available.
229
+ * `XDG_RUNTIME_DIR` environment variable if available.
230
+ * `$HOME/.ruby-debug-sock` if `$HOME` is available.
231
+
232
+ ### Remote debug (2) TCP/IP
233
+
234
+ You can open the TCP/IP port instead of using UNIX domain socket.
235
+
236
+ ```
237
+ # (1) Use `rdbg` command
238
+ $ rdbg -O --port=12345 target.rb
239
+ # or
240
+ $ rdbg --open --port=12345 target.rb
241
+ Debugger can attach via TCP/IP (localhost:12345)
242
+ ...
243
+
244
+ # (2) Use `-r debug/open` command line option
245
+
246
+ $ RUBY_DEBUG_PORT=12345 ruby -r debug/open target.rb
247
+ Debugger can attach via TCP/IP (localhost:12345)
248
+ ...
249
+
250
+ # (3) Write `require 'debug/open' in .rb files
251
+ $ cat target.rb
252
+ require 'debug/open' # open the debugger entry point.
253
+ ...
254
+
255
+ # and run with environment variable RUBY_DEBUG_PORT
256
+ $ RUBY_DEBUG_PORT=12345 ruby target.rb
257
+ Debugger can attach via TCP/IP (localhost:12345)
258
+ ...
259
+
260
+ # or
261
+
262
+ $ cat target.rb
263
+ require 'debug/server' # introduce remote debugging feature
264
+ DEBUGGER__.open(port: 12345)
265
+ # or DEBUGGER__.open_tcp(port: 12345)
266
+
267
+ $ ruby target.rb
268
+ Debugger can attach via TCP/IP (localhost:12345)
269
+ ...
270
+ ```
271
+
272
+ 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.
273
+
274
+ To attach the debuggee process, specify the port number (and hostname if needed) for the `rdbg --attach` (or `rdbg -A`) command.
275
+
276
+ ```
277
+ $ rdbg --attach 12345
278
+ $ rdbg --attach hostname 12345
279
+ ```
280
+
281
+ ### Initial scripts
282
+
283
+ 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.
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`.
286
+
287
+ 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.
288
+
289
+ ### Environment variables
290
+
291
+ You can control debuggee's behavior with environment variables:
292
+
293
+ * `RUBY_DEBUG_NONSTOP`: 1 for nonstop at the beggining of program.
294
+ * `RUBY_DEBUG_INIT_SCRIPT`: Initial script path loaded at the first stop.
295
+ * `RUBY_DEBUG_COMMANDS`: Debug commands invoked at the first stop. Commands should be separated by ';;'.
296
+ * `RUBY_DEBUG_SHOW_SRC_LINES`: Show n lines source code on breakpoint (default: 10 lines).
297
+ * `RUBY_DEBUG_SHOW_FRAMES`: Show n frames on breakpoint (default: 2 frames).
298
+
299
+ * Remote debugging
300
+ * `RUBY_DEBUG_PORT`: TCP/IP remote debugging: port to open.
301
+ * `RUBY_DEBUG_HOST`: TCP/IP remote debugging: host (localhost if not given) to open.
302
+ * `RUBY_DEBUG_SOCK_DIR`: UNIX Domain Socket remote debugging: socket directory to open.
303
+
304
+ ## Debug command on the debug console
305
+
306
+ * `Enter` repeats the last command (useful when repeating `step`s).
307
+ * `Ctrl-D` is equal to `quit` command.
308
+ * [debug command compare sheet - Google Sheets](https://docs.google.com/spreadsheets/d/1TlmmUDsvwK4sSIyoMv-io52BUUz__R5wpu-ComXlsw0/edit?usp=sharing)
309
+
310
+ You can use the following debug commands. Each command should be written in 1 line.
311
+ The `[...]` notation means this part can be elimiante. For example, `s[tep]` means `s` or `step` are valid command. `ste` is not valid.
312
+ The `<...>` notation means the argument.
313
+
314
+ <%= DEBUGGER__.help %>
315
+
316
+ ## rdbg command help
317
+
318
+ ```
319
+ <%= `exe/rdbg --help` %>
320
+ ```
321
+
322
+ # Contributing
323
+
324
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.
325
+
metadata CHANGED
@@ -1,52 +1,27 @@
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.beta1
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
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: debug_inspector
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
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
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Debugging functionality for Ruby. This is completely rewritten debug.rb
14
+ which was contained by the encient Ruby versions.
42
15
  email:
43
16
  - ko1@atdot.net
44
17
  executables:
45
18
  - rdbg
46
- extensions: []
19
+ extensions:
20
+ - ext/debug/extconf.rb
47
21
  extra_rdoc_files: []
48
22
  files:
49
23
  - ".gitignore"
24
+ - Gemfile
50
25
  - LICENSE.txt
51
26
  - README.md
52
27
  - Rakefile
@@ -54,25 +29,30 @@ files:
54
29
  - bin/setup
55
30
  - debug.gemspec
56
31
  - exe/rdbg
32
+ - ext/debug/debug.c
33
+ - ext/debug/extconf.rb
34
+ - ext/debug/iseq_collector.c
57
35
  - lib/debug.rb
58
36
  - lib/debug/bp.vim
59
37
  - lib/debug/breakpoint.rb
60
38
  - lib/debug/client.rb
61
39
  - lib/debug/config.rb
62
- - lib/debug/repl.rb
40
+ - lib/debug/console.rb
41
+ - lib/debug/open.rb
42
+ - lib/debug/run.rb
63
43
  - lib/debug/server.rb
64
44
  - lib/debug/session.rb
65
45
  - lib/debug/source_repository.rb
66
- - lib/debug/tcpserver.rb
67
46
  - lib/debug/thread_client.rb
68
- - lib/debug/unixserver.rb
69
47
  - lib/debug/version.rb
70
- homepage: https://github.com/ko1/debug
48
+ - misc/README.md.erb
49
+ homepage: https://github.com/ruby/debug
71
50
  licenses:
72
- - MIT
51
+ - Ruby
52
+ - BSD-2-Clause
73
53
  metadata:
74
- homepage_uri: https://github.com/ko1/debug
75
- source_code_uri: https://github.com/ko1/debug
54
+ homepage_uri: https://github.com/ruby/debug
55
+ source_code_uri: https://github.com/ruby/debug
76
56
  post_install_message:
77
57
  rdoc_options: []
78
58
  require_paths:
@@ -88,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
68
  - !ruby/object:Gem::Version
89
69
  version: 1.3.1
90
70
  requirements: []
91
- rubygems_version: 3.1.4
71
+ rubygems_version: 3.1.6
92
72
  signing_key:
93
73
  specification_version: 4
94
- summary: debug.rb
74
+ summary: Debugging functionality for Ruby
95
75
  test_files: []
data/lib/debug/repl.rb DELETED
@@ -1,69 +0,0 @@
1
- require_relative 'session'
2
-
3
- module DEBUGGER__
4
- class UI_Repl
5
- def initialize
6
- end
7
-
8
- def quit n
9
- exit n
10
- end
11
-
12
- def ask prompt
13
- print prompt
14
- (gets || '').strip
15
- end
16
-
17
- def puts str
18
- case str
19
- when Array
20
- str.each{|line|
21
- $stdout.puts line.chomp
22
- }
23
- when String
24
- str.each_line{|line|
25
- $stdout.puts line.chomp
26
- }
27
- when nil
28
- $stdout.puts
29
- end
30
- end
31
-
32
- begin
33
- require 'readline'
34
- def readline
35
- setup_interrupt do
36
- str = Readline.readline("\n(rdb) ", true)
37
- (str || 'quit').strip
38
- end
39
- end
40
- rescue LoadError
41
- def readline
42
- setup_interrupt do
43
- print "\n(rdb) "
44
- (gets || 'quit').strip
45
- end
46
- end
47
- end
48
-
49
- def setup_interrupt
50
- current_thread = Thread.current # should be session_server thread
51
-
52
- prev_handler = trap(:INT){
53
- current_thread.raise Interrupt
54
- }
55
-
56
- yield
57
- ensure
58
- trap(:INT, prev_handler)
59
- end
60
- end
61
-
62
- initialize_session UI_Repl.new
63
-
64
- PREV_HANDLER = trap(:SIGINT){
65
- ThreadClient.current.on_trap
66
- }
67
-
68
- DEBUGGER__.add_line_breakpoint $0, 1
69
- end