Ruby 2.1.5p273(2014-11-13revision48405)

- 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 ruby_id_types id_types;
28 enum {
29 RUBY_ENCODING_INLINE_MAX = ENCODING_INLINE_MAX,
30 RUBY_ENCODING_SHIFT = ENCODING_SHIFT,
31 RUBY_ENC_CODERANGE_MASK = ENC_CODERANGE_MASK,
32 RUBY_ENC_CODERANGE_UNKNOWN = ENC_CODERANGE_UNKNOWN,
33 RUBY_ENC_CODERANGE_7BIT = ENC_CODERANGE_7BIT,
34 RUBY_ENC_CODERANGE_VALID = ENC_CODERANGE_VALID,
35 RUBY_ENC_CODERANGE_BROKEN = ENC_CODERANGE_BROKEN,
36 RUBY_FL_WB_PROTECTED = FL_WB_PROTECTED,
37 RUBY_FL_PROMOTED = FL_PROMOTED,
38 RUBY_FL_FINALIZE = FL_FINALIZE,
39 RUBY_FL_TAINT = FL_TAINT,
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 }
ruby_debug_print_value
VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
Definition: debug.c:95
FL_EXIVAR
#define FL_EXIVAR
Definition: ruby.h:1139
FL_USER17
#define FL_USER17
Definition: ruby.h:1161
FALSE
#define FALSE
Definition: nkf.h:174
NODE_LSHIFT
#define NODE_LSHIFT
Definition: node.h:286
FL_USER14
#define FL_USER14
Definition: ruby.h:1158
FL_USER7
#define FL_USER7
Definition: ruby.h:1151
method_ids
enum ruby_method_ids method_ids
Definition: debug.c:26
FL_USHIFT
#define FL_USHIFT
Definition: ruby.h:1142
ruby.h
FL_TAINT
#define FL_TAINT
Definition: ruby.h:1137
nd_line
#define nd_line(n)
Definition: node.h:288
ruby_each_words
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
Definition: util.c:3767
various
enum @3::@4 various
id
const int id
Definition: nkf.c:209
eval_intern.h
node_type
node_type
Definition: node.h:22
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
FL_USER2
#define FL_USER2
Definition: ruby.h:1146
FL_USER15
#define FL_USER15
Definition: ruby.h:1159
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_USER8
#define FL_USER8
Definition: ruby.h:1152
FL_USER19
#define FL_USER19
Definition: ruby.h:1163
ENC_CODERANGE_MASK
#define ENC_CODERANGE_MASK
Definition: encoding.h:47
ruby_tag_type
ruby_tag_type
Definition: eval_intern.h:177
nd_type
#define nd_type(n)
Definition: node.h:282
id_types
enum ruby_id_types id_types
Definition: debug.c:27
ENC_CODERANGE_7BIT
#define ENC_CODERANGE_7BIT
Definition: encoding.h:49
id.h
FL_USER4
#define FL_USER4
Definition: ruby.h:1148
RNode
Definition: node.h:239
FL_SINGLETON
#define FL_SINGLETON
Definition: ruby.h:1133
FL_USER13
#define FL_USER13
Definition: ruby.h:1157
RUBY_FL_USER19
const VALUE RUBY_FL_USER19
Definition: debug.c:70
node_type
enum node_type node_type
Definition: debug.c:25
FL_USER0
#define FL_USER0
Definition: ruby.h:1144
FL_USER1
#define FL_USER1
Definition: ruby.h:1145
level
#define level
FL_USER6
#define FL_USER6
Definition: ruby.h:1150
RUBY_NODE_LMASK
const SIGNED_VALUE RUBY_NODE_LMASK
Definition: debug.c:71
ENCODING_SHIFT
#define ENCODING_SHIFT
Definition: encoding.h:28
NODE_LMASK
#define NODE_LMASK
Definition: node.h:287
FL_USER18
#define FL_USER18
Definition: ruby.h:1162
ruby_id_types
ruby_id_types
Definition: id.h:16
ruby_special_consts
ruby_special_consts
Definition: ruby.h:397
ENC_CODERANGE_UNKNOWN
#define ENC_CODERANGE_UNKNOWN
Definition: encoding.h:48
ENC_CODERANGE_BROKEN
#define ENC_CODERANGE_BROKEN
Definition: encoding.h:51
ENC_CODERANGE_VALID
#define ENC_CODERANGE_VALID
Definition: encoding.h:50
ruby_enable_coredump
int ruby_enable_coredump
Definition: signal.c:1243
encoding.h
FL_FINALIZE
#define FL_FINALIZE
Definition: ruby.h:1136
util.h
TRUE
#define TRUE
Definition: nkf.h:175
ruby_initial_gc_stress_ptr
VALUE * ruby_initial_gc_stress_ptr
Definition: gc.c:601
ENCODING_MASK
#define ENCODING_MASK
Definition: encoding.h:29
FL_USER5
#define FL_USER5
Definition: ruby.h:1149
SET_WHEN
#define SET_WHEN(name, var)
ID
unsigned long ID
Definition: ruby.h:89
FL_USER12
#define FL_USER12
Definition: ruby.h:1156
NODE_FL_NEWLINE
#define NODE_FL_NEWLINE
Definition: node.h:275
vm_core.h
VALUE
unsigned long VALUE
Definition: ruby.h:88
ruby_value_type
ruby_value_type
Definition: ruby.h:442
ruby_set_debug_option
void ruby_set_debug_option(const char *str)
Definition: debug.c:159
StringValueCStr
#define StringValueCStr(v)
Definition: ruby.h:541
NODE_TYPESHIFT
#define NODE_TYPESHIFT
Definition: node.h:279
FL_USER16
#define FL_USER16
Definition: ruby.h:1160
ENCODING_INLINE_MAX
#define ENCODING_INLINE_MAX
Definition: encoding.h:27
ruby_dummy_gdb_enums
const union @3 ruby_dummy_gdb_enums
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:1603
special_consts
enum ruby_special_consts special_consts
Definition: debug.c:22
FL_WB_PROTECTED
#define FL_WB_PROTECTED
Definition: ruby.h:1134
value_type
enum ruby_value_type value_type
Definition: debug.c:23
FL_USER11
#define FL_USER11
Definition: ruby.h:1155
ruby_debug_print_v
void ruby_debug_print_v(VALUE v)
Definition: debug.c:108
FL_USER10
#define FL_USER10
Definition: ruby.h:1154
FL_USER9
#define FL_USER9
Definition: ruby.h:1153
ruby_method_ids
ruby_method_ids
Definition: id.h:67
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:17230
FL_FREEZE
#define FL_FREEZE
Definition: ruby.h:1140
rb_inspect
VALUE rb_inspect(VALUE)
Definition: object.c:470
FL_USER3
#define FL_USER3
Definition: ruby.h:1147
ruby_debug_breakpoint
void ruby_debug_breakpoint(void)
Definition: debug.c:134
NODE_TYPEMASK
#define NODE_TYPEMASK
Definition: node.h:280
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_PROMOTED
#define FL_PROMOTED
Definition: ruby.h:1135
SIGNED_VALUE
#define SIGNED_VALUE
Definition: ruby.h:90