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
- #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
- #stack_size ⇒ Object
-
#step_into(steps, force = false) ⇒ Object
Stops the current context after a number of
stepsare made. -
#step_out(frame) ⇒ Object
Stops after frame number
frameis activated. -
#step_over(lines, frame = nil, force = false) ⇒ Object
Steps over
lineslines. - #stop_reason ⇒ Object
-
#stop_return(frame) ⇒ Object
Stops before frame number
frameis activated. -
#suspend ⇒ nil
Suspends the thread when it is running.
-
#suspended? ⇒ Boolean
Returns
trueif 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
14 15 16 |
# File 'lib/byebug/context.rb', line 14 def ignored(path) IGNORED_FILES.include?(path) end |
.real_stack_size ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/byebug/context.rb', line 6 def real_stack_size if backtrace = Thread.current.backtrace_locations backtrace.drop_while { |l| ignored(l.path) || l.path == '(eval)' } .take_while { |l| !ignored(l.path) } .size end end |
Instance Method Details
#at_breakpoint(brkpnt) ⇒ Object
55 56 57 |
# File 'lib/byebug/context.rb', line 55 def at_breakpoint(brkpnt) handler.at_breakpoint(self, brkpnt) end |
#at_catchpoint(excpt) ⇒ Object
59 60 61 |
# File 'lib/byebug/context.rb', line 59 def at_catchpoint(excpt) handler.at_catchpoint(self, excpt) end |
#at_line(file, line) ⇒ Object
67 68 69 |
# File 'lib/byebug/context.rb', line 67 def at_line(file, line) handler.at_line(self, file, line) unless IGNORED_FILES.include?(file) end |
#at_return(file, line) ⇒ Object
71 72 73 |
# File 'lib/byebug/context.rb', line 71 def at_return(file, line) handler.at_return(self, file, line) unless IGNORED_FILES.include?(file) end |
#at_tracing(file, line) ⇒ Object
63 64 65 |
# File 'lib/byebug/context.rb', line 63 def at_tracing(file, line) handler.at_tracing(self, file, line) unless IGNORED_FILES.include?(file) end |
#c_frame_args(frame_no) ⇒ Object
25 26 27 28 29 |
# File 'lib/byebug/context.rb', line 25 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 |
#dead? ⇒ Boolean
#frame_args(frame_no = 0) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/byebug/context.rb', line 42 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.
213 214 215 216 217 218 219 |
# File 'ext/byebug/context.c', line 213
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.
227 228 229 230 231 232 233 |
# File 'ext/byebug/context.c', line 227
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.
241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/byebug/context.c', line 241
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.
259 260 261 262 263 264 265 266 267 268 269 |
# File 'ext/byebug/context.c', line 259
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
20 21 22 23 |
# File 'lib/byebug/context.rb', line 20 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.
277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/byebug/context.c', line 277
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.
295 296 297 298 299 300 301 |
# File 'ext/byebug/context.c', line 295
static VALUE
Context_frame_self(int argc, VALUE *argv, VALUE self)
{
FRAME_SETUP
return dc_frame_self(context, frame_n);
}
|
#handler ⇒ Object
51 52 53 |
# File 'lib/byebug/context.rb', line 51 def handler Byebug.handler or raise 'No interface loaded' end |
#ignored? ⇒ Boolean
#resume ⇒ nil
Resumes thread from the suspended mode.
335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'ext/byebug/context.c', line 335
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
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/byebug/context.rb', line 31 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 |
#stack_size ⇒ Object
#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.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/byebug/context.c', line 401
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.
430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'ext/byebug/context.c', line 430
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->stack_size)
rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
context->after_frame = context->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.
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'ext/byebug/context.c', line 453
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->stack_size == 0)
rb_raise(rb_eRuntimeError, "No frames collected.");
rb_scan_args(argc, argv, "12", &lines, &frame, &force);
context->lines = FIX2INT(lines);
if (FIX2INT(frame) < 0 || FIX2INT(frame) >= context->stack_size)
rb_raise(rb_eRuntimeError, "Destination frame is out of range.");
context->dest_frame = context->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
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 390 391 |
# File 'ext/byebug/context.c', line 365
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.
486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'ext/byebug/context.c', line 486
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->stack_size)
rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
context->before_frame = context->stack_size - FIX2INT(frame);
return frame;
}
|
#suspend ⇒ nil
Suspends the thread when it is running.
521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'ext/byebug/context.c', line 521
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.
540 541 542 543 544 545 546 547 |
# File 'ext/byebug/context.c', line 540
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.
582 583 584 585 586 587 588 589 |
# File 'ext/byebug/context.c', line 582
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.
597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'ext/byebug/context.c', line 597
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;
}
|