OSDN Git Service

* config/sh/sh.h (SH5_WOULD_BE_PARTIAL_NREGS): Use GET_MODE_SIZE
[pf3gnuchains/gcc-fork.git] / gcc / dbxout.c
index e25dd3c..cb7df88 100644 (file)
@@ -16,8 +16,8 @@ for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 
 /* Output dbx-format symbol table data.
@@ -89,6 +89,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "target.h"
 #include "langhooks.h"
 #include "obstack.h"
+#include "expr.h"
 
 #ifdef XCOFF_DEBUGGING_INFO
 #include "xcoffout.h"
@@ -241,13 +242,6 @@ static GTY(()) int scope_labelno;
 
 static GTY(()) int dbxout_source_line_counter;
 
-/* Nonzero if we have actually used any of the GDB extensions
-   to the debugging format.  The idea is that we use them for the
-   first time only if there's a strong reason, but once we have done that,
-   we use them whenever convenient.  */
-
-static GTY(()) int have_used_extensions = 0;
-
 /* Number for the next N_SOL filename stabs label.  The number 0 is reserved
    for the N_SO filename stabs label.  */
 
@@ -275,7 +269,7 @@ static int pending_bincls = 0;
 static const char *base_input_file;
 
 #ifdef DEBUG_SYMS_TEXT
-#define FORCE_TEXT current_function_section (current_function_decl);
+#define FORCE_TEXT switch_to_section (current_function_section ())
 #else
 #define FORCE_TEXT
 #endif
@@ -863,7 +857,7 @@ dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
       obstack_1grow (&stabstr_ob, '\0');
 
       len = obstack_object_size (&stabstr_ob);
-      chunk = str = obstack_finish (&stabstr_ob);
+      chunk = str = XOBFINISH (&stabstr_ob, char *);
 
       /* Within the buffer are a sequence of NUL-separated strings,
         each of which is to be written out as a separate stab
@@ -896,7 +890,7 @@ dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
         comma than to do a two-character fputs.  */
       obstack_grow (&stabstr_ob, "\",", 2);
       len = obstack_object_size (&stabstr_ob);
-      str = obstack_finish (&stabstr_ob);
+      str = XOBFINISH (&stabstr_ob, char *);
       
       fwrite (str, 1, len, asm_out_file);
       DBX_FINISH_STABS (sym, code, line, addr, label, number);
@@ -913,7 +907,7 @@ dbxout_function_end (tree decl)
 
   /* The Lscope label must be emitted even if we aren't doing anything
      else; dbxout_block needs it.  */
-  function_section (current_function_decl);
+  switch_to_section (function_section (current_function_decl));
   
   /* Convert Lscope into the appropriate format for local labels in case
      the system doesn't insert underscores in front of user generated
@@ -978,6 +972,8 @@ get_lang_number (void)
     return N_SO_PASCAL;
   else if (strcmp (language_string, "GNU Objective-C") == 0)
     return N_SO_OBJC;
+  else if (strcmp (language_string, "GNU Objective-C++") == 0)
+    return N_SO_OBJCPLUS;
   else
     return 0;
 
@@ -1037,7 +1033,7 @@ dbxout_init (const char *input_file_name)
 
   if (used_ltext_label_name)
     {
-      text_section ();
+      switch_to_section (text_section);
       targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
     }
 
@@ -1236,7 +1232,7 @@ dbxout_source_file (const char *filename)
     {
       /* Don't change section amid function.  */
       if (current_function_decl == NULL_TREE)
-       text_section ();
+       switch_to_section (text_section);
 
       dbxout_begin_simple_stabs (filename, N_SOL);
       dbxout_stab_value_internal_label ("Ltext", &source_label_number);
@@ -1324,9 +1320,7 @@ dbxout_function_decl (tree decl)
 static void
 dbxout_global_decl (tree decl)
 {
-  if (TREE_CODE (decl) == VAR_DECL
-      && ! DECL_EXTERNAL (decl)
-      && DECL_RTL_SET_P (decl))        /* Not necessary?  */
+  if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
     {
       int saved_tree_used = TREE_USED (decl);
       TREE_USED (decl) = 1;
@@ -1353,7 +1347,7 @@ dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
   DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
  {
-   text_section ();
+   switch_to_section (text_section);
    dbxout_begin_empty_stabs (N_SO);
    dbxout_stab_value_internal_label ("Letext", 0);
  }
@@ -1430,7 +1424,6 @@ dbxout_type_fields (tree type)
              && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
                  || TREE_CODE (tem) != FIELD_DECL))
            {
-             have_used_extensions = 1;
              stabstr_C ('/');
              stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
            }
@@ -1445,7 +1438,6 @@ dbxout_type_fields (tree type)
                {
                  tree name = DECL_ASSEMBLER_NAME (tem);
 
-                 have_used_extensions = 1;
                  stabstr_C (':');
                  stabstr_I (name);
                  stabstr_C (';');
@@ -1860,7 +1852,6 @@ dbxout_type (tree type, int full)
          if (use_gnu_debug_info_extensions
              && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
            {
-             have_used_extensions = 1;
              stabstr_S ("@s");
              stabstr_D (TYPE_PRECISION (type));
              stabstr_C (';');
@@ -1877,7 +1868,6 @@ dbxout_type (tree type, int full)
          if (use_gnu_debug_info_extensions
              && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
            {
-             have_used_extensions = 1;
              stabstr_S ("@s");
              stabstr_D (TYPE_PRECISION (type));
              stabstr_C (';');
@@ -1924,7 +1914,6 @@ dbxout_type (tree type, int full)
     case CHAR_TYPE:
       if (use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_S ("@s");
          stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
          stabstr_S (";-20;");
@@ -1942,7 +1931,6 @@ dbxout_type (tree type, int full)
     case BOOLEAN_TYPE:
       if (use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_S ("@s");
          stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
          stabstr_S (";-16;");
@@ -1988,7 +1976,6 @@ dbxout_type (tree type, int full)
       /* Make arrays of packed bits look like bitstrings for chill.  */
       if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_S ("@s");
          stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
          stabstr_S (";@S;S");
@@ -1997,10 +1984,7 @@ dbxout_type (tree type, int full)
        }
 
       if (use_gnu_debug_info_extensions && vector_type)
-       {
-         have_used_extensions = 1;
-         stabstr_S ("@V;");
-       }
+       stabstr_S ("@V;");
 
       /* Output "a" followed by a range type definition
         for the index type of the array
@@ -2010,7 +1994,6 @@ dbxout_type (tree type, int full)
         different from an array of characters.  */
       if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_S ("@S;");
        }
       tem = TYPE_DOMAIN (type);
@@ -2080,7 +2063,6 @@ dbxout_type (tree type, int full)
              {
                if (BINFO_N_BASE_BINFOS (binfo))
                  {
-                   have_used_extensions = 1;
                    stabstr_C ('!');
                    stabstr_U (BINFO_N_BASE_BINFOS (binfo));
                    stabstr_C (',');
@@ -2093,13 +2075,13 @@ dbxout_type (tree type, int full)
 
                if (use_gnu_debug_info_extensions)
                  {
-                   have_used_extensions = 1;
                    stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
                    stabstr_C (access == access_public_node ? '2' :
                                   access == access_protected_node
                                   ? '1' :'0');
                    if (BINFO_VIRTUAL_P (child)
-                       && strcmp (lang_hooks.name, "GNU C++") == 0)
+                       && (strcmp (lang_hooks.name, "GNU C++") == 0
+                           || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
                      /* For a virtual base, print the (negative)
                         offset within the vtable where we must look
                         to find the necessary adjustment.  */
@@ -2138,7 +2120,6 @@ dbxout_type (tree type, int full)
       dbxout_type_fields (type);
       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
        {
-         have_used_extensions = 1;
          dbxout_type_methods (type);
        }
 
@@ -2148,7 +2129,6 @@ dbxout_type (tree type, int full)
          /* Avoid the ~ if we don't really need it--it confuses dbx.  */
          && TYPE_VFIELD (type))
        {
-         have_used_extensions = 1;
 
          /* We need to write out info about what field this class
             uses as its "main" vtable pointer field, because if this
@@ -2179,7 +2159,6 @@ dbxout_type (tree type, int full)
       if (use_gnu_debug_info_extensions
          && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
        {
-         have_used_extensions = 1;
          stabstr_S ("@s");
          stabstr_D (TYPE_PRECISION (type));
          stabstr_C (';');
@@ -2215,7 +2194,6 @@ dbxout_type (tree type, int full)
     case METHOD_TYPE:
       if (use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_C ('#');
 
          /* Write the argument types out longhand.  */
@@ -2233,7 +2211,6 @@ dbxout_type (tree type, int full)
     case OFFSET_TYPE:
       if (use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_C ('@');
          dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
          stabstr_C (',');
@@ -2247,7 +2224,6 @@ dbxout_type (tree type, int full)
     case REFERENCE_TYPE:
       if (use_gnu_debug_info_extensions)
        {
-         have_used_extensions = 1;
          stabstr_C ('&');
        }
       else
@@ -2348,6 +2324,63 @@ dbxout_class_name_qualifiers (tree decl)
     }
 }
 \f
+/* This is a specialized subset of expand_expr for use by dbxout_symbol in
+   evaluating DECL_VALUE_EXPR.  In particular, we stop if we find decls that
+   havn't been expanded, or if the expression is getting so complex we won't
+   be able to represent it in stabs anyway.  Returns NULL on failure.  */
+
+static rtx
+dbxout_expand_expr (tree expr)
+{
+  switch (TREE_CODE (expr))
+    {
+    case VAR_DECL:
+    case PARM_DECL:
+      if (DECL_HAS_VALUE_EXPR_P (expr))
+       return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
+      /* FALLTHRU */
+
+    case CONST_DECL:
+    case RESULT_DECL:
+      return DECL_RTL_IF_SET (expr);
+
+    case INTEGER_CST:
+      return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
+
+    case COMPONENT_REF:
+    case ARRAY_REF:
+    case ARRAY_RANGE_REF:
+    case BIT_FIELD_REF:
+      {
+       enum machine_mode mode;
+       HOST_WIDE_INT bitsize, bitpos;
+       tree offset, tem;
+       int volatilep = 0, unsignedp = 0;
+       rtx x;
+
+       tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
+                                  &mode, &unsignedp, &volatilep, true);
+
+       x = dbxout_expand_expr (tem);
+       if (x == NULL || !MEM_P (x))
+         return NULL;
+       if (offset != NULL)
+         {
+           if (!host_integerp (offset, 0))
+             return NULL;
+           x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
+         }
+       if (bitpos != 0)
+         x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
+
+       return x;
+      }
+
+    default:
+      return NULL;
+    }
+}
+
 /* Output a .stabs for the symbol defined by DECL,
    which must be a ..._DECL node in the normal namespace.
    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
@@ -2360,6 +2393,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
   tree type = TREE_TYPE (decl);
   tree context = NULL_TREE;
   int result = 0;
+  rtx decl_rtl;
 
   /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
   ++debug_nesting;
@@ -2444,7 +2478,8 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
       break;
 
     case FUNCTION_DECL:
-      if (DECL_RTL (decl) == 0)
+      decl_rtl = DECL_RTL_IF_SET (decl);
+      if (!decl_rtl)
        DBXOUT_DECR_NESTING_AND_RETURN (0);
       if (DECL_EXTERNAL (decl))
        break;
@@ -2455,8 +2490,8 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
       /* Don't mention an inline instance of a nested function.  */
       if (context && DECL_FROM_INLINE (decl))
        break;
-      if (!MEM_P (DECL_RTL (decl))
-         || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
+      if (!MEM_P (decl_rtl)
+         || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
        break;
 
       dbxout_begin_complex_stabs ();
@@ -2480,8 +2515,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
          stabstr_I (DECL_NAME (context));
        }
 
-      dbxout_finish_complex_stabs (decl, N_FUN, XEXP (DECL_RTL (decl), 0),
-                                  0, 0);
+      dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
       break;
 
     case TYPE_DECL:
@@ -2523,7 +2557,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
                 || TREE_CODE (type) == UNION_TYPE
                 || TREE_CODE (type) == QUAL_UNION_TYPE)
                && TYPE_NAME (type) == decl
-               && !(use_gnu_debug_info_extensions && have_used_extensions)
+               && !use_gnu_debug_info_extensions
                && !TREE_ASM_WRITTEN (TYPE_NAME (type))
                /* Distinguish the implicit typedefs of C++
                   from explicit ones that might be found in C.  */
@@ -2549,11 +2583,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
 
            dbxout_begin_complex_stabs ();
 
-           /* Output leading class/struct qualifiers.
-              ??? why not set have_used_extensions here ... because
-              then the test of it below would always be true, I
-              guess.  But it's not clear to me why we shouldn't do
-              that always in extended mode.  */
+           /* Output leading class/struct qualifiers.  */
            if (use_gnu_debug_info_extensions)
              dbxout_class_name_qualifiers (decl);
 
@@ -2570,7 +2600,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
                   from explicit ones that might be found in C.  */
                && DECL_ARTIFICIAL (decl))
              {
-               if (use_gnu_debug_info_extensions && have_used_extensions)
+               if (use_gnu_debug_info_extensions)
                  {
                    stabstr_C ('T');
                    TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
@@ -2635,10 +2665,7 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
       gcc_unreachable ();
 
     case RESULT_DECL:
-      /* Named return value, treat like a VAR_DECL.  */
     case VAR_DECL:
-      if (! DECL_RTL_SET_P (decl))
-       DBXOUT_DECR_NESTING_AND_RETURN (0);
       /* Don't mention a variable that is external.
         Let the file that defines it describe it.  */
       if (DECL_EXTERNAL (decl))
@@ -2653,7 +2680,8 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
          && host_integerp (DECL_INITIAL (decl), 0)
          && ! TREE_ASM_WRITTEN (decl)
          && (DECL_CONTEXT (decl) == NULL_TREE
-             || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK)
+             || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
+             || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
          && TREE_PUBLIC (decl) == 0)
        {
          /* The sun4 assembler does not grok this.  */
@@ -2664,8 +2692,8 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
              HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
 
              dbxout_begin_complex_stabs ();
-             stabstr_I (DECL_NAME (decl));
-             stabstr_S (":c=i");
+             dbxout_symbol_name (decl, NULL, 'c');
+             stabstr_S ("=i");
              stabstr_D (ival);
              dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
              DBXOUT_DECR_NESTING;
@@ -2676,13 +2704,17 @@ dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
        }
       /* else it is something we handle like a normal variable.  */
 
-      SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
+      decl_rtl = dbxout_expand_expr (decl);
+      if (!decl_rtl)
+       DBXOUT_DECR_NESTING_AND_RETURN (0);
+
+      decl_rtl = eliminate_regs (decl_rtl, 0, NULL_RTX);
 #ifdef LEAF_REG_REMAP
       if (current_function_uses_only_leaf_regs)
-       leaf_renumber_regs_insn (DECL_RTL (decl));
+       leaf_renumber_regs_insn (decl_rtl);
 #endif
 
-      result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
+      result = dbxout_symbol_location (decl, type, 0, decl_rtl);
       break;
 
     default:
@@ -2806,7 +2838,7 @@ dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
            {
              /* Ultrix `as' seems to need this.  */
 #ifdef DBX_STATIC_STAB_DATA_SECTION
-             data_section ();
+             switch_to_section (data_section);
 #endif
              code = N_STSYM;
            }