debug 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3e49208dc5aafac57624c1bfb06a1f1d4975bc1a3ea1739b170cd97b4805f80
4
- data.tar.gz: 631bb42bb4bb78cb6bda141e062e317edfb49fc01bbf6e4ca65036efc5175c12
3
+ metadata.gz: 5e9851059a728e477461cc318c9b94932fa0aeb19215f936ab6c25cf62f67cd0
4
+ data.tar.gz: b050eee3dbf0afecfda2c1221fe38ab678808405c10f89d5832a1950e2728aa8
5
5
  SHA512:
6
- metadata.gz: 03d36a4f2ba792570d77206897e112e74947cf951f36dbd62b94f6faefbc431735b92da833682b1e768368e9393051cc7efea784daf853ab6d927b57780ca780
7
- data.tar.gz: 837963016cb3d8cb932796706323761ecbcdda55d9c8da0cc68d1d324ad92018e06959489273edbb7a3f0fadc817d699dd744266a3e48ce6ce1647370a77cd1d
6
+ metadata.gz: a15549ee06b890a32d0960dd24a99c4c925d66b5f6512a7e5ff3052f10ca3a255038d44eaa2d10046cbe2b68bca121c813db3a8e5fea68def5dcd2e1797864d7
7
+ data.tar.gz: '058b5ef8c6e40a8ccfa12b62b09c8808c1b524c398e37a25ffd790b8a8e0364026911478019d06100b7a6d8fde878dd7695f2f2630f3f35f37f12695b84b2ddf'
data/README.md CHANGED
@@ -8,7 +8,7 @@ This debug.rb is replacement of traditional lib/debug.rb standard library which
8
8
  New debug.rb has several advantages:
9
9
 
10
10
  * Fast: No performance penalty on non-stepping mode and non-breakpoints.
11
- * Remote debugging: Support remote debugging natively.
11
+ * [Remote debugging](#remote-debugging): Support remote debugging natively.
12
12
  * UNIX domain socket
13
13
  * TCP/IP
14
14
  * VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
@@ -44,22 +44,24 @@ To use a debugger, roughly you will do the following steps:
44
44
  2. Run a program with the debugger.
45
45
  3. At the breakpoint, enter the debugger console.
46
46
  4. Use debug commands.
47
- * Query the program status (e.g. `p lvar` to see the local variable `lvar`).
48
- * Control program flow (e.g. move to the another line with `step`, to the next line with `next`).
49
- * Set another breakpoint (e.g. `catch Exception` to set a breakpoint when `Exception` is raised).
50
- * Change the configuration (e.g. `config set no_color true` to disable coloring).
47
+ * [Evaluate Ruby expressions](#evaluate) (e.g. `p lvar` to see the local variable `lvar`).
48
+ * [Query the program status](#information) (e.g. `info` to see information about the current frame).
49
+ * [Control program flow](#control-flow) (e.g. move to the another line with `step`, to the next line with `next`).
50
+ * [Set another breakpoint](#breakpoint) (e.g. `catch Exception` to set a breakpoint that'll be triggered when `Exception` is raised).
51
+ * [Activate tracing in your program](#trace) (e.g. `trace call` to trace method calls).
52
+ * [Change the configuration](#configuration-1) (e.g. `config set no_color true` to disable coloring).
51
53
  * Continue the program (`c` or `continue`) and goto 3.
52
54
 
53
55
  ## Invoke with the debugger
54
56
 
55
57
  There are several options for (1) and (2). Please choose your favorite way.
56
58
 
57
- ### Modify source code as `binding.pry` and `binding.irb`
59
+ ### Modify source code with [`binding.break`](#bindingbreak-method) (similar to `binding.pry` or `binding.irb`)
58
60
 
59
- 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` method (`binding.b` for short) into lines where you want to stop as breakpoints like `binding.pry` and `binding.irb`.
61
+ 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`.
60
62
  After that, you run the program as usual and you will enter the debug console at breakpoints you inserted.
61
63
 
62
- The following example shows the demonstration of `binding.break`.
64
+ The following example shows the demonstration of [`binding.break`](#bindingbreak-method).
63
65
 
64
66
  ```shell
65
67
  $ cat target.rb # Sample program
@@ -355,7 +357,7 @@ config set no_color true
355
357
  * `RUBY_DEBUG_LOG_LEVEL` (`log_level`): Log level same as Logger (default: WARN)
356
358
  * `RUBY_DEBUG_SHOW_SRC_LINES` (`show_src_lines`): Show n lines source code on breakpoint (default: 10 lines)
357
359
  * `RUBY_DEBUG_SHOW_FRAMES` (`show_frames`): Show n frames on breakpoint (default: 2 frames)
358
- * `RUBY_DEBUG_USE_SHORT_PATH` (`use_short_path`): Show shoten PATH (like $(Gem)/foo.rb)
360
+ * `RUBY_DEBUG_USE_SHORT_PATH` (`use_short_path`): Show shorten PATH (like $(Gem)/foo.rb)
359
361
  * `RUBY_DEBUG_NO_COLOR` (`no_color`): Do not use colorize (default: false)
360
362
  * `RUBY_DEBUG_NO_SIGINT_HOOK` (`no_sigint_hook`): Do not suspend on SIGINT (default: false)
361
363
  * `RUBY_DEBUG_NO_RELINE` (`no_reline`): Do not use Reline library (default: false)
@@ -494,7 +496,7 @@ The `<...>` notation means the argument.
494
496
  * Show information about the current frame (local variables)
495
497
  * It includes `self` as `%self` and a return value as `%return`.
496
498
  * `i[nfo] i[var[s]]` or `i[nfo] instance`
497
- * Show information about insttance variables about `self`.
499
+ * Show information about instance variables about `self`.
498
500
  * `i[nfo] c[onst[s]]` or `i[nfo] constant[s]`
499
501
  * Show information about accessible constants except toplevel constants.
500
502
  * `i[nfo] g[lobal[s]]`
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ Rake::ExtensionTask.new("debug") do |ext|
15
15
  ext.lib_dir = "lib/debug"
16
16
  end
17
17
 
18
- task :default => [:clobber, :compile, :test, 'README.md']
18
+ task :default => [:clobber, :compile, 'README.md', :test]
19
19
 
20
20
  file 'README.md' => ['lib/debug/session.rb', 'lib/debug/config.rb',
21
21
  'exe/rdbg', 'misc/README.md.erb'] do
data/TODO.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Basic functionality
4
4
 
5
5
  * Support Ractors
6
- * Signal (SIGINT) trap handling
6
+ * Signal (SIGINT) trap handling
7
7
 
8
8
  ## UI
9
9
 
@@ -12,6 +12,7 @@
12
12
  * Interactive record & play debugging
13
13
  * irb integration
14
14
  * Web browser integrated UI
15
+ * History file
15
16
 
16
17
  ## Debug command
17
18
 
data/lib/debug/config.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DEBUGGER__
4
+ LOG_LEVELS = {
5
+ UNKNOWN: 0,
6
+ FATAL: 1,
7
+ ERROR: 2,
8
+ WARN: 3,
9
+ INFO: 4,
10
+ }.freeze
11
+
4
12
  CONFIG_SET = {
5
13
  # UI setting
6
14
  log_level: ['RUBY_DEBUG_LOG_LEVEL', "UI: Log level same as Logger (default: WARN)", :loglevel],
7
15
  show_src_lines: ['RUBY_DEBUG_SHOW_SRC_LINES', "UI: Show n lines source code on breakpoint (default: 10 lines)", :int],
8
16
  show_frames: ['RUBY_DEBUG_SHOW_FRAMES', "UI: Show n frames on breakpoint (default: 2 frames)", :int],
9
- use_short_path: ['RUBY_DEBUG_USE_SHORT_PATH', "UI: Show shoten PATH (like $(Gem)/foo.rb)", :bool],
17
+ use_short_path: ['RUBY_DEBUG_USE_SHORT_PATH', "UI: Show shorten PATH (like $(Gem)/foo.rb)", :bool],
10
18
  no_color: ['RUBY_DEBUG_NO_COLOR', "UI: Do not use colorize (default: false)", :bool],
11
19
  no_sigint_hook: ['RUBY_DEBUG_NO_SIGINT_HOOK', "UI: Do not suspend on SIGINT (default: false)", :bool],
12
20
  no_reline: ['RUBY_DEBUG_NO_RELINE', "UI: Do not use Reline library (default: false)", :bool],
@@ -372,7 +380,7 @@ module DEBUGGER__
372
380
  desc = cat = nil
373
381
  cmds = Hash.new
374
382
 
375
- File.read(File.join(__dir__, 'session.rb')).each_line do |line|
383
+ File.read(File.join(__dir__, 'session.rb'), encoding: Encoding::UTF_8).each_line do |line|
376
384
  case line
377
385
  when /\A\s*### (.+)/
378
386
  cat = $1
@@ -153,8 +153,8 @@ module DEBUGGER__
153
153
  when 'setFunctionBreakpoints'
154
154
  send_response req
155
155
  when 'setExceptionBreakpoints'
156
- filters = args.dig('filterOptions').map{|bp_info|
157
- case bp_info.dig('filterId')
156
+ process_filter = ->(filter_id) {
157
+ case filter_id
158
158
  when 'any'
159
159
  bp = SESSION.add_catch_breakpoint 'Exception'
160
160
  when 'RuntimeError'
@@ -163,10 +163,19 @@ module DEBUGGER__
163
163
  bp = nil
164
164
  end
165
165
  {
166
- verifiled: bp ? true : false,
166
+ verified: bp ? true : false,
167
167
  message: bp.inspect,
168
168
  }
169
169
  }
170
+
171
+ filters = args.fetch('filters').map {|filter_id|
172
+ process_filter.call(filter_id)
173
+ }
174
+
175
+ filters += args.fetch('filterOptions', {}).map{|bp_info|
176
+ process_filter.call(bp_info.dig('filterId'))
177
+ }
178
+
170
179
  send_response req, breakpoints: filters
171
180
  when 'configurationDone'
172
181
  send_response req
@@ -354,7 +363,7 @@ module DEBUGGER__
354
363
  fail_response req
355
364
  end
356
365
  else
357
- raise "Uknown type: #{ref.inspect}"
366
+ raise "Unknown type: #{ref.inspect}"
358
367
  end
359
368
  else
360
369
  fail_response req
@@ -471,7 +480,7 @@ module DEBUGGER__
471
480
  fid = args.shift
472
481
  frame = @target_frames[fid]
473
482
 
474
- lnum =
483
+ lnum =
475
484
  if frame.binding
476
485
  frame.binding.local_variables.size
477
486
  elsif vars = frame.local_variables
@@ -580,7 +589,7 @@ module DEBUGGER__
580
589
  end
581
590
  event! :dap_result, :evaluate, req, tid: self.id, **evaluate_result(result)
582
591
  else
583
- raise "Unkown req: #{args.inspect}"
592
+ raise "Unknown req: #{args.inspect}"
584
593
  end
585
594
  end
586
595
 
data/lib/debug/session.rb CHANGED
@@ -1,7 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # skip to load debugger for bundle exec
4
- return if $0.end_with?('bin/bundle') && ARGV.first == 'exec'
4
+
5
+ if $0.end_with?('bin/bundle') && ARGV.first == 'exec'
6
+ trace_var(:$0) do |file|
7
+ trace_var(:$0, nil)
8
+ if /-r (#{__dir__}\S+)/ =~ ENV['RUBYOPT']
9
+ lib = $1
10
+ $LOADED_FEATURES.delete_if{|path| path.start_with?(__dir__)}
11
+ ENV['RUBY_DEBUG_INITIAL_SUSPEND_PATH'] = file
12
+ require lib
13
+ ENV['RUBY_DEBUG_INITIAL_SUSPEND_PATH'] = nil
14
+ end
15
+ end
16
+
17
+ return
18
+ end
5
19
 
6
20
  require_relative 'config'
7
21
  require_relative 'thread_client'
@@ -9,6 +23,10 @@ require_relative 'source_repository'
9
23
  require_relative 'breakpoint'
10
24
  require_relative 'tracer'
11
25
 
26
+ # To prevent loading old lib/debug.rb in Ruby 2.6 to 3.0
27
+ $LOADED_FEATURES << 'debug.rb'
28
+ require 'debug' # invalidate the $LOADED_FEATURE cache
29
+
12
30
  require 'json' if ENV['RUBY_DEBUG_TEST_MODE']
13
31
 
14
32
  class RubyVM::InstructionSequence
@@ -159,7 +177,7 @@ module DEBUGGER__
159
177
 
160
178
  def session_server_main
161
179
  while evt = pop_event
162
- # varible `@internal_info` is only used for test
180
+ # variable `@internal_info` is only used for test
163
181
  tc, output, ev, @internal_info, *ev_args = evt
164
182
  output.each{|str| @ui.puts str}
165
183
 
@@ -598,7 +616,7 @@ module DEBUGGER__
598
616
  # * Show information about the current frame (local variables)
599
617
  # * It includes `self` as `%self` and a return value as `%return`.
600
618
  # * `i[nfo] i[var[s]]` or `i[nfo] instance`
601
- # * Show information about insttance variables about `self`.
619
+ # * Show information about instance variables about `self`.
602
620
  # * `i[nfo] c[onst[s]]` or `i[nfo] constant[s]`
603
621
  # * Show information about accessible constants except toplevel constants.
604
622
  # * `i[nfo] g[lobal[s]]`
@@ -1507,7 +1525,10 @@ module DEBUGGER__
1507
1525
 
1508
1526
  def self.setup_initial_suspend
1509
1527
  if !CONFIG[:nonstop]
1510
- if loc = ::DEBUGGER__.require_location
1528
+ case
1529
+ when path = ENV['RUBY_DEBUG_INITIAL_SUSPEND_PATH']
1530
+ add_line_breakpoint path, 0, oneshot: true, hook_call: false
1531
+ when loc = ::DEBUGGER__.require_location
1511
1532
  # require 'debug/start' or 'debug'
1512
1533
  add_line_breakpoint loc.absolute_path, loc.lineno + 1, oneshot: true, hook_call: false
1513
1534
  else
@@ -1519,29 +1540,8 @@ module DEBUGGER__
1519
1540
 
1520
1541
  class << self
1521
1542
  define_method :initialize_session do |ui|
1522
- DEBUGGER__.warn "Session start (pid: #{Process.pid})"
1523
-
1543
+ DEBUGGER__.info "Session start (pid: #{Process.pid})"
1524
1544
  ::DEBUGGER__.const_set(:SESSION, Session.new(ui))
1525
-
1526
- # default breakpoints
1527
-
1528
- # ::DEBUGGER__.add_catch_breakpoint 'RuntimeError'
1529
-
1530
- Binding.module_eval do
1531
- def break pre: nil, do: nil
1532
- return unless SESSION.active?
1533
-
1534
- if pre || (do_expr = binding.local_variable_get(:do))
1535
- cmds = ['binding.break', pre, do_expr]
1536
- end
1537
-
1538
- ::DEBUGGER__.add_line_breakpoint __FILE__, __LINE__ + 1, oneshot: true, command: cmds
1539
- true
1540
- end
1541
- alias b break
1542
- # alias bp break
1543
- end
1544
-
1545
1545
  load_rc
1546
1546
  end
1547
1547
  end
@@ -1599,14 +1599,6 @@ module DEBUGGER__
1599
1599
  end
1600
1600
  end
1601
1601
 
1602
- LOG_LEVELS = {
1603
- UNKNOWN: 0,
1604
- FATAL: 1,
1605
- ERROR: 2,
1606
- WARN: 3,
1607
- INFO: 4,
1608
- }.freeze
1609
-
1610
1602
  def self.warn msg
1611
1603
  log :WARN, msg
1612
1604
  end
@@ -1694,3 +1686,31 @@ module DEBUGGER__
1694
1686
  end
1695
1687
  end
1696
1688
 
1689
+ class Binding
1690
+ def break pre: nil, do: nil
1691
+ return if !defined?(::DEBUGGER__::SESSION) || !::DEBUGGER__::SESSION.active?
1692
+
1693
+ if pre || (do_expr = binding.local_variable_get(:do))
1694
+ cmds = ['binding.break', pre, do_expr]
1695
+ end
1696
+
1697
+ ::DEBUGGER__.add_line_breakpoint __FILE__, __LINE__ + 1, oneshot: true, command: cmds
1698
+ self
1699
+ end
1700
+ alias b break
1701
+ end
1702
+
1703
+ module Kernel
1704
+ if RUBY_VERSION >= '2.7.0'
1705
+ eval <<~RUBY, binding, __FILE__, __LINE__
1706
+ def debugger(...)
1707
+ binding.break(...)
1708
+ end
1709
+ RUBY
1710
+ else
1711
+ def debugger pre: nil, do: nil
1712
+ b = binding
1713
+ b.break pre: pre, do: b.local_variable_get(:do)
1714
+ end
1715
+ end
1716
+ end
data/lib/debug/tracer.rb CHANGED
@@ -216,7 +216,7 @@ module DEBUGGER__
216
216
  out tp, " #{colorized_obj_inspect} is used as a parameter #{colorized_name} of #{method_info}"
217
217
  end
218
218
  when :rest
219
- next name == :"*"
219
+ next if name == :"*"
220
220
 
221
221
  ary = b.local_variable_get(name)
222
222
  ary.each{|e|
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.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/misc/README.md.erb CHANGED
@@ -8,7 +8,7 @@ This debug.rb is replacement of traditional lib/debug.rb standard library which
8
8
  New debug.rb has several advantages:
9
9
 
10
10
  * Fast: No performance penalty on non-stepping mode and non-breakpoints.
11
- * Remote debugging: Support remote debugging natively.
11
+ * [Remote debugging](#remote-debugging): Support remote debugging natively.
12
12
  * UNIX domain socket
13
13
  * TCP/IP
14
14
  * VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
@@ -44,22 +44,24 @@ To use a debugger, roughly you will do the following steps:
44
44
  2. Run a program with the debugger.
45
45
  3. At the breakpoint, enter the debugger console.
46
46
  4. Use debug commands.
47
- * Query the program status (e.g. `p lvar` to see the local variable `lvar`).
48
- * Control program flow (e.g. move to the another line with `step`, to the next line with `next`).
49
- * Set another breakpoint (e.g. `catch Exception` to set a breakpoint when `Exception` is raised).
50
- * Change the configuration (e.g. `config set no_color true` to disable coloring).
47
+ * [Evaluate Ruby expressions](#evaluate) (e.g. `p lvar` to see the local variable `lvar`).
48
+ * [Query the program status](#information) (e.g. `info` to see information about the current frame).
49
+ * [Control program flow](#control-flow) (e.g. move to the another line with `step`, to the next line with `next`).
50
+ * [Set another breakpoint](#breakpoint) (e.g. `catch Exception` to set a breakpoint that'll be triggered when `Exception` is raised).
51
+ * [Activate tracing in your program](#trace) (e.g. `trace call` to trace method calls).
52
+ * [Change the configuration](#configuration-1) (e.g. `config set no_color true` to disable coloring).
51
53
  * Continue the program (`c` or `continue`) and goto 3.
52
54
 
53
55
  ## Invoke with the debugger
54
56
 
55
57
  There are several options for (1) and (2). Please choose your favorite way.
56
58
 
57
- ### Modify source code as `binding.pry` and `binding.irb`
59
+ ### Modify source code with [`binding.break`](#bindingbreak-method) (similar to `binding.pry` or `binding.irb`)
58
60
 
59
- 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` method (`binding.b` for short) into lines where you want to stop as breakpoints like `binding.pry` and `binding.irb`.
61
+ 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`.
60
62
  After that, you run the program as usual and you will enter the debug console at breakpoints you inserted.
61
63
 
62
- The following example shows the demonstration of `binding.break`.
64
+ The following example shows the demonstration of [`binding.break`](#bindingbreak-method).
63
65
 
64
66
  ```shell
65
67
  $ cat target.rb # Sample program
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.0.0
4
+ version: 1.1.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-09-08 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb