2000-05-01 13:42:38 +04:00
|
|
|
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
2003-07-27 09:49:03 +04:00
|
|
|
# Copyright (C) 2000-2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
if $SAFE > 0
|
|
|
|
STDERR.print "-r debug.rb is not available in safe mode\n"
|
|
|
|
exit 1
|
|
|
|
end
|
1999-10-15 12:52:18 +04:00
|
|
|
|
2000-06-28 12:31:35 +04:00
|
|
|
require 'tracer'
|
2002-01-04 17:15:33 +03:00
|
|
|
require 'pp'
|
2000-10-14 18:44:58 +04:00
|
|
|
|
2000-06-28 12:31:35 +04:00
|
|
|
class Tracer
|
|
|
|
def Tracer.trace_func(*vars)
|
2000-08-07 09:05:04 +04:00
|
|
|
Single.trace_func(*vars)
|
2000-06-28 12:31:35 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-10-14 18:44:58 +04:00
|
|
|
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
2000-06-28 12:31:35 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
class DEBUGGER__
|
2002-02-25 18:30:31 +03:00
|
|
|
class Mutex
|
|
|
|
def initialize
|
|
|
|
@locker = nil
|
|
|
|
@waiting = []
|
|
|
|
@locked = false;
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def locked?
|
|
|
|
@locked
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def lock
|
2003-04-04 09:12:19 +04:00
|
|
|
return if Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
return if @locker == Thread.current
|
|
|
|
while (Thread.critical = true; @locked)
|
|
|
|
@waiting.push Thread.current
|
|
|
|
Thread.stop
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
@locked = true
|
|
|
|
@locker = Thread.current
|
|
|
|
Thread.critical = false
|
|
|
|
self
|
|
|
|
end
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def unlock
|
2003-04-04 09:12:19 +04:00
|
|
|
return if Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
return unless @locked
|
|
|
|
unless @locker == Thread.current
|
|
|
|
raise RuntimeError, "unlocked by other"
|
|
|
|
end
|
|
|
|
Thread.critical = true
|
|
|
|
t = @waiting.shift
|
|
|
|
@locked = false
|
|
|
|
@locker = nil
|
|
|
|
Thread.critical = false
|
|
|
|
t.run if t
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
MUTEX = Mutex.new
|
|
|
|
|
|
|
|
class Context
|
|
|
|
DEBUG_LAST_CMD = []
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'readline'
|
|
|
|
def readline(prompt, hist)
|
|
|
|
Readline::readline(prompt, hist)
|
|
|
|
end
|
|
|
|
rescue LoadError
|
|
|
|
def readline(prompt, hist)
|
|
|
|
STDOUT.print prompt
|
|
|
|
STDOUT.flush
|
|
|
|
line = STDIN.gets
|
|
|
|
exit unless line
|
|
|
|
line.chomp!
|
|
|
|
line
|
|
|
|
end
|
|
|
|
USE_READLINE = false
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def initialize
|
|
|
|
if Thread.current == Thread.main
|
|
|
|
@stop_next = 1
|
|
|
|
else
|
|
|
|
@stop_next = 0
|
|
|
|
end
|
|
|
|
@last_file = nil
|
|
|
|
@file = nil
|
|
|
|
@line = nil
|
|
|
|
@no_step = nil
|
|
|
|
@frames = []
|
|
|
|
@finish_pos = 0
|
|
|
|
@trace = false
|
|
|
|
@catch = "StandardError"
|
|
|
|
@suspend_next = false
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def stop_next(n=1)
|
|
|
|
@stop_next = n
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_suspend
|
|
|
|
@suspend_next = true
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def clear_suspend
|
|
|
|
@suspend_next = false
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def suspend_all
|
|
|
|
DEBUGGER__.suspend
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def resume_all
|
|
|
|
DEBUGGER__.resume
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_suspend
|
2003-04-04 09:12:19 +04:00
|
|
|
return if Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
while (Thread.critical = true; @suspend_next)
|
|
|
|
DEBUGGER__.waiting.push Thread.current
|
2000-12-27 08:59:03 +03:00
|
|
|
@suspend_next = false
|
2002-02-25 18:30:31 +03:00
|
|
|
Thread.stop
|
2000-12-27 08:59:03 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
Thread.critical = false
|
|
|
|
end
|
2000-12-27 08:59:03 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def trace?
|
|
|
|
@trace
|
|
|
|
end
|
2000-12-27 08:59:03 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_trace(arg)
|
|
|
|
@trace = arg
|
|
|
|
end
|
2000-12-27 08:59:03 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def stdout
|
|
|
|
DEBUGGER__.stdout
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def break_points
|
|
|
|
DEBUGGER__.break_points
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def display
|
|
|
|
DEBUGGER__.display
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def context(th)
|
|
|
|
DEBUGGER__.context(th)
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_trace_all(arg)
|
|
|
|
DEBUGGER__.set_trace(arg)
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_last_thread(th)
|
|
|
|
DEBUGGER__.set_last_thread(th)
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_eval(str, binding)
|
|
|
|
begin
|
|
|
|
val = eval(str, binding)
|
2003-03-03 08:17:39 +03:00
|
|
|
rescue StandardError, ScriptError => e
|
|
|
|
at = eval("caller(1)", binding)
|
|
|
|
stdout.printf "%s:%s\n", at.shift, e.to_s.sub(/\(eval\):1:(in `.*?':)?/, '')
|
2002-02-25 18:30:31 +03:00
|
|
|
for i in at
|
|
|
|
stdout.printf "\tfrom %s\n", i
|
|
|
|
end
|
|
|
|
throw :debug_error
|
2000-12-25 10:31:43 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_silent_eval(str, binding)
|
|
|
|
begin
|
2003-10-16 21:46:14 +04:00
|
|
|
eval(str, binding)
|
2002-02-25 18:30:31 +03:00
|
|
|
rescue StandardError, ScriptError
|
|
|
|
nil
|
2000-12-25 10:31:43 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def var_list(ary, binding)
|
|
|
|
ary.sort!
|
|
|
|
for v in ary
|
|
|
|
stdout.printf " %s => %s\n", v, eval(v, binding).inspect
|
2000-12-27 08:59:03 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-12-27 08:59:03 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_variable_info(input, binding)
|
|
|
|
case input
|
2004-07-23 11:52:38 +04:00
|
|
|
when /^\s*g(?:lobal)?\s*$/
|
2002-02-25 18:30:31 +03:00
|
|
|
var_list(global_variables, binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2004-07-23 11:52:38 +04:00
|
|
|
when /^\s*l(?:ocal)?\s*$/
|
2002-02-25 18:30:31 +03:00
|
|
|
var_list(eval("local_variables", binding), binding)
|
|
|
|
|
|
|
|
when /^\s*i(?:nstance)?\s+/
|
|
|
|
obj = debug_eval($', binding)
|
|
|
|
var_list(obj.instance_variables, obj.instance_eval{binding()})
|
2000-08-28 13:53:42 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*c(?:onst(?:ant)?)?\s+/
|
|
|
|
obj = debug_eval($', binding)
|
|
|
|
unless obj.kind_of? Module
|
|
|
|
stdout.print "Should be Class/Module: ", $', "\n"
|
|
|
|
else
|
|
|
|
var_list(obj.constants, obj.module_eval{binding()})
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_method_info(input, binding)
|
|
|
|
case input
|
|
|
|
when /^i(:?nstance)?\s+/
|
|
|
|
obj = debug_eval($', binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
len = 0
|
|
|
|
for v in obj.methods.sort
|
|
|
|
len += v.size + 1
|
|
|
|
if len > 70
|
|
|
|
len = v.size + 1
|
|
|
|
stdout.print "\n"
|
1999-08-13 09:45:20 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.print v, " "
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.print "\n"
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
obj = debug_eval(input, binding)
|
|
|
|
unless obj.kind_of? Module
|
|
|
|
stdout.print "Should be Class/Module: ", input, "\n"
|
|
|
|
else
|
2000-01-05 07:41:21 +03:00
|
|
|
len = 0
|
2003-05-22 20:37:22 +04:00
|
|
|
for v in obj.instance_methods(false).sort
|
2000-01-05 07:41:21 +03:00
|
|
|
len += v.size + 1
|
|
|
|
if len > 70
|
|
|
|
len = v.size + 1
|
|
|
|
stdout.print "\n"
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
stdout.print v, " "
|
|
|
|
end
|
|
|
|
stdout.print "\n"
|
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def thnum
|
|
|
|
num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
|
|
|
|
unless num
|
|
|
|
DEBUGGER__.make_thread_list
|
2000-01-05 07:41:21 +03:00
|
|
|
num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
|
|
|
num
|
|
|
|
end
|
|
|
|
|
|
|
|
def debug_command(file, line, id, binding)
|
|
|
|
MUTEX.lock
|
2005-07-10 07:47:56 +04:00
|
|
|
unless defined?($debugger_restart) and $debugger_restart
|
2005-05-24 19:24:23 +04:00
|
|
|
callcc{|c| $debugger_restart = c}
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
set_last_thread(Thread.current)
|
|
|
|
frame_pos = 0
|
|
|
|
binding_file = file
|
|
|
|
binding_line = line
|
|
|
|
previous_line = nil
|
2003-10-13 17:05:24 +04:00
|
|
|
if ENV['EMACS']
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.printf "\032\032%s:%d:\n", binding_file, binding_line
|
|
|
|
else
|
|
|
|
stdout.printf "%s:%d:%s", binding_file, binding_line,
|
|
|
|
line_at(binding_file, binding_line)
|
|
|
|
end
|
|
|
|
@frames[0] = [binding, file, line, id]
|
|
|
|
display_expressions(binding)
|
|
|
|
prompt = true
|
|
|
|
while prompt and input = readline("(rdb:%d) "%thnum(), true)
|
|
|
|
catch(:debug_error) do
|
|
|
|
if input == ""
|
2003-11-28 17:23:33 +03:00
|
|
|
next unless DEBUG_LAST_CMD[0]
|
2002-02-25 18:30:31 +03:00
|
|
|
input = DEBUG_LAST_CMD[0]
|
|
|
|
stdout.print input, "\n"
|
|
|
|
else
|
|
|
|
DEBUG_LAST_CMD[0] = input
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2003-07-27 09:49:03 +04:00
|
|
|
when /^\s*b(?:reak)?\s+(?:(.+):)?([^.:]+)$/
|
2002-03-29 14:52:09 +03:00
|
|
|
pos = $2
|
2003-10-16 21:46:14 +04:00
|
|
|
if $1
|
|
|
|
klass = debug_silent_eval($1, binding)
|
|
|
|
file = $1
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
if pos =~ /^\d+$/
|
|
|
|
pname = pos
|
|
|
|
pos = pos.to_i
|
2000-05-01 13:42:38 +04:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
pname = pos = pos.intern.id2name
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2003-07-27 09:49:03 +04:00
|
|
|
break_points.push [true, 0, klass || file, pos]
|
|
|
|
stdout.printf "Set breakpoint %d at %s:%s\n", break_points.size, klass || file, pname
|
|
|
|
|
|
|
|
when /^\s*b(?:reak)?\s+(.+)[#.]([^.:]+)$/
|
|
|
|
pos = $2.intern.id2name
|
|
|
|
klass = debug_eval($1, binding)
|
|
|
|
break_points.push [true, 0, klass, pos]
|
|
|
|
stdout.printf "Set breakpoint %d at %s.%s\n", break_points.size, klass, pos
|
2002-02-25 18:30:31 +03:00
|
|
|
|
|
|
|
when /^\s*wat(?:ch)?\s+(.+)$/
|
|
|
|
exp = $1
|
|
|
|
break_points.push [true, 1, exp]
|
2005-07-10 07:47:56 +04:00
|
|
|
stdout.printf "Set watchpoint %d:%s\n", break_points.size, exp
|
2002-02-25 18:30:31 +03:00
|
|
|
|
|
|
|
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]
|
2000-10-14 18:44:58 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
n += 1
|
2000-06-28 12:31:35 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
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]
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
n += 1
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
|
|
|
if break_points.size == 0
|
|
|
|
stdout.print "No breakpoints\n"
|
|
|
|
else
|
|
|
|
stdout.print "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
when /^\s*del(?:ete)?(?:\s+(\d+))?$/
|
|
|
|
pos = $1
|
|
|
|
unless pos
|
|
|
|
input = readline("Clear all breakpoints? (y/n) ", false)
|
|
|
|
if input == "y"
|
2000-05-01 13:42:38 +04:00
|
|
|
for b in break_points
|
2002-02-25 18:30:31 +03:00
|
|
|
b[0] = false
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
pos = pos.to_i
|
|
|
|
if break_points[pos-1]
|
|
|
|
break_points[pos-1][0] = false
|
2000-05-01 13:42:38 +04:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.printf "Breakpoint %d is not defined\n", pos
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*disp(?:lay)?\s+(.+)$/
|
|
|
|
exp = $1
|
|
|
|
display.push [true, exp]
|
|
|
|
stdout.printf "%d: ", display.size
|
|
|
|
display_expression(exp, binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
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
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
pos = pos.to_i
|
|
|
|
if display[pos-1]
|
|
|
|
display[pos-1][0] = false
|
2000-05-01 13:42:38 +04:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.printf "Display expression %d is not defined\n", pos
|
2000-05-01 13:42:38 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*c(?:ont)?$/
|
|
|
|
prompt = false
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*s(?:tep)?(?:\s+(\d+))?$/
|
|
|
|
if $1
|
|
|
|
lev = $1.to_i
|
|
|
|
else
|
|
|
|
lev = 1
|
|
|
|
end
|
|
|
|
@stop_next = lev
|
|
|
|
prompt = false
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
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
|
|
|
|
prompt = false
|
|
|
|
|
|
|
|
when /^\s*w(?:here)?$/, /^\s*f(?:rame)?$/
|
|
|
|
display_frames(frame_pos)
|
|
|
|
|
|
|
|
when /^\s*l(?:ist)?(?:\s+(.+))?$/
|
|
|
|
if not $1
|
|
|
|
b = previous_line ? previous_line + 10 : binding_line - 5
|
|
|
|
e = b + 9
|
|
|
|
elsif $1 == '-'
|
|
|
|
b = previous_line ? previous_line - 10 : binding_line - 5
|
|
|
|
e = b + 9
|
|
|
|
else
|
2003-03-29 09:39:50 +03:00
|
|
|
b, e = $1.split(/[-,]/)
|
2002-02-25 18:30:31 +03:00
|
|
|
if e
|
|
|
|
b = b.to_i
|
|
|
|
e = e.to_i
|
2000-05-01 13:42:38 +04:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
b = b.to_i - 5
|
|
|
|
e = b + 9
|
1999-08-13 09:45:20 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
|
|
|
previous_line = b
|
|
|
|
display_list(b, e, binding_file, binding_line)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*up(?:\s+(\d+))?$/
|
|
|
|
previous_line = nil
|
|
|
|
if $1
|
|
|
|
lev = $1.to_i
|
|
|
|
else
|
|
|
|
lev = 1
|
|
|
|
end
|
|
|
|
frame_pos += lev
|
|
|
|
if frame_pos >= @frames.size
|
|
|
|
frame_pos = @frames.size - 1
|
|
|
|
stdout.print "At toplevel\n"
|
|
|
|
end
|
|
|
|
binding, binding_file, binding_line = @frames[frame_pos]
|
|
|
|
stdout.print format_frame(frame_pos)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*down(?:\s+(\d+))?$/
|
|
|
|
previous_line = nil
|
|
|
|
if $1
|
|
|
|
lev = $1.to_i
|
|
|
|
else
|
|
|
|
lev = 1
|
|
|
|
end
|
|
|
|
frame_pos -= lev
|
|
|
|
if frame_pos < 0
|
|
|
|
frame_pos = 0
|
|
|
|
stdout.print "At stack bottom\n"
|
|
|
|
end
|
|
|
|
binding, binding_file, binding_line = @frames[frame_pos]
|
|
|
|
stdout.print format_frame(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
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*cat(?:ch)?(?:\s+(.+))?$/
|
|
|
|
if $1
|
|
|
|
excn = $1
|
|
|
|
if excn == 'off'
|
|
|
|
@catch = nil
|
|
|
|
stdout.print "Clear catchpoint.\n"
|
2000-01-05 07:41:21 +03:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
@catch = excn
|
|
|
|
stdout.printf "Set catchpoint %s.\n", @catch
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
if @catch
|
|
|
|
stdout.printf "Catchpoint %s.\n", @catch
|
2000-10-14 18:44:58 +04:00
|
|
|
else
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.print "No catchpoint.\n"
|
2000-10-14 18:44:58 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-10-14 18:44:58 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*q(?:uit)?$/
|
|
|
|
input = readline("Really quit? (y/n) ", false)
|
|
|
|
if input == "y"
|
|
|
|
exit! # exit -> exit!: No graceful way to stop threads...
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2004-01-07 06:42:00 +03:00
|
|
|
when /^\s*v(?:ar)?\s+/
|
2002-02-25 18:30:31 +03:00
|
|
|
debug_variable_info($', binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2004-01-07 06:42:00 +03:00
|
|
|
when /^\s*m(?:ethod)?\s+/
|
2002-02-25 18:30:31 +03:00
|
|
|
debug_method_info($', binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2004-01-07 06:42:00 +03:00
|
|
|
when /^\s*th(?:read)?\s+/
|
2002-02-25 18:30:31 +03:00
|
|
|
if DEBUGGER__.debug_thread_info($', binding) == :cont
|
|
|
|
prompt = false
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2004-01-07 06:42:00 +03:00
|
|
|
when /^\s*pp\s+/
|
2002-09-11 16:29:17 +04:00
|
|
|
PP.pp(debug_eval($', binding), stdout)
|
2002-01-04 17:15:33 +03:00
|
|
|
|
2004-01-07 06:42:00 +03:00
|
|
|
when /^\s*p\s+/
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.printf "%s\n", debug_eval($', binding).inspect
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2005-05-24 19:24:23 +04:00
|
|
|
when /^\s*r(?:estart)?$/
|
|
|
|
$debugger_restart.call
|
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^\s*h(?:elp)?$/
|
|
|
|
debug_print_help()
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
v = debug_eval(input, binding)
|
2003-08-11 17:41:18 +04:00
|
|
|
stdout.printf "%s\n", v.inspect
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
MUTEX.unlock
|
|
|
|
resume_all
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_print_help
|
|
|
|
stdout.print <<EOHELP
|
2000-05-01 13:42:38 +04:00
|
|
|
Debugger help v.-0.002b
|
|
|
|
Commands
|
2004-12-06 18:31:26 +03:00
|
|
|
b[reak] [file:|class:]<line|method>
|
2003-07-27 09:49:03 +04:00
|
|
|
b[reak] [class.]<line|method>
|
2000-10-20 20:37:01 +04:00
|
|
|
set breakpoint to some position
|
2000-05-01 13:42:38 +04:00
|
|
|
wat[ch] <expression> set watchpoint to some expression
|
2006-07-09 03:17:53 +04:00
|
|
|
cat[ch] (<exception>|off) set catchpoint to an exception
|
2000-05-01 13:42:38 +04:00
|
|
|
b[reak] list breakpoints
|
2000-10-14 18:44:58 +04:00
|
|
|
cat[ch] show catchpoint
|
2001-03-21 06:41:45 +03:00
|
|
|
del[ete][ nnn] delete some or all breakpoints
|
2000-05-01 13:42:38 +04:00
|
|
|
disp[lay] <expression> add expression into display expression list
|
|
|
|
undisp[lay][ nnn] delete one particular or all display expressions
|
|
|
|
c[ont] run until program ends or hit breakpoint
|
|
|
|
s[tep][ nnn] step (into methods) one line or till line nnn
|
|
|
|
n[ext][ nnn] go over one line or till line nnn
|
|
|
|
w[here] display frames
|
|
|
|
f[rame] alias for where
|
|
|
|
l[ist][ (-|nn-mm)] list program, - lists backwards
|
|
|
|
nn-mm lists given lines
|
|
|
|
up[ nn] move to higher frame
|
|
|
|
down[ nn] move to lower frame
|
|
|
|
fin[ish] return to outer frame
|
2000-12-25 10:31:43 +03:00
|
|
|
tr[ace] (on|off) set trace mode of current thread
|
|
|
|
tr[ace] (on|off) all set trace mode of all threads
|
2000-05-01 13:42:38 +04:00
|
|
|
q[uit] exit from debugger
|
|
|
|
v[ar] g[lobal] show global variables
|
|
|
|
v[ar] l[ocal] show local variables
|
|
|
|
v[ar] i[nstance] <object> show instance variables of object
|
|
|
|
v[ar] c[onst] <object> show constants of object
|
|
|
|
m[ethod] i[nstance] <obj> show methods of object
|
2000-08-15 10:22:49 +04:00
|
|
|
m[ethod] <class|module> show instance methods of class or module
|
2000-05-01 13:42:38 +04:00
|
|
|
th[read] l[ist] list all threads
|
2000-12-25 10:31:43 +03:00
|
|
|
th[read] c[ur[rent]] show current thread
|
|
|
|
th[read] [sw[itch]] <nnn> switch thread context to nnn
|
|
|
|
th[read] stop <nnn> stop thread nnn
|
|
|
|
th[read] resume <nnn> resume thread nnn
|
2000-05-01 13:42:38 +04:00
|
|
|
p expression evaluate expression and print its value
|
|
|
|
h[elp] print this help
|
|
|
|
<everything else> evaluate
|
|
|
|
EOHELP
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_expressions(binding)
|
|
|
|
n = 1
|
|
|
|
for d in display
|
|
|
|
if d[0]
|
|
|
|
stdout.printf "%d: ", n
|
|
|
|
display_expression(d[1], binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
n += 1
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def display_expression(exp, binding)
|
|
|
|
stdout.printf "%s = %s\n", exp, debug_silent_eval(exp, binding).to_s
|
|
|
|
end
|
2000-08-28 13:53:42 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def frame_set_pos(file, line)
|
|
|
|
if @frames[0]
|
|
|
|
@frames[0][1] = file
|
|
|
|
@frames[0][2] = line
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def display_frames(pos)
|
|
|
|
0.upto(@frames.size - 1) do |n|
|
|
|
|
if n == pos
|
|
|
|
stdout.print "--> "
|
|
|
|
else
|
|
|
|
stdout.print " "
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.print format_frame(n)
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def format_frame(pos)
|
|
|
|
bind, file, line, id = @frames[pos]
|
|
|
|
sprintf "#%d %s:%s%s\n", pos + 1, file, line,
|
|
|
|
(id ? ":in `#{id.id2name}'" : "")
|
|
|
|
end
|
2002-02-23 12:40:58 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def display_list(b, e, file, line)
|
|
|
|
stdout.printf "[%d, %d] in %s\n", b, e, file
|
|
|
|
if lines = SCRIPT_LINES__[file] and lines != true
|
|
|
|
n = 0
|
|
|
|
b.upto(e) do |n|
|
|
|
|
if n > 0 && lines[n-1]
|
|
|
|
if n == line
|
|
|
|
stdout.printf "=> %d %s\n", n, lines[n-1].chomp
|
|
|
|
else
|
|
|
|
stdout.printf " %d %s\n", n, lines[n-1].chomp
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
else
|
|
|
|
stdout.printf "No sourcefile available for %s\n", file
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def line_at(file, line)
|
|
|
|
lines = SCRIPT_LINES__[file]
|
|
|
|
if lines
|
|
|
|
return "\n" if lines == true
|
|
|
|
line = lines[line-1]
|
|
|
|
return "\n" unless line
|
|
|
|
return line
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
return "\n"
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_funcname(id)
|
|
|
|
if id.nil?
|
|
|
|
"toplevel"
|
|
|
|
else
|
|
|
|
id.id2name
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2003-07-27 09:49:03 +04:00
|
|
|
def check_break_points(file, klass, pos, binding, id)
|
2002-02-25 18:30:31 +03:00
|
|
|
return false if break_points.empty?
|
|
|
|
n = 1
|
|
|
|
for b in break_points
|
2003-07-27 09:49:03 +04:00
|
|
|
if b[0] # valid
|
|
|
|
if b[1] == 0 # breakpoint
|
|
|
|
if (b[2] == file and b[3] == pos) or
|
|
|
|
(klass and b[2] == klass and b[3] == pos)
|
|
|
|
stdout.printf "Breakpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
elsif b[1] == 1 # watchpoint
|
2002-02-25 18:30:31 +03:00
|
|
|
if debug_silent_eval(b[2], binding)
|
|
|
|
stdout.printf "Watchpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
|
2000-01-05 07:41:21 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
n += 1
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
return false
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def excn_handle(file, line, id, binding)
|
2002-10-02 20:45:35 +04:00
|
|
|
if $!.class <= SystemExit
|
2002-02-25 18:30:31 +03:00
|
|
|
set_trace_func nil
|
|
|
|
exit
|
|
|
|
end
|
2000-10-14 18:44:58 +04:00
|
|
|
|
2002-10-02 20:45:35 +04:00
|
|
|
if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch })
|
|
|
|
stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class
|
2002-02-25 18:30:31 +03:00
|
|
|
fs = @frames.size
|
|
|
|
tb = caller(0)[-fs..-1]
|
|
|
|
if tb
|
|
|
|
for i in tb
|
|
|
|
stdout.printf "\tfrom %s\n", i
|
2000-10-20 20:37:01 +04:00
|
|
|
end
|
2000-10-14 18:44:58 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
suspend_all
|
|
|
|
debug_command(file, line, id, binding)
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def trace_func(event, file, line, id, binding, klass)
|
|
|
|
Tracer.trace_func(event, file, line, id, binding, klass) if trace?
|
|
|
|
context(Thread.current).check_suspend
|
|
|
|
@file = file
|
|
|
|
@line = line
|
|
|
|
case event
|
|
|
|
when 'line'
|
|
|
|
frame_set_pos(file, line)
|
|
|
|
if !@no_step or @frames.size == @no_step
|
|
|
|
@stop_next -= 1
|
2003-07-24 22:33:50 +04:00
|
|
|
@stop_next = -1 if @stop_next < 0
|
2002-02-25 18:30:31 +03:00
|
|
|
elsif @frames.size < @no_step
|
|
|
|
@stop_next = 0 # break here before leaving...
|
|
|
|
else
|
|
|
|
# nothing to do. skipped.
|
|
|
|
end
|
2003-07-27 09:49:03 +04:00
|
|
|
if @stop_next == 0 or check_break_points(file, nil, line, binding, id)
|
2002-02-25 18:30:31 +03:00
|
|
|
@no_step = nil
|
|
|
|
suspend_all
|
|
|
|
debug_command(file, line, id, binding)
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'call'
|
|
|
|
@frames.unshift [binding, file, line, id]
|
2003-07-27 09:49:03 +04:00
|
|
|
if check_break_points(file, klass, id.id2name, binding, id)
|
2002-02-25 18:30:31 +03:00
|
|
|
suspend_all
|
|
|
|
debug_command(file, line, id, binding)
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'c-call'
|
|
|
|
frame_set_pos(file, line)
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'class'
|
|
|
|
@frames.unshift [binding, file, line, id]
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'return', 'end'
|
|
|
|
if @frames.size == @finish_pos
|
|
|
|
@stop_next = 1
|
|
|
|
@finish_pos = 0
|
|
|
|
end
|
|
|
|
@frames.shift
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'end'
|
|
|
|
@frames.shift
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when 'raise'
|
|
|
|
excn_handle(file, line, id, binding)
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
@last_file = file
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
trap("INT") { DEBUGGER__.interrupt }
|
|
|
|
@last_thread = Thread::main
|
|
|
|
@max_thread = 1
|
|
|
|
@thread_list = {Thread::main => 1}
|
|
|
|
@break_points = []
|
|
|
|
@display = []
|
|
|
|
@waiting = []
|
|
|
|
@stdout = STDOUT
|
|
|
|
|
|
|
|
class << DEBUGGER__
|
|
|
|
def stdout
|
|
|
|
@stdout
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def stdout=(s)
|
|
|
|
@stdout = s
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def display
|
|
|
|
@display
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def break_points
|
|
|
|
@break_points
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def waiting
|
|
|
|
@waiting
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_trace( arg )
|
2003-04-04 09:12:19 +04:00
|
|
|
saved_crit = Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
Thread.critical = true
|
|
|
|
make_thread_list
|
2003-05-30 20:08:03 +04:00
|
|
|
for th, in @thread_list
|
|
|
|
context(th).set_trace arg
|
2000-12-25 10:31:43 +03:00
|
|
|
end
|
2003-04-04 09:12:19 +04:00
|
|
|
Thread.critical = saved_crit
|
2002-02-25 18:30:31 +03:00
|
|
|
arg
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def set_last_thread(th)
|
|
|
|
@last_thread = th
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def suspend
|
2003-04-04 09:12:19 +04:00
|
|
|
saved_crit = Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
Thread.critical = true
|
|
|
|
make_thread_list
|
2003-05-30 20:08:03 +04:00
|
|
|
for th, in @thread_list
|
|
|
|
next if th == Thread.current
|
|
|
|
context(th).set_suspend
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2003-04-04 09:12:19 +04:00
|
|
|
Thread.critical = saved_crit
|
2002-02-25 18:30:31 +03:00
|
|
|
# Schedule other threads to suspend as soon as possible.
|
2003-04-04 09:12:19 +04:00
|
|
|
Thread.pass unless Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def resume
|
2003-04-04 09:12:19 +04:00
|
|
|
saved_crit = Thread.critical
|
2002-02-25 18:30:31 +03:00
|
|
|
Thread.critical = true
|
|
|
|
make_thread_list
|
2003-05-30 20:08:03 +04:00
|
|
|
for th, in @thread_list
|
|
|
|
next if th == Thread.current
|
|
|
|
context(th).clear_suspend
|
2000-12-25 10:31:43 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
waiting.each do |th|
|
|
|
|
th.run
|
2000-12-25 10:31:43 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
waiting.clear
|
2003-04-04 09:12:19 +04:00
|
|
|
Thread.critical = saved_crit
|
2002-02-25 18:30:31 +03:00
|
|
|
# Schedule other threads to restart as soon as possible.
|
|
|
|
Thread.pass
|
|
|
|
end
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def context(thread=Thread.current)
|
|
|
|
c = thread[:__debugger_data__]
|
|
|
|
unless c
|
|
|
|
thread[:__debugger_data__] = c = Context.new
|
1999-08-13 09:45:20 +04:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
c
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def interrupt
|
|
|
|
context(@last_thread).stop_next
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def get_thread(num)
|
|
|
|
th = @thread_list.index(num)
|
|
|
|
unless th
|
|
|
|
@stdout.print "No thread ##{num}\n"
|
|
|
|
throw :debug_error
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
th
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def thread_list(num)
|
|
|
|
th = get_thread(num)
|
|
|
|
if th == Thread.current
|
|
|
|
@stdout.print "+"
|
|
|
|
else
|
|
|
|
@stdout.print " "
|
|
|
|
end
|
|
|
|
@stdout.printf "%d ", num
|
|
|
|
@stdout.print th.inspect, "\t"
|
|
|
|
file = context(th).instance_eval{@file}
|
|
|
|
if file
|
|
|
|
@stdout.print file,":",context(th).instance_eval{@line}
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
@stdout.print "\n"
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def thread_list_all
|
|
|
|
for th in @thread_list.values.sort
|
|
|
|
thread_list(th)
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def make_thread_list
|
|
|
|
hash = {}
|
|
|
|
for th in Thread::list
|
|
|
|
if @thread_list.key? th
|
|
|
|
hash[th] = @thread_list[th]
|
|
|
|
else
|
|
|
|
@max_thread += 1
|
|
|
|
hash[th] = @max_thread
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
@thread_list = hash
|
|
|
|
end
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
def debug_thread_info(input, binding)
|
|
|
|
case input
|
|
|
|
when /^l(?:ist)?/
|
|
|
|
make_thread_list
|
|
|
|
thread_list_all
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
when /^c(?:ur(?:rent)?)?$/
|
|
|
|
make_thread_list
|
|
|
|
thread_list(@thread_list[Thread.current])
|
2000-12-25 10:31:43 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
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
|
|
|
|
thread_list(@thread_list[th])
|
|
|
|
context(th).stop_next
|
|
|
|
th.run
|
|
|
|
return :cont
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
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
|
|
|
|
thread_list(@thread_list[th])
|
|
|
|
context(th).suspend
|
|
|
|
end
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
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
|
|
|
|
thread_list(@thread_list[th])
|
|
|
|
th.run
|
2000-01-05 07:41:21 +03:00
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
2002-02-25 18:30:31 +03:00
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-25 18:30:31 +03:00
|
|
|
stdout.printf "Debug.rb\n"
|
|
|
|
stdout.printf "Emacs support available.\n\n"
|
|
|
|
set_trace_func proc { |event, file, line, id, binding, klass, *rest|
|
|
|
|
DEBUGGER__.context.trace_func event, file, line, id, binding, klass
|
|
|
|
}
|
1999-10-15 12:52:18 +04:00
|
|
|
end
|