home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 321 / compsrc3 / sdbout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  20.9 KB  |  751 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. #include "config.h"
  23.  
  24. #ifdef SDB_DEBUGGING_INFO
  25.  
  26. #include "tree.h"
  27. #include "rtl.h"
  28. #include "c-tree.h"
  29. #include <stdio.h>
  30. #include <syms.h>
  31. /* #include <storclass.h>  used to be this instead of syms.h.  */
  32.  
  33. /* Line number of beginning of current function, minus one.  */
  34.  
  35. int sdb_begin_function_line = 0;
  36.  
  37. /* Counter to generate unique "names" for nameless struct members.  */
  38.  
  39. static int unnamed_struct_number = 0;
  40.  
  41. extern FILE *asm_out_file;
  42.  
  43. extern tree current_function_decl;
  44.  
  45. void sdbout_init ();
  46. void sdbout_syms ();
  47. void sdbout_symbol ();
  48. void sdbout_tags();
  49. void sdbout_types();
  50.  
  51. static void sdbout_one_type ();
  52.  
  53. /* Random macros describing parts of SDB data.  */
  54.  
  55. /* Put something here if lines get too long */
  56. #define CONTIN
  57.  
  58. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d;", (a))
  59. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d;", (a))
  60. #define PUT_SDB_VAL(a)                \
  61. ( fputs (".val\t", asm_out_file),        \
  62.   output_addr_const (asm_out_file, (a)),    \
  63.   fputc (';', asm_out_file))
  64. #define PUT_SDB_DEF(a) fprintf(asm_out_file, "\t.def\t%s;", a)
  65. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  66. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o;", a)
  67. #define PUT_SDB_TAG(a) fprintf(asm_out_file, "\t.tag\t%s;", a)
  68. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d;", a)
  69.  
  70. /* Return the sdb tag identifier string for TYPE
  71.    if TYPE has already been defined; otherwise return a null pointer.   */
  72.   
  73. #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
  74.  
  75. /* Set the sdb tag identifier string for TYPE to NAME.  */
  76.  
  77. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  78.   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
  79.  
  80. /* Return the name (a string) of the struct, union or enum tag
  81.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  82.  
  83. #define TAG_NAME(link) \
  84.   (((link) && TREE_PURPOSE((link)) \
  85.     && IDENTIFIER_POINTER(TREE_PURPOSE((link)))) \
  86.    ? IDENTIFIER_POINTER(TREE_PURPOSE((link))) : (char *) 0)
  87.  
  88. void
  89. sdbout_init (asm_file, input_file_name)
  90.      FILE *asm_file;
  91.      char *input_file_name;
  92. {
  93.   /* Get all permanent types not yet gotten
  94.      and output them.  */
  95.  
  96.   sdbout_types (nreverse (get_permanent_types ()));
  97. }
  98.  
  99. #if 0
  100.  
  101. /* return the tag identifier for type
  102.  */
  103.  
  104. {
  105. char *
  106. tag_of_ru_type (type,link)
  107.      tree type,link;
  108. {
  109.   if (TYPE_SYMTAB_ADDRESS (type))
  110.     return (char *)TYPE_SYMTAB_ADDRESS (type);
  111.   if (link &&
  112.       TREE_PURPOSE (link)
  113.       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
  114.     TYPE_SYMTAB_ADDRESS (type) =
  115.       (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
  116.   else
  117.     return (char *) TYPE_SYMTAB_ADDRESS (type);
  118. }
  119. #endif
  120.  
  121. /* Return a unique string to name an anonymous type.  */
  122.  
  123. static char *
  124. gen_fake_label ()
  125. {
  126.   char label[10];
  127.   char *labelstr;
  128.   sprintf (label, ".%dfake", unnamed_struct_number++);
  129.   labelstr = (char *) permalloc (strlen (label) + 1);
  130.   strcpy (labelstr, label);
  131.   return labelstr;
  132. }
  133.  
  134. /* Return the number which describes TYPE for SDB.
  135.    For pointers, etc., this function is recursive.
  136.    Each record, union or enumeral type must already have had a
  137.    tag number output.  */
  138.  
  139. /* The number is given by d6d5d4d3d2d1bbbb 
  140.    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
  141.    Thus, char *foo () has bbbb=T_CHAR
  142.               d1=D_FCN
  143.               d2=D_PTR
  144.  N_BTMASK=     017       1111     basic type field.
  145.  N_TSHIFT=       2                derived type shift
  146.  N_BTSHFT=       4                Basic type shift */
  147.  
  148. /* Produce the number that describes a pointer, function or array type.
  149.    PREV is the number describing the target, value or element type.
  150.    DT_type describes how to transform that type.  */
  151. #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
  152.   ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
  153.  
  154. static int
  155. plain_type (type)
  156.      tree type;
  157. {
  158.   if (type == 0)  
  159.     type = void_type_node;
  160.   if (type == error_mark_node)
  161.     type = integer_type_node;
  162.   switch (TREE_CODE (type))
  163.     {
  164.     case VOID_TYPE:
  165.       return T_INT;
  166.     case INTEGER_TYPE:
  167.       switch (int_size_in_bytes (type))
  168.     {
  169.     case 4:
  170.       return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  171.     case 1:
  172.       return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
  173.     case 2:
  174.       return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
  175.     default:
  176.       return 0;
  177.     }
  178.     case REAL_TYPE:
  179.       switch (int_size_in_bytes (type))
  180.     {
  181.     case 4:
  182.       return T_FLOAT;
  183.     default:
  184.       return T_DOUBLE;
  185.     }
  186.     case ARRAY_TYPE:
  187.       {
  188.     int m = plain_type (TREE_TYPE (type));
  189.     return PUSH_DERIVED_LEVEL (DT_ARY, m);
  190.       }
  191.     case RECORD_TYPE:
  192.     case UNION_TYPE:
  193.     case ENUMERAL_TYPE:
  194.       {
  195.     char *tag;
  196.     tag = KNOWN_TYPE_TAG (type);
  197.     if (tag) PUT_SDB_TAG (tag);
  198.     PUT_SDB_SIZE (int_size_in_bytes (type));
  199.     return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT :
  200.         (TREE_CODE (type) == UNION_TYPE) ? T_UNION :
  201.         T_ENUM);
  202.       }
  203.     case POINTER_TYPE:
  204.       {
  205.     int m = plain_type (TREE_TYPE (type));
  206.     return PUSH_DERIVED_LEVEL (DT_PTR, m);
  207.       }
  208.     case FUNCTION_TYPE:
  209.       {
  210.     int m = plain_type (TREE_TYPE (type));
  211.     return PUSH_DERIVED_LEVEL (DT_FCN, m);
  212.       }
  213.     default:
  214.       return 0;
  215.     }
  216. }
  217.  
  218. /* Output the symbols defined in block number DO_BLOCK.
  219.    Set NEXT_BLOCK_NUMBER to 0 before calling.
  220.  
  221.    This function works by walking the tree structure,
  222.    counting blocks, until it finds the desired block.  */
  223.  
  224. static int do_block = 0;
  225.  
  226. static int next_block_number;
  227.  
  228. static void
  229. sdbout_block (stmt)
  230.      register tree stmt;
  231. {
  232.   while (stmt)
  233.     {
  234.       switch (TREE_CODE (stmt))
  235.     {
  236.     case COMPOUND_STMT:
  237.     case LOOP_STMT:
  238.       sdbout_block (STMT_BODY (stmt));
  239.       break;
  240.  
  241.     case IF_STMT:
  242.       sdbout_block (STMT_THEN (stmt));
  243.       sdbout_block (STMT_ELSE (stmt));
  244.       break;
  245.  
  246.     case LET_STMT:
  247.       /* When we reach the specified block, output its symbols.  */
  248.       if (next_block_number == do_block)
  249.         {
  250.           sdbout_tags (STMT_TYPE_TAGS (stmt));
  251.           sdbout_syms (STMT_VARS (stmt));
  252.         }
  253.  
  254.       /* If we are past the specified block, stop the scan.  */
  255.       if (next_block_number < do_block)
  256.         return;
  257.  
  258.       next_block_number++;
  259.  
  260.       /* Scan the blocks within this block.  */
  261.       sdbout_block (STMT_BODY (stmt));
  262.     }
  263.       stmt = TREE_CHAIN (stmt);
  264.     }
  265. }
  266.  
  267. /* Call sdbout_symbol on each decl in the chain SYMS.  */
  268.  
  269. static void
  270. sdbout_syms (syms)
  271.      tree syms;
  272. {
  273.   while (syms)
  274.     {
  275.       sdbout_symbol (syms, 1);
  276.       syms = TREE_CHAIN (syms);
  277.     }
  278. }
  279.  
  280. /* Output SDB information for a symbol described by DECL.
  281.    LOCAL is nonzero if the symbol is not file-scope.  */
  282.  
  283. void
  284. sdbout_symbol (decl, local)
  285.      tree decl;
  286.      int local;
  287. {
  288.   int letter = 0;
  289.   tree type = TREE_TYPE (decl);
  290.  
  291.   /* If global, first output all types and all
  292.      struct, enum and union tags that have been created
  293.      and not yet output.  */
  294.  
  295.   if (local == 0)
  296.     {
  297.       sdbout_tags (gettags ());
  298.       sdbout_types (nreverse (get_permanent_types ()));
  299.     }
  300.  
  301.   switch (TREE_CODE (decl))
  302.     {
  303.     case CONST_DECL:
  304.       /* Enum values are defined by defining the enum type.  */
  305.       return;
  306.  
  307.     case FUNCTION_DECL:
  308.       if (TREE_EXTERNAL (decl))
  309.     return;
  310.       if (GET_CODE (DECL_RTL (decl)) != MEM
  311.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  312.     return;
  313.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  314.       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  315.       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
  316.       break;
  317.  
  318.     case TYPE_DECL:
  319.       /* Output typedef name.  */
  320.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  321.       PUT_SDB_SCL (C_TPDEF);
  322.       break;
  323.       
  324.     case PARM_DECL:
  325.       /* Parm decls go in their own separate chains
  326.      and are output by sdbout_reg_parms and sdbout_parms.  */
  327.       abort ();
  328.  
  329.     case VAR_DECL:
  330.       /* Don't mention a variable that is external.
  331.      Let the file that defines it describe it.  */
  332.       if (TREE_EXTERNAL (decl))
  333.     return;
  334.  
  335.       /* Don't mention a variable at all
  336.      if it was completely optimized into nothingness.  */
  337.       if (GET_CODE (DECL_RTL (decl)) == REG
  338.       && (REGNO (DECL_RTL (decl)) < 0
  339.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  340.     return;
  341.  
  342.       /* Ok, start a symtab entry and output the variable name.  */
  343.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  344.  
  345.       if (GET_CODE (DECL_RTL (decl)) == MEM
  346.       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  347.     {
  348.       if (TREE_PUBLIC (decl))
  349.         {
  350.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  351.               PUT_SDB_SCL (C_EXT);
  352.         }
  353.       else
  354.         {
  355.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  356.               PUT_SDB_SCL (C_STAT);
  357.         }
  358.     }
  359.       else if (GET_CODE (DECL_RTL (decl)) == REG)
  360.     {
  361.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  362.       PUT_SDB_SCL (C_REG);
  363.     }
  364.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  365.            && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  366.            || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  367.                && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  368.     /* If the value is indirect by memory or by a register
  369.        that isn't the frame pointer
  370.        then it means the object is variable-sized and address through
  371.        that register or stack slot.  DBX has no way to represent this
  372.        so all we can do is output the variable as a pointer.  */
  373.     {
  374.       if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  375.         {
  376.           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  377.           PUT_SDB_SCL (C_REG);
  378.         }
  379.       else
  380.         {
  381.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
  382.          (CONST_INT...)))).
  383.          We want the value of that CONST_INT.  */
  384.           /* Encore compiler hates a newline in a macro arg, it seems.  */
  385.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1)));
  386.           PUT_SDB_SCL (C_AUTO);
  387.         }
  388.  
  389.       type = build_pointer_type (TREE_TYPE (decl));
  390.     }
  391.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  392.            && XEXP (DECL_RTL (decl), 0) != const0_rtx)
  393.     /* const0_rtx is used as the address for a variable that
  394.        is a dummy due to an erroneous declaration.
  395.        Ignore such vars.  */
  396.     {
  397.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  398.          We want the value of that CONST_INT.  */
  399.       PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1)));
  400.       PUT_SDB_SCL (C_AUTO);
  401.     }
  402.       break;
  403.     }
  404.   PUT_SDB_TYPE (plain_type (type));
  405.   PUT_SDB_ENDEF;
  406. }
  407.  
  408. /* Given a list of TREE_LIST nodes that point at types,
  409.    output those types for SDB.
  410.    We must check to include those that have been mentioned already with
  411.    only a cross-reference.  */
  412.  
  413. void
  414. sdbout_tags (tags)
  415.      tree tags;
  416. {
  417.   register tree link;
  418.  
  419.   for (link = tags; link; link = TREE_CHAIN (link))
  420.     {
  421.       register tree type = TREE_VALUE (link);
  422.  
  423.       if (TREE_PURPOSE (link) != 0
  424.       && ! KNOWN_TYPE_TAG (type)
  425.       && TYPE_SIZE (type) != 0)
  426.     sdbout_one_type (type, TAG_NAME (link));
  427.     }
  428. }
  429.  
  430. /* Given a chain of ..._TYPE nodes, all of which have names,
  431.    output definitions of those names, as typedefs.  */
  432.  
  433. void
  434. sdbout_types (types)
  435.      register tree types;
  436. {
  437.   register tree link;
  438.  
  439.   for (link = types; link; link = TREE_CHAIN (link))
  440.     sdbout_one_type (link, 0);
  441. }
  442.  
  443. static void
  444. sdbout_type (type)
  445.      tree type;
  446. {
  447.   register tree tem;
  448.   if (type == error_mark_node)
  449.     type = integer_type_node;
  450.   PUT_SDB_TYPE (plain_type (type));
  451. }
  452.  
  453. /* Use this to put out the top level defined record and union types
  454.    for later reference.  If this is a struct with a name, then put that
  455.    name out.  Other unnamed structs will have .xxfake labels generated so
  456.    that they may be referred to later.
  457.    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
  458.    It may NOT be called recursively.  */
  459.  
  460. static void
  461. sdbout_one_type (type, name)
  462.      char *name;
  463.      tree type;
  464. {
  465.   switch (TREE_CODE (type))
  466.     {
  467.     case RECORD_TYPE:
  468.     case UNION_TYPE:
  469.     case ENUMERAL_TYPE:
  470.       /* Don't output a type twice.  */
  471.       if (KNOWN_TYPE_TAG (type))
  472.     return;
  473.  
  474.       /* Output a structure type.  */
  475.       {
  476.     int size = int_size_in_bytes (type);
  477.     int member_scl;
  478.     tree tem;
  479.  
  480.     if (!name || !*name)
  481.       name = gen_fake_label ();
  482.     SET_KNOWN_TYPE_TAG (type, name);
  483.     PUT_SDB_DEF (name);
  484.  
  485.     switch (TREE_CODE (type))
  486.       {
  487.       case UNION_TYPE:
  488.         PUT_SDB_SCL (C_UNTAG);
  489.         PUT_SDB_TYPE (T_UNION);
  490.         member_scl = C_MOU;
  491.         break;
  492.  
  493.       case RECORD_TYPE:
  494.         PUT_SDB_SCL (C_STRTAG);
  495.         PUT_SDB_TYPE (T_STRUCT);
  496.         member_scl = C_MOS;
  497.         break;
  498.  
  499.       case ENUMERAL_TYPE:
  500.         PUT_SDB_SCL (C_ENTAG);
  501.         PUT_SDB_TYPE (T_ENUM);
  502.         member_scl = C_MOE;
  503.         break;
  504.       }
  505.  
  506.     PUT_SDB_SIZE (size);
  507.     PUT_SDB_ENDEF;
  508.  
  509.     /* output the individual fields */
  510.  
  511.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  512.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  513.         {
  514.           PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
  515.           PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
  516.           PUT_SDB_SCL (C_MOE);
  517.           PUT_SDB_TYPE (T_MOE);
  518.           PUT_SDB_ENDEF;
  519.         }
  520.       
  521.     else            /* record or union type */
  522.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  523.         /* Output the name, type, position (in bits), size (in bits)
  524.            of each field.  */
  525.         /* Omit here the nameless fields that are used to skip bits.  */
  526.         if (DECL_NAME (tem) != 0)
  527.           {
  528.         CONTIN;
  529.         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
  530.         if (tem->decl.mode == BImode)
  531.           {
  532.             PUT_SDB_INT_VAL (DECL_OFFSET (tem));
  533.             PUT_SDB_SCL (C_FIELD);
  534.             sdbout_type (TREE_TYPE (tem));
  535.           }
  536.         else
  537.           {
  538.             PUT_SDB_INT_VAL (DECL_OFFSET (tem) / BITS_PER_UNIT);
  539.             PUT_SDB_SCL (member_scl);
  540.             sdbout_type (TREE_TYPE (tem));
  541.           }
  542.         PUT_SDB_ENDEF;
  543.           }
  544.     /* output end of a structure,union, or enumeral definition */
  545.    
  546.     PUT_SDB_DEF (".eos");
  547.     PUT_SDB_INT_VAL (size);
  548.     PUT_SDB_SCL (C_EOS);
  549.     PUT_SDB_TAG (name);
  550.     PUT_SDB_SIZE (size);
  551.     PUT_SDB_ENDEF;
  552.     break;
  553.       }
  554.     }
  555. }
  556.  
  557. /* Output definitions of all parameters, referring when possible to the
  558.    place where the parameters were passed rather than the copies used
  559.    within the function.     This is done as part of starting the function.
  560.    PARMS is a chain of PARM_DECL nodes.  */
  561.  
  562. static void
  563. sdbout_parms (parms1)
  564.      tree parms1;
  565. {
  566.   tree type;
  567.   tree parms;
  568.  
  569.   for (parms = parms1; parms; parms = TREE_CHAIN (parms))
  570.     {
  571.       int current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  572.  
  573.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  574.       if (GET_CODE (DECL_RTL (parms)) == REG
  575.       && REGNO (DECL_RTL (parms)) >= 0
  576.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  577.     type = DECL_ARG_TYPE (parms);
  578.       else
  579.     {
  580.       /* This is the case where the parm is passed as an int or double
  581.          and it is converted to a char, short or float and stored back
  582.          in the parmlist.  In this case, describe the parm
  583.          with the variable's declared type, and adjust the address
  584.          if the least significant bytes (which we are using) are not
  585.          the first ones.  */
  586. #ifdef BYTES_BIG_ENDIAN
  587.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  588.         current_sym_value +=
  589.           (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  590.            - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  591. #endif
  592.       if (GET_CODE (DECL_RTL (parms)) == MEM
  593.           && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  594.           && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  595.           && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  596.           == current_sym_value))
  597.         type = TREE_TYPE (parms);
  598.       else
  599.         {
  600.           current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  601.           type = DECL_ARG_TYPE (parms);
  602.         }
  603.     }
  604.      
  605.       PUT_SDB_INT_VAL (current_sym_value);
  606.       PUT_SDB_SCL (C_ARG);
  607.       PUT_SDB_TYPE (plain_type (type));
  608.       PUT_SDB_ENDEF;
  609.     }
  610. }
  611.  
  612. /* Output definitions, referring to registers,
  613.    of all the parms in PARMS which are stored in registers during the function.
  614.    PARMS is a chain of PARM_DECL nodes.
  615.    This is done as part of starting the function.  */
  616.  
  617. static void
  618. sdbout_reg_parms (parms)
  619.      tree parms;
  620. {
  621.   while (parms)
  622.     {
  623.       if (GET_CODE (DECL_RTL (parms)) == REG
  624.       && REGNO (DECL_RTL (parms)) >= 0
  625.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  626.     {
  627.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  628.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  629.         PUT_SDB_SCL (C_REG);
  630.       PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  631.       PUT_SDB_ENDEF;
  632.     }
  633.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  634.            && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  635.            && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  636.     {
  637.       int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  638.       /* A parm declared char is really passed as an int,
  639.          so it occupies the least significant bytes.
  640.          On a big-endian machine those are not the low-numbered ones.  */
  641. #ifdef BYTES_BIG_ENDIAN
  642.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  643.         offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  644.                - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  645. #endif
  646.       if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  647.         {
  648.           PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));          
  649.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)));
  650.           PUT_SDB_SCL (C_AUTO);
  651.           PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  652.           PUT_SDB_ENDEF;
  653.         }
  654.     }
  655.       parms = TREE_CHAIN (parms);
  656.     }
  657. }
  658.  
  659. /* Describe the beginning of an internal block within a function.
  660.    Also output descriptions of variables defined in this block.
  661.  
  662.    N is the number of the block, by order of beginning, counting from 1,
  663.    and not counting the outermost (function top-level) block.
  664.    The blocks match the LET_STMTS in DECL_INITIAL (current_function_decl),
  665.    if the count starts at 0 for the outermost one.  */
  666.  
  667. void
  668. sdbout_begin_block (file, line, n)
  669.      FILE *file;
  670.      int line;
  671.      int n;
  672. {
  673.   tree decl = current_function_decl;
  674.   fprintf (file,
  675.        "\t.def\t.bb;\t.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",
  676.        line - sdb_begin_function_line);
  677.   if (n == 1)
  678.     {
  679.       /* Include the outermost LET_STMT's variables in block 1.  */
  680.       next_block_number = 0;
  681.       do_block = 0;
  682.       sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  683.     }
  684.   next_block_number = 0;
  685.   do_block = n;
  686.   sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  687. }
  688.  
  689. /* Describe the end line-number of an internal block within a function.  */
  690.      
  691. void
  692. sdbout_end_block (file, line)
  693.      FILE *file;
  694.      int line;
  695. {
  696.   fprintf (file,
  697.        "\t.def\t.eb;.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n" ,
  698.        line - sdb_begin_function_line);
  699. }
  700.  
  701. /* Called at beginning of function (after prologue).
  702.    Record the function's starting line number, so we can output
  703.    relative line numbers for the other lines.
  704.    Describe beginning of outermost block.
  705.    Also describe the parameter list.  */
  706.  
  707. void
  708. sdbout_begin_function (line)
  709.      int line;
  710. {
  711.   sdb_begin_function_line = line - 1;
  712.   fprintf (asm_out_file,
  713.        "\t.def\t.bf;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",
  714.        line);
  715.   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
  716.   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
  717. }
  718.  
  719. /* Called at end of function (before epilogue).
  720.    Describe end of outermost block.  */
  721.  
  722. void
  723. sdbout_end_function (line)
  724.      int line;
  725. {
  726.   fprintf (asm_out_file,
  727.        "\t.def\t.ef;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",
  728.        line - sdb_begin_function_line);
  729. }
  730.  
  731. /* Output sdb info for the current function name.
  732.    Called from assemble_function.  */
  733.  
  734. sdbout_mark_begin_function ()
  735. {
  736.   sdbout_symbol (current_function_decl, 0);
  737. }
  738.  
  739. /* Output end-of-definition address for current function and linenumber.  */
  740.  
  741. void
  742. sdbout_mark_end_function ()
  743. {
  744.   PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
  745.   fputs ("\t.val\t.;", asm_out_file);
  746.   PUT_SDB_SCL (C_EFCN);
  747.   PUT_SDB_ENDEF;
  748. }
  749.  
  750. #endif
  751.