Module: Debugger
- Defined in:
- ext/ruby_debug/ruby_debug.c
Constant Summary collapse
- VERSION =
rb_str_new2(DEBUG_VERSION)
Class Method Summary collapse
-
.add_breakpoint(source, pos, condition = nil) ⇒ Object
Adds a new breakpoint.
-
.catchpoint(string) ⇒ String
Sets catchpoint.
-
.breakpoints ⇒ Array
Returns an array of breakpoints.
-
.catchpoints ⇒ Hash
Returns a current catchpoints, which is a hash exception names that will trigger a debugger when raised.
-
.contexts ⇒ Array
Returns an array of all contexts.
-
.current_context ⇒ Object
Returns current context.
-
.debug ⇒ Object
:nodoc:.
-
.debug=(value) ⇒ Object
:nodoc:.
-
.debug_at_exit { ... } ⇒ Proc
Register
at_exit
hook which is escaped from the debugger. -
.debug_load(file, stop = false, increment_start = false) ⇒ nil
Same as Kernel#load but resets current context’s frames.
-
.keep_frame_binding=(bool) ⇒ Object
Setting to
true
will make the debugger create frame bindings. -
.keep_frame_binding? ⇒ Boolean
Returns
true
if the debugger will collect frame bindings. -
.last_interrupted ⇒ Object
Returns last debugged context.
-
.post_mortem=(bool) ⇒ Object
Sets post-moterm flag.
-
.post_mortem? ⇒ Boolean
Returns
true
if post-moterm debugging is enabled. -
.remove_breakpoint(id) ⇒ Object
Removes breakpoint by its id.
-
.resume ⇒ Debugger
Resumes all contexts.
-
.skip { ... } ⇒ Object?
The code inside of the block is escaped from the debugger.
-
.start_ ⇒ Object
This method is internal and activates the debugger.
-
.started? ⇒ Boolean
Returns
true
the debugger is started. -
.stop ⇒ Boolean
This method disables the debugger.
-
.suspend ⇒ Debugger
Suspends all contexts.
-
.thread_context(thread) ⇒ Object
Returns context of the thread passed as an argument.
-
.tracing ⇒ Boolean
Returns
true
if the global tracing is activated. -
.tracing=(bool) ⇒ Object
Sets the global tracing flag.
-
.track_frame_args=(bool) ⇒ Object
Setting to
true
will make the debugger save argument info on calls. -
.track_fame_args? ⇒ Boolean
Returns
true
if the debugger track frame argument values on calls.
Class Method Details
.add_breakpoint(source, pos, condition = nil) ⇒ Object
Adds a new breakpoint. source is a name of a file or a class. pos is a line number or a method name if source is a class name. condition is a string which is evaluated to true
when this breakpoint is activated.
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 |
# File 'ext/ruby_debug/ruby_debug.c', line 2536
static VALUE
debug_add_breakpoint(int argc, VALUE *argv, VALUE self)
{
VALUE result;
debug_check_started();
result = create_breakpoint_from_args(argc, argv, ++bkp_count);
rb_ary_push(rdebug_breakpoints, result);
return result;
}
|
.catchpoint(string) ⇒ String
Sets catchpoint. Returns the string passed.
249 250 251 252 253 254 255 256 257 258 259 |
# File 'ext/ruby_debug/breakpoint.c', line 249
VALUE
rdebug_add_catchpoint(VALUE self, VALUE value)
{
debug_check_started();
if (TYPE(value) != T_STRING) {
rb_raise(rb_eTypeError, "value of a catchpoint must be String");
}
rb_hash_aset(rdebug_catchpoints, rb_str_dup(value), INT2FIX(0));
return value;
}
|
.breakpoints ⇒ Array
Returns an array of breakpoints.
2518 2519 2520 2521 2522 2523 2524 |
# File 'ext/ruby_debug/ruby_debug.c', line 2518
static VALUE
debug_breakpoints(VALUE self)
{
debug_check_started();
return rdebug_breakpoints;
}
|
.catchpoints ⇒ Hash
Returns a current catchpoints, which is a hash exception names that will trigger a debugger when raised. The values are the number of times taht catchpoint was hit, initially 0.
235 236 237 238 239 240 241 |
# File 'ext/ruby_debug/breakpoint.c', line 235
VALUE
debug_catchpoints(VALUE self)
{
debug_check_started();
return rdebug_catchpoints;
}
|
.contexts ⇒ Array
Returns an array of all contexts.
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 |
# File 'ext/ruby_debug/ruby_debug.c', line 1261
static VALUE
debug_contexts(VALUE self)
{
volatile VALUE list;
volatile VALUE new_list;
VALUE thread, context;
threads_table_t *threads_table;
debug_context_t *debug_context;
int i;
debug_check_started();
new_list = rb_ary_new();
list = rb_funcall(rb_cThread, idList, 0);
for(i = 0; i < RARRAY_LEN(list); i++)
{
thread = rb_ary_entry(list, i);
thread_context_lookup(thread, &context, NULL, 1);
rb_ary_push(new_list, context);
}
threads_table_clear(rdebug_threads_tbl);
Data_Get_Struct(rdebug_threads_tbl, threads_table_t, threads_table);
for(i = 0; i < RARRAY_LEN(new_list); i++)
{
context = rb_ary_entry(new_list, i);
Data_Get_Struct(context, debug_context_t, debug_context);
st_insert(threads_table->tbl, debug_context->thread_id, context);
}
return new_list;
}
|
.current_context ⇒ Object
Returns current context. Note: Debugger.current_context.thread == Thread.current
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 |
# File 'ext/ruby_debug/ruby_debug.c', line 1226
static VALUE
debug_current_context(VALUE self)
{
VALUE thread, context;
debug_check_started();
thread = rb_thread_current();
thread_context_lookup(thread, &context, NULL, 1);
return context;
}
|
.debug ⇒ Object
:nodoc:
1461 1462 1463 1464 1465 |
# File 'ext/ruby_debug/ruby_debug.c', line 1461
static VALUE
debug_debug(VALUE self)
{
return debug;
}
|
.debug=(value) ⇒ Object
:nodoc:
1468 1469 1470 1471 1472 1473 |
# File 'ext/ruby_debug/ruby_debug.c', line 1468
static VALUE
debug_set_debug(VALUE self, VALUE value)
{
debug = RTEST(value) ? Qtrue : Qfalse;
return value;
}
|
.debug_at_exit { ... } ⇒ Proc
Register at_exit
hook which is escaped from the debugger. FOR INTERNAL USE ONLY.
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'ext/ruby_debug/ruby_debug.c', line 1598
static VALUE
debug_at_exit(VALUE self)
{
VALUE proc;
if (!rb_block_given_p())
rb_raise(rb_eArgError, "called without a block");
proc = rb_block_proc();
rb_set_end_proc(debug_at_exit_i, proc);
return proc;
}
|
.debug_load(file, stop = false, increment_start = false) ⇒ nil
Same as Kernel#load but resets current context’s frames. stop
parameter forces the debugger to stop at the first line of code in the file
increment_start
determines if start_count should be incremented. When
control threads are used, they have to be set up before loading the
debugger; so here +increment_start+ will be false.
FOR INTERNAL USE ONLY.
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 |
# File 'ext/ruby_debug/ruby_debug.c', line 1493
static VALUE
debug_debug_load(int argc, VALUE *argv, VALUE self)
{
VALUE file, stop, context, increment_start;
debug_context_t *debug_context;
int state = 0;
if(rb_scan_args(argc, argv, "12", &file, &stop, &increment_start) == 1)
{
stop = Qfalse;
increment_start = Qtrue;
}
debug_start(self);
if (Qfalse == increment_start) start_count--;
context = debug_current_context(self);
Data_Get_Struct(context, debug_context_t, debug_context);
debug_context->stack_size = 0;
if(RTEST(stop))
debug_context->stop_next = 1;
/* Initializing $0 to the script's path */
ruby_script(RSTRING_PTR(file));
rb_load_protect(file, 0, &state);
if (0 != state)
{
VALUE errinfo = rb_errinfo();
debug_suspend(self);
reset_stepping_stop_points(debug_context);
rb_set_errinfo(Qnil);
return errinfo;
}
/* We should run all at_exit handler's in order to provide,
* for instance, a chance to run all defined test cases */
rb_exec_end_proc();
/* We could have issued a Debugger.stop inside the debug
session. */
if (start_count > 0)
debug_stop(self);
return Qnil;
}
|
.keep_frame_binding=(bool) ⇒ Object
Setting to true
will make the debugger create frame bindings.
1453 1454 1455 1456 1457 1458 |
# File 'ext/ruby_debug/ruby_debug.c', line 1453
static VALUE
debug_set_keep_frame_binding(VALUE self, VALUE value)
{
keep_frame_binding = RTEST(value) ? Qtrue : Qfalse;
return value;
}
|
.keep_frame_binding? ⇒ Boolean
Returns true
if the debugger will collect frame bindings.
1441 1442 1443 1444 1445 |
# File 'ext/ruby_debug/ruby_debug.c', line 1441
static VALUE
debug_keep_frame_binding(VALUE self)
{
return keep_frame_binding;
}
|
.last_interrupted ⇒ Object
Returns last debugged context.
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'ext/ruby_debug/ruby_debug.c', line 1205
static VALUE
debug_last_interrupted(VALUE self)
{
VALUE result = Qnil;
threads_table_t *threads_table;
debug_check_started();
Data_Get_Struct(rdebug_threads_tbl, threads_table_t, threads_table);
st_foreach(threads_table->tbl, find_last_context_func, (st_data_t)&result);
return result;
}
|
.post_mortem=(bool) ⇒ Object
Sets post-moterm flag. FOR INTERNAL USE ONLY.
1401 1402 1403 1404 1405 1406 1407 1408 |
# File 'ext/ruby_debug/ruby_debug.c', line 1401
static VALUE
debug_set_post_mortem(VALUE self, VALUE value)
{
debug_check_started();
post_mortem = RTEST(value) ? Qtrue : Qfalse;
return value;
}
|
.post_mortem? ⇒ Boolean
Returns true
if post-moterm debugging is enabled.
1388 1389 1390 1391 1392 |
# File 'ext/ruby_debug/ruby_debug.c', line 1388
static VALUE
debug_post_mortem(VALUE self)
{
return post_mortem;
}
|
.remove_breakpoint(id) ⇒ Object
Removes breakpoint by its id. id is an identificator of a breakpoint.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'ext/ruby_debug/breakpoint.c', line 204
VALUE
rdebug_remove_breakpoint(VALUE self, VALUE id_value)
{
int i;
int id;
VALUE breakpoint;
debug_breakpoint_t *debug_breakpoint;
id = FIX2INT(id_value);
for( i = 0; i < RARRAY_LEN(rdebug_breakpoints); i += 1 )
{
breakpoint = rb_ary_entry(rdebug_breakpoints, i);
Data_Get_Struct(breakpoint, debug_breakpoint_t, debug_breakpoint);
if(debug_breakpoint->id == id)
{
rb_ary_delete_at(rdebug_breakpoints, i);
return breakpoint;
}
}
return Qnil;
}
|
.resume ⇒ Debugger
Resumes all contexts.
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 |
# File 'ext/ruby_debug/ruby_debug.c', line 1330
static VALUE
debug_resume(VALUE self)
{
VALUE current, context;
VALUE context_list;
debug_context_t *debug_context;
int i;
debug_check_started();
context_list = debug_contexts(self);
thread_context_lookup(rb_thread_current(), ¤t, NULL, 1);
for(i = 0; i < RARRAY_LEN(context_list); i++)
{
context = rb_ary_entry(context_list, i);
if(current == context)
continue;
Data_Get_Struct(context, debug_context_t, debug_context);
context_resume_0(debug_context);
}
rb_thread_schedule();
return self;
}
|
.skip { ... } ⇒ Object?
The code inside of the block is escaped from the debugger.
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 |
# File 'ext/ruby_debug/ruby_debug.c', line 1559
static VALUE
debug_skip(VALUE self)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "called without a block");
}
if(!IS_STARTED)
return rb_yield(Qnil);
set_current_skipped_status(Qtrue);
return rb_ensure(rb_yield, Qnil, set_current_skipped_status, Qfalse);
}
|
.start_ ⇒ Boolean .start_ { ... } ⇒ Boolean
This method is internal and activates the debugger. Use Debugger.start (from lib/ruby-debug-base.rb
) instead.
The return value is the value of !Debugger.started? before issuing the start
; That is, true
is returned, unless debugger was previously started.
If a block is given, it starts debugger and yields to block. When the block is finished executing it stops the debugger with Debugger.stop method. Inside the block you will probably want to have a call to Debugger.debugger. For example:
Debugger.start{debugger; foo} # Stop inside of foo
Also, ruby-debug only allows one invocation of debugger at a time; nested Debugger.start’s have no effect and you can’t use this inside the debugger itself.
Note that if you want to completely remove the debugger hook, you must call Debugger.stop as many times as you called Debugger.start method.
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
# File 'ext/ruby_debug/ruby_debug.c', line 1132
static VALUE
debug_start(VALUE self)
{
VALUE result;
start_count++;
if(IS_STARTED)
result = Qfalse;
else
{
locker = Qnil;
rdebug_breakpoints = rb_ary_new();
rdebug_catchpoints = rb_hash_new();
rdebug_threads_tbl = threads_table_create();
rb_add_event_hook(debug_event_hook, RUBY_EVENT_ALL, Qnil);
result = Qtrue;
}
if(rb_block_given_p())
rb_ensure(rb_yield, self, debug_stop_i, self);
return result;
}
|
.started? ⇒ Boolean
Returns true
the debugger is started.
331 332 333 334 335 |
# File 'ext/ruby_debug/ruby_debug.c', line 331
static VALUE
debug_is_started(VALUE self)
{
return IS_STARTED ? Qtrue : Qfalse;
}
|
.stop ⇒ Boolean
This method disables the debugger. It returns true
if the debugger is disabled, otherwise it returns false
.
Note that if you want to complete remove the debugger hook, you must call Debugger.stop as many times as you called Debugger.start method.
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'ext/ruby_debug/ruby_debug.c', line 1168
static VALUE
debug_stop(VALUE self)
{
debug_check_started();
start_count--;
if(start_count)
return Qfalse;
rb_remove_event_hook(debug_event_hook);
locker = Qnil;
rdebug_breakpoints = Qnil;
rdebug_threads_tbl = Qnil;
return Qtrue;
}
|
.suspend ⇒ Debugger
Suspends all contexts.
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
# File 'ext/ruby_debug/ruby_debug.c', line 1299
static VALUE
debug_suspend(VALUE self)
{
VALUE current, context;
VALUE context_list;
debug_context_t *debug_context;
int i;
debug_check_started();
context_list = debug_contexts(self);
thread_context_lookup(rb_thread_current(), ¤t, NULL, 1);
for(i = 0; i < RARRAY_LEN(context_list); i++)
{
context = rb_ary_entry(context_list, i);
if(current == context)
continue;
Data_Get_Struct(context, debug_context_t, debug_context);
context_suspend_0(debug_context);
}
return self;
}
|
.thread_context(thread) ⇒ Object
Returns context of the thread passed as an argument.
1245 1246 1247 1248 1249 1250 1251 1252 1253 |
# File 'ext/ruby_debug/ruby_debug.c', line 1245
static VALUE
debug_thread_context(VALUE self, VALUE thread)
{
VALUE context;
debug_check_started();
thread_context_lookup(thread, &context, NULL, 1);
return context;
}
|
.tracing ⇒ Boolean
Returns true
if the global tracing is activated.
1363 1364 1365 1366 1367 |
# File 'ext/ruby_debug/ruby_debug.c', line 1363
static VALUE
debug_tracing(VALUE self)
{
return tracing;
}
|
.tracing=(bool) ⇒ Object
Sets the global tracing flag.
1375 1376 1377 1378 1379 1380 |
# File 'ext/ruby_debug/ruby_debug.c', line 1375
static VALUE
debug_set_tracing(VALUE self, VALUE value)
{
tracing = RTEST(value) ? Qtrue : Qfalse;
return value;
}
|
.track_frame_args=(bool) ⇒ Object
Setting to true
will make the debugger save argument info on calls.
1428 1429 1430 1431 1432 1433 |
# File 'ext/ruby_debug/ruby_debug.c', line 1428
static VALUE
debug_set_track_frame_args(VALUE self, VALUE value)
{
track_frame_args = RTEST(value) ? Qtrue : Qfalse;
return value;
}
|
.track_fame_args? ⇒ Boolean
Returns true
if the debugger track frame argument values on calls.
1416 1417 1418 1419 1420 |
# File 'ext/ruby_debug/ruby_debug.c', line 1416
static VALUE
debug_track_frame_args(VALUE self)
{
return track_frame_args;
}
|