trepanning 1.93.35 → 2.15.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +491 -55
  3. data/LICENSE +1 -1
  4. data/NEWS +18 -14
  5. data/README.md +5 -22
  6. data/Rakefile +22 -1
  7. data/app/breakpoint.rb +5 -3
  8. data/app/core.rb +147 -179
  9. data/app/default.rb +47 -46
  10. data/app/file.rb +6 -7
  11. data/app/frame.rb +183 -176
  12. data/app/markdown.rb +2 -9
  13. data/app/options.rb +1 -1
  14. data/app/run.rb +71 -37
  15. data/interface/script.rb +8 -8
  16. data/io.rb +19 -20
  17. data/lib/trepanning.rb +292 -297
  18. data/processor.rb +332 -344
  19. data/processor/breakpoint.rb +98 -96
  20. data/processor/command/base/submgr.rb +9 -9
  21. data/processor/command/break.rb +40 -38
  22. data/processor/command/continue.rb +15 -10
  23. data/processor/command/debug.rb +6 -25
  24. data/processor/command/delete.rb +21 -12
  25. data/processor/command/directory.rb +15 -13
  26. data/processor/command/disable.rb +12 -9
  27. data/processor/command/disassemble.rb +80 -74
  28. data/processor/command/display.rb +15 -12
  29. data/processor/command/down.rb +8 -3
  30. data/processor/command/edit.rb +37 -23
  31. data/processor/command/enable.rb +11 -8
  32. data/processor/command/eval.rb +24 -22
  33. data/processor/command/finish.rb +50 -48
  34. data/processor/command/help.rb +1 -1
  35. data/processor/command/info_subcmd/breakpoints.rb +7 -7
  36. data/processor/command/info_subcmd/files.rb +195 -196
  37. data/processor/command/info_subcmd/frame.rb +7 -4
  38. data/processor/command/info_subcmd/locals.rb +29 -12
  39. data/processor/command/info_subcmd/program.rb +48 -39
  40. data/processor/command/info_subcmd/registers_subcmd/ep.rb +46 -0
  41. data/processor/command/info_subcmd/registers_subcmd/helper.rb +32 -35
  42. data/processor/command/info_subcmd/registers_subcmd/sp.rb +29 -23
  43. data/processor/command/info_subcmd/return.rb +28 -10
  44. data/processor/command/info_subcmd/variables_subcmd/class.rb +3 -3
  45. data/processor/command/info_subcmd/variables_subcmd/constants.rb +77 -0
  46. data/processor/command/info_subcmd/variables_subcmd/globals.rb +7 -7
  47. data/processor/command/info_subcmd/variables_subcmd/instance.rb +68 -22
  48. data/processor/command/info_subcmd/variables_subcmd/locals.rb +148 -67
  49. data/processor/command/list.rb +14 -8
  50. data/processor/command/macro.rb +1 -1
  51. data/processor/command/next.rb +1 -0
  52. data/processor/command/set_subcmd/auto.rb +3 -3
  53. data/processor/command/set_subcmd/different.rb +30 -29
  54. data/processor/command/set_subcmd/events.rb +74 -48
  55. data/processor/command/set_subcmd/max_subcmd/list.rb +12 -5
  56. data/processor/command/set_subcmd/max_subcmd/width.rb +28 -19
  57. data/processor/command/set_subcmd/register.rb +37 -0
  58. data/processor/command/set_subcmd/register_subcmd/pc.rb +67 -0
  59. data/processor/command/set_subcmd/register_subcmd/sp.rb +75 -0
  60. data/processor/command/set_subcmd/reload.rb +12 -10
  61. data/processor/command/set_subcmd/return.rb +68 -44
  62. data/processor/command/shell.rb +3 -2
  63. data/processor/command/show_subcmd/different.rb +17 -14
  64. data/processor/command/show_subcmd/events.rb +25 -25
  65. data/processor/default.rb +1 -1
  66. data/processor/eval.rb +14 -15
  67. data/processor/frame.rb +43 -36
  68. data/processor/help.rb +5 -5
  69. data/processor/hook.rb +26 -29
  70. data/processor/location.rb +54 -51
  71. data/processor/mock.rb +4 -3
  72. data/processor/running.rb +113 -103
  73. data/processor/validate.rb +401 -373
  74. data/test/data/debug.cmd +8 -0
  75. data/test/data/debug.right +13 -0
  76. data/test/data/debugger-stop.right +6 -4
  77. data/test/data/fname-with-blank.cmd +1 -1
  78. data/test/data/fname-with-blank.right +5 -0
  79. data/test/data/pc.cmd +8 -0
  80. data/test/data/pc.right +10 -0
  81. data/test/data/quit.right +3 -1
  82. data/test/data/trace.cmd +2 -2
  83. data/test/data/trace.right +41 -20
  84. data/test/example/assign.rb +6 -0
  85. data/test/functional/fn_helper.rb +11 -17
  86. data/test/functional/test-break-long.rb +15 -16
  87. data/test/functional/test-break.rb +6 -8
  88. data/test/functional/test-condition.rb +8 -10
  89. data/test/functional/test-debugger-call-bug.rb +21 -22
  90. data/test/functional/test-delete.rb +57 -59
  91. data/test/functional/test-eval.rb +101 -103
  92. data/test/functional/test-finish.rb +24 -33
  93. data/test/functional/test-immediate-step-bug.rb +6 -10
  94. data/test/functional/test-next.rb +64 -65
  95. data/test/functional/test-raise.rb +63 -64
  96. data/test/functional/test-recursive-bt.rb +81 -76
  97. data/test/functional/test-remap.rb +6 -7
  98. data/test/functional/test-return.rb +44 -38
  99. data/test/functional/test-step.rb +55 -53
  100. data/test/functional/test-stepbug.rb +6 -9
  101. data/test/functional/test-watchg.rb +40 -39
  102. data/test/integration/test-debug.rb +12 -0
  103. data/test/integration/test-debugger-stop.rb +7 -7
  104. data/test/integration/test-pc.rb +24 -0
  105. data/test/integration/test-trace.rb +1 -1
  106. data/test/unit/cmd-helper.rb +0 -1
  107. data/test/unit/test-app-brkpt.rb +21 -21
  108. data/test/unit/test-app-brkptmgr.rb +7 -8
  109. data/test/unit/test-app-display.rb +3 -4
  110. data/test/unit/test-app-frame.rb +4 -5
  111. data/test/unit/test-base-subsubcmd.rb +2 -2
  112. data/test/unit/test-cmd-break.rb +6 -6
  113. data/test/unit/test-cmd-endisable.rb +7 -6
  114. data/test/unit/test-cmd-parse_list_cmd.rb +24 -24
  115. data/test/unit/test-io-tcpserver.rb +39 -35
  116. data/test/unit/test-proc-default.rb +23 -22
  117. data/test/unit/test-proc-eval.rb +1 -2
  118. data/test/unit/test-proc-frame.rb +8 -9
  119. data/test/unit/test-proc-list.rb +1 -1
  120. data/test/unit/test-proc-location.rb +2 -2
  121. data/test/unit/test-proc-main.rb +10 -10
  122. data/test/unit/test-proc-validate.rb +11 -13
  123. data/test/unit/test-subcmd-help.rb +1 -2
  124. data/trepanning.gemspec +8 -13
  125. metadata +44 -95
  126. data/COPYING +0 -57
  127. data/data/custom_require.rb +0 -44
  128. data/data/perldb.bindings +0 -17
  129. data/data/prelude.rb +0 -38
  130. data/processor/command/info_subcmd/variables_subcmd/constant.rb +0 -41
  131. data/processor/command/raise.rb +0 -48
  132. data/processor/command/set_subcmd/pc.rb +0 -62
  133. data/processor/command/set_subcmd/sp.rb +0 -67
  134. data/processor/eventbuf.rb +0 -133
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.org>
1
+ Copyright (C) 2010, 2015 Rocky Bernstein <rockyb@rubyforge.org>
2
2
  All rights reserved.
3
3
  *
4
4
  Redistribution and use in source and binary forms, with or without
data/NEWS CHANGED
@@ -1,22 +1,26 @@
1
- (1.93.40) Mar 12, 2015
2
- - remove stray space after backtick in markdown
3
- - list command continues where it last left off
4
- - empty debugger command repeats last command
5
- - Use markdown in Gem description
1
+ (2.15.33) Mar 8, 2015
6
2
 
7
- (1.93.32) Mar 8, 2015
8
- - Remove reference to threadframe
9
-
10
- (1.93.31) Mar 8, 2015
11
-
12
- - Remove threadframe dependency - it's built into patched Ruby
3
+ - Remove threadframe dependency - it's built into patched Ruby, replace with
4
+ rubyvm-frame.rb
13
5
  - add dependencies for coderay and ansi-termcolor
14
6
  - More subcommand help converted to markdown format.
15
7
 
16
- (1.93.30) Mar 5, 2015
17
- - Make it work on a patched Ruby 1.9.3 p551
18
- - include columnize and linecache-tf gems
8
+ (2.15.30) Mar 5, 2015
9
+ - Make it work on a patched Ruby 2.1.5 with runtime debugger support
10
+ This means:
11
+ * high-speed breakpoints, "step over" (next), and "step out" (finish)
12
+ * when stopped in a C function, we can get parameter values
13
+ * the source location of C functions is memory address (gdb can
14
+ use this)
15
+ * VM inspection, including sp, pc, instruction sequences,
16
+ and local table
17
+ * can change return values in Ruby code, often
18
+ * can see/set the runtime event masks debugger triggers on
19
+ * can get the eval string when stopped in an eval()
19
20
  - Help text is rendered via redcloth/markdown
21
+ - When we are in a raise event which is non-local, indicate that
22
+ - Remove aliases 'd' and 'u' for "down" and "up"; gdb has different meanings for
23
+ these letters
20
24
 
21
25
  (0.1.6) Nov 25, 2012
22
26
  - Make it work on Ruby 1.9.3 p327
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- The trepanning debugger gdb-like debugger. As such, it is both a high-level and low-level debugger. It is a also a rewrite of *ruby-debug*. But to provide all of the functionality that it has, it requires a patched version of MRI Ruby 1.9.3 or 1.9.2 found the [rb-threadframe project](https://rocky/rb-threadframe). The additional run-time support in the MRI is what gives this some debugger power that you won't find in other MRI 1.9 debuggers.
1
+ The trepanning debugger gdb-like debugger. As such, it is both a high-level and low-level debugger. It is a also a rewrite of *ruby-debug*. But to provide all of the functionality that it has, it requires a patched version of MRI Ruby 2.1.5, 1.9.3 or 1.9.2 found the [ruby-debugger-runtime project](https://sourceforge.net/projects/ruby-debugger-runtime/). The additional run-time support in the MRI is what gives this [powerful features](https://github.com/rocky/rb-trepanning/wiki/Cool-things) that you won't find in other MRI 2.1 or 1.9 debuggers that don't use this runtime.
2
2
 
3
3
  See the [installation instructions](https://github.com/rocky/rb-trepanning/wiki/How-to-Install-rb-trepanning).
4
4
 
@@ -36,27 +36,10 @@ The return value from Trepan is the return value of the block, i.e. the final va
36
36
  You can run the same thing inside your Ruby program, but probably you don't want to give a block. Instead, you may want to have debugging start on the next statement in the code:
37
37
 
38
38
  ```ruby
39
- require 'trepan'
40
- Trepan.debug # Don't stop here...
41
- work # but stop here.
39
+ require 'trepanning'
40
+ ...
41
+ debugger # stop here
42
42
  ```
43
43
 
44
- The above is really shorthand for something like:
45
44
 
46
- ```ruby
47
- $trepan = Trepan.new
48
- $trepan.debugger
49
- ```
50
-
51
- The global variable *$trepan* set holds debugger settings, such as `autolist` or `autoeval` settings and breakpoint information.
52
-
53
- Due to the line-event orientation in ruby-debug, it occasionally was convenient to add a synchronous stop in your program. I don't think that will be necessary here, but if you do call to the debugger at the point of the call rather than the subsequent stopping point, set opts[:immediate] to true. Example:
54
-
55
- ```ruby
56
-
57
- # ... work, work, work
58
- mydbg.debugger(:immediate=>true) # enter debugger here
59
- # ... work, work, work
60
- ```
61
-
62
- There is extensive on-line help. Run `help` inside the debugger.
45
+ There is extensive on-line help, much in markdown format that displays nicely in a terminal. Run `help` inside the debugger.
data/Rakefile CHANGED
@@ -1,12 +1,33 @@
1
1
  #!/usr/bin/env rake
2
2
  # -*- Ruby -*-
3
3
  require 'rubygems'
4
+ require 'rbconfig'
4
5
 
5
- ROOT_DIR = File.dirname(__FILE__)
6
6
  GEM_PROG = ENV['GEM_PROG'] || 'gem'
7
+ ROOT_DIR = File.dirname(__FILE__)
7
8
  Gemspec_filename='trepanning.gemspec'
8
9
  require_relative './app/options'
9
10
 
11
+ unless defined? RubyVM::Frame and RbConfig::CONFIG.member?('rb-threadframe')
12
+ raise RuntimeError,
13
+ 'This package is for MRI Ruby 2.1.5 with debugger runtime support!\nDownload from ' +
14
+ 'http://downloads.sourceforge.net/project/ruby-debugger-runtime/ruby-2.1/'
15
+ end
16
+
17
+ ruby_version = RbConfig::CONFIG['RUBY_PROGRAM_VERSION']
18
+ if ruby_version == '1.9.3'
19
+ raise RuntimeError,
20
+ "This is version trepanning #{Trepan::VERSION}. " +
21
+ "Ruby #{ruby_version} you want version 1.93..."
22
+ elsif ruby_version == '1.9.2'
23
+ raise RuntimeError,
24
+ "This is version trepanning #{Trepan::VERSION}. " +
25
+ "Ruby #{ruby_version} you want version 1.92..."
26
+ elsif ruby_version != '2.1.5'
27
+ raise RuntimeError,
28
+ "This package only works on version Ruby version 2.1.5. You have #{ruby_version}."
29
+ end
30
+
10
31
  def gemspec
11
32
  @gemspec ||= eval(File.read(Gemspec_filename), binding, Gemspec_filename)
12
33
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010-2011, 2013, 2015 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Copyright (C) 2010-2011, 2013,2015 Rocky Bernstein <rockyb@rubyforge.net>
3
3
 
4
4
  # Breakpoint objects
5
5
  class Trepan
@@ -11,7 +11,8 @@ class Trepan
11
11
  # we want to (also) record hits independent
12
12
  # of the condition?
13
13
  attr_reader :id # Fixnum. Name of breakpoint
14
- attr_reader :ignore # Fixnum. Number of times encountered to ignore
14
+ attr_reader :ignore # Fixnum. Number of times to ignore
15
+ # before triggering
15
16
  attr_reader :iseq # Instruction sequence associated with this
16
17
  # breakpoint. From this we can derive
17
18
  # information such as source location.
@@ -62,8 +63,9 @@ class Trepan
62
63
  @id = @@next_id
63
64
  @@next_id += 1
64
65
  end
66
+
65
67
  raise RuntimeError,
66
- "Unable to set breakpoint in #{iseq.name} at offset #{offset}" unless set
68
+ "Unable to set breakpoint in #{iseq.name} at offset #{@offset}" unless set
67
69
  end
68
70
 
69
71
  def condition?(bind)
@@ -1,203 +1,171 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
- require 'thread_frame'
4
- require 'trace'
5
- # require_relative '../../rb-trace/app/trace'
2
+ # Copyright (C) 2010, 2014-2015 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ require 'set'
6
5
  require_relative '../processor'
7
- class Trepan
8
- # This class contains the Trepan core routines, such as an event
9
- # processor which is responsible of handling what to do when an event is
10
- # triggered.
11
- #
12
- # See also 'rdbgr' the top-level Trepan class and command-line routine
13
- # which ultimately will call this.
14
-
15
- class Core
16
- attr_accessor :async_events # bitmask of asyncronous events - used all
17
- # the time
18
- attr_reader :dbgr # Trepan instance
19
- attr_reader :event # String - event which triggering event
20
- # processor
21
- attr_reader :event_proc # Proc of method event_processor
22
- attr_accessor :exception # Return exception to pass back. A 'raise'
23
- # command can set this.
24
- attr_reader :frame # ThreadFrame instance
25
- attr_reader :hook_arg # 'arg' passed from trace hook
26
- attr_accessor :mutex # mutex to lock out other threads from
27
- # entering debugger while we are in it.
28
- attr_accessor :processor # Trepan::CmdProc instance
29
- attr_reader :settings # Hash of things you can configure
30
- attr_accessor :step_count # Fixnum. Negative means no tracing,
31
- # 0 means stop on next event, 1 means
32
- # ignore one event. Step events gives the
33
- # kind of things to count as a step.
34
- attr_accessor :step_events # bitmask of events - used only when
35
- # we are stepping
36
- attr_accessor :unmaskable_events
37
-
38
- include Trace
39
-
40
- unless defined?(CORE_DEFAULT_SETTINGS)
41
- # Synchronous events
42
- STEPPING_EVENT_MASK =
43
- LINE_EVENT_MASK | CLASS_EVENT_MASK | CALL_EVENT_MASK |
44
- RETURN_EVENT_MASK | C_CALL_EVENT_MASK | C_RETURN_EVENT_MASK |
45
- INSN_EVENT_MASK | BRKPT_EVENT_MASK | YIELD_EVENT_MASK |
46
- LEAVE_EVENT_MASK | SEND_EVENT_MASK
47
-
48
- ASYNC_EVENT_MASK =
49
- RAISE_EVENT_MASK | VM_EVENT_MASK | SWITCH_EVENT_MASK
50
-
51
- CORE_DEFAULT_SETTINGS = {
52
- :cmdproc_opts => {},
53
- :debug_core_events => false,
54
- :hook_name => :event_processor, # or :old_event_processor
55
- :step_count => 0, # Stop at next event
56
- :async_events => ASYNC_EVENT_MASK,
57
-
58
- # Not sure what the "right" set really is. The below is just
59
- # a guess. Use "set events" or customize in ~/.trepanrc
60
- :step_events =>
61
- # (DEFAULT_EVENT_MASK | INSN_EVENT_MASK) &
62
- (DEFAULT_EVENT_MASK ) &
63
- ~(C_CALL_EVENT_MASK | C_RETURN_EVENT_MASK | SEND_EVENT_MASK)
64
- }
65
6
 
66
- end
7
+ class Trepan
8
+ # This class contains the Trepan core routines, such as an event
9
+ # processor which is responsible of handling what to do when an event is
10
+ # triggered.
11
+ #
12
+ # See also lib/trepanning.rb, the top-level Trepan class, and command-line routine
13
+ # bin/trepan which ultimately will call this.
14
+
15
+ class Core
16
+ attr_accessor :async_events # bitmask of asyncronous events - used all
17
+ # the time
18
+ attr_reader :dbgr # Trepan instance
19
+ attr_reader :event # String - event which triggering event
20
+ # processor
21
+ attr_reader :event_proc # Proc of method event_processor
22
+ attr_accessor :exception # Return exception to pass back. A 'raise'
23
+ # command can set this.
24
+ attr_reader :frame # ThreadFrame instance
25
+ attr_reader :hook_arg # 'arg' passed from trace hook
26
+ attr_accessor :mutex # mutex to lock out other threads from
27
+ # entering debugger while we are in it.
28
+ attr_accessor :processor # Trepan::CmdProc instance
29
+ attr_reader :settings # Hash of things you can configure
30
+ attr_accessor :step_count # Fixnum. Negative means no tracing,
31
+ # 0 means stop on next event, 1 means
32
+ # ignore one event. Step events gives the
33
+ # kind of things to count as a step.
34
+ attr_accessor :top_skip # Number of top frames to ignore
35
+ attr_accessor :step_events # bitmask of events - used only when
36
+ # we are stepping
37
+ attr_accessor :unmaskable_events
38
+ attr_reader :trace_point
39
+
40
+ unless defined?(CORE_DEFAULT_SETTINGS)
41
+ # Synchronous events
42
+ STEPPING_EVENTS = Set.new([:line, :class, :call, :return, :c_call,
43
+ :c_return, :raise, :b_call, :b_return,
44
+ :thread_begin, :thread_end, :brkpt])
45
+ ASYNC_EVENTS = Set.new([:raise])
46
+
47
+ CORE_DEFAULT_SETTINGS = {
48
+ :cmdproc_opts => {},
49
+ :debug_core_events => false,
50
+ :hook_name => :event_processor,
51
+ :step_count => 0, # Stop at next event
52
+ :async_events => ASYNC_EVENTS,
53
+
54
+ # Not sure what the "right" set really is. The below is just
55
+ # a guess. Use "set events" or customize in ~/.trepanrc
56
+ :step_events => STEPPING_EVENTS - [:c_call, :c_return]
57
+ }
67
58
 
68
- def initialize(debugger, settings={})
69
- @dbgr = debugger
70
- @exception = nil
71
- @mutex = Mutex.new
72
- @settings = CORE_DEFAULT_SETTINGS.merge(settings)
73
-
74
- @step_count = @settings[:step_count]
75
- @step_events = @settings[:step_events]
76
- @async_events = @settings[:async_events]
77
- @debug_events = @settings[:debug_core_events]
78
-
79
- hook_name = @settings[:hook_name]
80
- @event_proc = self.method(hook_name).to_proc
81
- @processor = CmdProcessor.new(self, @settings[:cmdproc_opts])
82
- @unmaskable_events = %w(brkpt raise switch vm)
83
- @current_thread = nil
84
- end
59
+ end
85
60
 
86
- def step_events_list
87
- if 0 == @step_events
88
- return nil
89
- else
90
- Trace.bitmask2events(@step_events).join(', ')
91
- end
92
- end
61
+ def initialize(debugger, settings={})
62
+ @dbgr = debugger
63
+ @exception = nil
64
+ @mutex = Mutex.new
65
+ @settings = CORE_DEFAULT_SETTINGS.merge(settings)
66
+
67
+ @step_count = @settings[:step_count]
68
+ @step_events = @settings[:step_events]
69
+ @async_events = @settings[:async_events]
70
+ @debug_events = @settings[:debug_core_events]
71
+
72
+ hook_name = @settings[:hook_name]
73
+ @event_proc = self.method(hook_name).to_proc
74
+ @processor = CmdProcessor.new(self, @settings[:cmdproc_opts])
75
+ @unmaskable_events = %w(brkpt raise switch vm)
76
+ @current_thread = nil
77
+ @top_skip = 0
78
+ @trace_point = nil
79
+ end
93
80
 
94
- # A trace-hook processor with the interface a trace hook should have.
95
- def event_processor(event, frame, arg=nil)
81
+ def step_events_list
82
+ if @trace_point
83
+ @trace_point.event_mask
84
+ else
85
+ nil
86
+ end
87
+ end
96
88
 
97
- return_exception = nil
98
- # FIXME: check for breakpoints or other unmaskable events.
99
- # For now there are none.
89
+ # A trace-hook processor for tracepoints
90
+ def event_processor_tp(tp)
91
+ ## FIXME: tracepoint has an arg param. Figure out how to use it.
92
+ @trace_point = tp
93
+ # RubyVM::Frame.get.frame.trace_off = true
94
+ # p @trace_point
95
+ # p @trace_point.event, @trace_point.frame.source_location
96
+ retval = event_processor(tp.frame, tp.event)
97
+ @trace_point = nil
98
+ return retval
99
+ end
100
100
 
101
- return if @mutex.locked? and Thread.current == @current_thread
101
+ # A trace-hook processor with the interface a trace hook should have.
102
+ def event_processor(frame, event, hook_arg=nil)
102
103
 
103
- @mutex.synchronize do
104
- @current_thread = Thread.current
105
- @frame = frame
106
- while @frame.type == 'IFUNC'
107
- @frame = @frame.prev
108
- end
104
+ return_exception = nil
105
+ # FIXME: check for breakpoints or other unmaskable events.
106
+ # For now there are none.
109
107
 
110
- if @step_count > 0
111
- @step_count -= 1
112
- break
113
- elsif @step_count < 0 && ! @unmaskable_events.member?(event)
114
- break
115
- end
108
+ return if @mutex.locked? and Thread.current == @current_thread
116
109
 
117
- @event = event
118
- @hook_arg = arg
119
-
120
- ### debug:
121
- ### puts "#{frame.file[1]}:#{frame.source_location[0]}:in `#{frame.method}' #{event}" # if %w(line).member?(event)
122
- @processor.process_commands(@frame)
123
-
124
- # FIXME: There should be a Trace.event_mask which should return the first
125
- # mask that matches the given trace hook.
126
- if @step_count < 0
127
- # If we are continuing, no need to stop at stepping events.
128
- Trace.event_masks[0] &= ~STEPPING_EVENT_MASK
129
- else
130
- # Set to trace only those events we are interested in.
131
-
132
- # Don't step/trace into Ruby routines called from here in the code
133
- # below (e.g. "trace_hooks").
134
- step_count_save = step_count
135
- @step_count = -1
136
-
137
- unless @event_proc == dbgr.trace_filter.hook_proc
138
- dbgr.trace_filter.add_trace_func(@event_proc)
139
- ## debug: p '+++1', @event_proc, dbgr.trace_filter.hook_proc
140
- end
141
-
142
- # FIXME: this doesn't work. Bug in rb-trace?
143
- # Trace.event_masks[0] = @step_events | @async_events
144
- RubyVM::TraceHook::trace_hooks[0].event_mask =
145
- @step_events | @async_events
146
- @step_count = step_count_save
147
- end
110
+ @mutex.synchronize do
111
+ @current_thread = Thread.current
112
+ @frame = frame
148
113
 
149
- # Nil out variables just in case...
114
+ if dbgr.trace_filter.member?(@frame.method)
115
+ # puts "Not tracing #{@frame.method}"
116
+ return
117
+ end
150
118
 
151
- return_exception = @exception
152
- @frame = @event = @arg = @exception = nil
119
+ if @step_count > 0
120
+ @step_count -= 1
121
+ break
122
+ elsif @step_count < 0 && ! @unmaskable_events.member?(event.to_s)
123
+ break
124
+ end
153
125
 
154
- end
155
- return return_exception
156
- end
126
+ @event = event
127
+ @hook_arg = hook_arg
157
128
 
158
- # A Ruby 1.8-style event processor. We don't use file, line, id, bind.
159
- def old_event_processor(event, file, line, id, bind, klass)
160
- event_processor(event, RubyVM::Frame.current.prev)
161
- end
129
+ ### debug:
130
+ ### puts "#{frame.file[1]}:#{frame.source_location[0]}:in `#{frame.method}' #{event}"
131
+ # if %w(line).member?(event)
132
+ @processor.process_commands(@frame, top_skip)
162
133
 
163
- # Call this from inside the program you want to get a synchronous
164
- # call to the debugger. set prev_count to the number of levels
165
- # *before* the caller you want to skip.
166
- def debugger(prev_count=0)
167
- while @frame && @frame.type == 'IFUNC'
168
- @frame = @frame.prev
169
- end
170
- frame = RubyVM::Frame.current.prev(prev_count+1)
171
- @step_count = 0 # Make event processor stop
172
- event_processor('debugger-call', frame)
173
- end
134
+ # Nil out variables just in case...
174
135
 
175
- # A trace-hook processor for 'trace var'
176
- def trace_var_processor(var_name, value)
177
- frame = RubyVM::Frame.current.prev(2)
178
- if 'CFUNC' == frame.type
179
- # Don't need the C call that got us here.
180
- prev = frame.prev
181
- frame = frame.prev if prev
182
- end
136
+ return_exception = @exception
137
+ @frame = @event = @arg = @exception = nil
138
+ @top_skip = 0
139
+ end
140
+ return return_exception
141
+ end
183
142
 
184
- # Stop future tracing into the debugger
185
- Thread.current.tracing = true
143
+ # A trace-hook processor for 'trace var'
144
+ def trace_var_processor(var_name, value)
145
+ frame = RubyVM::Frame.get
146
+ frame.trace_off = true
147
+ frame.prev.trace_off = true
148
+ # We need to skip this frame and the lamdba that in trace_var()
149
+ # and a C call() in that lambda. See command/watchg.rb
150
+ frame = RubyVM::Frame.get(3)
151
+
152
+ @step_count = 0 # Make event processor stop
153
+ event_processor(frame, 'trace-var', [var_name, value])
154
+ end
186
155
 
187
- @step_count = 0 # Make event processor stop
188
- event_processor('trace-var', frame, [var_name, value])
189
156
  end
190
-
191
- end
192
157
  end
193
158
  if __FILE__ == $0
194
- require_relative '../lib/trepanning'
195
- dbg = Trepan.new()
196
- if ARGV.size > 0
197
- def foo(dbg)
198
- p 'foo here'
199
- dbg.debugger(:immediate=>true)
159
+ require_relative '../lib/trepanning'
160
+ dbg = Trepan.new()
161
+ if ARGV.size > 0
162
+ def foo(dbg)
163
+ p 'foo here'
164
+ dbg.debugger
165
+ end
166
+ foo(dbg)
167
+ x = 5
168
+ y = File.basename("foo.rb", ".rb")
169
+ puts "yeah"
200
170
  end
201
- foo(dbg)
202
- end
203
171
  end