* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / debug.c
blob265e864aec43304697477b9b7267917c8ffafc34
1 /**********************************************************************
3 debug.c -
5 $Author$
6 created at: 04/08/25 02:31:54 JST
8 Copyright (C) 2004-2007 Koichi Sasada
10 **********************************************************************/
12 #include "ruby/ruby.h"
13 #include "ruby/encoding.h"
14 #include "ruby/util.h"
15 #include "debug.h"
16 #include "eval_intern.h"
17 #include "vm_core.h"
19 /* for gdb */
20 static const union {
21 enum ruby_special_consts special_consts;
22 enum ruby_value_type value_type;
23 enum ruby_tag_type tag_type;
24 enum node_type node_type;
25 enum {
26 RUBY_ENCODING_INLINE_MAX = ENCODING_INLINE_MAX,
27 RUBY_ENCODING_SHIFT = ENCODING_SHIFT,
28 RUBY_ENCODING_MASK = ENCODING_MASK,
29 RUBY_ENC_CODERANGE_MASK = ENC_CODERANGE_MASK,
30 RUBY_ENC_CODERANGE_UNKNOWN = ENC_CODERANGE_UNKNOWN,
31 RUBY_ENC_CODERANGE_7BIT = ENC_CODERANGE_7BIT,
32 RUBY_ENC_CODERANGE_VALID = ENC_CODERANGE_VALID,
33 RUBY_ENC_CODERANGE_BROKEN = ENC_CODERANGE_BROKEN,
34 RUBY_FL_MARK = FL_MARK,
35 RUBY_FL_RESERVED = FL_RESERVED,
36 RUBY_FL_FINALIZE = FL_FINALIZE,
37 RUBY_FL_TAINT = FL_TAINT,
38 RUBY_FL_UNTRUSTED = FL_UNTRUSTED,
39 RUBY_FL_EXIVAR = FL_EXIVAR,
40 RUBY_FL_FREEZE = FL_FREEZE,
41 RUBY_FL_SINGLETON = FL_SINGLETON,
42 RUBY_FL_USER0 = FL_USER0,
43 RUBY_FL_USER1 = FL_USER1,
44 RUBY_FL_USER2 = FL_USER2,
45 RUBY_FL_USER3 = FL_USER3,
46 RUBY_FL_USER4 = FL_USER4,
47 RUBY_FL_USER5 = FL_USER5,
48 RUBY_FL_USER6 = FL_USER6,
49 RUBY_FL_USER7 = FL_USER7,
50 RUBY_FL_USER8 = FL_USER8,
51 RUBY_FL_USER9 = FL_USER9,
52 RUBY_FL_USER10 = FL_USER10,
53 RUBY_FL_USER11 = FL_USER11,
54 RUBY_FL_USER12 = FL_USER12,
55 RUBY_FL_USER13 = FL_USER13,
56 RUBY_FL_USER14 = FL_USER14,
57 RUBY_FL_USER15 = FL_USER15,
58 RUBY_FL_USER16 = FL_USER16,
59 RUBY_FL_USER17 = FL_USER17,
60 RUBY_FL_USER18 = FL_USER18,
61 RUBY_FL_USHIFT = FL_USHIFT,
62 RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
63 RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
64 RUBY_NODE_LSHIFT = NODE_LSHIFT,
65 RUBY_NODE_LMASK = NODE_LMASK,
66 RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
67 } various;
68 } dummy_gdb_enums;
70 const VALUE RUBY_FL_USER19 = FL_USER19;
72 int
73 ruby_debug_print_indent(int level, int debug_level, int indent_level)
75 if (level < debug_level) {
76 fprintf(stderr, "%*s", indent_level, "");
77 fflush(stderr);
78 return Qtrue;
80 return Qfalse;
83 void
84 ruby_debug_printf(const char *format, ...)
86 va_list ap;
87 va_start(ap, format);
88 vfprintf(stderr, format, ap);
89 va_end(ap);
92 VALUE
93 ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
95 if (level < debug_level) {
96 VALUE str;
97 str = rb_inspect(obj);
98 fprintf(stderr, "DBG> %s: %s\n", header,
99 obj == -1 ? "" : StringValueCStr(str));
100 fflush(stderr);
102 return obj;
105 void
106 ruby_debug_print_v(VALUE v)
108 ruby_debug_print_value(0, 1, "", v);
112 ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
114 if (level < debug_level) {
115 fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
116 fflush(stderr);
118 return id;
121 NODE *
122 ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
124 if (level < debug_level) {
125 fprintf(stderr, "DBG> %s: %s (%lu)\n", header,
126 ruby_node_name(nd_type(node)), nd_line(node));
128 return (NODE *)node;
131 void
132 ruby_debug_breakpoint(void)
134 /* */
137 #ifdef RUBY_DEBUG_ENV
138 static void
139 set_debug_option(const char *str, int len, void *arg)
141 #define SET_WHEN(name, var) do { \
142 if (len == sizeof(name) - 1 && \
143 strncmp(str, name, len) == 0) { \
144 extern int var; \
145 var = 1; \
146 return; \
148 } while (0)
149 SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr);
150 SET_WHEN("core", ruby_enable_coredump);
151 fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
154 void
155 ruby_set_debug_option(const char *str)
157 ruby_each_words(str, set_debug_option, 0);
159 #endif