readapt 1.1.1 → 1.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/readapt/breakpoints.c +8 -8
- data/ext/readapt/{hash_table.c → lookup_table.c} +40 -40
- data/ext/readapt/lookup_table.h +30 -0
- data/ext/readapt/monitor.c +41 -4
- data/lib/readapt/breakpoint.rb +1 -0
- data/lib/readapt/finder.rb +14 -0
- data/lib/readapt/thread.rb +2 -0
- data/lib/readapt/version.rb +1 -1
- metadata +4 -4
- data/ext/readapt/hash_table.h +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e59a68966e356664acd69d2d4800e4052ca1573ad28ccc5b754d299541f6673b
|
4
|
+
data.tar.gz: 443c6a7c9a099e60471fb2858868d21a5a320b8e9a52abf4823efb10c810f841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f2043df9c0b0e8e07d83597dcdc88a5025b022e642225ec2b3e908a19004028606ef7d8aae91cba9865b36549f77e127e04e19e1f47127626398d9f02dca12
|
7
|
+
data.tar.gz: b2773a63a86505811cb71fe1da7490984a033283c0fa0cc91c20e1dd126ad4a515a9a33f45525b5a2024ebfb6af4d5acb98e9869736c03c9cada8bea5ec68dfb
|
data/CHANGELOG.md
CHANGED
data/ext/readapt/breakpoints.c
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
2
|
+
#include "lookup_table.h"
|
3
3
|
|
4
4
|
static VALUE m_Breakpoints;
|
5
|
-
|
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
|
-
|
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
|
-
|
40
|
+
lt_long_array *lines;
|
41
41
|
long i;
|
42
42
|
|
43
|
-
lines =
|
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
|
-
|
65
|
-
ht =
|
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 =
|
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 "
|
5
|
+
#include "lookup_table.h"
|
6
6
|
|
7
|
-
static
|
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
|
-
|
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(
|
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
|
26
|
+
static lt_item *lt_new_item(char *key, const long *value, const long size)
|
27
27
|
{
|
28
|
-
|
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
|
36
|
+
* Delete the lt_item
|
37
37
|
*/
|
38
|
-
static void
|
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
|
46
|
+
* Initialize a new empty lookup table
|
47
47
|
*/
|
48
|
-
|
48
|
+
lt_lookup_table *lt_new()
|
49
49
|
{
|
50
|
-
|
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
|
57
|
+
* Delete the lookup table
|
58
58
|
*/
|
59
|
-
void
|
59
|
+
void lt_del_lookup_table(lt_lookup_table *ht)
|
60
60
|
{
|
61
61
|
int i;
|
62
|
-
|
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
|
-
|
68
|
+
lt_del_item(item);
|
69
69
|
}
|
70
70
|
free(ht->items);
|
71
71
|
free(ht);
|
72
72
|
}
|
73
73
|
|
74
|
-
static
|
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
|
97
|
+
return lt_search_part(ht, key, next + 1, next + ((ht->size - next) / 2));
|
98
98
|
}
|
99
99
|
else
|
100
100
|
{
|
101
|
-
return
|
101
|
+
return lt_search_part(ht, key, cursor + 1, next / 2);
|
102
102
|
}
|
103
103
|
}
|
104
|
-
return
|
104
|
+
return lt_search_part(ht, key, cursor + 1, next / 2);
|
105
105
|
}
|
106
106
|
|
107
|
-
static
|
107
|
+
static lt_long_array *lt_search_key(lt_lookup_table *ht, char *key)
|
108
108
|
{
|
109
|
-
return
|
109
|
+
return lt_search_part(ht, key, 0, ht->size / 2);
|
110
110
|
}
|
111
111
|
|
112
|
-
static void
|
112
|
+
static void lt_delete_key(lt_lookup_table *ht, char *key)
|
113
113
|
{
|
114
|
-
|
115
|
-
|
114
|
+
lt_long_array *found;
|
115
|
+
lt_item **tmp;
|
116
116
|
long i;
|
117
117
|
long cursor = 0;
|
118
118
|
|
119
|
-
found =
|
119
|
+
found = lt_search_key(ht, key);
|
120
120
|
if (found)
|
121
121
|
{
|
122
|
-
tmp = malloc(sizeof(
|
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
|
-
|
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
|
141
|
+
static void lt_insert_key(lt_lookup_table *ht, char *key, const long *value, const long size)
|
142
142
|
{
|
143
|
-
|
144
|
-
|
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
|
-
|
150
|
+
lt_delete_key(ht, key);
|
151
151
|
|
152
152
|
if (size == 0)
|
153
153
|
{
|
154
154
|
return;
|
155
155
|
}
|
156
156
|
|
157
|
-
item =
|
158
|
-
tmp = malloc(sizeof(
|
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
|
190
|
+
* Add an item to the lookup table
|
191
191
|
*/
|
192
|
-
void
|
192
|
+
void lt_insert(lt_lookup_table *ht, char *key, const long *value, const long size)
|
193
193
|
{
|
194
|
-
|
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
|
-
|
200
|
+
lt_long_array *lt_search(lt_lookup_table *ht, char *key)
|
201
201
|
{
|
202
|
-
return
|
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
|
208
|
+
void lt_delete(lt_lookup_table *ht, char *key)
|
209
209
|
{
|
210
|
-
|
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_
|
data/ext/readapt/monitor.c
CHANGED
@@ -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
|
}
|
data/lib/readapt/breakpoint.rb
CHANGED
data/lib/readapt/finder.rb
CHANGED
@@ -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)
|
data/lib/readapt/thread.rb
CHANGED
@@ -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
|
data/lib/readapt/version.rb
CHANGED
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.
|
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:
|
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
|
data/ext/readapt/hash_table.h
DELETED
@@ -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_
|