debase 0.2.2.beta2 → 0.2.2.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/context.c +2 -0
- data/ext/debase_internals.c +103 -20
- data/ext/debase_internals.h +2 -0
- data/ext/hacks.h +4 -0
- data/lib/debase.rb +2 -3
- data/lib/debase/version.rb +1 -1
- data/test/test_base.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e783c3d7dbe46b855cb1d5405a8a7a688832fa7d
|
4
|
+
data.tar.gz: a6e2e176ab8aa8f43fda15bf44d902264a5435e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96588d5f13dff2238fb6eda79b2828544b362b4255f76b108cac98f412fff55d825916aaa43be864b04a9899643dcf63a9d884fb624cd6823cd8b8f6597b80d1
|
7
|
+
data.tar.gz: 043b548b36ccf5e9953cb2308d0a73b3dc14874e952afdd3ca6886ec0cc46f8650853be56db200019b731397c5a43c2f003385a74df55eda7ad73ccdbdf8fa26
|
data/ext/context.c
CHANGED
@@ -147,6 +147,7 @@ context_create(VALUE thread, VALUE cDebugThread) {
|
|
147
147
|
context->last_line = -1;
|
148
148
|
context->stop_frame = -1;
|
149
149
|
context->thread_pause = 0;
|
150
|
+
context->stop_reason = CTX_STOP_NONE;
|
150
151
|
reset_stepping_stop_points(context);
|
151
152
|
if(rb_obj_class(thread) == cDebugThread) CTX_FL_SET(context, CTX_FL_IGNORE);
|
152
153
|
return Data_Wrap_Struct(cContext, Context_mark, Context_free, context);
|
@@ -272,6 +273,7 @@ Context_pause(VALUE self)
|
|
272
273
|
return Qfalse;
|
273
274
|
}
|
274
275
|
|
276
|
+
enable_trace_points();
|
275
277
|
context->thread_pause = 1;
|
276
278
|
return Qtrue;
|
277
279
|
}
|
data/ext/debase_internals.c
CHANGED
@@ -23,6 +23,17 @@ static VALUE idAtCatchpoint;
|
|
23
23
|
static VALUE idFileFilter;
|
24
24
|
static VALUE idAccept;
|
25
25
|
|
26
|
+
static void
|
27
|
+
print_debug(const char *message, ...)
|
28
|
+
{
|
29
|
+
va_list ap;
|
30
|
+
|
31
|
+
if (verbose == Qfalse) return;
|
32
|
+
va_start(ap, message);
|
33
|
+
vfprintf(stderr, message, ap);
|
34
|
+
va_end(ap);
|
35
|
+
}
|
36
|
+
|
26
37
|
static VALUE
|
27
38
|
is_path_accepted(VALUE path) {
|
28
39
|
VALUE filter;
|
@@ -49,6 +60,82 @@ Debase_current_context(VALUE self)
|
|
49
60
|
return Debase_thread_context(self, rb_thread_current());
|
50
61
|
}
|
51
62
|
|
63
|
+
static int
|
64
|
+
set_recalc_flag(VALUE thread, VALUE context_object, VALUE ignored)
|
65
|
+
{
|
66
|
+
debug_context_t *context;
|
67
|
+
|
68
|
+
Data_Get_Struct(context_object, debug_context_t, context);
|
69
|
+
CTX_FL_SET(context, CTX_FL_UPDATE_STACK);
|
70
|
+
|
71
|
+
return ST_CONTINUE;
|
72
|
+
}
|
73
|
+
|
74
|
+
static int
|
75
|
+
can_disable_trace_points(VALUE thread, VALUE context_object, VALUE result)
|
76
|
+
{
|
77
|
+
debug_context_t *context;
|
78
|
+
|
79
|
+
Data_Get_Struct(context_object, debug_context_t, context);
|
80
|
+
|
81
|
+
if (-1 != context->dest_frame
|
82
|
+
|| context->stop_line >= 0
|
83
|
+
|| -1 != context->stop_next
|
84
|
+
|| context->stop_reason != CTX_STOP_NONE
|
85
|
+
|| context->thread_pause != 0)
|
86
|
+
{
|
87
|
+
print_debug("can_disable_tp: %d %d %d %d\n", context->dest_frame, context->stop_line,
|
88
|
+
context->stop_next, context->stop_reason);
|
89
|
+
*((VALUE *) result) = Qfalse;
|
90
|
+
return ST_STOP;
|
91
|
+
}
|
92
|
+
return ST_CONTINUE;
|
93
|
+
}
|
94
|
+
|
95
|
+
static void
|
96
|
+
try_disable_trace_points()
|
97
|
+
{
|
98
|
+
VALUE can_disable = Qtrue;
|
99
|
+
|
100
|
+
if (RARRAY_LEN(breakpoints) != 0) return;
|
101
|
+
print_debug("disable_tps: no breakpoints\n");
|
102
|
+
if (RHASH_EMPTY_P(catchpoints)) return;
|
103
|
+
print_debug("disable_tps: no catchpoints\n");
|
104
|
+
if (rb_tracepoint_enabled_p(tpLine) == Qfalse) return;
|
105
|
+
print_debug("disable_tps: tps are enabled\n");
|
106
|
+
|
107
|
+
rb_hash_foreach(contexts, can_disable_trace_points, (VALUE)&can_disable);
|
108
|
+
if (can_disable == Qfalse) return;
|
109
|
+
print_debug("disable_tps: can disable contexts\n");
|
110
|
+
|
111
|
+
rb_tracepoint_disable(tpLine);
|
112
|
+
rb_tracepoint_disable(tpCall);
|
113
|
+
rb_tracepoint_disable(tpReturn);
|
114
|
+
rb_tracepoint_disable(tpRaise);
|
115
|
+
rb_hash_foreach(contexts, set_recalc_flag, 0);
|
116
|
+
}
|
117
|
+
|
118
|
+
extern VALUE
|
119
|
+
enable_trace_points()
|
120
|
+
{
|
121
|
+
print_debug("enable_tps: \n");
|
122
|
+
if (rb_tracepoint_enabled_p(tpLine) == Qtrue) return Qtrue;
|
123
|
+
print_debug("enable_tps: need to enable\n");
|
124
|
+
|
125
|
+
rb_tracepoint_enable(tpLine);
|
126
|
+
rb_tracepoint_enable(tpCall);
|
127
|
+
rb_tracepoint_enable(tpReturn);
|
128
|
+
rb_tracepoint_enable(tpRaise);
|
129
|
+
|
130
|
+
return Qfalse;
|
131
|
+
}
|
132
|
+
|
133
|
+
static VALUE
|
134
|
+
Debase_enable_trace_points(VALUE self)
|
135
|
+
{
|
136
|
+
return enable_trace_points();
|
137
|
+
}
|
138
|
+
|
52
139
|
static int
|
53
140
|
remove_dead_threads(VALUE thread, VALUE context, VALUE ignored)
|
54
141
|
{
|
@@ -71,6 +158,8 @@ cleanup(debug_context_t *context)
|
|
71
158
|
thread = remove_from_locked();
|
72
159
|
if(thread != Qnil)
|
73
160
|
rb_thread_run(thread);
|
161
|
+
|
162
|
+
try_disable_trace_points();
|
74
163
|
}
|
75
164
|
|
76
165
|
static int
|
@@ -377,15 +466,18 @@ Debase_setup_tracepoints(VALUE self)
|
|
377
466
|
catchpoints = rb_hash_new();
|
378
467
|
|
379
468
|
tpLine = rb_tracepoint_new(Qnil, RUBY_EVENT_LINE, process_line_event, NULL);
|
380
|
-
|
381
|
-
|
469
|
+
rb_global_variable(&tpLine);
|
470
|
+
|
471
|
+
tpReturn = rb_tracepoint_new(Qnil, RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_C_RETURN | RUBY_EVENT_END,
|
382
472
|
process_return_event, NULL);
|
383
|
-
|
384
|
-
|
473
|
+
rb_global_variable(&tpReturn);
|
474
|
+
|
475
|
+
tpCall = rb_tracepoint_new(Qnil, RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_C_CALL | RUBY_EVENT_CLASS,
|
385
476
|
process_call_event, NULL);
|
386
|
-
|
477
|
+
rb_global_variable(&tpCall);
|
478
|
+
|
387
479
|
tpRaise = rb_tracepoint_new(Qnil, RUBY_EVENT_RAISE, process_raise_event, NULL);
|
388
|
-
|
480
|
+
rb_global_variable(&tpRaise);
|
389
481
|
|
390
482
|
return Qnil;
|
391
483
|
}
|
@@ -418,7 +510,10 @@ debase_prepare_context(VALUE self, VALUE file, VALUE stop)
|
|
418
510
|
context_object = Debase_current_context(self);
|
419
511
|
Data_Get_Struct(context_object, debug_context_t, context);
|
420
512
|
|
421
|
-
if(RTEST(stop))
|
513
|
+
if(RTEST(stop)) {
|
514
|
+
context->stop_next = 1;
|
515
|
+
Debase_enable_trace_points(self);
|
516
|
+
}
|
422
517
|
ruby_script(RSTRING_PTR(file));
|
423
518
|
return self;
|
424
519
|
}
|
@@ -510,18 +605,6 @@ Debase_set_verbose(VALUE self, VALUE value)
|
|
510
605
|
return value;
|
511
606
|
}
|
512
607
|
|
513
|
-
/*
|
514
|
-
* call-seq:
|
515
|
-
* Debase.tp_raise -> TracePoint
|
516
|
-
*
|
517
|
-
* Returns trace point we use to track :raise events
|
518
|
-
*/
|
519
|
-
static VALUE
|
520
|
-
Debase_get_tp_raise(VALUE self)
|
521
|
-
{
|
522
|
-
return tpRaise;
|
523
|
-
}
|
524
|
-
|
525
608
|
/*
|
526
609
|
* Document-class: Debase
|
527
610
|
*
|
@@ -541,10 +624,10 @@ Init_debase_internals()
|
|
541
624
|
rb_define_module_function(mDebase, "contexts", Debase_contexts, 0);
|
542
625
|
rb_define_module_function(mDebase, "breakpoints", Debase_breakpoints, 0);
|
543
626
|
rb_define_module_function(mDebase, "catchpoints", Debase_catchpoints, 0);
|
544
|
-
rb_define_module_function(mDebase, "tp_raise", Debase_get_tp_raise, 0);
|
545
627
|
rb_define_module_function(mDebase, "started?", Debase_started, 0);
|
546
628
|
rb_define_module_function(mDebase, "verbose?", Debase_verbose, 0);
|
547
629
|
rb_define_module_function(mDebase, "verbose=", Debase_set_verbose, 1);
|
630
|
+
rb_define_module_function(mDebase, "enable_trace_points", Debase_enable_trace_points, 0);
|
548
631
|
|
549
632
|
idAlive = rb_intern("alive?");
|
550
633
|
idAtLine = rb_intern("at_line");
|
data/ext/debase_internals.h
CHANGED
@@ -18,6 +18,7 @@ typedef struct rb_trace_arg_struct rb_trace_point_t;
|
|
18
18
|
#define CTX_FL_STEPPED (1<<8)
|
19
19
|
#define CTX_FL_FORCE_MOVE (1<<9)
|
20
20
|
#define CTX_FL_CATCHING (1<<10)
|
21
|
+
#define CTX_FL_UPDATE_STACK (1<<11)
|
21
22
|
|
22
23
|
/* macro functions */
|
23
24
|
#define CTX_FL_TEST(c,f) ((c)->flags & (f))
|
@@ -88,6 +89,7 @@ typedef struct locked_thread_t {
|
|
88
89
|
extern int is_in_locked(VALUE thread_id);
|
89
90
|
extern void add_to_locked(VALUE thread);
|
90
91
|
extern VALUE remove_from_locked();
|
92
|
+
extern VALUE enable_trace_points();
|
91
93
|
|
92
94
|
/* breakpoints and catchpoints */
|
93
95
|
/* types */
|
data/ext/hacks.h
CHANGED
@@ -10,4 +10,8 @@ update_stack_size(debug_context_t *context)
|
|
10
10
|
thread = ruby_current_thread;
|
11
11
|
/* see backtrace_each in vm_backtrace.c */
|
12
12
|
context->stack_size = (int)(RUBY_VM_END_CONTROL_FRAME(thread) - thread->cfp - 1);
|
13
|
+
if (CTX_FL_TEST(context, CTX_FL_UPDATE_STACK)) {
|
14
|
+
context->calced_stack_size = context->stack_size;
|
15
|
+
CTX_FL_UNSET(context, CTX_FL_UPDATE_STACK);
|
16
|
+
}
|
13
17
|
}
|
data/lib/debase.rb
CHANGED
@@ -29,6 +29,7 @@ module Debase
|
|
29
29
|
def add_breakpoint(file, line, expr=nil)
|
30
30
|
breakpoint = Breakpoint.new(file, line, expr)
|
31
31
|
breakpoints << breakpoint
|
32
|
+
enable_trace_points
|
32
33
|
breakpoint
|
33
34
|
end
|
34
35
|
|
@@ -48,17 +49,15 @@ module Debase
|
|
48
49
|
|
49
50
|
def add_catchpoint(exception)
|
50
51
|
catchpoints[exception] = 0
|
51
|
-
|
52
|
+
enable_trace_points
|
52
53
|
end
|
53
54
|
|
54
55
|
def remove_catchpoint(exception)
|
55
56
|
catchpoints.delete(exception)
|
56
|
-
tp_raise.disable if catchpoints.empty?
|
57
57
|
end
|
58
58
|
|
59
59
|
def clear_catchpoints
|
60
60
|
catchpoints.clear
|
61
|
-
tp_raise.disable
|
62
61
|
end
|
63
62
|
|
64
63
|
#call-seq:
|
data/lib/debase/version.rb
CHANGED
data/test/test_base.rb
CHANGED
@@ -12,6 +12,8 @@ class TestRubyDebug < Test::Unit::TestCase
|
|
12
12
|
assert_equal(false, Debugger.started?,
|
13
13
|
'debugger should not initially be started.')
|
14
14
|
Debugger.start_
|
15
|
+
# we need to add the breakpoint to force enabling trace points
|
16
|
+
Debugger.add_breakpoint(__FILE__, 1)
|
15
17
|
assert(Debugger.started?,
|
16
18
|
'debugger should now be started.')
|
17
19
|
# assert_equal(__LINE__, Debugger.current_context.frame_line)
|
@@ -37,6 +39,8 @@ class TestRubyDebug < Test::Unit::TestCase
|
|
37
39
|
assert_equal(false, Debugger.started?,
|
38
40
|
'Debugger should not initially be started.')
|
39
41
|
Debugger.start_
|
42
|
+
# we need to add the breakpoint to force enabling trace points
|
43
|
+
Debugger.add_breakpoint(__FILE__, 1)
|
40
44
|
assert(Debugger.started?,
|
41
45
|
'Debugger should now be started.')
|
42
46
|
assert_equal(false, Debugger.debug,
|