Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

debug.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 debug.c -
4
5 $Author: ko1 $
6 created at: 04/08/25 02:31:54 JST
7
8 Copyright (C) 2004-2007 Koichi Sasada
9
10 **********************************************************************/
11
12 #include "ruby/ruby.h"
13 #include "ruby/encoding.h"
14 #include "ruby/util.h"
15 #include "vm_debug.h"
16 #include "eval_intern.h"
17 #include "vm_core.h"
18 #include "id.h"
19
20 /* for gdb */
21 const union {
22 enum ruby_special_consts special_consts;
23 enum ruby_value_type value_type;
24 enum ruby_tag_type tag_type;
25 enum node_type node_type;
26 enum ruby_method_ids method_ids;
27 enum {
28 RUBY_ENCODING_INLINE_MAX = ENCODING_INLINE_MAX,
29 RUBY_ENCODING_SHIFT = ENCODING_SHIFT,
30 RUBY_ENC_CODERANGE_MASK = ENC_CODERANGE_MASK,
31 RUBY_ENC_CODERANGE_UNKNOWN = ENC_CODERANGE_UNKNOWN,
32 RUBY_ENC_CODERANGE_7BIT = ENC_CODERANGE_7BIT,
33 RUBY_ENC_CODERANGE_VALID = ENC_CODERANGE_VALID,
34 RUBY_ENC_CODERANGE_BROKEN = ENC_CODERANGE_BROKEN,
35 RUBY_FL_RESERVED1 = FL_RESERVED1,
36 RUBY_FL_RESERVED2 = FL_RESERVED2,
37 RUBY_FL_FINALIZE = FL_FINALIZE,
38 RUBY_FL_TAINT = FL_TAINT,
39 RUBY_FL_UNTRUSTED = FL_UNTRUSTED,
40 RUBY_FL_EXIVAR = FL_EXIVAR,
41 RUBY_FL_FREEZE = FL_FREEZE,
42 RUBY_FL_SINGLETON = FL_SINGLETON,
43 RUBY_FL_USER0 = FL_USER0,
44 RUBY_FL_USER1 = FL_USER1,
45 RUBY_FL_USER2 = FL_USER2,
46 RUBY_FL_USER3 = FL_USER3,
47 RUBY_FL_USER4 = FL_USER4,
48 RUBY_FL_USER5 = FL_USER5,
49 RUBY_FL_USER6 = FL_USER6,
50 RUBY_FL_USER7 = FL_USER7,
51 RUBY_FL_USER8 = FL_USER8,
52 RUBY_FL_USER9 = FL_USER9,
53 RUBY_FL_USER10 = FL_USER10,
54 RUBY_FL_USER11 = FL_USER11,
55 RUBY_FL_USER12 = FL_USER12,
56 RUBY_FL_USER13 = FL_USER13,
57 RUBY_FL_USER14 = FL_USER14,
58 RUBY_FL_USER15 = FL_USER15,
59 RUBY_FL_USER16 = FL_USER16,
60 RUBY_FL_USER17 = FL_USER17,
61 RUBY_FL_USER18 = FL_USER18,
62 RUBY_FL_USHIFT = FL_USHIFT,
63 RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
64 RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
65 RUBY_NODE_LSHIFT = NODE_LSHIFT,
66 RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
67 } various;
68 } ruby_dummy_gdb_enums;
69
70 const VALUE RUBY_FL_USER19 = FL_USER19;
71 const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
72 const VALUE RUBY_ENCODING_MASK = ENCODING_MASK;
73
74 int
75 ruby_debug_print_indent(int level, int debug_level, int indent_level)
76 {
77 if (level < debug_level) {
78 fprintf(stderr, "%*s", indent_level, "");
79 fflush(stderr);
80 return TRUE;
81 }
82 return FALSE;
83 }
84
85 void
86 ruby_debug_printf(const char *format, ...)
87 {
88 va_list ap;
89 va_start(ap, format);
90 vfprintf(stderr, format, ap);
91 va_end(ap);
92 }
93
94 VALUE
95 ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
96 {
97 if (level < debug_level) {
98 VALUE str;
99 str = rb_inspect(obj);
100 fprintf(stderr, "DBG> %s: %s\n", header,
101 obj == (VALUE)(SIGNED_VALUE)-1 ? "" : StringValueCStr(str));
102 fflush(stderr);
103 }
104 return obj;
105 }
106
107 void
108 ruby_debug_print_v(VALUE v)
109 {
110 ruby_debug_print_value(0, 1, "", v);
111 }
112
113 ID
114 ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
115 {
116 if (level < debug_level) {
117 fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
118 fflush(stderr);
119 }
120 return id;
121 }
122
123 NODE *
124 ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
125 {
126 if (level < debug_level) {
127 fprintf(stderr, "DBG> %s: %s (%u)\n", header,
128 ruby_node_name(nd_type(node)), nd_line(node));
129 }
130 return (NODE *)node;
131 }
132
133 void
134 ruby_debug_breakpoint(void)
135 {
136 /* */
137 }
138
139 static void
140 set_debug_option(const char *str, int len, void *arg)
141 {
142 #define SET_WHEN(name, var) do { \
143 if (len == sizeof(name) - 1 && \
144 strncmp(str, (name), len) == 0) { \
145 extern int var; \
146 var = 1; \
147 return; \
148 } \
149 } while (0)
150 SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr);
151 SET_WHEN("core", ruby_enable_coredump);
152 #if defined _WIN32 && defined _MSC_VER && _MSC_VER >= 1400
153 SET_WHEN("rtc_error", ruby_w32_rtc_error);
154 #endif
155 fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
156 }
157
158 void
159 ruby_set_debug_option(const char *str)
160 {
161 ruby_each_words(str, set_debug_option, 0);
162 }
FL_USER0
#define FL_USER0
nd_type
#define nd_type(n)
ruby_debug_print_value
VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
Definition: debug.c:95
ENC_CODERANGE_MASK
#define ENC_CODERANGE_MASK
ruby_initial_gc_stress_ptr
int * ruby_initial_gc_stress_ptr
Definition: gc.c:267
FL_USER7
#define FL_USER7
FALSE
#define FALSE
Definition: nkf.h:174
ruby_method_ids
ruby_method_ids
Definition: ripper.y:55
method_ids
enum ruby_method_ids method_ids
Definition: debug.c:26
FL_USER13
#define FL_USER13
ruby.h
FL_EXIVAR
#define FL_EXIVAR
ruby_each_words
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
Definition: util.c:3764
FL_USER3
#define FL_USER3
FL_RESERVED1
#define FL_RESERVED1
FL_USER9
#define FL_USER9
eval_intern.h
tag_type
enum ruby_tag_type tag_type
Definition: debug.c:24
ruby_debug_printf
void ruby_debug_printf(const char *format,...)
Definition: debug.c:86
NODE_TYPEMASK
#define NODE_TYPEMASK
ruby_debug_print_indent
int ruby_debug_print_indent(int level, int debug_level, int indent_level)
Definition: debug.c:75
vm_debug.h
FL_USER1
#define FL_USER1
FL_USER17
#define FL_USER17
ruby_tag_type
ruby_tag_type
Definition: eval_intern.h:124
FL_UNTRUSTED
#define FL_UNTRUSTED
various
enum @2::@3 various
ruby_value_type
ruby_value_type
Definition: ripper.y:450
ENC_CODERANGE_BROKEN
#define ENC_CODERANGE_BROKEN
id.h
RNode
Definition: ripper.y:240
FL_USER5
#define FL_USER5
FL_FINALIZE
#define FL_FINALIZE
RUBY_FL_USER19
const VALUE RUBY_FL_USER19
Definition: debug.c:70
ENCODING_INLINE_MAX
#define ENCODING_INLINE_MAX
FL_USER19
#define FL_USER19
ruby_dummy_gdb_enums
union @2 ruby_dummy_gdb_enums
str
static VALUE char * str
Definition: tcltklib.c:3547
FL_USER6
#define FL_USER6
RUBY_NODE_LMASK
const SIGNED_VALUE RUBY_NODE_LMASK
Definition: debug.c:71
StringValueCStr
#define StringValueCStr(v)
ID
unsigned long ID
Definition: ripper.y:105
va_end
va_end(args)
FL_USER18
#define FL_USER18
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
FL_USER2
#define FL_USER2
FL_USER8
#define FL_USER8
ENC_CODERANGE_UNKNOWN
#define ENC_CODERANGE_UNKNOWN
ruby_enable_coredump
int ruby_enable_coredump
Definition: signal.c:1091
encoding.h
FL_USER4
#define FL_USER4
node_type
node_type
Definition: ripper.y:23
level
gz level
Definition: zlib.c:2264
id
const int id
Definition: nkf.c:209
NODE_LSHIFT
#define NODE_LSHIFT
util.h
TRUE
#define TRUE
Definition: nkf.h:175
NODE_LMASK
#define NODE_LMASK
FL_USER12
#define FL_USER12
SET_WHEN
#define SET_WHEN(name, var)
FL_TAINT
#define FL_TAINT
vm_core.h
FL_FREEZE
#define FL_FREEZE
FL_USER10
#define FL_USER10
ruby_set_debug_option
void ruby_set_debug_option(const char *str)
Definition: debug.c:159
ENC_CODERANGE_VALID
#define ENC_CODERANGE_VALID
FL_USHIFT
#define FL_USHIFT
arg
arg
Definition: ripper.y:1315
ENC_CODERANGE_7BIT
#define ENC_CODERANGE_7BIT
FL_SINGLETON
#define FL_SINGLETON
NODE_TYPESHIFT
#define NODE_TYPESHIFT
ruby_special_consts
ruby_special_consts
Definition: ripper.y:405
ruby_debug_print_node
NODE * ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
Definition: debug.c:124
ruby_node_name
const char * ruby_node_name(int node)
Definition: iseq.c:1578
special_consts
enum ruby_special_consts special_consts
Definition: debug.c:22
NODE_FL_NEWLINE
#define NODE_FL_NEWLINE
value_type
enum ruby_value_type value_type
Definition: debug.c:23
FL_RESERVED2
#define FL_RESERVED2
FL_USER15
#define FL_USER15
ruby_debug_print_v
void ruby_debug_print_v(VALUE v)
Definition: debug.c:108
SIGNED_VALUE
#define SIGNED_VALUE
set_debug_option
static void set_debug_option(const char *str, int len, void *arg)
Definition: debug.c:140
rb_id2name
const char * rb_id2name(ID id)
Definition: ripper.c:17005
VALUE
unsigned long VALUE
Definition: ripper.y:104
ruby_debug_breakpoint
void ruby_debug_breakpoint(void)
Definition: debug.c:134
v
BDIGIT v
Definition: bigdecimal.c:5656
nd_line
#define nd_line(n)
FL_USER14
#define FL_USER14
ENCODING_MASK
#define ENCODING_MASK
RUBY_ENCODING_MASK
const VALUE RUBY_ENCODING_MASK
Definition: debug.c:72
ruby_debug_print_id
ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
Definition: debug.c:114
FL_USER16
#define FL_USER16
FL_USER11
#define FL_USER11
ENCODING_SHIFT
#define ENCODING_SHIFT
rb_inspect
VALUE rb_inspect(VALUE)
Definition: object.c:402
len
size_t len
Definition: tcltklib.c:3568