Class: Byebug::Context
- Inherits:
-
Object
- Object
- Byebug::Context
- Defined in:
- lib/byebug/context.rb,
ext/byebug/context.c
Overview
Mantains context information for the debugger and it’s the main communication point between the library and the C-extension through the at_breakpoint, at_catchpoint, at_tracing, at_line and at_return callbacks
Class Method Summary collapse
- .bin_file ⇒ Object
-
.ignored_files ⇒ Object
List of files byebug will ignore while debugging.
- .lib_files ⇒ Object
Instance Method Summary collapse
- #at_breakpoint(brkpnt) ⇒ Object
- #at_catchpoint(excpt) ⇒ Object
- #at_line(file, line) ⇒ Object
- #at_return(file, line) ⇒ Object
- #at_tracing(file, line) ⇒ Object
- #backtrace ⇒ Object
- #dead? ⇒ Boolean
-
#frame_args(frame_no = 0) ⇒ Object
Gets current method arguments for a frame.
-
#frame_binding(frame_position = 0) ⇒ Binding
Returns frame’s binding.
-
#frame_class(frame_position = 0) ⇒ Binding
Returns frame’s defined class.
-
#frame_file(frame_position = 0) ⇒ String
Returns the name of the file in the frame.
-
#frame_line(frame_position = 0) ⇒ Integer
Returns the line number in the file.
-
#frame_locals(frame_no = 0) ⇒ Object
Gets local variables for a frame.
-
#frame_method(frame_position = 0) ⇒ Object
Returns the sym of the called method.
-
#frame_self(frame_postion = 0) ⇒ Object
Returns self object of the frame.
- #handler ⇒ Object
- #ignored? ⇒ Boolean
-
#ignored_file?(path) ⇒ Boolean
Tells whether a file is ignored by the debugger.
- #interrupt ⇒ Object
-
#resume ⇒ nil
Resumes thread from the suspended mode.
-
#stack_size ⇒ Object
Context’s stack size.
-
#step_into(steps, frame = 0) ⇒ Object
Stops the current context after a number of
steps
are made from frameframe
(by default the newest one). -
#step_out(n_frames = 1, force = false) ⇒ Object
Stops after
n_frames
frames are finished. -
#step_over(lines, frame = 0) ⇒ Object
Steps over
lines
lines in frameframe
(by default the newest one) or higher (if frameframe
finishes). - #stop_reason ⇒ Object
-
#suspend ⇒ nil
Suspends the thread when it is running.
-
#suspended? ⇒ Boolean
Returns
true
if the thread is suspended by debugger. -
#switch ⇒ nil
Switches execution to this context.
- #thnum ⇒ Object
- #thread ⇒ Object
-
#tracing ⇒ Boolean
Returns the tracing flag for the current context.
-
#tracing=(bool) ⇒ Object
Controls the tracing for this context.
Class Method Details
.bin_file ⇒ Object
15 16 17 |
# File 'lib/byebug/context.rb', line 15 def self.bin_file @bin_file ||= Gem.bin_path('byebug', 'byebug') end |
.ignored_files ⇒ Object
List of files byebug will ignore while debugging
11 12 13 |
# File 'lib/byebug/context.rb', line 11 def self.ignored_files Byebug.mode == :standalone ? lib_files + [bin_file] : lib_files end |
.lib_files ⇒ Object
19 20 21 |
# File 'lib/byebug/context.rb', line 19 def self.lib_files @lib_files ||= Dir.glob(File.('../../**/*.rb', __FILE__)) end |
Instance Method Details
#at_breakpoint(brkpnt) ⇒ Object
77 78 79 |
# File 'lib/byebug/context.rb', line 77 def at_breakpoint(brkpnt) handler.at_breakpoint(self, brkpnt) end |
#at_catchpoint(excpt) ⇒ Object
81 82 83 |
# File 'lib/byebug/context.rb', line 81 def at_catchpoint(excpt) handler.at_catchpoint(self, excpt) end |
#at_line(file, line) ⇒ Object
89 90 91 |
# File 'lib/byebug/context.rb', line 89 def at_line(file, line) handler.at_line(self, file, line) unless ignored_file?(file) end |
#at_return(file, line) ⇒ Object
93 94 95 |
# File 'lib/byebug/context.rb', line 93 def at_return(file, line) handler.at_return(self, file, line) unless ignored_file?(file) end |
#at_tracing(file, line) ⇒ Object
85 86 87 |
# File 'lib/byebug/context.rb', line 85 def at_tracing(file, line) handler.at_tracing(self, file, line) unless ignored_file?(file) end |
#backtrace ⇒ Object
#dead? ⇒ Boolean
#frame_args(frame_no = 0) ⇒ Object
Gets current method arguments for a frame.
66 67 68 69 70 71 |
# File 'lib/byebug/context.rb', line 66 def frame_args(frame_no = 0) bind = frame_binding(frame_no) return c_frame_args(frame_no) unless bind ruby_frame_args(bind) end |
#frame_binding(frame_position = 0) ⇒ Binding
Returns frame’s binding.
211 212 213 214 215 216 217 |
# File 'ext/byebug/context.c', line 211
static VALUE
Context_frame_binding(int argc, VALUE * argv, VALUE self)
{
FRAME_SETUP;
return dc_frame_binding(context, frame_n);
}
|
#frame_class(frame_position = 0) ⇒ Binding
Returns frame’s defined class.
225 226 227 228 229 230 231 |
# File 'ext/byebug/context.c', line 225
static VALUE
Context_frame_class(int argc, VALUE * argv, VALUE self)
{
FRAME_SETUP;
return dc_frame_class(context, frame_n);
}
|
#frame_file(frame_position = 0) ⇒ String
Returns the name of the file in the frame.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'ext/byebug/context.c', line 239
static VALUE
Context_frame_file(int argc, VALUE * argv, VALUE self)
{
VALUE loc, absolute_path;
FRAME_SETUP;
loc = dc_frame_location(context, frame_n);
absolute_path = rb_funcall(loc, rb_intern("absolute_path"), 0);
if (!NIL_P(absolute_path))
return absolute_path;
return rb_funcall(loc, rb_intern("path"), 0);
}
|
#frame_line(frame_position = 0) ⇒ Integer
Returns the line number in the file.
262 263 264 265 266 267 268 269 270 271 272 |
# File 'ext/byebug/context.c', line 262
static VALUE
Context_frame_line(int argc, VALUE * argv, VALUE self)
{
VALUE loc;
FRAME_SETUP;
loc = dc_frame_location(context, frame_n);
return rb_funcall(loc, rb_intern("lineno"), 0);
}
|
#frame_locals(frame_no = 0) ⇒ Object
Gets local variables for a frame.
TODO: Use brand new local_variable_get,set,defined? for rubies >= 2.1
54 55 56 57 58 59 |
# File 'lib/byebug/context.rb', line 54 def frame_locals(frame_no = 0) bind = frame_binding(frame_no) return [] unless bind bind.eval('local_variables.inject({}){|h, v| h[v] = eval(v.to_s); h}') end |
#frame_method(frame_position = 0) ⇒ Object
Returns the sym of the called method.
280 281 282 283 284 285 286 287 288 289 290 |
# File 'ext/byebug/context.c', line 280
static VALUE
Context_frame_method(int argc, VALUE * argv, VALUE self)
{
VALUE loc;
FRAME_SETUP;
loc = dc_frame_location(context, frame_n);
return rb_str_intern(rb_funcall(loc, rb_intern("label"), 0));
}
|
#frame_self(frame_postion = 0) ⇒ Object
Returns self object of the frame.
298 299 300 301 302 303 304 |
# File 'ext/byebug/context.c', line 298
static VALUE
Context_frame_self(int argc, VALUE * argv, VALUE self)
{
FRAME_SETUP;
return dc_frame_self(context, frame_n);
}
|
#handler ⇒ Object
73 74 75 |
# File 'lib/byebug/context.rb', line 73 def handler Byebug.handler || fail('No interface loaded') end |
#ignored? ⇒ Boolean
#ignored_file?(path) ⇒ Boolean
Tells whether a file is ignored by the debugger.
28 29 30 |
# File 'lib/byebug/context.rb', line 28 def ignored_file?(path) self.class.ignored_files.include?(path) end |
#interrupt ⇒ Object
43 44 45 |
# File 'lib/byebug/context.rb', line 43 def interrupt step_into 1 end |
#resume ⇒ nil
Resumes thread from the suspended mode.
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'ext/byebug/context.c', line 328
static VALUE
Context_resume(VALUE self)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (!CTX_FL_TEST(context, CTX_FL_SUSPEND))
return Qnil;
CTX_FL_UNSET(context, CTX_FL_SUSPEND);
if (CTX_FL_TEST(context, CTX_FL_WAS_RUNNING))
rb_thread_wakeup(context->thread);
return Qnil;
}
|
#stack_size ⇒ Object
Context’s stack size
35 36 37 38 39 40 41 |
# File 'lib/byebug/context.rb', line 35 def stack_size return 0 unless backtrace backtrace.drop_while { |l| ignored_file?(l.first.path) } .take_while { |l| !ignored_file?(l.first.path) } .size end |
#step_into(steps, frame = 0) ⇒ Object
Stops the current context after a number of steps
are made from frame frame
(by default the newest one).
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'ext/byebug/context.c', line 398
static VALUE
Context_step_into(int argc, VALUE * argv, VALUE self)
{
VALUE steps, v_frame;
int n_args, from_frame;
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (context->calced_stack_size == 0)
rb_raise(rb_eRuntimeError, "No frames collected.");
n_args = rb_scan_args(argc, argv, "11", &steps, &v_frame);
if (FIX2INT(steps) <= 0)
rb_raise(rb_eRuntimeError, "Steps argument can't be negative.");
from_frame = n_args == 1 ? 0 : FIX2INT(v_frame);
if (from_frame < 0 || from_frame >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Destination frame (%d) is out of range (%d)",
from_frame, context->calced_stack_size);
else if (from_frame > 0)
CTX_FL_SET(context, CTX_FL_IGNORE_STEPS);
context->steps = FIX2INT(steps);
context->dest_frame = context->calced_stack_size - from_frame;
return steps;
}
|
#step_out(n_frames = 1, force = false) ⇒ Object
Stops after n_frames
frames are finished. force
parameter (if true) ensures that the execution will stop in the specified frame even when there are no more instructions to run. In that case, it will stop when the return event for that frame is triggered.
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'ext/byebug/context.c', line 438
static VALUE
Context_step_out(int argc, VALUE * argv, VALUE self)
{
int n_args, n_frames;
VALUE v_frames, force;
debug_context_t *context;
n_args = rb_scan_args(argc, argv, "02", &v_frames, &force);
n_frames = n_args == 0 ? 1 : FIX2INT(v_frames);
Data_Get_Struct(self, debug_context_t, context);
if (n_frames < 0 || n_frames > context->calced_stack_size)
rb_raise(rb_eRuntimeError,
"You want to finish %d frames, but stack size is only %d",
n_frames, context->calced_stack_size);
context->steps_out = n_frames;
if (n_args == 2 && RTEST(force))
CTX_FL_SET(context, CTX_FL_STOP_ON_RET);
else
CTX_FL_UNSET(context, CTX_FL_STOP_ON_RET);
return Qnil;
}
|
#step_over(lines, frame = 0) ⇒ Object
Steps over lines
lines in frame frame
(by default the newest one) or higher (if frame frame
finishes).
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'ext/byebug/context.c', line 471
static VALUE
Context_step_over(int argc, VALUE * argv, VALUE self)
{
int n_args, frame;
VALUE lines, v_frame;
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (context->calced_stack_size == 0)
rb_raise(rb_eRuntimeError, "No frames collected.");
n_args = rb_scan_args(argc, argv, "11", &lines, &v_frame);
frame = n_args == 1 ? 0 : FIX2INT(v_frame);
if (frame < 0 || frame >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Destination frame (%d) is out of range (%d)",
frame, context->calced_stack_size);
context->lines = FIX2INT(lines);
context->dest_frame = context->calced_stack_size - frame;
return Qnil;
}
|
#stop_reason ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'ext/byebug/context.c', line 362
static VALUE
Context_stop_reason(VALUE self)
{
debug_context_t *context;
const char *symbol;
Data_Get_Struct(self, debug_context_t, context);
if (CTX_FL_TEST(context, CTX_FL_DEAD))
symbol = "post-mortem";
else
switch (context->stop_reason)
{
case CTX_STOP_STEP:
symbol = "step";
break;
case CTX_STOP_BREAKPOINT:
symbol = "breakpoint";
break;
case CTX_STOP_CATCHPOINT:
symbol = "catchpoint";
break;
case CTX_STOP_NONE:
default:
symbol = "none";
}
return ID2SYM(rb_intern(symbol));
}
|
#suspend ⇒ nil
Suspends the thread when it is running.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'ext/byebug/context.c', line 502
static VALUE
Context_suspend(VALUE self)
{
VALUE status;
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
status = rb_funcall(context->thread, rb_intern("status"), 0);
if (rb_str_cmp(status, rb_str_new2("run")) == 0)
CTX_FL_SET(context, CTX_FL_WAS_RUNNING);
else if (rb_str_cmp(status, rb_str_new2("sleep")) == 0)
CTX_FL_UNSET(context, CTX_FL_WAS_RUNNING);
else
return Qnil;
CTX_FL_SET(context, CTX_FL_SUSPEND);
return Qnil;
}
|
#suspended? ⇒ Boolean
Returns true
if the thread is suspended by debugger.
552 553 554 555 556 557 558 559 560 |
# File 'ext/byebug/context.c', line 552
static VALUE
Context_is_suspended(VALUE self)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
return CTX_FL_TEST(context, CTX_FL_SUSPEND) ? Qtrue : Qfalse;
}
|
#switch ⇒ nil
Switches execution to this context.
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'ext/byebug/context.c', line 530
static VALUE
Context_switch(VALUE self)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
next_thread = context->thread;
context->steps = 1;
context->steps_out = 0;
CTX_FL_SET(context, CTX_FL_STOP_ON_RET);
return Qnil;
}
|
#thnum ⇒ Object
#thread ⇒ Object
#tracing ⇒ Boolean
Returns the tracing flag for the current context.
598 599 600 601 602 603 604 605 |
# File 'ext/byebug/context.c', line 598
static VALUE
Context_tracing(VALUE self)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
return CTX_FL_TEST(context, CTX_FL_TRACING) ? Qtrue : Qfalse;
}
|
#tracing=(bool) ⇒ Object
Controls the tracing for this context.
613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'ext/byebug/context.c', line 613
static VALUE
Context_set_tracing(VALUE self, VALUE value)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (RTEST(value))
CTX_FL_SET(context, CTX_FL_TRACING);
else
CTX_FL_UNSET(context, CTX_FL_TRACING);
return value;
}
|