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
@@ -1,46 +1,59 @@
1
1
  # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
3
  require_relative '../app/iseq'
4
+ require_relative 'virtual'
4
5
 
5
- class Trepan
6
- class CmdProcessor
6
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
7
7
 
8
- def show_bytecode(line=@frame.vm_location.line)
9
- meth = @frame.method
8
+ def show_bytecode(line=@frame.vm_location.line, ip=@frame.next_ip)
9
+ meth = @frame.method
10
+ if 0 == line
11
+ start, fin = Trepan::ISeq::ip_ranges_for_ip(@frame.method.lines, ip)[0]
12
+ else
10
13
  start = meth.first_ip_on_line(line)
11
- fin = meth.first_ip_on_line(line+1)
12
-
13
- if !fin || fin == -1
14
- fin = meth.iseq.size
15
- end
16
-
17
- start += 1 if start == -1
18
- section "Bytecode between #{start} and #{fin-1} for line #{line}"
19
-
20
- iseq_decoder = Rubinius::InstructionDecoder.new(meth.iseq)
21
- partial = iseq_decoder.decode_between(start, fin)
22
-
23
- ip = start
24
-
25
- prefixes = []
26
- disasm = partial.inject('') do |result, ins|
27
- inst = Rubinius::CompiledMethod::Instruction.new(ins, meth, ip)
28
- prefixes << ISeq::disasm_prefix(ip, frame.next_ip, meth)
29
- ip += ins.size
30
- result += "#{inst}\n"
14
+ unless start
15
+ errmsg "Can't find bytecode for line #{line}"
16
+ return
31
17
  end
32
-
33
- # FIXME DRY with command/disassemble.rb
34
- if @settings[:highlight]
35
- require_relative '../app/rbx-llvm'
36
- @llvm_highlighter = CodeRay::Duo[:llvm, :term]
37
- # llvm_scanner = CodeRay.scanner :llvm
38
- # p llvm_scanner.tokenize(disasm)
39
- disasm = @llvm_highlighter.encode(disasm)
40
- end
41
- disasm.split("\n").each_with_index do |inst, i|
42
- msg "#{prefixes[i]} #{inst}", :unlimited => true
18
+ fin = meth.first_ip_on_line(line+1)
19
+ end
20
+
21
+ if !fin || fin == -1
22
+ fin = meth.iseq.size
23
+ end
24
+
25
+ start += 1 if start == -1
26
+ suffix =
27
+ if 0 == line
28
+ "tail code before line #{Trepan::ISeq::tail_code_line(meth, ip)}"
29
+ else
30
+ "line #{line}"
43
31
  end
32
+ section "Bytecode between #{start} and #{fin-1} for line #{suffix}"
33
+
34
+ iseq_decoder = Rubinius::InstructionDecoder.new(meth.iseq)
35
+ partial = iseq_decoder.decode_between(start, fin)
36
+
37
+ ip = start
38
+
39
+ prefixes = []
40
+ disasm = partial.inject('') do |result, ins|
41
+ inst = Rubinius::CompiledMethod::Instruction.new(ins, meth, ip)
42
+ prefixes << Trepan::ISeq::disasm_prefix(ip, frame.next_ip, meth)
43
+ ip += ins.size
44
+ result += "#{inst}\n"
45
+ end
46
+
47
+ # FIXME DRY with command/disassemble.rb
48
+ if @settings[:highlight]
49
+ require_relative '../app/rbx-llvm'
50
+ @llvm_highlighter = CodeRay::Duo[:llvm, :term]
51
+ # llvm_scanner = CodeRay.scanner :llvm
52
+ # p llvm_scanner.tokenize(disasm)
53
+ disasm = @llvm_highlighter.encode(disasm)
54
+ end
55
+ disasm.split("\n").each_with_index do |inst, i|
56
+ msg "#{prefixes[i]} #{inst}", :unlimited => true
44
57
  end
45
58
  end
46
59
  end
data/processor/display.rb CHANGED
@@ -1,14 +1,49 @@
1
1
  # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
2
  require 'rubygems'; require 'require_relative'
3
3
  require_relative '../app/display'
4
+ require_relative 'virtual'
4
5
  class Trepan
5
- class CmdProcessor
6
+ class CmdProcessor < VirtualCmdProcessor
6
7
  attr_reader :displays
7
-
8
+
8
9
  def display_initialize
9
10
  @displays = DisplayMgr.new
10
11
  end
11
-
12
+
13
+ def display_find(num, show_errmsg = true)
14
+ if 0 == @displays.size
15
+ errmsg('No display expressions set.') if show_errmsg
16
+ return nil
17
+ elsif num > @displays.max || num < 1
18
+ errmsg('Display number %d is out of range 1..%d' %
19
+ [num, @displays.max]) if show_errmsg
20
+ return nil
21
+ end
22
+ disp = @displays[num]
23
+ if disp
24
+ return disp
25
+ else
26
+ errmsg('Display number %d previously deleted.' %
27
+ num) if show_errmsg
28
+ return nil
29
+ end
30
+ end
31
+
32
+ # Enable or disable a breakpoint given its breakpoint number.
33
+ def en_disable_display_by_number(num, do_enable=true)
34
+ disp = display_find(num)
35
+ return false unless disp
36
+
37
+ enable_disable = do_enable ? 'en' : 'dis'
38
+ if disp.enabled? == do_enable
39
+ errmsg('Display %d previously %sabled.' %
40
+ [num, enable_disable])
41
+ return false
42
+ end
43
+ disp.enabled = do_enable
44
+ return true
45
+ end
46
+
12
47
  def run_eval_display(args={})
13
48
  for line in @displays.display(@frame) do
14
49
  msg(line)
data/processor/eval.rb CHANGED
@@ -1,66 +1,67 @@
1
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
- class Trepan
3
- class CmdProcessor
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'
3
+ require 'require_relative'
4
+ require_relative 'virtual'
5
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
4
6
 
5
- def debug_eval(str, max_fake_filename=15)
6
- begin
7
- debug_eval_with_exception(str, max_fake_filename)
8
- rescue SyntaxError, StandardError, ScriptError => e
9
- exception_dump(e, @settings[:stack_trace_on_error], $!.backtrace)
10
- nil
11
- end
12
- end
13
-
14
- def debug_eval_with_exception(str, max_fake_filename=15)
15
- @frame.run(str, fake_eval_filename(str, max_fake_filename))
7
+ def debug_eval(str, max_fake_filename=15)
8
+ begin
9
+ debug_eval_with_exception(str, max_fake_filename)
10
+ rescue SyntaxError, StandardError, ScriptError => e
11
+ exception_dump(e, @settings[:stack_trace_on_error], $!.backtrace)
12
+ nil
16
13
  end
17
-
18
- def debug_eval_no_errmsg(str, max_fake_filename=15)
19
- begin
20
- debug_eval_with_exception(str, max_fake_filename)
21
- rescue SyntaxError, StandardError, ScriptError => e
22
- nil
23
- end
14
+ end
15
+
16
+ def debug_eval_with_exception(str, max_fake_filename=15)
17
+ @frame.run(str, fake_eval_filename(str, max_fake_filename))
18
+ end
19
+
20
+ def debug_eval_no_errmsg(str, max_fake_filename=15)
21
+ begin
22
+ debug_eval_with_exception(str, max_fake_filename)
23
+ rescue SyntaxError, StandardError, ScriptError => e
24
+ nil
24
25
  end
25
-
26
- def eval_code(str, max_fake_filename)
27
- obj = debug_eval(str, max_fake_filename)
28
-
29
- idx = @user_variables
30
- @user_variables += 1
31
-
32
- str = "$d#{idx}"
33
- Rubinius::Globals[str.to_sym] = obj
34
- msg "#{str} = #{obj.inspect}"
35
- obj
26
+ end
27
+
28
+ def eval_code(str, max_fake_filename)
29
+ obj = debug_eval(str, max_fake_filename)
30
+
31
+ idx = @user_variables
32
+ @user_variables += 1
33
+
34
+ str = "$d#{idx}"
35
+ Rubinius::Globals[str.to_sym] = obj
36
+ msg "#{str} = #{obj.inspect}"
37
+ obj
38
+ end
39
+
40
+ def exception_dump(e, stack_trace, backtrace)
41
+ str = "#{e.class} Exception:\n\t#{e.message}"
42
+ if stack_trace
43
+ str += "\n" + backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
36
44
  end
37
-
38
- def exception_dump(e, stack_trace, backtrace)
39
- str = "#{e.class} Exception:\n\t#{e.message}"
40
- if stack_trace
41
- str += "\n" + backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
45
+ msg str
46
+ # throw :debug_error
47
+ end
48
+
49
+ def fake_eval_filename(str, maxlen = 15)
50
+ fake_filename =
51
+ if maxlen < str.size
52
+ # FIXME: Guard against \" in positions 13..15?
53
+ str.inspect[0..maxlen-1] + '"...'
54
+ else
55
+ str.inspect
42
56
  end
43
- msg str
44
- # throw :debug_error
45
- end
46
-
47
- def fake_eval_filename(str, maxlen = 15)
48
- fake_filename =
49
- if maxlen < str.size
50
- # FIXME: Guard against \" in positions 13..15?
51
- str.inspect[0..maxlen-1] + '"...'
52
- else
53
- str.inspect
54
- end
55
- "(eval #{fake_filename})"
56
- end
57
-
57
+ "(eval #{fake_filename})"
58
58
  end
59
+
59
60
  end
60
61
 
61
62
  if __FILE__ == $0
62
63
  # Demo it.
63
- cmdp = Trepan::CmdProcessor.new
64
+ cmdp = Trepan::CmdProcessor.new([])
64
65
  puts cmdp.fake_eval_filename('x = 1; y = 2')
65
66
  puts cmdp.fake_eval_filename('x = 1; y = 2', 7)
66
67
  def cmdp.errmsg(msg)
@@ -5,86 +5,86 @@
5
5
  require 'rubygems'; require 'require_relative'
6
6
  require 'linecache'
7
7
  require_relative '../app/eventbuffer'
8
+ require_relative 'virtual'
8
9
 
9
- class Trepan
10
- class CmdProcessor
10
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
11
11
 
12
- attr_reader :eventbuf
13
- attr_reader :event_tracefilter
14
-
15
- def eventbuf_initialize(size=100)
16
- @eventbuf = Trace::EventBuffer.new(size)
17
- # @event_tracefilter = Trace::Filter.new
18
- end
19
-
20
- # def event_processor(event, frame, arg=nil)
21
- # @eventbuf.append(event, frame, arg)
22
- # end
23
-
24
- # Print event buffer entries from FROM up to TO try to stay within
25
- # WIDTH. We show source lines only the first time they are
26
- # encountered. Also we use separators to indicate points that the
27
- # debugger has stopped at.
28
- def eventbuf_print(from=nil, to=nil, width=80)
29
- sep = '-' * ((width - 7) / 2)
30
- last_container, last_location = nil, nil
31
- if from == nil || !@eventbuf.marks[-1]
32
- mark_index = 0
33
- else
34
- mark_index = @eventbuf.marks.size-1
35
- translated_from = @eventbuf.zero_pos + from
36
- @eventbuf.marks.each_with_index do
37
- |m, i|
38
- if m > translated_from
39
- mark_index = [0, i-1].max
40
- break
41
- elsif m == translated_from
42
- mark_index = i
43
- break
44
- end
12
+ attr_reader :eventbuf
13
+ attr_reader :event_tracefilter
14
+
15
+ def eventbuf_initialize(size=100)
16
+ @eventbuf = Trace::EventBuffer.new(size)
17
+ # @event_tracefilter = Trace::Filter.new
18
+ end
19
+
20
+ # def event_processor(event, frame, arg=nil)
21
+ # @eventbuf.append(event, frame, arg)
22
+ # end
23
+
24
+ # Print event buffer entries from FROM up to TO try to stay within
25
+ # WIDTH. We show source lines only the first time they are
26
+ # encountered. Also we use separators to indicate points that the
27
+ # debugger has stopped at.
28
+ def eventbuf_print(from=nil, to=nil, width=80)
29
+ sep = '-' * ((width - 7) / 2)
30
+ last_container, last_location = nil, nil
31
+ if from == nil || !@eventbuf.marks[-1]
32
+ mark_index = 0
33
+ else
34
+ mark_index = @eventbuf.marks.size-1
35
+ translated_from = @eventbuf.zero_pos + from
36
+ @eventbuf.marks.each_with_index do
37
+ |m, i|
38
+ if m > translated_from
39
+ mark_index = [0, i-1].max
40
+ break
41
+ elsif m == translated_from
42
+ mark_index = i
43
+ break
45
44
  end
46
45
  end
47
-
48
- nextmark = @eventbuf.marks[mark_index]
49
- @eventbuf.each_with_index(from, to) do |e, i|
50
- if nextmark
51
- if nextmark == i
52
- msg "#{sep} %5d #{sep}" % (mark_index - @eventbuf.marks.size)
53
- mark_index += 1 if mark_index < @eventbuf.marks.size - 1
54
- nextmark = @eventbuf.marks[mark_index]
55
- elsif nextmark < i
56
- mark_index += 1 if mark_index < @eventbuf.marks.size - 1
57
- nextmark = @eventbuf.marks[mark_index]
58
- end
46
+ end
47
+
48
+ nextmark = @eventbuf.marks[mark_index]
49
+ @eventbuf.each_with_index(from, to) do |e, i|
50
+ if nextmark
51
+ if nextmark == i
52
+ msg "#{sep} %5d #{sep}" % (mark_index - @eventbuf.marks.size)
53
+ mark_index += 1 if mark_index < @eventbuf.marks.size - 1
54
+ nextmark = @eventbuf.marks[mark_index]
55
+ elsif nextmark < i
56
+ mark_index += 1 if mark_index < @eventbuf.marks.size - 1
57
+ nextmark = @eventbuf.marks[mark_index]
59
58
  end
60
- last_container, last_location, mess =
61
- format_eventbuf_entry(e, last_container, last_location) if e
62
- msg mess
63
59
  end
60
+ last_container, last_location, mess =
61
+ format_eventbuf_entry(e, last_container, last_location) if e
62
+ msg mess
64
63
  end
65
-
66
- # Show event buffer entry. If the location is the same as the previous
67
- # location we don't show the duplicated location information.
68
- def format_eventbuf_entry(item, last_container, last_location)
69
- mess = format_location(item.event, item.frame, 0)
70
- return nil, nil, mess
71
- end
72
-
73
- # FIXME: multiple hook mechanism needs work.
74
- # def start_capture
75
- # @event_tracefilter.add_trace_func(method(:event_processor).to_proc,
76
- # Trace::DEFAULT_EVENT_MASK)
77
- # end
78
-
79
- # def stop_capture
80
- # @event_tracefilter.set_trace_func(nil)
81
- # end
82
-
83
64
  end
65
+
66
+ # Show event buffer entry. If the location is the same as the previous
67
+ # location we don't show the duplicated location information.
68
+ def format_eventbuf_entry(item, last_container, last_location)
69
+ mess = format_location(item.event, item.frame, 0)
70
+ return nil, nil, mess
71
+ end
72
+
73
+ # FIXME: multiple hook mechanism needs work.
74
+ # def start_capture
75
+ # @event_tracefilter.add_trace_func(method(:event_processor).to_proc,
76
+ # Trace::DEFAULT_EVENT_MASK)
77
+ # end
78
+
79
+ # def stop_capture
80
+ # @event_tracefilter.set_trace_func(nil)
81
+ # end
82
+
84
83
  end
84
+
85
85
  if __FILE__ == $0
86
86
  # Demo it.
87
- cmdproc = Trepan::CmdProcessor.new
87
+ cmdproc = Trepan::CmdProcessor.new([])
88
88
  cmdproc.eventbuf_initialize(5)
89
89
 
90
90
  def cmdproc.msg(mess)
data/processor/frame.rb CHANGED
@@ -3,209 +3,208 @@ require 'rubygems'; require 'require_relative'
3
3
  require_relative '../app/complete'
4
4
  require_relative '../app/frame'
5
5
  require_relative '../app/util'
6
- class Trepan
7
- class CmdProcessor
8
-
9
- include Util
10
- attr_reader :current_thread
11
-
12
- # ThreadFrame, current frame
13
- attr_accessor :frame
14
-
15
- # frame index in a "backtrace" command
16
- attr_accessor :frame_index
17
- attr_reader :hide_level
18
-
19
- # Hash[thread_id] -> FixNum, the level of the last frame to
20
- # show. If we called the debugger directly, then there is
21
- # generally a portion of a backtrace we don't want to show. We
22
- # don't need to store this for all threads, just those we want to
23
- # hide frame on. A value of 1 means to hide just the oldest
24
- # level. The default or showing all levels is 0.
25
- attr_accessor :hidelevels
26
-
27
- # Hash[container] -> file container. This gives us a way to map non-file
28
- # container objects to a file container for display.
29
- attr_accessor :remap_container
6
+ require_relative 'virtual'
7
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
8
+
9
+ include Trepan::Util
10
+ attr_reader :current_thread
11
+
12
+ # ThreadFrame, current frame
13
+ attr_accessor :frame
14
+
15
+ # frame index in a "backtrace" command
16
+ attr_accessor :frame_index
17
+ attr_reader :hide_level
18
+
19
+ # Hash[thread_id] -> FixNum, the level of the last frame to
20
+ # show. If we called the debugger directly, then there is
21
+ # generally a portion of a backtrace we don't want to show. We
22
+ # don't need to store this for all threads, just those we want to
23
+ # hide frame on. A value of 1 means to hide just the oldest
24
+ # level. The default or showing all levels is 0.
25
+ attr_accessor :hidelevels
26
+
27
+ # Hash[container] -> file container. This gives us a way to map non-file
28
+ # container objects to a file container for display.
29
+ attr_accessor :remap_container
30
+
31
+ attr_accessor :stack_size
32
+
33
+ # top frame of current thread.
34
+ attr_accessor :top_frame
35
+ # attr_reader :threads2frames # Hash[thread_id] -> top_frame
30
36
 
31
- attr_accessor :stack_size
32
-
33
- # top frame of current thread.
34
- attr_accessor :top_frame
35
- # attr_reader :threads2frames # Hash[thread_id] -> top_frame
36
-
37
-
38
- def adjust_frame(frame_num, absolute_pos)
39
- frame, frame_num = get_frame(frame_num, absolute_pos)
40
- if frame
41
- @frame = @dbgr.frame(frame_num)
42
- @frame_index = frame_num
43
- print_location unless @settings[:traceprint]
44
- @line_no = @frame.line
45
- @frame
46
- else
47
- nil
48
- end
49
- end
50
37
 
51
- def frame_low_high(direction)
52
- if direction
53
- low, high = [ @frame_index * -direction,
54
- (@stack_size - 1 - @frame_index) * direction ]
55
- low, high = [high, low] if direction < 0
56
- [low, high]
57
- else
58
- [-@stack_size, @stack_size-1]
38
+ def adjust_frame(frame_num, absolute_pos)
39
+ frame, frame_num = get_frame(frame_num, absolute_pos)
40
+ if frame
41
+ @frame = @dbgr.frame(frame_num)
42
+ @frame_index = frame_num
43
+ unless @settings[:traceprint]
44
+ msg "--> #%d %s" % [frame_num,
45
+ @frame.describe(:show_ip => false,
46
+ :basename =>settings[:basename])]
47
+ print_location
59
48
  end
49
+ @line_no = @frame.line
50
+ @frame
51
+ else
52
+ nil
60
53
  end
61
-
62
- def frame_complete(prefix, direction)
63
- low, high = frame_low_high(direction)
64
- ary = (low..high).map{|i| i.to_s}
65
- Trepan::Complete.complete_token(ary, prefix)
54
+ end
55
+
56
+ def frame_low_high(direction)
57
+ if direction
58
+ low, high = [ @frame_index * -direction,
59
+ (@stack_size - 1 - @frame_index) * direction ]
60
+ low, high = [high, low] if direction < 0
61
+ [low, high]
62
+ else
63
+ [-@stack_size, @stack_size-1]
66
64
  end
67
-
68
- # def frame_container(frame, canonicalize=true)
69
- # container =
70
- # if @remap_container.member?(frame.source_container)
71
- # @remap_container[frame.source_container]
72
- # elsif frame.iseq && @remap_iseq.member?(frame.iseq.sha1)
73
- # @remap_iseq[frame.iseq.sha1]
74
- # else
75
- # frame.source_container
76
- # end
77
-
78
- # container[1] = canonic_file(container[1]) if canonicalize
79
- # container
80
- # end
81
-
82
- # Initializes the thread and frame variables: @frame, @top_frame,
83
- # @frame_index, @current_thread, and @threads2frames
84
- def frame_setup
85
- @frame_index = 0
86
- @frame = @top_frame = @dbgr.current_frame
87
- @current_thread = @dbgr.debugee_thread
88
- @line_no = @frame.line
89
-
90
- @threads2frames ||= {}
91
- @threads2frames[@current_thread] = @top_frame
92
- set_hide_level
65
+ end
66
+
67
+ def frame_complete(prefix, direction)
68
+ low, high = frame_low_high(direction)
69
+ ary = (low..high).map{|i| i.to_s}
70
+ Trepan::Complete.complete_token(ary, prefix)
71
+ end
72
+
73
+ # def frame_container(frame, canonicalize=true)
74
+ # container =
75
+ # if @remap_container.member?(frame.source_container)
76
+ # @remap_container[frame.source_container]
77
+ # elsif frame.iseq && @remap_iseq.member?(frame.iseq.sha1)
78
+ # @remap_iseq[frame.iseq.sha1]
79
+ # else
80
+ # frame.source_container
81
+ # end
82
+
83
+ # container[1] = canonic_file(container[1]) if canonicalize
84
+ # container
85
+ # end
86
+
87
+ # Initializes the thread and frame variables: @frame, @top_frame,
88
+ # @frame_index, @current_thread, and @threads2frames
89
+ def frame_setup
90
+ @frame_index = 0
91
+ @frame = @top_frame = @dbgr.current_frame
92
+ @current_thread = @dbgr.debugee_thread
93
+ @line_no = @frame.line
94
+
95
+ @threads2frames ||= {}
96
+ @threads2frames[@current_thread] = @top_frame
97
+ set_hide_level
98
+ end
99
+
100
+ # Remove access to thread and frame variables
101
+ def frame_teardown
102
+ @top_frame = @frame = @frame_index = @current_thread = nil
103
+ @threads2frames = {}
104
+ end
105
+
106
+ def frame_initialize
107
+ @remap_container = {}
108
+ @remap_iseq = {}
109
+ @hidelevels = Hash.new(nil)
110
+ @hide_level = 0
111
+ end
112
+
113
+ def get_frame(frame_num, absolute_pos)
114
+ if absolute_pos
115
+ frame_num += @stack_size if frame_num < 0
116
+ else
117
+ frame_num += @frame_index
93
118
  end
94
-
95
- # Remove access to thread and frame variables
96
- def frame_teardown
97
- @top_frame = @frame = @frame_index = @current_thread = nil
98
- @threads2frames = {}
119
+
120
+ if frame_num < 0
121
+ errmsg('Adjusting would put us beyond the newest frame.')
122
+ return [nil, nil]
123
+ elsif frame_num >= @stack_size
124
+ errmsg('Adjusting would put us beyond the oldest frame.')
125
+ return [nil, nil]
99
126
  end
100
-
101
- def frame_initialize
102
- @remap_container = {}
103
- @remap_iseq = {}
104
- @hidelevels = Hash.new(nil)
105
- @hide_level = 0
127
+
128
+ [frame, frame_num]
129
+ end
130
+
131
+ def parent_frame
132
+ frame = @dbgr.frame(@frame.number + 1)
133
+ unless frame
134
+ errmsg "Unable to find parent frame at level #{@frame.number+1}"
135
+ return nil
106
136
  end
107
-
108
- def get_frame(frame_num, absolute_pos)
109
- if absolute_pos
110
- frame_num += @stack_size if frame_num < 0
137
+ frame
138
+ end
139
+
140
+ def set_hide_level
141
+ max_stack_size = @dbgr.vm_locations.size
142
+ @hide_level =
143
+ if !@settings[:hidelevel] || @settings[:hidelevel] < 0
144
+ @settings[:hidelevel] = @hidelevels[@current_thread] =
145
+ find_main_script(@dbgr.vm_locations) || max_stack_size
111
146
  else
112
- frame_num += @frame_index
113
- end
114
-
115
- if frame_num < 0
116
- errmsg('Adjusting would put us beyond the newest frame.')
117
- return [nil, nil]
118
- elsif frame_num >= @stack_size
119
- errmsg('Adjusting would put us beyond the oldest frame.')
120
- return [nil, nil]
147
+ @settings[:hidelevel]
121
148
  end
122
-
123
- [frame, frame_num]
124
- end
125
-
126
- def parent_frame
127
- frame = @dbgr.frame(@frame.number + 1)
128
- unless frame
129
- errmsg "Unable to find parent frame at level #{@frame.number+1}"
130
- return nil
131
- end
132
- frame
133
- end
134
-
135
- def set_hide_level
136
- @hide_level =
137
- if !@settings[:hidelevel] || @settings[:hidelevel] < 0
138
- @settings[:hidelevel] = @hidelevels[@current_thread] =
139
- find_main_script(@dbgr.vm_locations) || max_stack_size
140
- else
141
- @settings[:hidelevel]
142
- end
143
- max_stack_size = @dbgr.vm_locations.size
144
- @stack_size = if @hide_level >= max_stack_size
145
- max_stack_size else max_stack_size - @hide_level
146
- end
147
- end
148
-
149
- # def get_nonsync_frame(tf)
150
- # if (tf.stack_size > 10)
151
- # check_frames = (0..5).map{|i| tf.prev(i).method}
152
- # if check_frames ==
153
- # %w(synchronize event_processor IFUNC call trace_hook IFUNC)
154
- # return tf.prev(6)
155
- # end
156
- # end
157
- # tf
158
- # end
159
-
160
- # def get_frame_from_thread(th)
161
- # if th == Thread.current
162
- # @threads2frames[th]
163
- # else
164
- # # FIXME: Check to see if we are blocked on entry to debugger.
165
- # # If so, walk back frames.
166
- # tf = get_nonsync_frame(th.threadframe)
167
- # @threads2frames = tf
168
- # end
169
- # end
170
-
171
- # # The dance we have to do to set debugger frame state to
172
- # # `frame', which is in the thread with id `thread_id'. We may
173
- # # need to the hide initial debugger frames.
174
- # def find_and_set_debugged_frame(th, position)
175
-
176
- # thread = threading._active[thread_id]
177
- # thread_name = thread.getName()
178
- # if (!@settings['dbg_pydbgr'] &&
179
- # thread_name == Mthread.current_thread_name())
180
- # # The frame we came in on ('current_thread_name') is
181
- # # the same as the one we want to switch to. In this case
182
- # # we need to some debugger frames are in this stack so
183
- # # we need to remove them.
184
- # newframe = Mthread.find_debugged_frame(frame)
185
- # frame = newframe unless newframe
186
- # end
187
- # ## FIXME: else: we might be blocked on other threads which are
188
- # # about to go into the debugger it not for the fact this one got there
189
- # # first. Possibly in the future we want
190
- # # to hide the blocks into threading of that locking code as well.
191
-
192
- # # Set stack to new frame
193
- # @frame, @curindex = Mcmdproc.get_stack(frame, nil, self.proc)
194
- # @proc.stack, @proc.curindex = self.stack, self.curindex
195
-
196
- # # @frame_thread_name = thread_name
197
- # end
149
+ @stack_size = if @hide_level >= max_stack_size
150
+ max_stack_size else max_stack_size - @hide_level
151
+ end
198
152
  end
153
+
154
+ # def get_nonsync_frame(tf)
155
+ # if (tf.stack_size > 10)
156
+ # check_frames = (0..5).map{|i| tf.prev(i).method}
157
+ # if check_frames ==
158
+ # %w(synchronize event_processor IFUNC call trace_hook IFUNC)
159
+ # return tf.prev(6)
160
+ # end
161
+ # end
162
+ # tf
163
+ # end
164
+
165
+ # def get_frame_from_thread(th)
166
+ # if th == Thread.current
167
+ # @threads2frames[th]
168
+ # else
169
+ # # FIXME: Check to see if we are blocked on entry to debugger.
170
+ # # If so, walk back frames.
171
+ # tf = get_nonsync_frame(th.threadframe)
172
+ # @threads2frames = tf
173
+ # end
174
+ # end
175
+
176
+ # # The dance we have to do to set debugger frame state to
177
+ # # `frame', which is in the thread with id `thread_id'. We may
178
+ # # need to the hide initial debugger frames.
179
+ # def find_and_set_debugged_frame(th, position)
180
+
181
+ # thread = threading._active[thread_id]
182
+ # thread_name = thread.getName()
183
+ # if (!@settings['dbg_pydbgr'] &&
184
+ # thread_name == Mthread.current_thread_name())
185
+ # # The frame we came in on ('current_thread_name') is
186
+ # # the same as the one we want to switch to. In this case
187
+ # # we need to some debugger frames are in this stack so
188
+ # # we need to remove them.
189
+ # newframe = Mthread.find_debugged_frame(frame)
190
+ # frame = newframe unless newframe
191
+ # end
192
+ # ## FIXME: else: we might be blocked on other threads which are
193
+ # # about to go into the debugger it not for the fact this one got there
194
+ # # first. Possibly in the future we want
195
+ # # to hide the blocks into threading of that locking code as well.
196
+
197
+ # # Set stack to new frame
198
+ # @frame, @curindex = Mcmdproc.get_stack(frame, nil, self.proc)
199
+ # @proc.stack, @proc.curindex = self.stack, self.curindex
200
+
201
+ # # @frame_thread_name = thread_name
202
+ # end
199
203
  end
200
204
 
201
205
  if __FILE__ == $0
202
206
  # Demo it.
203
- require_relative 'main' # Have to include before defining CmdProcessor!
204
- # FIXME
205
207
  class Trepan::CmdProcessor
206
- def errmsg(msg)
207
- puts msg
208
- end
209
208
  def print_location
210
209
  puts "frame location: #{frame.file} #{frame.line}"
211
210
  end