(linenum→info "unix/slp.c:2238")

ruby/1.9.0/debug.c

    1: /**********************************************************************
    2: 
    3:   debug.c -
    4: 
    5:   $Author: nobu $
    6:   $Date: 2007-12-21 17:31:24 +0900 (Fri, 21 Dec 2007) $
    7:   created at: 04/08/25 02:31:54 JST
    8: 
    9:   Copyright (C) 2004-2007 Koichi Sasada
   10: 
   11: **********************************************************************/
   12: 
   13: #include "ruby/ruby.h"
   14: #include "ruby/encoding.h"
   15: #include "debug.h"
   16: #include "vm_core.h"
   17: 
   18: /* for gdb */
   19: static const union {
   20:     enum ruby_special_consts    special_consts;
   21:     enum ruby_value_type        value_type;
   22:     enum node_type              node_type;
   23:     enum {
   24:         RUBY_ENCODING_INLINE_MAX = ENCODING_INLINE_MAX,
   25:         RUBY_ENCODING_SHIFT = ENCODING_SHIFT,
   26:         RUBY_ENCODING_MASK  = ENCODING_MASK,
   27:         RUBY_ENC_CODERANGE_MASK    = ENC_CODERANGE_MASK,
   28:         RUBY_ENC_CODERANGE_UNKNOWN = ENC_CODERANGE_UNKNOWN,
   29:         RUBY_ENC_CODERANGE_7BIT    = ENC_CODERANGE_7BIT,
   30:         RUBY_ENC_CODERANGE_VALID   = ENC_CODERANGE_VALID,
   31:         RUBY_ENC_CODERANGE_BROKEN  = ENC_CODERANGE_BROKEN, 
   32:         RUBY_FL_MARK        = FL_MARK,
   33:         RUBY_FL_RESERVED    = FL_RESERVED,
   34:         RUBY_FL_FINALIZE    = FL_FINALIZE,
   35:         RUBY_FL_TAINT       = FL_TAINT,
   36:         RUBY_FL_EXIVAR      = FL_EXIVAR,
   37:         RUBY_FL_FREEZE      = FL_FREEZE,
   38:         RUBY_FL_SINGLETON   = FL_SINGLETON,
   39:         RUBY_FL_USER0       = FL_USER0,
   40:         RUBY_FL_USER1       = FL_USER1,
   41:         RUBY_FL_USER2       = FL_USER2,
   42:         RUBY_FL_USER3       = FL_USER3,
   43:         RUBY_FL_USER4       = FL_USER4,
   44:         RUBY_FL_USER5       = FL_USER5,
   45:         RUBY_FL_USER6       = FL_USER6,
   46:         RUBY_FL_USER7       = FL_USER7,
   47:         RUBY_FL_USER8       = FL_USER8,
   48:         RUBY_FL_USER9       = FL_USER9,
   49:         RUBY_FL_USER10      = FL_USER10,
   50:         RUBY_FL_USER11      = FL_USER11,
   51:         RUBY_FL_USER12      = FL_USER12,
   52:         RUBY_FL_USER13      = FL_USER13,
   53:         RUBY_FL_USER14      = FL_USER14,
   54:         RUBY_FL_USER15      = FL_USER15,
   55:         RUBY_FL_USER16      = FL_USER16,
   56:         RUBY_FL_USER17      = FL_USER17,
   57:         RUBY_FL_USER18      = FL_USER18,
   58:         RUBY_FL_USER19      = FL_USER19,
   59:         RUBY_FL_USHIFT      = FL_USHIFT,
   60:         RUBY_NODE_NEWLINE   = NODE_NEWLINE,
   61:         RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
   62:         RUBY_NODE_TYPEMASK  = NODE_TYPEMASK,
   63:         RUBY_NODE_LSHIFT    = NODE_LSHIFT,
   64:         RUBY_NODE_LMASK     = NODE_LMASK,
   65:     } various;
   66: } dummy_gdb_enums;
   67: 
   68: const VALUE RUBY_FL_USER20    = FL_USER20;
   69: 
   70: void
   71: ruby_debug_print_indent(int level, int debug_level, int indent_level)
   72: {
   73:     if (level < debug_level) {
   74:         int i;
   75:         for (i = 0; i < indent_level; i++) {
   76:             fprintf(stderr, " ");
   77:         }
   78:         fflush(stderr);
   79:     }
   80: }
   81: 
   82: VALUE
   83: ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
   84: {
   85:     if (level < debug_level) {
   86:         VALUE str;
   87:         str = rb_inspect(obj);
   88:         fprintf(stderr, "DBG> %s: %s\n", header,
   89:                 obj == -1 ? "" : StringValueCStr(str));
   90:         fflush(stderr);
   91:     }
   92:     return obj;
   93: }
   94: 
   95: void
   96: ruby_debug_print_v(VALUE v)
   97: {
   98:     ruby_debug_print_value(0, 1, "", v);
   99: }
  100: 
  101: ID
  102: ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
  103: {
  104:     if (level < debug_level) {
  105:         fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
  106:         fflush(stderr);
  107:     }
  108:     return id;
  109: }
  110: 
  111: NODE *
  112: ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
  113: {
  114:     if (level < debug_level) {
  115:         fprintf(stderr, "DBG> %s: %s (%lu)\n", header,
  116:                 ruby_node_name(nd_type(node)), nd_line(node));
  117:     }
  118:     return (NODE *)node;
  119: }
  120: 
  121: void
  122: ruby_debug_breakpoint(void)
  123: {
  124:     /* */
  125: }
  126: 
  127: #ifdef RUBY_DEBUG_ENV
  128: #include <ctype.h>
  129: 
  130: void
  131: ruby_set_debug_option(const char *str)
  132: {
  133:     const char *end;
  134:     int len;
  135: 
  136:     if (!str) return;
  137:     for (; *str; str = end) {
  138:         while (ISSPACE(*str) || *str == ',') str++;
  139:         if (!*str) break;
  140:         end = str;
  141:         while (*end && !ISSPACE(*end) && *end != ',') end++;
  142:         len = end - str;
  143: #define SET_WHEN(name, var)                 \
  144:         if (len == sizeof(name) - 1 &&     \
  145:             strncmp(str, name, len) == 0) { \
  146:             extern int ruby_##var;         \
  147:             ruby_##var = 1;                \
  148:             continue;                      \
  149:         }
  150:         SET_WHEN("gc_stress", gc_stress);
  151:         SET_WHEN("core", enable_coredump);
  152:         fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
  153:     }
  154: }
  155: #endif
Syntax (Markdown)