Ruby  2.4.2p198(2017-09-14revision59899)
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 {
32  enum {
33  RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
34  RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
35  RUBY_NODE_LSHIFT = NODE_LSHIFT,
36  RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
37  } various;
39 
41 
42 int
43 ruby_debug_print_indent(int level, int debug_level, int indent_level)
44 {
45  if (level < debug_level) {
46  fprintf(stderr, "%*s", indent_level, "");
47  fflush(stderr);
48  return TRUE;
49  }
50  return FALSE;
51 }
52 
53 void
54 ruby_debug_printf(const char *format, ...)
55 {
56  va_list ap;
57  va_start(ap, format);
58  vfprintf(stderr, format, ap);
59  va_end(ap);
60 }
61 
62 #include "gc.h"
63 
64 VALUE
65 ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
66 {
67  if (level < debug_level) {
68  char buff[0x100];
69  rb_raw_obj_info(buff, 0x100, obj);
70 
71  fprintf(stderr, "DBG> %s: %s\n", header, buff);
72  fflush(stderr);
73  }
74  return obj;
75 }
76 
77 void
79 {
80  ruby_debug_print_value(0, 1, "", v);
81 }
82 
83 ID
84 ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
85 {
86  if (level < debug_level) {
87  fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
88  fflush(stderr);
89  }
90  return id;
91 }
92 
93 NODE *
94 ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
95 {
96  if (level < debug_level) {
97  fprintf(stderr, "DBG> %s: %s (%u)\n", header,
98  ruby_node_name(nd_type(node)), nd_line(node));
99  }
100  return (NODE *)node;
101 }
102 
103 void
105 {
106  /* */
107 }
108 
109 static void
110 set_debug_option(const char *str, int len, void *arg)
111 {
112 #if defined _WIN32 && RUBY_MSVCRT_VERSION >= 80
113  extern int ruby_w32_rtc_error;
114 #endif
115 #define SET_WHEN(name, var, val) do { \
116  if (len == sizeof(name) - 1 && \
117  strncmp(str, (name), len) == 0) { \
118  (var) = (val); \
119  return; \
120  } \
121  } while (0)
122  SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr, Qtrue);
123  SET_WHEN("core", ruby_enable_coredump, 1);
124 #if defined _WIN32 && RUBY_MSVCRT_VERSION >= 80
125  SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
126 #endif
127  fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
128 }
129 
130 void
131 ruby_set_debug_option(const char *str)
132 {
134 }
VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
Definition: debug.c:65
#define FALSE
Definition: nkf.h:174
ruby_tag_type
Definition: vm_core.h:152
#define NODE_LSHIFT
Definition: node.h:278
enum ruby_method_ids method_ids
Definition: debug.c:26
enum ruby_econv_flag_type econv_flag_types
Definition: debug.c:31
ruby_econv_flag_type
Definition: encoding.h:355
#define nd_line(n)
Definition: node.h:280
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
Definition: util.c:3814
#define Qtrue
Definition: ruby.h:437
#define SET_WHEN(name, var, val)
enum @3::@4 various
const int id
Definition: nkf.c:209
node_type
Definition: node.h:22
ruby_fl_type
Definition: ruby.h:810
enum ruby_tag_type tag_type
Definition: debug.c:24
void ruby_debug_printf(const char *format,...)
Definition: debug.c:54
#define ruby_enable_coredump
Definition: signal.c:1418
int ruby_debug_print_indent(int level, int debug_level, int indent_level)
Definition: debug.c:43
#define nd_type(n)
Definition: node.h:274
enum ruby_id_types id_types
Definition: debug.c:27
ruby_coderange_type
Definition: encoding.h:62
Definition: node.h:235
enum node_type node_type
Definition: debug.c:25
#define level
const SIGNED_VALUE RUBY_NODE_LMASK
Definition: debug.c:40
#define NODE_LMASK
Definition: node.h:279
ruby_id_types
Definition: id.h:16
ruby_special_consts
Definition: ruby.h:405
#define TRUE
Definition: nkf.h:175
VALUE * ruby_initial_gc_stress_ptr
Definition: gc.c:720
unsigned long ID
Definition: ruby.h:86
#define NODE_FL_NEWLINE
Definition: node.h:269
unsigned long VALUE
Definition: ruby.h:85
const char * rb_id2name(ID)
Definition: symbol.c:759
enum ruby_encoding_consts encoding_consts
Definition: debug.c:29
ruby_value_type
Definition: ruby.h:455
void ruby_set_debug_option(const char *str)
Definition: debug.c:131
register unsigned int len
Definition: zonetab.h:51
#define NODE_TYPESHIFT
Definition: node.h:271
enum ruby_coderange_type enc_coderange_types
Definition: debug.c:30
const union @3 ruby_dummy_gdb_enums
ruby_encoding_consts
Definition: encoding.h:28
NODE * ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
Definition: debug.c:94
const char * ruby_node_name(int node)
Definition: iseq.c:1739
enum ruby_special_consts special_consts
Definition: debug.c:22
enum ruby_value_type value_type
Definition: debug.c:23
void ruby_debug_print_v(VALUE v)
Definition: debug.c:78
ruby_method_ids
Definition: id.h:70
static void set_debug_option(const char *str, int len, void *arg)
Definition: debug.c:110
const char * rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
Definition: gc.c:9219
void ruby_debug_breakpoint(void)
Definition: debug.c:104
#define NODE_TYPEMASK
Definition: node.h:272
enum ruby_fl_type fl_types
Definition: debug.c:28
ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
Definition: debug.c:84
#define SIGNED_VALUE
Definition: ruby.h:87