summaryrefslogtreecommitdiff
path: root/lib/debug.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/debug.rb')
-rw-r--r--lib/debug.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/debug.rb b/lib/debug.rb
index bf53eb80a4..bf63ccf34d 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -3,7 +3,10 @@
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
# Copyright (C) 2000-2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-require 'continuation'
+if $SAFE > 0
+ STDERR.print "-r debug.rb is not available in safe mode\n"
+ exit 1
+end
require 'tracer'
require 'pp'
@@ -178,6 +181,9 @@ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__ # :nodoc:
class DEBUGGER__
MUTEX = Thread::Mutex.new # :nodoc:
+ CONTINUATIONS_SUPPORTED = RUBY_ENGINE == 'ruby'
+
+ require 'continuation' if CONTINUATIONS_SUPPORTED
class Context # :nodoc:
DEBUG_LAST_CMD = []
@@ -375,8 +381,10 @@ class DEBUGGER__
def debug_command(file, line, id, binding)
MUTEX.lock
- unless defined?($debugger_restart) and $debugger_restart
- callcc{|c| $debugger_restart = c}
+ if CONTINUATIONS_SUPPORTED
+ unless defined?($debugger_restart) and $debugger_restart
+ callcc{|c| $debugger_restart = c}
+ end
end
set_last_thread(Thread.current)
frame_pos = 0
@@ -648,7 +656,11 @@ class DEBUGGER__
stdout.printf "%s\n", debug_eval($', binding).inspect
when /^\s*r(?:estart)?$/
- $debugger_restart.call
+ if CONTINUATIONS_SUPPORTED
+ $debugger_restart.call
+ else
+ stdout.print "Restart requires continuations.\n"
+ end
when /^\s*h(?:elp)?$/
debug_print_help()
@@ -1097,9 +1109,11 @@ EOHELP
stdout.printf "Debug.rb\n"
stdout.printf "Emacs support available.\n\n"
- RubyVM::InstructionSequence.compile_option = {
- trace_instruction: true
- }
+ if defined?(RubyVM::InstructionSequence)
+ RubyVM::InstructionSequence.compile_option = {
+ trace_instruction: true
+ }
+ end
set_trace_func proc { |event, file, line, id, binding, klass, *rest|
DEBUGGER__.context.trace_func event, file, line, id, binding, klass
}