debug 1.0.0.beta5 → 1.0.0.beta6

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: '039bd2cbfdb3a67bbd91603b077a4f4784235fb0c7b48721a4b9f27b493231c6'
4
- data.tar.gz: f9605d076dff9d8571e70245baa5c2e97c2377cc7f92ee627cbc1f051361217b
3
+ metadata.gz: fffc4898e989a76e77a9076407cc1ba6d31b13a531e739c8972afe71bf049285
4
+ data.tar.gz: 190c18099e1078e00786dde75819b0b793647cd9508b0577e88d93d6a06c045c
5
5
  SHA512:
6
- metadata.gz: f222a8b1ec58fd6f5264e61ee8613e6ed229c9ebff73c6b4904c4c6c2bded0d625b776fb510b23dec57636cf576a68d471f0b91d7b01d36f8baad741ff64fd38
7
- data.tar.gz: 152431ba38203334bbf1c7449ff36a6d49f5116aaa78c017ca5ffa6d695ca87be06bc011822d0bbd325e15c46504385adf4ef94e74ebd37f97468f049da910e8
6
+ metadata.gz: 647e6c227bded49c962b8d6934557a26930664f5f1ddd57fd596c6651b1c655c1c77e64d5cbba28d2125cdd8a27817e33dc94d465d01f6b43b7f0be61ee30a35
7
+ data.tar.gz: ceb4dbf7b9479dc54ff5af725e973985493650ca9aaebd16878c4669fa037ae2ee1ec9ddddf83eb25dd65dc2057d0419a74005ec5d74c98585d855eb918e53bb
data/CONTRIBUTING.md CHANGED
@@ -15,8 +15,6 @@ If you spot any problem, please open an issue.
15
15
 
16
16
  ```bash
17
17
  $ rake test
18
- # or
19
- $ ruby bin/test-unit.rb
20
18
  ```
21
19
 
22
20
  ### Run specific test(s)
@@ -27,6 +25,199 @@ $ ruby test/debug/bp_test.rb # run all tests in the specified file
27
25
  $ ruby test/debug/bp_test.rb -h # to see all the test options
28
26
  ```
29
27
 
28
+ ## Generate Tests
29
+ There is a test generator in `debug.rb` project to make it easier to write tests.
30
+ ### Quickstart
31
+ This section shows you how to create test file by test generator. For more advanced informations on creating tests, please take a look at [gentest options](#gentest-options). (You can also check by `$bin/gentest -h`)
32
+ #### 1. Create a target file for debuggee.
33
+ Let's say, we created `target.rb` which is located in top level directory of debugger.
34
+ ```ruby
35
+ module Foo
36
+ class Bar
37
+ def self.a
38
+ "hello"
39
+ end
40
+ end
41
+ Bar.a
42
+ bar = Bar.new
43
+ end
44
+ ```
45
+ #### 2. Run `gentest` as shown in the example below.
46
+ ```shell
47
+ $ bin/gentest target.rb
48
+ ```
49
+ #### 3. Debugger will be executed. You can type any debug commands.
50
+ ```shell
51
+ $ bin/gentest target.rb
52
+ [1, 9] in ~/workspace/debug/target.rb
53
+ => 1| module Foo
54
+ 2| class Bar
55
+ 3| def self.a
56
+ 4| "hello"
57
+ 5| end
58
+ 6| end
59
+ 7| Bar.a
60
+ 8| bar = Bar.new
61
+ 9| end
62
+ =>#0 <main> at ~/workspace/debug/target.rb:1
63
+ INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:1","line":1}
64
+
65
+ (rdbg)s
66
+ s
67
+ [1, 9] in ~/workspace/debug/target.rb
68
+ 1| module Foo
69
+ => 2| class Bar
70
+ 3| def self.a
71
+ 4| "hello"
72
+ 5| end
73
+ 6| end
74
+ 7| Bar.a
75
+ 8| bar = Bar.new
76
+ 9| end
77
+ =>#0 <module:Foo> at ~/workspace/debug/target.rb:2
78
+ #1 <main> at ~/workspace/debug/target.rb:1
79
+ INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:2","line":2}
80
+
81
+ (rdbg)n
82
+ n
83
+ [1, 9] in ~/workspace/debug/target.rb
84
+ 1| module Foo
85
+ 2| class Bar
86
+ => 3| def self.a
87
+ 4| "hello"
88
+ 5| end
89
+ 6| end
90
+ 7| Bar.a
91
+ 8| bar = Bar.new
92
+ 9| end
93
+ =>#0 <class:Bar> at ~/workspace/debug/target.rb:3
94
+ #1 <module:Foo> at ~/workspace/debug/target.rb:2
95
+ #2 <main> at ~/workspace/debug/target.rb:1
96
+ INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:3","line":3}
97
+
98
+ (rdbg)b 7
99
+ b 7
100
+ INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:3","line":3}
101
+
102
+ (rdbg)c
103
+ c
104
+ [2, 9] in ~/workspace/debug/target.rb
105
+ 2| class Bar
106
+ 3| def self.a
107
+ 4| "hello"
108
+ 5| end
109
+ 6| end
110
+ => 7| Bar.a
111
+ 8| bar = Bar.new
112
+ 9| end
113
+ =>#0 <module:Foo> at ~/workspace/debug/target.rb:7
114
+ #1 <main> at ~/workspace/debug/target.rb:1
115
+
116
+ Stop by #0 BP - Line /Users/naotto/workspace/debug/target.rb:7 (line)
117
+ INTERNAL_INFO: {"location":"~/workspace/debug/target.rb:7","line":7}
118
+
119
+ (rdbg)q!
120
+ q!
121
+ ```
122
+ #### 4. The test file will be created as `test/debug/foo_test.rb`.
123
+ If the file already exists, **only method** will be added to it.
124
+ ```ruby
125
+ # frozen_string_literal: true
126
+
127
+ require_relative '../support/test_case'
128
+
129
+ module DEBUGGER__
130
+ class FooTest < TestCase
131
+ def program
132
+ <<~RUBY
133
+ 1| module Foo
134
+ 1| class Bar
135
+ 2| def self.a
136
+ 3| "hello"
137
+ 4| end
138
+ 5| end
139
+ 6| Bar.a
140
+ 7| bar = Bar.new
141
+ 8| end
142
+ RUBY
143
+ end
144
+
145
+ def test_foo
146
+ debug_code(program) do
147
+ type 's'
148
+ assert_line_num 2
149
+ assert_line_text([
150
+ /[1, 9] in .*/,
151
+ / 1| module Foo/,
152
+ /=> 2| class Bar/,
153
+ / 3| def self.a/,
154
+ / 4| "hello"/,
155
+ / 5| end/,
156
+ / 6| end/,
157
+ / 7| Bar.a/,
158
+ / 8| bar = Bar.new/,
159
+ / 9| end/,
160
+ /=>#0 <module:Foo> at .*/,
161
+ / #1 <main> at .*/
162
+ ])
163
+ type 'n'
164
+ assert_line_num 3
165
+ assert_line_text([
166
+ /[1, 9] in .*/,
167
+ / 1| module Foo/,
168
+ / 2| class Bar/,
169
+ /=> 3| def self.a/,
170
+ / 4| "hello"/,
171
+ / 5| end/,
172
+ / 6| end/,
173
+ / 7| Bar.a/,
174
+ / 8| bar = Bar.new/,
175
+ / 9| end/,
176
+ /=>#0 <class:Bar> at .*/,
177
+ / #1 <module:Foo> at .*/,
178
+ / #2 <main> at .*/
179
+ ])
180
+ type 'b 7'
181
+ assert_line_text(//)
182
+ type 'c'
183
+ assert_line_num 7
184
+ assert_line_text([
185
+ /[2, 9] in .*/,
186
+ / 2| class Bar/,
187
+ / 3| def self.a/,
188
+ / 4| "hello"/,
189
+ / 5| end/,
190
+ / 6| end/,
191
+ /=> 7| Bar.a/,
192
+ / 8| bar = Bar.new/,
193
+ / 9| end/,
194
+ /=>#0 <module:Foo> at .*/,
195
+ / #1 <main> at .*/,
196
+ //,
197
+ /Stop by #0 BP - Line .*/
198
+ ])
199
+ type 'q!'
200
+ end
201
+ end
202
+ end
203
+ end
204
+ ```
205
+
206
+ #### gentest options
207
+ You can get more information about `gentest` here.
208
+
209
+ The default method name is `test_foo` and the class name is `FooTest`. The file name will be `[Lowercase letters with "Test" removed from the class name]_test.rb`.
210
+ ```shell
211
+ # run without any options(test method name will be `test_foo`, class name will be `FooTest`, file name will be `foo_test.rb`)
212
+ $ bin/gentest target.rb
213
+ # specify the class name(test method name will be `test_foo`, class name will be `StepTest`, file name will be `step_test.rb`)
214
+ $ bin/gentest target.rb -c StepTest
215
+ # specify the method name(test method name will be `test_step`, class name will be `FooTest`, file name will be `foo_test.rb`)
216
+ $ bin/gentest target.rb -m test_step
217
+ # specify class name and method name(test method name will be `test_step`, class name will be `StepTest`, file name will be `step_test.rb`.)
218
+ $ bin/gentest target.rb -c StepTest -m test_step
219
+ ```
220
+
30
221
  ## To Update README
31
222
 
32
223
  This project generates `README.md` from the template `misc/README.md.erb`
data/README.md CHANGED
@@ -11,7 +11,7 @@ New debug.rb has several advantages:
11
11
  * Remote debugging: Support remote debugging natively.
12
12
  * UNIX domain socket
13
13
  * TCP/IP
14
- * VSCode/DAP integration (TODO)
14
+ * VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
15
15
  * Extensible: application can introduce debugging support with several methods
16
16
  * By `rdbg` command
17
17
  * By loading libraries with `-r` command line option
@@ -29,6 +29,16 @@ $ gem install debug --pre
29
29
 
30
30
  or specify `-Ipath/to/debug/lib` in `RUBYOPT` or each ruby command-line option, especially for debug this gem development.
31
31
 
32
+ If you use Bundler, write the following line to your Gemfile. And use rdbg command with -c option.
33
+
34
+ ```
35
+ gem "debug", ">= 1.0.0.beta"
36
+ ```
37
+
38
+ ```
39
+ $ rdbg -c bundle exec ruby target.rb
40
+ ```
41
+
32
42
  # How to use
33
43
 
34
44
  ## Invoke with debugger
@@ -70,10 +80,6 @@ $ ruby -r debug/run target.rb
70
80
  # target.rb
71
81
  require 'debug/run' # start the debug console
72
82
 
73
- # or
74
-
75
- require 'debug/session' # introduce the functionality
76
- DEBUGGER__.console # and start the debug console
77
83
  # ... rest of program ...
78
84
  ```
79
85
 
@@ -300,11 +306,9 @@ $ rdbg --attach hostname 12345
300
306
 
301
307
  ### Initial scripts
302
308
 
303
- 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.
304
-
305
- 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`.
309
+ If there are `~/.rdbgrc`, the file is loaded as initial scripts which contains debugger commands at the beginning of debug session. `RUBY_DEBUG_INIT_SCRIPT` environment variable can specify the initial script file. You can write configurations in a file. For example, you can set break points with `break file:123` in `~/.rdbgrc`.
306
310
 
307
- 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.
311
+ If there are `~/.rdbgrc.rb` is available, it is loaded as a ruby script at same timing.
308
312
 
309
313
  ### Environment variables
310
314
 
@@ -453,8 +457,13 @@ exe/rdbg [options] -- [debuggee options]
453
457
 
454
458
  Debug console mode:
455
459
  -n, --nonstop Do not stop at the beginning of the script.
456
- -e COMMAND execute debug command at the beginning of the script.
457
- -x, --init-script=FILE execute debug command in the FILE.
460
+ -e COMMAND Execute debug command at the beginning of the script.
461
+ -x, --init-script=FILE Execute debug command in the FILE.
462
+ --no-rc Ignore ~/.rdbgrc
463
+ --no-color Disable colorize
464
+ -c, --command Enable command mode.
465
+ The first argument should be a command name in $PATH.
466
+ Example: 'rdbg -c bundle exec rake test'
458
467
 
459
468
  -O, --open Start remote debugging with opening the network port.
460
469
  If TCP/IP options are not given,
@@ -486,7 +495,6 @@ Attach mode:
486
495
 
487
496
  Other options:
488
497
  -h, --help Print help
489
- -c, --command Command mode (first argument is command name)
490
498
  --util=NAME Utility mode (used by tools)
491
499
 
492
500
  NOTE
data/bin/gentest ADDED
@@ -0,0 +1,22 @@
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/exe/rdbg CHANGED
@@ -1,24 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/debug/client'
4
-
3
+ require_relative '../lib/debug/config'
5
4
  config = DEBUGGER__.parse_argv(ARGV)
6
5
 
7
6
  case config[:mode]
8
7
  when :start
9
8
  require 'rbconfig'
10
9
 
11
- if config[:remote]
12
- start_mode = "debug/open"
13
- else
14
- start_mode = "debug/run"
15
- end
10
+ libpath = File.join(File.expand_path(File.dirname(__dir__)), 'lib/debug')
11
+ start_mode = config[:remote] ? "open" : 'run'
12
+ cmd = config[:command] ? ARGV.shift : RbConfig.ruby
16
13
 
17
- ::DEBUGGER__.config_to_env(config)
14
+ env = ::DEBUGGER__.config_to_env_hash(config)
15
+ env['RUBYOPT'] = "-r #{libpath}/#{start_mode}"
18
16
 
19
- cmd = config[:command] ? ARGV.shift : RbConfig.ruby
20
- exec({'RUBYOPT' => "-I#{File.expand_path(File.dirname(__dir__))}/lib -r #{start_mode}"},
21
- cmd, *ARGV)
17
+ exec(env, cmd, *ARGV)
22
18
 
23
19
  when :attach
24
20
  require_relative "../lib/debug/client"
@@ -29,9 +25,9 @@ when :attach
29
25
 
30
26
  begin
31
27
  if ARGV.empty? && config[:port]
32
- connect [config[:host], config[:port]].compact
28
+ DEBUGGER__::Client.new([config[:host], config[:port]].compact).connect
33
29
  else
34
- connect ARGV
30
+ DEBUGGER__::Client.new(ARGV).connect
35
31
  end
36
32
  rescue DEBUGGER__::CommandLineOptionError
37
33
  puts opt.help
data/lib/debug.rb CHANGED
@@ -1 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'debug/session'
4
+ DEBUGGER__::start no_sigint_hook: true, nonstop: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'color'
2
4
 
3
5
  module DEBUGGER__
@@ -62,6 +64,10 @@ module DEBUGGER__
62
64
  to_s
63
65
  end
64
66
 
67
+ def duplicable?
68
+ false
69
+ end
70
+
65
71
  class << self
66
72
  include Color
67
73
 
@@ -155,6 +161,11 @@ module DEBUGGER__
155
161
  end
156
162
  end
157
163
 
164
+ def duplicable?
165
+ # only binding.bp or DEBUGGER__.console are duplicable
166
+ @oneshot
167
+ end
168
+
158
169
  NearestISeq = Struct.new(:iseq, :line, :events)
159
170
 
160
171
  def try_activate
data/lib/debug/client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'socket'
2
4
  require 'io/console/size'
3
5
 
@@ -13,11 +15,11 @@ module DEBUGGER__
13
15
  begin
14
16
  require 'readline'
15
17
  def readline
16
- Readline.readline("\n(rdb) ", true)
18
+ Readline.readline("\n(rdbg:remote) ", true)
17
19
  end
18
20
  rescue LoadError
19
21
  def readline
20
- print "\n(rdb) "
22
+ print "\n(rdbg:remote) "
21
23
  gets
22
24
  end
23
25
  end
@@ -162,10 +164,6 @@ module DEBUGGER__
162
164
  end
163
165
  end
164
166
 
165
- def connect argv = ARGV
166
- DEBUGGER__::Client.new(argv).connect
167
- end
168
-
169
167
  if __FILE__ == $0
170
- connect
168
+ DEBUGGER__::Client.new(argv).connect
171
169
  end
data/lib/debug/color.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'irb/color'
3
5
  require "irb/color_printer"
@@ -9,7 +11,7 @@ module DEBUGGER__
9
11
  module Color
10
12
  if defined? IRB::Color.colorize
11
13
  def colorize str, color
12
- if CONFIG[:use_colorize]
14
+ if !CONFIG[:no_color]
13
15
  IRB::Color.colorize str, color
14
16
  else
15
17
  str
@@ -23,7 +25,7 @@ module DEBUGGER__
23
25
 
24
26
  if defined? IRB::ColorPrinter.pp
25
27
  def color_pp obj
26
- IRB::ColorPrinter.pp(obj, "")
28
+ IRB::ColorPrinter.pp(obj, "".dup)
27
29
  end
28
30
  else
29
31
  def color_pp obj
@@ -32,7 +34,7 @@ module DEBUGGER__
32
34
  end
33
35
 
34
36
  def colored_inspect obj
35
- if CONFIG[:use_colorize]
37
+ if !CONFIG[:no_color]
36
38
  color_pp obj
37
39
  else
38
40
  obj.pretty_inspect