Annotation of gcc/sdbout.c, revision 1.1.1.7

1.1       root        1: /* Output sdb-format symbol table information from GNU compiler.
1.1.1.7 ! root        2:    Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
1.1       root        3: 
                      4: This file is part of GNU CC.
                      5: 
                      6: GNU CC is free software; you can redistribute it and/or modify
                      7: it under the terms of the GNU General Public License as published by
                      8: the Free Software Foundation; either version 2, or (at your option)
                      9: any later version.
                     10: 
                     11: GNU CC is distributed in the hope that it will be useful,
                     12: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: GNU General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU CC; see the file COPYING.  If not, write to
                     18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     19: 
                     20: /*  [email protected] says:
                     21: I modified the struct.c example and have a nm of a .o resulting from the
                     22: AT&T C compiler.  From the example below I would conclude the following:
                     23: 
                     24: 1. All .defs from structures are emitted as scanned.  The example below
                     25:    clearly shows the symbol table entries for BoxRec2 are after the first
                     26:    function.
                     27: 
                     28: 2. All functions and their locals (including statics) are emitted as scanned.
                     29: 
                     30: 3. All nested unnamed union and structure .defs must be emitted before
                     31:    the structure in which they are nested.  The AT&T assembler is a
                     32:    one pass beast as far as symbolics are concerned.
                     33: 
                     34: 4. All structure .defs are emitted before the typedefs that refer to them.
                     35: 
                     36: 5. All top level static and external variable definitions are moved to the
1.1.1.3   root       37:    end of file with all top level statics occurring first before externs.
1.1       root       38: 
                     39: 6. All undefined references are at the end of the file.
                     40: */
                     41: 
                     42: #include "config.h"
                     43: 
                     44: #ifdef SDB_DEBUGGING_INFO
                     45: 
                     46: #include "tree.h"
                     47: #include "rtl.h"
                     48: #include <stdio.h>
                     49: #include "regs.h"
                     50: #include "flags.h"
                     51: #include "insn-config.h"
                     52: #include "reload.h"
                     53: 
                     54: /* Mips systems use the SDB functions to dump out symbols, but
                     55:    do not supply usable syms.h include files.  */
1.1.1.7 ! root       56: #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(WINNT)
1.1       root       57: #include <syms.h>
                     58: /* Use T_INT if we don't have T_VOID.  */
                     59: #ifndef T_VOID
                     60: #define T_VOID T_INT
                     61: #endif
                     62: #else /* not USG, or MIPS */
                     63: #include "gsyms.h"
                     64: #endif /* not USG, or MIPS */
                     65: 
                     66: /* #include <storclass.h>  used to be this instead of syms.h.  */
                     67: 
                     68: /* 1 if PARM is passed to this function in memory.  */
                     69: 
                     70: #define PARM_PASSED_IN_MEMORY(PARM) \
                     71:  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
                     72: 
                     73: /* A C expression for the integer offset value of an automatic variable
                     74:    (C_AUTO) having address X (an RTX).  */
                     75: #ifndef DEBUGGER_AUTO_OFFSET
                     76: #define DEBUGGER_AUTO_OFFSET(X) \
                     77:   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
                     78: #endif
                     79: 
                     80: /* A C expression for the integer offset value of an argument (C_ARG)
                     81:    having address X (an RTX).  The nominal offset is OFFSET.  */
                     82: #ifndef DEBUGGER_ARG_OFFSET
                     83: #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
                     84: #endif
                     85: 
                     86: /* Line number of beginning of current function, minus one.
                     87:    Negative means not in a function or not using sdb.  */
                     88: 
                     89: int sdb_begin_function_line = -1;
                     90: 
                     91: /* Counter to generate unique "names" for nameless struct members.  */
                     92: 
                     93: static int unnamed_struct_number = 0;
                     94: 
                     95: extern FILE *asm_out_file;
                     96: 
                     97: extern tree current_function_decl;
                     98: 
                     99: void sdbout_init ();
                    100: void sdbout_symbol ();
                    101: void sdbout_types();
                    102: 
                    103: static void sdbout_typedefs ();
                    104: static void sdbout_syms ();
                    105: static void sdbout_one_type ();
                    106: static void sdbout_queue_anonymous_type ();
1.1.1.2   root      107: static void sdbout_dequeue_anonymous_types ();
1.1       root      108: static int plain_type_1 ();
                    109: 
                    110: /* Define the default sizes for various types.  */
                    111: 
                    112: #ifndef CHAR_TYPE_SIZE
                    113: #define CHAR_TYPE_SIZE BITS_PER_UNIT
                    114: #endif
                    115: 
                    116: #ifndef SHORT_TYPE_SIZE
                    117: #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
                    118: #endif
                    119: 
                    120: #ifndef INT_TYPE_SIZE
                    121: #define INT_TYPE_SIZE BITS_PER_WORD
                    122: #endif
                    123: 
                    124: #ifndef LONG_TYPE_SIZE
                    125: #define LONG_TYPE_SIZE BITS_PER_WORD
                    126: #endif
                    127: 
                    128: #ifndef LONG_LONG_TYPE_SIZE
                    129: #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
                    130: #endif
                    131: 
                    132: #ifndef FLOAT_TYPE_SIZE
                    133: #define FLOAT_TYPE_SIZE BITS_PER_WORD
                    134: #endif
                    135: 
                    136: #ifndef DOUBLE_TYPE_SIZE
                    137: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
                    138: #endif
                    139: 
                    140: #ifndef LONG_DOUBLE_TYPE_SIZE
                    141: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
                    142: #endif
                    143: 
                    144: /* Random macros describing parts of SDB data.  */
                    145: 
                    146: /* Put something here if lines get too long */
                    147: #define CONTIN
                    148: 
                    149: /* Default value of delimiter is ";".  */
                    150: #ifndef SDB_DELIM
                    151: #define SDB_DELIM      ";"
                    152: #endif
                    153: 
                    154: /* Maximum number of dimensions the assembler will allow.  */
                    155: #ifndef SDB_MAX_DIM
                    156: #define SDB_MAX_DIM 4
                    157: #endif
                    158: 
                    159: #ifndef PUT_SDB_SCL
                    160: #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
                    161: #endif
                    162: 
                    163: #ifndef PUT_SDB_INT_VAL
                    164: #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
                    165: #endif
                    166: 
                    167: #ifndef PUT_SDB_VAL
                    168: #define PUT_SDB_VAL(a)                         \
                    169: ( fputs ("\t.val\t", asm_out_file),            \
                    170:   output_addr_const (asm_out_file, (a)),       \
                    171:   fprintf (asm_out_file, SDB_DELIM))
                    172: #endif
                    173: 
                    174: #ifndef PUT_SDB_DEF
                    175: #define PUT_SDB_DEF(a)                         \
                    176: do { fprintf (asm_out_file, "\t.def\t");       \
                    177:      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
                    178:      fprintf (asm_out_file, SDB_DELIM); } while (0)
                    179: #endif
                    180: 
                    181: #ifndef PUT_SDB_PLAIN_DEF
                    182: #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
                    183: #endif
                    184: 
                    185: #ifndef PUT_SDB_ENDEF
                    186: #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
                    187: #endif
                    188: 
                    189: #ifndef PUT_SDB_TYPE
                    190: #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
                    191: #endif
                    192: 
                    193: #ifndef PUT_SDB_SIZE
                    194: #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
                    195: #endif
                    196: 
                    197: #ifndef PUT_SDB_START_DIM
                    198: #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
                    199: #endif
                    200: 
                    201: #ifndef PUT_SDB_NEXT_DIM
                    202: #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
                    203: #endif
                    204: 
                    205: #ifndef PUT_SDB_LAST_DIM
                    206: #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
                    207: #endif
                    208: 
                    209: #ifndef PUT_SDB_TAG
                    210: #define PUT_SDB_TAG(a)                         \
                    211: do { fprintf (asm_out_file, "\t.tag\t");       \
                    212:      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
                    213:      fprintf (asm_out_file, SDB_DELIM); } while (0)
                    214: #endif
                    215: 
                    216: #ifndef PUT_SDB_BLOCK_START
                    217: #define PUT_SDB_BLOCK_START(LINE)              \
                    218:   fprintf (asm_out_file,                       \
                    219:           "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
                    220:           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
                    221: #endif
                    222: 
                    223: #ifndef PUT_SDB_BLOCK_END
                    224: #define PUT_SDB_BLOCK_END(LINE)                        \
                    225:   fprintf (asm_out_file,                       \
                    226:           "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n",  \
                    227:           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
                    228: #endif
                    229: 
                    230: #ifndef PUT_SDB_FUNCTION_START
                    231: #define PUT_SDB_FUNCTION_START(LINE)           \
                    232:   fprintf (asm_out_file,                       \
                    233:           "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
                    234:           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
                    235: #endif
                    236: 
                    237: #ifndef PUT_SDB_FUNCTION_END
                    238: #define PUT_SDB_FUNCTION_END(LINE)             \
                    239:   fprintf (asm_out_file,                       \
                    240:           "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
                    241:           SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
                    242: #endif
                    243: 
                    244: #ifndef PUT_SDB_EPILOGUE_END
                    245: #define PUT_SDB_EPILOGUE_END(NAME)                     \
                    246: do { fprintf (asm_out_file, "\t.def\t");               \
                    247:      ASM_OUTPUT_LABELREF (asm_out_file, NAME);         \
                    248:      fprintf (asm_out_file,                            \
                    249:              "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",    \
                    250:              SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
                    251: #endif
                    252: 
                    253: #ifndef SDB_GENERATE_FAKE
                    254: #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
                    255:   sprintf ((BUFFER), ".%dfake", (NUMBER));
                    256: #endif
                    257: 
                    258: /* Return the sdb tag identifier string for TYPE
                    259:    if TYPE has already been defined; otherwise return a null pointer.   */
                    260: 
1.1.1.6   root      261: #define KNOWN_TYPE_TAG(type)  TYPE_SYMTAB_POINTER (type)
1.1       root      262: 
                    263: /* Set the sdb tag identifier string for TYPE to NAME.  */
                    264: 
                    265: #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
1.1.1.6   root      266:   TYPE_SYMTAB_POINTER (TYPE) = (NAME)
1.1       root      267: 
                    268: /* Return the name (a string) of the struct, union or enum tag
                    269:    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
                    270: 
                    271: #define TAG_NAME(link) \
                    272:   (((link) && TREE_PURPOSE ((link)) \
                    273:     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
                    274:    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
                    275: 
                    276: /* Ensure we don't output a negative line number.  */
                    277: #define MAKE_LINE_SAFE(line)  \
                    278:   if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
                    279: 
                    280: /* Set up for SDB output at the start of compilation.  */
                    281: 
                    282: void
                    283: sdbout_init (asm_file, input_file_name, syms)
                    284:      FILE *asm_file;
                    285:      char *input_file_name;
                    286:      tree syms;
                    287: {
1.1.1.6   root      288: #ifdef RMS_QUICK_HACK_1
                    289:   tree t;
                    290:   for (t = syms; t; t = TREE_CHAIN (t))
                    291:     if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
                    292:        && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
                    293:       sdbout_symbol (t, 0);
                    294: #endif  
                    295: 
1.1       root      296: #if 0 /* Nothing need be output for the predefined types.  */
                    297:   /* Get all permanent types that have typedef names,
                    298:      and output them all, except for those already output.  */
                    299: 
                    300:   sdbout_typedefs (syms);
                    301: #endif
                    302: }
                    303: 
                    304: #if 0
                    305: 
                    306: /* return the tag identifier for type
                    307:  */
                    308: 
                    309: char *
                    310: tag_of_ru_type (type,link)
                    311:      tree type,link;
                    312: {
                    313:   if (TYPE_SYMTAB_ADDRESS (type))
1.1.1.6   root      314:     return TYPE_SYMTAB_ADDRESS (type);
1.1       root      315:   if (link && TREE_PURPOSE (link)
                    316:       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
1.1.1.6   root      317:     TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
1.1       root      318:   else
                    319:     return (char *) TYPE_SYMTAB_ADDRESS (type);
                    320: }
                    321: #endif
                    322: 
                    323: /* Return a unique string to name an anonymous type.  */
                    324: 
                    325: static char *
                    326: gen_fake_label ()
                    327: {
                    328:   char label[10];
                    329:   char *labelstr;
                    330:   SDB_GENERATE_FAKE (label, unnamed_struct_number);
                    331:   unnamed_struct_number++;
                    332:   labelstr = (char *) permalloc (strlen (label) + 1);
                    333:   strcpy (labelstr, label);
                    334:   return labelstr;
                    335: }
                    336: 
                    337: /* Return the number which describes TYPE for SDB.
                    338:    For pointers, etc., this function is recursive.
                    339:    Each record, union or enumeral type must already have had a
                    340:    tag number output.  */
                    341: 
                    342: /* The number is given by d6d5d4d3d2d1bbbb
                    343:    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
                    344:    Thus, char *foo () has bbbb=T_CHAR
                    345:                          d1=D_FCN
                    346:                          d2=D_PTR
                    347:  N_BTMASK=     017       1111     basic type field.
                    348:  N_TSHIFT=       2                derived type shift
                    349:  N_BTSHFT=       4                Basic type shift */
                    350: 
                    351: /* Produce the number that describes a pointer, function or array type.
                    352:    PREV is the number describing the target, value or element type.
                    353:    DT_type describes how to transform that type.  */
1.1.1.5   root      354: #define PUSH_DERIVED_LEVEL(DT_type,PREV)               \
                    355:   ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT)                \
                    356:    | ((int)DT_type << (int)N_BTSHFT)                   \
                    357:    | ((PREV) & (int)N_BTMASK))
1.1       root      358: 
                    359: /* Number of elements used in sdb_dims.  */
                    360: static int sdb_n_dims = 0;
                    361: 
                    362: /* Table of array dimensions of current type.  */
                    363: static int sdb_dims[SDB_MAX_DIM];
                    364: 
                    365: /* Size of outermost array currently being processed.  */
                    366: static int sdb_type_size = -1;
                    367: 
                    368: static int
                    369: plain_type (type)
                    370:      tree type;
                    371: {
                    372:   int val = plain_type_1 (type);
                    373: 
                    374:   /* If we have already saved up some array dimensions, print them now.  */
                    375:   if (sdb_n_dims > 0)
                    376:     {
                    377:       int i;
                    378:       PUT_SDB_START_DIM;
                    379:       for (i = sdb_n_dims - 1; i > 0; i--)
                    380:        PUT_SDB_NEXT_DIM (sdb_dims[i]);
                    381:       PUT_SDB_LAST_DIM (sdb_dims[0]);
                    382:       sdb_n_dims = 0;
                    383: 
                    384:       sdb_type_size = int_size_in_bytes (type);
                    385:       /* Don't kill sdb if type is not laid out or has variable size.  */
                    386:       if (sdb_type_size < 0)
                    387:        sdb_type_size = 0;
                    388:     }
                    389:   /* If we have computed the size of an array containing this type,
                    390:      print it now.  */
                    391:   if (sdb_type_size >= 0)
                    392:     {
                    393:       PUT_SDB_SIZE (sdb_type_size);
                    394:       sdb_type_size = -1;
                    395:     }
                    396:   return val;
                    397: }
                    398: 
1.1.1.4   root      399: static int
                    400: template_name_p (name)
                    401:      tree name;
                    402: {
                    403:   register char *ptr = IDENTIFIER_POINTER (name);
                    404:   while (*ptr && *ptr != '<')
                    405:     ptr++;
                    406: 
                    407:   return *ptr != '\0';
                    408: }
                    409: 
1.1       root      410: static void
                    411: sdbout_record_type_name (type)
                    412:      tree type;
                    413: {
                    414:   char *name = 0;
                    415:   int no_name;
                    416: 
                    417:   if (KNOWN_TYPE_TAG (type))
                    418:     return;
                    419: 
                    420:   if (TYPE_NAME (type) != 0)
                    421:     {
                    422:       tree t = 0;
                    423:       /* Find the IDENTIFIER_NODE for the type name.  */
                    424:       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
                    425:        {
                    426:          t = TYPE_NAME (type);
                    427:        }
1.1.1.5   root      428: #if 1  /* As a temporary hack, use typedef names for C++ only.  */
1.1       root      429:       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
                    430:               && TYPE_LANG_SPECIFIC (type))
                    431:        {
                    432:          t = DECL_NAME (TYPE_NAME (type));
1.1.1.4   root      433:          /* The DECL_NAME for templates includes "<>", which breaks
                    434:             most assemblers.  Use its assembler name instead, which
                    435:             has been mangled into being safe.  */
                    436:          if (t && template_name_p (t))
                    437:            t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1.1       root      438:        }
                    439: #endif
                    440: 
                    441:       /* Now get the name as a string, or invent one.  */
1.1.1.4   root      442:       if (t != NULL_TREE)
1.1       root      443:        name = IDENTIFIER_POINTER (t);
                    444:     }
                    445: 
                    446:   no_name = (name == 0 || *name == 0);
                    447:   if (no_name)
                    448:     name = gen_fake_label ();
                    449: 
                    450:   SET_KNOWN_TYPE_TAG (type, name);
                    451: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    452:   if (no_name)
                    453:     sdbout_queue_anonymous_type (type);
                    454: #endif
                    455: }
                    456: 
                    457: static int
                    458: plain_type_1 (type)
                    459:      tree type;
                    460: {
                    461:   if (type == 0)
                    462:     type = void_type_node;
                    463:   if (type == error_mark_node)
                    464:     type = integer_type_node;
                    465:   type = TYPE_MAIN_VARIANT (type);
                    466: 
                    467:   switch (TREE_CODE (type))
                    468:     {
                    469:     case VOID_TYPE:
                    470:       return T_VOID;
                    471:     case INTEGER_TYPE:
                    472:       {
                    473:        int size = int_size_in_bytes (type) * BITS_PER_UNIT;
1.1.1.5   root      474: 
                    475:        /* Carefully distinguish all the standard types of C,
                    476:           without messing up if the language is not C.
                    477:           Note that we check only for the names that contain spaces;
                    478:           other names might occur by coincidence in other languages.  */
                    479:        if (TYPE_NAME (type) != 0
                    480:            && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
                    481:            && DECL_NAME (TYPE_NAME (type)) != 0
                    482:            && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
                    483:          {
                    484:            char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
                    485: 
                    486:            if (!strcmp (name, "unsigned char"))
                    487:              return T_UCHAR;
                    488:            if (!strcmp (name, "signed char"))
                    489:              return T_CHAR;
                    490:            if (!strcmp (name, "unsigned int"))
                    491:              return T_UINT;
                    492:            if (!strcmp (name, "short int"))
                    493:              return T_SHORT;
                    494:            if (!strcmp (name, "short unsigned int"))
                    495:              return T_USHORT;
                    496:            if (!strcmp (name, "long int"))
                    497:              return T_LONG;
                    498:            if (!strcmp (name, "long unsigned int"))
                    499:              return T_ULONG;
                    500:          }
                    501: 
1.1       root      502:        if (size == CHAR_TYPE_SIZE)
                    503:          return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
                    504:        if (size == SHORT_TYPE_SIZE)
                    505:          return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
                    506:        if (size == INT_TYPE_SIZE)
                    507:          return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
1.1.1.4   root      508:        if (size == LONG_TYPE_SIZE)
                    509:          return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
1.1       root      510:        return 0;
                    511:       }
                    512: 
                    513:     case REAL_TYPE:
                    514:       {
                    515:        int size = int_size_in_bytes (type) * BITS_PER_UNIT;
                    516:        if (size == FLOAT_TYPE_SIZE)
                    517:          return T_FLOAT;
                    518:        if (size == DOUBLE_TYPE_SIZE)
                    519:          return T_DOUBLE;
                    520:        return 0;
                    521:       }
                    522: 
                    523:     case ARRAY_TYPE:
                    524:       {
                    525:        int m;
                    526:        m = plain_type_1 (TREE_TYPE (type));
                    527:        if (sdb_n_dims < SDB_MAX_DIM)
                    528:          sdb_dims[sdb_n_dims++]
                    529:            = (TYPE_DOMAIN (type)
                    530:               ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
                    531:               : 0);
                    532:        return PUSH_DERIVED_LEVEL (DT_ARY, m);
                    533:       }
                    534: 
                    535:     case RECORD_TYPE:
                    536:     case UNION_TYPE:
1.1.1.5   root      537:     case QUAL_UNION_TYPE:
1.1       root      538:     case ENUMERAL_TYPE:
                    539:       {
                    540:        char *tag;
                    541: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    542:        sdbout_record_type_name (type);
                    543: #endif
                    544: #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
                    545:        if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
                    546: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    547:            || TYPE_MODE (type) != VOIDmode
                    548: #endif
                    549:            )
                    550: #endif
                    551:          {
                    552:            /* Output the referenced structure tag name
                    553:               only if the .def has already been finished.
                    554:               At least on 386, the Unix assembler
                    555:               cannot handle forward references to tags.  */
                    556:            /* But the 88100, it requires them, sigh... */
                    557:            /* And the MIPS requires unknown refs as well... */
                    558:            tag = KNOWN_TYPE_TAG (type);
                    559:            PUT_SDB_TAG (tag);
                    560:            /* These 3 lines used to follow the close brace.
                    561:               However, a size of 0 without a tag implies a tag of 0,
                    562:               so if we don't know a tag, we can't mention the size.  */
                    563:            sdb_type_size = int_size_in_bytes (type);
                    564:            if (sdb_type_size < 0)
                    565:              sdb_type_size = 0;
                    566:          }
                    567:        return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
                    568:                : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
1.1.1.5   root      569:                : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
1.1       root      570:                : T_ENUM);
                    571:       }
                    572:     case POINTER_TYPE:
                    573:     case REFERENCE_TYPE:
                    574:       {
                    575:        int m = plain_type_1 (TREE_TYPE (type));
                    576:        return PUSH_DERIVED_LEVEL (DT_PTR, m);
                    577:       }
                    578:     case FUNCTION_TYPE:
                    579:     case METHOD_TYPE:
                    580:       {
                    581:        int m = plain_type_1 (TREE_TYPE (type));
                    582:        return PUSH_DERIVED_LEVEL (DT_FCN, m);
                    583:       }
                    584:     default:
                    585:       return 0;
                    586:     }
                    587: }
                    588: 
                    589: /* Output the symbols defined in block number DO_BLOCK.
                    590:    Set NEXT_BLOCK_NUMBER to 0 before calling.
                    591: 
                    592:    This function works by walking the tree structure of blocks,
                    593:    counting blocks until it finds the desired block.  */
                    594: 
                    595: static int do_block = 0;
                    596: 
                    597: static int next_block_number;
                    598: 
                    599: static void
                    600: sdbout_block (block)
                    601:      register tree block;
                    602: {
                    603:   while (block)
                    604:     {
                    605:       /* Ignore blocks never expanded or otherwise marked as real.  */
                    606:       if (TREE_USED (block))
                    607:        {
                    608:          /* When we reach the specified block, output its symbols.  */
                    609:          if (next_block_number == do_block)
                    610:            {
                    611:              sdbout_syms (BLOCK_VARS (block));
                    612:            }
                    613: 
                    614:          /* If we are past the specified block, stop the scan.  */
                    615:          if (next_block_number > do_block)
                    616:            return;
                    617: 
                    618:          next_block_number++;
                    619: 
                    620:          /* Scan the blocks within this block.  */
                    621:          sdbout_block (BLOCK_SUBBLOCKS (block));
                    622:        }
                    623: 
                    624:       block = BLOCK_CHAIN (block);
                    625:     }
                    626: }
                    627: 
                    628: /* Call sdbout_symbol on each decl in the chain SYMS.  */
                    629: 
                    630: static void
                    631: sdbout_syms (syms)
                    632:      tree syms;
                    633: {
                    634:   while (syms)
                    635:     {
                    636:       if (TREE_CODE (syms) != LABEL_DECL)
                    637:        sdbout_symbol (syms, 1);
                    638:       syms = TREE_CHAIN (syms);
                    639:     }
                    640: }
                    641: 
                    642: /* Output SDB information for a symbol described by DECL.
                    643:    LOCAL is nonzero if the symbol is not file-scope.  */
                    644: 
                    645: void
                    646: sdbout_symbol (decl, local)
                    647:      tree decl;
                    648:      int local;
                    649: {
                    650:   tree type = TREE_TYPE (decl);
                    651:   tree context = NULL_TREE;
                    652:   rtx value;
                    653:   int regno = -1;
                    654:   char *name;
                    655: 
                    656:   sdbout_one_type (type);
                    657: 
1.1.1.3   root      658: #if 0 /* This loses when functions are marked to be ignored,
                    659:         which happens in the C++ front end.  */
                    660:   if (DECL_IGNORED_P (decl))
                    661:     return;
                    662: #endif
                    663: 
1.1       root      664:   switch (TREE_CODE (decl))
                    665:     {
                    666:     case CONST_DECL:
                    667:       /* Enum values are defined by defining the enum type.  */
                    668:       return;
                    669: 
                    670:     case FUNCTION_DECL:
                    671:       /* Don't mention a nested function under its parent.  */
                    672:       context = decl_function_context (decl);
                    673:       if (context == current_function_decl)
                    674:        return;
1.1.1.4   root      675:       if (DECL_EXTERNAL (decl))
1.1       root      676:        return;
                    677:       if (GET_CODE (DECL_RTL (decl)) != MEM
                    678:          || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
                    679:        return;
                    680:       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
                    681:       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
                    682:       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
                    683:       break;
                    684: 
                    685:     case TYPE_DECL:
                    686:       /* Done with tagged types.  */
                    687:       if (DECL_NAME (decl) == 0)
                    688:        return;
1.1.1.3   root      689:       if (DECL_IGNORED_P (decl))
                    690:        return;
1.1       root      691: 
                    692:       /* Output typedef name.  */
1.1.1.4   root      693:       if (template_name_p (DECL_NAME (decl)))
                    694:        PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
                    695:       else
                    696:        PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1       root      697:       PUT_SDB_SCL (C_TPDEF);
                    698:       break;
                    699: 
                    700:     case PARM_DECL:
                    701:       /* Parm decls go in their own separate chains
                    702:         and are output by sdbout_reg_parms and sdbout_parms.  */
                    703:       abort ();
                    704: 
                    705:     case VAR_DECL:
                    706:       /* Don't mention a variable that is external.
                    707:         Let the file that defines it describe it.  */
1.1.1.4   root      708:       if (DECL_EXTERNAL (decl))
1.1       root      709:        return;
                    710: 
1.1.1.3   root      711:       /* Ignore __FUNCTION__, etc.  */
                    712:       if (DECL_IGNORED_P (decl))
                    713:        return;
                    714: 
1.1       root      715:       /* If there was an error in the declaration, don't dump core
                    716:         if there is no RTL associated with the variable doesn't
                    717:         exist.  */
                    718:       if (DECL_RTL (decl) == 0)
                    719:        return;
                    720: 
1.1.1.4   root      721:       DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
                    722: #ifdef LEAF_REG_REMAP
                    723:       if (leaf_function)
                    724:        leaf_renumber_regs_insn (DECL_RTL (decl));
                    725: #endif
                    726:       value = DECL_RTL (decl);
1.1       root      727: 
                    728:       /* Don't mention a variable at all
                    729:         if it was completely optimized into nothingness.
                    730: 
                    731:         If DECL was from an inline function, then its rtl
                    732:         is not identically the rtl that was used in this
                    733:         particular compilation.  */
                    734:       if (GET_CODE (value) == REG)
                    735:        {
                    736:          regno = REGNO (DECL_RTL (decl));
                    737:          if (regno >= FIRST_PSEUDO_REGISTER)
                    738:            return;
                    739:        }
1.1.1.4   root      740:       else if (GET_CODE (value) == SUBREG)
1.1       root      741:        {
                    742:          int offset = 0;
                    743:          while (GET_CODE (value) == SUBREG)
                    744:            {
                    745:              offset += SUBREG_WORD (value);
                    746:              value = SUBREG_REG (value);
                    747:            }
                    748:          if (GET_CODE (value) == REG)
                    749:            {
                    750:              regno = REGNO (value);
                    751:              if (regno >= FIRST_PSEUDO_REGISTER)
1.1.1.4   root      752:                return;
                    753:              regno += offset;
1.1       root      754:            }
1.1.1.4   root      755:          alter_subreg (DECL_RTL (decl));
                    756:          value = DECL_RTL (decl);
1.1       root      757:        }
1.1.1.6   root      758:       /* Don't output anything if an auto variable
                    759:         gets RTL that is static.
                    760:         GAS version 2.2 can't handle such output.  */
                    761:       else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
                    762:               && ! TREE_STATIC (decl))
                    763:        return;
1.1       root      764: 
                    765:       /* Emit any structure, union, or enum type that has not been output.
                    766:         This occurs for tag-less structs (et al) used to declare variables
                    767:         within functions.  */
                    768:       if (TREE_CODE (type) == ENUMERAL_TYPE
                    769:          || TREE_CODE (type) == RECORD_TYPE
1.1.1.5   root      770:          || TREE_CODE (type) == UNION_TYPE
                    771:          || TREE_CODE (type) == QUAL_UNION_TYPE)
1.1       root      772:        {
                    773:          if (TYPE_SIZE (type) != 0             /* not a forward reference */
                    774:              && KNOWN_TYPE_TAG (type) == 0)    /* not yet declared */
                    775:            sdbout_one_type (type);
                    776:        }
                    777: 
                    778:       /* Defer SDB information for top-level initialized variables! */
                    779:       if (! local
                    780:          && GET_CODE (value) == MEM
                    781:          && DECL_INITIAL (decl))
                    782:        return;
                    783: 
1.1.1.4   root      784:       /* C++ in 2.3 makes nameless symbols.  That will be fixed later.
                    785:         For now, avoid crashing.  */
                    786:       if (DECL_NAME (decl) == NULL_TREE)
                    787:        return;
                    788: 
1.1       root      789:       /* Record the name for, starting a symtab entry.  */
1.1.1.7 ! root      790:       if (DECL_LANG_SPECIFIC (decl))
        !           791:        name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
        !           792:       else
        !           793:        name = IDENTIFIER_POINTER (DECL_NAME (decl));
1.1       root      794: 
                    795:       if (GET_CODE (value) == MEM
                    796:          && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
                    797:        {
                    798:          PUT_SDB_DEF (name);
                    799:          if (TREE_PUBLIC (decl))
                    800:            {
                    801:              PUT_SDB_VAL (XEXP (value, 0));
                    802:               PUT_SDB_SCL (C_EXT);
                    803:            }
                    804:          else
                    805:            {
                    806:              PUT_SDB_VAL (XEXP (value, 0));
                    807:               PUT_SDB_SCL (C_STAT);
                    808:            }
                    809:        }
                    810:       else if (regno >= 0)
                    811:        {
                    812:          PUT_SDB_DEF (name);
                    813:          PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
                    814:          PUT_SDB_SCL (C_REG);
                    815:        }
                    816:       else if (GET_CODE (value) == MEM
                    817:               && (GET_CODE (XEXP (value, 0)) == MEM
                    818:                   || (GET_CODE (XEXP (value, 0)) == REG
1.1.1.6   root      819:                       && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
1.1       root      820:                       && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
                    821:        /* If the value is indirect by memory or by a register
                    822:           that isn't the frame pointer
                    823:           then it means the object is variable-sized and address through
                    824:           that register or stack slot.  COFF has no way to represent this
                    825:           so all we can do is output the variable as a pointer.  */
                    826:        {
                    827:          PUT_SDB_DEF (name);
                    828:          if (GET_CODE (XEXP (value, 0)) == REG)
                    829:            {
                    830:              PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
                    831:              PUT_SDB_SCL (C_REG);
                    832:            }
                    833:          else
                    834:            {
                    835:              /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
                    836:                 (CONST_INT...)))).
                    837:                 We want the value of that CONST_INT.  */
                    838:              /* Encore compiler hates a newline in a macro arg, it seems.  */
                    839:              PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
                    840:                               (XEXP (XEXP (value, 0), 0)));
                    841:              PUT_SDB_SCL (C_AUTO);
                    842:            }
                    843: 
                    844:          type = build_pointer_type (TREE_TYPE (decl));
                    845:        }
                    846:       else if (GET_CODE (value) == MEM
1.1.1.7 ! root      847:               && ((GET_CODE (XEXP (value, 0)) == PLUS
        !           848:                    && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
        !           849:                    && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
        !           850:                   /* This is for variables which are at offset zero from
        !           851:                      the frame pointer.  This happens on the Alpha.
        !           852:                      Non-frame pointer registers are excluded above.  */
        !           853:                   || (GET_CODE (XEXP (value, 0)) == REG)))
1.1       root      854:        {
1.1.1.7 ! root      855:          /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
        !           856:             or (MEM (REG...)).  We want the value of that CONST_INT
        !           857:             or zero.  */
1.1       root      858:          PUT_SDB_DEF (name);
                    859:          PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
                    860:          PUT_SDB_SCL (C_AUTO);
                    861:        }
1.1.1.2   root      862:       else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
                    863:        {
                    864:          /* Handle an obscure case which can arise when optimizing and
                    865:             when there are few available registers.  (This is *always*
                    866:             the case for i386/i486 targets).  The DECL_RTL looks like
                    867:             (MEM (CONST ...)) even though this variable is a local `auto'
                    868:             or a local `register' variable.  In effect, what has happened
                    869:             is that the reload pass has seen that all assignments and
                    870:             references for one such a local variable can be replaced by
                    871:             equivalent assignments and references to some static storage
                    872:             variable, thereby avoiding the need for a register.  In such
                    873:             cases we're forced to lie to debuggers and tell them that
                    874:             this variable was itself `static'.  */
                    875:          PUT_SDB_DEF (name);
                    876:          PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
                    877:          PUT_SDB_SCL (C_STAT);
                    878:        }
1.1       root      879:       else
                    880:        {
                    881:          /* It is something we don't know how to represent for SDB.  */
                    882:          return;
                    883:        }
                    884:       break;
                    885:     }
                    886:   PUT_SDB_TYPE (plain_type (type));
                    887:   PUT_SDB_ENDEF;
                    888: }
                    889: 
                    890: /* Output SDB information for a top-level initialized variable
                    891:    that has been delayed.  */
                    892: 
                    893: void
                    894: sdbout_toplevel_data (decl)
                    895:      tree decl;
                    896: {
                    897:   tree type = TREE_TYPE (decl);
                    898: 
1.1.1.3   root      899:   if (DECL_IGNORED_P (decl))
                    900:     return;
                    901: 
1.1       root      902:   if (! (TREE_CODE (decl) == VAR_DECL
                    903:         && GET_CODE (DECL_RTL (decl)) == MEM
                    904:         && DECL_INITIAL (decl)))
                    905:     abort ();
                    906: 
                    907:   PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
                    908:   PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
                    909:   if (TREE_PUBLIC (decl))
                    910:     {
                    911:       PUT_SDB_SCL (C_EXT);
                    912:     }
                    913:   else
                    914:     {
                    915:       PUT_SDB_SCL (C_STAT);
                    916:     }
                    917:   PUT_SDB_TYPE (plain_type (type));
                    918:   PUT_SDB_ENDEF;
                    919: }
                    920: 
                    921: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    922: 
                    923: /* Machinery to record and output anonymous types. */
                    924: 
                    925: static tree anonymous_types;
                    926: 
                    927: static void
                    928: sdbout_queue_anonymous_type (type)
                    929:      tree type;
                    930: {
                    931:   anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
                    932: }
                    933: 
                    934: static void
                    935: sdbout_dequeue_anonymous_types ()
                    936: {
                    937:   register tree types, link;
                    938: 
                    939:   while (anonymous_types)
                    940:     {
                    941:       types = nreverse (anonymous_types);
                    942:       anonymous_types = NULL_TREE;
                    943: 
                    944:       for (link = types; link; link = TREE_CHAIN (link))
                    945:        {
                    946:          register tree type = TREE_VALUE (link);
                    947: 
1.1.1.2   root      948:          if (type && ! TREE_ASM_WRITTEN (type))
1.1       root      949:            sdbout_one_type (type);
                    950:        }
                    951:     }
                    952: }
                    953: 
                    954: #endif
                    955: 
                    956: /* Given a chain of ..._TYPE nodes, all of which have names,
                    957:    output definitions of those names, as typedefs.  */
                    958: 
                    959: void
                    960: sdbout_types (types)
                    961:      register tree types;
                    962: {
                    963:   register tree link;
                    964: 
                    965:   for (link = types; link; link = TREE_CHAIN (link))
                    966:     sdbout_one_type (link);
                    967: 
                    968: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    969:   sdbout_dequeue_anonymous_types ();
                    970: #endif
                    971: }
                    972: 
                    973: static void
                    974: sdbout_type (type)
                    975:      tree type;
                    976: {
                    977:   if (type == error_mark_node)
                    978:     type = integer_type_node;
                    979:   PUT_SDB_TYPE (plain_type (type));
                    980: }
                    981: 
                    982: /* Output types of the fields of type TYPE, if they are structs.
                    983: 
                    984:    Formerly did not chase through pointer types, since that could be circular.
                    985:    They must come before TYPE, since forward refs are not allowed.
                    986:    Now [email protected] says to try them.  */
                    987: 
                    988: static void
                    989: sdbout_field_types (type)
                    990:      tree type;
                    991: {
                    992:   tree tail;
                    993:   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
                    994:     if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
                    995:       sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
                    996:     else
                    997:       sdbout_one_type (TREE_TYPE (tail));
                    998: }
                    999: 
                   1000: /* Use this to put out the top level defined record and union types
                   1001:    for later reference.  If this is a struct with a name, then put that
                   1002:    name out.  Other unnamed structs will have .xxfake labels generated so
                   1003:    that they may be referred to later.
                   1004:    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
                   1005:    It may NOT be called recursively.  */
                   1006: 
                   1007: static void
                   1008: sdbout_one_type (type)
                   1009:      tree type;
                   1010: {
                   1011:   text_section ();
                   1012: 
                   1013:   switch (TREE_CODE (type))
                   1014:     {
                   1015:     case RECORD_TYPE:
                   1016:     case UNION_TYPE:
1.1.1.5   root     1017:     case QUAL_UNION_TYPE:
1.1       root     1018:     case ENUMERAL_TYPE:
                   1019:       type = TYPE_MAIN_VARIANT (type);
                   1020:       /* Don't output a type twice.  */
                   1021:       if (TREE_ASM_WRITTEN (type))
                   1022:        /* James said test TREE_ASM_BEING_WRITTEN here.  */
                   1023:        return;
                   1024: 
                   1025:       /* Output nothing if type is not yet defined.  */
                   1026:       if (TYPE_SIZE (type) == 0)
                   1027:        return;
                   1028: 
                   1029:       TREE_ASM_WRITTEN (type) = 1;
                   1030: #if 1
                   1031:       /* This is reputed to cause trouble with the following case,
1.1.1.4   root     1032:         but perhaps checking TYPE_SIZE above will fix it.  */
1.1       root     1033: 
                   1034:       /* Here is a test case:
                   1035: 
                   1036:        struct foo {
                   1037:          struct badstr *bbb;
                   1038:        } forwardref;
                   1039: 
                   1040:        typedef struct intermediate {
                   1041:          int aaaa;
                   1042:        } intermediate_ref;
                   1043: 
                   1044:        typedef struct badstr {
                   1045:          int ccccc;
                   1046:        } badtype;   */
                   1047: 
                   1048: #if 0
                   1049:       TREE_ASM_BEING_WRITTEN (type) = 1;
                   1050: #endif
                   1051:       /* This change, which ought to make better output,
                   1052:         used to make the COFF assembler unhappy.
                   1053:         Changes involving KNOWN_TYPE_TAG may fix the problem.  */
                   1054:       /* Before really doing anything, output types we want to refer to.  */
                   1055:       /* Note that in version 1 the following two lines
                   1056:         are not used if forward references are in use.  */
                   1057:       if (TREE_CODE (type) != ENUMERAL_TYPE)
                   1058:        sdbout_field_types (type);
                   1059: #if 0
                   1060:       TREE_ASM_WRITTEN (type) = 1;
                   1061: #endif
                   1062: #endif
                   1063: 
                   1064:       /* Output a structure type.  */
                   1065:       {
                   1066:        int size = int_size_in_bytes (type);
                   1067:        int member_scl;
                   1068:        tree tem;
                   1069:        int i, n_baseclasses = 0;
                   1070: 
                   1071:        /* Record the type tag, but not in its permanent place just yet.  */
                   1072:        sdbout_record_type_name (type);
                   1073: 
                   1074:        PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
                   1075: 
                   1076:        switch (TREE_CODE (type))
                   1077:          {
                   1078:          case UNION_TYPE:
1.1.1.5   root     1079:          case QUAL_UNION_TYPE:
1.1       root     1080:            PUT_SDB_SCL (C_UNTAG);
                   1081:            PUT_SDB_TYPE (T_UNION);
                   1082:            member_scl = C_MOU;
                   1083:            break;
                   1084: 
                   1085:          case RECORD_TYPE:
                   1086:            PUT_SDB_SCL (C_STRTAG);
                   1087:            PUT_SDB_TYPE (T_STRUCT);
                   1088:            member_scl = C_MOS;
                   1089:            break;
                   1090: 
                   1091:          case ENUMERAL_TYPE:
                   1092:            PUT_SDB_SCL (C_ENTAG);
                   1093:            PUT_SDB_TYPE (T_ENUM);
                   1094:            member_scl = C_MOE;
                   1095:            break;
                   1096:          }
                   1097: 
                   1098:        PUT_SDB_SIZE (size);
                   1099:        PUT_SDB_ENDEF;
                   1100: 
                   1101:        /* Print out the base class information with fields
                   1102:           named after the types they hold.  */
                   1103:        if (TYPE_BINFO (type)
                   1104:            && TYPE_BINFO_BASETYPES (type))
                   1105:          n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
                   1106:        for (i = 0; i < n_baseclasses; i++)
                   1107:          {
                   1108:            tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
                   1109:            tree child_type = BINFO_TYPE (child);
                   1110:            tree child_type_name;
                   1111:            if (TYPE_NAME (child_type) == 0)
                   1112:              continue;
                   1113:            if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
                   1114:              child_type_name = TYPE_NAME (child_type);
                   1115:            else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1.1.1.7 ! root     1116:              {
        !          1117:                child_type_name = DECL_NAME (TYPE_NAME (child_type));
        !          1118:                if (child_type_name && template_name_p (child_type_name))
        !          1119:                  child_type_name
        !          1120:                    = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
        !          1121:              }
1.1       root     1122:            else
                   1123:              continue;
                   1124: 
                   1125:            CONTIN;
                   1126:            PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
                   1127:            PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
                   1128:            PUT_SDB_SCL (member_scl);
                   1129:            sdbout_type (BINFO_TYPE (child));
                   1130:            PUT_SDB_ENDEF;
                   1131:          }
                   1132: 
                   1133:        /* output the individual fields */
                   1134: 
                   1135:        if (TREE_CODE (type) == ENUMERAL_TYPE)
                   1136:          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
                   1137:            {
                   1138:              PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
                   1139:              PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
                   1140:              PUT_SDB_SCL (C_MOE);
                   1141:              PUT_SDB_TYPE (T_MOE);
                   1142:              PUT_SDB_ENDEF;
                   1143:            }
                   1144: 
                   1145:        else                    /* record or union type */
                   1146:          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
                   1147:            /* Output the name, type, position (in bits), size (in bits)
                   1148:               of each field.  */
                   1149: 
                   1150:            /* Omit here the nameless fields that are used to skip bits.
                   1151:               Also omit fields with variable size or position.
                   1152:               Also omit non FIELD_DECL nodes that GNU C++ may put here.  */
                   1153:            if (TREE_CODE (tem) == FIELD_DECL
                   1154:                && DECL_NAME (tem) != 0
                   1155:                && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
                   1156:                && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
                   1157:              {
1.1.1.7 ! root     1158:                char *name;
        !          1159: 
1.1       root     1160:                CONTIN;
1.1.1.7 ! root     1161:                if (DECL_LANG_SPECIFIC (tem))
        !          1162:                  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
        !          1163:                else
        !          1164:                  name = IDENTIFIER_POINTER (DECL_NAME (tem));
        !          1165:                PUT_SDB_DEF (name);
1.1       root     1166:                if (DECL_BIT_FIELD_TYPE (tem))
                   1167:                  {
                   1168:                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
                   1169:                    PUT_SDB_SCL (C_FIELD);
                   1170:                    sdbout_type (DECL_BIT_FIELD_TYPE (tem));
                   1171:                    PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
                   1172:                  }
                   1173:                else
                   1174:                  {
                   1175:                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
                   1176:                                     / BITS_PER_UNIT);
                   1177:                    PUT_SDB_SCL (member_scl);
                   1178:                    sdbout_type (TREE_TYPE (tem));
                   1179:                  }
                   1180:                PUT_SDB_ENDEF;
                   1181:              }
                   1182:        /* output end of a structure,union, or enumeral definition */
                   1183: 
                   1184:        PUT_SDB_PLAIN_DEF ("eos");
                   1185:        PUT_SDB_INT_VAL (size);
                   1186:        PUT_SDB_SCL (C_EOS);
                   1187:        PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
                   1188:        PUT_SDB_SIZE (size);
                   1189:        PUT_SDB_ENDEF;
                   1190:        break;
                   1191:       }
                   1192:     }
                   1193: }
                   1194: 
                   1195: /* The following two functions output definitions of function parameters.
                   1196:    Each parameter gets a definition locating it in the parameter list.
                   1197:    Each parameter that is a register variable gets a second definition
                   1198:    locating it in the register.
                   1199: 
                   1200:    Printing or argument lists in gdb uses the definitions that
                   1201:    locate in the parameter list.  But reference to the variable in
                   1202:    expressions uses preferentially the definition as a register.  */
                   1203: 
                   1204: /* Output definitions, referring to storage in the parmlist,
                   1205:    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
                   1206: 
                   1207: static void
                   1208: sdbout_parms (parms)
                   1209:      tree parms;
                   1210: {
                   1211:   for (; parms; parms = TREE_CHAIN (parms))
                   1212:     if (DECL_NAME (parms))
                   1213:       {
                   1214:        int current_sym_value = 0;
                   1215:        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
                   1216: 
                   1217:        if (name == 0 || *name == 0)
                   1218:          name = gen_fake_label ();
                   1219: 
                   1220:        /* Perform any necessary register eliminations on the parameter's rtl,
                   1221:           so that the debugging output will be accurate.  */
                   1222:        DECL_INCOMING_RTL (parms) =
1.1.1.4   root     1223:          eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
                   1224:        DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1.1       root     1225: 
                   1226:        if (PARM_PASSED_IN_MEMORY (parms))
                   1227:          {
                   1228:            rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
                   1229:            tree type;
                   1230: 
                   1231:            /* ??? Here we assume that the parm address is indexed
                   1232:               off the frame pointer or arg pointer.
                   1233:               If that is not true, we produce meaningless results,
                   1234:               but do not crash.  */
                   1235:            if (GET_CODE (addr) == PLUS
                   1236:                && GET_CODE (XEXP (addr, 1)) == CONST_INT)
                   1237:              current_sym_value = INTVAL (XEXP (addr, 1));
                   1238:            else
                   1239:              current_sym_value = 0;
                   1240: 
                   1241:            if (GET_CODE (DECL_RTL (parms)) == REG
                   1242:                && REGNO (DECL_RTL (parms)) >= 0
                   1243:                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
                   1244:              type = DECL_ARG_TYPE (parms);
                   1245:            else
                   1246:              {
                   1247:                int original_sym_value = current_sym_value;
                   1248: 
                   1249:                /* This is the case where the parm is passed as an int or
                   1250:                   double and it is converted to a char, short or float
                   1251:                   and stored back in the parmlist.  In this case, describe
                   1252:                   the parm with the variable's declared type, and adjust
                   1253:                   the address if the least significant bytes (which we are
                   1254:                   using) are not the first ones.  */
                   1255: #if BYTES_BIG_ENDIAN
                   1256:                if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
                   1257:                  current_sym_value +=
                   1258:                    (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
                   1259:                     - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
                   1260: #endif
                   1261:                if (GET_CODE (DECL_RTL (parms)) == MEM
                   1262:                    && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
                   1263:                    && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
                   1264:                        == CONST_INT)
                   1265:                    && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
                   1266:                        == current_sym_value))
                   1267:                  type = TREE_TYPE (parms);
                   1268:                else
                   1269:                  {
                   1270:                    current_sym_value = original_sym_value;
                   1271:                    type = DECL_ARG_TYPE (parms);
                   1272:                  }
                   1273:              }
                   1274: 
                   1275:            PUT_SDB_DEF (name);
                   1276:            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
                   1277:            PUT_SDB_SCL (C_ARG);
                   1278:            PUT_SDB_TYPE (plain_type (type));
                   1279:            PUT_SDB_ENDEF;
                   1280:          }
                   1281:        else if (GET_CODE (DECL_RTL (parms)) == REG)
                   1282:          {
                   1283:            rtx best_rtl;
                   1284:            /* Parm passed in registers and lives in registers or nowhere.  */
                   1285: 
                   1286:            /* If parm lives in a register, use that register;
                   1287:               pretend the parm was passed there.  It would be more consistent
                   1288:               to describe the register where the parm was passed,
                   1289:               but in practice that register usually holds something else.  */
                   1290:            if (REGNO (DECL_RTL (parms)) >= 0
                   1291:                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
                   1292:              best_rtl = DECL_RTL (parms);
                   1293:            /* If the parm lives nowhere,
                   1294:               use the register where it was passed.  */
                   1295:            else
                   1296:              best_rtl = DECL_INCOMING_RTL (parms);
                   1297: 
                   1298:            PUT_SDB_DEF (name);
                   1299:            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
                   1300:            PUT_SDB_SCL (C_REGPARM);
                   1301:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1302:            PUT_SDB_ENDEF;
                   1303:          }
                   1304:        else if (GET_CODE (DECL_RTL (parms)) == MEM
                   1305:                 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
                   1306:          {
                   1307:            /* Parm was passed in registers but lives on the stack.  */
                   1308: 
                   1309:            /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
                   1310:               in which case we want the value of that CONST_INT,
                   1311:               or (MEM (REG ...)) or (MEM (MEM ...)),
                   1312:               in which case we use a value of zero.  */
                   1313:            if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
                   1314:                || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
                   1315:              current_sym_value = 0;
                   1316:            else
                   1317:              current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
                   1318: 
                   1319:            /* Again, this assumes the offset is based on the arg pointer.  */
                   1320:            PUT_SDB_DEF (name);
                   1321:            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
                   1322:                                                  XEXP (DECL_RTL (parms), 0)));
                   1323:            PUT_SDB_SCL (C_ARG);
                   1324:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1325:            PUT_SDB_ENDEF;
                   1326:          }
                   1327:       }
                   1328: }
                   1329: 
                   1330: /* Output definitions for the places where parms live during the function,
                   1331:    when different from where they were passed, when the parms were passed
                   1332:    in memory.
                   1333: 
                   1334:    It is not useful to do this for parms passed in registers
                   1335:    that live during the function in different registers, because it is
                   1336:    impossible to look in the passed register for the passed value,
                   1337:    so we use the within-the-function register to begin with.
                   1338: 
                   1339:    PARMS is a chain of PARM_DECL nodes.  */
                   1340: 
                   1341: static void
                   1342: sdbout_reg_parms (parms)
                   1343:      tree parms;
                   1344: {
                   1345:   for (; parms; parms = TREE_CHAIN (parms))
                   1346:     if (DECL_NAME (parms))
                   1347:       {
                   1348:        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
                   1349: 
                   1350:        /* Report parms that live in registers during the function
                   1351:           but were passed in memory.  */
                   1352:        if (GET_CODE (DECL_RTL (parms)) == REG
                   1353:            && REGNO (DECL_RTL (parms)) >= 0
                   1354:            && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
                   1355:            && PARM_PASSED_IN_MEMORY (parms))
                   1356:          {
                   1357:            if (name == 0 || *name == 0)
                   1358:              name = gen_fake_label ();
                   1359:            PUT_SDB_DEF (name);
                   1360:            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
                   1361:            PUT_SDB_SCL (C_REG);
                   1362:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1363:            PUT_SDB_ENDEF;
                   1364:          }
                   1365:        /* Report parms that live in memory but not where they were passed.  */
                   1366:        else if (GET_CODE (DECL_RTL (parms)) == MEM
                   1367:                 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
                   1368:                 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
                   1369:                 && PARM_PASSED_IN_MEMORY (parms)
                   1370:                 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
                   1371:          {
                   1372: #if 0 /* ??? It is not clear yet what should replace this.  */
                   1373:            int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
                   1374:            /* A parm declared char is really passed as an int,
                   1375:               so it occupies the least significant bytes.
                   1376:               On a big-endian machine those are not the low-numbered ones.  */
                   1377: #if BYTES_BIG_ENDIAN
                   1378:            if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
                   1379:              offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
                   1380:                         - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
                   1381: #endif
                   1382:            if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
                   1383: #endif
                   1384:              {
                   1385:                if (name == 0 || *name == 0)
                   1386:                  name = gen_fake_label ();
                   1387:                PUT_SDB_DEF (name);
                   1388:                PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
                   1389:                                 (XEXP (DECL_RTL (parms), 0)));
                   1390:                PUT_SDB_SCL (C_AUTO);
                   1391:                PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
                   1392:                PUT_SDB_ENDEF;
                   1393:              }
                   1394:          }
                   1395:       }
                   1396: }
                   1397: 
                   1398: /* Describe the beginning of an internal block within a function.
                   1399:    Also output descriptions of variables defined in this block.
                   1400: 
                   1401:    N is the number of the block, by order of beginning, counting from 1,
                   1402:    and not counting the outermost (function top-level) block.
                   1403:    The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
                   1404:    if the count starts at 0 for the outermost one.  */
                   1405: 
                   1406: void
                   1407: sdbout_begin_block (file, line, n)
                   1408:      FILE *file;
                   1409:      int line;
                   1410:      int n;
                   1411: {
                   1412:   tree decl = current_function_decl;
                   1413:   MAKE_LINE_SAFE (line);
1.1.1.7 ! root     1414: 
        !          1415:   /* The SCO compiler does not emit a separate block for the function level
        !          1416:      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
        !          1417:      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
        !          1418: #ifndef MIPS_DEBUGGING_INFO
        !          1419:   if (n != 1)
        !          1420: #endif
        !          1421:     PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
        !          1422: 
1.1       root     1423:   if (n == 1)
                   1424:     {
                   1425:       /* Include the outermost BLOCK's variables in block 1.  */
                   1426:       next_block_number = 0;
                   1427:       do_block = 0;
                   1428:       sdbout_block (DECL_INITIAL (decl));
                   1429:     }
                   1430:   /* If -g1, suppress all the internal symbols of functions
                   1431:      except for arguments.  */
                   1432:   if (debug_info_level != DINFO_LEVEL_TERSE)
                   1433:     {
                   1434:       next_block_number = 0;
                   1435:       do_block = n;
                   1436:       sdbout_block (DECL_INITIAL (decl));
                   1437:     }
                   1438: 
                   1439: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                   1440:   sdbout_dequeue_anonymous_types ();
                   1441: #endif
                   1442: }
                   1443: 
                   1444: /* Describe the end line-number of an internal block within a function.  */
                   1445: 
                   1446: void
1.1.1.7 ! root     1447: sdbout_end_block (file, line, n)
1.1       root     1448:      FILE *file;
                   1449:      int line;
1.1.1.7 ! root     1450:      int n;
1.1       root     1451: {
                   1452:   MAKE_LINE_SAFE (line);
1.1.1.7 ! root     1453: 
        !          1454:   /* The SCO compiler does not emit a separate block for the function level
        !          1455:      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
        !          1456:      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
        !          1457: #ifndef MIPS_DEBUGGING_INFO
        !          1458:   if (n != 1)
        !          1459: #endif
1.1       root     1460:   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
                   1461: }
                   1462: 
                   1463: /* Output sdb info for the current function name.
                   1464:    Called from assemble_start_function.  */
                   1465: 
                   1466: void
                   1467: sdbout_mark_begin_function ()
                   1468: {
                   1469:   sdbout_symbol (current_function_decl, 0);
                   1470: }
                   1471: 
                   1472: /* Called at beginning of function body (after prologue).
                   1473:    Record the function's starting line number, so we can output
                   1474:    relative line numbers for the other lines.
                   1475:    Describe beginning of outermost block.
                   1476:    Also describe the parameter list.  */
                   1477: 
                   1478: void
                   1479: sdbout_begin_function (line)
                   1480:      int line;
                   1481: {
                   1482:   sdb_begin_function_line = line - 1;
                   1483:   PUT_SDB_FUNCTION_START (line);
                   1484:   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
                   1485:   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
                   1486: }
                   1487: 
                   1488: /* Called at end of function (before epilogue).
                   1489:    Describe end of outermost block.  */
                   1490: 
                   1491: void
                   1492: sdbout_end_function (line)
                   1493:      int line;
                   1494: {
                   1495: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                   1496:   sdbout_dequeue_anonymous_types ();
                   1497: #endif
                   1498: 
                   1499:   MAKE_LINE_SAFE (line);
                   1500:   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
                   1501: 
                   1502:   /* Indicate we are between functions, for line-number output.  */
                   1503:   sdb_begin_function_line = -1;
                   1504: }
                   1505: 
                   1506: /* Output sdb info for the absolute end of a function.
                   1507:    Called after the epilogue is output.  */
                   1508: 
                   1509: void
                   1510: sdbout_end_epilogue ()
                   1511: {
                   1512:   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
                   1513:   PUT_SDB_EPILOGUE_END (name);
                   1514: }
                   1515: 
                   1516: /* Output sdb info for the given label.  Called only if LABEL_NAME (insn)
                   1517:    is present.  */
                   1518: 
                   1519: void
                   1520: sdbout_label (insn)
                   1521:      register rtx insn;
                   1522: {
                   1523:   PUT_SDB_DEF (LABEL_NAME (insn));
                   1524:   PUT_SDB_VAL (insn);
                   1525:   PUT_SDB_SCL (C_LABEL);
                   1526:   PUT_SDB_TYPE (T_NULL);
                   1527:   PUT_SDB_ENDEF;
                   1528: }
                   1529: 
                   1530: #endif /* SDB_DEBUGGING_INFO */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.