Annotation of gcc/sdbout.c, revision 1.1.1.3

1.1       root        1: /* Output sdb-format symbol table information from GNU compiler.
                      2:    Copyright (C) 1988, 1992 Free Software Foundation, Inc.
                      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.  */
                     56: #if defined(USG) && !defined(MIPS)
                     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: 
                    261: #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
                    262: 
                    263: /* Set the sdb tag identifier string for TYPE to NAME.  */
                    264: 
                    265: #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
                    266:   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
                    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: {
                    288: #if 0 /* Nothing need be output for the predefined types.  */
                    289:   /* Get all permanent types that have typedef names,
                    290:      and output them all, except for those already output.  */
                    291: 
                    292:   sdbout_typedefs (syms);
                    293: #endif
                    294: }
                    295: 
                    296: #if 0
                    297: 
                    298: /* return the tag identifier for type
                    299:  */
                    300: 
                    301: char *
                    302: tag_of_ru_type (type,link)
                    303:      tree type,link;
                    304: {
                    305:   if (TYPE_SYMTAB_ADDRESS (type))
                    306:     return (char *)TYPE_SYMTAB_ADDRESS (type);
                    307:   if (link && TREE_PURPOSE (link)
                    308:       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
                    309:     TYPE_SYMTAB_ADDRESS (type)
                    310:       = (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
                    311:   else
                    312:     return (char *) TYPE_SYMTAB_ADDRESS (type);
                    313: }
                    314: #endif
                    315: 
                    316: /* Return a unique string to name an anonymous type.  */
                    317: 
                    318: static char *
                    319: gen_fake_label ()
                    320: {
                    321:   char label[10];
                    322:   char *labelstr;
                    323:   SDB_GENERATE_FAKE (label, unnamed_struct_number);
                    324:   unnamed_struct_number++;
                    325:   labelstr = (char *) permalloc (strlen (label) + 1);
                    326:   strcpy (labelstr, label);
                    327:   return labelstr;
                    328: }
                    329: 
                    330: /* Return the number which describes TYPE for SDB.
                    331:    For pointers, etc., this function is recursive.
                    332:    Each record, union or enumeral type must already have had a
                    333:    tag number output.  */
                    334: 
                    335: /* The number is given by d6d5d4d3d2d1bbbb
                    336:    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
                    337:    Thus, char *foo () has bbbb=T_CHAR
                    338:                          d1=D_FCN
                    339:                          d2=D_PTR
                    340:  N_BTMASK=     017       1111     basic type field.
                    341:  N_TSHIFT=       2                derived type shift
                    342:  N_BTSHFT=       4                Basic type shift */
                    343: 
                    344: /* Produce the number that describes a pointer, function or array type.
                    345:    PREV is the number describing the target, value or element type.
                    346:    DT_type describes how to transform that type.  */
                    347: #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
                    348:   ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
                    349: 
                    350: /* Number of elements used in sdb_dims.  */
                    351: static int sdb_n_dims = 0;
                    352: 
                    353: /* Table of array dimensions of current type.  */
                    354: static int sdb_dims[SDB_MAX_DIM];
                    355: 
                    356: /* Size of outermost array currently being processed.  */
                    357: static int sdb_type_size = -1;
                    358: 
                    359: static int
                    360: plain_type (type)
                    361:      tree type;
                    362: {
                    363:   int val = plain_type_1 (type);
                    364: 
                    365:   /* If we have already saved up some array dimensions, print them now.  */
                    366:   if (sdb_n_dims > 0)
                    367:     {
                    368:       int i;
                    369:       PUT_SDB_START_DIM;
                    370:       for (i = sdb_n_dims - 1; i > 0; i--)
                    371:        PUT_SDB_NEXT_DIM (sdb_dims[i]);
                    372:       PUT_SDB_LAST_DIM (sdb_dims[0]);
                    373:       sdb_n_dims = 0;
                    374: 
                    375:       sdb_type_size = int_size_in_bytes (type);
                    376:       /* Don't kill sdb if type is not laid out or has variable size.  */
                    377:       if (sdb_type_size < 0)
                    378:        sdb_type_size = 0;
                    379:     }
                    380:   /* If we have computed the size of an array containing this type,
                    381:      print it now.  */
                    382:   if (sdb_type_size >= 0)
                    383:     {
                    384:       PUT_SDB_SIZE (sdb_type_size);
                    385:       sdb_type_size = -1;
                    386:     }
                    387:   return val;
                    388: }
                    389: 
                    390: static void
                    391: sdbout_record_type_name (type)
                    392:      tree type;
                    393: {
                    394:   char *name = 0;
                    395:   int no_name;
                    396: 
                    397:   if (KNOWN_TYPE_TAG (type))
                    398:     return;
                    399: 
                    400:   if (TYPE_NAME (type) != 0)
                    401:     {
                    402:       tree t = 0;
                    403:       /* Find the IDENTIFIER_NODE for the type name.  */
                    404:       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
                    405:        {
                    406:          t = TYPE_NAME (type);
                    407:        }
                    408: #if 1  /* As a temprary hack, use typedef names for C++ only.  */
                    409:       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
                    410:               && TYPE_LANG_SPECIFIC (type))
                    411:        {
                    412:          t = DECL_NAME (TYPE_NAME (type));
                    413:        }
                    414: #endif
                    415: 
                    416:       /* Now get the name as a string, or invent one.  */
                    417:       if (t != 0)
                    418:        name = IDENTIFIER_POINTER (t);
                    419:     }
                    420: 
                    421:   no_name = (name == 0 || *name == 0);
                    422:   if (no_name)
                    423:     name = gen_fake_label ();
                    424: 
                    425:   SET_KNOWN_TYPE_TAG (type, name);
                    426: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    427:   if (no_name)
                    428:     sdbout_queue_anonymous_type (type);
                    429: #endif
                    430: }
                    431: 
                    432: static int
                    433: plain_type_1 (type)
                    434:      tree type;
                    435: {
                    436:   if (type == 0)
                    437:     type = void_type_node;
                    438:   if (type == error_mark_node)
                    439:     type = integer_type_node;
                    440:   type = TYPE_MAIN_VARIANT (type);
                    441: 
                    442:   switch (TREE_CODE (type))
                    443:     {
                    444:     case VOID_TYPE:
                    445:       return T_VOID;
                    446:     case INTEGER_TYPE:
                    447:       {
                    448:        int size = int_size_in_bytes (type) * BITS_PER_UNIT;
                    449:        if (size == CHAR_TYPE_SIZE)
                    450:          return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
                    451:        if (size == SHORT_TYPE_SIZE)
                    452:          return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
                    453:        if (size == INT_TYPE_SIZE)
                    454:          return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
                    455:        return 0;
                    456:       }
                    457: 
                    458:     case REAL_TYPE:
                    459:       {
                    460:        int size = int_size_in_bytes (type) * BITS_PER_UNIT;
                    461:        if (size == FLOAT_TYPE_SIZE)
                    462:          return T_FLOAT;
                    463:        if (size == DOUBLE_TYPE_SIZE)
                    464:          return T_DOUBLE;
                    465:        return 0;
                    466:       }
                    467: 
                    468:     case ARRAY_TYPE:
                    469:       {
                    470:        int m;
                    471:        m = plain_type_1 (TREE_TYPE (type));
                    472:        if (sdb_n_dims < SDB_MAX_DIM)
                    473:          sdb_dims[sdb_n_dims++]
                    474:            = (TYPE_DOMAIN (type)
                    475:               ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
                    476:               : 0);
                    477:        return PUSH_DERIVED_LEVEL (DT_ARY, m);
                    478:       }
                    479: 
                    480:     case RECORD_TYPE:
                    481:     case UNION_TYPE:
                    482:     case ENUMERAL_TYPE:
                    483:       {
                    484:        char *tag;
                    485: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    486:        sdbout_record_type_name (type);
                    487: #endif
                    488: #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
                    489:        if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
                    490: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    491:            || TYPE_MODE (type) != VOIDmode
                    492: #endif
                    493:            )
                    494: #endif
                    495:          {
                    496:            /* Output the referenced structure tag name
                    497:               only if the .def has already been finished.
                    498:               At least on 386, the Unix assembler
                    499:               cannot handle forward references to tags.  */
                    500:            /* But the 88100, it requires them, sigh... */
                    501:            /* And the MIPS requires unknown refs as well... */
                    502:            tag = KNOWN_TYPE_TAG (type);
                    503:            PUT_SDB_TAG (tag);
                    504:            /* These 3 lines used to follow the close brace.
                    505:               However, a size of 0 without a tag implies a tag of 0,
                    506:               so if we don't know a tag, we can't mention the size.  */
                    507:            sdb_type_size = int_size_in_bytes (type);
                    508:            if (sdb_type_size < 0)
                    509:              sdb_type_size = 0;
                    510:          }
                    511:        return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
                    512:                : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
                    513:                : T_ENUM);
                    514:       }
                    515:     case POINTER_TYPE:
                    516:     case REFERENCE_TYPE:
                    517:       {
                    518:        int m = plain_type_1 (TREE_TYPE (type));
                    519:        return PUSH_DERIVED_LEVEL (DT_PTR, m);
                    520:       }
                    521:     case FUNCTION_TYPE:
                    522:     case METHOD_TYPE:
                    523:       {
                    524:        int m = plain_type_1 (TREE_TYPE (type));
                    525:        return PUSH_DERIVED_LEVEL (DT_FCN, m);
                    526:       }
                    527:     default:
                    528:       return 0;
                    529:     }
                    530: }
                    531: 
                    532: /* Output the symbols defined in block number DO_BLOCK.
                    533:    Set NEXT_BLOCK_NUMBER to 0 before calling.
                    534: 
                    535:    This function works by walking the tree structure of blocks,
                    536:    counting blocks until it finds the desired block.  */
                    537: 
                    538: static int do_block = 0;
                    539: 
                    540: static int next_block_number;
                    541: 
                    542: static void
                    543: sdbout_block (block)
                    544:      register tree block;
                    545: {
                    546:   while (block)
                    547:     {
                    548:       /* Ignore blocks never expanded or otherwise marked as real.  */
                    549:       if (TREE_USED (block))
                    550:        {
                    551:          /* When we reach the specified block, output its symbols.  */
                    552:          if (next_block_number == do_block)
                    553:            {
                    554:              sdbout_syms (BLOCK_VARS (block));
                    555:            }
                    556: 
                    557:          /* If we are past the specified block, stop the scan.  */
                    558:          if (next_block_number > do_block)
                    559:            return;
                    560: 
                    561:          next_block_number++;
                    562: 
                    563:          /* Scan the blocks within this block.  */
                    564:          sdbout_block (BLOCK_SUBBLOCKS (block));
                    565:        }
                    566: 
                    567:       block = BLOCK_CHAIN (block);
                    568:     }
                    569: }
                    570: 
                    571: /* Call sdbout_symbol on each decl in the chain SYMS.  */
                    572: 
                    573: static void
                    574: sdbout_syms (syms)
                    575:      tree syms;
                    576: {
                    577:   while (syms)
                    578:     {
                    579:       if (TREE_CODE (syms) != LABEL_DECL)
                    580:        sdbout_symbol (syms, 1);
                    581:       syms = TREE_CHAIN (syms);
                    582:     }
                    583: }
                    584: 
                    585: /* Output SDB information for a symbol described by DECL.
                    586:    LOCAL is nonzero if the symbol is not file-scope.  */
                    587: 
                    588: void
                    589: sdbout_symbol (decl, local)
                    590:      tree decl;
                    591:      int local;
                    592: {
                    593:   int letter = 0;
                    594:   tree type = TREE_TYPE (decl);
                    595:   tree context = NULL_TREE;
                    596:   rtx value;
                    597:   int regno = -1;
                    598:   char *name;
                    599: 
                    600:   sdbout_one_type (type);
                    601: 
1.1.1.3 ! root      602: #if 0 /* This loses when functions are marked to be ignored,
        !           603:         which happens in the C++ front end.  */
        !           604:   if (DECL_IGNORED_P (decl))
        !           605:     return;
        !           606: #endif
        !           607: 
1.1       root      608:   switch (TREE_CODE (decl))
                    609:     {
                    610:     case CONST_DECL:
                    611:       /* Enum values are defined by defining the enum type.  */
                    612:       return;
                    613: 
                    614:     case FUNCTION_DECL:
                    615:       /* Don't mention a nested function under its parent.  */
                    616:       context = decl_function_context (decl);
                    617:       if (context == current_function_decl)
                    618:        return;
                    619:       if (TREE_EXTERNAL (decl))
                    620:        return;
                    621:       if (GET_CODE (DECL_RTL (decl)) != MEM
                    622:          || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
                    623:        return;
                    624:       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
                    625:       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
                    626:       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
                    627:       break;
                    628: 
                    629:     case TYPE_DECL:
                    630:       /* Done with tagged types.  */
                    631:       if (DECL_NAME (decl) == 0)
                    632:        return;
1.1.1.3 ! root      633:       if (DECL_IGNORED_P (decl))
        !           634:        return;
1.1       root      635: 
                    636:       /* Output typedef name.  */
                    637:       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
                    638:       PUT_SDB_SCL (C_TPDEF);
                    639:       break;
                    640: 
                    641:     case PARM_DECL:
                    642:       /* Parm decls go in their own separate chains
                    643:         and are output by sdbout_reg_parms and sdbout_parms.  */
                    644:       abort ();
                    645: 
                    646:     case VAR_DECL:
                    647:       /* Don't mention a variable that is external.
                    648:         Let the file that defines it describe it.  */
                    649:       if (TREE_EXTERNAL (decl))
                    650:        return;
                    651: 
1.1.1.3 ! root      652:       /* Ignore __FUNCTION__, etc.  */
        !           653:       if (DECL_IGNORED_P (decl))
        !           654:        return;
        !           655: 
1.1       root      656:       /* If there was an error in the declaration, don't dump core
                    657:         if there is no RTL associated with the variable doesn't
                    658:         exist.  */
                    659:       if (DECL_RTL (decl) == 0)
                    660:        return;
                    661: 
                    662:       value = eliminate_regs (DECL_RTL (decl), 0, 0);
                    663: 
                    664:       /* Don't mention a variable at all
                    665:         if it was completely optimized into nothingness.
                    666: 
                    667:         If DECL was from an inline function, then its rtl
                    668:         is not identically the rtl that was used in this
                    669:         particular compilation.  */
                    670:       if (GET_CODE (value) == REG)
                    671:        {
                    672:          regno = REGNO (DECL_RTL (decl));
                    673:          if (regno >= FIRST_PSEUDO_REGISTER)
                    674:            regno = reg_renumber[REGNO (DECL_RTL (decl))];
                    675:          if (regno < 0)
                    676:            return;
                    677:        }
                    678:       else if (GET_CODE (DECL_RTL (decl)) == SUBREG)
                    679:        {
                    680:          int offset = 0;
                    681:          while (GET_CODE (value) == SUBREG)
                    682:            {
                    683:              offset += SUBREG_WORD (value);
                    684:              value = SUBREG_REG (value);
                    685:            }
                    686:          if (GET_CODE (value) == REG)
                    687:            {
                    688:              regno = REGNO (value);
                    689:              if (regno >= FIRST_PSEUDO_REGISTER)
                    690:                regno = reg_renumber[REGNO (value)];
                    691:              if (regno >= 0)
                    692:                regno += offset;
                    693:            }
                    694:        }
                    695: 
                    696:       /* Emit any structure, union, or enum type that has not been output.
                    697:         This occurs for tag-less structs (et al) used to declare variables
                    698:         within functions.  */
                    699:       if (TREE_CODE (type) == ENUMERAL_TYPE
                    700:          || TREE_CODE (type) == RECORD_TYPE
                    701:          || TREE_CODE (type) == UNION_TYPE)
                    702:        {
                    703:          if (TYPE_SIZE (type) != 0             /* not a forward reference */
                    704:              && KNOWN_TYPE_TAG (type) == 0)    /* not yet declared */
                    705:            sdbout_one_type (type);
                    706:        }
                    707: 
                    708:       /* Defer SDB information for top-level initialized variables! */
                    709:       if (! local
                    710:          && GET_CODE (value) == MEM
                    711:          && DECL_INITIAL (decl))
                    712:        return;
                    713: 
                    714:       /* Record the name for, starting a symtab entry.  */
                    715:       name = IDENTIFIER_POINTER (DECL_NAME (decl));
                    716: 
                    717:       if (GET_CODE (value) == MEM
                    718:          && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
                    719:        {
                    720:          PUT_SDB_DEF (name);
                    721:          if (TREE_PUBLIC (decl))
                    722:            {
                    723:              PUT_SDB_VAL (XEXP (value, 0));
                    724:               PUT_SDB_SCL (C_EXT);
                    725:            }
                    726:          else
                    727:            {
                    728:              PUT_SDB_VAL (XEXP (value, 0));
                    729:               PUT_SDB_SCL (C_STAT);
                    730:            }
                    731:        }
                    732:       else if (regno >= 0)
                    733:        {
                    734:          PUT_SDB_DEF (name);
                    735:          PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
                    736:          PUT_SDB_SCL (C_REG);
                    737:        }
                    738:       else if (GET_CODE (value) == MEM
                    739:               && (GET_CODE (XEXP (value, 0)) == MEM
                    740:                   || (GET_CODE (XEXP (value, 0)) == REG
                    741:                       && REGNO (XEXP (value, 0)) != FRAME_POINTER_REGNUM
                    742:                       && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
                    743:        /* If the value is indirect by memory or by a register
                    744:           that isn't the frame pointer
                    745:           then it means the object is variable-sized and address through
                    746:           that register or stack slot.  COFF has no way to represent this
                    747:           so all we can do is output the variable as a pointer.  */
                    748:        {
                    749:          PUT_SDB_DEF (name);
                    750:          if (GET_CODE (XEXP (value, 0)) == REG)
                    751:            {
                    752:              PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
                    753:              PUT_SDB_SCL (C_REG);
                    754:            }
                    755:          else
                    756:            {
                    757:              /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
                    758:                 (CONST_INT...)))).
                    759:                 We want the value of that CONST_INT.  */
                    760:              /* Encore compiler hates a newline in a macro arg, it seems.  */
                    761:              PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
                    762:                               (XEXP (XEXP (value, 0), 0)));
                    763:              PUT_SDB_SCL (C_AUTO);
                    764:            }
                    765: 
                    766:          type = build_pointer_type (TREE_TYPE (decl));
                    767:        }
                    768:       else if (GET_CODE (value) == MEM
                    769:               && GET_CODE (XEXP (value, 0)) == PLUS
                    770:               && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
                    771:               && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
                    772:        {
                    773:          /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
                    774:             We want the value of that CONST_INT.  */
                    775:          PUT_SDB_DEF (name);
                    776:          PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
                    777:          PUT_SDB_SCL (C_AUTO);
                    778:        }
1.1.1.2   root      779:       else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
                    780:        {
                    781:          /* Handle an obscure case which can arise when optimizing and
                    782:             when there are few available registers.  (This is *always*
                    783:             the case for i386/i486 targets).  The DECL_RTL looks like
                    784:             (MEM (CONST ...)) even though this variable is a local `auto'
                    785:             or a local `register' variable.  In effect, what has happened
                    786:             is that the reload pass has seen that all assignments and
                    787:             references for one such a local variable can be replaced by
                    788:             equivalent assignments and references to some static storage
                    789:             variable, thereby avoiding the need for a register.  In such
                    790:             cases we're forced to lie to debuggers and tell them that
                    791:             this variable was itself `static'.  */
                    792:          PUT_SDB_DEF (name);
                    793:          PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
                    794:          PUT_SDB_SCL (C_STAT);
                    795:        }
1.1       root      796:       else
                    797:        {
                    798:          /* It is something we don't know how to represent for SDB.  */
                    799:          return;
                    800:        }
                    801:       break;
                    802:     }
                    803:   PUT_SDB_TYPE (plain_type (type));
                    804:   PUT_SDB_ENDEF;
                    805: }
                    806: 
                    807: /* Output SDB information for a top-level initialized variable
                    808:    that has been delayed.  */
                    809: 
                    810: void
                    811: sdbout_toplevel_data (decl)
                    812:      tree decl;
                    813: {
                    814:   tree type = TREE_TYPE (decl);
                    815: 
1.1.1.3 ! root      816:   if (DECL_IGNORED_P (decl))
        !           817:     return;
        !           818: 
1.1       root      819:   if (! (TREE_CODE (decl) == VAR_DECL
                    820:         && GET_CODE (DECL_RTL (decl)) == MEM
                    821:         && DECL_INITIAL (decl)))
                    822:     abort ();
                    823: 
                    824:   PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
                    825:   PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
                    826:   if (TREE_PUBLIC (decl))
                    827:     {
                    828:       PUT_SDB_SCL (C_EXT);
                    829:     }
                    830:   else
                    831:     {
                    832:       PUT_SDB_SCL (C_STAT);
                    833:     }
                    834:   PUT_SDB_TYPE (plain_type (type));
                    835:   PUT_SDB_ENDEF;
                    836: }
                    837: 
                    838: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    839: 
                    840: /* Machinery to record and output anonymous types. */
                    841: 
                    842: static tree anonymous_types;
                    843: 
                    844: static void
                    845: sdbout_queue_anonymous_type (type)
                    846:      tree type;
                    847: {
                    848:   anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
                    849: }
                    850: 
                    851: static void
                    852: sdbout_dequeue_anonymous_types ()
                    853: {
                    854:   register tree types, link;
                    855: 
                    856:   while (anonymous_types)
                    857:     {
                    858:       types = nreverse (anonymous_types);
                    859:       anonymous_types = NULL_TREE;
                    860: 
                    861:       for (link = types; link; link = TREE_CHAIN (link))
                    862:        {
                    863:          register tree type = TREE_VALUE (link);
                    864: 
1.1.1.2   root      865:          if (type && ! TREE_ASM_WRITTEN (type))
1.1       root      866:            sdbout_one_type (type);
                    867:        }
                    868:     }
                    869: }
                    870: 
                    871: #endif
                    872: 
                    873: /* Given a chain of ..._TYPE nodes, all of which have names,
                    874:    output definitions of those names, as typedefs.  */
                    875: 
                    876: void
                    877: sdbout_types (types)
                    878:      register tree types;
                    879: {
                    880:   register tree link;
                    881: 
                    882:   for (link = types; link; link = TREE_CHAIN (link))
                    883:     sdbout_one_type (link);
                    884: 
                    885: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                    886:   sdbout_dequeue_anonymous_types ();
                    887: #endif
                    888: }
                    889: 
                    890: static void
                    891: sdbout_type (type)
                    892:      tree type;
                    893: {
                    894:   register tree tem;
                    895:   if (type == error_mark_node)
                    896:     type = integer_type_node;
                    897:   PUT_SDB_TYPE (plain_type (type));
                    898: }
                    899: 
                    900: /* Output types of the fields of type TYPE, if they are structs.
                    901: 
                    902:    Formerly did not chase through pointer types, since that could be circular.
                    903:    They must come before TYPE, since forward refs are not allowed.
                    904:    Now [email protected] says to try them.  */
                    905: 
                    906: static void
                    907: sdbout_field_types (type)
                    908:      tree type;
                    909: {
                    910:   tree tail;
                    911:   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
                    912:     if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
                    913:       sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
                    914:     else
                    915:       sdbout_one_type (TREE_TYPE (tail));
                    916: }
                    917: 
                    918: /* Use this to put out the top level defined record and union types
                    919:    for later reference.  If this is a struct with a name, then put that
                    920:    name out.  Other unnamed structs will have .xxfake labels generated so
                    921:    that they may be referred to later.
                    922:    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
                    923:    It may NOT be called recursively.  */
                    924: 
                    925: static void
                    926: sdbout_one_type (type)
                    927:      tree type;
                    928: {
                    929:   text_section ();
                    930: 
                    931:   switch (TREE_CODE (type))
                    932:     {
                    933:     case RECORD_TYPE:
                    934:     case UNION_TYPE:
                    935:     case ENUMERAL_TYPE:
                    936:       type = TYPE_MAIN_VARIANT (type);
                    937:       /* Don't output a type twice.  */
                    938:       if (TREE_ASM_WRITTEN (type))
                    939:        /* James said test TREE_ASM_BEING_WRITTEN here.  */
                    940:        return;
                    941: 
                    942:       /* Output nothing if type is not yet defined.  */
                    943:       if (TYPE_SIZE (type) == 0)
                    944:        return;
                    945: 
                    946:       TREE_ASM_WRITTEN (type) = 1;
                    947: #if 1
                    948:       /* This is reputed to cause trouble with the following case,
                    949:         but perhaps checking TYPE_SIZE above will fix it.
                    950: 
                    951:       /* Here is a test case:
                    952: 
                    953:        struct foo {
                    954:          struct badstr *bbb;
                    955:        } forwardref;
                    956: 
                    957:        typedef struct intermediate {
                    958:          int aaaa;
                    959:        } intermediate_ref;
                    960: 
                    961:        typedef struct badstr {
                    962:          int ccccc;
                    963:        } badtype;   */
                    964: 
                    965: #if 0
                    966:       TREE_ASM_BEING_WRITTEN (type) = 1;
                    967: #endif
                    968:       /* This change, which ought to make better output,
                    969:         used to make the COFF assembler unhappy.
                    970:         Changes involving KNOWN_TYPE_TAG may fix the problem.  */
                    971:       /* Before really doing anything, output types we want to refer to.  */
                    972:       /* Note that in version 1 the following two lines
                    973:         are not used if forward references are in use.  */
                    974:       if (TREE_CODE (type) != ENUMERAL_TYPE)
                    975:        sdbout_field_types (type);
                    976: #if 0
                    977:       TREE_ASM_WRITTEN (type) = 1;
                    978: #endif
                    979: #endif
                    980: 
                    981:       /* Output a structure type.  */
                    982:       {
                    983:        int size = int_size_in_bytes (type);
                    984:        int member_scl;
                    985:        tree tem;
                    986:        int i, n_baseclasses = 0;
                    987: 
                    988:        /* Record the type tag, but not in its permanent place just yet.  */
                    989:        sdbout_record_type_name (type);
                    990: 
                    991:        PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
                    992: 
                    993:        switch (TREE_CODE (type))
                    994:          {
                    995:          case UNION_TYPE:
                    996:            PUT_SDB_SCL (C_UNTAG);
                    997:            PUT_SDB_TYPE (T_UNION);
                    998:            member_scl = C_MOU;
                    999:            break;
                   1000: 
                   1001:          case RECORD_TYPE:
                   1002:            PUT_SDB_SCL (C_STRTAG);
                   1003:            PUT_SDB_TYPE (T_STRUCT);
                   1004:            member_scl = C_MOS;
                   1005:            break;
                   1006: 
                   1007:          case ENUMERAL_TYPE:
                   1008:            PUT_SDB_SCL (C_ENTAG);
                   1009:            PUT_SDB_TYPE (T_ENUM);
                   1010:            member_scl = C_MOE;
                   1011:            break;
                   1012:          }
                   1013: 
                   1014:        PUT_SDB_SIZE (size);
                   1015:        PUT_SDB_ENDEF;
                   1016: 
                   1017:        /* Print out the base class information with fields
                   1018:           named after the types they hold.  */
                   1019:        if (TYPE_BINFO (type)
                   1020:            && TYPE_BINFO_BASETYPES (type))
                   1021:          n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
                   1022:        for (i = 0; i < n_baseclasses; i++)
                   1023:          {
                   1024:            tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
                   1025:            tree child_type = BINFO_TYPE (child);
                   1026:            tree child_type_name;
                   1027:            if (TYPE_NAME (child_type) == 0)
                   1028:              continue;
                   1029:            if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
                   1030:              child_type_name = TYPE_NAME (child_type);
                   1031:            else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
                   1032:              child_type_name = DECL_NAME (TYPE_NAME (child_type));
                   1033:            else
                   1034:              continue;
                   1035: 
                   1036:            CONTIN;
                   1037:            PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
                   1038:            PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
                   1039:            PUT_SDB_SCL (member_scl);
                   1040:            sdbout_type (BINFO_TYPE (child));
                   1041:            PUT_SDB_ENDEF;
                   1042:          }
                   1043: 
                   1044:        /* output the individual fields */
                   1045: 
                   1046:        if (TREE_CODE (type) == ENUMERAL_TYPE)
                   1047:          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
                   1048:            {
                   1049:              PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
                   1050:              PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
                   1051:              PUT_SDB_SCL (C_MOE);
                   1052:              PUT_SDB_TYPE (T_MOE);
                   1053:              PUT_SDB_ENDEF;
                   1054:            }
                   1055: 
                   1056:        else                    /* record or union type */
                   1057:          for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
                   1058:            /* Output the name, type, position (in bits), size (in bits)
                   1059:               of each field.  */
                   1060: 
                   1061:            /* Omit here the nameless fields that are used to skip bits.
                   1062:               Also omit fields with variable size or position.
                   1063:               Also omit non FIELD_DECL nodes that GNU C++ may put here.  */
                   1064:            if (TREE_CODE (tem) == FIELD_DECL
                   1065:                && DECL_NAME (tem) != 0
                   1066:                && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
                   1067:                && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
                   1068:              {
                   1069:                CONTIN;
                   1070:                PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
                   1071:                if (DECL_BIT_FIELD_TYPE (tem))
                   1072:                  {
                   1073:                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
                   1074:                    PUT_SDB_SCL (C_FIELD);
                   1075:                    sdbout_type (DECL_BIT_FIELD_TYPE (tem));
                   1076:                    PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
                   1077:                  }
                   1078:                else
                   1079:                  {
                   1080:                    PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
                   1081:                                     / BITS_PER_UNIT);
                   1082:                    PUT_SDB_SCL (member_scl);
                   1083:                    sdbout_type (TREE_TYPE (tem));
                   1084:                  }
                   1085:                PUT_SDB_ENDEF;
                   1086:              }
                   1087:        /* output end of a structure,union, or enumeral definition */
                   1088: 
                   1089:        PUT_SDB_PLAIN_DEF ("eos");
                   1090:        PUT_SDB_INT_VAL (size);
                   1091:        PUT_SDB_SCL (C_EOS);
                   1092:        PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
                   1093:        PUT_SDB_SIZE (size);
                   1094:        PUT_SDB_ENDEF;
                   1095:        break;
                   1096:       }
                   1097:     }
                   1098: }
                   1099: 
                   1100: /* The following two functions output definitions of function parameters.
                   1101:    Each parameter gets a definition locating it in the parameter list.
                   1102:    Each parameter that is a register variable gets a second definition
                   1103:    locating it in the register.
                   1104: 
                   1105:    Printing or argument lists in gdb uses the definitions that
                   1106:    locate in the parameter list.  But reference to the variable in
                   1107:    expressions uses preferentially the definition as a register.  */
                   1108: 
                   1109: /* Output definitions, referring to storage in the parmlist,
                   1110:    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
                   1111: 
                   1112: static void
                   1113: sdbout_parms (parms)
                   1114:      tree parms;
                   1115: {
                   1116:   for (; parms; parms = TREE_CHAIN (parms))
                   1117:     if (DECL_NAME (parms))
                   1118:       {
                   1119:        int current_sym_value = 0;
                   1120:        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
                   1121: 
                   1122:        if (name == 0 || *name == 0)
                   1123:          name = gen_fake_label ();
                   1124: 
                   1125:        /* Perform any necessary register eliminations on the parameter's rtl,
                   1126:           so that the debugging output will be accurate.  */
                   1127:        DECL_INCOMING_RTL (parms) =
                   1128:          eliminate_regs (DECL_INCOMING_RTL (parms), 0, 0);
                   1129:        DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, 0);
                   1130: 
                   1131:        if (PARM_PASSED_IN_MEMORY (parms))
                   1132:          {
                   1133:            rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
                   1134:            tree type;
                   1135: 
                   1136:            /* ??? Here we assume that the parm address is indexed
                   1137:               off the frame pointer or arg pointer.
                   1138:               If that is not true, we produce meaningless results,
                   1139:               but do not crash.  */
                   1140:            if (GET_CODE (addr) == PLUS
                   1141:                && GET_CODE (XEXP (addr, 1)) == CONST_INT)
                   1142:              current_sym_value = INTVAL (XEXP (addr, 1));
                   1143:            else
                   1144:              current_sym_value = 0;
                   1145: 
                   1146:            if (GET_CODE (DECL_RTL (parms)) == REG
                   1147:                && REGNO (DECL_RTL (parms)) >= 0
                   1148:                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
                   1149:              type = DECL_ARG_TYPE (parms);
                   1150:            else
                   1151:              {
                   1152:                int original_sym_value = current_sym_value;
                   1153: 
                   1154:                /* This is the case where the parm is passed as an int or
                   1155:                   double and it is converted to a char, short or float
                   1156:                   and stored back in the parmlist.  In this case, describe
                   1157:                   the parm with the variable's declared type, and adjust
                   1158:                   the address if the least significant bytes (which we are
                   1159:                   using) are not the first ones.  */
                   1160: #if BYTES_BIG_ENDIAN
                   1161:                if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
                   1162:                  current_sym_value +=
                   1163:                    (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
                   1164:                     - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
                   1165: #endif
                   1166:                if (GET_CODE (DECL_RTL (parms)) == MEM
                   1167:                    && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
                   1168:                    && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
                   1169:                        == CONST_INT)
                   1170:                    && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
                   1171:                        == current_sym_value))
                   1172:                  type = TREE_TYPE (parms);
                   1173:                else
                   1174:                  {
                   1175:                    current_sym_value = original_sym_value;
                   1176:                    type = DECL_ARG_TYPE (parms);
                   1177:                  }
                   1178:              }
                   1179: 
                   1180:            PUT_SDB_DEF (name);
                   1181:            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
                   1182:            PUT_SDB_SCL (C_ARG);
                   1183:            PUT_SDB_TYPE (plain_type (type));
                   1184:            PUT_SDB_ENDEF;
                   1185:          }
                   1186:        else if (GET_CODE (DECL_RTL (parms)) == REG)
                   1187:          {
                   1188:            rtx best_rtl;
                   1189:            /* Parm passed in registers and lives in registers or nowhere.  */
                   1190: 
                   1191:            /* If parm lives in a register, use that register;
                   1192:               pretend the parm was passed there.  It would be more consistent
                   1193:               to describe the register where the parm was passed,
                   1194:               but in practice that register usually holds something else.  */
                   1195:            if (REGNO (DECL_RTL (parms)) >= 0
                   1196:                && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
                   1197:              best_rtl = DECL_RTL (parms);
                   1198:            /* If the parm lives nowhere,
                   1199:               use the register where it was passed.  */
                   1200:            else
                   1201:              best_rtl = DECL_INCOMING_RTL (parms);
                   1202: 
                   1203:            PUT_SDB_DEF (name);
                   1204:            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
                   1205:            PUT_SDB_SCL (C_REGPARM);
                   1206:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1207:            PUT_SDB_ENDEF;
                   1208:          }
                   1209:        else if (GET_CODE (DECL_RTL (parms)) == MEM
                   1210:                 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
                   1211:          {
                   1212:            /* Parm was passed in registers but lives on the stack.  */
                   1213: 
                   1214:            /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
                   1215:               in which case we want the value of that CONST_INT,
                   1216:               or (MEM (REG ...)) or (MEM (MEM ...)),
                   1217:               in which case we use a value of zero.  */
                   1218:            if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
                   1219:                || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
                   1220:              current_sym_value = 0;
                   1221:            else
                   1222:              current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
                   1223: 
                   1224:            /* Again, this assumes the offset is based on the arg pointer.  */
                   1225:            PUT_SDB_DEF (name);
                   1226:            PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
                   1227:                                                  XEXP (DECL_RTL (parms), 0)));
                   1228:            PUT_SDB_SCL (C_ARG);
                   1229:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1230:            PUT_SDB_ENDEF;
                   1231:          }
                   1232:       }
                   1233: }
                   1234: 
                   1235: /* Output definitions for the places where parms live during the function,
                   1236:    when different from where they were passed, when the parms were passed
                   1237:    in memory.
                   1238: 
                   1239:    It is not useful to do this for parms passed in registers
                   1240:    that live during the function in different registers, because it is
                   1241:    impossible to look in the passed register for the passed value,
                   1242:    so we use the within-the-function register to begin with.
                   1243: 
                   1244:    PARMS is a chain of PARM_DECL nodes.  */
                   1245: 
                   1246: static void
                   1247: sdbout_reg_parms (parms)
                   1248:      tree parms;
                   1249: {
                   1250:   for (; parms; parms = TREE_CHAIN (parms))
                   1251:     if (DECL_NAME (parms))
                   1252:       {
                   1253:        char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
                   1254: 
                   1255:        /* Report parms that live in registers during the function
                   1256:           but were passed in memory.  */
                   1257:        if (GET_CODE (DECL_RTL (parms)) == REG
                   1258:            && REGNO (DECL_RTL (parms)) >= 0
                   1259:            && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
                   1260:            && PARM_PASSED_IN_MEMORY (parms))
                   1261:          {
                   1262:            if (name == 0 || *name == 0)
                   1263:              name = gen_fake_label ();
                   1264:            PUT_SDB_DEF (name);
                   1265:            PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
                   1266:            PUT_SDB_SCL (C_REG);
                   1267:            PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
                   1268:            PUT_SDB_ENDEF;
                   1269:          }
                   1270:        /* Report parms that live in memory but not where they were passed.  */
                   1271:        else if (GET_CODE (DECL_RTL (parms)) == MEM
                   1272:                 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
                   1273:                 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
                   1274:                 && PARM_PASSED_IN_MEMORY (parms)
                   1275:                 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
                   1276:          {
                   1277: #if 0 /* ??? It is not clear yet what should replace this.  */
                   1278:            int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
                   1279:            /* A parm declared char is really passed as an int,
                   1280:               so it occupies the least significant bytes.
                   1281:               On a big-endian machine those are not the low-numbered ones.  */
                   1282: #if BYTES_BIG_ENDIAN
                   1283:            if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
                   1284:              offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
                   1285:                         - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
                   1286: #endif
                   1287:            if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
                   1288: #endif
                   1289:              {
                   1290:                if (name == 0 || *name == 0)
                   1291:                  name = gen_fake_label ();
                   1292:                PUT_SDB_DEF (name);
                   1293:                PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
                   1294:                                 (XEXP (DECL_RTL (parms), 0)));
                   1295:                PUT_SDB_SCL (C_AUTO);
                   1296:                PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
                   1297:                PUT_SDB_ENDEF;
                   1298:              }
                   1299:          }
                   1300:       }
                   1301: }
                   1302: 
                   1303: /* Describe the beginning of an internal block within a function.
                   1304:    Also output descriptions of variables defined in this block.
                   1305: 
                   1306:    N is the number of the block, by order of beginning, counting from 1,
                   1307:    and not counting the outermost (function top-level) block.
                   1308:    The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
                   1309:    if the count starts at 0 for the outermost one.  */
                   1310: 
                   1311: void
                   1312: sdbout_begin_block (file, line, n)
                   1313:      FILE *file;
                   1314:      int line;
                   1315:      int n;
                   1316: {
                   1317:   tree decl = current_function_decl;
                   1318:   MAKE_LINE_SAFE (line);
                   1319:   PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
                   1320:   if (n == 1)
                   1321:     {
                   1322:       /* Include the outermost BLOCK's variables in block 1.  */
                   1323:       next_block_number = 0;
                   1324:       do_block = 0;
                   1325:       sdbout_block (DECL_INITIAL (decl));
                   1326:     }
                   1327:   /* If -g1, suppress all the internal symbols of functions
                   1328:      except for arguments.  */
                   1329:   if (debug_info_level != DINFO_LEVEL_TERSE)
                   1330:     {
                   1331:       next_block_number = 0;
                   1332:       do_block = n;
                   1333:       sdbout_block (DECL_INITIAL (decl));
                   1334:     }
                   1335: 
                   1336: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                   1337:   sdbout_dequeue_anonymous_types ();
                   1338: #endif
                   1339: }
                   1340: 
                   1341: /* Describe the end line-number of an internal block within a function.  */
                   1342: 
                   1343: void
                   1344: sdbout_end_block (file, line)
                   1345:      FILE *file;
                   1346:      int line;
                   1347: {
                   1348:   MAKE_LINE_SAFE (line);
                   1349:   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
                   1350: }
                   1351: 
                   1352: /* Output sdb info for the current function name.
                   1353:    Called from assemble_start_function.  */
                   1354: 
                   1355: void
                   1356: sdbout_mark_begin_function ()
                   1357: {
                   1358:   sdbout_symbol (current_function_decl, 0);
                   1359: }
                   1360: 
                   1361: /* Called at beginning of function body (after prologue).
                   1362:    Record the function's starting line number, so we can output
                   1363:    relative line numbers for the other lines.
                   1364:    Describe beginning of outermost block.
                   1365:    Also describe the parameter list.  */
                   1366: 
                   1367: void
                   1368: sdbout_begin_function (line)
                   1369:      int line;
                   1370: {
                   1371:   sdb_begin_function_line = line - 1;
                   1372:   PUT_SDB_FUNCTION_START (line);
                   1373:   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
                   1374:   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
                   1375: }
                   1376: 
                   1377: /* Called at end of function (before epilogue).
                   1378:    Describe end of outermost block.  */
                   1379: 
                   1380: void
                   1381: sdbout_end_function (line)
                   1382:      int line;
                   1383: {
                   1384: #ifdef SDB_ALLOW_FORWARD_REFERENCES
                   1385:   sdbout_dequeue_anonymous_types ();
                   1386: #endif
                   1387: 
                   1388:   MAKE_LINE_SAFE (line);
                   1389:   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
                   1390: 
                   1391:   /* Indicate we are between functions, for line-number output.  */
                   1392:   sdb_begin_function_line = -1;
                   1393: }
                   1394: 
                   1395: /* Output sdb info for the absolute end of a function.
                   1396:    Called after the epilogue is output.  */
                   1397: 
                   1398: void
                   1399: sdbout_end_epilogue ()
                   1400: {
                   1401:   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
                   1402:   PUT_SDB_EPILOGUE_END (name);
                   1403: }
                   1404: 
                   1405: /* Output sdb info for the given label.  Called only if LABEL_NAME (insn)
                   1406:    is present.  */
                   1407: 
                   1408: void
                   1409: sdbout_label (insn)
                   1410:      register rtx insn;
                   1411: {
                   1412:   PUT_SDB_DEF (LABEL_NAME (insn));
                   1413:   PUT_SDB_VAL (insn);
                   1414:   PUT_SDB_SCL (C_LABEL);
                   1415:   PUT_SDB_TYPE (T_NULL);
                   1416:   PUT_SDB_ENDEF;
                   1417: }
                   1418: 
                   1419: #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.