Class: Byebug::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/byebug/context.rb,
ext/byebug/context.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ignored(path) ⇒ Object



20
21
22
# File 'lib/byebug/context.rb', line 20

def ignored(path)
  IGNORED_FILES.include?(path)
end

.stack_size(byebug_frames = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/byebug/context.rb', line 6

def stack_size(byebug_frames = false)
  if backtrace = Thread.current.backtrace_locations(0)
    unless byebug_frames
      backtrace = backtrace.drop_while { |l| !ignored(l.path) }
                           .drop_while { |l|  ignored(l.path) }
                           .take_while { |l| !ignored(l.path) }
    end
    backtrace.size
  else
    print 'WARNING: No backtrace available!!'
    0
  end
end

Instance Method Details

#at_breakpoint(brkpnt) ⇒ Object



65
66
67
# File 'lib/byebug/context.rb', line 65

def at_breakpoint(brkpnt)
  handler.at_breakpoint(self, brkpnt)
end

#at_catchpoint(excpt) ⇒ Object



69
70
71
# File 'lib/byebug/context.rb', line 69

def at_catchpoint(excpt)
  handler.at_catchpoint(self, excpt)
end

#at_line(file, line) ⇒ Object



77
78
79
# File 'lib/byebug/context.rb', line 77

def at_line(file, line)
  handler.at_line(self, file, line)
end

#at_return(file, line) ⇒ Object



81
82
83
# File 'lib/byebug/context.rb', line 81

def at_return(file, line)
  handler.at_return(self, file, line)
end

#at_tracing(file, line) ⇒ Object



73
74
75
# File 'lib/byebug/context.rb', line 73

def at_tracing(file, line)
  handler.at_tracing(self, file, line)
end

#c_frame_args(frame_no) ⇒ Object



35
36
37
38
39
# File 'lib/byebug/context.rb', line 35

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_sizeObject

#dead?Boolean

Returns:

  • (Boolean)

#frame_args(frame_no = 0) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/byebug/context.rb', line 52

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.

Returns:

  • (Binding)


207
208
209
210
211
212
213
# File 'ext/byebug/context.c', line 207

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.

Returns:

  • (Binding)


221
222
223
224
225
226
227
# File 'ext/byebug/context.c', line 221

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.

Returns:

  • (String)


235
236
237
238
239
240
241
242
243
244
245
# File 'ext/byebug/context.c', line 235

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.

Returns:

  • (Integer)


253
254
255
256
257
258
259
260
261
262
263
# File 'ext/byebug/context.c', line 253

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



30
31
32
33
# File 'lib/byebug/context.rb', line 30

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.



271
272
273
274
275
276
277
278
279
280
281
# File 'ext/byebug/context.c', line 271

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.

Returns:

  • (Object)


289
290
291
292
293
294
295
# File 'ext/byebug/context.c', line 289

static VALUE
Context_frame_self(int argc, VALUE *argv, VALUE self)
{
  FRAME_SETUP

  return dc_frame_self(context, frame_n);
}

#handlerObject



61
62
63
# File 'lib/byebug/context.rb', line 61

def handler
  Byebug.handler or raise 'No interface loaded'
end

#ignored?Boolean

Returns:

  • (Boolean)

#interruptObject



26
27
28
# File 'lib/byebug/context.rb', line 26

def interrupt
  self.step_into 1
end

#resumenil

Resumes thread from the suspended mode.

Returns:

  • (nil)


329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'ext/byebug/context.c', line 329

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/byebug/context.rb', line 41

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.message}\" " \
          "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.



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'ext/byebug/context.c', line 398

static VALUE
Context_step_into(int argc, VALUE *argv, VALUE self)
{
  VALUE steps, 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 n_frames frames are finished. Implements finish and next commands. force parameter (if true) ensures that the cursor will stop in the specified frame even when there’s no more instructions to run. In that case, it will stop when the return event for that frame is triggered.



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'ext/byebug/context.c', line 429

static VALUE
Context_step_out(int argc, VALUE *argv, VALUE self)
{
  int n_args, n_frames;
  VALUE v_frames, v_force;
  debug_context_t *context;

  n_args = rb_scan_args(argc, argv, "02", &v_frames, &v_force);
  n_frames = n_args == 0 ? 1 : FIX2INT(v_frames);
  v_force = (n_args < 2) ? Qfalse : v_force;

  Data_Get_Struct(self, debug_context_t, context);

  if (n_frames < 0 || n_frames >= context->calced_stack_size)
    rb_raise(rb_eRuntimeError, "Stop frame is out of range.");

  context->steps_out = n_frames;
  if (RTEST(v_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 = 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.



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'ext/byebug/context.c', line 463

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_reasonObject



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
# 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));
}

#suspendnil

Suspends the thread when it is running.

Returns:

  • (nil)


510
511
512
513
514
515
516
517
518
519
520
521
# File 'ext/byebug/context.c', line 510

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.

Returns:

  • (Boolean)


529
530
531
532
533
534
535
536
# File 'ext/byebug/context.c', line 529

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;
}

#thnumObject

#threadObject

#tracingBoolean

Returns the tracing flag for the current context.

Returns:

  • (Boolean)


571
572
573
574
575
576
577
578
# File 'ext/byebug/context.c', line 571

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.



586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'ext/byebug/context.c', line 586

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;
}