rbx-trepanning 0.2.0-universal-rubinius-2.0 → 0.2.1-universal-rubinius-2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
+ require 'redcard/rubinius'
4
5
  require_relative '../../command'
5
6
  require_relative '../../subcmd'
6
7
  require_relative '../../help'
@@ -14,7 +15,7 @@ class Trepan::SubcommandMgr < Trepan::Command
14
15
  CATEGORY = 'status'
15
16
  MIN_ARGS = 0
16
17
  MAX_ARGS = nil
17
- NAME = '?' # FIXME: Need to define this, but should
18
+ NAME = '?' # FIXME: Need to define this, but should
18
19
  # pick this up from class/file name.
19
20
  NEED_STACK = false
20
21
  end
@@ -33,6 +34,15 @@ class Trepan::SubcommandMgr < Trepan::Command
33
34
  load_debugger_subcommands(self)
34
35
  end
35
36
 
37
+ def get_const(klass, name)
38
+ name = name.to_sym if RedCard.check '1.9'
39
+ if klass.constants.member?(name)
40
+ klass.const_get(name)
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
36
46
  # Create an instance of each of the debugger subcommands. Commands
37
47
  # are found by importing files in the directory 'name' + '_sub'. Some
38
48
  # files are excluded via an array set in initialize. For each of
@@ -48,7 +58,7 @@ class Trepan::SubcommandMgr < Trepan::Command
48
58
  cmd_dir = File.dirname(__FILE__)
49
59
  subcmd_dir = File.join(cmd_dir, '..', name + '_subcmd')
50
60
  files = Dir.glob(File.join(subcmd_dir, '*.rb'))
51
- files.each do |rb|
61
+ files.each do |rb|
52
62
  basename = File.basename(rb, '.rb')
53
63
  if File.directory?(File.join(File.dirname(rb), basename + '_subcmd'))
54
64
  subcmd_names << name.capitalize + basename.capitalize
@@ -60,14 +70,12 @@ class Trepan::SubcommandMgr < Trepan::Command
60
70
 
61
71
  subcommands = {}
62
72
  cmd_names.each do |name|
63
- next unless Trepan::Subcommand.constants.member?(name)
64
- klass = Trepan::Subcommand.const_get(name)
73
+ next unless klass = get_const(Trepan::Subcommand, name)
65
74
  cmd = klass.send(:new, self)
66
75
  @subcmds.add(cmd)
67
76
  end
68
77
  subcmd_names.each do |name|
69
- next unless Trepan::SubSubcommand.constants.member?(name)
70
- subcmd_class = Trepan::SubSubcommand.const_get(name)
78
+ next unless subcmd_class = get_const(Trepan::SubSubcommand, name)
71
79
  begin
72
80
  cmd = subcmd_class.send(:new, self, parent)
73
81
  rescue Exception => exc
@@ -83,7 +91,7 @@ class Trepan::SubcommandMgr < Trepan::Command
83
91
  # help cmd subcmd
84
92
  # help cmd commands
85
93
  #
86
- # Our shtick is to give help for the overall command only if
94
+ # Our shtick is to give help for the overall command only if
87
95
  # subcommand or 'commands' is not given. If a subcommand is given and
88
96
  # found, then specific help for that is given. If 'commands' is given
89
97
  # we will list the all the subcommands.
@@ -94,8 +102,8 @@ class Trepan::SubcommandMgr < Trepan::Command
94
102
  if doc
95
103
  return doc
96
104
  else
97
- errmsg('Sorry - author mess up. ' +
98
- 'No help registered for command' +
105
+ errmsg('Sorry - author mess up. ' +
106
+ 'No help registered for command' +
99
107
  @name)
100
108
  return nil
101
109
  end
@@ -119,9 +127,9 @@ class Trepan::SubcommandMgr < Trepan::Command
119
127
  if doc
120
128
  return doc
121
129
  else
122
- errmsg('Sorry - author mess up. ' +
123
- 'No help registered for subcommand: ' +
124
- subcmd_name + ', of command: ' +
130
+ errmsg('Sorry - author mess up. ' +
131
+ 'No help registered for subcommand: ' +
132
+ subcmd_name + ', of command: ' +
125
133
  @name)
126
134
  return nil
127
135
  end
@@ -144,7 +152,7 @@ class Trepan::SubcommandMgr < Trepan::Command
144
152
 
145
153
  # Return an Array of subcommands that can start with +arg+. If none
146
154
  # found we just return +arg+.
147
- # FIXME: Not used any more?
155
+ # FIXME: Not used any more?
148
156
  def complete(prefix)
149
157
  Trepan::Complete.complete_token(@subcmds.subcmds.keys, prefix)
150
158
  end
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  # A base class for debugger subcommands of subcommands.
4
4
  #
5
5
  # Note: don't end classname with Command (capital C as in SubCommand),
6
- # since main will think this a command name like QuitCommand
7
- # ^
6
+ # since main will think this a command name like QuitCommand
7
+ # ^
8
8
 
9
9
  # Base Class for Trepan subcommands. We pull in some helper
10
10
  # functions for command from module cmdfns.
@@ -28,21 +28,19 @@ class Trepan
28
28
  end
29
29
 
30
30
  def string_in_show
31
- help_constant_sym = if self.class.constants.member?('SHORT_HELP')
32
- :SHORT_HELP
33
- else :HELP
34
- end
35
- str = my_const(help_constant_sym)
31
+ help = get_const(self.class, 'SHORT_HELP')
32
+ help = get_const(self.class, 'HELP') unless help
33
+ help = help.split[0] if !help
36
34
  %w(Show Set).each do |word|
37
- if 0 == str.index(word)
38
- str = str[word.size+1 ..-1].capitalize
35
+ if 0 == help.index(word)
36
+ help = help[word.size+1 ..-1].capitalize
39
37
  break
40
38
  end
41
39
  end
42
- str
40
+ help
43
41
  end
44
42
 
45
- # Set a Boolean-valued debugger setting.
43
+ # Set a Boolean-valued debugger setting.
46
44
  def run_set_bool(args, default=true)
47
45
  set_val = args.size < 2 ? 'on' : args[1]
48
46
  setting = @name.gsub(/^(set|show)/,'')
@@ -100,7 +98,7 @@ module Trepanning
100
98
 
101
99
  short_dirname = dirname[0...-'_subcmd'.size]
102
100
  short_parent_dirname = parent_dirname[0...-'_subcmd'.size]
103
- prefix = klass.const_set('PREFIX', %W(#{short_parent_dirname}
101
+ prefix = klass.const_set('PREFIX', %W(#{short_parent_dirname}
104
102
  #{short_dirname} #{name}))
105
103
  klass.const_set('CMD', prefix.join(' '))
106
104
  end
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
+ require 'redcard/rubinius'
4
5
  require_relative 'subcmd'
5
6
  require_relative '../../subcmd'
6
7
  require_relative '../../help'
@@ -13,7 +14,7 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
13
14
  CATEGORY = 'status'
14
15
  MIN_ARGS = 0
15
16
  MAX_ARGS = nil
16
- NAME = '?' # FIXME: Need to define this, but should
17
+ NAME = '?' # FIXME: Need to define this, but should
17
18
  # pick this up from class/file name.
18
19
  NEED_STACK = false
19
20
  end
@@ -21,10 +22,29 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
21
22
  attr_accessor :pname
22
23
  attr_accessor :subcmds # Array of instantiated Trepan::Subcommand objects
23
24
 
25
+ # Work around Ruby 1.8/1.9 incompatibility
26
+ def get_const(klass, name)
27
+ name = name.to_sym if RedCard.check '1.9'
28
+ if klass.constants.member?(name)
29
+ klass.const_get(name)
30
+ else
31
+ nil
32
+ end
33
+ end
34
+
35
+ def set_const(klass, name, val)
36
+ name = name.to_sym if RedCard.check '1.9'
37
+ if klass.constants.member?(name)
38
+ klass.const_set(name, val)
39
+ else
40
+ nil
41
+ end
42
+ end
43
+
24
44
  # Initialize show subcommands. Note: instance variable name
25
45
  # has to be setcmds ('set' + 'cmds') for subcommand completion
26
46
  # to work.
27
- # FIXME: do we need proc still?
47
+ # FIXME: do we need proc still?
28
48
  def initialize(proc, parent)
29
49
  name = obj_const(self, :NAME)
30
50
  @name = name.to_sym
@@ -38,11 +58,11 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
38
58
  # The below was the simplest way I could find to do this since
39
59
  # we are the super class but want to set the subclass's constant.
40
60
  # defined? didn't seem to work here.
41
- c = self.class.constants
42
- self.class.const_set('SHORT_HELP',
43
- self.class.const_get('HELP')) if
44
- c.member?('HELP') and !c.member?('SHORT_HELP')
45
-
61
+ if !get_const(self.class, 'SHORT_HELP') and (help = get_const(self.class, 'HELP'))
62
+ help = help.split
63
+ set_const(self.class, 'SHORT_HELP', help)
64
+ end
65
+
46
66
  load_debugger_subsubcommands(name, self)
47
67
  end
48
68
 
@@ -60,7 +80,7 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
60
80
  cmd_dir = File.dirname(__FILE__)
61
81
  subcmd_dir = File.join(cmd_dir, '..', @pname + '_subcmd', name + '_subcmd')
62
82
  files = Dir.glob(File.join(subcmd_dir, '*.rb'))
63
- files.each do |rb|
83
+ files.each do |rb|
64
84
  cmd_names << name.capitalize + File.basename(rb, '.rb').capitalize
65
85
  require rb
66
86
  end if File.directory?(subcmd_dir)
@@ -69,9 +89,8 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
69
89
  cmd_names.each do |subname|
70
90
  cmd_name = "#{pname}#{subname.downcase}"
71
91
  subclass_name = "#{@pname.capitalize}#{subname}"
72
- next unless
73
- Trepan::SubSubcommand.constants.member?(subclass_name)
74
- cmd = self.instance_eval("Trepan::SubSubcommand::" + subclass_name +
92
+ next unless subcmd_class = get_const(Trepan::SubSubcommand, subclass_name)
93
+ cmd = self.instance_eval("Trepan::SubSubcommand::" + subclass_name +
75
94
  ".new(self, @parent, '#{cmd_name}')")
76
95
  @subcmds.add(cmd, cmd_name)
77
96
  end
@@ -83,7 +102,7 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
83
102
  # help cmd subcmd
84
103
  # help cmd commands
85
104
  #
86
- # Our shtick is to give help for the overall command only if
105
+ # Our shtick is to give help for the overall command only if
87
106
  # subcommand or 'commands' is not given. If a subcommand is given and
88
107
  # found, then specific help for that is given. If 'commands' is given
89
108
  # we will list the all the subcommands.
@@ -94,8 +113,8 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
94
113
  if doc
95
114
  return doc
96
115
  else
97
- errmsg('Sorry - author mess up. ' +
98
- 'No help registered for command' +
116
+ errmsg('Sorry - author mess up. ' +
117
+ 'No help registered for command' +
99
118
  @name)
100
119
  return nil
101
120
  end
@@ -113,7 +132,7 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
113
132
  end
114
133
 
115
134
  # "help cmd subcmd". Give help specific for that subcommand if
116
- # the command matches uniquely, or show a list of matching
135
+ # the command matches uniquely, or show a list of matching
117
136
  # subcommands
118
137
  keyprefix_str = prefix.join('')
119
138
  key_str = keyprefix_str + subcmd_name
@@ -123,9 +142,9 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
123
142
  if doc
124
143
  return doc
125
144
  else
126
- errmsg('Sorry - author mess up. ' +
127
- 'No help registered for subcommand: ' +
128
- subcmd_name + ', of command: ' +
145
+ errmsg('Sorry - author mess up. ' +
146
+ 'No help registered for subcommand: ' +
147
+ subcmd_name + ', of command: ' +
129
148
  @name)
130
149
  return nil
131
150
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../command'
5
5
  require_relative '../../app/method'
@@ -19,7 +19,7 @@ class Trepan::Command::DisassembleCommand < Trepan::Command
19
19
  Disassembles Rubinius VM instructions. By default, the bytecode for the
20
20
  current line is disassembled only.
21
21
 
22
- If a method name is given, disassemble just that method.
22
+ If a method name is given, disassemble just that method.
23
23
 
24
24
  If a line number given, then disassemble just that line number if it
25
25
  has bytecode assocated with that line. Note that if a line has
@@ -54,7 +54,7 @@ Examples:
54
54
  prefixes = []
55
55
  disasm = ''
56
56
  cm.decode.each do |insn|
57
- show_line =
57
+ show_line =
58
58
  if insn.ip >= next_line_ip
59
59
  next_line_ip = lines.at(next_i+1)
60
60
  line_no = lines.at(next_i)
@@ -63,11 +63,11 @@ Examples:
63
63
  else
64
64
  false
65
65
  end
66
-
66
+
67
67
  prefixes << Trepan::ISeq::disasm_prefix(insn.ip, frame_ip, cm)
68
68
  str = insn.to_s
69
69
  if show_line
70
- str +=
70
+ str +=
71
71
  if insn.instance_variable_get('@comment')
72
72
  ' '
73
73
  elsif str[-1..-1] !~/\s/
@@ -75,7 +75,7 @@ Examples:
75
75
  else
76
76
  ''
77
77
  end
78
- str += "# line: #{line_no}"
78
+ str += "# line: #{line_no}"
79
79
  end
80
80
  disasm += "#{str}\n"
81
81
  end
@@ -92,15 +92,15 @@ Examples:
92
92
  errmsg 'Highlighting requested but CodeRay is not installed.'
93
93
  end
94
94
  end
95
-
95
+
96
96
  disasm.split("\n").each_with_index do |inst, i|
97
- msg ("#{prefixes[i]} #{inst}", :unlimited => true)
97
+ msg("#{prefixes[i]} #{inst}", :unlimited => true)
98
98
  end
99
99
  end
100
100
 
101
101
  def parse_options(options, args) # :nodoc
102
102
  parser = OptionParser.new do |opts|
103
- opts.on('-a', '--all',
103
+ opts.on('-a', '--all',
104
104
  'show entire method') do
105
105
  options[:all] = true
106
106
  end
@@ -114,7 +114,7 @@ Examples:
114
114
 
115
115
  end
116
116
 
117
- # Run command.
117
+ # Run command.
118
118
  def run(args)
119
119
  my_args = args[1..-1]
120
120
  options = parse_options(DEFAULT_OPTIONS.dup, my_args)
@@ -133,7 +133,7 @@ Examples:
133
133
  disassemble_method(cm.executable)
134
134
  else
135
135
  opts = {:msg_on_error => false }
136
- line_num = @proc.get_an_int(arg, opts)
136
+ line_num = @proc.get_an_int(arg, opts)
137
137
  if line_num
138
138
  cm = find_method_with_line(current_method, line_num)
139
139
  if cm
@@ -28,7 +28,7 @@ info line command.
28
28
  'breakpoints' => 'Making the program stop at certain points',
29
29
  'data' => 'Examining data',
30
30
  'files' => 'Specifying and examining files',
31
- 'running' => 'Running the program',
31
+ 'running' => 'Running the program',
32
32
  'status' => 'Status inquiries',
33
33
  'support' => 'Support facilities',
34
34
  'stack' => 'Examining the call stack',
@@ -50,15 +50,15 @@ info line command.
50
50
  end
51
51
 
52
52
  def complete(prefix)
53
- matches = Trepan::Complete.complete_token(CATEGORIES.keys + %w(* all) +
53
+ matches = Trepan::Complete.complete_token(CATEGORIES.keys + %w(* all) +
54
54
  @proc.commands.keys, prefix)
55
- aliases = Trepan::Complete.complete_token_filtered(@proc.aliases, prefix,
55
+ aliases = Trepan::Complete.complete_token_filtered(@proc.aliases, prefix,
56
56
  matches)
57
57
  (matches + aliases).sort
58
- end
58
+ end
59
59
 
60
60
  def complete_token_with_next(prefix)
61
- complete(prefix).map do |cmd|
61
+ complete(prefix).map do |cmd|
62
62
  [cmd, @proc.commands.member?(cmd) ? @proc.commands[cmd] : nil]
63
63
  end
64
64
  end
@@ -79,7 +79,7 @@ Type "help REGEXP" for the list of commands matching /^#{REGEXP}/.
79
79
  Type "help CLASS *" for the list of all commands in class CLASS.
80
80
  Type "help" followed by a command name for full documentation.
81
81
  '
82
- msg(final_msg)
82
+ msg(final_msg)
83
83
  end
84
84
 
85
85
  # This method runs the command
@@ -105,27 +105,27 @@ Type "help" followed by a command name for full documentation.
105
105
  elsif CATEGORIES.member?(cmd_name)
106
106
  show_category(args[1], args[2..-1])
107
107
  elsif @proc.commands.member?(cmd_name) or @proc.aliases.member?(cmd_name)
108
- real_name =
109
- if @proc.commands.member?(cmd_name)
108
+ real_name =
109
+ if @proc.commands.member?(cmd_name)
110
110
  cmd_name
111
111
  else
112
112
  @proc.aliases[cmd_name]
113
113
  end
114
114
  cmd_obj = @proc.commands[real_name]
115
- help_text =
116
- cmd_obj.respond_to?(:help) ? cmd_obj.help(args) :
115
+ help_text =
116
+ cmd_obj.respond_to?(:help) ? cmd_obj.help(args) :
117
117
  cmd_obj.class.const_get(:HELP)
118
118
  if help_text
119
- msg(help_text)
120
- if cmd_obj.class.constants.member?('ALIASES') and
121
- args.size == 2
122
- msg "Aliases: #{cmd_obj.class.const_get(:ALIASES).join(', ')}"
119
+ msg(help_text)
120
+ aliases=@proc.get_class_aliases(cmd_obj.class)
121
+ if !aliases.empty? and args.size == 2
122
+ msg "Aliases: #{aliases.join(', ')}"
123
123
  end
124
124
  end
125
125
  elsif @proc.macros.member?(cmd_name)
126
126
  msg "#{cmd_name} is a macro which expands to:"
127
127
  msg " #{@proc.macros[cmd_name]}", {:unlimited => true}
128
- else
128
+ else
129
129
  matches = @proc.commands.keys.grep(/^#{cmd_name}/).sort rescue []
130
130
  if matches.empty?
131
131
  errmsg("No commands found matching /^#{cmd_name}/. Try \"help\".")
@@ -146,37 +146,37 @@ Type "help" followed by a command name for full documentation.
146
146
 
147
147
  # Show short help for all commands in `category'.
148
148
  def show_category(category, args)
149
-
149
+
150
150
  if args.size == 1 && args[0] == '*'
151
151
  section "Commands in class %s:" % category
152
-
152
+
153
153
  cmds = @proc.commands.keys.select do |cmd_name|
154
154
  category == @proc.commands[cmd_name].category
155
155
  end.sort
156
156
  width = settings[:maxwidth]
157
157
  msg columnize_commands(cmds)
158
- return
158
+ return
159
159
  end
160
-
160
+
161
161
  section "Command class: %s" % category
162
162
  @proc.commands.keys.sort.each do |name|
163
163
  next if category != @proc.commands[name].category
164
164
  msg("%-13s -- %s" % [name, @proc.commands[name].short_help])
165
165
  end
166
166
  end
167
-
167
+
168
168
  def syntax_files
169
- @syntax_files ||= Dir.glob(File.join(HELP_DIR, '*.txt')).map do |txt|
169
+ @syntax_files ||= Dir.glob(File.join(HELP_DIR, '*.txt')).map do |txt|
170
170
  basename = File.basename(txt, '.txt')
171
171
  end
172
172
  end
173
-
173
+
174
174
  def show_command_syntax(args)
175
175
  if args.size == 2
176
176
  @syntax_summary_help ||= {}
177
177
  section "List of syntax help"
178
178
  syntax_files.each do |name|
179
- @syntax_summary_help[name] ||=
179
+ @syntax_summary_help[name] ||=
180
180
  File.open(File.join(HELP_DIR, "#{name}.txt")).readline.chomp
181
181
  msg " %-8s -- %s" % [name, @syntax_summary_help[name]]
182
182
  end
@@ -184,7 +184,7 @@ Type "help" followed by a command name for full documentation.
184
184
  args[2..-1].each do |name|
185
185
  if syntax_files.member?(name)
186
186
  @syntax_help ||= {}
187
- @syntax_help[name] =
187
+ @syntax_help[name] =
188
188
  File.open(File.join(HELP_DIR, "#{name}.txt")).readlines[2..-1].join
189
189
  section "Help for #{name}:"
190
190
  msg @syntax_help[name]