micro-lite-gem 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/byebug-13.0.0/CHANGELOG.md +980 -0
  3. data/byebug-13.0.0/CONTRIBUTING.md +58 -0
  4. data/byebug-13.0.0/GUIDE.md +1806 -0
  5. data/byebug-13.0.0/LICENSE +23 -0
  6. data/byebug-13.0.0/README.md +197 -0
  7. data/byebug-13.0.0/exe/byebug +6 -0
  8. data/byebug-13.0.0/ext/byebug/breakpoint.c +522 -0
  9. data/byebug-13.0.0/ext/byebug/byebug.c +906 -0
  10. data/byebug-13.0.0/ext/byebug/byebug.h +147 -0
  11. data/byebug-13.0.0/ext/byebug/context.c +682 -0
  12. data/byebug-13.0.0/ext/byebug/extconf.rb +12 -0
  13. data/byebug-13.0.0/ext/byebug/locker.c +96 -0
  14. data/byebug-13.0.0/ext/byebug/threads.c +254 -0
  15. data/byebug-13.0.0/lib/byebug/attacher.rb +48 -0
  16. data/byebug-13.0.0/lib/byebug/breakpoint.rb +94 -0
  17. data/byebug-13.0.0/lib/byebug/command.rb +111 -0
  18. data/byebug-13.0.0/lib/byebug/command_list.rb +34 -0
  19. data/byebug-13.0.0/lib/byebug/commands/break.rb +114 -0
  20. data/byebug-13.0.0/lib/byebug/commands/catch.rb +78 -0
  21. data/byebug-13.0.0/lib/byebug/commands/condition.rb +55 -0
  22. data/byebug-13.0.0/lib/byebug/commands/continue.rb +68 -0
  23. data/byebug-13.0.0/lib/byebug/commands/debug.rb +38 -0
  24. data/byebug-13.0.0/lib/byebug/commands/delete.rb +55 -0
  25. data/byebug-13.0.0/lib/byebug/commands/disable/breakpoints.rb +42 -0
  26. data/byebug-13.0.0/lib/byebug/commands/disable/display.rb +43 -0
  27. data/byebug-13.0.0/lib/byebug/commands/disable.rb +33 -0
  28. data/byebug-13.0.0/lib/byebug/commands/display.rb +66 -0
  29. data/byebug-13.0.0/lib/byebug/commands/down.rb +45 -0
  30. data/byebug-13.0.0/lib/byebug/commands/edit.rb +69 -0
  31. data/byebug-13.0.0/lib/byebug/commands/enable/breakpoints.rb +42 -0
  32. data/byebug-13.0.0/lib/byebug/commands/enable/display.rb +43 -0
  33. data/byebug-13.0.0/lib/byebug/commands/enable.rb +33 -0
  34. data/byebug-13.0.0/lib/byebug/commands/finish.rb +57 -0
  35. data/byebug-13.0.0/lib/byebug/commands/frame.rb +57 -0
  36. data/byebug-13.0.0/lib/byebug/commands/help.rb +64 -0
  37. data/byebug-13.0.0/lib/byebug/commands/history.rb +39 -0
  38. data/byebug-13.0.0/lib/byebug/commands/info/breakpoints.rb +65 -0
  39. data/byebug-13.0.0/lib/byebug/commands/info/display.rb +49 -0
  40. data/byebug-13.0.0/lib/byebug/commands/info/file.rb +80 -0
  41. data/byebug-13.0.0/lib/byebug/commands/info/line.rb +35 -0
  42. data/byebug-13.0.0/lib/byebug/commands/info/program.rb +49 -0
  43. data/byebug-13.0.0/lib/byebug/commands/info.rb +37 -0
  44. data/byebug-13.0.0/lib/byebug/commands/interrupt.rb +34 -0
  45. data/byebug-13.0.0/lib/byebug/commands/irb.rb +51 -0
  46. data/byebug-13.0.0/lib/byebug/commands/kill.rb +45 -0
  47. data/byebug-13.0.0/lib/byebug/commands/list.rb +159 -0
  48. data/byebug-13.0.0/lib/byebug/commands/method.rb +53 -0
  49. data/byebug-13.0.0/lib/byebug/commands/next.rb +40 -0
  50. data/byebug-13.0.0/lib/byebug/commands/pry.rb +41 -0
  51. data/byebug-13.0.0/lib/byebug/commands/quit.rb +42 -0
  52. data/byebug-13.0.0/lib/byebug/commands/restart.rb +64 -0
  53. data/byebug-13.0.0/lib/byebug/commands/save.rb +72 -0
  54. data/byebug-13.0.0/lib/byebug/commands/set.rb +79 -0
  55. data/byebug-13.0.0/lib/byebug/commands/show.rb +45 -0
  56. data/byebug-13.0.0/lib/byebug/commands/skip.rb +85 -0
  57. data/byebug-13.0.0/lib/byebug/commands/source.rb +40 -0
  58. data/byebug-13.0.0/lib/byebug/commands/step.rb +40 -0
  59. data/byebug-13.0.0/lib/byebug/commands/thread/current.rb +37 -0
  60. data/byebug-13.0.0/lib/byebug/commands/thread/list.rb +43 -0
  61. data/byebug-13.0.0/lib/byebug/commands/thread/resume.rb +45 -0
  62. data/byebug-13.0.0/lib/byebug/commands/thread/stop.rb +43 -0
  63. data/byebug-13.0.0/lib/byebug/commands/thread/switch.rb +46 -0
  64. data/byebug-13.0.0/lib/byebug/commands/thread.rb +34 -0
  65. data/byebug-13.0.0/lib/byebug/commands/tracevar.rb +54 -0
  66. data/byebug-13.0.0/lib/byebug/commands/undisplay.rb +51 -0
  67. data/byebug-13.0.0/lib/byebug/commands/untracevar.rb +36 -0
  68. data/byebug-13.0.0/lib/byebug/commands/up.rb +45 -0
  69. data/byebug-13.0.0/lib/byebug/commands/var/all.rb +41 -0
  70. data/byebug-13.0.0/lib/byebug/commands/var/args.rb +39 -0
  71. data/byebug-13.0.0/lib/byebug/commands/var/const.rb +49 -0
  72. data/byebug-13.0.0/lib/byebug/commands/var/global.rb +37 -0
  73. data/byebug-13.0.0/lib/byebug/commands/var/instance.rb +39 -0
  74. data/byebug-13.0.0/lib/byebug/commands/var/local.rb +39 -0
  75. data/byebug-13.0.0/lib/byebug/commands/var.rb +37 -0
  76. data/byebug-13.0.0/lib/byebug/commands/where.rb +64 -0
  77. data/byebug-13.0.0/lib/byebug/commands.rb +40 -0
  78. data/byebug-13.0.0/lib/byebug/context.rb +157 -0
  79. data/byebug-13.0.0/lib/byebug/core.rb +115 -0
  80. data/byebug-13.0.0/lib/byebug/errors.rb +29 -0
  81. data/byebug-13.0.0/lib/byebug/frame.rb +185 -0
  82. data/byebug-13.0.0/lib/byebug/helpers/bin.rb +47 -0
  83. data/byebug-13.0.0/lib/byebug/helpers/eval.rb +124 -0
  84. data/byebug-13.0.0/lib/byebug/helpers/file.rb +67 -0
  85. data/byebug-13.0.0/lib/byebug/helpers/frame.rb +75 -0
  86. data/byebug-13.0.0/lib/byebug/helpers/parse.rb +82 -0
  87. data/byebug-13.0.0/lib/byebug/helpers/path.rb +40 -0
  88. data/byebug-13.0.0/lib/byebug/helpers/reflection.rb +19 -0
  89. data/byebug-13.0.0/lib/byebug/helpers/string.rb +33 -0
  90. data/byebug-13.0.0/lib/byebug/helpers/thread.rb +67 -0
  91. data/byebug-13.0.0/lib/byebug/helpers/toggle.rb +62 -0
  92. data/byebug-13.0.0/lib/byebug/helpers/var.rb +70 -0
  93. data/byebug-13.0.0/lib/byebug/history.rb +120 -0
  94. data/byebug-13.0.0/lib/byebug/interface.rb +146 -0
  95. data/byebug-13.0.0/lib/byebug/interfaces/local_interface.rb +63 -0
  96. data/byebug-13.0.0/lib/byebug/interfaces/remote_interface.rb +50 -0
  97. data/byebug-13.0.0/lib/byebug/interfaces/script_interface.rb +33 -0
  98. data/byebug-13.0.0/lib/byebug/interfaces/test_interface.rb +67 -0
  99. data/byebug-13.0.0/lib/byebug/option_setter.rb +95 -0
  100. data/byebug-13.0.0/lib/byebug/printers/base.rb +68 -0
  101. data/byebug-13.0.0/lib/byebug/printers/plain.rb +44 -0
  102. data/byebug-13.0.0/lib/byebug/printers/texts/base.yml +115 -0
  103. data/byebug-13.0.0/lib/byebug/printers/texts/plain.yml +33 -0
  104. data/byebug-13.0.0/lib/byebug/processors/command_processor.rb +173 -0
  105. data/byebug-13.0.0/lib/byebug/processors/control_processor.rb +24 -0
  106. data/byebug-13.0.0/lib/byebug/processors/post_mortem_processor.rb +18 -0
  107. data/byebug-13.0.0/lib/byebug/processors/script_processor.rb +49 -0
  108. data/byebug-13.0.0/lib/byebug/remote/client.rb +57 -0
  109. data/byebug-13.0.0/lib/byebug/remote/server.rb +47 -0
  110. data/byebug-13.0.0/lib/byebug/remote.rb +85 -0
  111. data/byebug-13.0.0/lib/byebug/runner.rb +198 -0
  112. data/byebug-13.0.0/lib/byebug/setting.rb +79 -0
  113. data/byebug-13.0.0/lib/byebug/settings/autoirb.rb +29 -0
  114. data/byebug-13.0.0/lib/byebug/settings/autolist.rb +29 -0
  115. data/byebug-13.0.0/lib/byebug/settings/autopry.rb +29 -0
  116. data/byebug-13.0.0/lib/byebug/settings/autosave.rb +17 -0
  117. data/byebug-13.0.0/lib/byebug/settings/basename.rb +16 -0
  118. data/byebug-13.0.0/lib/byebug/settings/callstyle.rb +20 -0
  119. data/byebug-13.0.0/lib/byebug/settings/fullpath.rb +16 -0
  120. data/byebug-13.0.0/lib/byebug/settings/histfile.rb +20 -0
  121. data/byebug-13.0.0/lib/byebug/settings/histsize.rb +20 -0
  122. data/byebug-13.0.0/lib/byebug/settings/linetrace.rb +22 -0
  123. data/byebug-13.0.0/lib/byebug/settings/listsize.rb +21 -0
  124. data/byebug-13.0.0/lib/byebug/settings/post_mortem.rb +27 -0
  125. data/byebug-13.0.0/lib/byebug/settings/savefile.rb +20 -0
  126. data/byebug-13.0.0/lib/byebug/settings/stack_on_error.rb +15 -0
  127. data/byebug-13.0.0/lib/byebug/settings/width.rb +20 -0
  128. data/byebug-13.0.0/lib/byebug/source_file_formatter.rb +71 -0
  129. data/byebug-13.0.0/lib/byebug/subcommands.rb +54 -0
  130. data/byebug-13.0.0/lib/byebug/version.rb +8 -0
  131. data/byebug-13.0.0/lib/byebug.rb +3 -0
  132. data/micro-lite-gem.gemspec +12 -0
  133. metadata +172 -0
@@ -0,0 +1,522 @@
1
+ #include "byebug.h"
2
+
3
+ #ifdef _WIN32
4
+ #include <ctype.h>
5
+ #endif
6
+
7
+ #if defined DOSISH
8
+ #define isdirsep(x) ((x) == '/' || (x) == '\\')
9
+ #else
10
+ #define isdirsep(x) ((x) == '/')
11
+ #endif
12
+
13
+ static VALUE cBreakpoint;
14
+ static int breakpoint_max;
15
+
16
+ static ID idEval;
17
+
18
+ static VALUE
19
+ eval_expression(VALUE args)
20
+ {
21
+ return rb_funcall2(rb_mKernel, idEval, 2, RARRAY_PTR(args));
22
+ }
23
+
24
+ static void
25
+ mark_breakpoint(void *data)
26
+ {
27
+ breakpoint_t *breakpoint = data;
28
+
29
+ rb_gc_mark(breakpoint->source);
30
+ rb_gc_mark(breakpoint->expr);
31
+ }
32
+
33
+ static const rb_data_type_t breakpoint_type = {
34
+ "Byebug::Breakpoint",
35
+ {mark_breakpoint, RUBY_TYPED_DEFAULT_FREE},
36
+ };
37
+
38
+ static breakpoint_t *
39
+ brkpt_ptr(VALUE self)
40
+ {
41
+ breakpoint_t *breakpoint;
42
+
43
+ TypedData_Get_Struct(self, breakpoint_t, &breakpoint_type, breakpoint);
44
+ return breakpoint;
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * breakpoint.enabled? -> bool
50
+ *
51
+ * Returns +true+ if breakpoint is enabled, false otherwise.
52
+ */
53
+ static VALUE
54
+ brkpt_enabled(VALUE self)
55
+ {
56
+ breakpoint_t *breakpoint = brkpt_ptr(self);
57
+
58
+ return breakpoint->enabled;
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * breakpoint.enabled = true | false
64
+ *
65
+ * Enables or disables breakpoint.
66
+ */
67
+ static VALUE
68
+ brkpt_set_enabled(VALUE self, VALUE enabled)
69
+ {
70
+ breakpoint_t *breakpoint = brkpt_ptr(self);
71
+
72
+ return breakpoint->enabled = enabled;
73
+ }
74
+
75
+ /*
76
+ * call-seq:
77
+ * breakpoint.expr -> string
78
+ *
79
+ * Returns a conditional expression which indicates when this breakpoint should
80
+ * be activated.
81
+ */
82
+ static VALUE
83
+ brkpt_expr(VALUE self)
84
+ {
85
+ breakpoint_t *breakpoint = brkpt_ptr(self);
86
+
87
+ return breakpoint->expr;
88
+ }
89
+
90
+ /*
91
+ * call-seq:
92
+ * breakpoint.expr = string | nil
93
+ *
94
+ * Sets or unsets the conditional expression which indicates when this
95
+ * breakpoint should be activated.
96
+ */
97
+ static VALUE
98
+ brkpt_set_expr(VALUE self, VALUE expr)
99
+ {
100
+ breakpoint_t *breakpoint = brkpt_ptr(self);
101
+
102
+ breakpoint->expr = NIL_P(expr) ? expr : StringValue(expr);
103
+ return expr;
104
+ }
105
+
106
+ /*
107
+ * call-seq:
108
+ * breakpoint.hit_condition -> symbol
109
+ *
110
+ * Returns the hit condition of the breakpoint: +nil+ if it is an
111
+ * unconditional breakpoint, or :greater_or_equal, :equal or :modulo otherwise
112
+ */
113
+ static VALUE
114
+ brkpt_hit_condition(VALUE self)
115
+ {
116
+ breakpoint_t *breakpoint = brkpt_ptr(self);
117
+
118
+ switch (breakpoint->hit_condition)
119
+ {
120
+ case HIT_COND_GE:
121
+ return ID2SYM(rb_intern("greater_or_equal"));
122
+ case HIT_COND_EQ:
123
+ return ID2SYM(rb_intern("equal"));
124
+ case HIT_COND_MOD:
125
+ return ID2SYM(rb_intern("modulo"));
126
+ case HIT_COND_NONE:
127
+ default:
128
+ return Qnil;
129
+ }
130
+ }
131
+
132
+ /*
133
+ * call-seq:
134
+ * breakpoint.hit_condition = symbol
135
+ *
136
+ * Sets the hit condition of the breakpoint which must be one of the following
137
+ * values:
138
+ *
139
+ * +nil+ if it is an unconditional breakpoint, or
140
+ * :greater_or_equal(:ge), :equal(:eq), :modulo(:mod)
141
+ */
142
+ static VALUE
143
+ brkpt_set_hit_condition(VALUE self, VALUE value)
144
+ {
145
+ breakpoint_t *breakpoint = brkpt_ptr(self);
146
+ ID id_value;
147
+
148
+ if (NIL_P(value))
149
+ {
150
+ breakpoint->hit_condition = HIT_COND_NONE;
151
+ return value;
152
+ }
153
+
154
+ id_value = rb_to_id(value);
155
+
156
+ if (rb_intern("greater_or_equal") == id_value || rb_intern("ge") == id_value)
157
+ breakpoint->hit_condition = HIT_COND_GE;
158
+ else if (rb_intern("equal") == id_value || rb_intern("eq") == id_value)
159
+ breakpoint->hit_condition = HIT_COND_EQ;
160
+ else if (rb_intern("modulo") == id_value || rb_intern("mod") == id_value)
161
+ breakpoint->hit_condition = HIT_COND_MOD;
162
+ else
163
+ rb_raise(rb_eArgError, "Invalid condition parameter");
164
+ return value;
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * breakpoint.hit_count -> int
170
+ *
171
+ * Returns the number of times this breakpoint has been hit.
172
+ */
173
+ static VALUE
174
+ brkpt_hit_count(VALUE self)
175
+ {
176
+ breakpoint_t *breakpoint = brkpt_ptr(self);
177
+
178
+ return INT2FIX(breakpoint->hit_count);
179
+ }
180
+
181
+ /*
182
+ * call-seq:
183
+ * breakpoint.hit_value -> int
184
+ *
185
+ * Returns the hit value of the breakpoint, namely, a value to build a
186
+ * condition on the number of hits of the breakpoint.
187
+ */
188
+ static VALUE
189
+ brkpt_hit_value(VALUE self)
190
+ {
191
+ breakpoint_t *breakpoint = brkpt_ptr(self);
192
+
193
+ return INT2FIX(breakpoint->hit_value);
194
+ }
195
+
196
+ /*
197
+ * call-seq:
198
+ * breakpoint.hit_value = int
199
+ *
200
+ * Sets the hit value of the breakpoint. This allows the user to set conditions
201
+ * on the number of hits to enable/disable the breakpoint.
202
+ */
203
+ static VALUE
204
+ brkpt_set_hit_value(VALUE self, VALUE value)
205
+ {
206
+ breakpoint_t *breakpoint = brkpt_ptr(self);
207
+
208
+ breakpoint->hit_value = FIX2INT(value);
209
+ return value;
210
+ }
211
+
212
+ /*
213
+ * call-seq:
214
+ * breakpoint.id -> int
215
+ *
216
+ * Returns the id of the breakpoint.
217
+ */
218
+ static VALUE
219
+ brkpt_id(VALUE self)
220
+ {
221
+ breakpoint_t *breakpoint = brkpt_ptr(self);
222
+
223
+ return INT2FIX(breakpoint->id);
224
+ }
225
+
226
+ /*
227
+ * call-seq:
228
+ * breakpoint.pos -> string or int
229
+ *
230
+ * Returns the position of this breakpoint, either a method name or a line
231
+ * number.
232
+ */
233
+ static VALUE
234
+ brkpt_pos(VALUE self)
235
+ {
236
+ breakpoint_t *breakpoint = brkpt_ptr(self);
237
+
238
+ if (breakpoint->type == BP_METHOD_TYPE)
239
+ return rb_str_new2(rb_id2name(breakpoint->pos.mid));
240
+ else
241
+ return INT2FIX(breakpoint->pos.line);
242
+ }
243
+
244
+ /*
245
+ * call-seq:
246
+ * breakpoint.source -> string
247
+ *
248
+ * Returns the source file of the breakpoint.
249
+ */
250
+ static VALUE
251
+ brkpt_source(VALUE self)
252
+ {
253
+ breakpoint_t *breakpoint = brkpt_ptr(self);
254
+
255
+ return breakpoint->source;
256
+ }
257
+
258
+ static VALUE
259
+ brkpt_create(VALUE klass)
260
+ {
261
+ breakpoint_t *breakpoint;
262
+
263
+ return TypedData_Make_Struct(klass, breakpoint_t, &breakpoint_type, breakpoint);
264
+ }
265
+
266
+ static VALUE
267
+ brkpt_initialize(VALUE self, VALUE source, VALUE pos, VALUE expr)
268
+ {
269
+ breakpoint_t *breakpoint = brkpt_ptr(self);
270
+
271
+ breakpoint->type = FIXNUM_P(pos) ? BP_POS_TYPE : BP_METHOD_TYPE;
272
+ if (breakpoint->type == BP_POS_TYPE)
273
+ breakpoint->pos.line = FIX2INT(pos);
274
+ else
275
+ breakpoint->pos.mid = SYM2ID(pos);
276
+
277
+ breakpoint->id = ++breakpoint_max;
278
+ breakpoint->source = StringValue(source);
279
+ breakpoint->enabled = Qtrue;
280
+ breakpoint->expr = NIL_P(expr) ? expr : StringValue(expr);
281
+ breakpoint->hit_count = 0;
282
+ breakpoint->hit_value = 0;
283
+ breakpoint->hit_condition = HIT_COND_NONE;
284
+
285
+ return Qnil;
286
+ }
287
+
288
+ static int
289
+ filename_cmp_impl(VALUE source, char *file)
290
+ {
291
+ char *source_ptr, *file_ptr;
292
+ long s_len, f_len, min_len;
293
+ long s, f;
294
+ int dirsep_flag = 0;
295
+
296
+ s_len = RSTRING_LEN(source);
297
+ f_len = strlen(file);
298
+ min_len = s_len < f_len ? s_len : f_len;
299
+
300
+ source_ptr = RSTRING_PTR(source);
301
+ file_ptr = file;
302
+
303
+ for (s = s_len - 1, f = f_len - 1;
304
+ s >= s_len - min_len && f >= f_len - min_len; s--, f--)
305
+ {
306
+ if ((source_ptr[s] == '.' || file_ptr[f] == '.') && dirsep_flag)
307
+ return 1;
308
+ if (isdirsep(source_ptr[s]) && isdirsep(file_ptr[f]))
309
+ dirsep_flag = 1;
310
+ #ifdef DOSISH_DRIVE_LETTER
311
+ else if (s == 0)
312
+ return (toupper(source_ptr[s]) == toupper(file_ptr[f]));
313
+ #endif
314
+ else if (source_ptr[s] != file_ptr[f])
315
+ return 0;
316
+ }
317
+ return 1;
318
+ }
319
+
320
+ static int
321
+ filename_cmp(VALUE source, char *file)
322
+ {
323
+ #ifdef _WIN32
324
+ return filename_cmp_impl(source, file);
325
+ #else
326
+ #ifdef PATH_MAX
327
+ char path[PATH_MAX + 1];
328
+
329
+ path[PATH_MAX] = 0;
330
+ return filename_cmp_impl(source, realpath(file, path) != NULL ? path : file);
331
+ #else
332
+ char *path;
333
+ int result;
334
+
335
+ path = realpath(file, NULL);
336
+ result = filename_cmp_impl(source, path == NULL ? file : path);
337
+ free(path);
338
+ return result;
339
+ #endif
340
+ #endif
341
+ }
342
+
343
+ static int
344
+ classname_cmp(VALUE name, VALUE klass)
345
+ {
346
+ VALUE mod_name;
347
+ VALUE class_name = NIL_P(name) ? rb_str_new2("main") : name;
348
+
349
+ if (NIL_P(klass))
350
+ return 0;
351
+
352
+ mod_name = rb_mod_name(klass);
353
+ return (!NIL_P(mod_name) && rb_str_cmp(class_name, mod_name) == 0);
354
+ }
355
+
356
+ static int
357
+ check_breakpoint_by_hit_condition(VALUE rb_breakpoint)
358
+ {
359
+ breakpoint_t *breakpoint;
360
+
361
+ if (NIL_P(rb_breakpoint))
362
+ return 0;
363
+
364
+ breakpoint = brkpt_ptr(rb_breakpoint);
365
+ breakpoint->hit_count++;
366
+
367
+ if (Qtrue != breakpoint->enabled)
368
+ return 0;
369
+
370
+ switch (breakpoint->hit_condition)
371
+ {
372
+ case HIT_COND_NONE:
373
+ return 1;
374
+ case HIT_COND_GE: {
375
+ if (breakpoint->hit_count >= breakpoint->hit_value)
376
+ return 1;
377
+ break;
378
+ }
379
+ case HIT_COND_EQ: {
380
+ if (breakpoint->hit_count == breakpoint->hit_value)
381
+ return 1;
382
+ break;
383
+ }
384
+ case HIT_COND_MOD: {
385
+ if (breakpoint->hit_count % breakpoint->hit_value == 0)
386
+ return 1;
387
+ break;
388
+ }
389
+ }
390
+ return 0;
391
+ }
392
+
393
+ static int
394
+ check_breakpoint_by_pos(VALUE rb_breakpoint, char *file, int line)
395
+ {
396
+ breakpoint_t *breakpoint;
397
+
398
+ if (NIL_P(rb_breakpoint))
399
+ return 0;
400
+
401
+ breakpoint = brkpt_ptr(rb_breakpoint);
402
+
403
+ if (Qfalse == breakpoint->enabled || breakpoint->type != BP_POS_TYPE
404
+ || breakpoint->pos.line != line)
405
+ return 0;
406
+
407
+ return filename_cmp(breakpoint->source, file);
408
+ }
409
+
410
+ static int
411
+ check_breakpoint_by_method(VALUE rb_breakpoint, VALUE klass, ID mid, VALUE self)
412
+ {
413
+ breakpoint_t *breakpoint;
414
+
415
+ if (NIL_P(rb_breakpoint))
416
+ return 0;
417
+
418
+ breakpoint = brkpt_ptr(rb_breakpoint);
419
+
420
+ if (Qfalse == breakpoint->enabled || breakpoint->type != BP_METHOD_TYPE
421
+ || breakpoint->pos.mid != mid)
422
+ return 0;
423
+
424
+ if (classname_cmp(breakpoint->source, klass)
425
+ || ((rb_type(self) == T_CLASS || rb_type(self) == T_MODULE)
426
+ && classname_cmp(breakpoint->source, self)))
427
+ return 1;
428
+
429
+ return 0;
430
+ }
431
+
432
+ static int
433
+ check_breakpoint_by_expr(VALUE rb_breakpoint, VALUE bind)
434
+ {
435
+ breakpoint_t *breakpoint;
436
+ VALUE args, expr_result;
437
+
438
+ if (NIL_P(rb_breakpoint))
439
+ return 0;
440
+
441
+ breakpoint = brkpt_ptr(rb_breakpoint);
442
+
443
+ if (Qfalse == breakpoint->enabled)
444
+ return 0;
445
+
446
+ if (NIL_P(breakpoint->expr))
447
+ return 1;
448
+
449
+ args = rb_ary_new3(2, breakpoint->expr, bind);
450
+ expr_result = rb_protect(eval_expression, args, 0);
451
+
452
+ return RTEST(expr_result);
453
+ }
454
+
455
+ extern VALUE
456
+ find_breakpoint_by_pos(VALUE breakpoints, VALUE source, VALUE pos, VALUE bind)
457
+ {
458
+ VALUE breakpoint;
459
+ char *file;
460
+ int line;
461
+ int i;
462
+
463
+ file = RSTRING_PTR(source);
464
+ line = FIX2INT(pos);
465
+ for (i = 0; i < RARRAY_LENINT(breakpoints); i++)
466
+ {
467
+ breakpoint = rb_ary_entry(breakpoints, i);
468
+ if (check_breakpoint_by_pos(breakpoint, file, line)
469
+ && check_breakpoint_by_expr(breakpoint, bind)
470
+ && check_breakpoint_by_hit_condition(breakpoint))
471
+ {
472
+ return breakpoint;
473
+ }
474
+ }
475
+ return Qnil;
476
+ }
477
+
478
+ extern VALUE
479
+ find_breakpoint_by_method(VALUE breakpoints, VALUE klass, ID mid, VALUE bind,
480
+ VALUE self)
481
+ {
482
+ VALUE breakpoint;
483
+ int i;
484
+
485
+ for (i = 0; i < RARRAY_LENINT(breakpoints); i++)
486
+ {
487
+ breakpoint = rb_ary_entry(breakpoints, i);
488
+ if (check_breakpoint_by_method(breakpoint, klass, mid, self)
489
+ && check_breakpoint_by_expr(breakpoint, bind)
490
+ && check_breakpoint_by_hit_condition(breakpoint))
491
+ {
492
+ return breakpoint;
493
+ }
494
+ }
495
+ return Qnil;
496
+ }
497
+
498
+ void
499
+ Init_byebug_breakpoint(VALUE mByebug)
500
+ {
501
+ breakpoint_max = 0;
502
+
503
+ cBreakpoint = rb_define_class_under(mByebug, "Breakpoint", rb_cObject);
504
+
505
+ rb_define_alloc_func(cBreakpoint, brkpt_create);
506
+ rb_define_method(cBreakpoint, "initialize", brkpt_initialize, 3);
507
+
508
+ rb_define_method(cBreakpoint, "enabled?", brkpt_enabled, 0);
509
+ rb_define_method(cBreakpoint, "enabled=", brkpt_set_enabled, 1);
510
+ rb_define_method(cBreakpoint, "expr", brkpt_expr, 0);
511
+ rb_define_method(cBreakpoint, "expr=", brkpt_set_expr, 1);
512
+ rb_define_method(cBreakpoint, "hit_count", brkpt_hit_count, 0);
513
+ rb_define_method(cBreakpoint, "hit_condition", brkpt_hit_condition, 0);
514
+ rb_define_method(cBreakpoint, "hit_condition=", brkpt_set_hit_condition, 1);
515
+ rb_define_method(cBreakpoint, "hit_value", brkpt_hit_value, 0);
516
+ rb_define_method(cBreakpoint, "hit_value=", brkpt_set_hit_value, 1);
517
+ rb_define_method(cBreakpoint, "id", brkpt_id, 0);
518
+ rb_define_method(cBreakpoint, "pos", brkpt_pos, 0);
519
+ rb_define_method(cBreakpoint, "source", brkpt_source, 0);
520
+
521
+ idEval = rb_intern("eval");
522
+ }