pline 0.0.3

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 (51) hide show
  1. data/README +134 -0
  2. data/ext/pline/depend +55 -0
  3. data/ext/pline/extconf.rb +14 -0
  4. data/ext/pline/iseq.c +124 -0
  5. data/ext/pline/minfo.c +167 -0
  6. data/ext/pline/pline.c.rb +68 -0
  7. data/ext/pline/profiler.c +125 -0
  8. data/ext/pline/ruby_source/1.9.2/debug.h +36 -0
  9. data/ext/pline/ruby_source/1.9.2/eval_intern.h +232 -0
  10. data/ext/pline/ruby_source/1.9.2/gc.h +77 -0
  11. data/ext/pline/ruby_source/1.9.2/id.h +170 -0
  12. data/ext/pline/ruby_source/1.9.2/insns.inc +179 -0
  13. data/ext/pline/ruby_source/1.9.2/insns_info.inc +695 -0
  14. data/ext/pline/ruby_source/1.9.2/iseq.h +104 -0
  15. data/ext/pline/ruby_source/1.9.2/manual_update.h +19 -0
  16. data/ext/pline/ruby_source/1.9.2/method.h +103 -0
  17. data/ext/pline/ruby_source/1.9.2/node.h +483 -0
  18. data/ext/pline/ruby_source/1.9.2/thread_pthread.h +27 -0
  19. data/ext/pline/ruby_source/1.9.2/thread_win32.h +33 -0
  20. data/ext/pline/ruby_source/1.9.2/vm_core.h +706 -0
  21. data/ext/pline/ruby_source/1.9.2/vm_exec.h +184 -0
  22. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.c +1734 -0
  23. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.h +208 -0
  24. data/ext/pline/ruby_source/1.9.2/vm_opts.h +51 -0
  25. data/ext/pline/ruby_source/1.9.3/atomic.h +56 -0
  26. data/ext/pline/ruby_source/1.9.3/constant.h +34 -0
  27. data/ext/pline/ruby_source/1.9.3/debug.h +41 -0
  28. data/ext/pline/ruby_source/1.9.3/eval_intern.h +234 -0
  29. data/ext/pline/ruby_source/1.9.3/gc.h +98 -0
  30. data/ext/pline/ruby_source/1.9.3/id.h +175 -0
  31. data/ext/pline/ruby_source/1.9.3/insns.inc +179 -0
  32. data/ext/pline/ruby_source/1.9.3/insns_info.inc +695 -0
  33. data/ext/pline/ruby_source/1.9.3/internal.h +227 -0
  34. data/ext/pline/ruby_source/1.9.3/iseq.h +125 -0
  35. data/ext/pline/ruby_source/1.9.3/manual_update.h +19 -0
  36. data/ext/pline/ruby_source/1.9.3/method.h +105 -0
  37. data/ext/pline/ruby_source/1.9.3/node.h +503 -0
  38. data/ext/pline/ruby_source/1.9.3/thread_pthread.h +51 -0
  39. data/ext/pline/ruby_source/1.9.3/thread_win32.h +40 -0
  40. data/ext/pline/ruby_source/1.9.3/vm_core.h +756 -0
  41. data/ext/pline/ruby_source/1.9.3/vm_exec.h +184 -0
  42. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.c +1749 -0
  43. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.h +220 -0
  44. data/ext/pline/ruby_source/1.9.3/vm_opts.h +51 -0
  45. data/ext/pline/sinfo.c +311 -0
  46. data/lib/pline.rb +11 -0
  47. data/lib/pline/minfo.rb +22 -0
  48. data/lib/pline/summarize.rb +127 -0
  49. data/lib/pline/util.rb +54 -0
  50. data/pline.gemspec +28 -0
  51. metadata +102 -0
@@ -0,0 +1,68 @@
1
+ require "erb"
2
+
3
+ case RUBY_VERSION
4
+ when "1.9.2"
5
+ ruby_srcdir = "ruby_source/1.9.2"
6
+ when "1.9.3"
7
+ ruby_srcdir = "ruby_source/1.9.3"
8
+ else
9
+ raise("Unsupported ruby version #{RUBY_VERSION}")
10
+ end
11
+
12
+ ERB.new(DATA.read, 0, "%-").run()
13
+ __END__
14
+
15
+ #include <ruby.h>
16
+
17
+ #include "<%= ruby_srcdir %>/vm_core.h"
18
+ #include "<%= ruby_srcdir %>/eval_intern.h"
19
+ #include "<%= ruby_srcdir %>/iseq.h"
20
+ #include "<%= ruby_srcdir %>/gc.h"
21
+ #include <ruby/vm.h>
22
+ #include <ruby/encoding.h>
23
+ #include "<%= ruby_srcdir %>/vm_insnhelper.h"
24
+ #include "<%= ruby_srcdir %>/vm_insnhelper.c"
25
+ #include "<%= ruby_srcdir %>/vm_exec.h"
26
+
27
+ #define TRUE 1
28
+ #define FALSE 0
29
+
30
+ #ifdef USE_INSN_STACK_INCREASE
31
+ #undef USE_INSN_STACK_INCREASE
32
+ #endif
33
+ #define USE_INSN_STACK_INCREASE 1
34
+
35
+ #ifdef USE_INSN_RET_NUM
36
+ #undef USE_INSN_RET_NUM
37
+ #endif
38
+ #define USE_INSN_RET_NUM 1
39
+
40
+ #include "<%= ruby_srcdir %>/insns_info.inc"
41
+ #include "<%= ruby_srcdir %>/manual_update.h"
42
+
43
+ #ifndef _WIN32
44
+ #include <time.h>
45
+ #include <sys/time.h>
46
+ #endif
47
+
48
+ #define line2idx(l) ((l) - 1)
49
+ #define idx2line(i) ((i) + 1)
50
+ #define nano2micro(t) (((t) / 1000))
51
+ #define NOVALUE 0
52
+ #define has_value(v) ((v) != NOVALUE)
53
+
54
+ static VALUE mPLine, cSourceInfo, cMethodInfo, cSourceInfoContainer;
55
+
56
+ #include "iseq.c"
57
+ #include "sinfo.c"
58
+ #include "minfo.c"
59
+ #include "profiler.c"
60
+
61
+ VALUE Init_pline()
62
+ {
63
+ mPLine = rb_define_module("PLine");
64
+ pline_sinfo_init();
65
+ pline_minfo_init();
66
+ pline_profiler_init();
67
+ }
68
+
@@ -0,0 +1,125 @@
1
+ static int profiler_source_location(const char **p_srcfile, long *p_line)
2
+ {
3
+ #if 0
4
+ VALUE thval = rb_thread_current();
5
+ rb_thread_t *th = DATA_PTR(thval);
6
+ rb_control_frame_t *cfp = th->cfp;
7
+ rb_iseq_t *iseq;
8
+ const char *srcfile;
9
+ long line = -1, i, pc;
10
+
11
+ /* find cfp */
12
+ while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
13
+ if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
14
+ break;
15
+ }
16
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
17
+ }
18
+ if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
19
+ return 0;
20
+ }
21
+ iseq = cfp->iseq;
22
+
23
+ /* find sourcefile */
24
+ srcfile = RSTRING_PTR(iseq->filename);
25
+ if (!srcfile) {
26
+ return 0;
27
+ }
28
+
29
+ /* find line */
30
+ if (iseq->insn_info_size <= 0) {
31
+ return 0;
32
+ }
33
+ pc = cfp->pc - iseq->iseq_encoded;
34
+ for (i = 0; i < iseq->insn_info_size; i++) {
35
+ if (iseq->insn_info_table[i].position == pc) {
36
+ line = iseq->insn_info_table[i - 1].line_no;
37
+ break;
38
+ }
39
+ }
40
+ if (line < 0) {
41
+ line = iseq->insn_info_table[i - 1].line_no;
42
+ }
43
+ if (line < 0) {
44
+ rb_bug("pline_callback_info: should not be reached");
45
+ }
46
+ #else
47
+ const char *srcfile;
48
+ long line;
49
+
50
+ srcfile = rb_sourcefile();
51
+ if (!srcfile) {
52
+ return 0;
53
+ }
54
+
55
+ line = rb_sourceline();
56
+ if (line < 0) {
57
+ return 0;
58
+ }
59
+ #endif
60
+
61
+ *p_srcfile = srcfile;
62
+ *p_line = line;
63
+
64
+ return 1;
65
+ }
66
+
67
+ static void profiler_linetrace_callback(rb_event_flag_t event, VALUE arg, VALUE self, ID id, VALUE klass)
68
+ {
69
+ const char *srcfile;
70
+ long line;
71
+ int success = profiler_source_location(&srcfile, &line);
72
+ VALUE sinfo;
73
+
74
+ if (!success) return;
75
+ sinfo_measure(srcfile, line);
76
+
77
+ return;
78
+ }
79
+
80
+ static void profiler_linetrace(int remove)
81
+ {
82
+ static int hooked = 0;
83
+
84
+ if (remove) {
85
+ if (!hooked) return;
86
+ hooked = 0;
87
+ rb_remove_event_hook(&profiler_linetrace_callback);
88
+ return;
89
+ }
90
+
91
+ if (hooked) {
92
+ return;
93
+ }
94
+
95
+ rb_add_event_hook(&profiler_linetrace_callback, RUBY_EVENT_END, Qnil);
96
+ hooked = 1;
97
+
98
+ return;
99
+ }
100
+
101
+ static VALUE profiler_m_profile(int argc, VALUE *argv, VALUE self)
102
+ {
103
+ rb_iseq_t *iseq;
104
+ VALUE minfo, obj, mid, singleton_p = Qfalse;
105
+
106
+ rb_scan_args(argc, argv, "21", &obj, &mid, &singleton_p);
107
+
108
+ if (rb_obj_class(mid) != rb_cSymbol) {
109
+ rb_raise(rb_eArgError, "second argument should be symbol");
110
+ }
111
+
112
+ iseq = iseq_find(obj, mid, singleton_p);
113
+ minfo = rb_funcall(cMethodInfo, rb_intern("new"), 4, iseq->self, obj, mid, singleton_p);
114
+ iseq_inject(iseq);
115
+ profiler_linetrace(0);
116
+ rb_funcall(cMethodInfo, rb_intern("register"), 1, minfo);
117
+
118
+ return Qnil;
119
+ }
120
+
121
+ static void pline_profiler_init(void)
122
+ {
123
+ rb_define_singleton_method(mPLine, "profile", profiler_m_profile, -1);
124
+ }
125
+
@@ -0,0 +1,36 @@
1
+ /**********************************************************************
2
+
3
+ debug.h - YARV Debug function interface
4
+
5
+ $Author: akr $
6
+ created at: 04/08/25 02:33:49 JST
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_DEBUG_H
13
+ #define RUBY_DEBUG_H
14
+
15
+ #include "ruby/ruby.h"
16
+ #include "node.h"
17
+
18
+ #define dpv(h,v) ruby_debug_print_value(-1, 0, h, v)
19
+ #define dp(v) ruby_debug_print_value(-1, 0, "", v)
20
+ #define dpi(i) ruby_debug_print_id(-1, 0, "", i)
21
+ #define dpn(n) ruby_debug_print_node(-1, 0, "", n)
22
+
23
+ #define bp() ruby_debug_breakpoint()
24
+
25
+ VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v);
26
+ ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id);
27
+ NODE *ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node);
28
+ int ruby_debug_print_indent(int level, int debug_level, int indent_level);
29
+ void ruby_debug_breakpoint(void);
30
+ void ruby_debug_gc_check_func(void);
31
+
32
+ #ifdef RUBY_DEBUG_ENV
33
+ void ruby_set_debug_option(const char *str);
34
+ #endif
35
+
36
+ #endif /* RUBY_DEBUG_H */
@@ -0,0 +1,232 @@
1
+ #ifndef RUBY_EVAL_INTERN_H
2
+ #define RUBY_EVAL_INTERN_H
3
+
4
+ #include "ruby/ruby.h"
5
+ #include "vm_core.h"
6
+
7
+ #define PASS_PASSED_BLOCK_TH(th) do { \
8
+ (th)->passed_block = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \
9
+ (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \
10
+ } while (0)
11
+
12
+ #define PASS_PASSED_BLOCK() do { \
13
+ rb_thread_t * const __th__ = GET_THREAD(); \
14
+ PASS_PASSED_BLOCK_TH(__th__); \
15
+ } while (0)
16
+
17
+ #ifdef HAVE_STDLIB_H
18
+ #include <stdlib.h>
19
+ #endif
20
+ #ifndef EXIT_SUCCESS
21
+ #define EXIT_SUCCESS 0
22
+ #endif
23
+ #ifndef EXIT_FAILURE
24
+ #define EXIT_FAILURE 1
25
+ #endif
26
+
27
+ #include <stdio.h>
28
+ #include <setjmp.h>
29
+
30
+ #ifdef __APPLE__
31
+ #include <crt_externs.h>
32
+ #endif
33
+
34
+ /* Make alloca work the best possible way. */
35
+ #ifdef __GNUC__
36
+ # ifndef atarist
37
+ # ifndef alloca
38
+ # define alloca __builtin_alloca
39
+ # endif
40
+ # endif /* atarist */
41
+ #else
42
+ # ifdef HAVE_ALLOCA_H
43
+ # include <alloca.h>
44
+ # else
45
+ # ifdef _AIX
46
+ #pragma alloca
47
+ # else
48
+ # ifndef alloca /* predefined by HP cc +Olibcalls */
49
+ void *alloca();
50
+ # endif
51
+ # endif /* AIX */
52
+ # endif /* HAVE_ALLOCA_H */
53
+ #endif /* __GNUC__ */
54
+
55
+ #ifndef HAVE_STRING_H
56
+ char *strrchr(const char *, const char);
57
+ #endif
58
+
59
+ #ifdef HAVE_UNISTD_H
60
+ #include <unistd.h>
61
+ #endif
62
+
63
+ #ifdef HAVE_NET_SOCKET_H
64
+ #include <net/socket.h>
65
+ #endif
66
+
67
+ #define ruby_setjmp(env) RUBY_SETJMP(env)
68
+ #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
69
+ #ifdef __CYGWIN__
70
+ # ifndef _setjmp
71
+ int _setjmp(jmp_buf);
72
+ # endif
73
+ # ifndef _longjmp
74
+ NORETURN(void _longjmp(jmp_buf, int));
75
+ # endif
76
+ #endif
77
+
78
+ #include <sys/types.h>
79
+ #include <signal.h>
80
+ #include <errno.h>
81
+
82
+ #ifdef HAVE_SYS_SELECT_H
83
+ #include <sys/select.h>
84
+ #endif
85
+
86
+ /*
87
+ Solaris sys/select.h switches select to select_large_fdset to support larger
88
+ file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
89
+ But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
90
+ So following definition is required to use select_large_fdset.
91
+ */
92
+ #ifdef HAVE_SELECT_LARGE_FDSET
93
+ #define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
94
+ #endif
95
+
96
+ #ifdef HAVE_SYS_PARAM_H
97
+ #include <sys/param.h>
98
+ #endif
99
+
100
+ #include <sys/stat.h>
101
+
102
+ #define SAVE_ROOT_JMPBUF(th, stmt) do \
103
+ if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
104
+ stmt; \
105
+ } \
106
+ else { \
107
+ rb_fiber_start(); \
108
+ } while (0)
109
+
110
+ #define TH_PUSH_TAG(th) do { \
111
+ rb_thread_t * const _th = th; \
112
+ struct rb_vm_tag _tag; \
113
+ _tag.tag = 0; \
114
+ _tag.prev = _th->tag; \
115
+ _th->tag = &_tag;
116
+
117
+ #define TH_POP_TAG() \
118
+ _th->tag = _tag.prev; \
119
+ } while (0)
120
+
121
+ #define TH_POP_TAG2() \
122
+ _th->tag = _tag.prev
123
+
124
+ #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
125
+ #define POP_TAG() TH_POP_TAG()
126
+
127
+ #define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf)
128
+
129
+ #define EXEC_TAG() \
130
+ TH_EXEC_TAG()
131
+
132
+ #define TH_JUMP_TAG(th, st) do { \
133
+ ruby_longjmp(th->tag->buf,(st)); \
134
+ } while (0)
135
+
136
+ #define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), st)
137
+
138
+ enum ruby_tag_type {
139
+ RUBY_TAG_RETURN = 0x1,
140
+ RUBY_TAG_BREAK = 0x2,
141
+ RUBY_TAG_NEXT = 0x3,
142
+ RUBY_TAG_RETRY = 0x4,
143
+ RUBY_TAG_REDO = 0x5,
144
+ RUBY_TAG_RAISE = 0x6,
145
+ RUBY_TAG_THROW = 0x7,
146
+ RUBY_TAG_FATAL = 0x8,
147
+ RUBY_TAG_MASK = 0xf
148
+ };
149
+ #define TAG_RETURN RUBY_TAG_RETURN
150
+ #define TAG_BREAK RUBY_TAG_BREAK
151
+ #define TAG_NEXT RUBY_TAG_NEXT
152
+ #define TAG_RETRY RUBY_TAG_RETRY
153
+ #define TAG_REDO RUBY_TAG_REDO
154
+ #define TAG_RAISE RUBY_TAG_RAISE
155
+ #define TAG_THROW RUBY_TAG_THROW
156
+ #define TAG_FATAL RUBY_TAG_FATAL
157
+ #define TAG_MASK RUBY_TAG_MASK
158
+
159
+ #define NEW_THROW_OBJECT(val, pt, st) \
160
+ ((VALUE)rb_node_newnode(NODE_LIT, (VALUE)(val), (VALUE)(pt), (VALUE)(st)))
161
+ #define SET_THROWOBJ_CATCH_POINT(obj, val) \
162
+ (RNODE((obj))->u2.value = (val))
163
+ #define SET_THROWOBJ_STATE(obj, val) \
164
+ (RNODE((obj))->u3.value = (val))
165
+
166
+ #define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
167
+ #define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
168
+ #define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
169
+
170
+ #define SCOPE_TEST(f) (rb_vm_cref()->nd_visi & (f))
171
+ #define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
172
+ #define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
173
+
174
+ #define CHECK_STACK_OVERFLOW(cfp, margin) do \
175
+ if ((VALUE *)((char *)(((VALUE *)(cfp)->sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)cfp)) { \
176
+ rb_exc_raise(sysstack_error); \
177
+ } \
178
+ while (0)
179
+
180
+ void rb_thread_cleanup(void);
181
+ void rb_thread_wait_other_threads(void);
182
+
183
+ enum {
184
+ RAISED_EXCEPTION = 1,
185
+ RAISED_STACKOVERFLOW = 2,
186
+ RAISED_NOMEMORY = 4
187
+ };
188
+ int rb_threadptr_set_raised(rb_thread_t *th);
189
+ int rb_threadptr_reset_raised(rb_thread_t *th);
190
+ #define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
191
+ #define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
192
+ #define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
193
+ #define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
194
+
195
+ VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
196
+ VALUE rb_make_exception(int argc, VALUE *argv);
197
+
198
+ NORETURN(void rb_fiber_start(void));
199
+
200
+ NORETURN(void rb_print_undef(VALUE, ID, int));
201
+ NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
202
+ NORETURN(void rb_vm_jump_tag_but_local_jump(int, VALUE));
203
+ NORETURN(void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv,
204
+ VALUE obj, int call_status));
205
+
206
+ VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
207
+ NODE *rb_vm_cref(void);
208
+ VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename, VALUE filepath);
209
+ void rb_vm_set_progname(VALUE filename);
210
+ void rb_thread_terminate_all(void);
211
+ VALUE rb_vm_top_self();
212
+ VALUE rb_vm_cbase(void);
213
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
214
+ void rb_trap_restore_mask(void);
215
+
216
+ #ifndef CharNext /* defined as CharNext[AW] on Windows. */
217
+ #define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
218
+ #endif
219
+
220
+ #if defined DOSISH || defined __CYGWIN__
221
+ static inline void
222
+ translit_char(char *p, int from, int to)
223
+ {
224
+ while (*p) {
225
+ if ((unsigned char)*p == from)
226
+ *p = to;
227
+ p = CharNext(p);
228
+ }
229
+ }
230
+ #endif
231
+
232
+ #endif /* RUBY_EVAL_INTERN_H */