debug 1.3.4 → 1.6.0

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/tracer.rb CHANGED
@@ -66,15 +66,7 @@ module DEBUGGER__
66
66
  end
67
67
 
68
68
  def skip? tp
69
- if tp.path.start_with?(__dir__) ||
70
- tp.path.start_with?('<internal:') ||
71
- ThreadClient.current.management? ||
72
- skip_path?(tp.path) ||
73
- skip_with_pattern?(tp)
74
- true
75
- else
76
- false
77
- end
69
+ ThreadClient.current.management? || skip_path?(tp.path) || skip_with_pattern?(tp)
78
70
  end
79
71
 
80
72
  def skip_with_pattern?(tp)
@@ -82,18 +74,20 @@ module DEBUGGER__
82
74
  end
83
75
 
84
76
  def out tp, msg = nil, depth = caller.size - 1
85
- location_str = colorize("#{tp.path}:#{tp.lineno}", [:GREEN])
77
+ location_str = colorize("#{FrameInfo.pretty_path(tp.path)}:#{tp.lineno}", [:GREEN])
86
78
  buff = "#{header(depth)}#{msg} at #{location_str}"
87
79
 
88
80
  if false # TODO: Ractor.main?
89
81
  ThreadClient.current.on_trace self.object_id, buff
90
82
  else
91
83
  @output.puts buff
84
+ @output.flush
92
85
  end
93
86
  end
94
87
 
95
88
  def puts msg
96
89
  @output.puts msg
90
+ @output.flush
97
91
  end
98
92
 
99
93
  def minfo tp
@@ -125,7 +119,6 @@ module DEBUGGER__
125
119
  next if skip?(tp)
126
120
 
127
121
  depth = caller.size
128
- sp = ' ' * depth
129
122
 
130
123
  call_identifier_str =
131
124
  if tp.defined_class
@@ -139,10 +132,12 @@ module DEBUGGER__
139
132
  case tp.event
140
133
  when :call, :c_call, :b_call
141
134
  depth += 1 if tp.event == :c_call
135
+ sp = ' ' * depth
142
136
  out tp, ">#{sp}#{call_identifier_str}", depth
143
137
  when :return, :c_return, :b_return
144
138
  depth += 1 if tp.event == :c_return
145
- return_str = colorize_magenta(DEBUGGER__.short_inspect(tp.return_value))
139
+ sp = ' ' * depth
140
+ return_str = colorize_magenta(DEBUGGER__.safe_inspect(tp.return_value, short: true))
146
141
  out tp, "<#{sp}#{call_identifier_str} #=> #{return_str}", depth
147
142
  end
148
143
  }
@@ -191,7 +186,7 @@ module DEBUGGER__
191
186
  @tracer = TracePoint.new(:a_call){|tp|
192
187
  next if skip?(tp)
193
188
 
194
- if tp.self.object_id == @obj_id
189
+ if M_OBJECT_ID.bind_call(tp.self) == @obj_id
195
190
  klass = tp.defined_class
196
191
  method = tp.method_id
197
192
  method_info =
data/lib/debug/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DEBUGGER__
4
- VERSION = "1.3.4"
4
+ VERSION = "1.6.0"
5
5
  end
data/misc/README.md.erb CHANGED
@@ -1,19 +1,23 @@
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)
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) [![Protocol](https://github.com/ruby/debug/actions/workflows/protocol.yml/badge.svg)](https://github.com/ruby/debug/actions/workflows/protocol.yml)
2
2
 
3
3
  # debug.rb
4
4
 
5
- This library provides debugging functionality to Ruby.
5
+ This library provides debugging functionality to Ruby (MRI) 2.6 and later.
6
6
 
7
7
  This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by `set_trace_func`.
8
8
  New debug.rb has several advantages:
9
9
 
10
10
  * Fast: No performance penalty on non-stepping mode and non-breakpoints.
11
11
  * [Remote debugging](#remote-debugging): Support remote debugging natively.
12
- * UNIX domain socket
12
+ * UNIX domain socket (UDS)
13
13
  * TCP/IP
14
- * Integration with rich debugger frontend
15
- * VSCode/DAP ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
16
- * Chrome DevTools
14
+ * Integration with rich debugger frontends
15
+
16
+ Frontend | [Console](https://github.com/ruby/debug#invoke-as-a-remote-debuggee) | [VSCode](https://github.com/ruby/debug#vscode-integration) | [Chrome DevTool](#chrome-devtool-integration) |
17
+ ---|---|---|---|
18
+ Connection | UDS, TCP/IP | UDS, TCP/IP | TCP/IP |
19
+ Requirement | No | [vscode-rdbg](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) | Chrome |
20
+
17
21
  * Extensible: application can introduce debugging support with several ways:
18
22
  * By `rdbg` command
19
23
  * By loading libraries with `-r` command line option
@@ -38,6 +42,9 @@ If you use Bundler, write the following line to your Gemfile.
38
42
  gem "debug", ">= 1.0.0"
39
43
  ```
40
44
 
45
+ (The version constraint is important; `debug < 1.0.0` is an older,
46
+ abandoned gem that is completely different from this product.)
47
+
41
48
  # HOW TO USE
42
49
 
43
50
  To use a debugger, roughly you will do the following steps:
@@ -60,8 +67,14 @@ There are several options for (1) and (2). Please choose your favorite way.
60
67
 
61
68
  ### Modify source code with [`binding.break`](#bindingbreak-method) (similar to `binding.pry` or `binding.irb`)
62
69
 
63
- If you can modify the source code, you can use the debugger by adding `require 'debug'` line at the top of your program and putting [`binding.break`](#bindingbreak-method) method (`binding.b` for short) into lines where you want to stop as breakpoints like `binding.pry` and `binding.irb`.
64
- After that, you run the program as usual and you will enter the debug console at breakpoints you inserted.
70
+ If you can modify the source code, you can use the debugger by adding `require 'debug'` at the top of your program and putting [`binding.break`](#bindingbreak-method) method into lines where you want to stop as breakpoints like `binding.pry` and `binding.irb`.
71
+
72
+ You can also use its 2 aliases in the same way:
73
+
74
+ - `binding.b`
75
+ - `debugger`
76
+
77
+ After that, run the program as usual and you will enter the debug console at breakpoints you inserted.
65
78
 
66
79
  The following example shows the demonstration of [`binding.break`](#bindingbreak-method).
67
80
 
@@ -107,7 +120,7 @@ d => nil
107
120
  5| binding.break
108
121
  6| c = 3
109
122
  7| d = 4
110
- => 8| binding.break # Again the program stops at here
123
+ => 8| binding.break # Again the program stops here
111
124
  9| p [a, b, c, d]
112
125
  10|
113
126
  11| __END__
@@ -128,7 +141,7 @@ d => 4
128
141
  ### Invoke the program from the debugger as a traditional debuggers
129
142
 
130
143
  If you don't want to modify the source code, you can set breakpoints with a debug command `break` (`b` for short).
131
- Using `rdbg` command to launch the program without any modifications, you can run the program with the debugger.
144
+ Using `rdbg` command (or `bundle exec rdbg`) to launch the program without any modifications, you can run the program with the debugger.
132
145
 
133
146
  ```shell
134
147
  $ cat target.rb # Sample program
@@ -274,7 +287,12 @@ You can run your application as a remote debuggee and the remote debugger consol
274
287
 
275
288
  ### Invoke as a remote debuggee
276
289
 
277
- There are two ways to invoke a script as remote debuggee: Use `rdbg --open` and require `debug/open` (or `debug/open_nonstop`).
290
+ There are multiple ways to run your program as a debuggee:
291
+
292
+ Stop at program start | [`rdbg` option](https://github.com/ruby/debug#rdbg---open-or-rdbg--o-for-short) | [require](https://github.com/ruby/debug#require-debugopen-in-a-program) | [debugger API](https://github.com/ruby/debug#start-by-method)
293
+ ---|---|---|---|
294
+ Yes | `rdbg --open` | `require "debug/open"` | `DEBUGGER__.open`
295
+ No | `rdbg --open --nonstop` | `require "debug/open_nonstop"` | `DEBUGGER__.open(nonstop: true)`
278
296
 
279
297
  #### `rdbg --open` (or `rdbg -O` for short)
280
298
 
@@ -346,12 +364,14 @@ You can attach with external debugger frontend with VSCode and Chrome.
346
364
  $ rdbg --open=[frontend] target.rb
347
365
  ```
348
366
 
349
- will open a debug port and `[frontned]` can attache to the port.
367
+ will open a debug port and `[frontend]` can attach to the port.
350
368
 
351
369
  Also `open` command allows opening the debug port.
352
370
 
353
371
  #### VSCode integration
354
372
 
373
+ ([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required)
374
+
355
375
  If you don't run a debuggee Ruby process on VSCode, you can attach with VSCode later with the following steps.
356
376
 
357
377
  `rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command).
@@ -411,7 +431,7 @@ Note that you can attach with `rdbg --attach` and continue REPL debugging.
411
431
 
412
432
  #### Chrome DevTool integration
413
433
 
414
- With `rdbg --open=chrome` command will shows the following message.
434
+ With `rdbg --open=chrome` command will show the following message.
415
435
 
416
436
  ```
417
437
  $ rdbg target.rb --open=chrome
@@ -427,7 +447,7 @@ Type `devtools://devtools/bundled/inspector.html?ws=127.0.0.1:43633` in the addr
427
447
 
428
448
  Also `open chrome` command works like `open vscode`.
429
449
 
430
- For more information about how to use Chrome debugging, you might want to read [here](https://developer.chrome.com/docs/devtools/)
450
+ For more information about how to use Chrome debugging, you might want to read [here](https://developer.chrome.com/docs/devtools/).
431
451
 
432
452
  ## Configuration
433
453
 
@@ -444,10 +464,18 @@ config set log_level INFO
444
464
  config set no_color true
445
465
  ```
446
466
 
447
- <% cat = nil; DEBUGGER__::CONFIG_SET.each do |key, (env, desc)| %>
467
+ <% cat = nil; DEBUGGER__::CONFIG_SET.each do |key, (env, desc, _, default)| %>
448
468
  <% /\A(\w+): (.+)/ =~ desc; if cat != $1; cat = 1 %>
449
469
  * <%= $1 %>
450
- <% cat = $1; end %> * `<%= env %>` (`<%= key %>`): <%= $2 %><% end %>
470
+ <% cat = $1; end %> * `<%= env %>` (`<%= key %>`): <%= default ? "#{$2} (default: #{default})" : $2 %><% end %>
471
+
472
+ There are other environment variables:
473
+
474
+ * `NO_COLOR`: If the value is set, set `RUBY_DEBUG_NO_COLOR` ([NO_COLOR: disabling ANSI color output in various Unix commands](https://no-color.org/)).
475
+ * `RUBY_DEBUG_ENABLE`: If the value is `0`, do not enable debug.gem feature.
476
+ * `RUBY_DEBUG_ADDED_RUBYOPT`: Remove this value from `RUBYOPT` at first. This feature helps loading debug.gem with `RUBYOPT='-r debug/...'` and you don't want to derive it to child processes. In this case you can set `RUBY_DEBUG_ADDED_RUBYOPT='-r debug/...'` (same value) and this string will be deleted from `RUBYOPT` at first.
477
+ * `RUBY_DEBUG_EDITOR` or `EDITOR`: An editor used by `edit` debug command.
478
+ * `RUBY_DEBUG_BB`: Define `Kernel#bb` method which is alias of `Kernel#debugger`.
451
479
 
452
480
  ### Initial scripts
453
481
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.6.0
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-10-29 00:00:00.000000000 Z
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb
@@ -30,16 +30,16 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.7
33
+ version: 0.3.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.7
40
+ version: 0.3.1
41
41
  description: Debugging functionality for Ruby. This is completely rewritten debug.rb
42
- which was contained by the encient Ruby versions.
42
+ which was contained by the ancient Ruby versions.
43
43
  email:
44
44
  - ko1@atdot.net
45
45
  executables:
@@ -48,27 +48,18 @@ extensions:
48
48
  - ext/debug/extconf.rb
49
49
  extra_rdoc_files: []
50
50
  files:
51
- - ".github/ISSUE_TEMPLATE/bug_report.md"
52
- - ".github/ISSUE_TEMPLATE/custom.md"
53
- - ".github/ISSUE_TEMPLATE/feature_request.md"
54
- - ".github/workflows/ruby.yml"
55
- - ".gitignore"
56
51
  - CONTRIBUTING.md
57
52
  - Gemfile
58
53
  - LICENSE.txt
59
54
  - README.md
60
55
  - Rakefile
61
56
  - TODO.md
62
- - bin/console
63
- - bin/gentest
64
- - bin/setup
65
57
  - debug.gemspec
66
58
  - exe/rdbg
67
59
  - ext/debug/debug.c
68
60
  - ext/debug/extconf.rb
69
61
  - ext/debug/iseq_collector.c
70
62
  - lib/debug.rb
71
- - lib/debug/bp.vim
72
63
  - lib/debug/breakpoint.rb
73
64
  - lib/debug/client.rb
74
65
  - lib/debug/color.rb
@@ -111,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
102
  - !ruby/object:Gem::Version
112
103
  version: '0'
113
104
  requirements: []
114
- rubygems_version: 3.1.6
105
+ rubygems_version: 3.3.7
115
106
  signing_key:
116
107
  specification_version: 4
117
108
  summary: Debugging functionality for Ruby
@@ -1,24 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Your environment**
11
-
12
- * `ruby -v`:
13
- * `rdbg -v`:
14
-
15
- **Describe the bug**
16
- A clear and concise description of what the bug is.
17
-
18
- **To Reproduce**
19
-
20
- **Expected behavior**
21
- A clear and concise description of what you expected to happen.
22
-
23
- **Additional context**
24
- Add any other context about the problem here.
@@ -1,10 +0,0 @@
1
- ---
2
- name: Custom issue template
3
- about: Blank issue
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
-
@@ -1,14 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Your proposal**
11
- What is your idea?
12
-
13
- **Additional context**
14
- Add any other context or screenshots about the feature request here.
@@ -1,34 +0,0 @@
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 DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.bundle
10
- /Gemfile.lock
11
- /lib/debug/debug.so
12
- .ruby-version
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "debug"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/gentest DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
-
5
- require_relative '../test/tool/test_builder'
6
-
7
- file_info = {}
8
-
9
- OptionParser.new do |opt|
10
- opt.banner = 'Usage: bin/gentest [file] [option]'
11
- opt.on('-m METHOD', 'Method name in the test file') do |m|
12
- file_info[:method] = m
13
- end
14
- opt.on('-c CLASS', 'Class name in the test file') do |c|
15
- file_info[:class] = c
16
- end
17
- opt.parse!(ARGV)
18
- end
19
-
20
- exit if ARGV.empty?
21
-
22
- DEBUGGER__::TestBuilder.new(ARGV, file_info[:method], file_info[:class]).start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/debug/bp.vim DELETED
@@ -1,68 +0,0 @@
1
- let g:rdb_bps = {}
2
-
3
- function SET_BP()
4
- let signed = sign_getplaced(bufname(), {'lnum': line('.')})
5
- if empty(signed[0]['signs'])
6
- call sign_place(0, '', 'signBP', bufname(), {'lnum': line('.')})
7
- else
8
- "echo signed[0]['signs']
9
- call sign_unplace('', {'buffer': bufname(), 'id': signed[0]['signs'][0]['id']})
10
- endif
11
- endfunction
12
-
13
- function UPDATE_BPS()
14
- let signs = sign_getplaced(bufname())
15
- let key = expand('%:p')
16
-
17
- if empty(signs[0]['signs'])
18
- let removed = remove(g:rdb_bps, key)
19
- else
20
- let g:rdb_bps[key] = signs[0]['signs']
21
- endif
22
- endfunction
23
-
24
- function APPLY_BPS()
25
- let key = expand('%:p')
26
- if has_key(g:rdb_bps, key)
27
- for b in g:rdb_bps[key]
28
- call sign_place(0, '', 'signBP', bufname(), {'lnum': b['lnum']})
29
- endfor
30
- endif
31
- endfunction
32
-
33
- function WRITE_BPS()
34
- call writefile([json_encode(g:rdb_bps)], '.rdb_breakpoints.json')
35
- endfunction
36
-
37
- " load
38
- try
39
- let json = readfile('.rdb_breakpoints.json')
40
- let g:rdb_bps = json_decode(json[0])
41
- " {"/full/path/to/file1": [{"lnum": 10}, ...], ...}
42
- catch /Can't open/
43
- let g:rdb_bps = {}
44
- catch /Invalid arguments for function json_decode/
45
- let g:rdb_bps = {}
46
- endtry
47
-
48
- sign define signBP text=BR
49
-
50
- call APPLY_BPS()
51
-
52
- autocmd BufReadPost * call APPLY_BPS()
53
- autocmd BufUnload * call UPDATE_BPS()
54
- autocmd VimLeave * call WRITE_BPS()
55
-
56
- function! s:ruby_bp_settings() abort
57
- echomsg "Type <Space> to toggle break points and <q> to quit"
58
-
59
- if &readonly
60
- nnoremap <silent> <buffer> <Space> :call SET_BP()<CR>
61
- nnoremap <silent> <buffer> q :<C-u>quit<CR>
62
- endif
63
- endfunction
64
-
65
- " autocmd FileType ruby call s:ruby_bp_settings()
66
- autocmd BufEnter *.rb call s:ruby_bp_settings()
67
-
68
- call s:ruby_bp_settings()