Class: Byebug::Context
- Inherits:
-
Object
- Object
- Byebug::Context
- Defined in:
- lib/byebug/context.rb,
ext/byebug/context.c
Class Method Summary collapse
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
- #c_frame_args(frame_no) ⇒ Object
- #calced_stack_size ⇒ Object
- #dead? ⇒ Boolean
- #frame_args(frame_no = 0) ⇒ Object
-
#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) ⇒ Integer
Returns the line number in the file.
- #frame_locals(frame_no = 0) ⇒ Object
-
#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
-
#resume ⇒ nil
Resumes thread from the suspended mode.
- #ruby_frame_args(bind) ⇒ Object
-
#step_into(steps, force = false) ⇒ Object
Stops the current context after a number of
steps
are made. -
#step_out(frame) ⇒ Object
Stops after frame number
frame
is activated. -
#step_over(lines, frame = nil, force = false) ⇒ Object
Steps over
lines
lines. - #stop_reason ⇒ Object
-
#stop_return(frame) ⇒ Object
Stops before frame number
frame
is activated. -
#suspend ⇒ nil
Suspends the thread when it is running.
-
#suspended? ⇒ Boolean
Returns
true
if the thread is suspended by debugger. - #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
.ignored(path) ⇒ Object
23 24 25 |
# File 'lib/byebug/context.rb', line 23 def ignored(path) IGNORED_FILES.include?(path) end |
.real_stack_size ⇒ Object
17 18 19 20 21 |
# File 'lib/byebug/context.rb', line 17 def real_stack_size if backtrace = Thread.current.backtrace_locations(1) backtrace.size end end |
.stack_size ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/byebug/context.rb', line 6 def stack_size if backtrace = Thread.current.backtrace_locations(1) backtrace.drop_while { |l| ignored(l.path) || l.path == '(eval)' } .take_while { |l| !ignored(l.path) } .size else print 'No backtrace available!!' 0 end end |
Instance Method Details
#at_breakpoint(brkpnt) ⇒ Object
64 65 66 |
# File 'lib/byebug/context.rb', line 64 def at_breakpoint(brkpnt) handler.at_breakpoint(self, brkpnt) end |
#at_catchpoint(excpt) ⇒ Object
68 69 70 |
# File 'lib/byebug/context.rb', line 68 def at_catchpoint(excpt) handler.at_catchpoint(self, excpt) end |
#at_line(file, line) ⇒ Object
76 77 78 |
# File 'lib/byebug/context.rb', line 76 def at_line(file, line) handler.at_line(self, file, line) unless IGNORED_FILES.include?(file) end |
#at_return(file, line) ⇒ Object
80 81 82 |
# File 'lib/byebug/context.rb', line 80 def at_return(file, line) handler.at_return(self, file, line) unless IGNORED_FILES.include?(file) end |
#at_tracing(file, line) ⇒ Object
72 73 74 |
# File 'lib/byebug/context.rb', line 72 def at_tracing(file, line) handler.at_tracing(self, file, line) unless IGNORED_FILES.include?(file) end |
#c_frame_args(frame_no) ⇒ Object
34 35 36 37 38 |
# File 'lib/byebug/context.rb', line 34 def c_frame_args frame_no myself = frame_self frame_no return [] unless myself.to_s != 'main' myself.send(:method, frame_method(frame_no)).parameters end |
#calced_stack_size ⇒ Object
#dead? ⇒ Boolean
#frame_args(frame_no = 0) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/byebug/context.rb', line 51 def frame_args frame_no = 0 bind = frame_binding frame_no if bind.nil? c_frame_args frame_no else ruby_frame_args bind end end |
#frame_binding(frame_position = 0) ⇒ Binding
Returns frame’s binding.
214 215 216 217 218 219 220 |
# File 'ext/byebug/context.c', line 214
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.
228 229 230 231 232 233 234 |
# File 'ext/byebug/context.c', line 228
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.
242 243 244 245 246 247 248 249 250 251 252 |
# File 'ext/byebug/context.c', line 242
static VALUE
Context_frame_file(int argc, VALUE *argv, VALUE self)
{
VALUE loc;
FRAME_SETUP
loc = dc_frame_location(context, frame_n);
return rb_funcall(loc, rb_intern("path"), 0);
}
|
#frame_line(frame_position) ⇒ Integer
Returns the line number in the file.
260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/byebug/context.c', line 260
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
29 30 31 32 |
# File 'lib/byebug/context.rb', line 29 def frame_locals frame_no = 0 bind = frame_binding frame_no eval "local_variables.inject({}){|h, v| h[v] = eval(v.to_s); h}", bind end |
#frame_method(frame_position = 0) ⇒ Object
Returns the sym of the called method.
278 279 280 281 282 283 284 285 286 287 288 |
# File 'ext/byebug/context.c', line 278
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.
296 297 298 299 300 301 302 |
# File 'ext/byebug/context.c', line 296
static VALUE
Context_frame_self(int argc, VALUE *argv, VALUE self)
{
FRAME_SETUP
return dc_frame_self(context, frame_n);
}
|
#handler ⇒ Object
60 61 62 |
# File 'lib/byebug/context.rb', line 60 def handler Byebug.handler or raise 'No interface loaded' end |
#ignored? ⇒ Boolean
#resume ⇒ nil
Resumes thread from the suspended mode.
336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'ext/byebug/context.c', line 336
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))
rb_raise(rb_eRuntimeError, "Thread is not suspended.");
context_resume_0(context);
return Qnil;
}
|
#ruby_frame_args(bind) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/byebug/context.rb', line 40 def ruby_frame_args bind return [] unless eval '__method__', bind begin eval "self.method(__method__).parameters", bind rescue NameError => e print "WARNING: Got exception #{e.class}: \"#{e.}\" " \ "while retreving parameters from frame\n" return [] end end |
#step_into(steps, force = false) ⇒ Object
Stops the current context after a number of steps
are made. force
parameter (if true) ensures that the cursor moves away from the current line.
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'ext/byebug/context.c', line 405
static VALUE
Context_step_into(int argc, VALUE *argv, VALUE self)
{
VALUE steps;
VALUE force;
debug_context_t *context;
rb_scan_args(argc, argv, "11", &steps, &force);
if (FIX2INT(steps) < 0)
rb_raise(rb_eRuntimeError, "Steps argument can't be negative.");
Data_Get_Struct(self, debug_context_t, context);
context->steps = FIX2INT(steps);
if (RTEST(force))
CTX_FL_SET(context, CTX_FL_FORCE_MOVE);
else
CTX_FL_UNSET(context, CTX_FL_FORCE_MOVE);
return steps;
}
|
#step_out(frame) ⇒ Object
Stops after frame number frame
is activated. Implements finish
and next
commands.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'ext/byebug/context.c', line 434
static VALUE
Context_step_out(VALUE self, VALUE frame)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
context->after_frame = context->calced_stack_size - FIX2INT(frame);
return frame;
}
|
#step_over(lines, frame = nil, force = false) ⇒ Object
Steps over lines
lines. Make step over operation on frame
, by default the current frame. force
parameter (if true) ensures that the cursor moves away from the current line.
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'ext/byebug/context.c', line 458
static VALUE
Context_step_over(int argc, VALUE *argv, VALUE self)
{
VALUE lines, frame, force;
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.");
rb_scan_args(argc, argv, "12", &lines, &frame, &force);
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Destination frame is out of range.");
context->lines = FIX2INT(lines);
context->dest_frame = context->calced_stack_size - FIX2INT(frame);
if (RTEST(force))
CTX_FL_SET(context, CTX_FL_FORCE_MOVE);
else
CTX_FL_UNSET(context, CTX_FL_FORCE_MOVE);
return Qnil;
}
|
#stop_reason ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'ext/byebug/context.c', line 369
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));
}
|
#stop_return(frame) ⇒ Object
Stops before frame number frame
is activated. Useful when you enter the debugger after the last statement in a method.
491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'ext/byebug/context.c', line 491
static VALUE
Context_stop_return(VALUE self, VALUE frame)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
context->before_frame = context->calced_stack_size - FIX2INT(frame);
return frame;
}
|
#suspend ⇒ nil
Suspends the thread when it is running.
526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'ext/byebug/context.c', line 526
static VALUE
Context_suspend(VALUE self)
{
debug_context_t *context;
Data_Get_Struct(self, debug_context_t, context);
if (CTX_FL_TEST(context, CTX_FL_SUSPEND))
rb_raise(rb_eRuntimeError, "Already suspended.");
context_suspend_0(context);
return Qnil;
}
|
#suspended? ⇒ Boolean
Returns true
if the thread is suspended by debugger.
545 546 547 548 549 550 551 552 |
# File 'ext/byebug/context.c', line 545
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;
}
|
#thnum ⇒ Object
#thread ⇒ Object
#tracing ⇒ Boolean
Returns the tracing flag for the current context.
587 588 589 590 591 592 593 594 |
# File 'ext/byebug/context.c', line 587
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.
602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'ext/byebug/context.c', line 602
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;
}
|