ruby-changes:48546
From: nobu <ko1@a...>
Date: Sun, 5 Nov 2017 14:11:08 +0900 (JST)
Subject: [ruby-changes:48546] nobu:r60661 (trunk): runruby.rb: support run.gdb by --debugger option
nobu 2017-11-05 14:11:04 +0900 (Sun, 05 Nov 2017) New Revision: 60661 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60661 Log: runruby.rb: support run.gdb by --debugger option Modified files: trunk/tool/runruby.rb Index: tool/runruby.rb =================================================================== --- tool/runruby.rb (revision 60660) +++ tool/runruby.rb (revision 60661) @@ -23,7 +23,13 @@ while arg = ARGV[0] https://github.com/ruby/ruby/blob/trunk/tool/runruby.rb#L23 # obsolete switch do nothing when re =~ "debugger" require 'shellwords' - precommand.concat(value ? (Shellwords.shellwords(value) unless value == "no") : %w"gdb --args") + case value + when nil + debugger = :gdb + when "no" + else + debugger = Shellwords.shellwords(value) + end and precommand |= [:debugger] when re =~ "precommand" require 'shellwords' precommand.concat(Shellwords.shellwords(value)) @@ -37,19 +43,28 @@ end https://github.com/ruby/ruby/blob/trunk/tool/runruby.rb#L43 unless defined?(File.realpath) def File.realpath(*args) - Dir.chdir(expand_path(*args)) do - Dir.pwd + path = expand_path(*args) + if File.stat(path).directory? + Dir.chdir(path) {Dir.pwd} + else + dir, base = File.split(path) + File.join(Dir.chdir(dir) {Dir.pwd}, base) end end end srcdir ||= File.realpath('..', File.dirname(__FILE__)) -archdir ||= '.' +begin + conffile = File.realpath('rbconfig.rb', archdir) +rescue Errno::ENOENT => e + abort "#$0: rbconfig.rb not found, use --archdir option" +end -abs_archdir = File.expand_path(archdir) +abs_archdir = File.dirname(conffile) +archdir ||= abs_archdir $:.unshift(abs_archdir) -config = File.read(conffile = File.join(abs_archdir, 'rbconfig.rb')) +config = File.read(conffile) config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '') config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG @@ -106,12 +121,16 @@ end https://github.com/ruby/ruby/blob/trunk/tool/runruby.rb#L121 ENV.update env -if ENV['RUNRUBY_USE_GDB'] == 'true' - if File.exist?('run.gdb') - precommand = %w'gdb -x run.gdb --args' - else - precommand = %w'gdb --args' +if debugger or ENV['RUNRUBY_USE_GDB'] == 'true' + if debugger == :gdb + debugger = %w'gdb' + if File.exist?(gdb = 'run.gdb') or + File.exist?(gdb = File.join(abs_archdir, 'run.gdb')) + debugger.push('-x', gdb) + end + debugger << '--args' end + precommand[precommand.index(:debugger), 1] = debugger end cmd = [runner || ruby] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/