Ruby  2.0.0p598(2014-11-13revision48408)
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 {
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;
69 
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
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
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);
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
160 {
162 }
#define FL_USER0
#define nd_type(n)
VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
Definition: debug.c:95
#define ENC_CODERANGE_MASK
int * ruby_initial_gc_stress_ptr
Definition: gc.c:267
#define FL_USER7
#define FALSE
Definition: nkf.h:174
ruby_method_ids
Definition: ripper.y:55
enum ruby_method_ids method_ids
Definition: debug.c:26
#define FL_USER13
#define FL_EXIVAR
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
Definition: util.c:3766
#define FL_USER3
#define FL_RESERVED1
#define FL_USER9
enum ruby_tag_type tag_type
Definition: debug.c:24
void ruby_debug_printf(const char *format,...)
Definition: debug.c:86
#define NODE_TYPEMASK
int ruby_debug_print_indent(int level, int debug_level, int indent_level)
Definition: debug.c:75
#define FL_USER1
#define FL_USER17
ruby_tag_type
Definition: eval_intern.h:152
#define FL_UNTRUSTED
enum @2::@3 various
ruby_value_type
Definition: ripper.y:450
#define ENC_CODERANGE_BROKEN
Definition: ripper.y:240
#define FL_USER5
#define FL_FINALIZE
const VALUE RUBY_FL_USER19
Definition: debug.c:70
#define ENCODING_INLINE_MAX
#define FL_USER19
union @2 ruby_dummy_gdb_enums
static VALUE char * str
Definition: tcltklib.c:3546
#define FL_USER6
const SIGNED_VALUE RUBY_NODE_LMASK
Definition: debug.c:71
#define StringValueCStr(v)
unsigned long ID
Definition: ripper.y:105
va_end(args)
#define FL_USER18
static VALUE VALUE obj
Definition: tcltklib.c:3157
#define FL_USER2
#define FL_USER8
#define ENC_CODERANGE_UNKNOWN
int ruby_enable_coredump
Definition: signal.c:1110
#define FL_USER4
node_type
Definition: ripper.y:23
gz level
Definition: zlib.c:2262
const int id
Definition: nkf.c:209
#define NODE_LSHIFT
#define TRUE
Definition: nkf.h:175
#define NODE_LMASK
#define FL_USER12
#define SET_WHEN(name, var)
#define FL_TAINT
#define FL_FREEZE
#define FL_USER10
void ruby_set_debug_option(const char *str)
Definition: debug.c:159
#define ENC_CODERANGE_VALID
#define FL_USHIFT
arg
Definition: ripper.y:1317
#define ENC_CODERANGE_7BIT
#define FL_SINGLETON
#define NODE_TYPESHIFT
ruby_special_consts
Definition: ripper.y:405
NODE * ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
Definition: debug.c:124
const char * ruby_node_name(int node)
Definition: iseq.c:1582
enum ruby_special_consts special_consts
Definition: debug.c:22
#define NODE_FL_NEWLINE
enum ruby_value_type value_type
Definition: debug.c:23
#define FL_RESERVED2
#define FL_USER15
void ruby_debug_print_v(VALUE v)
Definition: debug.c:108
#define SIGNED_VALUE
static void set_debug_option(const char *str, int len, void *arg)
Definition: debug.c:140
const char * rb_id2name(ID id)
Definition: ripper.c:17006
unsigned long VALUE
Definition: ripper.y:104
void ruby_debug_breakpoint(void)
Definition: debug.c:134
BDIGIT v
Definition: bigdecimal.c:5677
#define nd_line(n)
#define FL_USER14
#define ENCODING_MASK
const VALUE RUBY_ENCODING_MASK
Definition: debug.c:72
ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
Definition: debug.c:114
#define FL_USER16
#define FL_USER11
#define ENCODING_SHIFT
VALUE rb_inspect(VALUE)
Definition: object.c:411
size_t len
Definition: tcltklib.c:3567