ed-precompiled_debug 1.11.0-arm64-darwin

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/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ begin
5
+ require "rake/extensiontask"
6
+ task :build => :compile
7
+
8
+ Rake::ExtensionTask.new("debug") do |ext|
9
+ ext.lib_dir = "lib/debug"
10
+ end
11
+ rescue LoadError
12
+ end
13
+
14
+ task :default => [:clobber, :compile, 'README.md', :check_readme, :test_console]
15
+
16
+ file 'README.md' => ['lib/debug/session.rb', 'lib/debug/config.rb',
17
+ 'exe/rdbg', 'misc/README.md.erb'] do
18
+ require_relative 'lib/debug/session'
19
+ require 'erb'
20
+ File.write 'README.md', ERB.new(File.read('misc/README.md.erb')).result
21
+ puts 'README.md is updated.'
22
+ end
23
+
24
+ task :check_readme do
25
+ require_relative 'lib/debug/session'
26
+ require 'erb'
27
+ current_readme = File.read("README.md")
28
+ generated_readme = ERB.new(File.read('misc/README.md.erb')).result
29
+
30
+ if current_readme != generated_readme
31
+ fail <<~MSG
32
+ The content of README.md doesn't match its template and/or source.
33
+ Please apply the changes to info source (e.g. command comments) or the template and run 'rake README.md' to update README.md.
34
+ MSG
35
+ end
36
+ end
37
+
38
+ desc "Run debug.gem test-framework tests"
39
+ Rake::TestTask.new(:test_test) do |t|
40
+ t.test_files = FileList["test/support/*_test.rb"]
41
+ end
42
+
43
+ desc "Run all debugger console related tests"
44
+ Rake::TestTask.new(:test_console) do |t|
45
+ t.test_files = FileList["test/console/*_test.rb"]
46
+ end
47
+
48
+ desc "Run all debugger protocols (CAP & DAP) related tests"
49
+ Rake::TestTask.new(:test_protocol) do |t|
50
+ t.test_files = FileList["test/protocol/*_test.rb"]
51
+ end
52
+
53
+ task test: 'test_console' do
54
+ warn '`rake test` doesn\'t run protocol tests. Use `rake test_all` to test all.'
55
+ end
56
+
57
+ task test_all: [:test_test, :test_console, :test_protocol]
data/TODO.md ADDED
@@ -0,0 +1,23 @@
1
+ # TODO
2
+
3
+ ## Basic functionality
4
+
5
+ * Support Fibers and Ractors
6
+
7
+ ## UI
8
+
9
+ * Multi-line support
10
+ * Completion for Ruby's code
11
+ * Interactive breakpoint setting
12
+ * Interactive record & play debugging
13
+ * irb integration
14
+
15
+ ## Debug command
16
+
17
+ * Watch points
18
+ * Lightweight watchpoints for instance variables with Ruby 3.3 features (TP:ivar_set)
19
+ * Alias
20
+
21
+ ## Debug port
22
+
23
+ * Debug port for monitoring
data/debug.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/debug/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ed-precompiled_debug"
5
+ spec.version = DEBUGGER__::VERSION
6
+ spec.authors = ["Koichi Sasada"]
7
+ spec.email = ["ko1@atdot.net"]
8
+
9
+ spec.summary = %q{Debugging functionality for Ruby}
10
+ spec.description = %q{Debugging functionality for Ruby. This is completely rewritten debug.rb which was contained by the ancient Ruby versions.}
11
+ spec.homepage = "https://github.com/ruby/debug"
12
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases/tag/v#{spec.version}"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.extensions = ['ext/debug/extconf.rb']
30
+
31
+ spec.add_dependency "irb", "~> 1.10" # for irb:debug integration
32
+ spec.add_dependency "reline", ">= 0.3.8"
33
+ end
data/exe/rdbg ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/debug/config'
4
+ config = DEBUGGER__::Config::parse_argv(ARGV)
5
+
6
+ # mode is not an actual configuration option
7
+ # it's only used to carry the result of parse_argv here
8
+ case config.delete(:mode)
9
+ when :start
10
+ require 'rbconfig'
11
+
12
+ libpath = File.join(File.expand_path(File.dirname(__dir__)), 'lib/debug')
13
+ start_mode = config[:open] ? "open" : 'start'
14
+ cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby)
15
+
16
+ if defined?($:.resolve_feature_path)
17
+ begin
18
+ _, sopath = $:.resolve_feature_path('debug/debug.so')
19
+ rescue LoadError
20
+ # raises LoadError before 3.1 (2.7 and 3.0)
21
+ else
22
+ sopath = File.dirname(File.dirname(sopath)) if sopath
23
+ end
24
+ else
25
+ # `$:.resolve_feature_path` is not defined in 2.6 or earlier.
26
+ so = "debug/debug.#{RbConfig::CONFIG['DLEXT']}"
27
+ sopath = $:.find {|dir| File.exist?(File.join(dir, so))}
28
+ end
29
+ added = "-r #{libpath}/#{start_mode}"
30
+ added = "-I #{sopath} #{added}" if sopath
31
+ rubyopt = ENV['RUBYOPT']
32
+ env = ::DEBUGGER__::Config.config_to_env_hash(config)
33
+ env['RUBY_DEBUG_ADDED_RUBYOPT'] = added
34
+ env['RUBYOPT'] = "#{rubyopt} #{added}"
35
+
36
+ exec(env, cmd, *ARGV)
37
+
38
+ when :attach
39
+ require_relative "../lib/debug/client"
40
+ ::DEBUGGER__::CONFIG.set_config(**config)
41
+
42
+ begin
43
+ if ARGV.empty? && config[:port]
44
+ DEBUGGER__::Client.new([config[:host], config[:port]].compact).connect
45
+ else
46
+ DEBUGGER__::Client.new(ARGV).connect
47
+ end
48
+ rescue DEBUGGER__::CommandLineOptionError
49
+ puts opt.help
50
+ end
51
+ else
52
+ raise # assert
53
+ end
data/ext/debug/debug.c ADDED
@@ -0,0 +1,228 @@
1
+
2
+ #include "ruby/ruby.h"
3
+ #include "ruby/debug.h"
4
+ #include "ruby/encoding.h"
5
+ #include "debug_version.h"
6
+ //
7
+ static VALUE rb_mDebugger;
8
+
9
+ // iseq
10
+ typedef struct rb_iseq_struct rb_iseq_t;
11
+ const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
12
+ VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
13
+
14
+ static VALUE
15
+ iseq_realpath(VALUE iseqw)
16
+ {
17
+ return rb_iseq_realpath(rb_iseqw_to_iseq(iseqw));
18
+ }
19
+
20
+ static VALUE rb_cFrameInfo;
21
+
22
+ static VALUE
23
+ di_entry(VALUE loc, VALUE self, VALUE binding, VALUE iseq, VALUE klass, VALUE depth)
24
+ {
25
+ return rb_struct_new(rb_cFrameInfo,
26
+ // :location, :self, :binding, :iseq, :class, :frame_depth,
27
+ loc, self, binding, iseq, klass, depth,
28
+ // :has_return_value, :return_value,
29
+ Qnil, Qnil,
30
+ // :has_raised_exception, :raised_exception,
31
+ Qnil, Qnil,
32
+ // :show_line, :local_variables
33
+ Qnil,
34
+ // :_local_variables, :_callee # for recorder
35
+ Qnil, Qnil,
36
+ // :dupped_binding
37
+ Qnil
38
+ );
39
+ }
40
+
41
+ static int
42
+ str_start_with(VALUE str, VALUE prefix)
43
+ {
44
+ StringValue(prefix);
45
+ rb_enc_check(str, prefix);
46
+ if (RSTRING_LEN(str) >= RSTRING_LEN(prefix) &&
47
+ memcmp(RSTRING_PTR(str), RSTRING_PTR(prefix), RSTRING_LEN(prefix)) == 0) {
48
+ return 1;
49
+ }
50
+ else {
51
+ return 0;
52
+ }
53
+ }
54
+
55
+ static VALUE
56
+ di_body(const rb_debug_inspector_t *dc, void *ptr)
57
+ {
58
+ VALUE skip_path_prefix = (VALUE)ptr;
59
+ VALUE locs = rb_debug_inspector_backtrace_locations(dc);
60
+ VALUE ary = rb_ary_new();
61
+ long len = RARRAY_LEN(locs);
62
+ long i;
63
+
64
+ for (i=1; i<len; i++) {
65
+ VALUE e;
66
+ VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
67
+ VALUE loc = RARRAY_AREF(locs, i);
68
+ VALUE path;
69
+
70
+ if (!NIL_P(iseq)) {
71
+ path = iseq_realpath(iseq);
72
+ }
73
+ else {
74
+ // C frame
75
+ path = rb_funcall(loc, rb_intern("path"), 0);
76
+ }
77
+
78
+ if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) {
79
+ continue;
80
+ }
81
+
82
+ e = di_entry(loc,
83
+ rb_debug_inspector_frame_self_get(dc, i),
84
+ rb_debug_inspector_frame_binding_get(dc, i),
85
+ iseq,
86
+ rb_debug_inspector_frame_class_get(dc, i),
87
+ #ifdef RB_DEBUG_INSPECTOR_FRAME_DEPTH
88
+ rb_debug_inspector_frame_depth(dc, i)
89
+ #else
90
+ INT2FIX(len - i)
91
+ #endif
92
+ );
93
+ rb_ary_push(ary, e);
94
+ }
95
+
96
+ return ary;
97
+ }
98
+
99
+ static VALUE
100
+ capture_frames(VALUE self, VALUE skip_path_prefix)
101
+ {
102
+ return rb_debug_inspector_open(di_body, (void *)skip_path_prefix);
103
+ }
104
+
105
+ #ifdef RB_DEBUG_INSPECTOR_FRAME_DEPTH
106
+ static VALUE
107
+ frame_depth(VALUE self)
108
+ {
109
+ return rb_debug_inspector_current_depth();
110
+ }
111
+ #else
112
+ static VALUE
113
+ frame_depth(VALUE self)
114
+ {
115
+ // TODO: more efficient API
116
+ VALUE bt = rb_make_backtrace();
117
+ return INT2FIX(RARRAY_LEN(bt));
118
+ }
119
+ #endif
120
+
121
+
122
+ // iseq
123
+
124
+ const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
125
+
126
+ #ifdef HAVE_RB_ISEQ_TYPE
127
+ VALUE rb_iseq_type(const rb_iseq_t *);
128
+
129
+ static VALUE
130
+ iseq_type(VALUE iseqw)
131
+ {
132
+ const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
133
+ return rb_iseq_type(iseq);
134
+ }
135
+ #endif
136
+
137
+ #ifdef HAVE_RB_ISEQ_PARAMETERS
138
+ VALUE rb_iseq_parameters(const rb_iseq_t *, int is_proc);
139
+
140
+ static VALUE
141
+ iseq_parameters_symbols(VALUE iseqw)
142
+ {
143
+ const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
144
+ VALUE params = rb_iseq_parameters(iseq, 0);
145
+ VALUE ary = rb_ary_new();
146
+
147
+ static VALUE sym_ast, sym_astast, sym_amp;
148
+
149
+ if (sym_ast == 0) {
150
+ sym_ast = ID2SYM(rb_intern("*"));
151
+ sym_astast = ID2SYM(rb_intern("**"));
152
+ sym_amp = ID2SYM(rb_intern("&"));
153
+ }
154
+
155
+ for (long i=0; i<RARRAY_LEN(params); i++) {
156
+ VALUE e = RARRAY_AREF(params, i);
157
+ if (RARRAY_LEN(e) == 2) {
158
+ VALUE sym = RARRAY_AREF(e, 1);
159
+ if (sym != sym_ast &&
160
+ sym != sym_astast &&
161
+ sym != sym_amp) rb_ary_push(ary, RARRAY_AREF(e, 1));
162
+ }
163
+ }
164
+
165
+ return ary;
166
+ }
167
+ #endif
168
+
169
+ #ifdef HAVE_RB_ISEQ_CODE_LOCATION
170
+ void rb_iseq_code_location(const rb_iseq_t *, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
171
+
172
+ static VALUE
173
+ iseq_first_line(VALUE iseqw)
174
+ {
175
+ const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
176
+ int line;
177
+ rb_iseq_code_location(iseq, &line, NULL, NULL, NULL);
178
+ return INT2NUM(line);
179
+ }
180
+
181
+ static VALUE
182
+ iseq_last_line(VALUE iseqw)
183
+ {
184
+ const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
185
+ int line;
186
+ rb_iseq_code_location(iseq, NULL, NULL, &line, NULL);
187
+ return INT2NUM(line);
188
+ }
189
+ #endif
190
+
191
+ #ifdef HAVE_RB_ISEQ
192
+ void Init_iseq_collector(void);
193
+ #endif
194
+
195
+ void
196
+ Init_debug(void)
197
+ {
198
+ #ifdef HAVE_RB_ISEQ
199
+ VALUE rb_mRubyVM = rb_const_get(rb_cObject, rb_intern("RubyVM"));
200
+ VALUE rb_cISeq = rb_const_get(rb_mRubyVM, rb_intern("InstructionSequence"));
201
+ #endif
202
+ rb_mDebugger = rb_const_get(rb_cObject, rb_intern("DEBUGGER__"));
203
+ rb_cFrameInfo = rb_const_get(rb_mDebugger, rb_intern("FrameInfo"));
204
+
205
+ // Debugger and FrameInfo were defined in Ruby. We need to register them
206
+ // as mark objects so they are automatically pinned.
207
+ rb_gc_register_mark_object(rb_mDebugger);
208
+ rb_gc_register_mark_object(rb_cFrameInfo);
209
+ rb_define_singleton_method(rb_mDebugger, "capture_frames", capture_frames, 1);
210
+ rb_define_singleton_method(rb_mDebugger, "frame_depth", frame_depth, 0);
211
+ rb_define_const(rb_mDebugger, "SO_VERSION", rb_str_new2(RUBY_DEBUG_VERSION));
212
+
213
+ // iseq
214
+ #ifdef HAVE_RB_ISEQ_TYPE
215
+ rb_define_method(rb_cISeq, "type", iseq_type, 0);
216
+ #endif
217
+ #ifdef HAVE_RB_ISEQ_PARAMETERS
218
+ rb_define_method(rb_cISeq, "parameters_symbols", iseq_parameters_symbols, 0);
219
+ #endif
220
+ #ifdef HAVE_RB_ISEQ_CODE_LOCATION
221
+ rb_define_method(rb_cISeq, "first_line", iseq_first_line, 0);
222
+ rb_define_method(rb_cISeq, "last_line", iseq_last_line, 0);
223
+ #endif
224
+
225
+ #ifdef HAVE_RB_ISEQ
226
+ Init_iseq_collector();
227
+ #endif
228
+ }
@@ -0,0 +1,27 @@
1
+ require 'mkmf'
2
+ require_relative '../../lib/debug/version'
3
+ File.write("debug_version.h", "#define RUBY_DEBUG_VERSION \"#{DEBUGGER__::VERSION}\"\n")
4
+ $distcleanfiles << "debug_version.h"
5
+
6
+ if defined? RubyVM
7
+ $defs << '-DHAVE_RB_ISEQ'
8
+ $defs << '-DHAVE_RB_ISEQ_PARAMETERS'
9
+ $defs << '-DHAVE_RB_ISEQ_CODE_LOCATION'
10
+
11
+ if RUBY_VERSION >= '3.1.0'
12
+ $defs << '-DHAVE_RB_ISEQ_TYPE'
13
+ end
14
+ else
15
+ # not on MRI
16
+
17
+ have_func "rb_iseq_parameters(NULL, 0)",
18
+ [["VALUE rb_iseq_parameters(void *, int is_proc);"]]
19
+
20
+ have_func "rb_iseq_code_location(NULL, NULL, NULL, NULL, NULL)",
21
+ [["void rb_iseq_code_location(void *, int *first_lineno, int *first_column, int *last_lineno, int *last_column);"]]
22
+ # from Ruby 3.1
23
+ have_func "rb_iseq_type(NULL)",
24
+ [["VALUE rb_iseq_type(void *);"]]
25
+ end
26
+
27
+ create_makefile 'debug/debug'
@@ -0,0 +1,93 @@
1
+ #include <ruby/ruby.h>
2
+
3
+ #ifdef HAVE_RB_ISEQ
4
+ VALUE rb_iseqw_new(VALUE v);
5
+ void rb_objspace_each_objects(
6
+ int (*callback)(void *start, void *end, size_t stride, void *data),
7
+ void *data);
8
+ size_t rb_obj_memsize_of(VALUE);
9
+
10
+ // implementation specific.
11
+ enum imemo_type {
12
+ imemo_iseq = 7,
13
+ imemo_mask = 0xf
14
+ };
15
+
16
+ static inline enum imemo_type
17
+ imemo_type(VALUE imemo)
18
+ {
19
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
20
+ }
21
+
22
+ static inline int
23
+ rb_obj_is_iseq(VALUE iseq)
24
+ {
25
+ return RB_TYPE_P(iseq, T_IMEMO) && imemo_type(iseq) == imemo_iseq;
26
+ }
27
+
28
+ struct iseq_i_data {
29
+ void (*func)(VALUE v, void *data);
30
+ void *data;
31
+ };
32
+
33
+ int
34
+ iseq_i(void *vstart, void *vend, size_t stride, void *ptr)
35
+ {
36
+ VALUE v;
37
+ struct iseq_i_data *data = (struct iseq_i_data *)ptr;
38
+
39
+ for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
40
+ if (RBASIC(v)->flags) {
41
+ switch (BUILTIN_TYPE(v)) {
42
+ case T_IMEMO:
43
+ if (rb_obj_is_iseq(v)) {
44
+ data->func(v, data->data);
45
+ }
46
+ continue;
47
+ default:
48
+ continue;
49
+ }
50
+ }
51
+ }
52
+
53
+ return 0;
54
+ }
55
+
56
+ static void
57
+ each_iseq_i(VALUE v, void *ptr)
58
+ {
59
+ rb_yield(rb_iseqw_new(v));
60
+ }
61
+
62
+ static VALUE
63
+ each_iseq(VALUE self)
64
+ {
65
+ struct iseq_i_data data = {each_iseq_i, NULL};
66
+ rb_objspace_each_objects(iseq_i, &data);
67
+ return Qnil;
68
+ }
69
+
70
+ static void
71
+ count_iseq_i(VALUE v, void *ptr)
72
+ {
73
+ size_t *sizep = (size_t *)ptr;
74
+ *sizep += 1;
75
+ }
76
+
77
+ static VALUE
78
+ count_iseq(VALUE self)
79
+ {
80
+ size_t size = 0;
81
+ struct iseq_i_data data = {count_iseq_i, &size};
82
+ rb_objspace_each_objects(iseq_i, &data);
83
+ return SIZET2NUM(size);
84
+ }
85
+
86
+ void
87
+ Init_iseq_collector(void)
88
+ {
89
+ VALUE rb_mObjSpace = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
90
+ rb_define_singleton_method(rb_mObjSpace, "each_iseq", each_iseq, 0);
91
+ rb_define_singleton_method(rb_mObjSpace, "count_iseq", count_iseq, 0);
92
+ }
93
+ #endif
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,77 @@
1
+
2
+ module DEBUGGER__
3
+ class AbbrevCommand
4
+ class TrieNode
5
+ def initialize
6
+ @children = {}
7
+ @types = {} # set
8
+ end
9
+
10
+ def append c, type
11
+ trie = (@children[c] ||= TrieNode.new)
12
+ trie.add_type type
13
+ end
14
+
15
+ def [](c)
16
+ @children[c]
17
+ end
18
+
19
+ def add_type type
20
+ @types[type] = true
21
+ self
22
+ end
23
+
24
+ def types
25
+ @types.keys
26
+ end
27
+
28
+ def type
29
+ if @types.size == 1
30
+ @types.keys.first
31
+ else
32
+ nil
33
+ end
34
+ end
35
+
36
+ def candidates
37
+ @children.map{|c, n|
38
+ ss = n.candidates
39
+ ss.empty? ? c :
40
+ ss.map{|s|
41
+ c+s
42
+ }
43
+ }.flatten
44
+ end
45
+ end
46
+
47
+ # config: { type: [commands...], ... }
48
+ def initialize config
49
+ @trie = TrieNode.new
50
+ build config
51
+ end
52
+
53
+ private def build config
54
+ config.each do |type, commands|
55
+ commands.each do |command|
56
+ trie = @trie
57
+ command.each_char do |c|
58
+ trie = trie.append(c, type)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def search str, if_none = nil
65
+ trie = @trie
66
+ str.each_char do |c|
67
+ if trie = trie[c]
68
+ return trie.type if trie.type
69
+ else
70
+ return if_none
71
+ end
72
+ end
73
+ yield trie.candidates.map{|s| str + s} if block_given?
74
+ if_none
75
+ end
76
+ end
77
+ end