From nobody at rubyforge.org Fri Jun 20 02:46:09 2008 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 20 Jun 2008 02:46:09 -0400 (EDT) Subject: [Ruby-debug-commits] [846] trunk: trace.rb: add "trace var" Message-ID: <20080620064609.935B618581AF@rubyforge.org> Revision: 846 Author: rockyb Date: 2008-06-20 02:46:08 -0400 (Fri, 20 Jun 2008) Log Message: ----------- trace.rb: add "trace var" ruby-debug-base.rb: remove another undefined warning. Modified Paths: -------------- trunk/CHANGES trunk/cli/ruby-debug/commands/trace.rb trunk/lib/ruby-debug-base.rb Modified: trunk/CHANGES =================================================================== --- trunk/CHANGES 2008-05-27 03:54:29 UTC (rev 845) +++ trunk/CHANGES 2008-06-20 06:46:08 UTC (rev 846) @@ -1,5 +1,6 @@ 0.10.2 - debugger(steps=0) breaks inside of debugger rather than wait for a line event. + - trace var varname (stop|nostop) added which issues trace_var. 0.10.1 4/10/08 - in honor of the 30th Birthday of Kate Schwarz Modified: trunk/cli/ruby-debug/commands/trace.rb =================================================================== --- trunk/cli/ruby-debug/commands/trace.rb 2008-05-27 03:54:29 UTC (rev 845) +++ trunk/cli/ruby-debug/commands/trace.rb 2008-06-20 06:46:08 UTC (rev 846) @@ -1,20 +1,43 @@ module Debugger class TraceCommand < Command # :nodoc: def regexp - /^\s*tr(?:ace)?(?:\s+(on|off))?(?:\s+(all))?$/ + /^\s* tr(?:ace)? (?: \s+ (\S+)) # on |off | var(iable) + (?: \s+ (\S+))? # (all | variable-name)? + (?: \s+ (\S+))? \s* # (stop | nostop)? + $/ix end def execute - if @match[2] - Debugger.tracing = @match[1] == 'on' - elsif @match[1] - Debugger.current_context.tracing = @match[1] == 'on' + if @match[1] =~ /on|off/ + onoff = 'on' == @match[1] + if @match[2] + Debugger.current_context.tracing = onoff + print "Tracing %s all threads.\n" % (onoff ? 'on' : 'off') + else + Debugger.tracing = onoff + print "Tracing %s on current thread.\n" % (onoff ? 'on' : 'off') + end + elsif @match[1] =~ /var(?:iable)?/ + varname=@match[2] + if debug_eval("defined?(#{varname})") + if @match[3] && @match[3] !~ /(:?no)?stop/ + errmsg("expecting 'stop' or 'nostop'; got %s\n" % @match[3]) + else + dbg_cmd = if @match[3] && (@match[3] !~ /nostop/) + 'debugger' else '' end + end + eval(" + trace_var(:#{varname}) do |val| + print \"traced variable #{varname} has value \#{val}\n\" + #{dbg_cmd} + end") + else + errmsg "#{varname} is not a global variable.\n" + end + else + errmsg("expecting 'on', 'off', 'var' or 'variable'; got: %s\n" % + @match[1]) end - if Debugger.tracing || Debugger.current_context.tracing - print "Trace on.\n" - else - print "Trace off.\n" - end end class << self @@ -26,8 +49,9 @@ %{ tr[ace] (on|off)\tset trace mode of current thread tr[ace] (on|off) all\tset trace mode of all threads + tr[ace] var(iable) VARNAME [stop|nostop]\tset trace variable on VARNAME } end end end -end \ No newline at end of file +end Modified: trunk/lib/ruby-debug-base.rb =================================================================== --- trunk/lib/ruby-debug-base.rb 2008-05-27 03:54:29 UTC (rev 845) +++ trunk/lib/ruby-debug-base.rb 2008-06-20 06:46:08 UTC (rev 846) @@ -94,6 +94,7 @@ # Get line +line_number+ from file named +filename+. Return "\n" # there was a problem. Leaking blanks are stripped off. def line_at(filename, line_number) # :nodoc: + @reload_on_change=nil unless defined?(@reload_on_change) line = LineCache::getline(filename, line_number, @reload_on_change) return "\n" unless line return "#{line.gsub(/^\s+/, '').chomp}\n"