Module: Byebug

Defined in:
ext/byebug/byebug.c

Defined Under Namespace

Classes: Breakpoint, DebugThread, ThreadsTable

Class Method Summary collapse

Class Method Details

.start_Boolean .start_ { ... } ⇒ Boolean

This method is internal and activates the debugger. Use Byebug.start (from lib/byebug.rb) instead.

The return value is the value of !Byebug.started? before issuing the start; That is, true is returned, unless byebug was previously started.

If a block is given, it starts byebug and yields to block. When the block is finished executing it stops the debugger with Byebug.stop method.

Overloads:

  • .start_Boolean

    Returns:

    • (Boolean)
  • .start_ { ... } ⇒ Boolean

    Yields:

    Returns:

    • (Boolean)


559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'ext/byebug/byebug.c', line 559

static VALUE
bb_start(VALUE self)
{
  VALUE result;

  if (IS_STARTED)
    result = Qfalse;
  else
  {
    locker      = Qnil;
    breakpoints = rb_ary_new();
    catchpoints = rb_hash_new();
    threads     = threads_create();

    register_tracepoints(self);
    result = Qtrue;
  }

  if (rb_block_given_p())
    rb_ensure(rb_yield, self, bb_stop, self);

  return result;
}

.add_catchpoint(exception) ⇒ Exception

Adds a new exception to the catchpoints array.

Returns:



788
789
790
791
792
793
794
795
796
# File 'ext/byebug/byebug.c', line 788

static VALUE
bb_add_catchpoint(VALUE self, VALUE value)
{
  if (TYPE(value) != T_STRING)
    rb_raise(rb_eTypeError, "value of a catchpoint must be String");

  rb_hash_aset(catchpoints, rb_str_dup(value), INT2FIX(0));
  return value;
}

.breakpointsArray

Returns an array of breakpoints.

Returns:

  • (Array)


764
765
766
767
768
# File 'ext/byebug/byebug.c', line 764

static VALUE
bb_breakpoints(VALUE self)
{
  return breakpoints;
}

.catchpointsArray

Returns an array of catchpoints.

Returns:

  • (Array)


776
777
778
779
780
# File 'ext/byebug/byebug.c', line 776

static VALUE
bb_catchpoints(VALUE self)
{
  return catchpoints;
}

.contextsArray

Returns an array of all contexts.

Returns:

  • (Array)


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
463
464
465
466
467
468
469
470
471
# File 'ext/byebug/byebug.c', line 438

static VALUE
bb_contexts(VALUE self)
{
  volatile VALUE list;
  volatile VALUE new_list;
  VALUE context;
  threads_table_t *t_tbl;
  debug_context_t *dc;
  int i;

  check_started();

  new_list = rb_ary_new();
  list = rb_funcall(rb_cThread, rb_intern("list"), 0);

  for (i = 0; i < RARRAY_LEN(list); i++)
  {
    VALUE thread = rb_ary_entry(list, i);
    thread_context_lookup(thread, &context);
    rb_ary_push(new_list, context);
  }

  threads_clear(threads);
  Data_Get_Struct(threads, threads_table_t, t_tbl);

  for (i = 0; i < RARRAY_LEN(new_list); i++)
  {
    context = rb_ary_entry(new_list, i);
    Data_Get_Struct(context, debug_context_t, dc);
    st_insert(t_tbl->tbl, dc->thread, context);
  }

  return new_list;
}

.current_contextObject

Returns the current context.

<i>Note:</i> Byebug.current_context.thread == Thread.current


498
499
500
501
502
503
504
505
506
507
508
# File 'ext/byebug/byebug.c', line 498

static VALUE
bb_current_context(VALUE self)
{
  VALUE context;

  check_started();

  thread_context_lookup(rb_thread_current(), &context);

  return context;
}

.debug_at_exit { ... } ⇒ Proc

Register at_exit hook which is escaped from byebug.

Yields:

Returns:

  • (Proc)


696
697
698
699
700
701
702
703
704
705
706
# File 'ext/byebug/byebug.c', line 696

static VALUE
bb_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) ⇒ nil

Same as Kernel#load but resets current context’s frames. stop parameter forces byebug to stop at the first line of code in file

Returns:

  • (nil)


590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# File 'ext/byebug/byebug.c', line 590

static VALUE
bb_load(int argc, VALUE *argv, VALUE self)
{
  VALUE file, stop, context;
  debug_context_t *dc;
  VALUE status = Qnil;
  int state = 0;

  if (rb_scan_args(argc, argv, "11", &file, &stop) == 1)
  {
    stop = Qfalse;
  }

  bb_start(self);

  context = bb_current_context(self);
  Data_Get_Struct(context, debug_context_t, dc);

  if (RTEST(stop)) dc->steps = 1;

  /* Reset stack size to ignore byebug's own frames */
  dc->stack_size = 0;

  /* Initializing $0 to the script's path */
  ruby_script(RSTRING_PTR(file));
  rb_load_protect(file, 0, &state);
  if (0 != state)
  {
    status = rb_errinfo();
    reset_stepping_stop_points(dc);
  }

  /* 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();

  return status;
}

.post_mortem=(bool) ⇒ Object

Sets post-moterm flag.



751
752
753
754
755
756
# File 'ext/byebug/byebug.c', line 751

static VALUE
bb_set_post_mortem(VALUE self, VALUE value)
{
  post_mortem = RTEST(value) ? Qtrue : Qfalse;
  return value;
}

.post_mortem?Boolean

Returns true if post-moterm debugging is enabled.

Returns:

  • (Boolean)


739
740
741
742
743
# File 'ext/byebug/byebug.c', line 739

static VALUE
bb_post_mortem(VALUE self)
{
  return post_mortem;
}

.started?Boolean

Returns true byebug is started.

Returns:

  • (Boolean)


516
517
518
519
520
# File 'ext/byebug/byebug.c', line 516

static VALUE
bb_started(VALUE self)
{
  return IS_STARTED;
}

.stopBoolean

This method disables byebug. It returns true if byebug was already disabled, otherwise it returns false.

Returns:

  • (Boolean)


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'ext/byebug/byebug.c', line 529

static VALUE
bb_stop(VALUE self)
{
  if (IS_STARTED)
  {
    clear_tracepoints(self);

    breakpoints = Qnil;
    catchpoints = Qnil;
    threads     = Qnil;

    return Qfalse;
  }
  return Qtrue;
}

.thread_context(thread) ⇒ Object

Returns context of the thread passed as an argument.



479
480
481
482
483
484
485
486
487
488
489
# File 'ext/byebug/byebug.c', line 479

static VALUE
bb_thread_context(VALUE self, VALUE thread)
{
  VALUE context;

  check_started();

  thread_context_lookup(thread, &context);

  return context;
}

.tracing=(bool) ⇒ Object

Sets the global tracing flag.



726
727
728
729
730
731
# File 'ext/byebug/byebug.c', line 726

static VALUE
bb_set_tracing(VALUE self, VALUE value)
{
  tracing = RTEST(value) ? Qtrue : Qfalse;
  return value;
}

.tracingBoolean

Returns true if global tracing is enabled.

Returns:

  • (Boolean)


714
715
716
717
718
# File 'ext/byebug/byebug.c', line 714

static VALUE
bb_tracing(VALUE self)
{
  return tracing;
}

.verboseBoolean

Returns true if verbose output of TracePoint API events is enabled.

Returns:

  • (Boolean)


635
636
637
638
639
# File 'ext/byebug/byebug.c', line 635

static VALUE
bb_verbose(VALUE self)
{
  return verbose;
}

.verbose=(bool) ⇒ Object

Enable verbose output of every TracePoint API events, useful for debugging byebug.



648
649
650
651
652
653
# File 'ext/byebug/byebug.c', line 648

static VALUE
bb_set_verbose(VALUE self, VALUE value)
{
  verbose = RTEST(value) ? Qtrue : Qfalse;
  return value;
}