rbx-trepanning 0.0.8-universal-rubinius-1.2 → 0.1.0-universal-rubinius-1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/ChangeLog +762 -238
  2. data/NEWS +44 -0
  3. data/Rakefile +61 -32
  4. data/app/breakpoint.rb +2 -0
  5. data/app/brkptmgr.rb +9 -11
  6. data/app/client.rb +0 -1
  7. data/app/cmd_parse.kpeg +21 -4
  8. data/app/cmd_parse.rb +10 -10
  9. data/app/cmd_parser.rb +1029 -840
  10. data/app/complete.rb +1 -1
  11. data/app/display.rb +38 -0
  12. data/app/file.rb +24 -0
  13. data/app/frame.rb +11 -4
  14. data/app/irb.rb +41 -39
  15. data/app/iseq.rb +71 -0
  16. data/app/options.rb +55 -30
  17. data/app/rbx-llvm.rb +0 -2
  18. data/app/run.rb +13 -9
  19. data/app/util.rb +55 -5
  20. data/bin/trepanx +3 -3
  21. data/data/irbrc +13 -13
  22. data/{interface/base_intf.rb → interface.rb} +5 -1
  23. data/interface/client.rb +4 -0
  24. data/interface/script.rb +13 -5
  25. data/interface/server.rb +5 -1
  26. data/interface/user.rb +8 -1
  27. data/{io/base_io.rb → io.rb} +0 -0
  28. data/io/input.rb +1 -1
  29. data/io/null_output.rb +28 -24
  30. data/io/string_array.rb +2 -3
  31. data/io/tcpclient.rb +1 -1
  32. data/io/tcpserver.rb +1 -1
  33. data/lib/trepanning.rb +11 -13
  34. data/{processor/main.rb → processor.rb} +50 -54
  35. data/processor/breakpoint.rb +150 -137
  36. data/processor/{command/base/cmd.rb → command.rb} +1 -1
  37. data/processor/command/alias.rb +14 -3
  38. data/processor/command/backtrace.rb +2 -1
  39. data/processor/command/base/subcmd.rb +1 -5
  40. data/processor/command/base/submgr.rb +5 -2
  41. data/processor/command/base/subsubcmd.rb +1 -1
  42. data/processor/command/base/subsubmgr.rb +4 -4
  43. data/processor/command/break.rb +1 -1
  44. data/processor/command/complete.rb +2 -1
  45. data/processor/command/condition.rb +2 -2
  46. data/processor/command/continue.rb +4 -4
  47. data/processor/command/delete.rb +34 -20
  48. data/processor/command/directory.rb +4 -4
  49. data/processor/command/disable.rb +71 -0
  50. data/processor/command/disassemble.rb +55 -22
  51. data/processor/command/display.rb +3 -1
  52. data/processor/command/down.rb +8 -8
  53. data/processor/command/edit.rb +74 -0
  54. data/processor/command/enable.rb +43 -0
  55. data/processor/command/eval.rb +37 -15
  56. data/processor/command/exit.rb +25 -6
  57. data/processor/command/finish.rb +5 -5
  58. data/processor/command/frame.rb +2 -2
  59. data/processor/command/help.rb +7 -9
  60. data/processor/command/help/README +10 -0
  61. data/processor/command/help/command.txt +37 -27
  62. data/processor/command/help/examples.txt +16 -0
  63. data/processor/command/help/filename.txt +1 -1
  64. data/processor/command/help/suffixes.txt +17 -0
  65. data/processor/command/info.rb +3 -1
  66. data/processor/command/info_subcmd/files.rb +3 -2
  67. data/processor/command/info_subcmd/frame.rb +2 -1
  68. data/processor/command/info_subcmd/line.rb +17 -28
  69. data/processor/command/info_subcmd/locals.rb +22 -0
  70. data/processor/command/{show_subcmd → info_subcmd}/macro.rb +4 -4
  71. data/processor/command/info_subcmd/program.rb +2 -0
  72. data/processor/command/info_subcmd/ruby.rb +2 -0
  73. data/processor/command/info_subcmd/source.rb +75 -0
  74. data/processor/command/info_subcmd/stack.rb +25 -0
  75. data/processor/command/info_subcmd/variables.rb +23 -36
  76. data/processor/command/info_subcmd/variables_subcmd/.gitignore +2 -0
  77. data/processor/command/info_subcmd/variables_subcmd/class.rb +42 -0
  78. data/processor/command/info_subcmd/variables_subcmd/constant.rb +42 -0
  79. data/processor/command/info_subcmd/variables_subcmd/globals.rb +69 -0
  80. data/processor/command/info_subcmd/variables_subcmd/instance.rb +42 -0
  81. data/processor/command/info_subcmd/variables_subcmd/locals.rb +80 -0
  82. data/processor/command/kill.rb +8 -9
  83. data/processor/command/list.rb +101 -167
  84. data/processor/command/macro.rb +28 -10
  85. data/processor/command/next.rb +2 -1
  86. data/processor/command/nexti.rb +1 -1
  87. data/processor/command/parsetree.rb +51 -0
  88. data/processor/command/pr.rb +1 -2
  89. data/processor/command/ps.rb +1 -1
  90. data/processor/command/restart.rb +2 -2
  91. data/processor/command/save.rb +1 -1
  92. data/processor/command/server.rb +1 -1
  93. data/processor/command/set_subcmd/abbrev.rb +25 -0
  94. data/processor/command/set_subcmd/auto.rb +7 -1
  95. data/processor/command/set_subcmd/auto_subcmd/eval.rb +1 -2
  96. data/processor/command/set_subcmd/auto_subcmd/irb.rb +2 -3
  97. data/processor/command/set_subcmd/auto_subcmd/list.rb +2 -3
  98. data/processor/command/set_subcmd/different.rb +1 -1
  99. data/processor/command/set_subcmd/highlight.rb +7 -1
  100. data/processor/command/set_subcmd/reload.rb +42 -0
  101. data/processor/command/set_subcmd/timer.rb +58 -0
  102. data/processor/command/set_subcmd/trace.rb +4 -3
  103. data/processor/command/{irb.rb → shell.rb} +22 -19
  104. data/processor/command/show_subcmd/abbrev.rb +20 -0
  105. data/processor/command/show_subcmd/{alias.rb → aliases.rb} +2 -2
  106. data/processor/command/show_subcmd/auto_subcmd/eval.rb +2 -6
  107. data/processor/command/show_subcmd/directories.rb +22 -0
  108. data/processor/command/show_subcmd/hidelevel.rb +1 -1
  109. data/processor/command/show_subcmd/highlight.rb +2 -1
  110. data/processor/command/show_subcmd/reload.rb +18 -0
  111. data/processor/command/show_subcmd/timer.rb +18 -0
  112. data/processor/command/source.rb +9 -9
  113. data/processor/command/step.rb +1 -1
  114. data/processor/command/tbreak.rb +3 -2
  115. data/processor/command/unalias.rb +11 -6
  116. data/processor/command/undisplay.rb +13 -9
  117. data/processor/command/up.rb +13 -14
  118. data/processor/default.rb +47 -44
  119. data/processor/disassemble.rb +48 -35
  120. data/processor/display.rb +38 -3
  121. data/processor/eval.rb +54 -53
  122. data/processor/eventbuf.rb +69 -69
  123. data/processor/frame.rb +186 -187
  124. data/processor/help.rb +6 -4
  125. data/processor/hook.rb +103 -102
  126. data/processor/list.rb +123 -0
  127. data/processor/load_cmds.rb +9 -1
  128. data/processor/location.rb +193 -188
  129. data/processor/mock.rb +1 -7
  130. data/processor/msg.rb +56 -42
  131. data/processor/running.rb +26 -15
  132. data/processor/stepping.rb +2 -1
  133. data/processor/subcmd.rb +18 -43
  134. data/processor/validate.rb +41 -30
  135. data/processor/virtual.rb +33 -0
  136. data/rbx-trepanning.gemspec +7 -8
  137. data/sample/rocky-trepanx-colors.rb +0 -1
  138. data/test/data/fname-with-blank.right +2 -0
  139. data/test/data/inline-call.right +11 -10
  140. data/test/data/quit.right +1 -0
  141. data/test/example/debugger-stop.rb +1 -1
  142. data/test/example/goto2goto.rb +11 -0
  143. data/test/functional/fn_helper.rb +2 -2
  144. data/test/functional/test-list.rb +7 -6
  145. data/test/integration/helper.rb +5 -5
  146. data/test/unit/cmd-helper.rb +2 -6
  147. data/test/unit/test-app-cmd_parser.rb +3 -2
  148. data/test/unit/test-app-display.rb +22 -0
  149. data/test/unit/test-app-options.rb +14 -10
  150. data/test/unit/test-app-run.rb +0 -2
  151. data/test/unit/test-app-util.rb +21 -4
  152. data/test/unit/test-base-cmd.rb +5 -7
  153. data/test/unit/test-base-subcmd.rb +1 -5
  154. data/test/unit/test-base-submgr.rb +1 -1
  155. data/test/unit/test-base-subsubcmd.rb +0 -4
  156. data/test/unit/test-bin-trepanx.rb +2 -2
  157. data/test/unit/test-cmd-break.rb +2 -0
  158. data/test/unit/test-cmd-edit.rb +34 -0
  159. data/test/unit/test-cmd-kill.rb +11 -4
  160. data/test/unit/test-cmd-parse_list_cmd.rb +36 -0
  161. data/test/unit/test-command.rb +45 -0
  162. data/test/unit/test-completion.rb +1 -1
  163. data/test/unit/test-proc-eval.rb +1 -2
  164. data/test/unit/test-proc-frame.rb +5 -3
  165. data/test/unit/test-proc-list.rb +55 -0
  166. data/test/unit/test-proc-load_cmds.rb +4 -3
  167. data/test/unit/test-proc-location.rb +32 -29
  168. data/test/unit/test-proc-main.rb +1 -5
  169. data/test/unit/test-proc-validate.rb +14 -4
  170. data/test/unit/test-subcmd-help.rb +1 -5
  171. metadata +73 -107
@@ -5,7 +5,7 @@
5
5
  # will think this a command name like QuitCommand
6
6
  require 'rubygems'; require 'require_relative'
7
7
  require 'columnize'
8
- require_relative '../../../app/complete'
8
+ require_relative '../app/complete'
9
9
 
10
10
  class Trepan
11
11
  class Command
@@ -1,6 +1,6 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
 
5
5
  class Trepan::Command::AliasCommand < Trepan::Command
6
6
 
@@ -9,7 +9,18 @@ class Trepan::Command::AliasCommand < Trepan::Command
9
9
  HELP = <<-HELP
10
10
  #{NAME} ALIAS COMMAND
11
11
 
12
- Add an alias for a COMMAND
12
+ Add alias ALIAS for a debugger command COMMAND.
13
+
14
+ Add an alias when you want to use a command abbreviation for a command
15
+ that would otherwise be ambigous. For example, by default we make 's'
16
+ be an alias of 'step' to force it to be used. Without the alias, "s"
17
+ might be "step", "show", or "set" among others
18
+
19
+ Example:
20
+
21
+ alias cat list # "cat rubyfile.rb" is the same as "list rubyfile.rb"
22
+ alias s step # "s" is now an alias for "step".
23
+ # The above examples done by default.
13
24
 
14
25
  See also 'unalias' and 'show #{NAME}'.
15
26
  HELP
@@ -50,5 +61,5 @@ if __FILE__ == $0
50
61
  dbgr, cmd = MockDebugger::setup
51
62
  cmd.run %W(#{cmd.name} yy foo)
52
63
  cmd.run [cmd.name]
53
- cmd.run %W(cmd.name yy next)
64
+ cmd.run %W(cmd.name yy alias)
54
65
  end
@@ -1,5 +1,6 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
1
2
  require 'rubygems'; require 'require_relative'
2
- require_relative './base/cmd'
3
+ require_relative '../command'
3
4
 
4
5
  class Trepan::Command::BacktraceCommand < Trepan::Command
5
6
  ALIASES = %w(bt where)
@@ -10,7 +10,7 @@
10
10
  # functions for command from module cmdfns.
11
11
 
12
12
  require 'rubygems'; require 'require_relative'
13
- require_relative 'cmd'
13
+ require_relative '../../command'
14
14
 
15
15
  class Trepan
16
16
 
@@ -131,10 +131,6 @@ class Trepan
131
131
  ["#{subcmd_prefix_string} #{settings[subcmd_setting_key]}"]
132
132
  end
133
133
 
134
- def settings
135
- @proc.settings
136
- end
137
-
138
134
  def subcmd_prefix_string
139
135
  self.class.const_get(:PREFIX).join(' ')
140
136
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
- require_relative 'cmd'
4
+ require_relative '../../command'
5
5
  require_relative '../../subcmd'
6
6
  require_relative '../../help'
7
7
  require_relative '../../../app/complete'
@@ -165,7 +165,10 @@ class Trepan::SubcommandMgr < Trepan::Command
165
165
  # Run that.
166
166
  subcmd = @subcmds.lookup(subcmd_prefix)
167
167
  if subcmd
168
- subcmd.run(args)
168
+ if @proc.ok_for_running(subcmd, subcmd.class.const_get('CMD'),
169
+ args.size-2)
170
+ subcmd.run(args)
171
+ end
169
172
  else
170
173
  undefined_subcmd(@name, subcmd_prefix)
171
174
  end
@@ -10,7 +10,7 @@
10
10
  # functions for command from module cmdfns.
11
11
 
12
12
  require 'rubygems'; require 'require_relative'
13
- require_relative 'cmd'
13
+ require_relative '../../command'
14
14
  require_relative 'subcmd'
15
15
 
16
16
  class Trepan
@@ -160,19 +160,19 @@ class Trepan::SubSubcommandMgr < Trepan::Subcommand
160
160
 
161
161
  def run(args)
162
162
  args = @parent.last_args if args.size == 0
163
- if args.size < 3 || args.size == 3 && args[-1] == '*'
163
+ if args.size < 3 || args.size == 3 && args[2] == '*'
164
164
  summary_list(obj_const(self, :NAME), @subcmds)
165
165
  return false
166
166
  end
167
167
 
168
- subcmd_prefix = args[0..2].join('')
168
+ subcmd_prefix = obj_const(self, :PREFIX).join('')
169
169
  # We were given: cmd subcmd ...
170
170
  # Run that.
171
- subcmd = @subcmds.lookup(subcmd_prefix)
171
+ subcmd = @subcmds.lookup(subcmd_prefix + args[2])
172
172
  if subcmd
173
173
  subcmd.run(args[2..-1])
174
174
  else
175
- undefined_subcmd(obj_const(self, :PREFIX).join(' '), args[-1])
175
+ undefined_subcmd(obj_const(self, :PREFIX).join(' '), args[2])
176
176
  end
177
177
  end
178
178
 
@@ -1,6 +1,6 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
- require_relative './base/cmd'
3
+ require_relative '../command'
4
4
 
5
5
  class Trepan::Command::BreakCommand < Trepan::Command
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
  require_relative '../load_cmds'
5
5
  class Trepan::Command::CompleteCommand < Trepan::Command
6
6
 
@@ -30,6 +30,7 @@ if __FILE__ == $0
30
30
  require_relative '../mock'
31
31
  dbgr, cmd = MockDebugger::setup
32
32
  %w(d b bt).each do |prefix|
33
+ cmd.proc.instance_variable_set('@cmd_argstr', prefix)
33
34
  cmd.run [cmd.name, prefix]
34
35
  puts '=' * 40
35
36
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
- require_relative 'base/cmd'
4
+ require_relative '../command'
5
5
  require_relative '../breakpoint'
6
6
  require_relative '../../app/breakpoint'
7
7
  require_relative '../../app/condition'
@@ -1,6 +1,6 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
  require_relative '../stepping'
5
5
 
6
6
  class Trepan::Command::ContinueCommand < Trepan::Command
@@ -14,15 +14,15 @@ the debugger however may occur via breakpoints or explicit calls, or
14
14
  exceptions.
15
15
 
16
16
  If a parameter is given, a temporary breakpoint is set at that position
17
- before continuing. Offset are numbers prefixed with an "O" otherwise
17
+ before continuing. Offset are numbers prefixed with an "@" otherwise
18
18
  the parameter is taken as a line number.
19
19
 
20
20
  Examples:
21
21
  #{NAME}
22
22
  #{NAME} 10 # continue to line 10
23
- #{NAME} o20 # continue to VM Instruction Sequence offset 20
23
+ #{NAME} @20 # continue to VM Instruction Sequence offset 20
24
24
  #{NAME} gcd # continue to first instruction of method gcd
25
- #{NAME} IRB.start o7 # continue to IRB.start offset 7
25
+ #{NAME} IRB.start @7 # continue to IRB.start offset 7
26
26
 
27
27
  See also 'step', 'next', 'finish', 'nexti' commands and "help location".
28
28
  HELP
@@ -1,29 +1,43 @@
1
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
1
2
  require 'rubygems'; require 'require_relative'
2
- require_relative './base/cmd'
3
+ require_relative '../command'
3
4
 
4
5
  class Trepan::Command::DeleteBreakpontCommand < Trepan::Command
5
- CATEGORY = 'breakpoints'
6
- NAME = File.basename(__FILE__, '.rb')
7
- SHORT_HELP = 'Delete a breakpoint'
8
- HELP = <<-HELP
9
- Specify the breakpoint by number, use 'info break' to see the numbers
10
- HELP
11
6
 
12
- def run(args)
13
- if args.size != 2
14
- errmsg 'Please specify which breakpoint by number'
15
- return
16
- end
7
+ unless defined?(HELP)
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP = <<-HELP
10
+ #{NAME} [bpnumber [bpnumber...]]
11
+
12
+ Delete some breakpoints.
13
+
14
+ Arguments are breakpoint numbers with spaces in between. To delete
15
+ all breakpoints, give no argument. those breakpoints. Without
16
+ argument, clear all breaks (but first ask confirmation).
17
17
 
18
- begin
19
- i = Integer(args[1])
20
- rescue ArgumentError
21
- errmsg "'#{args}' is not a number"
22
- return
18
+ See also the "clear" command which clears breakpoints by line/file
19
+ number.
20
+ HELP
21
+
22
+ CATEGORY = 'breakpoints'
23
+ SHORT_HELP = 'Delete some breakpoints'
24
+ end
25
+
26
+ def run(args)
27
+ if args.size == 1
28
+ if confirm('Delete all breakpoints?', false)
29
+ @proc.brkpts.reset
30
+ return
31
+ end
23
32
  end
24
-
25
- if @proc.delete_breakpoint_by_number(i)
26
- msg('Deleted breakpoint %d.' % i)
33
+ first = args.shift
34
+ args.each do |num_str|
35
+ opts = {:msg_on_error => '%s must be a number' % num_str}
36
+ i = @proc.get_an_int(num_str, opts)
37
+ if i
38
+ success = @proc.delete_breakpoint_by_number(num_str.to_i, false) if i
39
+ msg('Deleted breakpoint %d.' % i) if success
40
+ end
27
41
  end
28
42
  end
29
43
  end
@@ -1,6 +1,6 @@
1
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
- require_relative 'base/cmd'
3
+ require_relative '../command'
4
4
  class Trepan::Command::DirectoryCommand < Trepan::Command
5
5
 
6
6
  unless defined?(HELP)
@@ -36,8 +36,8 @@ Examples:
36
36
  msg "Source directories searched: #{settings[:directory]}"
37
37
  else
38
38
  if confirm('Reintialize source path to empty?', false)
39
- settings[:directory] = '$cdir:$cwd'
40
- msg 'Source directories searched: $cdir:$cwd'
39
+ settings[:directory] = '$rbx:$cdir:$cwd'
40
+ msg "Source directories searched: #{settings[:directory]}"
41
41
  end
42
42
  end
43
43
  end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../command'
5
+ require_relative '../../app/util'
6
+ require_relative '../breakpoint'
7
+ require_relative '../../app/breakpoint'
8
+
9
+ # disable breakpoint command. The difference however is that the
10
+ # parameter to @proc.en_disable_breakpoint_by_number is different (set
11
+ # as ENABLE_PARM below).
12
+ #
13
+ # NOTE: The enable command subclasses this, so beware when changing!
14
+ class Trepan::Command::DisableCommand < Trepan::Command
15
+
16
+ Trepan::Util.suppress_warnings {
17
+ NAME = File.basename(__FILE__, '.rb')
18
+ HELP = <<-HELP
19
+ #{NAME} [display] NUM1 [NUM2 ...]
20
+
21
+ Disables the breakpoints or display given as a space separated list of
22
+ numbers.
23
+
24
+ See also "enable" and "info break".
25
+ HELP
26
+
27
+ CATEGORY = 'breakpoints'
28
+ SHORT_HELP = 'Disable some breakpoints or displays'
29
+ }
30
+
31
+ def initialize(proc)
32
+ super
33
+ @enable_parm = false # true if enable
34
+ end
35
+
36
+ def run(args)
37
+ if args.size == 1
38
+ errmsg('No breakpoint or display number given.')
39
+ return
40
+ end
41
+ if args[1] == 'display'
42
+ args.shift
43
+ first = args.shift
44
+ args.each do |num_str|
45
+ i = @proc.get_an_int(num_str)
46
+ success = @proc.en_disable_display_by_number(i, @enable_parm) if i
47
+ msg("Display %s #{@name}d." % i) if success
48
+ end
49
+ end
50
+ first = args.shift
51
+ args.each do |num_str|
52
+ i = @proc.get_an_int(num_str)
53
+ success = @proc.en_disable_breakpoint_by_number(i, @enable_parm) if i
54
+ msg("Breakpoint %s #{@name}d." % i) if success
55
+ end
56
+ end
57
+ end
58
+
59
+ if __FILE__ == $0
60
+ require_relative '../mock'
61
+ dbgr, cmd = MockDebugger::setup
62
+ cmd.run([cmd.name])
63
+ cmd.run([cmd.name, '1'])
64
+ cmdproc = dbgr.core.processor
65
+ cmds = cmdproc.commands
66
+ break_cmd = cmds['break']
67
+ break_cmd.run(['break', cmdproc.frame.source_location[0].to_s])
68
+ # require_relative '../../lib/trepanning'
69
+ # Trepan.debug
70
+ cmd.run([cmd.name, '1'])
71
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
3
  require 'rubygems'; require 'require_relative'
4
- require_relative './base/cmd'
4
+ require_relative '../command'
5
5
  require_relative '../../app/method'
6
6
  require_relative '../../app/iseq'
7
7
 
@@ -10,10 +10,10 @@ class Trepan::Command::DisassembleCommand < Trepan::Command
10
10
  include Trepanning::Method
11
11
 
12
12
  NAME = File.basename(__FILE__, '.rb')
13
- ALIASES = %w(disas disassem) # Note we (will) have disable
13
+ ALIASES = %w(disasm) # Note we have disable
14
14
  CATEGORY = 'data'
15
15
  HELP = <<-HELP
16
- #{NAME} [all]
16
+ #{NAME} [--all | -a]
17
17
  #{NAME} [method|LINE-NUM]...
18
18
 
19
19
  Disassembles Rubinius VM instructions. By default, the bytecode for the
@@ -26,11 +26,11 @@ has bytecode assocated with that line. Note that if a line has
26
26
  discontinuous regions we will show just the first region associated
27
27
  with that line.
28
28
 
29
- If the argument is 'all', the entire method is shown as bytecode.
29
+ If the argument is '--all', the entire method is shown as bytecode.
30
30
 
31
31
  Examples:
32
32
  #{NAME} # dissasemble VM for current line
33
- #{NAME} all # disassemble entire current method
33
+ #{NAME} --all # disassemble entire current method
34
34
  #{NAME} [1,2].max # disassemble max method of Array
35
35
  #{NAME} Object.is_a? # disassemble Object.is_a?
36
36
  #{NAME} is_a? # same as above (probably)
@@ -40,6 +40,11 @@ Examples:
40
40
 
41
41
  NEED_STACK = true
42
42
  SHORT_HELP = 'Show the bytecode for the current method'
43
+ DEFAULT_OPTIONS = {
44
+ :all => false,
45
+ }
46
+
47
+ completion %w(-a --all)
43
48
 
44
49
  def disassemble_method(cm)
45
50
  frame_ip = (@proc.frame.method == cm) ? @proc.frame.next_ip : nil
@@ -77,11 +82,15 @@ Examples:
77
82
 
78
83
  # FIXME DRY with ../disassemble.rb
79
84
  if settings[:highlight]
80
- require_relative '../../app/rbx-llvm'
81
- @llvm_highlighter ||= CodeRay::Duo[:llvm, :term]
82
- # llvm_scanner = CodeRay.scanner :llvm
83
- # p llvm_scanner.tokenize(disasm)
84
- disasm = @llvm_highlighter.encode(disasm)
85
+ begin
86
+ require_relative '../../app/rbx-llvm'
87
+ @llvm_highlighter ||= CodeRay::Duo[:llvm, :term]
88
+ # llvm_scanner = CodeRay.scanner :llvm
89
+ # p llvm_scanner.tokenize(disasm)
90
+ disasm = @llvm_highlighter.encode(disasm)
91
+ rescue LoadError
92
+ errmsg 'Highlighting requested but CodeRay is not installed.'
93
+ end
85
94
  end
86
95
 
87
96
  disasm.split("\n").each_with_index do |inst, i|
@@ -89,13 +98,33 @@ Examples:
89
98
  end
90
99
  end
91
100
 
101
+ def parse_options(options, args) # :nodoc
102
+ parser = OptionParser.new do |opts|
103
+ opts.on('-a', '--all',
104
+ 'show entire method') do
105
+ options[:all] = true
106
+ end
107
+ end
108
+ begin
109
+ parser.parse! args
110
+ rescue OptionParser::InvalidOption => e
111
+ errmsg e
112
+ end
113
+ return options
114
+
115
+ end
116
+
92
117
  # Run command.
93
118
  def run(args)
94
- if 1 == args.size
95
- @proc.show_bytecode
96
- elsif 'all' == args[1]
97
- section "Bytecode for #{@proc.frame.vm_location.describe}"
98
- disassemble_method(current_method)
119
+ my_args = args[1..-1]
120
+ options = parse_options(DEFAULT_OPTIONS.dup, my_args)
121
+ if my_args.empty?
122
+ if options[:all]
123
+ section "Bytecode for #{@proc.frame.vm_location.describe}"
124
+ disassemble_method(current_method)
125
+ else
126
+ @proc.show_bytecode
127
+ end
99
128
  else
100
129
  args[1..-1].each do |arg|
101
130
  cm = @proc.parse_method(arg)
@@ -125,19 +154,23 @@ if __FILE__ == $0
125
154
  # Demo it.
126
155
  require_relative '../mock'
127
156
  dbgr, cmd = MockDebugger::setup
157
+ def five; 5 end
128
158
  def foo(cmd)
129
159
  puts "#{cmd.name}"
130
160
  cmd.run([cmd.name])
131
161
  puts '=' * 40
132
- puts "#{cmd.name} all"
133
- cmd.run([cmd.name, 'all'])
162
+ puts "#{cmd.name} --all"
163
+ # require_relative '../../lib/trepanning'; debugger
164
+ cmd.run([cmd.name, '--all'])
165
+ puts '=' * 40
166
+ cmd.run([cmd.name, '-a'])
134
167
  puts '=' * 40
135
- p cmd.proc.frame.vm_location.describe
136
- cmd.run([cmd.name, 'foo'])
168
+ cmd.run([cmd.name, 'five'])
169
+ ## FIXME: someday handle:
170
+ # puts '=' * 40
171
+ # cmd.run([cmd.name, '-a', 'five'])
137
172
  puts '=' * 40
138
- # require_relative '../../lib/trepanning'
139
- # debugger
140
- cmd.run([cmd.name, 'self.setup'])
173
+ cmd.run([cmd.name, 'MockDebugger::setup'])
141
174
  puts '=' * 40
142
175
  cmd.run([cmd.name, __LINE__.to_s])
143
176
  require 'irb'