debug 1.4.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +210 -6
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +0 -0
  5. data/README.md +161 -85
  6. data/Rakefile +33 -10
  7. data/TODO.md +8 -8
  8. data/debug.gemspec +9 -7
  9. data/exe/rdbg +23 -4
  10. data/ext/debug/debug.c +111 -21
  11. data/ext/debug/extconf.rb +23 -0
  12. data/ext/debug/iseq_collector.c +2 -0
  13. data/lib/debug/abbrev_command.rb +77 -0
  14. data/lib/debug/breakpoint.rb +102 -74
  15. data/lib/debug/client.rb +46 -12
  16. data/lib/debug/color.rb +0 -0
  17. data/lib/debug/config.rb +129 -36
  18. data/lib/debug/console.rb +46 -40
  19. data/lib/debug/dap_custom/traceInspector.rb +336 -0
  20. data/lib/debug/frame_info.rb +40 -25
  21. data/lib/debug/irb_integration.rb +37 -0
  22. data/lib/debug/local.rb +17 -11
  23. data/lib/debug/open.rb +0 -0
  24. data/lib/debug/open_nonstop.rb +0 -0
  25. data/lib/debug/prelude.rb +3 -2
  26. data/lib/debug/server.rb +126 -56
  27. data/lib/debug/server_cdp.rb +673 -248
  28. data/lib/debug/server_dap.rb +497 -261
  29. data/lib/debug/session.rb +899 -441
  30. data/lib/debug/source_repository.rb +122 -49
  31. data/lib/debug/start.rb +1 -1
  32. data/lib/debug/thread_client.rb +460 -155
  33. data/lib/debug/tracer.rb +10 -16
  34. data/lib/debug/version.rb +1 -1
  35. data/lib/debug.rb +7 -2
  36. data/misc/README.md.erb +106 -56
  37. metadata +14 -24
  38. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -24
  39. data/.github/ISSUE_TEMPLATE/custom.md +0 -10
  40. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
  41. data/.github/pull_request_template.md +0 -9
  42. data/.github/workflows/ruby.yml +0 -34
  43. data/.gitignore +0 -12
  44. data/bin/console +0 -14
  45. data/bin/gentest +0 -30
  46. data/bin/setup +0 -8
  47. data/lib/debug/bp.vim +0 -68
@@ -4,72 +4,145 @@ require_relative 'color'
4
4
 
5
5
  module DEBUGGER__
6
6
  class SourceRepository
7
- SrcInfo = Struct.new(:src, :colored)
7
+ include Color
8
8
 
9
- def initialize
10
- @files = {} # filename => SrcInfo
9
+ def file_src iseq
10
+ if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
11
+ File.readlines(path, chomp: true)
12
+ end
11
13
  end
12
14
 
13
- def add iseq, src
14
- if (path = iseq.absolute_path) && File.exist?(path)
15
- add_path path
16
- elsif src
17
- add_iseq iseq, src
15
+ def get iseq
16
+ return unless iseq
17
+
18
+ if CONFIG[:show_evaledsrc]
19
+ orig_src(iseq) || file_src(iseq)
20
+ else
21
+ file_src(iseq) || orig_src(iseq)
18
22
  end
19
23
  end
20
24
 
21
- def all_iseq iseq, rs = []
22
- rs << iseq
23
- iseq.each_child{|ci|
24
- all_iseq(ci, rs)
25
- }
26
- rs
27
- end
25
+ if defined?(RubyVM.keep_script_lines)
26
+ # Ruby 3.1 and later
27
+ RubyVM.keep_script_lines = true
28
+ require 'objspace'
28
29
 
29
- private def add_iseq iseq, src
30
- line = iseq.first_line
31
- if line > 1
32
- src = ("\n" * (line - 1)) + src
30
+ def initialize
31
+ # cache
32
+ @cmap = ObjectSpace::WeakMap.new
33
+ @loaded_file_map = {} # path => nil
33
34
  end
34
- si = SrcInfo.new(src.lines)
35
35
 
36
- all_iseq(iseq).each{|e|
37
- e.instance_variable_set(:@debugger_si, si)
38
- e.freeze
39
- }
40
- end
36
+ def add iseq, src
37
+ # only manage loaded file names
38
+ if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
39
+ if @loaded_file_map.has_key? path
40
+ return path, true # reloaded
41
+ else
42
+ @loaded_file_map[path] = path
43
+ return path, false
44
+ end
45
+ end
46
+ end
41
47
 
42
- private def add_path path
43
- src = File.read(path)
44
- src = src.gsub("\r\n", "\n") # CRLF -> LF
45
- @files[path] = SrcInfo.new(src.lines)
46
- rescue SystemCallError
47
- end
48
+ def orig_src iseq
49
+ lines = iseq.script_lines&.map(&:chomp)
50
+ line = iseq.first_line
51
+ if line > 1
52
+ [*([''] * (line - 1)), *lines]
53
+ else
54
+ lines
55
+ end
56
+ end
48
57
 
49
- private def get_si iseq
50
- return unless iseq
58
+ def get_colored iseq
59
+ if lines = @cmap[iseq]
60
+ lines
61
+ else
62
+ if src_lines = get(iseq)
63
+ @cmap[iseq] = colorize_code(src_lines.join("\n")).lines
64
+ else
65
+ nil
66
+ end
67
+ end
68
+ end
69
+ else
70
+ # ruby 3.0 or earlier
71
+ SrcInfo = Struct.new(:src, :colored)
51
72
 
52
- if iseq.instance_variable_defined?(:@debugger_si)
53
- iseq.instance_variable_get(:@debugger_si)
54
- elsif @files.has_key?(path = iseq.absolute_path)
55
- @files[path]
56
- elsif path
57
- add_path(path)
73
+ def initialize
74
+ @files = {} # filename => SrcInfo
58
75
  end
59
- end
60
76
 
61
- def get iseq
62
- if si = get_si(iseq)
63
- si.src
77
+ def add iseq, src
78
+ path = (iseq.absolute_path || iseq.path)
79
+
80
+ if path && File.exist?(path)
81
+ reloaded = @files.has_key? path
82
+
83
+ if src
84
+ add_iseq iseq, src
85
+ return path, reloaded
86
+ else
87
+ add_path path
88
+ return path, reloaded
89
+ end
90
+ else
91
+ add_iseq iseq, src
92
+ nil
93
+ end
64
94
  end
65
- end
66
95
 
67
- include Color
96
+ private def all_iseq iseq, rs = []
97
+ rs << iseq
98
+ iseq.each_child{|ci|
99
+ all_iseq(ci, rs)
100
+ }
101
+ rs
102
+ end
103
+
104
+ private def add_iseq iseq, src
105
+ line = iseq.first_line
106
+ if line > 1
107
+ src = ("\n" * (line - 1)) + src
108
+ end
109
+
110
+ si = SrcInfo.new(src.each_line.map{|l| l.chomp})
111
+ all_iseq(iseq).each{|e|
112
+ e.instance_variable_set(:@debugger_si, si)
113
+ e.freeze
114
+ }
115
+ end
116
+
117
+ private def add_path path
118
+ src_lines = File.readlines(path, chomp: true)
119
+ @files[path] = SrcInfo.new(src_lines)
120
+ rescue SystemCallError
121
+ end
122
+
123
+ private def get_si iseq
124
+ return unless iseq
125
+
126
+ if iseq.instance_variable_defined?(:@debugger_si)
127
+ iseq.instance_variable_get(:@debugger_si)
128
+ elsif @files.has_key?(path = (iseq.absolute_path || iseq.path))
129
+ @files[path]
130
+ elsif path
131
+ add_path(path)
132
+ end
133
+ end
134
+
135
+ def orig_src iseq
136
+ if si = get_si(iseq)
137
+ si.src
138
+ end
139
+ end
68
140
 
69
- def get_colored iseq
70
- if si = get_si(iseq)
71
- si.colored || begin
72
- si.colored = colorize_code(si.src.join).lines
141
+ def get_colored iseq
142
+ if si = get_si(iseq)
143
+ si.colored || begin
144
+ si.colored = colorize_code(si.src.join("\n")).lines
145
+ end
73
146
  end
74
147
  end
75
148
  end
data/lib/debug/start.rb CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative 'session'
4
4
  return unless defined?(DEBUGGER__)
5
- DEBUGGER__.start
5
+ DEBUGGER__.start no_sigint_hook: false