|
From: <caw...@us...> - 2007-08-09 12:52:25
|
Revision: 2947
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=2947&view=rev
Author: cawilliams
Date: 2007-08-09 05:52:23 -0700 (Thu, 09 Aug 2007)
Log Message:
-----------
add newest stuff from debug-commons-0.9.4
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/ruby/classic-debug-verbose.rb
trunk/org.rubypeople.rdt.launching/ruby/classic-debug.rb
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/ruby/ChangeLog
trunk/org.rubypeople.rdt.launching/ruby/MIT-LICENSE
trunk/org.rubypeople.rdt.launching/ruby/README
trunk/org.rubypeople.rdt.launching/ruby/classic-debug.txt
trunk/org.rubypeople.rdt.launching/ruby/context.rb
trunk/org.rubypeople.rdt.launching/ruby/xml_printer.rb
Added: trunk/org.rubypeople.rdt.launching/ruby/ChangeLog
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/ChangeLog (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/ChangeLog 2007-08-09 12:52:23 UTC (rev 2947)
@@ -0,0 +1,140 @@
+2007-08-08 Martin Krauskopf <mar...@su...>
+
+ * lib/context.rb: to_inspect = str.gsub(/\\n/, "\n") in debug_eval() to make
+ possible to evaluate multiline expressions. Frontend must escape new
+ lines accordingly.
+
+2007-07-31 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: synchronize get_thread_num method
+
+2007-07-25 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug-verbose.rb, lib/context.rb, lib/xml_printer.rb:
+ synchronizing all socket communication to prevent race condition
+
+2007-07-23 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug-verbose.rb, lib/context.rb, lib/xml_printer.rb: code
+ reorganization. Context and Printer class moved to their own files. No
+ semantic change.
+
+ * lib/classic-debug-verbose.rb, lib/context.rb, lib/xml_printer.rb,
+ build_dist: more code cleanup. Rubyfying Java names. No semantic changes.
+
+2007-07-19 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: do not allow to call 'set_trace_func' by debuggee
+
+ * lib/classic-debug.rb: s/DEBUGGER__/DC_DEBUGGER__ to prevent debug.rb
+ collisions
+
+2007-07-17 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: send message 'finished' back when exiting
+
+2007-07-16 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: 'exit' command implemented
+
+2007-07-15 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: More protocols unification: sent error when the
+ negative number is passed to delete
+
+2007-07-12 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: Make 'self' first in the local variables list
+ (merging fast and classic debuggers protocols)
+
+2007-07-11 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: turning off some logging in debug mode. *Too*
+ verbose to be useful in a frontend. Might be uncommented by developer for
+ now.
+
+2007-07-09 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: prevent error when debugger process is killed +
+ better error logging
+
+2007-07-04 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: Return <message> for unknown command (merging fast
+ and classic debuggers protocols)
+
+ * classic-debug/test/*, test-base/*: Initial test refactoring. Sharing
+ common tests which work for both, classic and fast debuggers. Currently
+ stepping_breakpoints_test.
+
+2007-06-18 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: do not send binary data within values of variables.
+ See http://www.netbeans.org/nonav/issues/show_bug.cgi?id=101748 for more
+ details.
+
+2007-05-06 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb, test/cd_inspect_test.rb: escaping error message in
+ processingException. Sometime caused to send invalid XML.
+
+ * 0.9.3 released
+
+2007-04-27 Martin Krauskopf <mar...@su...>
+
+ * test/test_base.rb, test/cd_*_test.rb, test: fixing tests for JRuby
+ interpreter
+
+2007-03-29 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb, test/cd_stepping_breakpoints_test.rb: fixed bug with
+ breakpoints removing
+
+ * 0.9.2 released
+
+2007-03-20 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb: fix for handling file names and path containing
+ spaces and/or semicolons. Breakpoint struct introduced.
+
+ * test/cd_stepping_breakpoints_test.rb test/readers.rb test/test_base.rb:
+ test for the space and/or semicolon in path edge cases
+
+ * 0.9.1 released
+
+2007-03-15 Martin Krauskopf <mar...@su...>
+
+ * etc/build_dist: simple script for building tarball
+
+ * etc/kill_debugger: might be handy during testing phase
+
+ * README: TOC, 1.8.6 works smoothly, intermediate Java library note
+
+ * classic-debug.txt: initial description of few commands
+
+ * 0.9.0 released
+
+2007-02-21 Martin Krauskopf <mar...@su...>
+
+ * classic-debug.txt, README: description of $RemoteDebugPort
+
+ * test/test_base.rb: trivial - use File.join
+
+2007-02-19 Martin Krauskopf <mar...@su...>
+
+ * lib/classic-debug.rb, test/cd_stepping_breakpoints_test.rb: fixing (my)
+ regression of next/continue behavior while stepping over.
+
+2007-02-16 Martin Krauskopf <mar...@su...>
+
+ * test/cd_inspect_test.rb, test/readers.rb: merging more RDT tests from Java
+ to Ruby
+
+ * test/cd_*_test.rb, test/test_base.rb (run_to_line): new function plus
+ relevant refactoring
+
+2007-02-15 Martin Krauskopf <mar...@su...>
+
+ Initial debug-commons based on the Markus Barchfeld's RDT work. See README
+ file in the project directory for more details.
+
Added: trunk/org.rubypeople.rdt.launching/ruby/MIT-LICENSE
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/MIT-LICENSE (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/MIT-LICENSE 2007-08-09 12:52:23 UTC (rev 2947)
@@ -0,0 +1,24 @@
+The file lib/classic-debug.rb is based on the debug.rb file from Ruby
+project.
+
+Copyright (c) 2007 debug-commons team
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
Added: trunk/org.rubypeople.rdt.launching/ruby/README
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/README (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/README 2007-08-09 12:52:23 UTC (rev 2947)
@@ -0,0 +1,91 @@
+= debug-commons
+
+
+== TOC
+- Overview
+- History, Future, Aims
+- Requirements
+- Install
+- Related (sub)projects [intermediate libraries]
+- License
+
+
+== Overview
+
+----
+Note: this document is currently being more-or-less duplicate of the
+debug-commons homepage. So for the up-to-date information look rather at the
+site directly and follow the links there:
+
+http://debug-commons.rubyforge.org/
+----
+
+debug-commons currently consist of wrappers around various Ruby debugging
+backends. 'Wrapping' in this case means that backends are enriched by
+producing/consuming a unified XML-based protocol. Currently there are two
+wrappers, one for Ruby "classic debugger" (debug.rb) and another for Kent
+Sibilev's ruby-debug gem implementation. Both protocols have a lot in common,
+however differ slightly due to the nature of their implementation and
+behaviour. Take a look at classic-debug.txt and ruby-debug.txt files for more
+detailed information about individual protocols.
+
+
+== History, Future, Aims
+
+The project was originally developed as part of Ruby Development Tools[1]. The
+debugger plugin was mainly developed by Markus Barchfeld with the help of
+Christopher Williams, Werner Schuster (murphee), Mirko Stocker (and others) who
+work on other parts of RDT. Later Martin Krauskopf, implementing NetBeans
+debugger module, wrote to RDT people about possible cooperation on the backend
+they had. First official email here:
+
+http://sourceforge.net/mailarchive/forum.php?thread_id=31511654&forum_id=9198
+
+(MK: RDT folks have invested and brought a nice bunch of work. I believe
+both sides (and hopefully others) will gain a lot in the end).
+
+
+This project was founded because there doesn't seem to be a general open source
+solution in the Ruby world for debugger-frontend implementers. The aim is to
+provide such a solution for anyone who wants to start (or is already working)
+on a debugger frontend (standalone GUI debugger, an IDE or editor plugin,
+remote CLI-based one, ...). You might take a look at from-time-to-time evolving
+Ruby Debugging document:
+
+http://debug-commons.rubyforge.org/misc/ruby-debugging.html
+
+Hopefully, in the future, we will have something similar as e.g. Java has with
+its JPDA.
+
+Currently there are RDT and NetBeans contributors working on this common
+project - and anyone is very welcome to join.
+
+There are some consideration to be done like joining/supporting a Common
+Debugger Protocol (http://www.xdebug.org/docs-dbgp.php), better support for
+JRuby, ... [TBD - probably separate TODO] so feel free to join the mailing
+list(s) for a discussion about current and feature plans [TBD - link to MLs]
+
+
+== Requirements
+Currently tests fully pass with Ruby 1.8.6. Latest official build of 1.8.5
+(p35) seems to end with Segmentation fault on some machines. So better to use
+1.8.6 for non-problematic run. JRuby has some problems which are being
+subsequently filed (and fixed) into their Tracker. See status on the project's
+official website for more details.
+
+
+== Install
+Project is distributed as tarball containing classic-debug backend. Soon there
+should be also ruby-debug extension.
+
+
+== Related (sub)projects [intermediate libraries]
+Together with the backends project there are also subprojects containing
+libraries intermediating socket communication between backends and a frontend.
+Currently only library for Java is there. Hopefully more will come.
+
+
+== License
+
+See MIT-LICENSE file.
+
Modified: trunk/org.rubypeople.rdt.launching/ruby/classic-debug-verbose.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/classic-debug-verbose.rb 2007-08-09 12:50:11 UTC (rev 2946)
+++ trunk/org.rubypeople.rdt.launching/ruby/classic-debug-verbose.rb 2007-08-09 12:52:23 UTC (rev 2947)
@@ -1,3 +1,3 @@
-module DebugVerbose
-end
-require 'classic-debug'
\ No newline at end of file
+module DebugVerbose
+end
+require 'classic-debug'
Modified: trunk/org.rubypeople.rdt.launching/ruby/classic-debug.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/classic-debug.rb 2007-08-09 12:50:11 UTC (rev 2946)
+++ trunk/org.rubypeople.rdt.launching/ruby/classic-debug.rb 2007-08-09 12:52:23 UTC (rev 2947)
@@ -1,1199 +1,359 @@
-# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-# Copyright (C) 2000 Information-technology Promotion Agency, Japan
-require 'cgi'
-require 'thread'
-require 'yaml'
-
-# REMOTE_DEBUG_PORT is the port on which the debugger waits for commands from a
-# front-end.
-#
-# RDT note: if you change this, you must also change the corresponding port in
-# org.rubypeople.rdt.internal.debug.core.RubyDebuggerProxy
-REMOTE_DEBUG_PORT = (defined? $RemoteDebugPort) ? $RemoteDebugPort : 1098
-
-# VERBOSE_DEBUGGER prints the communication between a front-end and ruby
-# debugger on stderr. If you have started a front-end debug session (and use
-# default preferences for colors of streams), the communication will be printed
-# in red letters to the front-end console.
-VERBOSE_DEBUGGER = defined? DebugVerbose
-
-class PrinterMultiplexer
- def initialize
- @printers = []
- end
-
- def addPrinter(printer)
- @printers << printer
- end
-
- def method_missing(methodName, *args)
- @printers.each { |printer|
- printer.send(methodName, *args)
- }
- end
-end
-
-class XmlPrinter
-
- def initialize(socket)
- @socket = socket
- end
-
- def out(*params)
- debugIntern(false, *params)
- if @socket then
- @socket.printf(*params)
- end
- end
-
- def printXml(s, *params)
- out(s, *params)
- end
-
- def printError(s, *params)
- out("<error>" + s + "</error>", *params)
- end
-
- def printMessage(s, *params)
- out("<message>" + s + "</message>", *params)
- end
-
- def printVariable(name, binding, kind)
- printVariableValue(name, eval(name, binding), kind)
- end
-
- def printVariableValue(name, value, kind)
- if value == nil then
- out("<variable name=\"%s\" kind=\"%s\"/>", CGI.escapeHTML(name), kind)
- return
- end
- if value.class().name == "Array" or value.class().name == "Hash" then
- hasChildren = value.length > 0
- if value.length == 0 then
- valueString = "Empty " + value.class().name
- else
- valueString = value.class().name + " (" + value.length.to_s + " element(s))"
- end
- else
- hasChildren = value.instance_variables.length > 0 || value.class.class_variables.length > 0
- valueString = value.to_s
- if valueString =~ /^\"/ then
- valueString.slice!(1..(valueString.length)-2)
- end
- end
- valueString = "[Binary Data]" if valueString.is_binary_data?
- out("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\"/>", CGI.escapeHTML(name), kind, CGI.escapeHTML(valueString), value.class(), hasChildren, value.respond_to?(:object_id) ? value.object_id : value.id)
- end
-
- def printBreakpoint(n, debugFuncName, file, pos)
- out("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%s\"/>", file, pos, DEBUGGER__.get_thread_num())
- end
-
- def printException(file, pos, exception)
- out("<exception file=\"%s\" line=\"%s\" type=\"%s\" message=\"%s\" threadId=\"%s\"/>", file, pos, exception.class, CGI.escapeHTML(exception.to_s), DEBUGGER__.get_thread_num())
- end
-
- def printStepEnd(file, line, framesCount)
- out("<suspended file=\"%s\" line=\"%s\" frames=\"%s\" threadId=\"%s\"/>", file, line, framesCount, DEBUGGER__.get_thread_num())
- end
-
- def printFrame(pos, n, file, line, id)
- out("<frame no=\"%s\" file=\"%s\" line=\"%s\"/>", n, file, line)
- end
-
- def printThread(num, thread)
- out("<thread id=\"%s\" status=\"%s\"/>", num, thread.status)
- end
-
- def printLoadResult(file, exception=nil)
- if exception then
- out("<loadResult file=\"%s\" exceptionType=\"%s\" exceptionMessage=\"%s\"/>", file, exception.class, CGI.escapeHTML(exception.to_s))
- else
- out("<loadResult file=\"%s\" status=\"OK\"/>", file)
- end
- end
-
- def debug(*params)
- debugIntern(true, *params)
- end
-
- def debugIntern(escape, *params)
- if VERBOSE_DEBUGGER then
- output = sprintf(*params)
- output = CGI.escapeHTML(output) if escape
- STDERR.print(output)
-# STDERR.print(' [[' + caller(0)[2].sub(/[^:]*:/, '') + ' ')
-# STDERR.print(Thread.current.to_s + ']]')
- STDERR.print("\n")
- end
- end
-end
-
-#multiplex = PrinterMultiplexer.new
-#multiplex.addPrinter(XmlPrinter.new(nil))
-#multiplex.addPrinter(XmlPrinter.new(nil))
-#multiplex.printXml("TEST")
-
-require 'socket'
-require 'tracer'
-
-class Tracer
- def Tracer.trace_func(*vars)
- Single.trace_func(*vars)
- end
-end
-
-SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
-
-class DEBUGGER__
-
- # type: 0 - breakpoint, 1 - watchpoint
- Breakpoint = Struct.new("Breakpoint", :valid, :type, :file, :pos)
-
- class CommandLinePrinter
- def printXml(s)
- # print XML only
- end
-
- def printVariable(name, binding, kind)
- stdout.printf " %s => %s\n", name, eval(name, binding).inspect
- end
-
- def printBreakpoint(n, debugFuncName, file, pos)
- stdout.printf "Breakpoint %d, %s at %s:%s\n", n, debugFuncName, file, pos
- stdout.flush
- end
-
- def printFrame(pos, n, file, line, id)
- if pos == n
- stdout.printf "--> #%d %s:%s%s\n", n, file, line, id ? ":in `#{id.id2name}'":""
- else
- stdout.printf " #%d %s:%s%s\n", n, file, line, id ? ":in `#{id.id2name}'":""
- end
- end
-
- def printException(file, line, exception)
- stdout.printf "%s:%d: `%s' (%s)\n", file, line, exception, exception.class
- stdout.flush
- end
-
- def printThread(num, thread)
- if thread == Thread.current
- stdout.print "+"
- else
- stdout.print " "
- end
- stdout.printf "%d ", num
- stdout.print thread.inspect, "\t"
- file = DEBUGGER__.context(thread).instance_eval{@file}
- if file
- stdout.print file, ":", DEBUGGER__.context(thread).instance_eval{@line}
- end
- stdout.print "\n"
- end
-
-
- def printStepEnd(file, line, framesCount)
-
- end
-
- def debug(*params)
-
- end
-
- def stdout
- DEBUGGER__.stdout
- end
- end
-
- class Context
- attr_reader :shouldResume
- def initialize
- @printer = DEBUGGER__.printer
- @socket = DEBUGGER__.socket
- @stop_next = 0
- @last_file = nil
- @file = nil
- @line = nil
- @no_step = nil
- @frames = []
- @current_frame = -1
- @finish_pos = 0
- @trace = false
- @catch = nil # "StandardError"
- @suspend_next = false
- @shouldResume = false
- end
-
- def stop_next(n=1)
- @stop_next = n
- end
-
- def set_suspend
- @suspend_next = true
- end
-
- def clear_suspend
- @suspend_next = false
- end
-
- def stopCurrentThread
- @printer.debug("Suspending : %s", Thread.current)
- Thread.stop()
- @printer.debug("Resumed : %s", Thread.current)
- end
-
- def trace?
- @trace
- end
-
- def set_trace(arg)
- @trace = arg
- end
-
- def stdout
- if @socket then
- @socket
- else
- DEBUGGER__.stdout
- end
- end
-
- def break_points
- DEBUGGER__.break_points
- end
-
- def display
- DEBUGGER__.display
- end
-
- def context(th)
- DEBUGGER__.context(th)
- end
-
- def set_trace_all(arg)
- DEBUGGER__.set_trace(arg)
- end
-
- def set_last_thread(th)
- DEBUGGER__.set_last_thread(th)
- end
-
- def debug_eval_private(str, binding)
- # evaluates str like "var.@instance_var.@instance_var"
- # and "var.privateMethod"
- # return value might be nil
- # the scan must detect array and hash accesses, which might
- # themselves contain point separated expressions, e.g.
- # array[Test.getX].y
- names = str.scan(/[^\[\]]*(?=\.)|.*\[.*\](?=\.)|.*$/)
- # names can contain empty strings
- obj = eval(names[0], binding)
- (1..names.length-1).each { |i|
- if names[i] != "" then
- if names[i].length > 2 && names[i][0..1] == '@@' then
- @printer.debug("Evaluating (class_var): %s on %s", names[i], obj )
- obj = obj.class.class_eval("#{names[i]}")
- else
- @printer.debug("Evaluating (instance_var): %s on %s", names[i], obj )
- obj = obj.instance_eval("#{names[i]}")
- end
- end
- }
- return obj
- end
-
- def debug_eval(str, binding, noPrivateInstanceVars = false)
- begin
- if noPrivateInstanceVars then
- val = eval(str, binding)
- else
- val = debug_eval_private(str, binding)
- end
- val
- rescue ScriptError, StandardError => error
- if error.to_s =~ /private method .* called for/ then
- return debug_eval(str, binding, true)
- end
- @printer.debug("Error in debug_eval (noPrivateInstancsVars=%s): %s", noPrivateInstanceVars, error)
- raise error
- end
- end
-
- def debug_silent_eval(str, binding)
- begin
- val = eval(str, binding)
- val
- rescue StandardError, ScriptError
- nil
- end
- end
-
- def var_list(ary, binding, kind)
- ary.sort! do |v1, v2|
- if v1 == 'self'
- result = -1
- elsif v2 == 'self'
- result = 1
- else
- result = v1 <=> v2
- end
- result
- end
- @printer.printXml("<variables>")
- for v in ary
- @printer.printVariable(v,binding, kind)
- end
- @printer.printXml("</variables>")
- end
-
- def printArrayElements(array)
- index = 0
- array.each { |e|
- @printer.printVariableValue('[' + index.to_s + ']', e, 'instance')
- index += 1
- }
- end
-
- def printHashElements(hash)
- hash.keys.each { | k |
- if k.class.name == "String"
- name = '\'' + k + '\''
- else
- name = k.to_s
- end
- @printer.printVariableValue(name, hash[k], 'instance')
- }
- end
-
-
- def getConstantsInClass(aClass)
- constants = aClass.constants() - Object.constants
- return constants.delete_if { |c| ! aClass.const_defined? c }
- end
-
-
- def getBinding(pos)
- # returns frame info of frame pos, if pos is within bound, nil otherwise
- pos = @current_frame unless pos
- pos = pos.to_i - 1
- if pos < 0 then
- @printer.debug("ERROR: illegal stack frame, using top frame.")
- pos = 0
- end
- if pos >= @frames.size then
- @printer.debug("ERROR: given stack frame number %i too high.", pos + 1)
- pos = @frames.size - 1
- end
- @printer.debug("Using frame %s (1-based) for evaluation of variable.", pos + 1)
- return @frames[pos][0]
- end
-
-
- def debug_variable_info(input, binding)
-
- case input
- when /^\s*g(?:lobal)?$/
- var_list(global_variables, binding, 'global')
-
- when /^\s*l(?:ocal)?\s*(\d+)?$/
- @printer.debug("Getting binding for frame #{$1}")
- new_binding = getBinding($1)
- if new_binding then
- binding = new_binding
- end
- begin
- #@printer.debug("binding=%s", binding)
- localVars = eval("local_variables", binding)
- # v 1.8.1 dies in eval @printer.debug("HERE")
- if eval('self.to_s', binding) !~ /main/ then
- localVars << "self"
- end
- var_list(localVars, binding, 'local')
- rescue StandardError => bang
- @printer.debug("Exception while evaluating local_variables: %s", bang)
- var_list([], binding, 'local')
- end
-
- when /^\s*i(?:nstance)?\s*(\d+)?\s+((?:[\\+-]0x)[\dabcdef]+)?/
- new_binding = getBinding($1)
- if new_binding then
- binding = new_binding
- end
- begin
- @printer.printXml("<variables>")
- if $2 then
- obj = ObjectSpace._id2ref($2.hex)
- if (!obj) then
- @printer.debug("unknown object id : %s", $2)
- end
- else
- obj = debug_eval($', binding)
- end
- if (obj.class.name == "Array") then
- printArrayElements(obj)
- return
- end
- if (obj.class.name == "Hash") then
- printHashElements(obj)
- return
- end
- @printer.debug("%s", obj)
- instanceBinding = obj.instance_eval{binding()}
- obj.instance_variables.each {
- | instanceVar |
- @printer.printVariable(instanceVar, instanceBinding, 'instance')
- }
- classBinding = obj.class.class_eval('binding()')
- obj.class.class_variables.each {
- | classVar |
- @printer.printVariable(classVar, classBinding, 'class')
- }
- # I'd like to optimize getting the constants, but they are more dynamic
- # than one would expect from true constants.
- getConstantsInClass(obj.class).each {
- | constant |
- @printer.printVariable(constant, classBinding, 'constant')
- }
- rescue StandardError => error
- @printer.debug("%s", error)
- ensure
- @printer.printXml("</variables>")
- end
-
-
- when /^\s*inspect\s*(\d+)?\s+/
- new_binding = getBinding($1)
- if new_binding then
- binding = new_binding
- end
- begin
- obj = debug_eval($', binding, true)
- rescue ScriptError, StandardError => error
- @printer.printXml("<processingException type=\"%s\" message=\"%s\"/>", error.class, CGI.escapeHTML(error.message))
- return
- end
- @printer.debug("%s", obj)
- @printer.printXml("<variables>")
- @printer.printVariableValue($', obj, "local")
- @printer.printXml("</variables>")
- end
- end
-
- def debug_method_info(input, binding)
- case input
- when /^i(:?nstance)?\s+/
- obj = debug_eval($', binding) # correct highlighting since RDT editor does not recognize $'
-
- len = 0
- for v in obj.methods.sort
- len += v.size + 1
- if len > 70
- len = v.size + 1
- stdout.print "\n"
- end
- stdout.print v, " "
- end
- stdout.print "\n"
-
- else
- obj = debug_eval(input, binding)
- unless obj.kind_of? Module
- stdout.print "Should be Class/Module: ", input, "\n"
- else
- len = 0
- for v in obj.instance_methods.sort
- len += v.size + 1
- if len > 70
- len = v.size + 1
- stdout.print "\n"
- end
- stdout.print v, " "
- end
- stdout.print "\n"
- end
- end
- end
-
- def thnum(thread=Thread.current)
- num = DEBUGGER__.instance_eval{@thread_list[thread]}
- unless num
- DEBUGGER__.make_thread_list
- num = DEBUGGER__.instance_eval{@thread_list[thread]}
- end
- num
- end
-
- def processInput(input)
- binding, file, line, id = @frames[0]
- input.split(";").each {
- | singleCommand |
- readUserInput(binding, file, line, singleCommand.strip)
- }
- end
-
- def readUserInput(binding, binding_file, binding_line, input)
-
- @printer.debug("Processing #{input}, binding=%s", binding)
- @shouldResume = false
- frame_pos = 0
- previous_line = nil
- display_expressions(binding)
-
- case input
- when /^\s*tr(?:ace)?(?:\s+(on|off))?(?:\s+(all))?$/
- if defined?( $2 )
- if $1 == 'on'
- set_trace_all true
- else
- set_trace_all false
- end
- elsif defined?( $1 )
- if $1 == 'on'
- set_trace true
- else
- set_trace false
- end
- end
- if trace?
- stdout.print "Trace on.\n"
- else
- stdout.print "Trace off.\n"
- end
-
- when /^\s*b(?:reak)?\s+(?:(.+):)?([^.:]+)$/
- pos = $2
- file = File.basename($1)
- if pos =~ /^\d+$/
- pname = pos
- pos = pos.to_i
- else
- pname = pos = pos.intern.id2name
- end
- # TODO: pname is not used
- id = DEBUGGER__.next_breakpoint_id
- break_points[id] = Breakpoint.new(true, 0, file, pos)
- @printer.printXml("<breakpointAdded no=\"%d\" location=\"%s:%s\"/>", id, file, pos)
-
- when /^\s*delete\s+(.*)$/
- arg = $1
- if arg !~ /(?:^\d+$)/
- @printer.printError "Delete argument '#{arg}' needs to be positive number"
- else
- breakpoint_id = arg.to_i
- if break_points.delete(breakpoint_id)
- @printer.printXml("<breakpointDeleted no=\"%d\"/>", breakpoint_id)
- else
- @printer.printError("No breakpoint with id: %d. Currently following breakpoints defined: %s",
- breakpoint_id, break_points.keys.join(', '))
- end
- end
-
- # when /^\s*wat(?:ch)?\s+(.+)$/
- # exp = $1
- # break_points.push [true, 1, exp]
- # stdout.printf "Set watchpoint %d\n", break_points.size, exp
-
- # when /^\s*b(?:reak)?$/
- # if break_points.find{|b| b[1] == 0}
- # n = 1
- # stdout.print "Breakpoints:\n"
- # for b in break_points
- # if b[0] and b[1] == 0
- # stdout.printf " %d %s:%s\n", n, b[2], b[3]
- # end
- # n += 1
- # end
- # end
- # if break_points.find{|b| b[1] == 1}
- # n = 1
- # stdout.print "\n"
- # stdout.print "Watchpoints:\n"
- # for b in break_points
- # if b[0] and b[1] == 1
- # stdout.printf " %d %s\n", n, b[2]
- # end
- # n += 1
- # end
- # end
- # if break_points.size == 0
- # stdout.print "No breakpoints\n"
- # else
- # stdout.print "\n"
- # end
-
- # when /^\s*disp(?:lay)?\s+(.+)$/
- # exp = $1
- # display.push [true, exp]
- # stdout.printf "%d: ", display.size
- # display_expression(exp, binding)
- #
- # when /^\s*disp(?:lay)?$/
- # display_expressions(binding)
- #
- # when /^\s*undisp(?:lay)?(?:\s+(\d+))?$/
- # pos = $1
- # unless pos
- # input = readline("Clear all expressions? (y/n) ", false)
- # if input == "y"
- # for d in display
- # d[0] = false
- # end
- # end
- # else
- # pos = pos.to_i
- # if display[pos-1]
- # display[pos-1][0] = false
- # else
- # stdout.printf "Display expression %d is not defined\n", pos
- # end
- # end
-
- when /^\s*c(?:ont)?$/
- @shouldResume = true
-
- when /^\s*s(?:tep)?(?:\s+(\d+))?$/
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- @stop_next = lev
- @shouldResume = true
-
- when /^\s*n(?:ext)?(?:\s+(\d+))?$/
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- @stop_next = lev
- @no_step = @frames.size - frame_pos
- @shouldResume = true
-
- when /^\s*w(?:here)?$/, /^\s*f(?:rame)?$/
- display_frames(frame_pos)
-
- # when /^\s*fin(?:ish)?$/
- # if frame_pos == @frames.size
- # stdout.print "\"finish\" not meaningful in the outermost frame.\n"
- # else
- # @finish_pos = @frames.size - frame_pos
- # frame_pos = 0
- # prompt = false
- # end
- when /^\s*f(?:rame)?\s+(\d+)\s*$/
- @printer.debug("Setting frame to #{$1}")
- @current_frame = $1.to_i
-
-
- when /^\s*cat(?:ch)?(?:\s+(.+))?$/
- # $1 can also be nil
- @catch = $1
- @catch = nil if @catch == 'off'
- if @catch then
- @printer.debug("Catchpoint set to #{@catch}")
- else
- @printer.debug("Catchpoints disabled")
- end
-
-
- when /^\s*v(?:ar)?\s+/
- debug_variable_info($', binding)
-
- when /^\s*m(?:ethod)?\s+/
- debug_method_info($', binding)
-
- when /^\s*th(?:read)?\s+/
- DEBUGGER__.debug_thread_info($', binding)
-
- when /^\s*p\s+/
- stdout.printf "%s\n", debug_eval($', binding).inspect
-
- when /^\s*load\s+/
- @printer.debug("loading file: %s", $')
- begin
- load $'
- @printer.printLoadResult($')
- rescue Exception => error
- @printer.printLoadResult($', error)
- end
-
- when /^\s*exit$/
- @printer.printMessage("finished")
- set_trace_func nil
- @socket.close
- exit!
-
- else
- @printer.printMessage("Unknown input: %s", input)
- end
-
- end
-
- def display_expressions(binding)
- n = 1
- for d in display
- if d[0]
- stdout.printf "%d: ", n
- display_expression(d[1], binding)
- end
- n += 1
- end
- end
-
- def display_expression(exp, binding)
- stdout.printf "%s = %s\n", exp, debug_silent_eval(exp, binding).to_s
- end
-
- def frame_set_pos(binding, file, line, id)
- if @frames[0] then
- @frames[0][0] = binding
- @frames[0][1] = file
- @frames[0][2] = line
- @frames[0][3] = id
- else
- @frames[0] = [binding, file, line, id]
- end
- end
-
- def display_frames(pos)
- pos += 1
- n = 0
- at = @frames
- @printer.printXml("<frames>")
- for bind, file, line, id in at
- n += 1
- break unless bind
- @printer.printFrame(pos, n, file, line, id)
- end
- @printer.printXml("</frames>")
- end
-
- def debug_funcname(id)
- if id.nil?
- "toplevel"
- else
- id.id2name
- end
- end
-
- def debug_command(file, line, id, binding)
- @printer.debug("debug_command, @stop_next=%s, @frames.size=%s", @stop_next, @frames.size)
- if @stop_next == 0 && @frames.size > 0 then
- # write suspended only if the suspension was originated by stepping and not before the start
- # of the program
- @printer.printStepEnd(file, line, @frames.size)
- end
- set_last_thread(Thread.current)
-
- #readUserInput(binding, file, line )
- #Thread.stop
- end
-
- def check_break_points(file, pos, binding, id)
- return false if break_points.empty?
- file = File.basename(file)
- n = 1
- break_points.each_value do |b|
-# @printer.debug("file=%s, pos=%s; breakpoint=[valid=%s, type=%s, file=%s, pos=%s]\n ",
-# file, pos, b.valid, b.type, b.file, b.pos)
- if b.valid
- if b.type == 0 and b.file == file and b.pos == pos # breakpoint
- @printer.printBreakpoint(n, debug_funcname(id), file, pos)
- return true
- elsif b.type == 1 # watchpoint
- if debug_silent_eval(b.file, binding)
- stdout.printf "Watchpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
- return true
- end
- end
- end
- n += 1
- end
- return false
- end
-
- def excn_handle(file, line, id, binding)
-
- if $!.class <= SystemExit
- @printer.debug( "SystemExit at %s:%d: `%s' (%s)\n", file, line, $!, $!.class )
- set_trace_func nil
- exit
- end
- if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch })
- @printer.printException(file, line, $!)
- fs = @frames.size
- tb = caller(0)[-fs..-1]
- stopCurrentThread
- @frames[0] = [binding, file, line, id]
- debug_command(file, line, id, binding)
- end
-
- end
-
- def trace_func(event, file, line, id, binding, klass)
- Tracer.trace_func(event, file, line, id, binding, klass) if trace?
-
- @file = file
- @line = line
- case event
- when 'line'
- # DEBUGGER__.printer().debug("trace line, file=%s, line=%s, stop_next=%d, binding=%s", file, line, @stop_next, binding)
- frame_set_pos(binding, file, line, id)
- if !@no_step or @frames.size == @no_step
- @stop_next -= 1
- @stop_next = -1 if @stop_next < 0
- elsif @frames.size < @no_step
- @stop_next = 0 # break here before leaving...
- else
- # nothing to do. skipped
- end
- if @stop_next == 0 or check_break_points(file, line, binding, id)
- @no_step = nil
- debug_command(file, line, id, binding)
- stopCurrentThread
- end
-
- when 'call'
-# DEBUGGER__.printer().debug("trace call, file=%s, line=%s, method=%s", file, line, id.id2name)
- @frames.unshift [binding, file, line, id]
- if check_break_points(file, id.id2name, binding, id) or
- check_break_points(klass.to_s, id.id2name, binding, id) then
- stopCurrentThread
- debug_command(file, line, id, binding)
- end
-
- when 'c-call'
- if @frames[0] then
- @frames[0][1] = file
- @frames[0][2] = line
- else
- @frames[0] = [binding, file, line, id]
- end
-
- when 'class'
- @frames.unshift [binding, file, line, id]
-
- when 'return', 'end'
-# DEBUGGER__.printer().debug("trace return and end, file=%s, line=%s", file, line)
- if @frames.size == @finish_pos
- @stop_next = 1
- @finish_pos = 0
- end
- @frames.shift
-
- when 'end'
-# DEBUGGER__.printer().debug("trace end, file=%s, line=%s", file, line)
- @frames.shift
-
- when 'raise'
- excn_handle(file, line, id, binding)
-
- end
- @last_file = file
- end
- end
-
- trap("INT") { DEBUGGER__.interrupt }
- @last_thread = Thread::main
- @max_thread = 1
- @max_breakpoint_id = 0
- @thread_list = {Thread::main => 1}
- @break_points = {} # id => Breakpoint
- @display = []
- @waiting = []
- @stdout = STDOUT
-
- class << DEBUGGER__
- def stdout
- @stdout
- end
-
- def stdout=(s)
- @stdout = s
- end
-
- def display
- @display
- end
-
- def break_points
- @break_points
- end
-
- def waiting
- @waiting
- end
-
- def set_trace( arg )
- Thread.critical = true
- make_thread_list
- for th in @thread_list
- context(th[0]).set_trace arg
- end
- Thread.critical = false
- end
-
- def set_last_thread(th)
- @last_thread = th
- end
-
- def suspend
- printer.debug("Suspending all")
- Thread.critical = true
- make_thread_list
- for th in @thread_list
- next if th[0] == Thread.current
- context(th[0]).set_suspend
- end
- Thread.critical = false
- # Schedule other threads to suspend as soon as possible.
- Thread.pass
- end
-
- def resume
- Thread.critical = true
- make_thread_list
- for th in @thread_list
- next if th[0] == Thread.current
- context(th[0]).clear_suspend
- end
- waiting.each do |th|
- th.run
- end
- waiting.clear
- Thread.critical = false
- # Schedule other threads to restart as soon as possible.
- Thread.pass
- end
-
- def context(thread=Thread.current)
- c = thread[:__debugger_data__]
- unless c
- thread[:__debugger_data__] = c = Context.new
- end
- c
- end
-
- def findThread(context)
- for thread in Thread::list
- if context == thread[:__debugger_data__]
- return thread
- end
- end
- end
-
- def interrupt
- context(@last_thread).stop_next
- end
-
- def get_thread(num)
- th = @thread_list.index(num)
- unless th
- printer.debug("No thread ##{num}\n")
- end
- th
- end
-
- def get_thread_num(thread=Thread.current)
- make_thread_list
- @thread_list[thread]
- end
-
- def print_thread(thread)
- num = @thread_list[thread]
- printer.printThread(num, thread)
- end
-
- def thread_list_all
- printer.printXml("<threads>")
- for num in @thread_list.values.sort
- printer.printThread(num, get_thread(num))
- end
- printer.printXml("</threads>")
- end
-
- def make_thread_list
- hash = {}
- for th in Thread::list
- next if th == @@inputReader
- if @thread_list.key? th
- hash[th] = @thread_list[th]
- else
- @max_thread += 1
- hash[th] = @max_thread
- end
- end
- @thread_list = hash
- end
-
- def debug_thread_info(input, binding)
- case input
- when /^l(?:ist)?/
- make_thread_list
- thread_list_all
-
- when /^c(?:ur(?:rent)?)?$/
- make_thread_list
- print_thread()
-
- when /^(?:sw(?:itch)?\s+)?(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- else
- print_thread(th)
- context(th).stop_next
- th.run
- return
- end
-
- when /^stop\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif th.stop?
- @stdout.print "Already stopped.\n"
- else
- print_thread(th)
- context(th).suspend
- end
-
- when /^resume\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif !th.stop?
- @stdout.print "Already running."
- else
- print_thread(th)
- th.run
- end
-
- when /^change\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- print_thread(th)
- return context(th)
- end
- end
-
- def next_breakpoint_id
- @max_breakpoint_id += 1
- end
- end
-
- @@socket = nil
- @@printer = nil
- @@inputReader = nil
- @@isStarted = false
-
- def DEBUGGER__.printer
- @@printer
- end
-
- def DEBUGGER__.socket
- @@socket
- end
-
- def DEBUGGER__.isStarted
- @@isStarted
- end
-
- def DEBUGGER__.setStarted
- @@isStarted = true
- end
-
-
- def DEBUGGER__.inputReader
- @@inputReader
- end
-
- def DEBUGGER__.traceOn()
- set_trace_func @@traceProc
- Thread.critical = false
- end
-
- def DEBUGGER__.traceOff()
- Thread.critical = true
- set_trace_func nil
- end
-
- def DEBUGGER__.readCommandLoop()
- sleep(1.0) # workaround for large files with ruby 1.6.8, otherwise parse exceptions
- loop do
- sleep(0.1)
- new_data, _, _ = IO.select( [socket], nil, nil, 0.001 )
- next unless new_data
- DEBUGGER__.traceOff()
- input = new_data[0].gets
- unless input
- @@printer.debug "Socket #{socket} closed. Ending."
- break
- end
- input.chomp!
- input.strip!
- @@printer.debug("READ #{input}")
- if !DEBUGGER__.isStarted && input == "cont" then
- DEBUGGER__.setStarted()
- DEBUGGER__.traceOn()
- next
- end
- input =~ /^th\s+(\d+)\s*;\s*/
- if $~ then
- @@printer.debug("Using context for thread: %s", $1.to_i)
- context = DEBUGGER__.context(get_thread($1.to_i))
- input = input[$~[0].length..input.length]
- else
- @@printer.debug("Using context for main thread : %s", Thread.main)
- context = DEBUGGER__.context(Thread.main)
- end
- context.processInput(input)
- if context.shouldResume then
- threadToResume = DEBUGGER__.findThread(context)
- end
- DEBUGGER__.traceOn()
- next unless threadToResume
- threadToResume.run()
- end
- end
-
- # use 127.0.0.1 instead of localhost because OSX 10.4
- server = TCPServer.new('127.0.0.1', REMOTE_DEBUG_PORT)
- puts "ruby #{RUBY_VERSION} debugger listens on port #{REMOTE_DEBUG_PORT}"
- $stdout.flush
- STDERR.sync = true
- @@socket = server.accept
- @@printer = XmlPrinter.new(@@socket)
- @@printer.debug("Socket connection established.")
-
- @@printer.debug("Starting command reader loop.")
- @@inputReader = Thread.new {
- begin
- DEBUGGER__.readCommandLoop()
- rescue ScriptError, StandardError => error
- y error
- y error.backtrace
- end
- }
-
- @@traceProc = proc { |event, file, line, id, binding, klass, *rest|
-
- #@@printer.debug("trace %s, %s:%s", event, file, line)
- next if Thread.current == DEBUGGER__.inputReader
- next if file =~ /classic-debug.rb$/
- #@@printer.debug("trace %s, %s:%s", event, file, line)
- while (!DEBUGGER__.isStarted) do
- @@printer.debug("Debugging not yet started.")
- sleep(1)
- end
- DEBUGGER__.context.trace_func event, file, line, id, binding, klass
- }
-
- @@printer.debug("Setting trace func: %s", @@traceProc)
- set_trace_func @@traceProc
-end
+# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
+# Copyright (C) 2000 Information-technology Promotion Agency, Japan
+
+require 'cgi'
+require 'thread'
+require 'yaml'
+require 'socket'
+require 'tracer'
+require 'xml_printer'
+require 'context'
+
+# REMOTE_DEBUG_PORT is the port on which the debugger waits for commands from a
+# front-end.
+#
+# RDT note: if you change this, you must also change the corresponding port in
+# org.rubypeople.rdt.internal.debug.core.RubyDebuggerProxy
+REMOTE_DEBUG_PORT = (defined? $RemoteDebugPort) ? $RemoteDebugPort : 1098
+
+# VERBOSE_DEBUGGER prints the communication between a front-end and ruby
+# debugger on stderr. If you have started a front-end debug session (and use
+# default preferences for colors of streams), the communication will be printed
+# in red letters to the front-end console.
+VERBOSE_DEBUGGER = defined? DebugVerbose
+
+class Tracer
+ def Tracer.trace_func(*vars)
+ Single.trace_func(*vars)
+ end
+end
+
+SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
+
+class DC_DEBUGGER__
+
+ # type: 0 - breakpoint, 1 - watchpoint
+ Breakpoint = Struct.new("Breakpoint", :valid, :type, :file, :pos)
+
+ trap("INT") { DC_DEBUGGER__.interrupt }
+ @last_thread = Thread::main
+ @max_thread = 1
+ @max_breakpoint_id = 0
+ @thread_list = {Thread::main => 1}
+ @break_points = {} # id => Breakpoint
+ @display = []
+ @waiting = []
+ @stdout = STDOUT
+
+ class << DC_DEBUGGER__
+ def stdout
+ @stdout
+ end
+
+ def stdout=(s)
+ @stdout = s
+ end
+
+ def display
+ @display
+ end
+
+ def break_points
+ @break_points
+ end
+
+ def waiting
+ @waiting
+ end
+
+ def set_trace( arg )
+ Thread.critical = true
+ make_thread_list
+ for th in @thread_list
+ context(th[0]).set_trace arg
+ end
+ Thread.critical = false
+ end
+
+ def set_last_thread(th)
+ @last_thread = th
+ end
+
+ def suspend
+ printer.debug("Suspending all")
+ Thread.critical = true
+ make_thread_list
+ for th in @thread_list
+ next if th[0] == Thread.current
+ context(th[0]).set_suspend
+ end
+ Thread.critical = false
+ # Schedule other threads to suspend as soon as possible.
+ Thread.pass
+ end
+
+ def resume
+ Thread.critical = true
+ make_thread_list
+ for th in @thread_list
+ next if th[0] == Thread.current
+ context(th[0]).clear_suspend
+ end
+ waiting.each do |th|
+ th.run
+ end
+ waiting.clear
+ Thread.critical = false
+ # Schedule other threads to restart as soon as possible.
+ Thread.pass
+ end
+
+ def context(thread=Thread.current)
+ c = thread[:__debugger_data__]
+ unless c
+ thread[:__debugger_data__] = c = DC_DEBUGGER__::Context.new
+ end
+ c
+ end
+
+ def find_thread(context)
+ for thread in Thread::list
+ if context == thread[:__debugger_data__]
+ return thread
+ end
+ end
+ @@printer.debug("thread for context '#{context}' was not found")
+ nil
+ end
+
+ def interrupt
+ context(@last_thread).stop_next
+ end
+
+ def get_thread(num)
+ th = @thread_list.index(num)
+ unless th
+ printer.debug("No thread ##{num}\n")
+ end
+ th
+ end
+
+ def get_thread_num(thread=Thread.current)
+ Thread.critical = true
+ make_thread_list
+ n = @thread_list[thread]
+ Thread.critical = false
+ n
+ end
+
+ def print_thread(thread)
+ num = @thread_list[thread]
+ printer.print_thread(num, thread)
+ end
+
+ def thread_list_all
+ printer.synchronize do
+ printer.print_xml("<threads>")
+ for num in @thread_list.values.sort
+ printer.print_thread(num, get_thread(num))
+ end
+ printer.print_xml("</threads>")
+ end
+ end
+
+ def make_thread_list
+ hash = {}
+ for th in Thread::list
+ next if th == @@input_reader
+ if @thread_list.key? th
+ hash[th] = @thread_list[th]
+ else
+ @max_thread += 1
+ hash[th] = @max_thread
+ end
+ end
+ @thread_list = hash
+ end
+
+ def debug_thread_info(input, binding)
+ case input
+ when /^l(?:ist)?/
+ make_thread_list
+ thread_list_all
+
+ when /^c(?:ur(?:rent)?)?$/
+ make_thread_list
+ print_thread()
+
+ when /^(?:sw(?:itch)?\s+)?(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ else
+ print_thread(th)
+ context(th).stop_next
+ th.run
+ return
+ end
+
+ when /^stop\s+(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ elsif th.stop?
+ @stdout.print "Already stopped.\n"
+ else
+ print_thread(th)
+ context(th).suspend
+ end
+
+ when /^resume\s+(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ elsif !th.stop?
+ @stdout.print "Already running."
+ else
+ print_thread(th)
+ th.run
+ end
+
+ when /^change\s+(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ print_thread(th)
+ return context(th)
+ end
+ end
+
+ def next_breakpoint_id
+ @max_breakpoint_id += 1
+ end
+ end
+
+ @@socket = nil
+ @@printer = nil
+ @@input_reader = nil
+ @@is_started = false
+
+ def DC_DEBUGGER__.printer
+ @@printer
+ end
+
+ def DC_DEBUGGER__.socket
+ @@socket
+ end
+
+ def DC_DEBUGGER__.is_started
+ @@is_started
+ end
+
+ def DC_DEBUGGER__.set_started
+ @@is_started = true
+ end
+
+
+ def DC_DEBUGGER__.input_reader
+ @@input_reader
+ end
+
+ def DC_DEBUGGER__.trace_on()
+ debug_commons_set_trace_func @@trace_proc
+ Thread.critical = false
+ end
+
+ def DC_DEBUGGER__.trace_off()
+ Thread.critical = true
+ debug_commons_set_trace_func nil
+ end
+
+ def DC_DEBUGGER__.read_command_loop()
+ sleep(1.0) # workaround for large files with ruby 1.6.8, otherwise parse exceptions
+ loop do
+ sleep(0.1)
+ new_data, _, _ = IO.select( [socket], nil, nil, 0.001 )
+ next unless new_data
+ DC_DEBUGGER__.trace_off()
+ input = new_data[0].gets
+ unless input
+ @@printer.debug "Socket #{socket} closed. Ending."
+ break
+ end
+ input.chomp!
+ input.strip!
+ @@printer.debug("READ #{input}")
+ if !DC_DEBUGGER__.is_started && input == "cont" then
+ DC_DEBUGGER__.set_started()
+ DC_DEBUGGER__.trace_on()
+ next
+ end
+ input =~ /^th\s+(\d+)\s*;\s*/
+ if $~ then
+ @@printer.debug("Using context for thread: %s", $1.to_i)
+ th = get_thread($1.to_i)
+ unless th
+ @@printer.debug("Cannot find thread ##{$1.to_i}. Skipping command '#{input}'")
+ DC_DEBUGGER__.trace_on()
+ next
+ end
+ context = DC_DEBUGGER__.context(th)
+ input = input[$~[0].length..input.length]
+ else
+ @@printer.debug("Using context for main thread : %s", Thread.main)
+ context = DC_DEBUGGER__.context(Thread.main)
+ end
+ context.process_input(input)
+ if context.should_resume then
+ thread_to_resume = DC_DEBUGGER__.find_thread(context)
+ end
+ DC_DEBUGGER__.trace_on()
+ next unless thread_to_resume
+ thread_to_resume.run()
+ end
+ end
+
+ # use 127.0.0.1 instead of localhost because OSX 10.4
+ server = TCPServer.new('127.0.0.1', REMOTE_DEBUG_PORT)
+ puts "ruby #{RUBY_VERSION} debugger listens on port #{REMOTE_DEBUG_PORT}"
+ $stdout.flush
+ STDERR.sync = true
+ @@socket = server.accept
+ @@printer = DC_DEBUGGER__::XmlPrinter.new(@@socket)
+ @@printer.debug("Socket connection established.")
+
+ @@printer.debug("Starting command reader loop.")
+ @@input_reader = Thread.new {
+ begin
+ DC_DEBUGGER__.read_command_loop()
+ rescue ScriptError, StandardError => error
+ y error
+ y error.backtrace
+ end
+ }
+
+ @@trace_proc = proc { |event, file, line, id, binding, klass, *rest|
+ #@@printer.debug("trace %s, %s:%s", event, file, line)
+ next if Thread.current == DC_DEBUGGER__.input_reader
+ next if file =~ /classic-debug.rb$/
+ #@@printer.debug("trace %s, %s:%s", event, file, line)
+ while (!DC_DEBUGGER__.is_started) do
+ @@printer.debug("Debugging not yet started.")
+ sleep(1)
+ end
+ DC_DEBUGGER__.context.trace_func(event, file, line, id, binding, klass)
+ }
+
+ @@printer.debug("Setting trace func: %s", @@trace_proc)
+ Kernel.module_eval(<<-"end;"
+ alias_method(:debug_commons_set_trace_func, :set_trace_func)
+ def set_trace_func(proc)
+ raise "Cannot call 'set_trace_func' method during debugging session."
+ end
+ end;
+ )
+ debug_commons_set_trace_func @@trace_proc
+
+end
Added: trunk/org.rubypeople.rdt.launching/ruby/classic-debug.txt
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/classic-debug.txt (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/classic-debug.txt 2007-08-09 12:52:23 UTC (rev 2947)
@@ -0,0 +1,108 @@
+Here you will find information about Classic Debugger. [WORK IN PROGRESS]
+
+Q: How can I change the default port (1098) on which Classic Debugger is
+ listening?
+
+A: During its startup, classic-debug.rb, takes a look whether $RemoteDebugPort
+ global variable is defined. If yes the debugger will use the value of
+ $RemoteDebugPort variable, otherwise default port (1098) is used. So you may
+ start the debugger with requiring a script with "$RemoteDebugPort=46951" as
+ the only content. E.g.:
+
+ $ ruby -r classic-debug.rb test.rb # default port will be used
+ ruby 1.8.5 debugger listens on port 1098
+
+ $ cat my_port.rb
+ $RemoteDebugPort=12345
+ $ ruby -r my_port.rb -r classic-debug.rb test.rb # port 12345 will be used
+ ruby 1.8.5 debugger listens on port 12345
+
+
+========================================================================
+========================================================================
+
+Protocol Specification:
+-----------------------
+
+ <frame_no> ::= <int>
+ <id> ::= <int>
+ <line_no> ::= <int>
+ <path> ::= [path_to_script]
+ <status> ::= run|sleep
+
+========================================================================
+Adding breakpoint
+-----------------
+
+Command:
+
+ b <script>:<line_no>
+ b test.rb:2
+
+Answer:
+
+ <breakpointAdded no="<id>" location="<script>:<line_no>"/>
+ <breakpointAdded no="1" location="test.rb:2"/>
+
+========================================================================
+Breakpoint hit event
+--------------------
+
+ <breakpoint file="<script>" line="<line_no>" threadId="<id>"/>
+ <breakpoint file="test.rb" line="2" threadId="1"/>
+
+========================================================================
+Thread listing
+--------------
+
+Command:
+
+ th l
+
+Answer:
+
+ <threads>
+ <thread id="<id>" status="<status>"/>
+ <thread id="2" status="sleep"/>
+ </threads>
+
+========================================================================
+Frame listing
+-------------
+
+Command:
+
+ th 1; w
+
+Answer:
+
+ <frames>
+ <frame no="<frame_no>" file="<script>" line="<line_no>"/>
+ </frames>
+
+========================================================================
+Variables listing
+-----------------
+
+Command:
+
+ frame 1; v local
+
+Answer:
+
+ <variables>
+ <variable name="array" kind="local" value="Array (2 element(s))" type="Array" hasChildren="true" objectId="-0x2418a904"/>
+ </variables>
+
+Command:
+
+ v i array
+
+Answer:
+
+ <variables>
+ <variable name="[0]" kind="instance" value="1" type="Fixnum" hasChildren="false" objectId="+0x3"/>
+ <variable name="[1]" kind="instance" value="2" type="Fixnum" hasChildren="false" objectId="+0x5"/>
+ </variables>
+
+========================================================================
Property changes on: trunk/org.rubypeople.rdt.launching/ruby/classic-debug.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.launching/ruby/context.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/context.rb (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/context.rb 2007-08-09 12:52:23 UTC (rev 2947)
@@ -0,0 +1,625 @@
+class DC_DEBUGGER__
+
+ class Context
+
+ attr_reader :should_resume
+
+ def initialize
+ @printer = DC_DEBUGGER__.printer
+ @socket = DC_DEBUGGER__.socket
+ @stop_next = 0
+ @last_file = nil
+ @file = nil
+ @line = nil
+ @no_step = nil
+ @frames = []
+ @current_frame = -1
+ @finish_pos = 0
+ @trace = false
+ @catch = nil # "StandardError"
+ @suspend_next = false
+ @should_resume = false
+ end
+
+ def stop_next(n=1)
+ @stop_next = n
+ end
+
+ def set_suspend
+ @suspend_next = true
+ end
+
+ def clear_suspend
+ @suspend_next = false
+ end
+
+ def stop_current_thread
+ @printer.debug("Suspending : %s", Thread.current)
+ Thread.stop()
+ @printer.debug("Resumed : %s", Thread.current)
+ end
+
+ def trace?
+ @trace
+ end
+
+ def set_trace(arg)
+ @trace = arg
+ end
+
+ def stdout
+ if @socket then
+ @socket
+ else
+ DC_DEBUGGER__.stdout
+ end
+ end
+
+ def break_points
+ DC_DEBUGGER__.break_points
+ end
+
+ def display
+ DC_DEBUGGER__.display
+ end
+
+ def context(th)
+ DC_DEBUGGER__.context(th)
+ end
+
+ def set_trace_all(arg)
+ DC_DEBUGGER__.set_trace(arg)
+ end
+
+ def set_last_thread(th)
+ DC_DEBUGGER__.set_last_thread(th)
+ end
+
+ def debug_eval_private(str, binding)
+ # evaluates str like "var.@instance_var.@instance_var"
+ # and "var.private_method"
+ # return value might be nil
+ # the scan must detect array and hash accesses, which might
+ # themselves contain point separated expressions, e.g.
+ # array[Test.getX].y
+ names = str.scan(/[^\[\]]*(?=\.)|.*\[.*\](?=\.)|.*$/)
+ # names can contain empty strings
+ obj = eval(names[0], binding)
+ (1..names....
[truncated message content] |