debug 0.2.0 → 1.0.0.beta3

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: 5ef5033a78a878b42dd6850ee75552d58a0a0e02bfb890b3bf8970d9b5076387
4
- data.tar.gz: a20c0455d990c8d74975ee9d67c327cfd9165f50a6ae32e6a69d79d6334bed56
3
+ metadata.gz: 9702de02ad9d9aab11e0f0113a3596110222f92178e2918e6f4c5ad66fb5e3fb
4
+ data.tar.gz: 6f8552da80d13f0c597223fa651a49f44810d7106feb73c8a93d73249c74a987
5
5
  SHA512:
6
- metadata.gz: 8421e8a499c15e797ccced0f4f6ee2e315c9a18332db39beac30978fdcc87ac541c765fbf1c6e31b577020949421a928139dc81d3bf0ed0fcc97f7d7e2158487
7
- data.tar.gz: bcab6869de9e3522bfa139a610ad5964121da2fd69678966fc0ab2c10d0b544d9692bbb2614e794b2df44ab7469d556fb86983be8dc6971c402c33ba816a6dc3
6
+ metadata.gz: 1a2386cd5fcde06d356cb35e1d5ff637c587c33a4fdf9e3866d11761276a31cf5586d383b8cd8f6074be24a681592db7d577b8fcf3270d63afff9256ddaaa78f
7
+ data.tar.gz: 373039bc43b6071d77c4bb103453258a50668224ea581b4fd0b5ec0bf3df7c4b95702e2bc3723e35c55e238aaf6fa9297090fa7daf8fe4c6eee22124f1087daf
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.bundle
9
10
  /Gemfile.lock
data/Gemfile CHANGED
@@ -1,8 +1,7 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in debug.gemspec
4
3
  gemspec
5
4
 
6
- group :development do
7
- gem "rake"
8
- end
5
+ gem "rake", "~> 12.0"
6
+ gem "rake-compiler"
7
+ gem "minitest", "~> 5.0"
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -1,52 +1,467 @@
1
- # Debug
1
+ # debug.rb
2
2
 
3
3
  This library provides debugging functionality to Ruby.
4
4
 
5
- ## Installation
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:
6
7
 
7
- Add this line to your application's Gemfile:
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.
8
21
 
9
- ```ruby
10
- gem 'debug'
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 beginning 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 # Continue 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 beginning 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 debugger 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)
11
200
  ```
12
201
 
13
- And then execute:
202
+ and you can input any debug commands. `c` (or `continue`) continues the debuggee process.
14
203
 
15
- $ bundle install
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).
16
206
 
17
- Or install it yourself as:
207
+ 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.
18
208
 
19
- $ gem install debug
209
+ * Use `rdbg -n` option
210
+ * Set the environment variable `RUBY_DEBUG_NONSTOP=1`
20
211
 
21
- ## Usage
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
+ ```
22
220
 
23
- To add a debugger to your code, start by requiring +debug+ in your
24
- program:
221
+ and you need to specify one (copy and paste the name):
25
222
 
26
- ```ruby
27
- def say(word)
28
- require 'debug'
29
- puts word
30
- end
31
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.
32
231
 
33
- This will cause Ruby to interrupt execution and show a prompt when the +say+
34
- method is run.
232
+ ### Remote debug (2) TCP/IP
35
233
 
36
- Once you're inside the prompt, you can start debugging your program.
234
+ You can open the TCP/IP port instead of using UNIX domain socket.
37
235
 
38
236
  ```
39
- (rdb:1) p word
40
- "hello"
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 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`.
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 beginning 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 eliminate. For example, `s[tep]` means `s` or `step` are valid command. `ste` is not valid.
312
+ The `<...>` notation means the argument.
313
+
314
+ ### Control flow
315
+
316
+ * `s[tep]`
317
+ * Step in. Resume the program until next breakable point.
318
+ * `n[ext]`
319
+ * Step over. Resume the program until next line.
320
+ * `fin[ish]`
321
+ * Finish this frame. Resume the program until the current frame is finished.
322
+ * `c[ontinue]`
323
+ * Resume the program.
324
+ * `q[uit]` or `Ctrl-D`
325
+ * Finish debugger (with the debuggee process on non-remote debugging).
326
+ * `q[uit]!`
327
+ * Same as q[uit] but without the confirmation prompt.
328
+ * `kill`
329
+ * Stop the debuggee process with `Kernal#exit!`.
330
+ * `kill!`
331
+ * Same as kill but without the confirmation prompt.
332
+
333
+ ### Breakpoint
334
+
335
+ * `b[reak]`
336
+ * Show all breakpoints.
337
+ * `b[reak] <line>`
338
+ * Set breakpoint on `<line>` at the current frame's file.
339
+ * `b[reak] <file>:<line>` or `<file> <line>`
340
+ * Set breakpoint on `<file>:<line>`.
341
+ * `b[reak] <class>#<name>`
342
+ * Set breakpoint on the method `<class>#<name>`.
343
+ * `b[reak] <expr>.<name>`
344
+ * Set breakpoint on the method `<expr>.<name>`.
345
+ * `b[reak] ... if <expr>`
346
+ * break if `<expr>` is true at specified location.
347
+ * `b[reak] if <expr>`
348
+ * break if `<expr>` is true at any lines.
349
+ * Note that this feature is super slow.
350
+ * `catch <Error>`
351
+ * Set breakpoint on raising `<Error>`.
352
+ * `watch <expr>`
353
+ * Stop the execution when the result of `<expr>` is changed.
354
+ * Note that this feature is super slow.
355
+ * `del[ete]`
356
+ * delete all breakpoints.
357
+ * `del[ete] <bpnum>`
358
+ * delete specified breakpoint.
359
+
360
+ ### Information
361
+
362
+ * `bt` or `backtrace`
363
+ * Show backtrace (frame) information.
364
+ * `l[ist]`
365
+ * Show current frame's source code.
366
+ * Next `list` command shows the successor lines.
367
+ * `l[ist] -`
368
+ * Show predecessor lines as opposed to the `list` command.
369
+ * `l[ist] <start>` or `l[ist] <start>-<end>`
370
+ * Show current frame's source code from the line <start> to <end> if given.
371
+ * `edit`
372
+ * Open the current file on the editor (use `EDITOR` environment variable).
373
+ * Note that edited file will not be reloaded.
374
+ * `edit <file>`
375
+ * Open <file> on the editor.
376
+ * `i[nfo]`
377
+ * Show information about the current frame (local variables)
378
+ * It includes `self` as `%self` and a return value as `%return`.
379
+ * `i[nfo] <expr>`
380
+ * Show information about the result of <expr>.
381
+ * `display`
382
+ * Show display setting.
383
+ * `display <expr>`
384
+ * Show the result of `<expr>` at every suspended timing.
385
+ * `undisplay`
386
+ * Remove all display settings.
387
+ * `undisplay <displaynum>`
388
+ * Remove a specified display setting.
389
+ * `trace [on|off]`
390
+ * enable or disable line tracer.
391
+
392
+ ### Frame control
393
+
394
+ * `f[rame]`
395
+ * Show the current frame.
396
+ * `f[rame] <framenum>`
397
+ * Specify a current frame. Evaluation are run on specified frame.
398
+ * `up`
399
+ * Specify the upper frame.
400
+ * `down`
401
+ * Specify the lower frame.
402
+
403
+ ### Evaluate
404
+
405
+ * `p <expr>`
406
+ * Evaluate like `p <expr>` on the current frame.
407
+ * `pp <expr>`
408
+ * Evaluate like `pp <expr>` on the current frame.
409
+ * `e[val] <expr>`
410
+ * Evaluate `<expr>` on the current frame.
411
+ * `irb`
412
+ * Invoke `irb` on the current frame.
413
+
414
+ ### Thread control
415
+
416
+ * `th[read]`
417
+ * Show all threads.
418
+ * `th[read] <thnum>`
419
+ * Switch thread specified by `<thnum>`.
420
+
421
+ ### Help
422
+
423
+ * `h[elp]`
424
+ * Show help for all commands.
425
+ * `h[elp] <command>`
426
+ * Show help for the given command.
427
+
428
+
429
+ ## rdbg command help
430
+
41
431
  ```
432
+ exe/rdbg [options] -- [debuggee options]
433
+
434
+ Debug console mode:
435
+ -n, --nonstop Do not stop at the beginning of the script.
436
+ -e [COMMAND] execute debug command at the beginning of the script.
437
+ -O, --open Start debuggee with opening the debugger port.
438
+ If TCP/IP options are not given,
439
+ a UNIX domain socket will be used.
440
+ --port=[PORT] Listening TCP/IP port
441
+ --host=[HOST] Listening TCP/IP host
42
442
 
43
- ## Development
443
+ Debug console mode runs Ruby program with the debug console.
44
444
 
45
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
445
+ rdbg target.rb foo bar starts like 'ruby target.rb foo bar'.
446
+ rdbg -- -r foo -e bar starts like 'ruby -r foo -e bar'.
447
+ rdbg -O target.rb foo bar starts and accepts attaching with UNIX domain socket.
448
+ rdbg -O --port 1234 target.rb foo bar starts accepts attaching with TCP/IP localhost:1234.
449
+ rdbg -O --port 1234 -- -r foo -e bar starts accepts attaching with TCP/IP localhost:1234.
46
450
 
47
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
451
+ Attach mode:
452
+ -A, --attach Attach to debuggee process.
48
453
 
49
- ## Contributing
454
+ Attach mode attaches the remote debug console to the debuggee process.
455
+
456
+ 'rdbg -A' tries to connect via UNIX domain socket.
457
+ If there are multiple processes are waiting for the
458
+ debugger connection, list possible debuggee names.
459
+ 'rdbg -A path' tries to connect via UNIX domain socket with given path name.
460
+ 'rdbg -A port' tries to connect to localhost:port via TCP/IP.
461
+ 'rdbg -A host port' tries to connect to host:port via TCP/IP.
462
+
463
+ ```
50
464
 
51
- Bug reports and pull requests are welcome on GitHub at https://github.com/hsbt/debug.
465
+ # Contributing
52
466
 
467
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/debug.