Permalink
Browse files

re-incorporated ruby-debug-cli files

  • Loading branch information...
1 parent 4e588a9 commit a4f236c8082e8f6b6be2fbc2b6d828ad3da1c24b @mark-moseley committed Oct 2, 2009
Showing with 4,725 additions and 18 deletions.
  1. +17 −15 Rakefile
  2. +173 −0 cli/ruby-debug.rb
  3. +228 −0 cli/ruby-debug/command.rb
  4. +153 −0 cli/ruby-debug/commands/breakpoints.rb
  5. +55 −0 cli/ruby-debug/commands/catchpoint.rb
  6. +49 −0 cli/ruby-debug/commands/condition.rb
  7. +38 −0 cli/ruby-debug/commands/continue.rb
  8. +107 −0 cli/ruby-debug/commands/control.rb
  9. +120 −0 cli/ruby-debug/commands/display.rb
  10. +48 −0 cli/ruby-debug/commands/edit.rb
  11. +202 −0 cli/ruby-debug/commands/enable.rb
  12. +176 −0 cli/ruby-debug/commands/eval.rb
  13. +42 −0 cli/ruby-debug/commands/finish.rb
  14. +301 −0 cli/ruby-debug/commands/frame.rb
  15. +56 −0 cli/ruby-debug/commands/help.rb
  16. +469 −0 cli/ruby-debug/commands/info.rb
  17. +123 −0 cli/ruby-debug/commands/irb.rb
  18. +66 −0 cli/ruby-debug/commands/jump.rb
  19. +51 −0 cli/ruby-debug/commands/kill.rb
  20. +94 −0 cli/ruby-debug/commands/list.rb
  21. +84 −0 cli/ruby-debug/commands/method.rb
  22. +39 −0 cli/ruby-debug/commands/quit.rb
  23. +40 −0 cli/ruby-debug/commands/reload.rb
  24. +90 −0 cli/ruby-debug/commands/save.rb
  25. +237 −0 cli/ruby-debug/commands/set.rb
  26. +253 −0 cli/ruby-debug/commands/show.rb
  27. +35 −0 cli/ruby-debug/commands/skip.rb
  28. +36 −0 cli/ruby-debug/commands/source.rb
  29. +81 −0 cli/ruby-debug/commands/stepping.rb
  30. +189 −0 cli/ruby-debug/commands/threads.rb
  31. +36 −0 cli/ruby-debug/commands/tmate.rb
  32. +57 −0 cli/ruby-debug/commands/trace.rb
  33. +199 −0 cli/ruby-debug/commands/variables.rb
  34. +5 −0 cli/ruby-debug/debugger.rb
  35. +69 −0 cli/ruby-debug/helper.rb
  36. +232 −0 cli/ruby-debug/interface.rb
  37. +474 −0 cli/ruby-debug/processor.rb
  38. +1 −1 ruby-debug.gemspec
  39. +0 −2 test/base/base.rb
View
@@ -101,9 +101,9 @@ end
# Base GEM Specification
base_spec = Gem::Specification.new do |spec|
- spec.name = "ruby-debug-base"
+ spec.name = "ruby-debug-base19"
- spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
+ spec.homepage = "http://rubyforge.org/projects/ruby-debug19/"
spec.summary = "Fast Ruby debugger - core component"
spec.description = <<-EOF
ruby-debug is a fast implementation of the standard Ruby debugger debug.rb.
@@ -112,19 +112,20 @@ provides support that front-ends can build on. It provides breakpoint
handling, bindings for stack frames among other things.
EOF
- spec.version = RUBY_DEBUG_VERSION
+ spec.version = "0.12.0"
- spec.author = "Kent Sibilev"
- spec.email = "ksibilev@yahoo.com"
+ spec.authors = ["Kent Sibilev", "Mark Moseley"]
+ spec.email = "mark@fast-software.com"
spec.platform = Gem::Platform::RUBY
spec.require_path = "lib"
- spec.extensions = ["ext/extconf.rb"]
+ spec.extensions = ["ext/ruby_debug/extconf.rb"]
spec.files = BASE_FILES.to_a
spec.required_ruby_version = '>= 1.8.2'
spec.date = Time.now
- spec.rubyforge_project = 'ruby-debug'
- spec.add_dependency('linecache', '>= 0.3')
+ spec.rubyforge_project = 'ruby-debug19'
+ spec.add_dependency('ruby_core_source', '>= 0.1.4')
+ spec.add_dependency('linecache19', '>= 0.5.11')
spec.test_files = FileList[BASE_TEST_FILE_LIST]
@@ -134,18 +135,18 @@ EOF
end
cli_spec = Gem::Specification.new do |spec|
- spec.name = "ruby-debug"
+ spec.name = "ruby-debug19"
- spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
+ spec.homepage = "http://rubyforge.org/projects/ruby-debug19/"
spec.summary = "Command line interface (CLI) for ruby-debug-base"
spec.description = <<-EOF
A generic command line interface for ruby-debug.
EOF
- spec.version = RUBY_DEBUG_VERSION
+ spec.version = "0.11.7"
- spec.author = "Kent Sibilev"
- spec.email = "ksibilev@yahoo.com"
+ spec.authors = ["Kent Sibilev", "Mark Moseley"]
+ spec.email = "mark@fast-software.com"
spec.platform = Gem::Platform::RUBY
spec.require_path = "cli"
spec.bindir = "bin"
@@ -155,8 +156,9 @@ EOF
spec.required_ruby_version = '>= 1.8.2'
spec.date = Time.now
spec.rubyforge_project = 'ruby-debug'
- spec.add_dependency('columnize', '>= 0.1')
- spec.add_dependency('ruby-debug-base', "~> #{RUBY_DEBUG_VERSION}.0")
+ spec.add_dependency('columnize', '>= 0.3.1')
+ spec.add_dependency('linecache19', '>= 0.5.11')
+ spec.add_dependency('ruby-debug-base19', '>= 0.12.0')
# FIXME: work out operational logistics for this
# spec.test_files = FileList[CLI_TEST_FILE_LIST]
View
@@ -0,0 +1,173 @@
+require 'pp'
+require 'stringio'
+require 'socket'
+require 'thread'
+require 'ruby-debug-base'
+require_relative 'ruby-debug/processor'
+
+module Debugger
+ self.handler = CommandProcessor.new
+
+ # the port number used for remote debugging
+ PORT = 8989 unless defined?(PORT)
+
+ # What file is used for debugger startup commands.
+ unless defined?(INITFILE)
+ if RUBY_PLATFORM =~ /mswin/
+ # Of course MS Windows has to be different
+ INITFILE = 'rdebug.ini'
+ HOME_DIR = (ENV['HOME'] ||
+ ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
+ else
+ INITFILE = '.rdebugrc'
+ HOME_DIR = ENV['HOME'].to_s
+ end
+ end
+
+ class << self
+ # gdb-style annotation mode. Used in GNU Emacs interface
+ attr_accessor :annotate
+
+ # in remote mode, wait for the remote connection
+ attr_accessor :wait_connection
+
+ # If set, a string to look for in caller() and is used to see
+ # if the call stack is truncated.
+ attr_accessor :start_sentinal
+
+ attr_reader :thread, :control_thread
+
+ def interface=(value) # :nodoc:
+ handler.interface = value
+ end
+
+ #
+ # Starts a remote debugger.
+ #
+ def start_remote(host = nil, port = PORT)
+ return if @thread
+
+ self.interface = nil
+ start
+
+ if port.kind_of?(Array)
+ cmd_port, ctrl_port = port
+ else
+ cmd_port, ctrl_port = port, port + 1
+ end
+
+ start_control(host, ctrl_port)
+
+ yield if block_given?
+
+ mutex = Mutex.new
+ proceed = ConditionVariable.new
+
+ @thread = DebugThread.new do
+ server = TCPServer.new(host, cmd_port)
+ while (session = server.accept)
+ self.interface = RemoteInterface.new(session)
+ if wait_connection
+ mutex.synchronize do
+ proceed.signal
+ end
+ end
+ end
+ end
+ if wait_connection
+ mutex.synchronize do
+ proceed.wait(mutex)
+ end
+ end
+ end
+ alias start_server start_remote
+
+ def start_control(host = nil, ctrl_port = PORT + 1) # :nodoc:
+ return if defined?(@control_thread) && @control_thread
+ @control_thread = DebugThread.new do
+ server = TCPServer.new(host, ctrl_port)
+ while (session = server.accept)
+ interface = RemoteInterface.new(session)
+ processor = ControlCommandProcessor.new(interface)
+ processor.process_commands
+ end
+ end
+ end
+
+ #
+ # Connects to the remote debugger
+ #
+ def start_client(host = 'localhost', port = PORT)
+ require "socket"
+ interface = Debugger::LocalInterface.new
+ socket = TCPSocket.new(host, port)
+ puts "Connected."
+
+ catch(:exit) do
+ while (line = socket.gets)
+ case line
+ when /^PROMPT (.*)$/
+ input = interface.read_command($1)
+ throw :exit unless input
+ socket.puts input
+ when /^CONFIRM (.*)$/
+ input = interface.confirm($1)
+ throw :exit unless input
+ socket.puts input
+ else
+ print line
+ end
+ end
+ end
+ socket.close
+ end
+
+ # Runs normal debugger initialization scripts
+ # Reads and executes the commands from init file (if any) in the
+ # current working directory. This is only done if the current
+ # directory is different from your home directory. Thus, you can
+ # have more than one init file, one generic in your home directory,
+ # and another, specific to the program you are debugging, in the
+ # directory where you invoke ruby-debug.
+ def run_init_script(out = handler.interface)
+ cwd_script_file = File.expand_path(File.join(".", INITFILE))
+ run_script(cwd_script_file, out) if File.exists?(cwd_script_file)
+
+ home_script_file = File.expand_path(File.join(HOME_DIR, INITFILE))
+ run_script(home_script_file, out) if File.exists?(home_script_file) and
+ cwd_script_file != home_script_file
+ end
+
+ #
+ # Runs a script file
+ #
+ def run_script(file, out = handler.interface, verbose=false)
+ interface = ScriptInterface.new(File.expand_path(file), out)
+ processor = ControlCommandProcessor.new(interface)
+ processor.process_commands(verbose)
+ end
+ end
+end
+
+module Kernel
+
+ # Enters the debugger in the current thread after _steps_ line events occur.
+ # Before entering the debugger startup script is read.
+ #
+ # Setting _steps_ to 0 will cause a break in the debugger subroutine
+ # and not wait for a line event to occur. You will have to go "up 1"
+ # in order to be back in your debugged program rather than the
+ # debugger. Settings _steps_ to 0 could be useful you want to stop
+ # right after the last statement in some scope, because the next
+ # step will take you out of some scope.
+ def debugger(steps = 1)
+ Debugger.start
+ Debugger.run_init_script(StringIO.new)
+ if 0 == steps
+ Debugger.current_context.stop_frame = 0
+ else
+ Debugger.current_context.stop_next = steps
+ end
+ end
+ alias breakpoint debugger unless respond_to?(:breakpoint)
+end
Oops, something went wrong.

0 comments on commit a4f236c

Please sign in to comment.