Skip to content

Commit a4f236c

Browse files
author
Mark Moseley
committed
re-incorporated ruby-debug-cli files
1 parent 4e588a9 commit a4f236c

39 files changed

+4725
-18
lines changed

Rakefile

+17-15
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ end
101101

102102
# Base GEM Specification
103103
base_spec = Gem::Specification.new do |spec|
104-
spec.name = "ruby-debug-base"
104+
spec.name = "ruby-debug-base19"
105105

106-
spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
106+
spec.homepage = "http://rubyforge.org/projects/ruby-debug19/"
107107
spec.summary = "Fast Ruby debugger - core component"
108108
spec.description = <<-EOF
109109
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
112112
handling, bindings for stack frames among other things.
113113
EOF
114114

115-
spec.version = RUBY_DEBUG_VERSION
115+
spec.version = "0.12.0"
116116

117-
spec.author = "Kent Sibilev"
118-
spec.email = "ksibilev@yahoo.com"
117+
spec.authors = ["Kent Sibilev", "Mark Moseley"]
118+
spec.email = "mark@fast-software.com"
119119
spec.platform = Gem::Platform::RUBY
120120
spec.require_path = "lib"
121-
spec.extensions = ["ext/extconf.rb"]
121+
spec.extensions = ["ext/ruby_debug/extconf.rb"]
122122
spec.files = BASE_FILES.to_a
123123

124124
spec.required_ruby_version = '>= 1.8.2'
125125
spec.date = Time.now
126-
spec.rubyforge_project = 'ruby-debug'
127-
spec.add_dependency('linecache', '>= 0.3')
126+
spec.rubyforge_project = 'ruby-debug19'
127+
spec.add_dependency('ruby_core_source', '>= 0.1.4')
128+
spec.add_dependency('linecache19', '>= 0.5.11')
128129

129130
spec.test_files = FileList[BASE_TEST_FILE_LIST]
130131

@@ -134,18 +135,18 @@ EOF
134135
end
135136

136137
cli_spec = Gem::Specification.new do |spec|
137-
spec.name = "ruby-debug"
138+
spec.name = "ruby-debug19"
138139

139-
spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
140+
spec.homepage = "http://rubyforge.org/projects/ruby-debug19/"
140141
spec.summary = "Command line interface (CLI) for ruby-debug-base"
141142
spec.description = <<-EOF
142143
A generic command line interface for ruby-debug.
143144
EOF
144145

145-
spec.version = RUBY_DEBUG_VERSION
146+
spec.version = "0.11.7"
146147

147-
spec.author = "Kent Sibilev"
148-
spec.email = "ksibilev@yahoo.com"
148+
spec.authors = ["Kent Sibilev", "Mark Moseley"]
149+
spec.email = "mark@fast-software.com"
149150
spec.platform = Gem::Platform::RUBY
150151
spec.require_path = "cli"
151152
spec.bindir = "bin"
@@ -155,8 +156,9 @@ EOF
155156
spec.required_ruby_version = '>= 1.8.2'
156157
spec.date = Time.now
157158
spec.rubyforge_project = 'ruby-debug'
158-
spec.add_dependency('columnize', '>= 0.1')
159-
spec.add_dependency('ruby-debug-base', "~> #{RUBY_DEBUG_VERSION}.0")
159+
spec.add_dependency('columnize', '>= 0.3.1')
160+
spec.add_dependency('linecache19', '>= 0.5.11')
161+
spec.add_dependency('ruby-debug-base19', '>= 0.12.0')
160162

161163
# FIXME: work out operational logistics for this
162164
# spec.test_files = FileList[CLI_TEST_FILE_LIST]

cli/ruby-debug.rb

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
require 'pp'
2+
require 'stringio'
3+
require 'socket'
4+
require 'thread'
5+
require 'ruby-debug-base'
6+
require_relative 'ruby-debug/processor'
7+
8+
module Debugger
9+
self.handler = CommandProcessor.new
10+
11+
# the port number used for remote debugging
12+
PORT = 8989 unless defined?(PORT)
13+
14+
# What file is used for debugger startup commands.
15+
unless defined?(INITFILE)
16+
if RUBY_PLATFORM =~ /mswin/
17+
# Of course MS Windows has to be different
18+
INITFILE = 'rdebug.ini'
19+
HOME_DIR = (ENV['HOME'] ||
20+
ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
21+
else
22+
INITFILE = '.rdebugrc'
23+
HOME_DIR = ENV['HOME'].to_s
24+
end
25+
end
26+
27+
class << self
28+
# gdb-style annotation mode. Used in GNU Emacs interface
29+
attr_accessor :annotate
30+
31+
# in remote mode, wait for the remote connection
32+
attr_accessor :wait_connection
33+
34+
# If set, a string to look for in caller() and is used to see
35+
# if the call stack is truncated.
36+
attr_accessor :start_sentinal
37+
38+
attr_reader :thread, :control_thread
39+
40+
def interface=(value) # :nodoc:
41+
handler.interface = value
42+
end
43+
44+
#
45+
# Starts a remote debugger.
46+
#
47+
def start_remote(host = nil, port = PORT)
48+
return if @thread
49+
50+
self.interface = nil
51+
start
52+
53+
if port.kind_of?(Array)
54+
cmd_port, ctrl_port = port
55+
else
56+
cmd_port, ctrl_port = port, port + 1
57+
end
58+
59+
start_control(host, ctrl_port)
60+
61+
yield if block_given?
62+
63+
mutex = Mutex.new
64+
proceed = ConditionVariable.new
65+
66+
@thread = DebugThread.new do
67+
server = TCPServer.new(host, cmd_port)
68+
while (session = server.accept)
69+
self.interface = RemoteInterface.new(session)
70+
if wait_connection
71+
mutex.synchronize do
72+
proceed.signal
73+
end
74+
end
75+
end
76+
end
77+
if wait_connection
78+
mutex.synchronize do
79+
proceed.wait(mutex)
80+
end
81+
end
82+
end
83+
alias start_server start_remote
84+
85+
def start_control(host = nil, ctrl_port = PORT + 1) # :nodoc:
86+
return if defined?(@control_thread) && @control_thread
87+
@control_thread = DebugThread.new do
88+
server = TCPServer.new(host, ctrl_port)
89+
while (session = server.accept)
90+
interface = RemoteInterface.new(session)
91+
processor = ControlCommandProcessor.new(interface)
92+
processor.process_commands
93+
end
94+
end
95+
end
96+
97+
#
98+
# Connects to the remote debugger
99+
#
100+
def start_client(host = 'localhost', port = PORT)
101+
require "socket"
102+
interface = Debugger::LocalInterface.new
103+
socket = TCPSocket.new(host, port)
104+
puts "Connected."
105+
106+
catch(:exit) do
107+
while (line = socket.gets)
108+
case line
109+
when /^PROMPT (.*)$/
110+
input = interface.read_command($1)
111+
throw :exit unless input
112+
socket.puts input
113+
when /^CONFIRM (.*)$/
114+
input = interface.confirm($1)
115+
throw :exit unless input
116+
socket.puts input
117+
else
118+
print line
119+
end
120+
end
121+
end
122+
socket.close
123+
end
124+
125+
# Runs normal debugger initialization scripts
126+
# Reads and executes the commands from init file (if any) in the
127+
# current working directory. This is only done if the current
128+
# directory is different from your home directory. Thus, you can
129+
# have more than one init file, one generic in your home directory,
130+
# and another, specific to the program you are debugging, in the
131+
# directory where you invoke ruby-debug.
132+
def run_init_script(out = handler.interface)
133+
cwd_script_file = File.expand_path(File.join(".", INITFILE))
134+
run_script(cwd_script_file, out) if File.exists?(cwd_script_file)
135+
136+
home_script_file = File.expand_path(File.join(HOME_DIR, INITFILE))
137+
run_script(home_script_file, out) if File.exists?(home_script_file) and
138+
cwd_script_file != home_script_file
139+
end
140+
141+
#
142+
# Runs a script file
143+
#
144+
def run_script(file, out = handler.interface, verbose=false)
145+
interface = ScriptInterface.new(File.expand_path(file), out)
146+
processor = ControlCommandProcessor.new(interface)
147+
processor.process_commands(verbose)
148+
end
149+
end
150+
end
151+
152+
module Kernel
153+
154+
# Enters the debugger in the current thread after _steps_ line events occur.
155+
# Before entering the debugger startup script is read.
156+
#
157+
# Setting _steps_ to 0 will cause a break in the debugger subroutine
158+
# and not wait for a line event to occur. You will have to go "up 1"
159+
# in order to be back in your debugged program rather than the
160+
# debugger. Settings _steps_ to 0 could be useful you want to stop
161+
# right after the last statement in some scope, because the next
162+
# step will take you out of some scope.
163+
def debugger(steps = 1)
164+
Debugger.start
165+
Debugger.run_init_script(StringIO.new)
166+
if 0 == steps
167+
Debugger.current_context.stop_frame = 0
168+
else
169+
Debugger.current_context.stop_next = steps
170+
end
171+
end
172+
alias breakpoint debugger unless respond_to?(:breakpoint)
173+
end

0 commit comments

Comments
 (0)