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,682 @@
1
+ #include "byebug.h"
2
+
3
+ static VALUE cContext;
4
+ static VALUE cDebugThread;
5
+ static int thnum_max = 0;
6
+
7
+ /* "Step", "Next" and "Finish" do their work by saving information about where
8
+ * to stop next. byebug_reset_stepping_stop_points removes/resets this information. */
9
+ extern void
10
+ byebug_reset_stepping_stop_points(debug_context_t *context)
11
+ {
12
+ context->dest_frame = -1;
13
+ context->lines = -1;
14
+ context->steps = -1;
15
+ context->steps_out = -1;
16
+ }
17
+
18
+ static void context_mark(void *data);
19
+
20
+ static const rb_data_type_t debug_context_type = {
21
+ "Byebug::Context",
22
+ {
23
+ context_mark,
24
+ RUBY_NEVER_FREE,
25
+ },
26
+ };
27
+
28
+ debug_context_t *
29
+ debug_context_ptr(VALUE self)
30
+ {
31
+ debug_context_t *context;
32
+
33
+ TypedData_Get_Struct(self, debug_context_t, &debug_context_type, context);
34
+ return context;
35
+ }
36
+
37
+ /*
38
+ * call-seq:
39
+ * context.dead? -> bool
40
+ *
41
+ * Returns +true+ if context doesn't represent a live context and is created
42
+ * during post-mortem exception handling.
43
+ */
44
+ static inline VALUE
45
+ Context_dead(VALUE self)
46
+ {
47
+ debug_context_t *context = debug_context_ptr(self);
48
+
49
+ return CTX_FL_TEST(context, CTX_FL_DEAD) ? Qtrue : Qfalse;
50
+ }
51
+
52
+ static void
53
+ context_mark(void *data)
54
+ {
55
+ debug_context_t *context = (debug_context_t *)data;
56
+
57
+ rb_gc_mark(context->backtrace);
58
+ }
59
+
60
+ static VALUE
61
+ dc_backtrace(const debug_context_t *context)
62
+ {
63
+ return context->backtrace;
64
+ }
65
+
66
+ static int
67
+ dc_stack_size(debug_context_t *context)
68
+ {
69
+
70
+ if (NIL_P(dc_backtrace(context)))
71
+ return 0;
72
+
73
+ return RARRAY_LENINT(dc_backtrace(context));
74
+ }
75
+
76
+ extern VALUE
77
+ byebug_context_create(VALUE thread)
78
+ {
79
+ debug_context_t *context;
80
+ VALUE obj = TypedData_Make_Struct(cContext, debug_context_t, &debug_context_type, context);
81
+
82
+ context->flags = 0;
83
+ context->thnum = ++thnum_max;
84
+ context->thread = thread;
85
+ byebug_reset_stepping_stop_points(context);
86
+ context->stop_reason = CTX_STOP_NONE;
87
+
88
+ rb_debug_inspector_open(context_backtrace_set, (void *)context);
89
+ context->calced_stack_size = dc_stack_size(context) + 1;
90
+
91
+ if (rb_obj_class(thread) == cDebugThread)
92
+ CTX_FL_SET(context, CTX_FL_IGNORE);
93
+
94
+ return obj;
95
+ }
96
+
97
+ extern VALUE
98
+ context_dup(debug_context_t *context)
99
+ {
100
+ debug_context_t *new_context;
101
+ VALUE obj = TypedData_Make_Struct(cContext, debug_context_t, &debug_context_type, new_context);
102
+
103
+ memcpy(new_context, context, sizeof(debug_context_t));
104
+ byebug_reset_stepping_stop_points(new_context);
105
+ new_context->backtrace = context->backtrace;
106
+ CTX_FL_SET(new_context, CTX_FL_DEAD);
107
+
108
+ return obj;
109
+ }
110
+
111
+
112
+ static VALUE
113
+ dc_frame_get(const debug_context_t *context, int frame_index, frame_part type)
114
+ {
115
+ VALUE frame;
116
+
117
+ if (NIL_P(dc_backtrace(context)))
118
+ rb_raise(rb_eRuntimeError, "Backtrace information is not available");
119
+
120
+ if (frame_index >= RARRAY_LENINT(dc_backtrace(context)))
121
+ rb_raise(rb_eRuntimeError, "That frame doesn't exist!");
122
+
123
+ frame = rb_ary_entry(dc_backtrace(context), frame_index);
124
+ return rb_ary_entry(frame, type);
125
+ }
126
+
127
+ static VALUE
128
+ dc_frame_location(const debug_context_t *context, int frame_index)
129
+ {
130
+ return dc_frame_get(context, frame_index, LOCATION);
131
+ }
132
+
133
+ static VALUE
134
+ dc_frame_self(const debug_context_t *context, int frame_index)
135
+ {
136
+ return dc_frame_get(context, frame_index, SELF);
137
+ }
138
+
139
+ static VALUE
140
+ dc_frame_class(const debug_context_t *context, int frame_index)
141
+ {
142
+ return dc_frame_get(context, frame_index, CLASS);
143
+ }
144
+
145
+ static VALUE
146
+ dc_frame_binding(const debug_context_t *context, int frame_index)
147
+ {
148
+ return dc_frame_get(context, frame_index, BINDING);
149
+ }
150
+
151
+ static VALUE
152
+ load_backtrace(const rb_debug_inspector_t *inspector)
153
+ {
154
+ VALUE backtrace = rb_ary_new();
155
+ VALUE locs = rb_debug_inspector_backtrace_locations(inspector);
156
+ int i;
157
+
158
+ for (i = 0; i < RARRAY_LENINT(locs); i++)
159
+ {
160
+ VALUE frame = rb_ary_new();
161
+
162
+ rb_ary_push(frame, rb_ary_entry(locs, i));
163
+ rb_ary_push(frame, rb_debug_inspector_frame_self_get(inspector, i));
164
+ rb_ary_push(frame, rb_debug_inspector_frame_class_get(inspector, i));
165
+ rb_ary_push(frame, rb_debug_inspector_frame_binding_get(inspector, i));
166
+
167
+ rb_ary_push(backtrace, frame);
168
+ }
169
+
170
+ return backtrace;
171
+ }
172
+
173
+ extern VALUE
174
+ context_backtrace_set(const rb_debug_inspector_t *inspector, void *data)
175
+ {
176
+ debug_context_t *dc = (debug_context_t *)data;
177
+
178
+ dc->backtrace = load_backtrace(inspector);
179
+
180
+ return Qnil;
181
+ }
182
+
183
+ static VALUE
184
+ open_debug_inspector_i(const rb_debug_inspector_t *inspector, void *data)
185
+ {
186
+ struct call_with_inspection_data *cwi =
187
+ (struct call_with_inspection_data *)data;
188
+
189
+ cwi->dc->backtrace = load_backtrace(inspector);
190
+
191
+ return rb_funcall2(cwi->ctx, cwi->id, cwi->argc, cwi->argv);
192
+ }
193
+
194
+ static VALUE
195
+ open_debug_inspector(struct call_with_inspection_data *cwi)
196
+ {
197
+ return rb_debug_inspector_open(open_debug_inspector_i, cwi);
198
+ }
199
+
200
+ static VALUE
201
+ open_debug_inspector_ensure(VALUE v)
202
+ {
203
+ return open_debug_inspector((struct call_with_inspection_data *)v);
204
+ }
205
+
206
+
207
+ static VALUE
208
+ close_debug_inspector(struct call_with_inspection_data *cwi)
209
+ {
210
+ cwi->dc->backtrace = Qnil;
211
+ return Qnil;
212
+ }
213
+
214
+ static VALUE
215
+ close_debug_inspector_ensure(VALUE v)
216
+ {
217
+ return close_debug_inspector((struct call_with_inspection_data *)v);
218
+ }
219
+
220
+ extern VALUE
221
+ call_with_debug_inspector(struct call_with_inspection_data *data)
222
+ {
223
+ return rb_ensure(open_debug_inspector_ensure, (VALUE)data, close_debug_inspector_ensure,
224
+ (VALUE)data);
225
+ }
226
+
227
+ #define FRAME_SETUP \
228
+ debug_context_t *context = debug_context_ptr(self); \
229
+ VALUE frame_no; \
230
+ int frame_n; \
231
+ if (!rb_scan_args(argc, argv, "01", &frame_no)) \
232
+ frame_n = 0; \
233
+ else \
234
+ frame_n = FIX2INT(frame_no);
235
+
236
+ /*
237
+ * call-seq:
238
+ * context.frame_binding(frame_position = 0) -> binding
239
+ *
240
+ * Returns frame's binding.
241
+ */
242
+ static VALUE
243
+ Context_frame_binding(int argc, VALUE *argv, VALUE self)
244
+ {
245
+ FRAME_SETUP;
246
+
247
+ return dc_frame_binding(context, frame_n);
248
+ }
249
+
250
+ /*
251
+ * call-seq:
252
+ * context.frame_class(frame_position = 0) -> class
253
+ *
254
+ * Returns frame's defined class.
255
+ */
256
+ static VALUE
257
+ Context_frame_class(int argc, VALUE *argv, VALUE self)
258
+ {
259
+ FRAME_SETUP;
260
+
261
+ return dc_frame_class(context, frame_n);
262
+ }
263
+
264
+ /*
265
+ * call-seq:
266
+ * context.frame_file(frame_position = 0) -> string
267
+ *
268
+ * Returns the name of the file in the frame.
269
+ */
270
+ static VALUE
271
+ Context_frame_file(int argc, VALUE *argv, VALUE self)
272
+ {
273
+ VALUE loc, absolute_path;
274
+
275
+ FRAME_SETUP;
276
+
277
+ loc = dc_frame_location(context, frame_n);
278
+
279
+ absolute_path = rb_funcall(loc, rb_intern("absolute_path"), 0);
280
+
281
+ if (!NIL_P(absolute_path))
282
+ return absolute_path;
283
+
284
+ return rb_funcall(loc, rb_intern("path"), 0);
285
+ }
286
+
287
+ /*
288
+ * call-seq:
289
+ * context.frame_line(frame_position = 0) -> int
290
+ *
291
+ * Returns the line number in the file in the frame.
292
+ */
293
+ static VALUE
294
+ Context_frame_line(int argc, VALUE *argv, VALUE self)
295
+ {
296
+ VALUE loc;
297
+
298
+ FRAME_SETUP;
299
+
300
+ loc = dc_frame_location(context, frame_n);
301
+
302
+ return rb_funcall(loc, rb_intern("lineno"), 0);
303
+ }
304
+
305
+ /*
306
+ * call-seq:
307
+ * context.frame_method(frame_position = 0) -> sym
308
+ *
309
+ * Returns the sym of the method in the frame.
310
+ */
311
+ static VALUE
312
+ Context_frame_method(int argc, VALUE *argv, VALUE self)
313
+ {
314
+ VALUE loc;
315
+
316
+ FRAME_SETUP;
317
+
318
+ loc = dc_frame_location(context, frame_n);
319
+
320
+ return rb_str_intern(rb_funcall(loc, rb_intern("label"), 0));
321
+ }
322
+
323
+ /*
324
+ * call-seq:
325
+ * context.frame_self(frame_postion = 0) -> obj
326
+ *
327
+ * Returns self object of the frame.
328
+ */
329
+ static VALUE
330
+ Context_frame_self(int argc, VALUE *argv, VALUE self)
331
+ {
332
+ FRAME_SETUP;
333
+
334
+ return dc_frame_self(context, frame_n);
335
+ }
336
+
337
+ /*
338
+ * call-seq:
339
+ * context.ignored? -> bool
340
+ *
341
+ * Returns the ignore flag for the context, which marks whether the associated
342
+ * thread is ignored while debugging.
343
+ */
344
+ static inline VALUE
345
+ Context_ignored(VALUE self)
346
+ {
347
+ debug_context_t *context = debug_context_ptr(self);
348
+
349
+ return CTX_FL_TEST(context, CTX_FL_IGNORE) ? Qtrue : Qfalse;
350
+ }
351
+
352
+ /*
353
+ * call-seq:
354
+ * context.resume -> nil
355
+ *
356
+ * Resumes thread from the suspended mode.
357
+ */
358
+ static VALUE
359
+ Context_resume(VALUE self)
360
+ {
361
+ debug_context_t *context = debug_context_ptr(self);
362
+
363
+ if (!CTX_FL_TEST(context, CTX_FL_SUSPEND))
364
+ return Qnil;
365
+
366
+ CTX_FL_UNSET(context, CTX_FL_SUSPEND);
367
+
368
+ if (CTX_FL_TEST(context, CTX_FL_WAS_RUNNING))
369
+ rb_thread_wakeup(context->thread);
370
+
371
+ return Qnil;
372
+ }
373
+
374
+ /*
375
+ * call-seq:
376
+ * context.backtrace-> Array
377
+ *
378
+ * Returns the frame stack of a context.
379
+ */
380
+ static inline VALUE
381
+ Context_backtrace(VALUE self)
382
+ {
383
+ debug_context_t *context = debug_context_ptr(self);
384
+
385
+ return dc_backtrace(context);
386
+ }
387
+
388
+ static VALUE
389
+ Context_stop_reason(VALUE self)
390
+ {
391
+ debug_context_t *context = debug_context_ptr(self);
392
+ const char *symbol;
393
+
394
+ if (CTX_FL_TEST(context, CTX_FL_DEAD))
395
+ symbol = "post-mortem";
396
+ else
397
+ switch (context->stop_reason)
398
+ {
399
+ case CTX_STOP_STEP:
400
+ symbol = "step";
401
+ break;
402
+ case CTX_STOP_BREAKPOINT:
403
+ symbol = "breakpoint";
404
+ break;
405
+ case CTX_STOP_CATCHPOINT:
406
+ symbol = "catchpoint";
407
+ break;
408
+ case CTX_STOP_NONE:
409
+ default:
410
+ symbol = "none";
411
+ }
412
+ return ID2SYM(rb_intern(symbol));
413
+ }
414
+
415
+ /*
416
+ * call-seq:
417
+ * context.step_into(steps, frame = 0)
418
+ *
419
+ * Stops the current context after a number of +steps+ are made from frame
420
+ * +frame+ (by default the newest one).
421
+ */
422
+ static VALUE
423
+ Context_step_into(int argc, VALUE *argv, VALUE self)
424
+ {
425
+ VALUE steps, v_frame;
426
+ int n_args, from_frame;
427
+ debug_context_t *context = debug_context_ptr(self);
428
+
429
+ if (context->calced_stack_size == 0)
430
+ rb_raise(rb_eRuntimeError, "No frames collected.");
431
+
432
+ n_args = rb_scan_args(argc, argv, "11", &steps, &v_frame);
433
+
434
+ if (FIX2INT(steps) <= 0)
435
+ rb_raise(rb_eRuntimeError, "Steps argument must be positive.");
436
+
437
+ from_frame = n_args == 1 ? 0 : FIX2INT(v_frame);
438
+
439
+ if (from_frame < 0 || from_frame >= context->calced_stack_size)
440
+ rb_raise(rb_eRuntimeError, "Destination frame (%d) is out of range (%d)",
441
+ from_frame, context->calced_stack_size);
442
+ else if (from_frame > 0)
443
+ CTX_FL_SET(context, CTX_FL_IGNORE_STEPS);
444
+
445
+ context->steps = FIX2INT(steps);
446
+ context->dest_frame = context->calced_stack_size - from_frame;
447
+
448
+ return steps;
449
+ }
450
+
451
+ /*
452
+ * call-seq:
453
+ * context.step_out(n_frames = 1, force = false)
454
+ *
455
+ * Stops after +n_frames+ frames are finished. +force+ parameter (if true)
456
+ * ensures that the execution will stop in the specified frame even when there
457
+ * are no more instructions to run. In that case, it will stop when the return
458
+ * event for that frame is triggered.
459
+ */
460
+ static VALUE
461
+ Context_step_out(int argc, VALUE *argv, VALUE self)
462
+ {
463
+ int n_args, n_frames;
464
+ VALUE v_frames, force;
465
+ debug_context_t *context = debug_context_ptr(self);
466
+
467
+ n_args = rb_scan_args(argc, argv, "02", &v_frames, &force);
468
+ n_frames = n_args == 0 ? 1 : FIX2INT(v_frames);
469
+
470
+ if (n_frames < 0 || n_frames > context->calced_stack_size)
471
+ rb_raise(rb_eRuntimeError,
472
+ "You want to finish %d frames, but stack size is only %d",
473
+ n_frames, context->calced_stack_size);
474
+
475
+ context->steps_out = n_frames;
476
+ if (n_args == 2 && RTEST(force))
477
+ CTX_FL_SET(context, CTX_FL_STOP_ON_RET);
478
+ else
479
+ CTX_FL_UNSET(context, CTX_FL_STOP_ON_RET);
480
+
481
+ return Qnil;
482
+ }
483
+
484
+ /*
485
+ * call-seq:
486
+ * context.step_over(lines, frame = 0)
487
+ *
488
+ * Steps over +lines+ lines in frame +frame+ (by default the newest one) or
489
+ * higher (if frame +frame+ finishes).
490
+ */
491
+ static VALUE
492
+ Context_step_over(int argc, VALUE *argv, VALUE self)
493
+ {
494
+ int n_args, frame;
495
+ VALUE lines, v_frame;
496
+ debug_context_t *context = debug_context_ptr(self);
497
+
498
+ if (context->calced_stack_size == 0)
499
+ rb_raise(rb_eRuntimeError, "No frames collected.");
500
+
501
+ n_args = rb_scan_args(argc, argv, "11", &lines, &v_frame);
502
+ frame = n_args == 1 ? 0 : FIX2INT(v_frame);
503
+
504
+ if (frame < 0 || frame >= context->calced_stack_size)
505
+ rb_raise(rb_eRuntimeError, "Destination frame (%d) is out of range (%d)",
506
+ frame, context->calced_stack_size);
507
+
508
+ context->lines = FIX2INT(lines);
509
+ context->dest_frame = context->calced_stack_size - frame;
510
+
511
+ return Qnil;
512
+ }
513
+
514
+ /*
515
+ * call-seq:
516
+ * context.suspend -> nil
517
+ *
518
+ * Suspends the thread when it is running.
519
+ */
520
+ static VALUE
521
+ Context_suspend(VALUE self)
522
+ {
523
+ VALUE status;
524
+ debug_context_t *context = debug_context_ptr(self);
525
+
526
+ status = rb_funcall(context->thread, rb_intern("status"), 0);
527
+
528
+ if (rb_str_cmp(status, rb_str_new2("run")) == 0)
529
+ CTX_FL_SET(context, CTX_FL_WAS_RUNNING);
530
+ else if (rb_str_cmp(status, rb_str_new2("sleep")) == 0)
531
+ CTX_FL_UNSET(context, CTX_FL_WAS_RUNNING);
532
+ else
533
+ return Qnil;
534
+
535
+ CTX_FL_SET(context, CTX_FL_SUSPEND);
536
+
537
+ return Qnil;
538
+ }
539
+
540
+ /*
541
+ * call-seq:
542
+ * context.switch -> nil
543
+ *
544
+ * Switches execution to this context.
545
+ */
546
+ static VALUE
547
+ Context_switch(VALUE self)
548
+ {
549
+ debug_context_t *context = debug_context_ptr(self);
550
+
551
+ next_thread = context->thread;
552
+
553
+ context->steps = 1;
554
+ context->steps_out = 0;
555
+ CTX_FL_SET(context, CTX_FL_STOP_ON_RET);
556
+
557
+ return Qnil;
558
+ }
559
+
560
+ /*
561
+ * call-seq:
562
+ * context.suspended? -> bool
563
+ *
564
+ * Returns +true+ if the thread is suspended by debugger.
565
+ */
566
+ static VALUE
567
+ Context_is_suspended(VALUE self)
568
+ {
569
+ debug_context_t *context = debug_context_ptr(self);
570
+
571
+ return CTX_FL_TEST(context, CTX_FL_SUSPEND) ? Qtrue : Qfalse;
572
+ }
573
+
574
+ /*
575
+ * call-seq:
576
+ * context.thnum -> int
577
+ *
578
+ * Returns the context's number.
579
+ */
580
+ static inline VALUE
581
+ Context_thnum(VALUE self)
582
+ {
583
+ debug_context_t *context = debug_context_ptr(self);
584
+
585
+ return INT2FIX(context->thnum);
586
+ }
587
+
588
+ /*
589
+ * call-seq:
590
+ * context.thread -> thread
591
+ *
592
+ * Returns the thread this context is associated with.
593
+ */
594
+ static inline VALUE
595
+ Context_thread(VALUE self)
596
+ {
597
+ debug_context_t *context = debug_context_ptr(self);
598
+
599
+ return context->thread;
600
+ }
601
+
602
+ /*
603
+ * call-seq:
604
+ * context.tracing -> bool
605
+ *
606
+ * Returns the tracing flag for the current context.
607
+ */
608
+ static VALUE
609
+ Context_tracing(VALUE self)
610
+ {
611
+ debug_context_t *context = debug_context_ptr(self);
612
+
613
+ return CTX_FL_TEST(context, CTX_FL_TRACING) ? Qtrue : Qfalse;
614
+ }
615
+
616
+ /*
617
+ * call-seq:
618
+ * context.tracing = bool
619
+ *
620
+ * Controls the tracing for this context.
621
+ */
622
+ static VALUE
623
+ Context_set_tracing(VALUE self, VALUE value)
624
+ {
625
+ debug_context_t *context = debug_context_ptr(self);
626
+
627
+ if (RTEST(value))
628
+ CTX_FL_SET(context, CTX_FL_TRACING);
629
+ else
630
+ CTX_FL_UNSET(context, CTX_FL_TRACING);
631
+ return value;
632
+ }
633
+
634
+ /* :nodoc: */
635
+ static VALUE
636
+ dt_inherited(VALUE klass)
637
+ {
638
+ UNUSED(klass);
639
+
640
+ rb_raise(rb_eRuntimeError, "Can't inherit Byebug::DebugThread class");
641
+
642
+ return Qnil;
643
+ }
644
+
645
+ /*
646
+ * Document-class: Context
647
+ *
648
+ * == Summary
649
+ *
650
+ * Byebug keeps a single instance of this class per thread.
651
+ */
652
+ void
653
+ Init_byebug_context(VALUE mByebug)
654
+ {
655
+ cContext = rb_define_class_under(mByebug, "Context", rb_cObject);
656
+ rb_undef_alloc_func(cContext);
657
+
658
+ rb_define_method(cContext, "backtrace", Context_backtrace, 0);
659
+ rb_define_method(cContext, "dead?", Context_dead, 0);
660
+ rb_define_method(cContext, "frame_binding", Context_frame_binding, -1);
661
+ rb_define_method(cContext, "frame_class", Context_frame_class, -1);
662
+ rb_define_method(cContext, "frame_file", Context_frame_file, -1);
663
+ rb_define_method(cContext, "frame_line", Context_frame_line, -1);
664
+ rb_define_method(cContext, "frame_method", Context_frame_method, -1);
665
+ rb_define_method(cContext, "frame_self", Context_frame_self, -1);
666
+ rb_define_method(cContext, "ignored?", Context_ignored, 0);
667
+ rb_define_method(cContext, "resume", Context_resume, 0);
668
+ rb_define_method(cContext, "step_into", Context_step_into, -1);
669
+ rb_define_method(cContext, "step_out", Context_step_out, -1);
670
+ rb_define_method(cContext, "step_over", Context_step_over, -1);
671
+ rb_define_method(cContext, "stop_reason", Context_stop_reason, 0);
672
+ rb_define_method(cContext, "suspend", Context_suspend, 0);
673
+ rb_define_method(cContext, "suspended?", Context_is_suspended, 0);
674
+ rb_define_method(cContext, "switch", Context_switch, 0);
675
+ rb_define_method(cContext, "thnum", Context_thnum, 0);
676
+ rb_define_method(cContext, "thread", Context_thread, 0);
677
+ rb_define_method(cContext, "tracing", Context_tracing, 0);
678
+ rb_define_method(cContext, "tracing=", Context_set_tracing, 1);
679
+
680
+ cDebugThread = rb_define_class_under(mByebug, "DebugThread", rb_cThread);
681
+ rb_define_singleton_method(cDebugThread, "inherited", dt_inherited, 0);
682
+ }
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ makefile_config = RbConfig::MAKEFILE_CONFIG
6
+
7
+ makefile_config["CC"] = ENV["CC"] if ENV["CC"]
8
+
9
+ makefile_config["CFLAGS"] << " -gdwarf-2 -g3 -O0" if ENV["debug"]
10
+
11
+ dir_config("ruby")
12
+ with_cflags(makefile_config["CFLAGS"]) { create_makefile("byebug/byebug") }