lib/debug/session.rb in debug-1.0.0.beta3 vs lib/debug/session.rb in debug-1.0.0.beta4
- old
+ new
@@ -1,20 +1,9 @@
-module DEBUGGER__
- # used in thread_client.c
- FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
- :has_return_value, :return_value, :show_line)
-end
-
-if File.exist? File.join(__dir__, 'debug.so')
- require_relative 'debug.so'
-else
- require "debug/debug"
-end
-
+
+require_relative 'thread_client'
require_relative 'source_repository'
require_relative 'breakpoint'
-require_relative 'thread_client'
require_relative 'config'
class RubyVM::InstructionSequence
def traceable_lines_norec lines
code = self.to_a[13]
@@ -59,11 +48,11 @@
@ui = ui
@sr = SourceRepository.new
@bps = {} # bp.key => bp
# [file, line] => LineBreakpoint
# "Error" => CatchBreakpoint
- # Method => MethodBreakpoint
+ # "Foo#bar" => MethodBreakpoint
# [:watch, expr] => WatchExprBreakpoint
# [:check, expr] => CheckBreakpoint
@th_clients = {} # {Thread => ThreadClient}
@q_evt = Queue.new
@displays = []
@@ -71,11 +60,12 @@
@tc_id = 0
@initial_commands = []
@tp_load_script = TracePoint.new(:script_compiled){|tp|
ThreadClient.current.on_load tp.instruction_sequence, tp.eval_script
- }.enable
+ }
+ @tp_load_script.enable
@session_server = Thread.new do
Thread.current.abort_on_exception = true
while evt = @q_evt.pop
@@ -147,22 +137,27 @@
setup_threads
@tp_thread_begin = TracePoint.new(:thread_begin){|tp|
ThreadClient.current.on_thread_begin Thread.current
- }.enable
+ }
+ @tp_thread_begin.enable
end
def add_initial_commands cmds
cmds.each{|c|
c.gsub('#.*', '').strip!
@initial_commands << c unless c.empty?
}
end
def source path
- @sr.get(path)
+ if CONFIG[:use_colorize]
+ @sr.get_colored(path)
+ else
+ @sr.get(path)
+ end
end
def inspect
"DEBUGGER__::SESSION"
end
@@ -407,21 +402,27 @@
return :retry
end
@tc << [:show, :edit, arg]
- # * `i[nfo]`
+ # * `i[nfo]`, `i[nfo] l[ocal[s]]`
# * Show information about the current frame (local variables)
# * It includes `self` as `%self` and a return value as `%return`.
- # * `i[nfo] <expr>`
- # * Show information about the result of <expr>.
+ # * `i[nfo] th[read[s]]
+ # * Show all threads (same as `th[read]`).
when 'i', 'info'
case arg
when nil
@tc << [:show, :local]
+ when 'l', /locals?/
+ @tc << [:show, :local]
+ when 'th', /threads?/
+ thread_list
+ return :retry
else
- @tc << [:show, :object_info, arg]
+ show_help 'info'
+ return :retry
end
# * `display`
# * Show display setting.
# * `display <expr>`
@@ -853,11 +854,11 @@
@bps.has_key? [file, line]
end
def add_catch_breakpoint arg
bp = CatchBreakpoint.new(arg)
- add_braekpoint bp
+ add_breakpoint bp
end
def add_check_breakpoint expr
bp = CheckBreakpoint.new(expr)
add_breakpoint bp
@@ -895,30 +896,41 @@
def method_added tp
b = tp.binding
if var_name = b.local_variables.first
mid = b.local_variable_get(var_name)
- found = false
+ unresolved = false
@bps.each{|k, bp|
case bp
when MethodBreakpoint
if bp.method.nil?
- found = true
if bp.sig_method_name == mid.to_s
- bp.enable(quiet: true)
+ bp.try_enable(quiet: true)
end
end
+
+ unresolved = true unless bp.enabled?
end
}
- unless found
+ unless unresolved
METHOD_ADDED_TRACKER.disable
end
end
end
end
+ # manual configuration methods
+
+ def self.add_line_breakpoint file, line, **kw
+ ::DEBUGGER__::SESSION.add_line_breakpoint file, line, **kw
+ end
+
+ def self.add_catch_breakpoint pat
+ ::DEBUGGER__::SESSION.add_catch_breakpoint pat
+ end
+
# String for requring location
# nil for -r
def self.require_location
locs = caller_locations
dir_prefix = /#{__dir__}/
@@ -932,26 +944,47 @@
end
end
nil
end
- def self.console
+ # start methods
+
+ def self.console **kw
+ set_config(kw)
+
+ require_relative 'console'
initialize_session UI_Console.new
@prev_handler = trap(:SIGINT){
ThreadClient.current.on_trap :SIGINT
}
end
- def self.add_line_breakpoint file, line, **kw
- ::DEBUGGER__::SESSION.add_line_breakpoint file, line, **kw
+ def self.open host: nil, port: ::DEBUGGER__::CONFIG[:port], sock_path: nil, sock_dir: nil, **kw
+ set_config(kw)
+
+ if port
+ open_tcp host: host, port: port
+ else
+ open_unix sock_path: sock_path, sock_dir: sock_dir
+ end
end
- def self.add_catch_breakpoint pat
- ::DEBUGGER__::SESSION.add_catch_breakpoint pat
+ def self.open_tcp host: nil, port:, **kw
+ set_config(kw)
+ require_relative 'server'
+ initialize_session UI_TcpServer.new(host: host, port: port)
end
+ def self.open_unix sock_path: nil, sock_dir: nil, **kw
+ set_config(kw)
+ require_relative 'server'
+ initialize_session UI_UnixDomainServer.new(sock_dir: sock_dir, sock_path: sock_path)
+ end
+
+ # boot utilities
+
class << self
define_method :initialize_session do |ui|
::DEBUGGER__.const_set(:SESSION, Session.new(ui))
# default breakpoints
@@ -961,11 +994,11 @@
Binding.module_eval do
::DEBUGGER__.add_line_breakpoint __FILE__, __LINE__ + 1
def bp; nil; end
end
- if ::DEBUGGER__::CONFIG[:nonstop] != '1'
+ if !::DEBUGGER__::CONFIG[:nonstop]
if loc = ::DEBUGGER__.require_location
# require 'debug/console' or 'debug'
add_line_breakpoint loc.absolute_path, loc.lineno + 1, oneshot: true, hook_call: false
else
# -r
@@ -1049,11 +1082,9 @@
}
r << ''
}
r.join("\n")
end
-
- CONFIG = ::DEBUGGER__.parse_argv(ENV['RUBY_DEBUG_OPT'])
class ::Module
def method_added mid; end
def singleton_method_added mid; end
end