readapt 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 295695183ba788850e623e648d35a63a4c9ecbf43c3c94c1dc927669fd5c2b9f
4
- data.tar.gz: ac4e9d7285ba410753e5a20e0043ca4fa805d491c48a3bc02a6337ecec801454
3
+ metadata.gz: e59a68966e356664acd69d2d4800e4052ca1573ad28ccc5b754d299541f6673b
4
+ data.tar.gz: 443c6a7c9a099e60471fb2858868d21a5a320b8e9a52abf4823efb10c810f841
5
5
  SHA512:
6
- metadata.gz: eea4ad41e690bc2f3ee820dde72da7555d8d856a722f3607a8defe35fb134128ca3af70a3711d9cd8db77a074d54003631b6946f533687cd2523af4b67bd1847
7
- data.tar.gz: 83801884e0a1a8f043920ced5938c5095cb0a98c10c9e9cb4fa530600a67024a7aa5d443ea5499d11c194b438b5126bc4571793565b8d675cbe8dfe657d46d73
6
+ metadata.gz: 71f2043df9c0b0e8e07d83597dcdc88a5025b022e642225ec2b3e908a19004028606ef7d8aae91cba9865b36549f77e127e04e19e1f47127626398d9f02dca12
7
+ data.tar.gz: b2773a63a86505811cb71fe1da7490984a033283c0fa0cc91c20e1dd126ad4a515a9a33f45525b5a2024ebfb6af4d5acb98e9869736c03c9cada8bea5ec68dfb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.2.0 - February 24, 2021
2
+ - Pause on exceptions
3
+ - Refactored lookup tables
4
+
1
5
  # 1.1.1 - December 15, 2020
2
6
  - Update rake
3
7
  - Fix Encoding::UndefinedConversionError (#8)
@@ -1,8 +1,8 @@
1
1
  #include "ruby.h"
2
- #include "hash_table.h"
2
+ #include "lookup_table.h"
3
3
 
4
4
  static VALUE m_Breakpoints;
5
- ht_hash_table *ht;
5
+ lt_lookup_table *ht;
6
6
 
7
7
  void breakpoints_set(char *file, long *lines)
8
8
  {
@@ -20,7 +20,7 @@ static VALUE breakpoints_set_s(VALUE self, VALUE file, VALUE lines)
20
20
  {
21
21
  ll[i] = NUM2LONG(rb_ary_entry(lines, i));
22
22
  }
23
- ht_insert(ht, StringValueCStr(file), ll, length);
23
+ lt_insert(ht, StringValueCStr(file), ll, length);
24
24
  free(ll);
25
25
  return Qnil;
26
26
  }
@@ -37,10 +37,10 @@ static VALUE breakpoints_delete_s(VALUE self, VALUE file)
37
37
 
38
38
  int breakpoints_match(char *file, long line)
39
39
  {
40
- ht_long_array *lines;
40
+ lt_long_array *lines;
41
41
  long i;
42
42
 
43
- lines = ht_search(ht, file);
43
+ lines = lt_search(ht, file);
44
44
  if (lines != NULL)
45
45
  {
46
46
  for (i = 0; i < lines->size; i++)
@@ -61,8 +61,8 @@ static VALUE breakpoints_match_s(VALUE self, VALUE file, VALUE line)
61
61
 
62
62
  static VALUE breakpoints_clear_s(VALUE self)
63
63
  {
64
- ht_del_hash_table(ht);
65
- ht = ht_new();
64
+ lt_del_lookup_table(ht);
65
+ ht = lt_new();
66
66
  return Qnil;
67
67
  }
68
68
 
@@ -79,5 +79,5 @@ void initialize_breakpoints(VALUE m_Readapt)
79
79
  rb_define_singleton_method(m_Breakpoints, "match", breakpoints_match_s, 2);
80
80
  rb_define_singleton_method(m_Breakpoints, "clear", breakpoints_clear_s, 0);
81
81
 
82
- ht = ht_new(); // TODO Need to free?
82
+ ht = lt_new(); // TODO Need to free?
83
83
  }
@@ -2,19 +2,19 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
 
5
- #include "hash_table.h"
5
+ #include "lookup_table.h"
6
6
 
7
- static ht_long_array *copy_array(const long *value, const long size)
7
+ static lt_long_array *copy_array(const long *value, const long size)
8
8
  {
9
9
  long i;
10
10
  long *items = malloc(sizeof(long) * size);
11
- ht_long_array *result;
11
+ lt_long_array *result;
12
12
 
13
13
  for (i = 0; i < size; i++)
14
14
  {
15
15
  items[i] = value[i];
16
16
  }
17
- result = malloc(sizeof(ht_long_array));
17
+ result = malloc(sizeof(lt_long_array));
18
18
  result->items = (size ? items : NULL);
19
19
  result->size = size;
20
20
  return result;
@@ -23,9 +23,9 @@ static ht_long_array *copy_array(const long *value, const long size)
23
23
  /*
24
24
  * Initialize a new item
25
25
  */
26
- static ht_item *ht_new_item(char *key, const long *value, const long size)
26
+ static lt_item *lt_new_item(char *key, const long *value, const long size)
27
27
  {
28
- ht_item *i = malloc(sizeof(ht_item));
28
+ lt_item *i = malloc(sizeof(lt_item));
29
29
  i->key = malloc(sizeof(char) * (strlen(key) + 1));
30
30
  strcpy(i->key, key);
31
31
  i->value = copy_array(value, size);
@@ -33,9 +33,9 @@ static ht_item *ht_new_item(char *key, const long *value, const long size)
33
33
  }
34
34
 
35
35
  /*
36
- * Delete the ht_item
36
+ * Delete the lt_item
37
37
  */
38
- static void ht_del_item(ht_item *i)
38
+ static void lt_del_item(lt_item *i)
39
39
  {
40
40
  free(i->key);
41
41
  free(i->value->items);
@@ -43,35 +43,35 @@ static void ht_del_item(ht_item *i)
43
43
  }
44
44
 
45
45
  /*
46
- * Initialize a new empty hash table
46
+ * Initialize a new empty lookup table
47
47
  */
48
- ht_hash_table *ht_new()
48
+ lt_lookup_table *lt_new()
49
49
  {
50
- ht_hash_table *ht = malloc(sizeof(ht_hash_table));
50
+ lt_lookup_table *ht = malloc(sizeof(lt_lookup_table));
51
51
  ht->items = NULL;
52
52
  ht->size = 0;
53
53
  return ht;
54
54
  }
55
55
 
56
56
  /*
57
- * Delete the hash table
57
+ * Delete the lookup table
58
58
  */
59
- void ht_del_hash_table(ht_hash_table *ht)
59
+ void lt_del_lookup_table(lt_lookup_table *ht)
60
60
  {
61
61
  int i;
62
- ht_item *item;
62
+ lt_item *item;
63
63
 
64
64
  // Iterate through items and delete any that are found
65
65
  for (i = 0; i < ht->size; i++)
66
66
  {
67
67
  item = ht->items[i];
68
- ht_del_item(item);
68
+ lt_del_item(item);
69
69
  }
70
70
  free(ht->items);
71
71
  free(ht);
72
72
  }
73
73
 
74
- static ht_long_array *ht_search_part(ht_hash_table *ht, char *key, long cursor, long next)
74
+ static lt_long_array *lt_search_part(lt_lookup_table *ht, char *key, long cursor, long next)
75
75
  {
76
76
  int cmp;
77
77
 
@@ -94,37 +94,37 @@ static ht_long_array *ht_search_part(ht_hash_table *ht, char *key, long cursor,
94
94
  }
95
95
  else if (cmp < 0)
96
96
  {
97
- return ht_search_part(ht, key, next + 1, next + ((ht->size - next) / 2));
97
+ return lt_search_part(ht, key, next + 1, next + ((ht->size - next) / 2));
98
98
  }
99
99
  else
100
100
  {
101
- return ht_search_part(ht, key, cursor + 1, next / 2);
101
+ return lt_search_part(ht, key, cursor + 1, next / 2);
102
102
  }
103
103
  }
104
- return ht_search_part(ht, key, cursor + 1, next / 2);
104
+ return lt_search_part(ht, key, cursor + 1, next / 2);
105
105
  }
106
106
 
107
- static ht_long_array *ht_search_key(ht_hash_table *ht, char *key)
107
+ static lt_long_array *lt_search_key(lt_lookup_table *ht, char *key)
108
108
  {
109
- return ht_search_part(ht, key, 0, ht->size / 2);
109
+ return lt_search_part(ht, key, 0, ht->size / 2);
110
110
  }
111
111
 
112
- static void ht_delete_key(ht_hash_table *ht, char *key)
112
+ static void lt_delete_key(lt_lookup_table *ht, char *key)
113
113
  {
114
- ht_long_array *found;
115
- ht_item **tmp;
114
+ lt_long_array *found;
115
+ lt_item **tmp;
116
116
  long i;
117
117
  long cursor = 0;
118
118
 
119
- found = ht_search_key(ht, key);
119
+ found = lt_search_key(ht, key);
120
120
  if (found)
121
121
  {
122
- tmp = malloc(sizeof(ht_item) * (ht->size - 1));
122
+ tmp = malloc(sizeof(lt_item) * (ht->size - 1));
123
123
  for (i = 0; i < ht->size; i++)
124
124
  {
125
125
  if (ht->items[i]->key == key)
126
126
  {
127
- ht_del_item(ht->items[i]);
127
+ lt_del_item(ht->items[i]);
128
128
  }
129
129
  else
130
130
  {
@@ -138,24 +138,24 @@ static void ht_delete_key(ht_hash_table *ht, char *key)
138
138
  }
139
139
  }
140
140
 
141
- static void ht_insert_key(ht_hash_table *ht, char *key, const long *value, const long size)
141
+ static void lt_insert_key(lt_lookup_table *ht, char *key, const long *value, const long size)
142
142
  {
143
- ht_item *item;
144
- ht_item **tmp;
143
+ lt_item *item;
144
+ lt_item **tmp;
145
145
  long i;
146
146
  long cursor = 0;
147
147
  int inserted = 0;
148
148
  int cmp;
149
149
 
150
- ht_delete_key(ht, key);
150
+ lt_delete_key(ht, key);
151
151
 
152
152
  if (size == 0)
153
153
  {
154
154
  return;
155
155
  }
156
156
 
157
- item = ht_new_item(key, value, size);
158
- tmp = malloc(sizeof(ht_item) * (ht->size + 1));
157
+ item = lt_new_item(key, value, size);
158
+ tmp = malloc(sizeof(lt_item) * (ht->size + 1));
159
159
 
160
160
  for (i = 0; i < ht->size; i++)
161
161
  {
@@ -187,25 +187,25 @@ static void ht_insert_key(ht_hash_table *ht, char *key, const long *value, const
187
187
  }
188
188
 
189
189
  /*
190
- * Add an item to the hash table
190
+ * Add an item to the lookup table
191
191
  */
192
- void ht_insert(ht_hash_table *ht, char *key, const long *value, const long size)
192
+ void lt_insert(lt_lookup_table *ht, char *key, const long *value, const long size)
193
193
  {
194
- ht_insert_key(ht, key, value, size);
194
+ lt_insert_key(ht, key, value, size);
195
195
  }
196
196
 
197
197
  /*
198
198
  * Get the key's value or NULL if it doesn't exist
199
199
  */
200
- ht_long_array *ht_search(ht_hash_table *ht, char *key)
200
+ lt_long_array *lt_search(lt_lookup_table *ht, char *key)
201
201
  {
202
- return ht_search_key(ht, key);
202
+ return lt_search_key(ht, key);
203
203
  }
204
204
 
205
205
  /*
206
206
  * Delete the key's item if it exists
207
207
  */
208
- void ht_delete(ht_hash_table *ht, char *key)
208
+ void lt_delete(lt_lookup_table *ht, char *key)
209
209
  {
210
- ht_delete_key(ht, key);
210
+ lt_delete_key(ht, key);
211
211
  }
@@ -0,0 +1,30 @@
1
+ #ifndef LOOKUP_TABLE_H_
2
+ #define LOOKUP_TABLE_H_
3
+
4
+ typedef struct lt_long_array
5
+ {
6
+ long *items;
7
+ long size;
8
+ } lt_long_array;
9
+
10
+ // lt_item is an item in the lookup table
11
+ typedef struct lt_item
12
+ {
13
+ char *key;
14
+ lt_long_array *value;
15
+ } lt_item;
16
+
17
+ typedef struct lt_lookup_table
18
+ {
19
+ long size;
20
+ lt_item **items;
21
+ } lt_lookup_table;
22
+
23
+ lt_lookup_table *lt_new();
24
+ void lt_del_lookup_table(lt_lookup_table *ht);
25
+
26
+ void lt_insert(lt_lookup_table *ht, char *key, const long *value, const long size);
27
+ lt_long_array *lt_search(lt_lookup_table *ht, char *key);
28
+ void lt_delete(lt_lookup_table *h, char *key);
29
+
30
+ #endif // LOOKUP_TABLE_H_
@@ -14,6 +14,7 @@ static VALUE tpCall;
14
14
  static VALUE tpReturn;
15
15
  static VALUE tpThreadBegin;
16
16
  static VALUE tpThreadEnd;
17
+ static VALUE tpRaise;
17
18
  static VALUE debugProc;
18
19
  static int firstLineEvent = 0;
19
20
  static char *entryFile;
@@ -99,7 +100,6 @@ process_line_event(VALUE tracepoint, void *data)
99
100
 
100
101
  arg = rb_tracearg_from_tracepoint(tracepoint);
101
102
  tmp = rb_tracearg_path(arg);
102
- // tp_file = normalize_path_new_cstr(StringValueCStr(tmp));
103
103
  tp_file = StringValueCStr(tmp);
104
104
  normalize_path(tp_file);
105
105
  tmp = rb_tracearg_lineno(arg);
@@ -136,8 +136,6 @@ process_line_event(VALUE tracepoint, void *data)
136
136
  {
137
137
  monitor_debug(tp_file, tp_line, tracepoint, ptr, dapEvent);
138
138
  }
139
-
140
- // free(tp_file);
141
139
  }
142
140
  }
143
141
 
@@ -210,6 +208,40 @@ process_thread_end_event(VALUE tracepoint, void *data)
210
208
  }
211
209
  }
212
210
 
211
+ static void
212
+ process_raise_event(VALUE tracepoint, void *data)
213
+ {
214
+ rb_trace_arg_t *arg;
215
+ VALUE exception;
216
+ VALUE ref;
217
+ thread_reference_t *ptr;
218
+ VALUE tmp;
219
+ char *tp_file;
220
+ long tp_line;
221
+
222
+ ref = thread_current_reference();
223
+ if (ref != Qnil)
224
+ {
225
+ arg = rb_tracearg_from_tracepoint(tracepoint);
226
+ exception = rb_tracearg_raised_exception(arg);
227
+ if (rb_class_inherited_p(rb_obj_class(exception), rb_eStandardError)) {
228
+ ptr = thread_reference_pointer(ref);
229
+ tmp = rb_tracearg_path(arg);
230
+ tp_file = StringValueCStr(tmp);
231
+ normalize_path(tp_file);
232
+ tmp = rb_tracearg_lineno(arg);
233
+ tp_line = NUM2INT(tmp);
234
+ monitor_debug(
235
+ tp_file,
236
+ tp_line,
237
+ tracepoint,
238
+ ptr,
239
+ rb_intern("raise")
240
+ );
241
+ }
242
+ }
243
+ }
244
+
213
245
  static VALUE
214
246
  monitor_enable_s(VALUE self, VALUE file)
215
247
  {
@@ -218,7 +250,6 @@ monitor_enable_s(VALUE self, VALUE file)
218
250
 
219
251
  if (rb_block_given_p()) {
220
252
  debugProc = rb_block_proc();
221
- rb_global_variable(&debugProc);
222
253
  } else {
223
254
  rb_raise(rb_eArgError, "must be called with a block");
224
255
  }
@@ -250,6 +281,7 @@ monitor_enable_s(VALUE self, VALUE file)
250
281
  rb_tracepoint_enable(tpReturn);
251
282
  rb_tracepoint_enable(tpThreadBegin);
252
283
  rb_tracepoint_enable(tpThreadEnd);
284
+ rb_tracepoint_enable(tpRaise);
253
285
  return previous;
254
286
  }
255
287
 
@@ -264,6 +296,7 @@ monitor_disable_s(VALUE self)
264
296
  rb_tracepoint_disable(tpReturn);
265
297
  rb_tracepoint_disable(tpThreadBegin);
266
298
  rb_tracepoint_disable(tpThreadEnd);
299
+ rb_tracepoint_disable(tpRaise);
267
300
 
268
301
  free(entryFile);
269
302
  entryFile = NULL;
@@ -304,6 +337,7 @@ void initialize_monitor(VALUE m_Readapt)
304
337
  tpReturn = rb_tracepoint_new(Qnil, RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_END | RUBY_EVENT_C_RETURN, process_return_event, NULL);
305
338
  tpThreadBegin = rb_tracepoint_new(Qnil, RUBY_EVENT_THREAD_BEGIN, process_thread_begin_event, NULL);
306
339
  tpThreadEnd = rb_tracepoint_new(Qnil, RUBY_EVENT_THREAD_END, process_thread_end_event, NULL);
340
+ tpRaise = rb_tracepoint_new(Qnil, RUBY_EVENT_RAISE, process_raise_event, NULL);
307
341
  debugProc = Qnil;
308
342
 
309
343
  id_continue = rb_intern("continue");
@@ -316,4 +350,7 @@ void initialize_monitor(VALUE m_Readapt)
316
350
  rb_global_variable(&tpReturn);
317
351
  rb_global_variable(&tpThreadBegin);
318
352
  rb_global_variable(&tpThreadEnd);
353
+ rb_global_variable(&tpRaise);
354
+
355
+ rb_global_variable(&debugProc);
319
356
  }
@@ -13,6 +13,7 @@ module Readapt
13
13
  @hit_condition = hit_condition
14
14
  end
15
15
 
16
+ # @return [Integer]
16
17
  def hit_cursor
17
18
  @hit_cursor ||= 0
18
19
  end
@@ -1,14 +1,28 @@
1
1
  require 'pathname'
2
2
 
3
3
  module Readapt
4
+ # Methods to find a program in the current directory or one of the
5
+ # environment paths.
6
+ #
4
7
  module Finder
5
8
  module_function
6
9
 
10
+ # Get the program's fully qualified path. Search first in the current
11
+ # directory, then the environment paths.
12
+ #
13
+ # @raise [LoadError] if the program was not found
14
+ #
15
+ # @param program [String] The name of the program
16
+ # @return [String] The fully qualified path
7
17
  def find program
8
18
  return program if File.exist?(program)
9
19
  which(program) || raise(LoadError, "#{program} is not a valid Ruby file or program")
10
20
  end
11
21
 
22
+ # Search the environment paths for the given program.
23
+ #
24
+ # @param program [String] The name of the program
25
+ # @return [String] The fully qualified path, or nil if it was not found
12
26
  def which program
13
27
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
14
28
  exe = File.join(path, program)
@@ -9,6 +9,7 @@ module Readapt
9
9
  # @return [Symbol]
10
10
  attr_accessor :control
11
11
 
12
+ # @return [String]
12
13
  def name
13
14
  @name ||= begin
14
15
  @@next_id += 1
@@ -16,6 +17,7 @@ module Readapt
16
17
  end
17
18
  end
18
19
 
20
+ # @return [Object]
19
21
  def object
20
22
  ObjectSpace._id2ref(id)
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module Readapt
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readapt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-15 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -121,10 +121,10 @@ files:
121
121
  - ext/readapt/extconf.rb
122
122
  - ext/readapt/frame.c
123
123
  - ext/readapt/frame.h
124
- - ext/readapt/hash_table.c
125
- - ext/readapt/hash_table.h
126
124
  - ext/readapt/inspector.c
127
125
  - ext/readapt/inspector.h
126
+ - ext/readapt/lookup_table.c
127
+ - ext/readapt/lookup_table.h
128
128
  - ext/readapt/monitor.c
129
129
  - ext/readapt/monitor.h
130
130
  - ext/readapt/normalize.c
@@ -1,30 +0,0 @@
1
- #ifndef HASH_TABLE_H_
2
- #define HASH_TABLE_H_
3
-
4
- typedef struct ht_long_array
5
- {
6
- long *items;
7
- long size;
8
- } ht_long_array;
9
-
10
- // ht_item is an item in the hash table
11
- typedef struct ht_item
12
- {
13
- char *key;
14
- ht_long_array *value;
15
- } ht_item;
16
-
17
- typedef struct ht_hash_table
18
- {
19
- long size;
20
- ht_item **items;
21
- } ht_hash_table;
22
-
23
- ht_hash_table *ht_new();
24
- void ht_del_hash_table(ht_hash_table *ht);
25
-
26
- void ht_insert(ht_hash_table *ht, char *key, const long *value, const long size);
27
- ht_long_array *ht_search(ht_hash_table *ht, char *key);
28
- void ht_delete(ht_hash_table *h, char *key);
29
-
30
- #endif // HASH_TABLE_H_