Bug 23142, SIGSEGV in is_strip_section
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index 14122021c63863ad3b096a0c823f3cfd0e21d161..a56702aa1d2386d177fdee2d1687f86bf4cb5940 100644 (file)
@@ -1,6 +1,6 @@
 /* Support routines for decoding "stabs" debugging information format.
 
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -41,7 +41,7 @@
 #include "demangle.h"
 #include "gdb-demangle.h"
 #include "language.h"
-#include "doublest.h"
+#include "target-float.h"
 #include "cp-abi.h"
 #include "cp-support.h"
 #include <ctype.h>
@@ -52,8 +52,6 @@
 #include "stabsread.h"         /* Our own declarations */
 #undef EXTERN
 
-extern void _initialize_stabsread (void);
-
 struct nextfield
 {
   struct nextfield *next;
@@ -85,14 +83,14 @@ struct field_info
   };
 
 static void
-read_one_struct_field (struct field_info *, char **, char *,
+read_one_struct_field (struct field_info *, const char **, const char *,
                       struct type *, struct objfile *);
 
 static struct type *dbx_alloc_type (int[2], struct objfile *);
 
-static long read_huge_number (char **, int, int *, int);
+static long read_huge_number (const char **, int, int *, int);
 
-static struct type *error_type (char **, struct objfile *);
+static struct type *error_type (const char **, struct objfile *);
 
 static void
 patch_block_stabs (struct pending *, struct pending_stabs *,
@@ -100,35 +98,37 @@ patch_block_stabs (struct pending *, struct pending_stabs *,
 
 static void fix_common_block (struct symbol *, CORE_ADDR);
 
-static int read_type_number (char **, int *);
+static int read_type_number (const char **, int *);
 
-static struct type *read_type (char **, struct objfile *);
+static struct type *read_type (const char **, struct objfile *);
 
-static struct type *read_range_type (char **, int[2], int, struct objfile *);
+static struct type *read_range_type (const char **, int[2],
+                                    int, struct objfile *);
 
-static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
+static struct type *read_sun_builtin_type (const char **,
+                                          int[2], struct objfile *);
 
-static struct type *read_sun_floating_type (char **, int[2],
+static struct type *read_sun_floating_type (const char **, int[2],
                                            struct objfile *);
 
-static struct type *read_enum_type (char **, struct type *, struct objfile *);
+static struct type *read_enum_type (const char **, struct type *, struct objfile *);
 
 static struct type *rs6000_builtin_type (int, struct objfile *);
 
 static int
-read_member_functions (struct field_info *, char **, struct type *,
+read_member_functions (struct field_info *, const char **, struct type *,
                       struct objfile *);
 
 static int
-read_struct_fields (struct field_info *, char **, struct type *,
+read_struct_fields (struct field_info *, const char **, struct type *,
                    struct objfile *);
 
 static int
-read_baseclasses (struct field_info *, char **, struct type *,
+read_baseclasses (struct field_info *, const char **, struct type *,
                  struct objfile *);
 
 static int
-read_tilde_fields (struct field_info *, char **, struct type *,
+read_tilde_fields (struct field_info *, const char **, struct type *,
                   struct objfile *);
 
 static int attach_fn_fields_to_type (struct field_info *, struct type *);
@@ -136,24 +136,25 @@ static int attach_fn_fields_to_type (struct field_info *, struct type *);
 static int attach_fields_to_type (struct field_info *, struct type *,
                                  struct objfile *);
 
-static struct type *read_struct_type (char **, struct type *,
+static struct type *read_struct_type (const char **, struct type *,
                                       enum type_code,
                                      struct objfile *);
 
-static struct type *read_array_type (char **, struct type *,
+static struct type *read_array_type (const char **, struct type *,
                                     struct objfile *);
 
-static struct field *read_args (char **, int, struct objfile *, int *, int *);
+static struct field *read_args (const char **, int, struct objfile *,
+                               int *, int *);
 
 static void add_undefined_type (struct type *, int[2]);
 
 static int
-read_cpp_abbrev (struct field_info *, char **, struct type *,
+read_cpp_abbrev (struct field_info *, const char **, struct type *,
                 struct objfile *);
 
-static char *find_name_end (char *name);
+static const char *find_name_end (const char *name);
 
-static int process_reference (char **string);
+static int process_reference (const char **string);
 
 void stabsread_clear_cache (void);
 
@@ -367,7 +368,7 @@ dbx_init_float_type (struct objfile *objfile, int bits)
   if (format)
     type = init_float_type (objfile, bits, NULL, format);
   else
-    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, NULL);
+    type = init_type (objfile, TYPE_CODE_ERROR, bits, NULL);
 
   return type;
 }
@@ -381,7 +382,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
 {
   int ii;
   char *name;
-  char *pp;
+  const char *pp;
   struct symbol *sym;
 
   if (stabs)
@@ -461,7 +462,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
    Returns 0 for success, -1 for error.  */
 
 static int
-read_type_number (char **pp, int *typenums)
+read_type_number (const char **pp, int *typenums)
 {
   int nbits;
 
@@ -496,7 +497,7 @@ read_type_number (char **pp, int *typenums)
 
 struct ref_map
 {
-  char *stabs;
+  const char *stabs;
   CORE_ADDR value;
   struct symbol *sym;
 };
@@ -528,7 +529,7 @@ stabsread_clear_cache (void)
    find them, using their reference numbers as our index.
    These will be used later when we resolve references.  */
 void
-ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
+ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
 {
   if (ref_count == 0)
     ref_chunk = 0;
@@ -563,9 +564,9 @@ ref_search (int refnum)
    reference number.  Move STRING beyond the reference id.  */
 
 static int
-process_reference (char **string)
+process_reference (const char **string)
 {
-  char *p;
+  const char *p;
   int refnum = 0;
 
   if (**string != '#')
@@ -588,9 +589,9 @@ process_reference (char **string)
    definition for later use.  Return the reference number.  */
 
 int
-symbol_reference_defined (char **string)
+symbol_reference_defined (const char **string)
 {
-  char *p = *string;
+  const char *p = *string;
   int refnum = 0;
 
   refnum = process_reference (&p);
@@ -641,12 +642,12 @@ static int stab_register_index;
 static int stab_regparm_index;
 
 struct symbol *
-define_symbol (CORE_ADDR valu, char *string, int desc, int type,
+define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
               struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym;
-  char *p = (char *) find_name_end (string);
+  const char *p = find_name_end (string);
   int deftype;
   int synonym = 0;
   int i;
@@ -722,7 +723,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
          /* SunPRO (3.0 at least) static variable encoding.  */
          if (gdbarch_static_transform_name_p (gdbarch))
            goto normal;
-         /* ... fall through ...  */
+         /* fall through */
 
        default:
          complaint (&symfile_complaints, _("Unknown C++ symbol name `%s'"),
@@ -797,19 +798,15 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
        {
        case 'r':
          {
-           double d = atof (p);
            gdb_byte *dbl_valu;
            struct type *dbl_type;
 
-           /* FIXME-if-picky-about-floating-accuracy: Should be using
-              target arithmetic to get the value.  real.c in GCC
-              probably has the necessary code.  */
-
            dbl_type = objfile_type (objfile)->builtin_double;
            dbl_valu
              = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
                                            TYPE_LENGTH (dbl_type));
-           store_typed_floating (dbl_valu, dbl_type, d);
+
+           target_float_from_string (dbl_valu, dbl_type, std::string (p));
 
            SYMBOL_TYPE (sym) = dbl_type;
            SYMBOL_VALUE_BYTES (sym) = dbl_valu;
@@ -976,7 +973,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
          struct type *ftype = SYMBOL_TYPE (sym);
          int nsemi = 0;
          int nparams = 0;
-         char *p1 = p;
+         const char *p1 = p;
 
          /* Obtain a worst case guess for the number of arguments
             by counting the semicolons.  */
@@ -1103,6 +1100,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
            }
          break;
        }
+      /* Fall through.  */
 
     case 'P':
       /* acc seems to use P to declare the prototypes of functions that
@@ -1490,7 +1488,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
    debugger will be able to read the new symbol tables.  */
 
 static struct type *
-error_type (char **pp, struct objfile *objfile)
+error_type (const char **pp, struct objfile *objfile)
 {
   complaint (&symfile_complaints,
             _("couldn't parse type; debugger out of date?"));
@@ -1523,7 +1521,7 @@ error_type (char **pp, struct objfile *objfile)
    deciding whether to call read_type.  */
 
 static struct type *
-read_type (char **pp, struct objfile *objfile)
+read_type (const char **pp, struct objfile *objfile)
 {
   struct type *type = 0;
   struct type *type1;
@@ -1595,7 +1593,7 @@ again:
        char *type_name;
 
        {
-         char *from, *to, *p, *q1, *q2;
+         const char *from, *p, *q1, *q2;
 
          /* Set the type code according to the following letter.  */
          switch ((*pp)[0])
@@ -1661,7 +1659,7 @@ again:
            }
          if (type_name == NULL)
            {
-             to = type_name = (char *)
+             char *to = type_name = (char *)
                obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
 
              /* Copy the name.  */
@@ -1910,7 +1908,7 @@ again:
       else
        /* type attribute */
        {
-         char *attr = *pp;
+         const char *attr = *pp;
 
          /* Skip to the semicolon.  */
          while (**pp != ';' && **pp != '\0')
@@ -2152,7 +2150,7 @@ rs6000_builtin_type (int typenum, struct objfile *objfile)
       rettype = init_integer_type (objfile, 32, 1, "unsigned long");
       break;
     case 11:
-      rettype = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+      rettype = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
       break;
     case 12:
       /* IEEE single precision (32 bit).  */
@@ -2280,8 +2278,8 @@ stabs_method_name_from_physname (const char *physname)
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_member_functions (struct field_info *fip, char **pp, struct type *type,
-                      struct objfile *objfile)
+read_member_functions (struct field_info *fip, const char **pp,
+                      struct type *type, struct objfile *objfile)
 {
   int nfn_fields = 0;
   int length = 0;
@@ -2296,7 +2294,7 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
   struct next_fnfieldlist *new_fnlist;
   struct next_fnfield *new_sublist;
   char *main_fn_name;
-  char *p;
+  const char *p;
 
   /* Process each list until we find something that is not a member function
      or find the end of the functions.  */
@@ -2535,7 +2533,8 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
              complaint (&symfile_complaints,
                         _("member function type missing, got '%c'"),
                         (*pp)[-1]);
-             /* Fall through into normal member function.  */
+             /* Normal member function.  */
+             /* Fall through.  */
 
            case '.':
              /* normal member function.  */
@@ -2770,10 +2769,10 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
    keep parsing and it's time for error_type().  */
 
 static int
-read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
+read_cpp_abbrev (struct field_info *fip, const char **pp, struct type *type,
                 struct objfile *objfile)
 {
-  char *p;
+  const char *p;
   const char *name;
   char cpp_abbrev;
   struct type *context;
@@ -2866,7 +2865,7 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
 }
 
 static void
-read_one_struct_field (struct field_info *fip, char **pp, char *p,
+read_one_struct_field (struct field_info *fip, const char **pp, const char *p,
                       struct type *type, struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -3009,10 +3008,10 @@ read_one_struct_field (struct field_info *fip, char **pp, char *p,
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_struct_fields (struct field_info *fip, char **pp, struct type *type,
+read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
                    struct objfile *objfile)
 {
-  char *p;
+  const char *p;
   struct nextfield *newobj;
 
   /* We better set p right now, in case there are no fields at all...    */
@@ -3107,7 +3106,7 @@ read_struct_fields (struct field_info *fip, char **pp, struct type *type,
 
 
 static int
-read_baseclasses (struct field_info *fip, char **pp, struct type *type,
+read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
                  struct objfile *objfile)
 {
   int i;
@@ -3233,10 +3232,10 @@ read_baseclasses (struct field_info *fip, char **pp, struct type *type,
    so we can look for the vptr base class info.  */
 
 static int
-read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
+read_tilde_fields (struct field_info *fip, const char **pp, struct type *type,
                   struct objfile *objfile)
 {
-  char *p;
+  const char *p;
 
   STABS_CONTINUE (pp, objfile);
 
@@ -3509,7 +3508,7 @@ set_length_in_type_chain (struct type *type)
  */
 
 static struct type *
-read_struct_type (char **pp, struct type *type, enum type_code type_code,
+read_struct_type (const char **pp, struct type *type, enum type_code type_code,
                   struct objfile *objfile)
 {
   struct cleanup *back_to;
@@ -3583,7 +3582,7 @@ read_struct_type (char **pp, struct type *type, enum type_code type_code,
    array.  */
 
 static struct type *
-read_array_type (char **pp, struct type *type,
+read_array_type (const char **pp, struct type *type,
                 struct objfile *objfile)
 {
   struct type *index_type, *element_type, *range_type;
@@ -3646,11 +3645,11 @@ read_array_type (char **pp, struct type *type,
    Also defines the symbols that represent the values of the type.  */
 
 static struct type *
-read_enum_type (char **pp, struct type *type,
+read_enum_type (const char **pp, struct type *type,
                struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  char *p;
+  const char *p;
   char *name;
   long n;
   struct symbol *sym;
@@ -3772,7 +3771,7 @@ read_enum_type (char **pp, struct type *type,
    FIXME.  */
 
 static struct type *
-read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
+read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
 {
   int type_bits;
   int nbits;
@@ -3834,7 +3833,8 @@ read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
 
   if (type_bits == 0)
     {
-      struct type *type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+      struct type *type = init_type (objfile, TYPE_CODE_VOID,
+                                    TARGET_CHAR_BIT, NULL);
       if (unsigned_type)
         TYPE_UNSIGNED (type) = 1;
       return type;
@@ -3847,7 +3847,8 @@ read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
 }
 
 static struct type *
-read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
+read_sun_floating_type (const char **pp, int typenums[2],
+                       struct objfile *objfile)
 {
   int nbits;
   int details;
@@ -3895,9 +3896,10 @@ read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
    If encounter garbage, set *BITS to -1 and return 0.  */
 
 static long
-read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
+read_huge_number (const char **pp, int end, int *bits,
+                 int twos_complement_bits)
 {
-  char *p = *pp;
+  const char *p = *pp;
   int sign = 1;
   int sign_bit = 0;
   long n = 0;
@@ -3932,7 +3934,7 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
         negative number.  */
 
       size_t len;
-      char *p1 = p;
+      const char *p1 = p;
 
       while ((c = *p1) >= '0' && c < '8')
        p1++;
@@ -4059,11 +4061,11 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
 }
 
 static struct type *
-read_range_type (char **pp, int typenums[2], int type_size,
+read_range_type (const char **pp, int typenums[2], int type_size,
                  struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  char *orig_pp = *pp;
+  const char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
   int n2bits, n3bits;
@@ -4144,7 +4146,7 @@ read_range_type (char **pp, int typenums[2], int type_size,
 
   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   if (self_subrange && n2 == 0 && n3 == 0)
-    return init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+    return init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
 
   /* If n3 is zero and n2 is positive, we want a floating type, and n2
      is the width in bytes.
@@ -4190,7 +4192,8 @@ read_range_type (char **pp, int typenums[2], int type_size,
      itself with range 0-127.  */
   else if (self_subrange && n2 == 0 && n3 == 127)
     {
-      struct type *type = init_integer_type (objfile, 1, 0, NULL);
+      struct type *type = init_integer_type (objfile, TARGET_CHAR_BIT,
+                                            0, NULL);
       TYPE_NOSIGN (type) = 1;
       return type;
     }
@@ -4267,7 +4270,7 @@ handle_true_range:
    if there is an error.  */
 
 static struct field *
-read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
+read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
           int *varargsp)
 {
   /* FIXME!  Remove this arbitrary limit!  */
@@ -4331,7 +4334,7 @@ static char *common_block_name;
    to remain after this function returns.  */
 
 void
-common_block_start (char *name, struct objfile *objfile)
+common_block_start (const char *name, struct objfile *objfile)
 {
   if (common_block_name != NULL)
     {
@@ -4814,10 +4817,10 @@ finish_global_stabs (struct objfile *objfile)
 
 /* Find the end of the name, delimited by a ':', but don't match
    ObjC symbols which look like -[Foo bar::]:bla.  */
-static char *
-find_name_end (char *name)
+static const char *
+find_name_end (const char *name)
 {
-  char *s = name;
+  const char *s = name;
 
   if (s[0] == '-' || *s == '+')
     {
This page took 0.071149 seconds and 4 git commands to generate.