• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

debug.c

Go to the documentation of this file.
00001 /**********************************************************************
00002 
00003   debug.c -
00004 
00005   $Author: yugui $
00006   created at: 04/08/25 02:31:54 JST
00007 
00008   Copyright (C) 2004-2007 Koichi Sasada
00009 
00010 **********************************************************************/
00011 
00012 #include "ruby/ruby.h"
00013 #include "ruby/encoding.h"
00014 #include "ruby/util.h"
00015 #include "debug.h"
00016 #include "eval_intern.h"
00017 #include "vm_core.h"
00018 #include "id.h"
00019 
00020 /* for gdb */
00021 const union {
00022     enum ruby_special_consts    special_consts;
00023     enum ruby_value_type        value_type;
00024     enum ruby_tag_type          tag_type;
00025     enum node_type              node_type;
00026     enum ruby_method_ids        method_ids;
00027     enum {
00028         RUBY_ENCODING_INLINE_MAX = ENCODING_INLINE_MAX,
00029         RUBY_ENCODING_SHIFT = ENCODING_SHIFT,
00030         RUBY_ENC_CODERANGE_MASK    = ENC_CODERANGE_MASK,
00031         RUBY_ENC_CODERANGE_UNKNOWN = ENC_CODERANGE_UNKNOWN,
00032         RUBY_ENC_CODERANGE_7BIT    = ENC_CODERANGE_7BIT,
00033         RUBY_ENC_CODERANGE_VALID   = ENC_CODERANGE_VALID,
00034         RUBY_ENC_CODERANGE_BROKEN  = ENC_CODERANGE_BROKEN,
00035         RUBY_FL_MARK        = FL_MARK,
00036         RUBY_FL_RESERVED    = FL_RESERVED,
00037         RUBY_FL_FINALIZE    = FL_FINALIZE,
00038         RUBY_FL_TAINT       = FL_TAINT,
00039         RUBY_FL_UNTRUSTED   = FL_UNTRUSTED,
00040         RUBY_FL_EXIVAR      = FL_EXIVAR,
00041         RUBY_FL_FREEZE      = FL_FREEZE,
00042         RUBY_FL_SINGLETON   = FL_SINGLETON,
00043         RUBY_FL_USER0       = FL_USER0,
00044         RUBY_FL_USER1       = FL_USER1,
00045         RUBY_FL_USER2       = FL_USER2,
00046         RUBY_FL_USER3       = FL_USER3,
00047         RUBY_FL_USER4       = FL_USER4,
00048         RUBY_FL_USER5       = FL_USER5,
00049         RUBY_FL_USER6       = FL_USER6,
00050         RUBY_FL_USER7       = FL_USER7,
00051         RUBY_FL_USER8       = FL_USER8,
00052         RUBY_FL_USER9       = FL_USER9,
00053         RUBY_FL_USER10      = FL_USER10,
00054         RUBY_FL_USER11      = FL_USER11,
00055         RUBY_FL_USER12      = FL_USER12,
00056         RUBY_FL_USER13      = FL_USER13,
00057         RUBY_FL_USER14      = FL_USER14,
00058         RUBY_FL_USER15      = FL_USER15,
00059         RUBY_FL_USER16      = FL_USER16,
00060         RUBY_FL_USER17      = FL_USER17,
00061         RUBY_FL_USER18      = FL_USER18,
00062         RUBY_FL_USHIFT      = FL_USHIFT,
00063         RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
00064         RUBY_NODE_TYPEMASK  = NODE_TYPEMASK,
00065         RUBY_NODE_LSHIFT    = NODE_LSHIFT,
00066         RUBY_NODE_FL_NEWLINE   = NODE_FL_NEWLINE
00067     } various;
00068 } ruby_dummy_gdb_enums;
00069 
00070 const VALUE RUBY_FL_USER19    = FL_USER19;
00071 const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
00072 const VALUE RUBY_ENCODING_MASK  = ENCODING_MASK;
00073 
00074 int
00075 ruby_debug_print_indent(int level, int debug_level, int indent_level)
00076 {
00077     if (level < debug_level) {
00078         fprintf(stderr, "%*s", indent_level, "");
00079         fflush(stderr);
00080         return TRUE;
00081     }
00082     return FALSE;
00083 }
00084 
00085 void
00086 ruby_debug_printf(const char *format, ...)
00087 {
00088     va_list ap;
00089     va_start(ap, format);
00090     vfprintf(stderr, format, ap);
00091     va_end(ap);
00092 }
00093 
00094 VALUE
00095 ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
00096 {
00097     if (level < debug_level) {
00098         VALUE str;
00099         str = rb_inspect(obj);
00100         fprintf(stderr, "DBG> %s: %s\n", header,
00101                 obj == (VALUE)(SIGNED_VALUE)-1 ? "" : StringValueCStr(str));
00102         fflush(stderr);
00103     }
00104     return obj;
00105 }
00106 
00107 void
00108 ruby_debug_print_v(VALUE v)
00109 {
00110     ruby_debug_print_value(0, 1, "", v);
00111 }
00112 
00113 ID
00114 ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
00115 {
00116     if (level < debug_level) {
00117         fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
00118         fflush(stderr);
00119     }
00120     return id;
00121 }
00122 
00123 NODE *
00124 ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
00125 {
00126     if (level < debug_level) {
00127         fprintf(stderr, "DBG> %s: %s (%u)\n", header,
00128                 ruby_node_name(nd_type(node)), nd_line(node));
00129     }
00130     return (NODE *)node;
00131 }
00132 
00133 void
00134 ruby_debug_breakpoint(void)
00135 {
00136     /* */
00137 }
00138 
00139 #ifdef RUBY_DEBUG_ENV
00140 static void
00141 set_debug_option(const char *str, int len, void *arg)
00142 {
00143 #define SET_WHEN(name, var) do {            \
00144         if (len == sizeof(name) - 1 &&      \
00145             strncmp(str, name, len) == 0) { \
00146             extern int var;         \
00147             var = 1;                \
00148             return;                         \
00149         }                                   \
00150     } while (0)
00151     SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr);
00152     SET_WHEN("core", ruby_enable_coredump);
00153 #if defined _WIN32 && defined _MSC_VER && _MSC_VER >= 1400
00154     SET_WHEN("rtc_error", ruby_w32_rtc_error);
00155 #endif
00156     fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
00157 }
00158 
00159 void
00160 ruby_set_debug_option(const char *str)
00161 {
00162     ruby_each_words(str, set_debug_option, 0);
00163 }
00164 #endif
00165 

Generated on Thu Sep 8 2011 03:46:41 for Ruby by  doxygen 1.7.1