Class: Debugger::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-debug.rb,
ext/ruby_debug.c

Instance Method Summary collapse

Instance Method Details

#dead?( = bool) ⇒ Boolean

Returns true if context doesn’t represent a live context and is created during post-mortem exception handling.

Returns:

  • (Boolean)


1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
# File 'ext/ruby_debug.c', line 1909

static VALUE
context_dead(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    return CTX_FL_TEST(debug_context, CTX_FL_DEAD) ? Qtrue : Qfalse;
}

#frame_binding(frame) ⇒ Binding

Returns frame’s binding.

Returns:

  • (Binding)


1585
1586
1587
1588
1589
1590
1591
1592
1593
# File 'ext/ruby_debug.c', line 1585

static VALUE
context_frame_binding(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    return GET_FRAME->binding;
}

#frame_file(frame) ⇒ String

Returns the name of the file.

Returns:

  • (String)


1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
# File 'ext/ruby_debug.c', line 1638

static VALUE
context_frame_file(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);

    return rb_str_new2(GET_FRAME->file);
}

#frame_id(frame) ⇒ Object

Returns the sym of the called method.



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
# File 'ext/ruby_debug.c', line 1601

static VALUE
context_frame_id(VALUE self, VALUE frame)
{

    debug_context_t *debug_context;
    ID id;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);

    id = GET_FRAME->id;
    return id ? ID2SYM(id): Qnil;
}

#frame_line(frame) ⇒ Integer

Returns the line number in the file.

Returns:

  • (Integer)


1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
# File 'ext/ruby_debug.c', line 1621

static VALUE
context_frame_line(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);

    return INT2FIX(GET_FRAME->line);
}

#frame_locals(frame) ⇒ Hash

Returns frame’s local variables.

Returns:

  • (Hash)


1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
# File 'ext/ruby_debug.c', line 1685

static VALUE
context_frame_locals(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;
    debug_frame_t *debug_frame;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    
    debug_frame = GET_FRAME;
    if(debug_frame->dead)
	return debug_frame->info.copy.locals;
    else
	return context_copy_locals(debug_frame);
}

#frame_self(frame) ⇒ Object

Returns self object of the frame.

Returns:

  • (Object)


1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
# File 'ext/ruby_debug.c', line 1707

static VALUE
context_frame_self(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;
    debug_frame_t *debug_frame;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);

    debug_frame = GET_FRAME;
    return debug_frame->self;
}

#ignoreBoolean

Returns the ignore flag for the current context.

Returns:

  • (Boolean)


1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
# File 'ext/ruby_debug.c', line 1870

static VALUE
context_ignore(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    return CTX_FL_TEST(debug_context, CTX_FL_IGNORE) ? Qtrue : Qfalse;
}

#tracking=(bool) ⇒ Object

Controls the ignore flag for this context.



1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
# File 'ext/ruby_debug.c', line 1887

static VALUE
context_set_ignore(VALUE self, VALUE value)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    if(RTEST(value))
        CTX_FL_SET(debug_context, CTX_FL_IGNORE);
    else
        CTX_FL_UNSET(debug_context, CTX_FL_IGNORE);
    return value;
}

#interruptObject



18
19
20
# File 'lib/ruby-debug.rb', line 18

def interrupt
  self.stop_next = 1
end

#resumenil

Resumes the thread from the suspended mode.

Returns:

  • (nil)


1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
# File 'ext/ruby_debug.c', line 1811

static VALUE
context_resume(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    if(!CTX_FL_TEST(debug_context, CTX_FL_SUSPEND))
        rb_raise(rb_eRuntimeError, "Thread is not suspended.");
    CTX_FL_UNSET(debug_context, CTX_FL_SUSPEND);
    rb_thread_run(context_thread_0(debug_context));
    return Qnil;
}

#stack_sizeObject

Returns the size of the context stack.



1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
# File 'ext/ruby_debug.c', line 1726

static VALUE
context_stack_size(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);

    return INT2FIX(debug_context->stack_size);
}

#step_over(steps) ⇒ Object

Steps over a steps number of times.



1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
# File 'ext/ruby_debug.c', line 1520

static VALUE
context_step_over(int argc, VALUE *argv, VALUE self)
{
    VALUE lines, frame;
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    if(debug_context->stack_size == 0)
        rb_raise(rb_eRuntimeError, "No frames collected.");

    rb_scan_args(argc, argv, "11", &lines, &frame);
    debug_context->stop_line = FIX2INT(lines);
    if(argc == 1)
    {
        debug_context->dest_frame = debug_context->stack_size;
    }
    else
    {
        if(FIX2INT(frame) < 0 && FIX2INT(frame) >= debug_context->stack_size)
            rb_raise(rb_eRuntimeError, "Destination frame is out of range.");
        debug_context->dest_frame = debug_context->stack_size - FIX2INT(frame);
    }

    return Qnil;
}

#stop_frame(frame) ⇒ Object

Stops when a frame with number frame is activated. Implements up and down commands.



1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
# File 'ext/ruby_debug.c', line 1553

static VALUE
context_stop_frame(VALUE self, VALUE frame)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    if(FIX2INT(frame) < 0 && FIX2INT(frame) >= debug_context->stack_size)
        rb_raise(rb_eRuntimeError, "Stop frame is out of range.");
    debug_context->stop_frame = debug_context->stack_size - FIX2INT(frame);

    return frame;
}

#stop_next=(steps) ⇒ Object

Stops the current context after a number steps are made.



1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
# File 'ext/ruby_debug.c', line 1500

static VALUE
context_stop_next(VALUE self, VALUE steps)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    if(FIX2INT(steps) < 0)
    rb_raise(rb_eRuntimeError, "Steps argument can't be negative.");
    debug_context->stop_next = FIX2INT(steps);
    
    return steps;
}

#suspendnil

Suspends the thread when it is running.

Returns:

  • (nil)


1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
# File 'ext/ruby_debug.c', line 1774

static VALUE
context_suspend(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    if(CTX_FL_TEST(debug_context, CTX_FL_SUSPEND))
        rb_raise(rb_eRuntimeError, "Already suspended.");
    CTX_FL_SET(debug_context, CTX_FL_SUSPEND);
    return Qnil;
}

#suspended?Boolean

Returns true if the thread is suspended by debugger.

Returns:

  • (Boolean)


1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
# File 'ext/ruby_debug.c', line 1794

static VALUE
context_is_suspended(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    return CTX_FL_TEST(debug_context, CTX_FL_SUSPEND) ? Qtrue : Qfalse;
}

#thnumInteger

Returns the context’s number.

Returns:

  • (Integer)


1759
1760
1761
1762
1763
1764
1765
1766
# File 'ext/ruby_debug.c', line 1759

static VALUE
context_thnum(VALUE self)
{
    debug_context_t *debug_context;

    Data_Get_Struct(self, debug_context_t, debug_context);
    return INT2FIX(debug_context->thnum);
}

#threadObject

Returns a thread this context is associated with.



1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'ext/ruby_debug.c', line 1743

static VALUE
context_thread(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();
    Data_Get_Struct(self, debug_context_t, debug_context);
    return context_thread_0(debug_context);
}

#tracingBoolean

Returns the tracing flag for the current context.

Returns:

  • (Boolean)


1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
# File 'ext/ruby_debug.c', line 1832

static VALUE
context_tracing(VALUE self)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    return CTX_FL_TEST(debug_context, CTX_FL_TRACING) ? Qtrue : Qfalse;
}

#tracking=(bool) ⇒ Object

Controls the tracing for this context.



1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
# File 'ext/ruby_debug.c', line 1849

static VALUE
context_set_tracing(VALUE self, VALUE value)
{
    debug_context_t *debug_context;

    debug_check_started();

    Data_Get_Struct(self, debug_context_t, debug_context);
    if(RTEST(value))
        CTX_FL_SET(debug_context, CTX_FL_TRACING);
    else
        CTX_FL_UNSET(debug_context, CTX_FL_TRACING);
    return value;
}