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
data/processor/mock.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Mock setup for commands.
3
3
  require 'rubygems'; require 'require_relative'
4
4
 
5
- require_relative 'main'
5
+ require_relative '../processor'
6
6
 
7
7
  # require_relative '../app/core'
8
8
  require_relative '../app/default'
@@ -83,12 +83,6 @@ module MockDebugger
83
83
  def cmd.confirm(prompt, default)
84
84
  true
85
85
  end
86
- def cmd.errmsg(message, opts={})
87
- puts "Error: #{message}"
88
- end
89
- def cmd.msg(message, opts={})
90
- puts message
91
- end
92
86
  def cmd.msg_nocr(message, opts={})
93
87
  print message
94
88
  end
data/processor/msg.rb CHANGED
@@ -2,59 +2,73 @@
2
2
  # I/O related command processor methods
3
3
  require 'rubygems'; require 'require_relative'
4
4
  require_relative '../app/util'
5
- class Trepan
6
- class CmdProcessor
7
- attr_accessor :ruby_highlighter
5
+ require_relative 'virtual'
8
6
 
9
- def errmsg(message, opts={})
10
- message = safe_rep(message) unless opts[:unlimited]
11
- if @settings[:highlight] && defined?(Term::ANSIColor)
12
- message =
13
- Term::ANSIColor.italic + message + Term::ANSIColor.reset
14
- end
15
- @dbgr.intf[-1].errmsg(message)
16
- end
7
+ begin require 'term/ansicolor'; rescue LoadError; end
17
8
 
18
- def msg(message, opts={})
19
- message = safe_rep(message) unless opts[:unlimited]
20
- @dbgr.intf[-1].msg(message)
21
- end
9
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
10
+ attr_accessor :ruby_highlighter
11
+
12
+ def confirm(msg, default)
13
+ @settings[:confirm] ? @dbgr.intf[-1].confirm(msg, default) : true
14
+ end
22
15
 
23
- def msg_nocr(message, opts={})
16
+ def errmsg(message, opts={})
17
+ if message.kind_of?(Array)
18
+ message.each do |mess|
19
+ errmsg(mess, opts)
20
+ end
21
+ return
22
+ else
24
23
  message = safe_rep(message) unless opts[:unlimited]
25
- @dbgr.intf[-1].msg_nocr(message)
26
24
  end
27
-
28
- def read_command()
29
- @dbgr.intf[-1].read_command(@prompt)
25
+ if @settings[:highlight] && defined?(Term::ANSIColor)
26
+ message =
27
+ Term::ANSIColor.italic + message + Term::ANSIColor.reset
30
28
  end
29
+ @dbgr.intf[-1].errmsg(message)
30
+ end
31
31
 
32
- def ruby_format(text)
33
- return text unless settings[:highlight]
34
- unless @ruby_highlighter
35
- begin
36
- require 'coderay'
37
- require 'term/ansicolor'
38
- @ruby_highlighter = CodeRay::Duo[:ruby, :term]
39
- rescue LoadError
40
- return text
41
- end
42
- end
43
- return @ruby_highlighter.encode(text)
44
- end
32
+ def msg(message, opts={})
33
+ message = safe_rep(message) unless opts[:unlimited]
34
+ message = ruby_format(message) if opts[:code]
35
+ @dbgr.intf[-1].msg(message)
36
+ end
45
37
 
46
- def safe_rep(str)
47
- Util::safe_repr(str, @settings[:maxstring])
48
- end
38
+ def msg_nocr(message, opts={})
39
+ message = safe_rep(message) unless opts[:unlimited]
40
+ @dbgr.intf[-1].msg_nocr(message)
41
+ end
49
42
 
50
- def section(message, opts={})
51
- message = safe_rep(message) unless opts[:unlimited]
52
- if @settings[:highlight] && defined?(Term::ANSIColor)
53
- message =
54
- Term::ANSIColor.bold + message + Term::ANSIColor.reset
43
+ def read_command()
44
+ @dbgr.intf[-1].read_command(@prompt)
45
+ end
46
+
47
+ def ruby_format(text)
48
+ return text unless settings[:highlight]
49
+ unless @ruby_highlighter
50
+ begin
51
+ require 'coderay'
52
+ require 'term/ansicolor'
53
+ @ruby_highlighter = CodeRay::Duo[:ruby, :term]
54
+ rescue LoadError
55
+ return text
55
56
  end
56
- @dbgr.intf[-1].msg(message)
57
57
  end
58
+ return @ruby_highlighter.encode(text)
59
+ end
58
60
 
61
+ def safe_rep(str)
62
+ Trepan::Util::safe_repr(str, @settings[:maxstring])
59
63
  end
64
+
65
+ def section(message, opts={})
66
+ message = safe_rep(message) unless opts[:unlimited]
67
+ if @settings[:highlight] && defined?(Term::ANSIColor)
68
+ message =
69
+ Term::ANSIColor.bold + message + Term::ANSIColor.reset
70
+ end
71
+ @dbgr.intf[-1].msg(message)
72
+ end
73
+
60
74
  end
data/processor/running.rb CHANGED
@@ -1,10 +1,9 @@
1
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
- require 'rubygems'; require 'require_relative'
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
2
  require 'set'
4
- ## require_relative '../app/core'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'virtual'
5
5
  class Trepan
6
- class CmdProcessor
7
-
6
+ class CmdProcessor < VirtualCmdProcessor
8
7
 
9
8
  attr_accessor :ignore_file_re # Hash[file_re] -> String
10
9
  # action. File re's we don't want
@@ -35,6 +34,8 @@ class Trepan
35
34
  # # FIXME: turn line_number into a condition.
36
35
 
37
36
  def continue(return_to_program)
37
+ @next_level = 32000 # I'm guessing the stack size can't
38
+ # ever reach this
38
39
  @next_thread = nil
39
40
  @step_count = -1 # No more event stepping
40
41
  if 'step-finish' == return_to_program
@@ -46,10 +47,11 @@ class Trepan
46
47
 
47
48
  # Does whatever setup needs to be done to set to ignore stepping
48
49
  # to the finish of the current method. Elsewhere in
49
- # "skipping_step?" we do the checking.
50
+ # "stepping_skip?" we do the checking.
50
51
  def finish(level_count=0, opts={})
51
52
  step_to_return_or_yield
52
53
  continue('finish')
54
+ @next_level = @stack_size - level_count
53
55
  @next_thread = @current_thread
54
56
 
55
57
  @step_count = 2 if 'nostack' == opts[:different_pos]
@@ -62,15 +64,16 @@ class Trepan
62
64
  def step_finish
63
65
  step_to_return_or_yield
64
66
  continue('step')
65
- @next_thread = @current_thread
67
+ @next_thread = @current_thread
66
68
  end
67
69
 
68
- # # Does whatever needs to be done to set to "next" program
69
- # # execution.
70
- # def next(step_count=1, opts={})
71
- # step(step_count, opts)
72
- # @next_thread = Thread.current
73
- # end
70
+ # Does whatever needs to be done to set to "next" program
71
+ # execution.
72
+ def next(step_count=1, opts={})
73
+ step('step', step_count, opts)
74
+ @next_level = opts[:next_level] || @stack_size
75
+ @next_thread = Thread.current
76
+ end
74
77
 
75
78
  # Does whatever needs to be done to set to step program
76
79
  # execution.
@@ -136,8 +139,16 @@ class Trepan
136
139
  # like the @settings[:different] are met.
137
140
  def stepping_skip?
138
141
 
139
- debug_loc = "#{frame.vm_location.describe} #{frame.line}" if
140
- @settings[:debugskip]
142
+ if @settings[:'debugskip']
143
+ puts "diff: #{@different_pos}, event : #{@event}, #{@stop_events.inspect}"
144
+ puts "step_count : #{@step_count}"
145
+ puts "next_level : #{@next_level}, ssize : #{@stack_size}"
146
+ puts "next_thread : #{@next_thread}, thread: #{Thread.current}"
147
+ end
148
+
149
+ return true if
150
+ !frame || (@next_level < @stack_size &&
151
+ Thread.current == @next_thread && @event != 'raise')
141
152
 
142
153
  if @step_count < 0
143
154
  # We may eventually stop for some other reason, but it's not
@@ -1,7 +1,8 @@
1
1
  require 'rubygems'; require 'require_relative'
2
2
  require_relative '../app/iseq'
3
+ require_relative 'virtual'
3
4
  class Trepan
4
- class CmdProcessor
5
+ class CmdProcessor < VirtualCmdProcessor
5
6
 
6
7
  def stepping_initialize
7
8
  @step_brkpts = []
data/processor/subcmd.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  # gdb-like subcommand processing.
3
3
 
4
+ ### FIXME: move into command/base/submgr.rb
4
5
  class Trepan
5
6
  class Subcmd
6
7
 
@@ -14,17 +15,24 @@ class Trepan
14
15
 
15
16
  # Find subcmd in self.subcmds
16
17
  def lookup(subcmd_prefix, use_regexp=true)
17
- compare = if use_regexp
18
- lambda{|name| name.to_s =~ /^#{subcmd_prefix}/}
19
- else
20
- lambda{|name| 0 == name.to_s.index(subcmd_prefix)}
21
- end
18
+ compare =
19
+ if !@cmd.settings[:abbrev]
20
+ lambda{|name| name.to_s == subcmd_prefix}
21
+ elsif use_regexp
22
+ lambda{|name| name.to_s =~ /^#{subcmd_prefix}/}
23
+ else
24
+ lambda{|name| 0 == name.to_s.index(subcmd_prefix)}
25
+ end
26
+ candidates = []
22
27
  @subcmds.each do |subcmd_name, subcmd|
23
28
  if compare.call(subcmd_name) &&
24
29
  subcmd_prefix.size >= subcmd.class.const_get(:MIN_ABBREV)
25
- return subcmd
30
+ candidates << subcmd
26
31
  end
27
32
  end
33
+ if candidates.size == 1
34
+ return candidates.first
35
+ end
28
36
  return nil
29
37
  end
30
38
 
@@ -55,53 +63,20 @@ class Trepan
55
63
  # so we might not want to show that.
56
64
  def add(subcmd_cb, subcmd_name=nil)
57
65
  subcmd_name ||= subcmd_cb.name
58
- @subcmds[subcmd_name.to_s] = subcmd_cb
66
+ @subcmds[subcmd_name] = subcmd_cb
59
67
 
60
68
  # We keep a list of subcommands to assist command completion
61
69
  @cmdlist << subcmd_name
62
70
  end
63
71
 
64
- # Run subcmd_name with args using obj for the environent
65
- def run( subcmd_name, arg)
66
- entry=lookup(subcmd_name)
67
- if entry
68
- entry['callback'].send(arg)
69
- else
70
- @proc.undefined_cmd(entry.__class__.name, subcmd_name)
71
- end
72
- end
73
-
74
72
  # help for subcommands
75
73
  # Note: format of help is compatible with ddd.
76
74
  def help(*args)
77
-
78
- msg args
79
- subcmd_prefix = args[0]
80
- if not subcmd_prefix or subcmd_prefix.size == 0
81
- @proc.msg(self.doc)
82
- @proc.msg("\nList of %s subcommands:\n" % [@name])
83
- @list.each do |subcmd_name|
84
- subcmd_helper(subcmd_name, obj, true, true)
85
- end
86
-
87
- entry = lookup(subcmd_prefix)
88
- if entry and entry.respond_to? :help
89
- entry.help(args)
90
- else
91
- @proc.errmsg("Unknown 'help %s' subcommand %s" %
92
- [@name, subcmd_prefix])
93
- end
94
- end
75
+ # Not used but tested for.
95
76
  end
96
77
 
97
78
  def list
98
- @subcmds.keys.sort
99
- end
100
-
101
- # Error message when a subcommand doesn't exist.
102
- def undefined_subcmd(cmd, subcmd)
103
- @proc.errmsg('Undefined "%s" command: "%s". Try "help".' %
104
- [cmd, subcmd])
79
+ @subcmds.keys.map{|k| k.to_s}.sort
105
80
  end
106
81
  end
107
82
  end
@@ -111,7 +86,7 @@ if __FILE__ == $0
111
86
 
112
87
  require 'rubygems'; require 'require_relative'
113
88
  require_relative 'mock'
114
- require_relative 'command/base/cmd'
89
+ require_relative 'command'
115
90
 
116
91
  class Trepan::TestCommand < Trepan::Command
117
92
 
@@ -9,29 +9,34 @@ require 'linecache'
9
9
 
10
10
  require_relative '../app/cmd_parse'
11
11
  require_relative '../app/condition'
12
+ require_relative '../app/file'
12
13
  require_relative '../app/method'
13
14
  require_relative '../app/validate'
14
15
 
15
16
  require_relative 'location' # for resolve_file_with_dir
16
17
  require_relative 'msg' # for errmsg, msg
18
+ require_relative 'virtual'
17
19
 
18
20
  class Trepan
19
- class CmdProcessor
21
+ class CmdProcessor < Trepan::VirtualCmdProcessor
20
22
 
21
23
  attr_reader :dbgr_script_iseqs
22
24
  attr_reader :dbgr_iseqs
23
-
25
+ attr_reader :file_exists_proc # Like File.exists? but checks using
26
+ # cached files
27
+
24
28
  include Trepanning::Method
29
+ include Trepanning::FileName
25
30
  include Trepan::Validate
26
31
  ## include Trepan::ThreadHelper
27
32
  include Trepan::Condition
28
-
33
+
29
34
  def confirm(msg, default)
30
35
  @settings[:confirm] ? @dbgr.intf[-1].confirm(msg, default) : true
31
36
  end
32
-
33
- # Like cmdfns.get_an_int(), but if there's a stack frame use that
34
- # in evaluation.
37
+
38
+ # Check that arg is an Integer between opts[:min_value] and
39
+ # opts[:max_value]
35
40
  def get_an_int(arg, opts={})
36
41
  ret_value = get_int_noerr(arg)
37
42
  if !ret_value
@@ -53,12 +58,12 @@ class Trepan
53
58
  end
54
59
  return ret_value
55
60
  end
56
-
61
+
57
62
  unless defined?(DEFAULT_GET_INT_OPTS)
58
63
  DEFAULT_GET_INT_OPTS = {
59
64
  :min_value => 0, :default => 1, :cmdname => nil, :max_value => nil}
60
65
  end
61
-
66
+
62
67
  # If argument parameter 'arg' is not given, then use what is in
63
68
  # opts[:default]. If String 'arg' evaluates to an integer between
64
69
  # least min_value and at_most, use that. Otherwise report an
@@ -103,7 +108,7 @@ class Trepan
103
108
  end
104
109
  return val
105
110
  end
106
-
111
+
107
112
  def get_int_list(args, opts={})
108
113
  args.map{|arg| get_an_int(arg, opts)}.compact
109
114
  end
@@ -118,7 +123,7 @@ class Trepan
118
123
  rescue
119
124
  nil
120
125
  end
121
-
126
+
122
127
  def get_thread_from_string(id_or_num_str)
123
128
  if id_or_num_str == '.'
124
129
  Thread.current
@@ -133,20 +138,21 @@ class Trepan
133
138
  end
134
139
  end
135
140
  end
136
-
141
+
137
142
  def position_to_line_and_offset(cm, filename, position, offset_type)
138
143
  case offset_type
139
144
  when :line
140
145
  vm_offset = cm.first_ip_on_line(position, -2)
141
146
  line_no = position
142
147
  when :offset
148
+ position = position.position unless position.kind_of?(Fixnum)
143
149
  line_no = cm.line_from_ip(position)
144
150
  vm_offset = position
145
151
  when nil
146
152
  vm_offset, line_no =
147
153
  if cm.lines[0] == -1
148
- [cm.lines[2], cm.lines.size > 3 ? cm.lines[3] : cm.lines[1]]
149
- else
154
+ [cm.lines[0], cm.lines.size > 3 ? cm.lines[3] : cm.lines[1]]
155
+ else
150
156
  [cm.lines[0], cm.lines[1]]
151
157
  end
152
158
  else
@@ -155,7 +161,7 @@ class Trepan
155
161
  end
156
162
  return [line_no, vm_offset]
157
163
  end
158
-
164
+
159
165
  # Parse a breakpoint position. On success return:
160
166
  # - the CompileMethod the position is in
161
167
  # - the line number - a Fixnum
@@ -185,7 +191,7 @@ class Trepan
185
191
  errmsg("Unable to get breakpoint position for #{position_str}")
186
192
  return [nil] * 5
187
193
  end
188
-
194
+
189
195
  # Return true if arg is 'on' or 1 and false arg is 'off' or 0.
190
196
  # Any other value is raises TypeError.
191
197
  def get_onoff(arg, default=nil, print_error=true)
@@ -201,14 +207,14 @@ class Trepan
201
207
  darg = arg.downcase
202
208
  return true if arg == '1' || darg == 'on'
203
209
  return false if arg == '0' || darg =='off'
204
-
210
+
205
211
  errmsg("Expecting 'on', 1, 'off', or 0. Got: %s." % arg.to_s) if
206
212
  print_error
207
213
  raise TypeError
208
214
  end
209
-
210
- include CmdParser
211
-
215
+
216
+ include Trepan::CmdParser
217
+
212
218
  def get_method(meth)
213
219
  start_binding =
214
220
  begin
@@ -227,14 +233,14 @@ class Trepan
227
233
  end
228
234
  end
229
235
  end
230
-
236
+
231
237
  # FIXME: this is a ? method but we return
232
238
  # the method value.
233
239
  def method?(meth)
234
240
  get_method(meth)
235
241
  end
236
-
237
- # parse_position(self, arg)->(meth, filename, offset, offset_type)
242
+
243
+ # parse_position(self)->(meth, filename, offset, offset_type)
238
244
  # See app/cmd_parser.kpeg for the syntax of a position which
239
245
  # should include things like:
240
246
  # Parse arg as [filename:]lineno | function | module
@@ -258,9 +264,10 @@ class Trepan
258
264
  filename = canonic_file(info.container)
259
265
  cm =
260
266
  if canonic_file(@frame.file) == filename
261
- cm = @frame.method
262
267
  if :line == info.position_type
263
- find_method_with_line(cm, info.position)
268
+ find_method_with_line(@frame.method, info.position)
269
+ else
270
+ @frame.method
264
271
  end
265
272
  else
266
273
  LineCache.compiled_method(filename)
@@ -286,7 +293,7 @@ class Trepan
286
293
  return [nil] * 4
287
294
  end
288
295
  end
289
-
296
+
290
297
  def parse_method(meth_str)
291
298
  begin
292
299
  meth_for_string(meth_str, @frame.binding)
@@ -296,17 +303,24 @@ class Trepan
296
303
  nil
297
304
  end
298
305
  end
299
-
306
+
300
307
  def validate_initialize
301
308
  ## top_srcdir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
302
309
  ## @dbgr_script_iseqs, @dbgr_iseqs = filter_scripts(top_srcdir)
310
+ @file_exists_proc = Proc.new {|filename|
311
+ if LineCache.cached?(filename) || LineCache.cached_script?(filename) ||
312
+ (File.readable?(filename) && !File.directory?(filename))
313
+ true
314
+ else
315
+ find_load_path(filename)
316
+ end
317
+ }
303
318
  end
304
319
  end
305
320
  end
306
321
 
307
322
  if __FILE__ == $0
308
323
  # Demo it.
309
- # FIXME have to pull in main for its initalize routine
310
324
  DIRNAME = File.dirname(__FILE__)
311
325
  load File.join(DIRNAME, 'main.rb')
312
326
 
@@ -319,9 +333,6 @@ if __FILE__ == $0
319
333
  puts "get_int_noerr(#{val}) = #{cmdproc.get_int_noerr(val).inspect}"
320
334
  end
321
335
  def foo; 5 end
322
- def cmdproc.errmsg(msg)
323
- puts msg
324
- end
325
336
 
326
337
  pos = cmdproc.parse_position('../../rubies/rbx-head/bin/irb')
327
338
  puts pos.inspect