Skip to content

Commit

Permalink
Partial sync with rbx-trepanning:
Browse files Browse the repository at this point in the history
  interface/base_intf.rb -> interface.rb
  base_io -> io.rb
  processor/main.rb -> processor.b
  • Loading branch information
rocky committed Aug 28, 2011
1 parent 5ed1f7b commit 111fed3
Show file tree
Hide file tree
Showing 24 changed files with 321 additions and 331 deletions.
2 changes: 1 addition & 1 deletion interface/base_intf.rb → interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Trepan
# - another interface in another process or computer
class Interface

attr_accessor :interactive, :history_io, :history_save, :input, :output
attr_accessor :history_io, :history_save, :interactive, :input, :output

unless defined?(YES)
YES = %w(y yes oui si yep ja)
Expand Down
2 changes: 1 addition & 1 deletion interface/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Our local modules
require 'rubygems'; require 'require_relative'
require_relative 'base_intf'
require_relative '../interface'
require_relative '../io/input'
require_relative '../io/string_array'

Expand Down
2 changes: 1 addition & 1 deletion interface/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Our local modules
require 'rubygems'; require 'require_relative'
require_relative 'base_intf'
require_relative '../interface'
require_relative 'comcodes'
require_relative '../io/input'
require_relative '../io/tcpserver'
Expand Down
4 changes: 3 additions & 1 deletion interface/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Our local modules

require 'rubygems'; require 'require_relative'
require_relative 'base_intf'
require_relative '../interface'
require_relative '../io/input'

# Interface when communicating with the user.
Expand Down Expand Up @@ -162,4 +162,6 @@ def readline(prompt='')
end
end
puts "User interface closed?: #{intf.closed?}"
intf.close
STDERR.puts "User interface closed?: #{intf.closed?}"
end
File renamed without changes.
2 changes: 1 addition & 1 deletion io/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

require 'rubygems'; require 'require_relative'
require_relative 'base_io'
require_relative '../io'

module Trepan

Expand Down
2 changes: 1 addition & 1 deletion io/null_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

require 'rubygems'; require 'require_relative'
require_relative 'base_io'
require_relative '../io'

class Trepan::OutputNull < Trepan::OutputBase
def initialize(out, opts={})
Expand Down
4 changes: 2 additions & 2 deletions io/string_array.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>

# Simulate I/O using lists of strings.

require 'rubygems'; require 'require_relative'
require_relative 'base_io'
require_relative '../io'

# Simulate I/O using an array of strings. Sort of like StringIO, but
# even simplier.
Expand Down
2 changes: 1 addition & 1 deletion io/tcpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require 'socket'
require 'rubygems'; require 'require_relative'
require_relative 'base_io'
require_relative '../io'
require_relative 'tcpfns'

module Trepan
Expand Down
2 changes: 1 addition & 1 deletion io/tcpserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'socket'
require 'rubygems'; require 'require_relative'
require_relative '../app/default' # For host and port
require_relative 'base_io'
require_relative '../io'
require_relative 'tcpfns'

module Trepan
Expand Down
3 changes: 2 additions & 1 deletion lib/trepanning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
require 'require_relative'
require_relative '../interface/script'
require_relative '../interface/user'
require_relative '../processor/processor'
require_relative '../processor/old-processor'
require_relative '../processor'

module Trepan

Expand Down
38 changes: 3 additions & 35 deletions processor/main.rb → processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%w(default display eval eventbuf frame hook load_cmds location msg running
validate).each do
|mod_str|
require_relative mod_str
require_relative File.join('processor', mod_str);
end
## require_relative '../app/brkptmgr'

Expand Down Expand Up @@ -64,34 +64,6 @@ class CmdProcessor < VirtualCmdProcessor
# [location, container, stack_size,
# current_thread, pc_offset]

unless defined?(EVENT2ICON)
# Event icons used in printing locations.
EVENT2ICON = {
'brkpt' => 'xx',
'tbrkpt' => 'x1',
'c-call' => 'C>',
'c-return' => '<C',
'step-call' => '->',
'call' => '->',
'class' => '::',
'coverage' => '[]',
'debugger-call' => ':o',
'end' => '-|',
'line' => '--',
'raise' => '!!',
'return' => '<-',
'start' => '>>',
'switch' => 'sw',
'trace-var' => '$V',
'unknown' => '?!',
'vm' => 'VM',
'vm-insn' => '..',
}
# These events are important enough event that we always want to
# stop on them.
UNMASKABLE_EVENTS = Set.new(['end', 'raise', 'unknown'])
end

## def initialize(dbgr, settings={})
def initialize(interfaces, settings={})
@cmd_queue = []
Expand Down Expand Up @@ -201,11 +173,7 @@ def process_command_and_quit?()
@cmd_queue.shift
end
if @current_command.empty?
if @last_command && intf.interactive?
@current_command = @last_command
else
next
end
next unless @last_command && intf.interactive?;
end
next if @current_command[0..0] == '#' # Skip comment lines
break
Expand Down Expand Up @@ -412,7 +380,7 @@ def undefined_command(cmd_name)

if __FILE__ == $0
$0 = 'foo' # So we don't get here again
require_relative '../lib/trepanning'
require_relative 'lib/trepanning'
puts "To be continued...."
exit
dbg = Trepan.new(:nx => true)
Expand Down
4 changes: 0 additions & 4 deletions processor/command/base/subcmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ def save_command_from_settings
["#{subcmd_prefix_string} #{settings[subcmd_setting_key]}"]
end

def settings
@proc.settings
end

def subcmd_prefix_string
self.class.const_get(:PREFIX).join(' ')
end
Expand Down
29 changes: 23 additions & 6 deletions processor/command/exit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Trepan::Command::ExitCommand < Trepan::Command
NAME = File.basename(__FILE__, '.rb')
ALIASES = %w(quit q q! quit! exit!)
HELP = <<-HELP
#{NAME} [exitcode] - hard exit of the debugged program.
#{NAME} [exitcode] [unconditionally] - hard exit of the debugged program.
The program being debugged is exited via exit!() which does not run
the Kernel at_exit finalizers. If a return code is given, that is the
Expand All @@ -18,6 +18,13 @@ class Trepan::Command::ExitCommand < Trepan::Command
prompted to confirm quitting. However if you do not want to be
prompted, add ! the end. (vim/vi/ed users can use alias q!).
Examples:
#{NAME} # quit prompting if we are interactive
#{NAME} unconditionally # quit without prompting
#{NAME}! # same as above
#{NAME} 0 # same as "quit"
#{NAME}! 1 # unconditional quit setting exit code 1
See also "kill" and "set confirm".'
HELP

Expand All @@ -32,7 +39,7 @@ class Trepan::Command::ExitCommand < Trepan::Command
# This method runs the command
def run(args) # :nodoc
unconditional =
if args.size > 1 && args[1] == 'unconditionally'
if args.size > 1 && args[-1] == 'unconditionally'
args.shift
true
elsif args[0][-1..-1] == '!'
Expand All @@ -44,7 +51,17 @@ def run(args) # :nodoc
msg('Quit not confirmed.')
return
end
exitrc = (args.size > 1) ? exitrc = Integer(args[1]) rescue 0 : 0

if (args.size > 1)
if args[1] =~ /\d+/
exitrc = args[1].to_i;
else
errmsg "Bad an Integer return type \"#{args[1]}\"";
return;
end
else
exitrc = 0
end

# FIXME: Is this the best/most general way?
## @proc.finalize
Expand All @@ -59,8 +76,8 @@ def run(args) # :nodoc
if __FILE__ == $0
require_relative '../mock'
dbgr, cmd = MockDebugger::setup
puts "before #{cmd.name}"
fork { cmd.run([cmd.name]) }
puts "before #{cmd.name} 10"
Process.fork { cmd.run([cmd.name]) } if
Process.respond_to?(:fork)
cmd.run([cmd.name, 'foo'])
cmd.run([cmd.name, '10'])
end
3 changes: 2 additions & 1 deletion processor/command/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def show_category(category, args)
category == @proc.commands[cmd_name].category
end.sort
width = settings[:maxwidth]
return columnize_commands(cmds)
msg columnize_commands(cmds)
return
end

msg('')
Expand Down
2 changes: 1 addition & 1 deletion processor/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def summary_help(subcmd)
# like "show", "info" or "set". Generally this means list
# all of the subcommands.
def summary_list(name, subcmds)
msg "List of #{name} commands (with minimum abbreviation in parenthesis):"
section "List of #{name} commands (with minimum abbreviation in parenthesis):"
subcmds.list.each do |subcmd_name|
# Some commands have lots of output.
# they are excluded here because 'in_list' is false.
Expand Down
25 changes: 25 additions & 0 deletions processor/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@
require_relative 'virtual'
class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor

unless defined?(EVENT2ICON)
# Event icons used in printing locations.
EVENT2ICON = {
'brkpt' => 'xx',
'tbrkpt' => 'x1',
'c-call' => 'C>',
'c-return' => '<C',
'step-call' => '->',
'call' => '->',
'class' => '::',
'coverage' => '[]',
'debugger-call' => ':o',
'end' => '-|',
'line' => '--',
'raise' => '!!',
'return' => '<-',
'start' => '>>',
'switch' => 'sw',
'trace-var' => '$V',
'unknown' => '?!',
'vm' => 'VM',
'vm-insn' => '..',
}
end

def canonic_file(filename, resolve=true)
# For now we want resolved filenames
if @settings[:basename]
Expand Down
3 changes: 2 additions & 1 deletion processor/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
require_relative '../interface/user' # user interface (includes I/O)

require 'ruby-debug-base'; Debugger.start(:init => true)
require_relative 'processor'
require_relative '../processor'
require_relative 'old-processor'

module MockDebugger
class MockDebugger
Expand Down
6 changes: 6 additions & 0 deletions processor/msg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
require_relative '../app/util'
require_relative 'virtual'

begin require 'term/ansicolor'; rescue LoadError; end

class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
attr_accessor :ruby_highlighter

def confirm(msg, default)
@settings[:confirm] ? @dbgr.intf[-1].confirm(msg, default) : true
end

def errmsg(message, opts={})
if message.kind_of?(Array)
message.each do |mess|
Expand Down
5 changes: 2 additions & 3 deletions processor/processor.rb → processor/old-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
require 'ruby-debug-base'
require 'require_relative'
require_relative '../interface/user'
require_relative './command'
require_relative './default'
require_relative './main'
require_relative '../processor/command'
require_relative '../processor/default'
require_relative '../app/frame'

# _Trepan_ is the module name space for this debugger.
Expand Down
29 changes: 1 addition & 28 deletions processor/subcmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,10 @@ def add(subcmd_cb, subcmd_name=nil)
@cmdlist << subcmd_name
end

# Run subcmd_name with args using obj for the environent
def run( subcmd_name, arg)
entry=lookup(subcmd_name)
if entry
entry['callback'].send(arg)
else
@proc.undefined_cmd(entry.__class__.name, subcmd_name)
end
end

# help for subcommands
# Note: format of help is compatible with ddd.
def help(*args)

msg args
subcmd_prefix = args[0]
if not subcmd_prefix or subcmd_prefix.size == 0
@proc.msg(self.doc)
@proc.msg("\nList of %s subcommands:\n" % [@name])
@list.each do |subcmd_name|
subcmd_helper(subcmd_name, obj, true, true)
end

entry = lookup(subcmd_prefix)
if entry and entry.respond_to? :help
entry.help(args)
else
@proc.errmsg("Unknown 'help %s' subcommand %s" %
[@name, subcmd_prefix])
end
end
# Not used but tested for.
end

def list
Expand Down
Loading

0 comments on commit 111fed3

Please sign in to comment.