ruby-debug 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 0.5.3
2
+ - Added Module#post_mortem_method method, which wraps any method with Debugger.post_mortem block.
3
+ - Added breakpoint id, which is not dependent on the breakpoint position in Debugger.breakpoints array.
4
+
1
5
  0.5.2
2
6
  - Fixes interoperability problems with rspec.
3
7
  - Made 'exit' as an alias to 'quit'
data/ext/ruby_debug.c CHANGED
@@ -4,7 +4,7 @@
4
4
  #include <rubysig.h>
5
5
  #include <st.h>
6
6
 
7
- #define DEBUG_VERSION "0.5.2"
7
+ #define DEBUG_VERSION "0.5.3"
8
8
 
9
9
  #define CTX_FL_MOVED (1<<1)
10
10
  #define CTX_FL_SUSPEND (1<<2)
@@ -43,6 +43,7 @@ typedef struct {
43
43
  } debug_frame_t;
44
44
 
45
45
  typedef struct {
46
+ int id;
46
47
  VALUE source;
47
48
  VALUE pos;
48
49
  VALUE expr;
@@ -81,6 +82,7 @@ static ID idIndex;
81
82
 
82
83
  static int start_count = 0;
83
84
  static int thnum_max = 0;
85
+ static int bkp_count = 0;
84
86
  static int last_debugged_thnum = -1;
85
87
 
86
88
  static VALUE create_binding(VALUE);
@@ -627,7 +629,6 @@ debug_event_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
627
629
  if(post_mortem == Qtrue && self)
628
630
  {
629
631
  binding = create_binding(self);
630
- rb_ivar_set(ruby_errinfo, rb_intern("@__debug_binding"), binding);
631
632
  rb_ivar_set(ruby_errinfo, rb_intern("@__debug_file"), file);
632
633
  rb_ivar_set(ruby_errinfo, rb_intern("@__debug_line"), line);
633
634
  rb_ivar_set(ruby_errinfo, rb_intern("@__debug_binding"), binding);
@@ -784,6 +785,7 @@ debug_add_breakpoint(int argc, VALUE *argv, VALUE self)
784
785
 
785
786
  breakpoint = ALLOC(debug_breakpoint_t);
786
787
  breakpoint->source = StringValue(source);
788
+ breakpoint->id = ++bkp_count;
787
789
  breakpoint->pos = pos;
788
790
  breakpoint->expr = NIL_P(expr) ? expr: StringValue(expr);
789
791
  result = Data_Wrap_Struct(cBreakpoint, breakpoint_mark, xfree, breakpoint);
@@ -791,6 +793,36 @@ debug_add_breakpoint(int argc, VALUE *argv, VALUE self)
791
793
  return result;
792
794
  }
793
795
 
796
+ /*
797
+ * call-seq:
798
+ * Debugger.remove_breakpoint(id) -> breakpoint
799
+ *
800
+ * Removes breakpoint by its id.
801
+ * <i>id</i> is an identificator of a breakpoint.
802
+ */
803
+ static VALUE
804
+ debug_remove_breakpoint(VALUE self, VALUE id_value)
805
+ {
806
+ int i;
807
+ int id;
808
+ VALUE breakpoint;
809
+ debug_breakpoint_t *debug_breakpoint;
810
+
811
+ id = FIX2INT(id_value);
812
+
813
+ for( i = 0; i < RARRAY(breakpoints)->len; i += 1 )
814
+ {
815
+ breakpoint = rb_ary_entry(breakpoints, i);
816
+ Data_Get_Struct(breakpoint, debug_breakpoint_t, debug_breakpoint);
817
+ if(debug_breakpoint->id == id)
818
+ {
819
+ rb_ary_delete_at(breakpoints, i);
820
+ return breakpoint;
821
+ }
822
+ }
823
+ return Qnil;
824
+ }
825
+
794
826
  /*
795
827
  * call-seq:
796
828
  * Debugger.breakpoints -> array
@@ -1503,6 +1535,21 @@ breakpoint_expr(VALUE self)
1503
1535
  return breakpoint->expr;
1504
1536
  }
1505
1537
 
1538
+ /*
1539
+ * call-seq:
1540
+ * breakpoint.id -> int
1541
+ *
1542
+ * Returns id of the breakpoint.
1543
+ */
1544
+ static VALUE
1545
+ breakpoint_id(VALUE self)
1546
+ {
1547
+ debug_breakpoint_t *breakpoint;
1548
+
1549
+ Data_Get_Struct(self, debug_breakpoint_t, breakpoint);
1550
+ return INT2FIX(breakpoint->id);
1551
+ }
1552
+
1506
1553
  /*
1507
1554
  * Document-class: Context
1508
1555
  *
@@ -1562,6 +1609,7 @@ Init_breakpoint()
1562
1609
  rb_define_method(cBreakpoint, "source", breakpoint_source, 0);
1563
1610
  rb_define_method(cBreakpoint, "pos", breakpoint_pos, 0);
1564
1611
  rb_define_method(cBreakpoint, "expr", breakpoint_expr, 0);
1612
+ rb_define_method(cBreakpoint, "id", breakpoint_id, 0);
1565
1613
  }
1566
1614
 
1567
1615
  /*
@@ -1585,6 +1633,7 @@ Init_ruby_debug()
1585
1633
  rb_define_module_function(mDebugger, "started?", debug_is_started, 0);
1586
1634
  rb_define_module_function(mDebugger, "breakpoints", debug_breakpoints, 0);
1587
1635
  rb_define_module_function(mDebugger, "add_breakpoint", debug_add_breakpoint, -1);
1636
+ rb_define_module_function(mDebugger, "remove_breakpoint", debug_remove_breakpoint, 1);
1588
1637
  rb_define_module_function(mDebugger, "catchpoint", debug_catchpoint, 0);
1589
1638
  rb_define_module_function(mDebugger, "catchpoint=", debug_set_catchpoint, 1);
1590
1639
  rb_define_module_function(mDebugger, "last_context", debug_last_interrupted, 0);
data/lib/ruby-debug.rb CHANGED
@@ -77,7 +77,7 @@ module Debugger
77
77
  def interface=(value) # :nodoc:
78
78
  processor.interface = value
79
79
  end
80
-
80
+
81
81
  #
82
82
  # Starts a remote debugger.
83
83
  #
@@ -256,7 +256,8 @@ module Debugger
256
256
  end
257
257
 
258
258
  def handle_post_mortem(exp)
259
- processor.at_line(nil, exp.__debug_file, exp.__debug_line, exp.__debug_binding, exp.__debug_frames)
259
+ return if exp.__debug_frames.empty?
260
+ processor.at_line(nil, exp.__debug_file, exp.__debug_line, exp.__debug_frames.first.binding, exp.__debug_frames)
260
261
  end
261
262
  private :handle_post_mortem
262
263
  end
@@ -301,4 +302,22 @@ class Module
301
302
  end
302
303
  EOD
303
304
  end
305
+
306
+ #
307
+ # Wraps the +meth+ method with Debugger.post_mortem {...} block.
308
+ #
309
+ def post_mortem_method(meth)
310
+ old_meth = "__postmortem_#{meth}"
311
+ old_meth = "#{$1}_set" if old_meth =~ /^(.+)=$/
312
+ alias_method old_meth.to_sym, meth
313
+ class_eval <<-EOD
314
+ def #{meth}(*args, &block)
315
+ Debugger.start do |dbg|
316
+ dbg.post_mortem do
317
+ #{old_meth}(*args, &block)
318
+ end
319
+ end
320
+ end
321
+ EOD
322
+ end
304
323
  end
@@ -46,8 +46,8 @@ module Debugger
46
46
  pos = pos.intern.id2name
47
47
  end
48
48
 
49
- Debugger.add_breakpoint file, pos, expr
50
- print "Set breakpoint %d at %s:%s\n", Debugger.breakpoints.size, file, pos.to_s
49
+ b = Debugger.add_breakpoint file, pos, expr
50
+ print "Set breakpoint %d at %s:%s\n", b.id, file, pos.to_s
51
51
  end
52
52
 
53
53
  class << self
@@ -74,11 +74,11 @@ module Debugger
74
74
  def execute
75
75
  unless Debugger.breakpoints.empty?
76
76
  print "Breakpoints:\n"
77
- Debugger.breakpoints.each_with_index do |b, n|
77
+ Debugger.breakpoints.sort_by{|b| b.id }.each do |b|
78
78
  if b.expr.nil?
79
- print " %d %s:%s\n", n+1, b.source, b.pos
79
+ print " %d %s:%s\n", b.id, b.source, b.pos
80
80
  else
81
- print " %d %s:%s if %s\n", n+1, b.source, b.pos, b.expr
81
+ print " %d %s:%s if %s\n", b.id, b.source, b.pos, b.expr
82
82
  end
83
83
  end
84
84
  print "\n"
@@ -115,7 +115,7 @@ module Debugger
115
115
  end
116
116
  else
117
117
  pos = pos.to_i
118
- unless Debugger.breakpoints.delete_at(pos-1)
118
+ unless Debugger.remove_breakpoint(pos)
119
119
  print "Breakpoint %d is not defined\n", pos
120
120
  end
121
121
  end
@@ -89,7 +89,7 @@ module Debugger
89
89
 
90
90
  class ScriptInterface # :nodoc:
91
91
  def initialize(file, out)
92
- @file = open(file)
92
+ @file = file.respond_to?(:gets) ? file : open(file)
93
93
  @out = out
94
94
  end
95
95
 
@@ -11,6 +11,7 @@ module Debugger
11
11
  @display = []
12
12
  @mutex = Mutex.new
13
13
  @last_cmd = nil
14
+ @actions = []
14
15
  end
15
16
 
16
17
  def interface=(interface)
@@ -66,7 +67,7 @@ module Debugger
66
67
  process_commands(context, file, line, binding, frames)
67
68
  end
68
69
  protect :at_line
69
-
70
+
70
71
  private
71
72
 
72
73
  def print(*args)
@@ -106,18 +107,20 @@ module Debugger
106
107
  @last_cmd = input
107
108
  end
108
109
 
109
- if cmd = commands.find{ |c| c.match(input) }
110
- if context.nil? && cmd.class.need_context
111
- print "Command is unavailable\n"
112
- else
113
- cmd.execute
114
- end
115
- else
116
- unknown_cmd = commands.find{|cmd| cmd.class.unknown }
117
- if unknown_cmd
118
- unknown_cmd.execute
110
+ input.split(";").each do |input|
111
+ if cmd = commands.find{ |c| c.match(input) }
112
+ if context.nil? && cmd.class.need_context
113
+ print "Command is unavailable\n"
114
+ else
115
+ cmd.execute
116
+ end
119
117
  else
120
- print "Unknown command\n"
118
+ unknown_cmd = commands.find{|cmd| cmd.class.unknown }
119
+ if unknown_cmd
120
+ unknown_cmd.execute
121
+ else
122
+ print "Unknown command\n"
123
+ end
121
124
  end
122
125
  end
123
126
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: ruby-debug
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
7
- date: 2006-12-21 16:17:01 -05:00
6
+ version: 0.5.3
7
+ date: 2007-01-21 03:38:07 -05:00
8
8
  summary: Fast Ruby debugger
9
9
  require_paths:
10
10
  - lib