Class: Byebug::Breakpoint

Inherits:
Object
  • Object
show all
Defined in:
ext/byebug/breakpoint.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, pos, expr) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'ext/byebug/breakpoint.c', line 109

static VALUE
Breakpoint_initialize(VALUE self, VALUE source, VALUE pos, VALUE expr)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);

  breakpoint->type = FIXNUM_P(pos) ? BP_POS_TYPE : BP_METHOD_TYPE;
  if(breakpoint->type == BP_POS_TYPE)
      breakpoint->pos.line = FIX2INT(pos);
  else
      breakpoint->pos.mid = SYM2ID(pos);

  breakpoint->id = ++breakpoint_max;
  breakpoint->source = StringValue(source);
  breakpoint->enabled = Qtrue;
  breakpoint->expr = NIL_P(expr) ? expr : StringValue(expr);
  breakpoint->hit_count = 0;
  breakpoint->hit_value = 0;
  breakpoint->hit_condition = HIT_COND_NONE;

  return Qnil;
}

Class Method Details

.remove(breakpoints, id_value) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/byebug/breakpoint.c', line 133

static VALUE
Breakpoint_remove(VALUE self, VALUE breakpoints, VALUE id_value)
{
  int i;
  int id;
  VALUE breakpoint_object;
  breakpoint_t *breakpoint;

  if (breakpoints == Qnil) return Qnil;

  id = FIX2INT(id_value);

  for(i = 0; i < RARRAY_LEN(breakpoints); i++)
  {
    breakpoint_object = rb_ary_entry(breakpoints, i);
    Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
    if(breakpoint->id == id)
    {
      rb_ary_delete_at(breakpoints, i);
      return breakpoint_object;
    }
  }
  return Qnil;
}

Instance Method Details

#enabled=(bool) ⇒ Object



217
218
219
220
221
222
223
224
# File 'ext/byebug/breakpoint.c', line 217

static VALUE
Breakpoint_set_enabled(VALUE self, VALUE bool)
{
    breakpoint_t *breakpoint;

    Data_Get_Struct(self, breakpoint_t, breakpoint);
    return breakpoint->enabled = bool;
}

#enabled?Boolean

Returns:

  • (Boolean)


208
209
210
211
212
213
214
215
# File 'ext/byebug/breakpoint.c', line 208

static VALUE
Breakpoint_enabled(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  return breakpoint->enabled;
}

#exprObject



189
190
191
192
193
194
195
196
# File 'ext/byebug/breakpoint.c', line 189

static VALUE
Breakpoint_expr(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  return breakpoint->expr;
}

#expr=(expr) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'ext/byebug/breakpoint.c', line 198

static VALUE
Breakpoint_set_expr(VALUE self, VALUE expr)
{
    breakpoint_t *breakpoint;

    Data_Get_Struct(self, breakpoint_t, breakpoint);
    breakpoint->expr = NIL_P(expr) ? expr: StringValue(expr);
    return expr;
}

#hit_conditionObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'ext/byebug/breakpoint.c', line 53

static VALUE
Breakpoint_hit_condition(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  switch(breakpoint->hit_condition)
  {
    case HIT_COND_GE:
      return ID2SYM(rb_intern("greater_or_equal"));
    case HIT_COND_EQ:
      return ID2SYM(rb_intern("equal"));
    case HIT_COND_MOD:
      return ID2SYM(rb_intern("modulo"));
    case HIT_COND_NONE:
    default:
      return Qnil;
  }
}

#hit_condition=(value) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'ext/byebug/breakpoint.c', line 73

static VALUE
Breakpoint_set_hit_condition(VALUE self, VALUE value)
{
  breakpoint_t *breakpoint;
  ID id_value;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  id_value = rb_to_id(value);

  if(rb_intern("greater_or_equal") == id_value || rb_intern("ge") == id_value)
    breakpoint->hit_condition = HIT_COND_GE;
  else if(rb_intern("equal") == id_value || rb_intern("eq") == id_value)
    breakpoint->hit_condition = HIT_COND_EQ;
  else if(rb_intern("modulo") == id_value || rb_intern("mod") == id_value)
    breakpoint->hit_condition = HIT_COND_MOD;
  else
    rb_raise(rb_eArgError, "Invalid condition parameter");
  return value;
}

#hit_countObject



24
25
26
27
28
29
30
31
# File 'ext/byebug/breakpoint.c', line 24

static VALUE
Breakpoint_hit_count(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  return INT2FIX(breakpoint->hit_count);
}

#hit_valueObject



34
35
36
37
38
39
40
41
# File 'ext/byebug/breakpoint.c', line 34

static VALUE
Breakpoint_hit_value(VALUE self)
{
    breakpoint_t *breakpoint;

    Data_Get_Struct(self, breakpoint_t, breakpoint);
    return INT2FIX(breakpoint->hit_value);
}

#hit_value=(value) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'ext/byebug/breakpoint.c', line 43

static VALUE
Breakpoint_set_hit_value(VALUE self, VALUE value)
{
    breakpoint_t *breakpoint;

    Data_Get_Struct(self, breakpoint_t, breakpoint);
    breakpoint->hit_value = FIX2INT(value);
    return value;
}

#idObject



158
159
160
161
162
163
164
165
# File 'ext/byebug/breakpoint.c', line 158

static VALUE
Breakpoint_id(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  return INT2FIX(breakpoint->id);
}

#posObject



176
177
178
179
180
181
182
183
184
185
186
# File 'ext/byebug/breakpoint.c', line 176

static VALUE
Breakpoint_pos(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  if(breakpoint->type == BP_METHOD_TYPE)
      return rb_str_new2(rb_id2name(breakpoint->pos.mid));
  else
      return INT2FIX(breakpoint->pos.line);
}

#sourceObject



167
168
169
170
171
172
173
174
# File 'ext/byebug/breakpoint.c', line 167

static VALUE
Breakpoint_source(VALUE self)
{
  breakpoint_t *breakpoint;

  Data_Get_Struct(self, breakpoint_t, breakpoint);
  return breakpoint->source;
}