Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Extract-to-lib rdebug options parsing, add tests #108

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ ext/ruby_debug/ruby_debug.c
ext/ruby_debug/ruby_debug.h

Gemfile.lock

.ruby-version
.ruby-gemset

9 changes: 9 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :minitest do
# with Minitest::Unit
watch(%r{^test/(.*)\/?(.*)_test\.rb})
watch(%r{^lib/(.*/)?([^/]+)\.rb}) { 'test' }
watch(%r{^test/test_helper\.rb}) { 'test' }
end
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Please report them [on github](http://github.com/cldwalker/debugger/issues).
[See here](http://tagaholic.me/contributing.html) for contribution policies.
Let's keep this working for the ruby community!

* After forking the repo, run `rake compile` before running `rake test`.

## Related projects

* [debugger-completion](https://github.com/cldwalker/debugger-completion) - autocompletion for
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SO_NAME = "ruby_debug.so"
desc "Run new MiniTest tests."
task :test do
Rake::TestTask.new(:test) do |t|
t.test_files = FileList["test/*_test.rb"]
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
end
end
Expand Down
168 changes: 18 additions & 150 deletions bin/rdebug
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# <tt>--cport</tt> options
#
#<tt>--cport=</tt><i>port</i>::
# Use port <i>port</i> for access to debugger control.
# Use port <i>port</i> for access to debugger control. Default 8990
#
#<tt>-d | --debug</tt>::
# Set $DEBUG true.
Expand Down Expand Up @@ -55,7 +55,7 @@
# Do not stop when script is loaded.
#
#<tt>-p | --port=PORT</tt>::
# Host name used for remote debugging.
# Host name used for remote debugging. Default 8989
#
#<tt>-r | --require</tt><i>script</i>::
# Require the library, before executing your script.
Expand Down Expand Up @@ -105,6 +105,7 @@
require 'optparse'
require 'ostruct'
require 'debugger'
require_relative '../lib/debugger/runner/rdebug_option_parser'

def debug_program(options)
# Make sure Ruby script syntax checks okay.
Expand Down Expand Up @@ -143,140 +144,6 @@ def whence_file(prog_script)
return prog_script
end

options = OpenStruct.new(
'annotate' => Debugger.annotate,
'client' => false,
'control' => true,
'cport' => Debugger::PORT + 1,
'host' => nil,
'quit' => true,
'no_rewrite_program' => false,
'stop' => true,
'nx' => false,
'port' => Debugger::PORT,
'restart_script' => nil,
'script' => nil,
'server' => false,
'tracing' => false,
'verbose_long' => false,
'wait' => false
)

def process_options(options)
program = File.basename($0)
opts = OptionParser.new do |opts|
opts.banner = <<EOB
#{program} #{Debugger::VERSION}
Usage: #{program} [options] <script.rb> -- <script.rb parameters>
EOB
opts.separator ""
opts.separator "Options:"
opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
|annotate|
Debugger.annotate = annotate
end
opts.on("-c", "--client", "Connect to remote debugger") do
options.client = true
end
opts.on("--cport PORT", Integer, "Port used for control commands") do
|cport|
options.cport = cport
end
opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
opts.on("--emacs LEVEL", Integer,
"Activates full Emacs support at annotation level LEVEL") do
|level|
Debugger.annotate = level.to_i
ENV['EMACS'] = '1'
ENV['COLUMNS'] = '120' if ENV['COLUMNS'].to_i < 120
options.control = false
options.quit = false
end
opts.on('--emacs-basic', 'Activates basic Emacs mode') do
ENV['EMACS'] = '1'
end
opts.on('-h', '--host HOST', 'Host name used for remote debugging') do
|host|
options.host = host
end
opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
$LOAD_PATH.unshift(path)
end
opts.on('--no-control', 'Do not automatically start control thread') do
options.control = false
end
opts.on('--no-quit', 'Do not quit when script finishes') do
options.quit = false
end
opts.on('--no-rewrite-program',
'Do not set $0 to the program being debugged') do
options.no_rewrite_program = true
end
opts.on('--no-stop', 'Do not stop when script is loaded') do
options.stop = false
end
opts.on('-nx', 'Not run debugger initialization files (e.g. .rdebugrc') do
options.nx = true
end
opts.on('-p', '--port PORT', Integer, 'Port used for remote debugging') do
|port|
options.port = port
end
opts.on('-r', '--require SCRIPT', String,
'Require the library, before executing your script') do |name|
if name == 'debug'
puts "debugger is not compatible with Ruby's 'debug' library. This option is ignored."
else
require name
end
end
opts.on('--restart-script FILE', String,
'Name of the script file to run. Erased after read') do
|restart_script|
options.restart_script = restart_script
unless File.exists?(options.restart_script)
puts "Script file '#{options.restart_script}' is not found"
exit
end
end
opts.on('--script FILE', String, 'Name of the script file to run') do
|script|
options.script = script
unless File.exists?(options.script)
puts "Script file '#{options.script}' is not found"
exit
end
end
opts.on('-s', '--server', 'Listen for remote connections') do
options.server = true
end
opts.on('-w', '--wait', 'Wait for a client connection, implies -s option') do
options.wait = true
end
opts.on('-x', '--trace', 'Turn on line tracing') {options.tracing = true}
opts.separator ''
opts.separator 'Common options:'
opts.on_tail('--help', 'Show this message') do
puts opts
exit
end
opts.on_tail('--version',
'Print the version') do
puts "debugger #{Debugger::VERSION}"
exit
end
opts.on('--verbose', 'Turn on verbose mode') do
$VERBOSE = true
options.verbose_long = true
end
opts.on_tail('-v',
'Print version number, then turn on verbose mode') do
puts "debugger #{Debugger::VERSION}"
$VERBOSE = true
end
end
return opts
end

# What file is used for debugger startup commands.
unless defined?(OPTS_INITFILE)
Expand All @@ -297,21 +164,21 @@ begin
rescue
end

opts = process_options(options)
if not defined? Debugger::ARGV
Debugger::ARGV = ARGV.clone
end
rdebug_path = File.expand_path($0)
if RUBY_PLATFORM =~ /mswin/
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
end
Debugger::RDEBUG_SCRIPT = rdebug_path
Debugger::RDEBUG_FILE = __FILE__
Debugger::INITIAL_DIR = Dir.pwd

begin
if not defined? Debugger::ARGV
Debugger::ARGV = ARGV.clone
end
rdebug_path = File.expand_path($0)
if RUBY_PLATFORM =~ /mswin/
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
end
Debugger::RDEBUG_SCRIPT = rdebug_path
Debugger::RDEBUG_FILE = __FILE__
Debugger::INITIAL_DIR = Dir.pwd
opts.parse! ARGV
options = RdebugOptionParser.instance.parse ARGV
rescue StandardError => e
puts opts
puts RdebugOptionParser.instance
puts
puts e.message
exit(-1)
Expand All @@ -322,7 +189,8 @@ if options.client
else
if ARGV.empty?
exit if $VERBOSE and not options.verbose_long
puts opts
# Print the possible options and exit
puts RdebugOptionParser.instance
puts
puts 'Must specify a script to run'
exit(-1)
Expand Down
1 change: 1 addition & 0 deletions debugger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ handling, bindings for stack frames among other things.
s.add_development_dependency 'rake-compiler', '~> 0.8.0'
s.add_development_dependency 'minitest', '~> 2.12.1'
s.add_development_dependency 'mocha', '~> 0.13.0'
s.add_development_dependency 'guard-minitest'
s.license = "BSD"
end
Loading