byebug 3.5.1 → 4.0.0

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.rubocop.yml +18 -1
  4. data/.travis.yml +21 -1
  5. data/CHANGELOG.md +356 -308
  6. data/CONTRIBUTING.md +31 -15
  7. data/GUIDE.md +859 -475
  8. data/Gemfile +8 -10
  9. data/LICENSE +1 -1
  10. data/README.md +41 -45
  11. data/Rakefile +30 -28
  12. data/byebug.gemspec +18 -18
  13. data/ext/byebug/breakpoint.c +88 -75
  14. data/ext/byebug/byebug.c +253 -252
  15. data/ext/byebug/byebug.h +53 -53
  16. data/ext/byebug/context.c +188 -159
  17. data/ext/byebug/extconf.rb +9 -6
  18. data/ext/byebug/locker.c +53 -11
  19. data/ext/byebug/threads.c +137 -39
  20. data/lib/byebug/attacher.rb +7 -2
  21. data/lib/byebug/breakpoint.rb +30 -0
  22. data/lib/byebug/command.rb +36 -32
  23. data/lib/byebug/commands/break.rb +49 -48
  24. data/lib/byebug/commands/catch.rb +64 -0
  25. data/lib/byebug/commands/condition.rb +13 -9
  26. data/lib/byebug/commands/continue.rb +8 -4
  27. data/lib/byebug/commands/delete.rb +10 -4
  28. data/lib/byebug/commands/display.rb +33 -25
  29. data/lib/byebug/commands/edit.rb +18 -13
  30. data/lib/byebug/commands/enable_disable.rb +26 -24
  31. data/lib/byebug/commands/eval.rb +77 -35
  32. data/lib/byebug/commands/finish.rb +9 -5
  33. data/lib/byebug/commands/frame.rb +66 -125
  34. data/lib/byebug/commands/help.rb +14 -21
  35. data/lib/byebug/commands/history.rb +5 -1
  36. data/lib/byebug/commands/info.rb +41 -106
  37. data/lib/byebug/commands/interrupt.rb +6 -2
  38. data/lib/byebug/commands/irb.rb +5 -2
  39. data/lib/byebug/commands/kill.rb +6 -2
  40. data/lib/byebug/commands/list.rb +21 -14
  41. data/lib/byebug/commands/method.rb +17 -9
  42. data/lib/byebug/commands/pry.rb +13 -3
  43. data/lib/byebug/commands/quit.rb +10 -5
  44. data/lib/byebug/commands/restart.rb +12 -19
  45. data/lib/byebug/commands/save.rb +10 -6
  46. data/lib/byebug/commands/set.rb +15 -14
  47. data/lib/byebug/commands/show.rb +8 -8
  48. data/lib/byebug/commands/source.rb +14 -8
  49. data/lib/byebug/commands/stepping.rb +15 -29
  50. data/lib/byebug/commands/threads.rb +73 -49
  51. data/lib/byebug/commands/tracevar.rb +56 -0
  52. data/lib/byebug/commands/undisplay.rb +8 -4
  53. data/lib/byebug/commands/untracevar.rb +38 -0
  54. data/lib/byebug/commands/var.rb +107 -0
  55. data/lib/byebug/context.rb +78 -42
  56. data/lib/byebug/core.rb +78 -40
  57. data/lib/byebug/helper.rb +58 -42
  58. data/lib/byebug/history.rb +12 -1
  59. data/lib/byebug/interface.rb +91 -11
  60. data/lib/byebug/interfaces/local_interface.rb +12 -19
  61. data/lib/byebug/interfaces/remote_interface.rb +12 -15
  62. data/lib/byebug/interfaces/script_interface.rb +14 -18
  63. data/lib/byebug/interfaces/test_interface.rb +54 -0
  64. data/lib/byebug/printers/base.rb +64 -0
  65. data/lib/byebug/printers/plain.rb +53 -0
  66. data/lib/byebug/processor.rb +20 -1
  67. data/lib/byebug/processors/command_processor.rb +57 -172
  68. data/lib/byebug/processors/control_command_processor.rb +16 -43
  69. data/lib/byebug/remote.rb +13 -7
  70. data/lib/byebug/runner.rb +102 -54
  71. data/lib/byebug/setting.rb +45 -68
  72. data/lib/byebug/settings/autoeval.rb +2 -0
  73. data/lib/byebug/settings/autoirb.rb +3 -0
  74. data/lib/byebug/settings/autolist.rb +3 -0
  75. data/lib/byebug/settings/autosave.rb +2 -0
  76. data/lib/byebug/settings/basename.rb +2 -0
  77. data/lib/byebug/settings/callstyle.rb +2 -0
  78. data/lib/byebug/settings/fullpath.rb +2 -0
  79. data/lib/byebug/settings/histfile.rb +2 -0
  80. data/lib/byebug/settings/histsize.rb +2 -0
  81. data/lib/byebug/settings/linetrace.rb +2 -0
  82. data/lib/byebug/settings/listsize.rb +2 -0
  83. data/lib/byebug/settings/post_mortem.rb +7 -2
  84. data/lib/byebug/settings/stack_on_error.rb +2 -0
  85. data/lib/byebug/settings/verbose.rb +2 -0
  86. data/lib/byebug/settings/width.rb +2 -0
  87. data/lib/byebug/state.rb +12 -0
  88. data/lib/byebug/states/control_state.rb +26 -0
  89. data/lib/byebug/states/regular_state.rb +178 -0
  90. data/lib/byebug/version.rb +1 -1
  91. metadata +24 -109
  92. data/lib/byebug/commands/catchpoint.rb +0 -53
  93. data/lib/byebug/commands/reload.rb +0 -29
  94. data/lib/byebug/commands/trace.rb +0 -50
  95. data/lib/byebug/commands/variables.rb +0 -206
  96. data/lib/byebug/options.rb +0 -46
  97. data/lib/byebug/settings/autoreload.rb +0 -12
  98. data/lib/byebug/settings/forcestep.rb +0 -14
  99. data/lib/byebug/settings/testing.rb +0 -12
  100. data/lib/byebug/settings/tracing_plus.rb +0 -11
  101. data/test/commands/break_test.rb +0 -364
  102. data/test/commands/condition_test.rb +0 -85
  103. data/test/commands/continue_test.rb +0 -47
  104. data/test/commands/delete_test.rb +0 -26
  105. data/test/commands/display_test.rb +0 -37
  106. data/test/commands/edit_test.rb +0 -52
  107. data/test/commands/eval_test.rb +0 -89
  108. data/test/commands/finish_test.rb +0 -74
  109. data/test/commands/frame_test.rb +0 -223
  110. data/test/commands/help_test.rb +0 -66
  111. data/test/commands/history_test.rb +0 -61
  112. data/test/commands/info_test.rb +0 -238
  113. data/test/commands/interrupt_test.rb +0 -45
  114. data/test/commands/irb_test.rb +0 -28
  115. data/test/commands/kill_test.rb +0 -50
  116. data/test/commands/list_test.rb +0 -174
  117. data/test/commands/method_test.rb +0 -52
  118. data/test/commands/post_mortem_test.rb +0 -71
  119. data/test/commands/pry_test.rb +0 -26
  120. data/test/commands/quit_test.rb +0 -53
  121. data/test/commands/reload_test.rb +0 -39
  122. data/test/commands/restart_test.rb +0 -46
  123. data/test/commands/save_test.rb +0 -67
  124. data/test/commands/set_test.rb +0 -140
  125. data/test/commands/show_test.rb +0 -76
  126. data/test/commands/source_test.rb +0 -46
  127. data/test/commands/stepping_test.rb +0 -192
  128. data/test/commands/thread_test.rb +0 -164
  129. data/test/commands/trace_test.rb +0 -71
  130. data/test/commands/undisplay_test.rb +0 -75
  131. data/test/commands/variables_test.rb +0 -105
  132. data/test/debugger_alias_test.rb +0 -7
  133. data/test/runner_test.rb +0 -150
  134. data/test/support/matchers.rb +0 -65
  135. data/test/support/test_interface.rb +0 -59
  136. data/test/support/utils.rb +0 -122
  137. data/test/test_helper.rb +0 -58
@@ -1,10 +1,10 @@
1
1
  #include <byebug.h>
2
2
 
3
- static VALUE mByebug; /* Ruby Byebug Module object */
3
+ static VALUE mByebug; /* Ruby Byebug Module object */
4
4
 
5
- static VALUE tracing = Qfalse;
5
+ static VALUE tracing = Qfalse;
6
6
  static VALUE post_mortem = Qfalse;
7
- static VALUE verbose = Qfalse;
7
+ static VALUE verbose = Qfalse;
8
8
 
9
9
  static VALUE catchpoints = Qnil;
10
10
  static VALUE breakpoints = Qnil;
@@ -12,8 +12,7 @@ static VALUE tracepoints = Qnil;
12
12
 
13
13
  static VALUE raised_exception = Qnil;
14
14
 
15
- /* To allow thread syncronization, we must stop threads when debugging */
16
- VALUE locker = Qnil;
15
+ static ID idPuts;
17
16
 
18
17
  /* Hash table with active threads and their associated contexts */
19
18
  VALUE threads = Qnil;
@@ -25,8 +24,10 @@ VALUE threads = Qnil;
25
24
  * Returns an array of breakpoints.
26
25
  */
27
26
  static VALUE
28
- bb_breakpoints(VALUE self)
27
+ Breakpoints(VALUE self)
29
28
  {
29
+ UNUSED(self);
30
+
30
31
  if (NIL_P(breakpoints))
31
32
  breakpoints = rb_ary_new();
32
33
 
@@ -40,8 +41,10 @@ bb_breakpoints(VALUE self)
40
41
  * Returns an array of catchpoints.
41
42
  */
42
43
  static VALUE
43
- bb_catchpoints(VALUE self)
44
+ Catchpoints(VALUE self)
44
45
  {
46
+ UNUSED(self);
47
+
45
48
  return catchpoints;
46
49
  }
47
50
 
@@ -52,8 +55,10 @@ bb_catchpoints(VALUE self)
52
55
  * Returns raised exception when in post_mortem mode.
53
56
  */
54
57
  static VALUE
55
- bb_raised_exception(VALUE self)
58
+ Raised_exception(VALUE self)
56
59
  {
60
+ UNUSED(self);
61
+
57
62
  return raised_exception;
58
63
  }
59
64
 
@@ -68,90 +73,95 @@ check_started()
68
73
  }
69
74
 
70
75
  static void
71
- trace_print(rb_trace_arg_t *trace_arg, debug_context_t *dc)
76
+ trace_print(rb_trace_arg_t * trace_arg, debug_context_t * dc,
77
+ const char *file_filter, const char *debug_msg)
72
78
  {
73
- if (trace_arg)
74
- {
75
- const char *event = rb_id2name(SYM2ID(rb_tracearg_event(trace_arg)));
76
- char *path = RSTRING_PTR(rb_tracearg_path(trace_arg));
77
- int line = NUM2INT(rb_tracearg_lineno(trace_arg));
78
- VALUE v_mid_sym = rb_tracearg_method_id(trace_arg);
79
- VALUE v_mid_id = NIL_P(v_mid_sym) ? Qnil : SYM2ID(v_mid_sym);
80
- const char *mid = NIL_P(v_mid_id) ? "" : rb_id2name(v_mid_id);
81
- printf("%*s (%d)->[#%d] %s@%s:%d %s\n", dc->calced_stack_size, "",
82
- dc->calced_stack_size, dc->thnum, event, path, line, mid);
83
- }
84
- }
79
+ char *fullpath = NULL;
80
+ const char *basename;
81
+ int filtered = 0;
82
+ const char *event = rb_id2name(SYM2ID(rb_tracearg_event(trace_arg)));
85
83
 
86
- static void
87
- cleanup(debug_context_t *dc)
88
- {
89
- VALUE thread;
84
+ VALUE rb_path = rb_tracearg_path(trace_arg);
85
+ const char *path = NIL_P(rb_path) ? "" : RSTRING_PTR(rb_path);
90
86
 
91
- dc->stop_reason = CTX_STOP_NONE;
87
+ int line = NUM2INT(rb_tracearg_lineno(trace_arg));
92
88
 
93
- /* checks for dead threads */
94
- check_threads_table();
89
+ VALUE rb_mid = rb_tracearg_method_id(trace_arg);
90
+ const char *mid = NIL_P(rb_mid) ? "(top level)" : rb_id2name(SYM2ID(rb_mid));
95
91
 
96
- /* release a lock */
97
- locker = Qnil;
98
-
99
- /* let the next thread to run */
100
- thread = remove_from_locked();
101
- if (thread != Qnil)
102
- rb_thread_run(thread);
103
- }
92
+ VALUE rb_cl = rb_tracearg_defined_class(trace_arg);
93
+ VALUE rb_cl_name = NIL_P(rb_cl) ? rb_cl : rb_mod_name(rb_cl);
94
+ const char *defined_class = NIL_P(rb_cl_name) ? "" : RSTRING_PTR(rb_cl_name);
104
95
 
105
- #define EVENT_SETUP \
106
- rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(trace_point); \
107
- debug_context_t *dc; \
108
- VALUE context; \
109
- thread_context_lookup(rb_thread_current(), &context); \
110
- Data_Get_Struct(context, debug_context_t, dc); \
111
-
112
- #define EVENT_COMMON \
113
- if (verbose == Qtrue) trace_print(trace_arg, dc); \
114
- if (!trace_common(trace_arg, dc)) { return; } \
96
+ if (!trace_arg)
97
+ return;
115
98
 
116
- static int
117
- trace_common(rb_trace_arg_t *trace_arg, debug_context_t *dc)
118
- {
119
- /* return if thread marked as 'ignored', like byebug's control thread */
120
- if (CTX_FL_TEST(dc, CTX_FL_IGNORE))
99
+ if (file_filter)
121
100
  {
122
- cleanup(dc);
123
- return 0;
124
- }
101
+ #ifndef _WIN32
102
+ fullpath = realpath(path, NULL);
103
+ #endif
104
+ basename = fullpath ? strrchr(fullpath, '/') : path;
125
105
 
126
- halt_while_other_thread_is_active(dc);
106
+ if (!basename || strncmp(basename + 1, file_filter, strlen(file_filter)))
107
+ filtered = 1;
127
108
 
128
- /* Get the lock! */
129
- locker = rb_thread_current();
109
+ #ifndef _WIN32
110
+ free(fullpath);
111
+ #endif
112
+ }
130
113
 
131
- /* Many events per line, but only *one* breakpoint */
132
- if (dc->last_line != rb_tracearg_lineno(trace_arg) ||
133
- dc->last_file != rb_tracearg_path(trace_arg))
114
+ if (!filtered)
134
115
  {
135
- CTX_FL_SET(dc, CTX_FL_ENABLE_BKPT);
116
+ if (debug_msg)
117
+ rb_funcall(mByebug, idPuts, 1,
118
+ rb_sprintf("[#%d] %s\n", dc->thnum, debug_msg));
119
+ else
120
+ rb_funcall(mByebug, idPuts, 1,
121
+ rb_sprintf("%*s [#%d] %s@%s:%d %s#%s\n", dc->calced_stack_size,
122
+ "", dc->thnum, event, path, line, defined_class,
123
+ mid));
136
124
  }
137
-
138
- return 1;
139
125
  }
140
126
 
141
127
  static void
142
- save_current_position(debug_context_t *dc, VALUE file, VALUE line)
128
+ cleanup(debug_context_t * dc)
143
129
  {
144
- dc->last_file = file;
145
- dc->last_line = line;
146
- CTX_FL_UNSET(dc, CTX_FL_ENABLE_BKPT);
147
- CTX_FL_UNSET(dc, CTX_FL_FORCE_MOVE);
148
- }
130
+ dc->stop_reason = CTX_STOP_NONE;
131
+
132
+ release_lock();
133
+ }
134
+
135
+ #define EVENT_TEARDOWN cleanup(dc);
136
+
137
+ #define EVENT_SETUP \
138
+ debug_context_t *dc; \
139
+ VALUE context; \
140
+ rb_trace_arg_t *trace_arg; \
141
+ \
142
+ UNUSED(data); \
143
+ \
144
+ if (!is_living_thread(rb_thread_current())) \
145
+ return; \
146
+ \
147
+ thread_context_lookup(rb_thread_current(), &context); \
148
+ Data_Get_Struct(context, debug_context_t, dc); \
149
+ \
150
+ if (CTX_FL_TEST(dc, CTX_FL_IGNORE)) \
151
+ return; \
152
+ \
153
+ acquire_lock(dc); \
154
+ \
155
+ trace_arg = rb_tracearg_from_tracepoint(trace_point); \
156
+ if (verbose == Qtrue) \
157
+ trace_print(trace_arg, dc, 0, 0); \
158
+
149
159
 
150
160
  /* Functions that return control to byebug after the different events */
151
161
 
152
162
  static VALUE
153
- call_at(VALUE context_obj, debug_context_t *dc, ID mid, int argc, VALUE a0,
154
- VALUE a1)
163
+ call_at(VALUE context_obj, debug_context_t * dc, ID mid, int argc, VALUE a0,
164
+ VALUE a1)
155
165
  {
156
166
  struct call_with_inspection_data cwi;
157
167
  VALUE argv[2];
@@ -159,52 +169,51 @@ call_at(VALUE context_obj, debug_context_t *dc, ID mid, int argc, VALUE a0,
159
169
  argv[0] = a0;
160
170
  argv[1] = a1;
161
171
 
162
- cwi.dc = dc;
172
+ cwi.dc = dc;
163
173
  cwi.context_obj = context_obj;
164
- cwi.id = mid;
165
- cwi.argc = argc;
166
- cwi.argv = &argv[0];
174
+ cwi.id = mid;
175
+ cwi.argc = argc;
176
+ cwi.argv = &argv[0];
167
177
 
168
178
  return call_with_debug_inspector(&cwi);
169
179
  }
170
180
 
171
181
  static VALUE
172
- call_at_line(VALUE context_obj, debug_context_t *dc, VALUE file, VALUE line)
182
+ call_at_line(VALUE context_obj, debug_context_t * dc, VALUE file, VALUE line)
173
183
  {
174
- save_current_position(dc, file, line);
175
184
  return call_at(context_obj, dc, rb_intern("at_line"), 2, file, line);
176
185
  }
177
186
 
178
187
  static VALUE
179
- call_at_tracing(VALUE context_obj, debug_context_t *dc, VALUE file, VALUE line)
188
+ call_at_tracing(VALUE context_obj, debug_context_t * dc, VALUE file, VALUE line)
180
189
  {
181
190
  return call_at(context_obj, dc, rb_intern("at_tracing"), 2, file, line);
182
191
  }
183
192
 
184
193
  static VALUE
185
- call_at_breakpoint(VALUE context_obj, debug_context_t *dc, VALUE breakpoint)
194
+ call_at_breakpoint(VALUE context_obj, debug_context_t * dc, VALUE breakpoint)
186
195
  {
187
196
  dc->stop_reason = CTX_STOP_BREAKPOINT;
188
197
  return call_at(context_obj, dc, rb_intern("at_breakpoint"), 1, breakpoint, 0);
189
198
  }
190
199
 
191
200
  static VALUE
192
- call_at_catchpoint(VALUE context_obj, debug_context_t *dc, VALUE exp)
201
+ call_at_catchpoint(VALUE context_obj, debug_context_t * dc, VALUE exp)
193
202
  {
194
203
  dc->stop_reason = CTX_STOP_CATCHPOINT;
195
204
  return call_at(context_obj, dc, rb_intern("at_catchpoint"), 1, exp, 0);
196
205
  }
197
206
 
198
207
  static VALUE
199
- call_at_return(VALUE context_obj, debug_context_t *dc, VALUE file, VALUE line)
208
+ call_at_return(VALUE context_obj, debug_context_t * dc, VALUE file, VALUE line)
200
209
  {
201
- CTX_FL_UNSET(dc, CTX_FL_STOP_ON_RET);
210
+ dc->stop_reason = CTX_STOP_BREAKPOINT;
202
211
  return call_at(context_obj, dc, rb_intern("at_return"), 2, file, line);
203
212
  }
204
213
 
205
214
  static void
206
- call_at_line_check(VALUE context_obj, debug_context_t *dc,
207
- VALUE breakpoint, VALUE file, VALUE line)
215
+ call_at_line_check(VALUE context_obj, debug_context_t * dc, VALUE breakpoint,
216
+ VALUE file, VALUE line)
208
217
  {
209
218
  dc->stop_reason = CTX_STOP_STEP;
210
219
 
@@ -221,102 +230,95 @@ call_at_line_check(VALUE context_obj, debug_context_t *dc,
221
230
  static void
222
231
  line_event(VALUE trace_point, void *data)
223
232
  {
224
- VALUE breakpoint, file, line, binding, self;
225
- int moved = 0;
233
+ VALUE brkpnt, file, line, binding;
226
234
 
227
- EVENT_SETUP
235
+ EVENT_SETUP;
228
236
 
229
- breakpoint = Qnil;
230
- file = rb_tracearg_path(trace_arg);
231
- line = rb_tracearg_lineno(trace_arg);
237
+ file = rb_tracearg_path(trace_arg);
238
+ line = rb_tracearg_lineno(trace_arg);
232
239
  binding = rb_tracearg_binding(trace_arg);
233
- self = rb_tracearg_self(trace_arg);
234
-
235
- EVENT_COMMON
236
-
237
- if (dc->calced_stack_size == 0) dc->calced_stack_size++;
238
-
239
- if (dc->last_line != rb_tracearg_lineno(trace_arg) ||
240
- dc->last_file != rb_tracearg_path(trace_arg))
241
- {
242
- moved = 1;
243
- }
244
240
 
245
241
  if (RTEST(tracing))
246
242
  call_at_tracing(context, dc, file, line);
247
243
 
248
- if (moved || !CTX_FL_TEST(dc, CTX_FL_FORCE_MOVE))
249
- {
244
+ if (!CTX_FL_TEST(dc, CTX_FL_IGNORE_STEPS))
250
245
  dc->steps = dc->steps <= 0 ? -1 : dc->steps - 1;
251
- if (dc->calced_stack_size <= dc->dest_frame)
252
- {
253
- dc->lines = dc->lines <= 0 ? -1 : dc->lines - 1;
254
- if (dc->calced_stack_size < dc->dest_frame)
255
- {
256
- dc->dest_frame = dc->calced_stack_size;
257
- rb_funcall(mByebug, rb_intern("puts"), 1,
258
- rb_str_new2("Next went up a frame because previous frame finished\n"));
259
- }
260
- }
261
- }
262
246
 
263
- if (dc->steps == 0 || dc->lines == 0 ||
264
- (CTX_FL_TEST(dc, CTX_FL_ENABLE_BKPT) &&
265
- (!NIL_P(
266
- breakpoint = find_breakpoint_by_pos(bb_breakpoints(self), file, line, binding)))))
247
+ if (dc->calced_stack_size <= dc->dest_frame)
267
248
  {
268
- call_at_line_check(context, dc, breakpoint, file, line);
249
+ dc->dest_frame = dc->calced_stack_size;
250
+ CTX_FL_UNSET(dc, CTX_FL_IGNORE_STEPS);
251
+
252
+ dc->lines = dc->lines <= 0 ? -1 : dc->lines - 1;
269
253
  }
270
254
 
271
- cleanup(dc);
255
+ if (dc->steps == 0 || dc->lines == 0)
256
+ call_at_line_check(context, dc, Qnil, file, line);
257
+
258
+ brkpnt = Qnil;
259
+
260
+ if (!NIL_P(breakpoints))
261
+ brkpnt = find_breakpoint_by_pos(breakpoints, file, line, binding);
262
+
263
+ if (!NIL_P(brkpnt))
264
+ call_at_line_check(context, dc, brkpnt, file, line);
265
+
266
+ EVENT_TEARDOWN;
272
267
  }
273
268
 
274
269
  static void
275
270
  call_event(VALUE trace_point, void *data)
276
271
  {
277
- VALUE breakpoint, klass, msym, mid, binding, self, file, line;
272
+ VALUE brkpnt, klass, msym, mid, binding, self, file, line;
278
273
 
279
- EVENT_SETUP
274
+ EVENT_SETUP;
275
+
276
+ if (dc->calced_stack_size <= dc->dest_frame)
277
+ CTX_FL_UNSET(dc, CTX_FL_IGNORE_STEPS);
280
278
 
281
279
  dc->calced_stack_size++;
282
280
 
283
- if (CTX_FL_TEST(dc, CTX_FL_STOP_ON_RET))
284
- dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out + 1;
281
+ dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out + 1;
285
282
 
286
- EVENT_COMMON
283
+ /* nil method_id means we are at top level so there can't be a method
284
+ * breakpoint here. Just leave then. */
285
+ msym = rb_tracearg_method_id(trace_arg);
286
+ if (NIL_P(msym))
287
+ {
288
+ EVENT_TEARDOWN;
289
+ return;
290
+ }
287
291
 
288
- breakpoint = Qnil;
289
- klass = rb_tracearg_defined_class(trace_arg);
290
- msym = rb_tracearg_method_id(trace_arg);
291
- mid = NIL_P(msym) ? Qnil : SYM2ID(msym);
292
+ mid = SYM2ID(msym);
293
+ klass = rb_tracearg_defined_class(trace_arg);
292
294
  binding = rb_tracearg_binding(trace_arg);
293
- self = rb_tracearg_self(trace_arg);
294
- file = rb_tracearg_path(trace_arg);
295
- line = rb_tracearg_lineno(trace_arg);
295
+ self = rb_tracearg_self(trace_arg);
296
+ file = rb_tracearg_path(trace_arg);
297
+ line = rb_tracearg_lineno(trace_arg);
296
298
 
297
- breakpoint = find_breakpoint_by_method(bb_breakpoints(self), klass, mid, binding, self);
298
- if (breakpoint != Qnil)
299
+ brkpnt = Qnil;
300
+
301
+ if (!NIL_P(breakpoints))
302
+ brkpnt = find_breakpoint_by_method(breakpoints, klass, mid, binding, self);
303
+
304
+ if (!NIL_P(brkpnt))
299
305
  {
300
- call_at_breakpoint(context, dc, breakpoint);
306
+ call_at_breakpoint(context, dc, brkpnt);
301
307
  call_at_line(context, dc, file, line);
302
308
  }
303
309
 
304
- cleanup(dc);
310
+ EVENT_TEARDOWN;
305
311
  }
306
312
 
307
313
  static void
308
314
  return_event(VALUE trace_point, void *data)
309
315
  {
310
- EVENT_SETUP
311
-
312
- if (dc->calced_stack_size > 0) dc->calced_stack_size--;
316
+ EVENT_SETUP;
313
317
 
314
- EVENT_COMMON
318
+ dc->calced_stack_size--;
315
319
 
316
320
  if (dc->steps_out == 1)
317
- {
318
321
  dc->steps = 1;
319
- }
320
322
  else if ((dc->steps_out == 0) && (CTX_FL_TEST(dc, CTX_FL_STOP_ON_RET)))
321
323
  {
322
324
  VALUE file, line;
@@ -329,41 +331,27 @@ return_event(VALUE trace_point, void *data)
329
331
 
330
332
  dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out - 1;
331
333
 
332
- cleanup(dc);
334
+ EVENT_TEARDOWN;
333
335
  }
334
336
 
335
337
  static void
336
- c_call_event(VALUE trace_point, void *data)
338
+ raw_call_event(VALUE trace_point, void *data)
337
339
  {
338
- EVENT_SETUP
340
+ EVENT_SETUP;
339
341
 
340
342
  dc->calced_stack_size++;
341
343
 
342
- EVENT_COMMON
343
-
344
- cleanup(dc);
344
+ EVENT_TEARDOWN;
345
345
  }
346
346
 
347
347
  static void
348
- c_return_event(VALUE trace_point, void *data)
348
+ raw_return_event(VALUE trace_point, void *data)
349
349
  {
350
- EVENT_SETUP
350
+ EVENT_SETUP;
351
351
 
352
- if (dc->calced_stack_size > 0) dc->calced_stack_size--;
352
+ dc->calced_stack_size--;
353
353
 
354
- EVENT_COMMON
355
-
356
- cleanup(dc);
357
- }
358
-
359
- static void
360
- thread_event(VALUE trace_point, void *data)
361
- {
362
- EVENT_SETUP
363
-
364
- EVENT_COMMON
365
-
366
- cleanup(dc);
354
+ EVENT_TEARDOWN;
367
355
  }
368
356
 
369
357
  static void
@@ -374,32 +362,30 @@ raise_event(VALUE trace_point, void *data)
374
362
  int i;
375
363
  debug_context_t *new_dc;
376
364
 
377
- EVENT_SETUP
378
-
379
- EVENT_COMMON
365
+ EVENT_SETUP;
380
366
 
381
- path = rb_tracearg_path(trace_arg);
382
- lineno = rb_tracearg_lineno(trace_arg);
383
- binding = rb_tracearg_binding(trace_arg);
367
+ path = rb_tracearg_path(trace_arg);
368
+ lineno = rb_tracearg_lineno(trace_arg);
369
+ binding = rb_tracearg_binding(trace_arg);
384
370
  raised_exception = rb_tracearg_raised_exception(trace_arg);
385
371
 
386
372
  if (post_mortem == Qtrue)
387
373
  {
388
374
  post_mortem_context = context_dup(dc);
389
- rb_ivar_set(raised_exception, rb_intern("@__bb_file") , path);
390
- rb_ivar_set(raised_exception, rb_intern("@__bb_line") , lineno);
375
+ rb_ivar_set(raised_exception, rb_intern("@__bb_file"), path);
376
+ rb_ivar_set(raised_exception, rb_intern("@__bb_line"), lineno);
391
377
  rb_ivar_set(raised_exception, rb_intern("@__bb_binding"), binding);
392
- rb_ivar_set(raised_exception, rb_intern("@__bb_context"), post_mortem_context);
378
+ rb_ivar_set(raised_exception, rb_intern("@__bb_context"),
379
+ post_mortem_context);
393
380
 
394
381
  Data_Get_Struct(post_mortem_context, debug_context_t, new_dc);
395
382
  rb_debug_inspector_open(context_backtrace_set, (void *)new_dc);
396
383
  }
397
384
 
398
- if (catchpoints == Qnil ||
399
- dc->calced_stack_size == 0 ||
400
- RHASH_TBL(catchpoints)->num_entries == 0)
385
+ if (catchpoints == Qnil || dc->calced_stack_size == 0
386
+ || RHASH_TBL(catchpoints)->num_entries == 0)
401
387
  {
402
- cleanup(dc);
388
+ EVENT_TEARDOWN;
403
389
  return;
404
390
  }
405
391
 
@@ -410,8 +396,8 @@ raise_event(VALUE trace_point, void *data)
410
396
  VALUE ancestor_class, module_name, hit_count;
411
397
 
412
398
  ancestor_class = rb_ary_entry(ancestors, i);
413
- module_name = rb_mod_name(ancestor_class);
414
- hit_count = rb_hash_aref(catchpoints, module_name);
399
+ module_name = rb_mod_name(ancestor_class);
400
+ hit_count = rb_hash_aref(catchpoints, module_name);
415
401
 
416
402
  /* increment exception */
417
403
  if (hit_count != Qnil)
@@ -423,7 +409,7 @@ raise_event(VALUE trace_point, void *data)
423
409
  }
424
410
  }
425
411
 
426
- cleanup(dc);
412
+ EVENT_TEARDOWN;
427
413
  }
428
414
 
429
415
 
@@ -435,23 +421,23 @@ register_tracepoints(VALUE self)
435
421
  int i;
436
422
  VALUE traces = tracepoints;
437
423
 
424
+ UNUSED(self);
425
+
438
426
  if (NIL_P(traces))
439
427
  {
440
- int line_msk = RUBY_EVENT_LINE;
441
- int call_msk = RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS;
442
- int return_msk = RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_END;
443
- int c_call_msk = RUBY_EVENT_C_CALL;
444
- int c_ret_msk = RUBY_EVENT_C_RETURN;
445
- int raise_msk = RUBY_EVENT_RAISE;
446
- int thread_msk = RUBY_EVENT_THREAD_BEGIN | RUBY_EVENT_THREAD_END;
447
-
448
- VALUE tpLine = rb_tracepoint_new(Qnil, line_msk , line_event , 0);
449
- VALUE tpCall = rb_tracepoint_new(Qnil, call_msk , call_event , 0);
450
- VALUE tpReturn = rb_tracepoint_new(Qnil, return_msk, return_event , 0);
451
- VALUE tpCCall = rb_tracepoint_new(Qnil, c_call_msk, c_call_event , 0);
452
- VALUE tpCReturn = rb_tracepoint_new(Qnil, c_ret_msk , c_return_event, 0);
453
- VALUE tpRaise = rb_tracepoint_new(Qnil, raise_msk , raise_event , 0);
454
- VALUE tpThread = rb_tracepoint_new(Qnil, thread_msk, thread_event , 0);
428
+ int line_msk = RUBY_EVENT_LINE;
429
+ int call_msk = RUBY_EVENT_CALL;
430
+ int ret_msk = RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_END;
431
+ int raw_call_msk = RUBY_EVENT_C_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS;
432
+ int raw_ret_msk = RUBY_EVENT_C_RETURN;
433
+ int raise_msk = RUBY_EVENT_RAISE;
434
+
435
+ VALUE tpLine = rb_tracepoint_new(Qnil, line_msk, line_event, 0);
436
+ VALUE tpCall = rb_tracepoint_new(Qnil, call_msk, call_event, 0);
437
+ VALUE tpReturn = rb_tracepoint_new(Qnil, ret_msk, return_event, 0);
438
+ VALUE tpCCall = rb_tracepoint_new(Qnil, raw_call_msk, raw_call_event, 0);
439
+ VALUE tpCReturn = rb_tracepoint_new(Qnil, raw_ret_msk, raw_return_event, 0);
440
+ VALUE tpRaise = rb_tracepoint_new(Qnil, raise_msk, raise_event, 0);
455
441
 
456
442
  traces = rb_ary_new();
457
443
  rb_ary_push(traces, tpLine);
@@ -460,7 +446,6 @@ register_tracepoints(VALUE self)
460
446
  rb_ary_push(traces, tpCCall);
461
447
  rb_ary_push(traces, tpCReturn);
462
448
  rb_ary_push(traces, tpRaise);
463
- rb_ary_push(traces, tpThread);
464
449
 
465
450
  tracepoints = traces;
466
451
  }
@@ -474,7 +459,9 @@ clear_tracepoints(VALUE self)
474
459
  {
475
460
  int i;
476
461
 
477
- for (i = RARRAY_LENINT(tracepoints)-1; i >= 0; i--)
462
+ UNUSED(self);
463
+
464
+ for (i = RARRAY_LENINT(tracepoints) - 1; i >= 0; i--)
478
465
  rb_tracepoint_disable(rb_ary_entry(tracepoints, i));
479
466
  }
480
467
 
@@ -488,7 +475,7 @@ clear_tracepoints(VALUE self)
488
475
  * Returns an array of all contexts.
489
476
  */
490
477
  static VALUE
491
- bb_contexts(VALUE self)
478
+ Contexts(VALUE self)
492
479
  {
493
480
  volatile VALUE list;
494
481
  volatile VALUE new_list;
@@ -497,6 +484,8 @@ bb_contexts(VALUE self)
497
484
  debug_context_t *dc;
498
485
  int i;
499
486
 
487
+ UNUSED(self);
488
+
500
489
  check_started();
501
490
 
502
491
  new_list = rb_ary_new();
@@ -505,6 +494,7 @@ bb_contexts(VALUE self)
505
494
  for (i = 0; i < RARRAY_LENINT(list); i++)
506
495
  {
507
496
  VALUE thread = rb_ary_entry(list, i);
497
+
508
498
  thread_context_lookup(thread, &context);
509
499
  rb_ary_push(new_list, context);
510
500
  }
@@ -529,10 +519,12 @@ bb_contexts(VALUE self)
529
519
  * Returns context of the thread passed as an argument.
530
520
  */
531
521
  static VALUE
532
- bb_thread_context(VALUE self, VALUE thread)
522
+ Thread_context(VALUE self, VALUE thread)
533
523
  {
534
524
  VALUE context;
535
525
 
526
+ UNUSED(self);
527
+
536
528
  check_started();
537
529
 
538
530
  thread_context_lookup(thread, &context);
@@ -548,10 +540,12 @@ bb_thread_context(VALUE self, VALUE thread)
548
540
  * <i>Note:</i> Byebug.current_context.thread == Thread.current
549
541
  */
550
542
  static VALUE
551
- bb_current_context(VALUE self)
543
+ Current_context(VALUE self)
552
544
  {
553
545
  VALUE context;
554
546
 
547
+ UNUSED(self);
548
+
555
549
  check_started();
556
550
 
557
551
  thread_context_lookup(rb_thread_current(), &context);
@@ -566,8 +560,10 @@ bb_current_context(VALUE self)
566
560
  * Returns +true+ byebug is started.
567
561
  */
568
562
  static VALUE
569
- bb_started(VALUE self)
563
+ Started(VALUE self)
570
564
  {
565
+ UNUSED(self);
566
+
571
567
  return IS_STARTED;
572
568
  }
573
569
 
@@ -579,55 +575,49 @@ bb_started(VALUE self)
579
575
  * disabled, otherwise it returns +false+.
580
576
  */
581
577
  static VALUE
582
- bb_stop(VALUE self)
578
+ Stop(VALUE self)
583
579
  {
580
+ UNUSED(self);
581
+
584
582
  if (IS_STARTED)
585
583
  {
586
584
  clear_tracepoints(self);
587
585
 
588
586
  breakpoints = Qnil;
589
587
  catchpoints = Qnil;
590
- threads = Qnil;
588
+ threads = Qnil;
591
589
 
592
590
  return Qfalse;
593
591
  }
592
+
594
593
  return Qtrue;
595
594
  }
596
595
 
597
596
  /*
598
597
  * call-seq:
599
598
  * Byebug.start -> bool
600
- * Byebug.start { ... } -> bool
601
- *
602
- * If a block is given, it starts byebug and yields block. After the block is
603
- * executed it stops byebug with Byebug.stop method. Inside the block you
604
- * will probably want to have a call to Byebug.byebug. For example:
605
- *
606
- * Byebug.start { byebug; foo } # Stop inside of foo
607
599
  *
608
600
  * The return value is the value of !Byebug.started? <i>before</i> issuing the
609
601
  * +start+; That is, +true+ is returned, unless byebug was previously started.
610
602
  */
611
603
  static VALUE
612
- bb_start(VALUE self)
604
+ Start(VALUE self)
613
605
  {
614
606
  VALUE result;
615
607
 
608
+ UNUSED(self);
609
+
616
610
  if (IS_STARTED)
617
611
  result = Qfalse;
618
612
  else
619
613
  {
620
- locker = Qnil;
621
614
  catchpoints = rb_hash_new();
622
- threads = create_threads_table();
615
+ threads = create_threads_table();
623
616
 
624
617
  register_tracepoints(self);
625
618
  result = Qtrue;
626
619
  }
627
620
 
628
- if (rb_block_given_p())
629
- rb_ensure(rb_yield, self, bb_stop, self);
630
-
631
621
  return result;
632
622
  }
633
623
 
@@ -639,29 +629,28 @@ bb_start(VALUE self)
639
629
  * +stop+ parameter forces byebug to stop at the first line of code in +file+
640
630
  */
641
631
  static VALUE
642
- bb_load(int argc, VALUE *argv, VALUE self)
632
+ Debug_load(int argc, VALUE * argv, VALUE self)
643
633
  {
644
634
  VALUE file, stop, context;
645
635
  debug_context_t *dc;
646
636
  VALUE status = Qnil;
647
637
  int state = 0;
648
638
 
639
+ UNUSED(self);
640
+
649
641
  if (rb_scan_args(argc, argv, "11", &file, &stop) == 1)
650
- {
651
642
  stop = Qfalse;
652
- }
653
643
 
654
- bb_start(self);
644
+ Start(self);
655
645
 
656
- context = bb_current_context(self);
646
+ context = Current_context(self);
657
647
  Data_Get_Struct(context, debug_context_t, dc);
658
648
 
659
649
  dc->calced_stack_size = 1;
660
650
 
661
- if (RTEST(stop)) dc->steps = 1;
651
+ if (RTEST(stop))
652
+ dc->steps = 1;
662
653
 
663
- /* Initializing $0 to the script's path */
664
- ruby_script(RSTRING_PTR(file));
665
654
  rb_load_protect(file, 0, &state);
666
655
  if (0 != state)
667
656
  {
@@ -669,10 +658,6 @@ bb_load(int argc, VALUE *argv, VALUE self)
669
658
  reset_stepping_stop_points(dc);
670
659
  }
671
660
 
672
- /* We should run all at_exit handler's in order to provide, for instance, a
673
- * chance to run all defined test cases */
674
- rb_exec_end_proc();
675
-
676
661
  return status;
677
662
  }
678
663
 
@@ -683,8 +668,10 @@ bb_load(int argc, VALUE *argv, VALUE self)
683
668
  * Returns +true+ if verbose output of TracePoint API events is enabled.
684
669
  */
685
670
  static VALUE
686
- bb_verbose(VALUE self)
671
+ Verbose(VALUE self)
687
672
  {
673
+ UNUSED(self);
674
+
688
675
  return verbose;
689
676
  }
690
677
 
@@ -696,8 +683,10 @@ bb_verbose(VALUE self)
696
683
  * byebug.
697
684
  */
698
685
  static VALUE
699
- bb_set_verbose(VALUE self, VALUE value)
686
+ Set_verbose(VALUE self, VALUE value)
700
687
  {
688
+ UNUSED(self);
689
+
701
690
  verbose = RTEST(value) ? Qtrue : Qfalse;
702
691
  return value;
703
692
  }
@@ -709,8 +698,10 @@ bb_set_verbose(VALUE self, VALUE value)
709
698
  * Returns +true+ if global tracing is enabled.
710
699
  */
711
700
  static VALUE
712
- bb_tracing(VALUE self)
701
+ Tracing(VALUE self)
713
702
  {
703
+ UNUSED(self);
704
+
714
705
  return tracing;
715
706
  }
716
707
 
@@ -721,8 +712,10 @@ bb_tracing(VALUE self)
721
712
  * Sets the global tracing flag.
722
713
  */
723
714
  static VALUE
724
- bb_set_tracing(VALUE self, VALUE value)
715
+ Set_tracing(VALUE self, VALUE value)
725
716
  {
717
+ UNUSED(self);
718
+
726
719
  tracing = RTEST(value) ? Qtrue : Qfalse;
727
720
  return value;
728
721
  }
@@ -734,8 +727,10 @@ bb_set_tracing(VALUE self, VALUE value)
734
727
  * Returns +true+ if post-mortem debugging is enabled.
735
728
  */
736
729
  static VALUE
737
- bb_post_mortem(VALUE self)
730
+ Post_mortem(VALUE self)
738
731
  {
732
+ UNUSED(self);
733
+
739
734
  return post_mortem;
740
735
  }
741
736
 
@@ -746,8 +741,10 @@ bb_post_mortem(VALUE self)
746
741
  * Sets post-moterm flag.
747
742
  */
748
743
  static VALUE
749
- bb_set_post_mortem(VALUE self, VALUE value)
744
+ Set_post_mortem(VALUE self, VALUE value)
750
745
  {
746
+ UNUSED(self);
747
+
751
748
  post_mortem = RTEST(value) ? Qtrue : Qfalse;
752
749
  return value;
753
750
  }
@@ -759,8 +756,10 @@ bb_set_post_mortem(VALUE self, VALUE value)
759
756
  * Adds a new exception to the catchpoints array.
760
757
  */
761
758
  static VALUE
762
- bb_add_catchpoint(VALUE self, VALUE value)
759
+ Add_catchpoint(VALUE self, VALUE value)
763
760
  {
761
+ UNUSED(self);
762
+
764
763
  if (TYPE(value) != T_STRING)
765
764
  rb_raise(rb_eTypeError, "value of a catchpoint must be String");
766
765
 
@@ -781,23 +780,23 @@ Init_byebug()
781
780
  {
782
781
  mByebug = rb_define_module("Byebug");
783
782
 
784
- rb_define_module_function(mByebug, "add_catchpoint" , bb_add_catchpoint , 1);
785
- rb_define_module_function(mByebug, "breakpoints" , bb_breakpoints , 0);
786
- rb_define_module_function(mByebug, "catchpoints" , bb_catchpoints , 0);
787
- rb_define_module_function(mByebug, "contexts" , bb_contexts , 0);
788
- rb_define_module_function(mByebug, "current_context" , bb_current_context , 0);
789
- rb_define_module_function(mByebug, "debug_load" , bb_load , -1);
790
- rb_define_module_function(mByebug, "post_mortem?" , bb_post_mortem , 0);
791
- rb_define_module_function(mByebug, "post_mortem=" , bb_set_post_mortem , 1);
792
- rb_define_module_function(mByebug, "raised_exception", bb_raised_exception, 0);
793
- rb_define_module_function(mByebug, "start" , bb_start , 0);
794
- rb_define_module_function(mByebug, "started?" , bb_started , 0);
795
- rb_define_module_function(mByebug, "stop" , bb_stop , 0);
796
- rb_define_module_function(mByebug, "thread_context" , bb_thread_context , 1);
797
- rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0);
798
- rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1);
799
- rb_define_module_function(mByebug, "verbose?" , bb_verbose , 0);
800
- rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1);
783
+ rb_define_module_function(mByebug, "add_catchpoint", Add_catchpoint, 1);
784
+ rb_define_module_function(mByebug, "breakpoints", Breakpoints, 0);
785
+ rb_define_module_function(mByebug, "catchpoints", Catchpoints, 0);
786
+ rb_define_module_function(mByebug, "contexts", Contexts, 0);
787
+ rb_define_module_function(mByebug, "current_context", Current_context, 0);
788
+ rb_define_module_function(mByebug, "debug_load", Debug_load, -1);
789
+ rb_define_module_function(mByebug, "post_mortem?", Post_mortem, 0);
790
+ rb_define_module_function(mByebug, "post_mortem=", Set_post_mortem, 1);
791
+ rb_define_module_function(mByebug, "raised_exception", Raised_exception, 0);
792
+ rb_define_module_function(mByebug, "start", Start, 0);
793
+ rb_define_module_function(mByebug, "started?", Started, 0);
794
+ rb_define_module_function(mByebug, "stop", Stop, 0);
795
+ rb_define_module_function(mByebug, "thread_context", Thread_context, 1);
796
+ rb_define_module_function(mByebug, "tracing?", Tracing, 0);
797
+ rb_define_module_function(mByebug, "tracing=", Set_tracing, 1);
798
+ rb_define_module_function(mByebug, "verbose?", Verbose, 0);
799
+ rb_define_module_function(mByebug, "verbose=", Set_verbose, 1);
801
800
 
802
801
  Init_threads_table(mByebug);
803
802
  Init_context(mByebug);
@@ -808,4 +807,6 @@ Init_byebug()
808
807
  rb_global_variable(&tracepoints);
809
808
  rb_global_variable(&raised_exception);
810
809
  rb_global_variable(&threads);
810
+
811
+ idPuts = rb_intern("puts");
811
812
  }