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/io/tcpclient.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'socket'
6
6
  require 'rubygems'; require 'require_relative'
7
- require_relative 'base_io'
7
+ require_relative '../io'
8
8
  require_relative 'tcpfns'
9
9
 
10
10
  class Trepan
data/io/tcpserver.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  require 'socket'
6
6
  require 'rubygems'; require 'require_relative'
7
7
  require_relative '../app/default' # For host and port
8
- require_relative 'base_io'
8
+ require_relative '../io'
9
9
  require_relative 'tcpfns'
10
10
 
11
11
  class Trepan
data/lib/trepanning.rb CHANGED
@@ -8,7 +8,7 @@ require 'rubygems'; require 'require_relative'
8
8
  require_relative '../app/complete' # command completion
9
9
  require_relative '../app/frame'
10
10
  require_relative '../app/util' # get_dollar_0
11
- require_relative '../processor/main'
11
+ require_relative '../processor'
12
12
  require_relative '../app/breakpoint'
13
13
  require_relative '../app/default' # default debugger settings
14
14
  require_relative '../app/breakpoint'
@@ -50,7 +50,8 @@ class Trepan
50
50
  @input = @settings[:input] || STDIN
51
51
  @output = @settings[:output] || STDOUT
52
52
 
53
- cmdproc_settings = {:highlight => @settings[:highlight]}
53
+ cmdproc_settings = {:highlight => @settings[:highlight],
54
+ :traceprint => @settings[:traceprint]}
54
55
 
55
56
  @processor = CmdProcessor.new(self, cmdproc_settings)
56
57
  @completion_proc = method(:completion_method)
@@ -73,7 +74,7 @@ class Trepan
73
74
  opts[:host] = @settings[:host] if @settings[:host]
74
75
  opts[:complete] = @completion_proc
75
76
  opts[:readline] ||= @settings[:readline]
76
- [Trepan::ClientInterface.new(nil, nil, nil, nil, opts)]
77
+ [Trepan::ClientInterface.new(nil, nil, nil, {}, opts)]
77
78
  else
78
79
  opts = {:complete => @completion_proc,
79
80
  :readline => @settings[:readline]}
@@ -159,7 +160,7 @@ class Trepan
159
160
  'step', 'set hidelevel -1'
160
161
  ]
161
162
  else
162
- ['next', 'next',
163
+ ['next', 'next', 'next',
163
164
  # 'set kernelstep off', # eventually would like 'on'
164
165
  'set hidelevel -1',
165
166
  'step', ]
@@ -204,15 +205,10 @@ class Trepan
204
205
  @processor.hidelevels[@thread] = @settings[:hide_level]
205
206
  end
206
207
 
207
- # unless defined?(PROG_UNRESOLVED_SCRIPT)
208
- # # We may later do more sophisticated things...
209
- # Trepan.const_set('PROG_UNRESOLVED_SCRIPT',
210
- # Rubinius::OS_ARGV.index($0) ? $0 : nil)
211
- # end
212
-
213
208
  process_cmdfile_setting(settings)
214
209
 
215
- # Feed info to the debugger thread!
210
+ # Feed info (breakpoint, debugged program thread, channel and backtrace
211
+ # info) to the debugger thread
216
212
  locs = Rubinius::VM.backtrace(@settings[:offset] + 1, true)
217
213
 
218
214
  method = Rubinius::CompiledMethod.of_sender
@@ -226,6 +222,8 @@ class Trepan
226
222
  # wait for the debugger to release us
227
223
  channel.receive
228
224
 
225
+ # Now that there is a debugger on the other end, set the debugged
226
+ # program thread to call us when it hits a breakpoint.
229
227
  Thread.current.set_debugger_thread @thread
230
228
  self
231
229
  end
@@ -233,7 +231,7 @@ class Trepan
233
231
 
234
232
  def stop(settings = {})
235
233
  @processor.finalize
236
- Rubinius::VM.debug_channel = nil
234
+ # Rubinius::VM.debug_channel = nil
237
235
  end
238
236
 
239
237
  def add_command_file(cmdfile, opts={}, stderr=$stderr)
@@ -301,7 +299,7 @@ class Trepan
301
299
  status = @breakpoint.hit!(@vm_locations.first.variables)
302
300
  if status
303
301
  break
304
- elsif status.nil?
302
+ elsif @breakpoint.enabled? && status.nil?
305
303
  # A permanent breakpoint. Check the condition.
306
304
  break if @breakpoint.condition?(@current_frame.binding)
307
305
  end
@@ -10,12 +10,12 @@ require 'rubygems'; require 'require_relative'
10
10
  %w(default breakpoint disassemble display eval eventbuf load_cmds location
11
11
  frame hook msg running stepping validate).each do
12
12
  |mod_str|
13
- require_relative mod_str
13
+ require_relative "processor/#{mod_str}"
14
14
  end
15
- ## require_relative '../app/brkptmgr'
15
+ require_relative 'app/brkptmgr'
16
16
 
17
17
  class Trepan
18
- class CmdProcessor
18
+ class CmdProcessor < VirtualCmdProcessor
19
19
 
20
20
  # SEE ALSO attr's in require_relative's of loop above.
21
21
 
@@ -42,6 +42,9 @@ class Trepan
42
42
  # the command loop (which often continues to
43
43
  # run the debugged program).
44
44
  attr_accessor :line_no # Last line shown in "list" command
45
+ attr_accessor :next_level # Fixnum. frame.stack_size has to
46
+ # be <= than this. If next'ing,
47
+ # this will be > 0.
45
48
  attr_accessor :next_thread # Thread. If non-nil then in
46
49
  # stepping the thread has to be
47
50
  # this thread.
@@ -58,34 +61,6 @@ class Trepan
58
61
  # current_thread, pc_offset]
59
62
 
60
63
 
61
- unless defined?(EVENT2ICON)
62
- # Event icons used in printing locations.
63
- EVENT2ICON = {
64
- 'brkpt' => 'xx',
65
- 'tbrkpt' => 'x1',
66
- 'c-call' => 'C>',
67
- 'c-return' => '<C',
68
- 'step-call' => '->',
69
- 'call' => '->',
70
- 'class' => '::',
71
- 'coverage' => '[]',
72
- 'debugger-call' => ':o',
73
- 'end' => '-|',
74
- 'line' => '--',
75
- 'raise' => '!!',
76
- 'return' => '<-',
77
- 'start' => '>>',
78
- 'switch' => 'sw',
79
- 'trace-var' => '$V',
80
- 'unknown' => '?!',
81
- 'vm' => 'VM',
82
- 'vm-insn' => '..',
83
- }
84
- # These events are important enough event that we always want to
85
- # stop on them.
86
- UNMASKABLE_EVENTS = Set.new(['end', 'raise', 'unknown'])
87
- end
88
-
89
64
  def initialize(dbgr, settings={})
90
65
  @cmd_queue = []
91
66
  @dbgr = dbgr
@@ -93,6 +68,7 @@ class Trepan
93
68
  @hidelevels = {}
94
69
  @last_command = nil
95
70
  @last_pos = [nil, nil, nil, nil, nil, nil]
71
+ @next_level = 32000
96
72
  @next_thread = nil
97
73
  @user_variables = 0
98
74
 
@@ -121,6 +97,8 @@ class Trepan
121
97
  self.send("#{submod}_initialize")
122
98
  end
123
99
  hook_initialize(commands)
100
+ # unconditional_prehooks.insert_if_new(-1, *@trace_hook) if
101
+ # settings[:traceprint]
124
102
  end
125
103
 
126
104
  def compute_prompt
@@ -184,11 +162,7 @@ class Trepan
184
162
  @cmd_queue.shift
185
163
  end
186
164
  if @current_command.empty?
187
- if @last_command && intf.interactive?
188
- @current_command = @last_command
189
- else
190
- next
191
- end
165
+ next unless @last_command && intf.interactive?;
192
166
  end
193
167
  next if @current_command[0..0] == '#' # Skip comment lines
194
168
  break
@@ -200,7 +174,6 @@ class Trepan
200
174
  @last_command = nil
201
175
  print_location
202
176
  else
203
- msg "That's all folks..."
204
177
  ## FIXME: think of something better.
205
178
  quit('exit!')
206
179
  return true
@@ -228,14 +201,18 @@ class Trepan
228
201
  if breakpoint?
229
202
  delete_breakpoint(@brkpt) if @brkpt.temp?
230
203
  @last_pos = [@frame.vm_location, @stack_size, @current_thread, @event]
231
- else
232
- if stepping_skip? # || @stack_size <= @hide_level
204
+ end
205
+
206
+ if stepping_skip? # || @stack_size <= @hide_level
207
+ if @next_thread
208
+ self.next(@step_count, :next_level => @next_level)
209
+ else
233
210
  step(@return_to_program, @step_count, {}, @stop_condition)
234
- return true
235
- elsif @event == 'start'
236
- step('step', 0)
237
- return true
238
211
  end
212
+ return true
213
+ elsif @event == 'start'
214
+ step('step', 0)
215
+ return true
239
216
  end
240
217
 
241
218
  @prompt = compute_prompt
@@ -259,14 +236,18 @@ class Trepan
259
236
  skip_command = before_cmdloop
260
237
  while not @leave_cmd_loop do
261
238
  begin
262
- if !skip_command
263
- break if process_command_and_quit?()
264
- end
239
+ # if settings[:traceprint]
240
+ # @return_to_program = 'step'
241
+ # else
242
+ if !skip_command
243
+ break if process_command_and_quit?()
244
+ end
245
+ # end
265
246
  if @return_to_program
266
247
  after_cmdloop
267
248
  if @step_count >= 0 && 'finish' != @return_to_program
268
249
  @step_bp = step_over_by(1)
269
- run_command('disassemble') if settings[:debugstep]
250
+ run_command('disassemble all') if settings[:debugstep]
270
251
  dbgr.listen('step' == @return_to_program)
271
252
  else
272
253
  @step_bp = nil
@@ -278,7 +259,12 @@ class Trepan
278
259
  @dbgr.stop
279
260
  raise
280
261
  rescue Exception => exc
281
- errmsg("Internal debugger error: #{exc.inspect}")
262
+ # If we are inside the script interface errmsg may fail.
263
+ begin
264
+ errmsg("Internal debugger error: #{exc.inspect}")
265
+ rescue IOError
266
+ $stderr.puts "Internal debugger error: #{exc.inspect}"
267
+ end
282
268
  exception_dump(exc, @settings[:debugexcept], $!.backtrace)
283
269
  end
284
270
  end
@@ -330,7 +316,10 @@ class Trepan
330
316
  else
331
317
  @cmd_name
332
318
  end
333
-
319
+
320
+ run_cmd_name = uniq_abbrev(@commands.keys, run_cmd_name) if
321
+ !@commands.member?(run_cmd_name) && @settings[:abbrev]
322
+
334
323
  if @commands.member?(run_cmd_name)
335
324
  cmd = @commands[run_cmd_name]
336
325
  if ok_for_running(cmd, run_cmd_name, args.size-1)
@@ -345,16 +334,23 @@ class Trepan
345
334
  # Eval anything that's not a command or has been
346
335
  # requested to be eval'd
347
336
  if settings[:autoeval] || eval_command
348
- eval_code(current_command, @settings[:maxstring])
349
- else
350
- undefined_command(cmd_name)
337
+ begin
338
+ eval_code(current_command, @settings[:maxstring])
339
+ return false
340
+ rescue NameError
341
+ end
351
342
  end
343
+ undefined_command(cmd_name)
352
344
  return false
353
345
  end
354
346
 
355
347
  # Error message when a command doesn't exist
356
348
  def undefined_command(cmd_name)
357
- errmsg('Undefined command: "%s". Try "help".' % cmd_name)
349
+ begin
350
+ errmsg('Undefined command: "%s". Try "help".' % cmd_name)
351
+ rescue
352
+ $stderr.puts 'Undefined command: "%s". Try "help".' % cmd_name
353
+ end
358
354
  end
359
355
 
360
356
  # FIXME: Allow access to both Trepan::CmdProcessor and Trepan
@@ -368,7 +364,7 @@ end
368
364
 
369
365
  if __FILE__ == $0
370
366
  $0 = 'foo' # So we don't get here again
371
- require_relative '../lib/trepanning'
367
+ require_relative 'lib/trepanning'
372
368
  dbg = Trepan.new(:nx => true)
373
369
  cmdproc = dbg.instance_variable_get('@processor')
374
370
  cmdproc.msg('I am main')
@@ -1,154 +1,167 @@
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 'virtual'
3
4
  require_relative '../app/brkptmgr'
4
- class Trepan
5
-
6
- class CmdProcessor
7
-
8
- attr_reader :brkpts # BreakpointManager.
9
-
10
- attr_reader :brkpt # Breakpoint. If we are stopped at a
11
- # breakpoint this is the one we
12
- # found. (There may be other
13
- # breakpoints that would have caused a stop
14
- # as well; this is just one of them).
15
- # If no breakpoint stop this is nil.
16
-
17
- def breakpoint_initialize
18
- @brkpts = BreakpointMgr.new
19
- @brkpt = nil
5
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
6
+
7
+ attr_reader :brkpts # BreakpointManager.
8
+
9
+ attr_reader :brkpt # Breakpoint. If we are stopped at a
10
+ # breakpoint this is the one we
11
+ # found. (There may be other
12
+ # breakpoints that would have caused a stop
13
+ # as well; this is just one of them).
14
+ # If no breakpoint stop this is nil.
15
+
16
+ def breakpoint_initialize
17
+ @brkpts = Trepan::BreakpointMgr.new
18
+ @brkpt = nil
19
+ end
20
+
21
+ def breakpoint_finalize
22
+ @brkpts.finalize
23
+ end
24
+
25
+ def breakpoint?
26
+ @brkpt = @dbgr.breakpoint
27
+ return !!@brkpt && %w(tbrkpt brkpt).member?(@brkpt.event)
28
+ end
29
+
30
+ def breakpoint_find(bpnum, show_errmsg = true)
31
+ if 0 == @brkpts.size
32
+ errmsg('No breakpoints set.') if show_errmsg
33
+ return nil
34
+ elsif bpnum > brkpts.size || bpnum < 1
35
+ errmsg('Breakpoint number %d is out of range 1..%d' %
36
+ [bpnum, brkpts.size]) if show_errmsg
37
+ return nil
20
38
  end
21
-
22
- def breakpoint_finalize
23
- @brkpts.finalize
39
+ bp = @brkpts[bpnum]
40
+ unless bp
41
+ errmsg "Unknown breakpoint '#{bpnum}'" if show_errmsg
42
+ return nil
24
43
  end
25
-
26
- def breakpoint?
27
- @brkpt = @dbgr.breakpoint
28
- return !!@brkpt && %w(tbrkpt brkpt).member?(@brkpt.event)
29
- end
30
-
31
- def breakpoint_find(bpnum, show_errmsg = true)
32
- if 0 == @brkpts.size
33
- errmsg('No breakpoints set.') if show_errmsg
34
- return nil
35
- elsif bpnum > brkpts.size || bpnum < 1
36
- errmsg('Breakpoint number %d is out of range 1..%d' %
37
- [bpnum, brkpts.size]) if show_errmsg
38
- return nil
39
- end
40
- bp = @brkpts[bpnum]
41
- unless bp
42
- errmsg "Unknown breakpoint '#{bpnum}'" if show_errmsg
43
- return nil
44
+ bp
45
+ end
46
+
47
+ def set_breakpoint_method(meth, line=nil, ip=nil,
48
+ opts={:event => 'brkpt', :negate=>false,
49
+ :temp => false})
50
+ cm =
51
+ if meth.kind_of?(Method) || meth.kind_of?(UnboundMethod)
52
+ meth.executable
53
+ else
54
+ meth
44
55
  end
45
- bp
56
+
57
+ unless cm.kind_of?(Rubinius::CompiledMethod)
58
+ errmsg "Unsupported method type: #{cm.class}"
59
+ return nil
46
60
  end
47
61
 
48
- def set_breakpoint_method(meth, line=nil, ip=nil,
49
- opts={:event => 'brkpt', :negate=>false,
50
- :temp => false})
51
- cm =
52
- if meth.kind_of?(Method) || meth.kind_of?(UnboundMethod)
53
- meth.executable
54
- else
55
- meth
56
- end
57
-
58
- unless cm.kind_of?(Rubinius::CompiledMethod)
59
- errmsg "Unsupported method type: #{cm.class}"
62
+ if line && line > 0
63
+ ip = cm.first_ip_on_line(line, -2) unless ip
64
+
65
+ unless ip
66
+ errmsg "Unknown line '#{line}' in method '#{cm.name}'"
60
67
  return nil
61
68
  end
62
-
63
- if line
64
- ip = cm.first_ip_on_line(line, -2)
65
-
66
- unless ip
67
- errmsg "Unknown line '#{line}' in method '#{cm.name}'"
68
- return nil
69
- end
70
- elsif !ip
71
- line = cm.first_line
72
- ip = 0
73
- end
74
-
75
- # def lines without code will have value -1.
76
- ip = 0 if -1 == ip
77
-
78
- bp = @brkpts.add(meth.name, cm, ip, line, @brkpts.max+1, opts)
79
- bp.activate
80
- msg("Set %sbreakpoint #{bp.id}: #{meth.name}() at #{bp.location}" %
81
- (opts[:temp] ? 'temporary ' : ''))
82
- return bp
83
- end
84
-
85
- # MRI 1.9.2 code
86
- # def breakpoint_find(bpnum, show_errmsg = true)
87
- # if 0 == @brkpts.size
88
- # errmsg('No breakpoints set.') if show_errmsg
89
- # return nil
90
- # elsif bpnum > @brkpts.max || bpnum < 1
91
- # errmsg('Breakpoint number %d is out of range 1..%d' %
92
- # [bpnum, @brkpts.max]) if show_errmsg
93
- # return nil
94
- # end
95
- # bp = @brkpts[bpnum]
96
- # if bp
97
- # return bp
98
- # else
99
- # errmsg('Breakpoint number %d previously deleted.' %
100
- # bpnum) if show_errmsg
101
- # return nil
102
- # end
103
- # end
104
-
105
- # # Does whatever needs to be done to set a breakpoint
106
- # def breakpoint_line(line_number, iseq, temp=false)
107
- # # FIXME: handle breakpoint conditions.
108
- # iseq = iseq.child_iseqs.detect do |iseq|
109
- # iseq.lineoffsets.keys.member?(line_number)
110
- # end
111
- # offset =
112
- # if iseq
113
- # # FIXME
114
- # iseq.line2offsets(line_number)[1] || iseq.line2offsets(line_number)[0]
115
- # else
116
- # nil
117
- # end
118
- # unless offset
119
- # place = "in #{iseq.source_container.join(' ')} " if iseq
120
- # errmsg("No line #{line_number} found #{place}for breakpoint.")
121
- # return nil
122
- # end
123
- # @brkpts.add(iseq, offset, :temp => temp)
124
- # end
125
-
126
- # def breakpoint_offset(offset, iseq, temp=false)
127
- # # FIXME: handle breakpoint conditions.
128
- # unless iseq.offsetlines.keys.member?(offset)
129
- # errmsg("Offset #{offset} not found in #{iseq.name} for breakpoint.")
130
- # return nil
131
- # end
132
- # @brkpts.add(iseq, offset, :temp => temp, :type => 'offset')
133
- # end
134
-
135
- # Delete a breakpoint given its breakpoint number.
136
- # FIXME: use do_enable
137
- def delete_breakpoint_by_number(bpnum, do_enable=true)
138
- bp = breakpoint_find(bpnum)
139
- return false unless bp
140
- delete_breakpoint(bp)
69
+ elsif !ip
70
+ line = cm.first_line
71
+ ip = 0
141
72
  end
142
-
143
- def delete_breakpoint(bp)
144
- @brkpts.delete_by_brkpt(bp)
145
- return true
73
+
74
+ # def lines without code will have value -1.
75
+ ip = 0 if -1 == ip
76
+
77
+ bp = @brkpts.add(meth.name, cm, ip, line, @brkpts.max+1, opts)
78
+ bp.activate
79
+ msg("Set %sbreakpoint #{bp.id}: #{meth.name}() at #{bp.location}" %
80
+ (opts[:temp] ? 'temporary ' : ''))
81
+ return bp
82
+ end
83
+
84
+ # MRI 1.9.2 code
85
+ # def breakpoint_find(bpnum, show_errmsg = true)
86
+ # if 0 == @brkpts.size
87
+ # errmsg('No breakpoints set.') if show_errmsg
88
+ # return nil
89
+ # elsif bpnum > @brkpts.max || bpnum < 1
90
+ # errmsg('Breakpoint number %d is out of range 1..%d' %
91
+ # [bpnum, @brkpts.max]) if show_errmsg
92
+ # return nil
93
+ # end
94
+ # bp = @brkpts[bpnum]
95
+ # if bp
96
+ # return bp
97
+ # else
98
+ # errmsg('Breakpoint number %d previously deleted.' %
99
+ # bpnum) if show_errmsg
100
+ # return nil
101
+ # end
102
+ # end
103
+
104
+ # # Does whatever needs to be done to set a breakpoint
105
+ # def breakpoint_line(line_number, iseq, temp=false)
106
+ # # FIXME: handle breakpoint conditions.
107
+ # iseq = iseq.child_iseqs.detect do |iseq|
108
+ # iseq.lineoffsets.keys.member?(line_number)
109
+ # end
110
+ # offset =
111
+ # if iseq
112
+ # # FIXME
113
+ # iseq.line2offsets(line_number)[1] || iseq.line2offsets(line_number)[0]
114
+ # else
115
+ # nil
116
+ # end
117
+ # unless offset
118
+ # place = "in #{iseq.source_container.join(' ')} " if iseq
119
+ # errmsg("No line #{line_number} found #{place}for breakpoint.")
120
+ # return nil
121
+ # end
122
+ # @brkpts.add(iseq, offset, :temp => temp)
123
+ # end
124
+
125
+ # def breakpoint_offset(offset, iseq, temp=false)
126
+ # # FIXME: handle breakpoint conditions.
127
+ # unless iseq.offsetlines.keys.member?(offset)
128
+ # errmsg("Offset #{offset} not found in #{iseq.name} for breakpoint.")
129
+ # return nil
130
+ # end
131
+ # @brkpts.add(iseq, offset, :temp => temp, :type => 'offset')
132
+ # end
133
+
134
+ # Delete a breakpoint given its breakpoint number.
135
+ # FIXME: use do_enable
136
+ def delete_breakpoint_by_number(bpnum, do_enable=true)
137
+ bp = breakpoint_find(bpnum)
138
+ return false unless bp
139
+ delete_breakpoint(bp)
140
+ end
141
+
142
+ # Enable or disable a breakpoint given its breakpoint number.
143
+ def en_disable_breakpoint_by_number(bpnum, do_enable=true)
144
+ bp = breakpoint_find(bpnum)
145
+ return false unless bp
146
+
147
+ enable_disable = do_enable ? 'en' : 'dis'
148
+ if bp.enabled? == do_enable
149
+ errmsg('Breakpoint %d previously %sabled.' %
150
+ [bpnum, enable_disable])
151
+ return false
146
152
  end
147
-
153
+ bp.enabled = do_enable
154
+ return true
155
+ end
156
+
157
+ def delete_breakpoint(bp)
158
+ @brkpts.delete_by_brkpt(bp)
159
+ return true
148
160
  end
161
+
149
162
  end
150
163
 
151
164
  if __FILE__ == $0
152
- cmdproc = Trepan::CmdProcessor.new
165
+ cmdproc = Trepan::CmdProcessor.new([])
153
166
  cmdproc.breakpoint_initialize
154
167
  end