Use obstack_strdup more
authorTom Tromey <tom@tromey.com>
Sat, 18 May 2019 21:56:03 +0000 (15:56 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 7 Aug 2019 02:08:48 +0000 (20:08 -0600)
This changes gdb to use obstack_strdup when appropriate, rather than
the wordier obstack_copy0.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

* xcoffread.c (SYMNAME_ALLOC, process_xcoff_symbol): Use
obstack_strdup.
* typeprint.c (typedef_hash_table::find_global_typedef): Use
obstack_strdup.
* symfile.c (allocate_compunit_symtab): Use obstack_strdup.
* stabsread.c (common_block_start): Use obstack_strdup.
* objfiles.c (set_objfile_main_name, objfile): Use
obstack_strdup.
* namespace.c (add_using_directive): Use obstack_strdup.
* mdebugread.c (parse_symbol, parse_type): Use obstack_strdup.
* jit.c (finalize_symtab): Use obstack_strdup.
* dwarf2read.c (fixup_go_packaging, dwarf2_physname)
(guess_partial_die_structure_name, partial_die_info::fixup)
(dwarf2_name): Use obstack_strdup.
* coffread.c (coff_read_struct_type, coff_read_enum_type): Use
obstack_strdup.
* c-exp.y (scan_macro_expansion): Use obstack_strdup.
* buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use
obstack_strdup.
* ada-lang.c (ada_decode_symbol): Use obstack_strdup.

14 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/buildsym.c
gdb/c-exp.y
gdb/coffread.c
gdb/dwarf2read.c
gdb/jit.c
gdb/mdebugread.c
gdb/namespace.c
gdb/objfiles.c
gdb/stabsread.c
gdb/symfile.c
gdb/typeprint.c
gdb/xcoffread.c

index 9724858474dedc787262cd972de3703e129422e6..3974808c0782d16c1b3a0c855d15ba03e0c5c000 100644 (file)
@@ -1,3 +1,26 @@
+2019-08-06  Tom Tromey  <tom@tromey.com>
+
+       * xcoffread.c (SYMNAME_ALLOC, process_xcoff_symbol): Use
+       obstack_strdup.
+       * typeprint.c (typedef_hash_table::find_global_typedef): Use
+       obstack_strdup.
+       * symfile.c (allocate_compunit_symtab): Use obstack_strdup.
+       * stabsread.c (common_block_start): Use obstack_strdup.
+       * objfiles.c (set_objfile_main_name, objfile): Use
+       obstack_strdup.
+       * namespace.c (add_using_directive): Use obstack_strdup.
+       * mdebugread.c (parse_symbol, parse_type): Use obstack_strdup.
+       * jit.c (finalize_symtab): Use obstack_strdup.
+       * dwarf2read.c (fixup_go_packaging, dwarf2_physname)
+       (guess_partial_die_structure_name, partial_die_info::fixup)
+       (dwarf2_name): Use obstack_strdup.
+       * coffread.c (coff_read_struct_type, coff_read_enum_type): Use
+       obstack_strdup.
+       * c-exp.y (scan_macro_expansion): Use obstack_strdup.
+       * buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use
+       obstack_strdup.
+       * ada-lang.c (ada_decode_symbol): Use obstack_strdup.
+
 2019-08-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * unittests/help-doc-selftests.c: New file.
index 65c358d4722ec0a5a3cd2f30dc35a94c54bccdc5..21a8e92462f849a456d750989086b234d9b9d8a5 100644 (file)
@@ -1395,8 +1395,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
       gsymbol->ada_mangled = 1;
 
       if (obstack != NULL)
-       *resultp
-         = (const char *) obstack_copy0 (obstack, decoded, strlen (decoded));
+       *resultp = obstack_strdup (obstack, decoded);
       else
         {
          /* Sometimes, we can't find a corresponding objfile, in
index 9a23c8f52545299e664138163184334be7533bd3..8e05706c4be7ead2ce8dbae8d76f7c7c2a60e6a7 100644 (file)
@@ -1031,9 +1031,8 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
     {
       /* Reallocate the dirname on the symbol obstack.  */
       const char *comp_dir = m_comp_dir.get ();
-      COMPUNIT_DIRNAME (cu)
-       = (const char *) obstack_copy0 (&m_objfile->objfile_obstack,
-                                       comp_dir, strlen (comp_dir));
+      COMPUNIT_DIRNAME (cu) = obstack_strdup (&m_objfile->objfile_obstack,
+                                             comp_dir);
     }
 
   /* Save the debug format string (if any) in the symtab.  */
index 47e82b698b418e467f114b03dc1400c0a3e297a7..439a72a10de426d4e8cbf853178b4baef0720411 100644 (file)
@@ -2490,15 +2490,14 @@ static const struct token ident_tokens[] =
 static void
 scan_macro_expansion (char *expansion)
 {
-  char *copy;
+  const char *copy;
 
   /* We'd better not be trying to push the stack twice.  */
   gdb_assert (! cpstate->macro_original_text);
 
   /* Copy to the obstack, and then free the intermediate
      expansion.  */
-  copy = (char *) obstack_copy0 (&cpstate->expansion_obstack, expansion,
-                                strlen (expansion));
+  copy = obstack_strdup (&cpstate->expansion_obstack, expansion);
   xfree (expansion);
 
   /* Save the old lexptr value, so we can return to it when we're done
index 0c7c4b58b6fdc01c22093c533102b74a464ff087..e24ab8d2f4bb50a133778f319ea2395a0408c4a5 100644 (file)
@@ -2019,9 +2019,7 @@ coff_read_struct_type (int index, int length, int lastsym,
          list = newobj;
 
          /* Save the data.  */
-         list->field.name
-           = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                           name, strlen (name));
+         list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
          FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
                                                  &sub_aux, objfile);
          SET_FIELD_BITPOS (list->field, 8 * ms->c_value);
@@ -2037,9 +2035,7 @@ coff_read_struct_type (int index, int length, int lastsym,
          list = newobj;
 
          /* Save the data.  */
-         list->field.name
-           = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                           name, strlen (name));
+         list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
          FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
                                                  &sub_aux, objfile);
          SET_FIELD_BITPOS (list->field, ms->c_value);
@@ -2109,8 +2105,7 @@ coff_read_enum_type (int index, int length, int lastsym,
        case C_MOE:
          sym = allocate_symbol (objfile);
 
-         name = (char *) obstack_copy0 (&objfile->objfile_obstack, name,
-                                        strlen (name));
+         name = obstack_strdup (&objfile->objfile_obstack, name);
          SYMBOL_SET_LINKAGE_NAME (sym, name);
          SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
index cde56688b34341f11f4983b9a6462e58e0255a99..ab974a54a32ee46c15ce251f1af26e95b83fa5bb 100644 (file)
@@ -9806,9 +9806,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
     {
       struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
       const char *saved_package_name
-       = (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack,
-                                       package_name,
-                                       strlen (package_name));
+       = obstack_strdup (&objfile->per_bfd->storage_obstack, package_name);
       struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
                                     saved_package_name);
       struct symbol *sym;
@@ -11070,9 +11068,7 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
     retval = canon;
 
   if (need_copy)
-    retval = ((const char *)
-             obstack_copy0 (&objfile->per_bfd->storage_obstack,
-                            retval, strlen (retval)));
+    retval = obstack_strdup (&objfile->per_bfd->storage_obstack, retval);
 
   return retval;
 }
@@ -18982,10 +18978,8 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
            {
              struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
              struct_pdi->name
-               = ((const char *)
-                  obstack_copy0 (&objfile->per_bfd->storage_obstack,
-                                 actual_class_name,
-                                 strlen (actual_class_name)));
+               = obstack_strdup (&objfile->per_bfd->storage_obstack,
+                                 actual_class_name);
              xfree (actual_class_name);
            }
          break;
@@ -19067,10 +19061,7 @@ partial_die_info::fixup (struct dwarf2_cu *cu)
            base = demangled;
 
          struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-         name
-           = ((const char *)
-              obstack_copy0 (&objfile->per_bfd->storage_obstack,
-                             base, strlen (base)));
+         name = obstack_strdup (&objfile->per_bfd->storage_obstack, base);
          xfree (demangled);
        }
     }
@@ -22725,9 +22716,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
 
              /* FIXME: we already did this for the partial symbol... */
              DW_STRING (attr)
-               = ((const char *)
-                  obstack_copy0 (&objfile->per_bfd->storage_obstack,
-                                 demangled, strlen (demangled)));
+               = obstack_strdup (&objfile->per_bfd->storage_obstack,
+                                 demangled);
              DW_STRING_IS_CANONICAL (attr) = 1;
              xfree (demangled);
 
index ce73e3fa5b1c66f154034daa3f25b2439d12177e..87f8d8f88597d924eb878cabaccae5cd5488b731 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -700,10 +700,8 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
       SYMBOL_BLOCK_VALUE (block_name) = new_block;
 
-      block_name->ginfo.name
-       = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                       gdb_block_iter->name,
-                                       strlen (gdb_block_iter->name));
+      block_name->ginfo.name = obstack_strdup (&objfile->objfile_obstack,
+                                              gdb_block_iter->name);
 
       BLOCK_FUNCTION (new_block) = block_name;
 
index 7d0cbb71a911e52bd70407686e956a83a082582e..18c1d1f7c9ed508125acfba032b892f14c82902c 100644 (file)
@@ -1066,8 +1066,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
                enum_sym = allocate_symbol (mdebugread_objfile);
                SYMBOL_SET_LINKAGE_NAME
                  (enum_sym,
-                  (char *) obstack_copy0 (&mdebugread_objfile->objfile_obstack,
-                                          f->name, strlen (f->name)));
+                  obstack_strdup (&mdebugread_objfile->objfile_obstack,
+                                  f->name));
                SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
                SYMBOL_TYPE (enum_sym) = t;
                SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
@@ -1688,9 +1688,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
          else if (TYPE_NAME (tp) == NULL
                   || strcmp (TYPE_NAME (tp), name) != 0)
            TYPE_NAME (tp)
-             = ((const char *)
-                obstack_copy0 (&mdebugread_objfile->objfile_obstack,
-                               name, strlen (name)));
+             = obstack_strdup (&mdebugread_objfile->objfile_obstack, name);
        }
     }
 
@@ -1726,9 +1724,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
          if (TYPE_NAME (tp) == NULL
              || strcmp (TYPE_NAME (tp), name) != 0)
            TYPE_NAME (tp)
-             = ((const char *)
-                obstack_copy0 (&mdebugread_objfile->objfile_obstack,
-                               name, strlen (name)));
+             = obstack_strdup (&mdebugread_objfile->objfile_obstack, name);
        }
     }
   if (t->bt == btTypedef)
index 62c7214951a765fdc8e56932fbf3f2e2a5984569..04b49ef0e34abca53e46552f14443f86101cf160 100644 (file)
@@ -87,10 +87,8 @@ add_using_directive (struct using_direct **using_directives,
 
   if (copy_names)
     {
-      newobj->import_src
-       = (const char *) obstack_copy0 (obstack, src, strlen (src));
-      newobj->import_dest
-       = (const char *) obstack_copy0 (obstack, dest, strlen (dest));
+      newobj->import_src = obstack_strdup (obstack, src);
+      newobj->import_dest = obstack_strdup (obstack, dest);
     }
   else
     {
@@ -99,15 +97,12 @@ add_using_directive (struct using_direct **using_directives,
     }
 
   if (alias != NULL && copy_names)
-    newobj->alias
-      = (const char *) obstack_copy0 (obstack, alias, strlen (alias));
+    newobj->alias = obstack_strdup (obstack, alias);
   else
     newobj->alias = alias;
 
   if (declaration != NULL && copy_names)
-    newobj->declaration
-      = (const char *) obstack_copy0 (obstack, declaration,
-                                     strlen (declaration));
+    newobj->declaration = obstack_strdup (obstack, declaration);
   else
     newobj->declaration = declaration;
 
index 84d9681bf4ea69bd9181497f64e76d13521e7084..7cbcbbd01b0e9b776afac6180b3f2d733d156520 100644 (file)
@@ -166,8 +166,7 @@ set_objfile_main_name (struct objfile *objfile,
   if (objfile->per_bfd->name_of_main == NULL
       || strcmp (objfile->per_bfd->name_of_main, name) != 0)
     objfile->per_bfd->name_of_main
-      = (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack, name,
-                                     strlen (name));
+      = obstack_strdup (&objfile->per_bfd->storage_obstack, name);
   objfile->per_bfd->language_of_main = lang;
 }
 
@@ -356,10 +355,7 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
       name_holder = gdb_abspath (name);
       expanded_name = name_holder.get ();
     }
-  original_name
-    = (char *) obstack_copy0 (&objfile_obstack,
-                             expanded_name,
-                             strlen (expanded_name));
+  original_name = obstack_strdup (&objfile_obstack, expanded_name);
 
   /* Update the per-objfile information that comes from the bfd, ensuring
      that any data that is reference is saved in the per-objfile data
index a3fe6c99ca3529bed7b3fb239b0c4b33c6445f40..b7524e71a35f162ebf088658221900c35ab7a199 100644 (file)
@@ -4293,8 +4293,7 @@ common_block_start (const char *name, struct objfile *objfile)
     }
   common_block = *get_local_symbols ();
   common_block_i = common_block ? common_block->nsyms : 0;
-  common_block_name = (char *) obstack_copy0 (&objfile->objfile_obstack, name,
-                                             strlen (name));
+  common_block_name = obstack_strdup (&objfile->objfile_obstack, name);
 }
 
 /* Process a N_ECOMM symbol.  */
index dff626e94d91fc2f7f2b83241af62466e5be16b9..b927de5e9bfe163415fc5b94590cbf4fb008549d 100644 (file)
@@ -2882,9 +2882,7 @@ allocate_compunit_symtab (struct objfile *objfile, const char *name)
      Just save the basename to avoid path issues (too long for display,
      relative vs absolute, etc.).  */
   saved_name = lbasename (name);
-  cu->name
-    = (const char *) obstack_copy0 (&objfile->objfile_obstack, saved_name,
-                                   strlen (saved_name));
+  cu->name = obstack_strdup (&objfile->objfile_obstack, saved_name);
 
   COMPUNIT_DEBUGFORMAT (cu) = "unknown";
 
index 6a052005d4bf484db79f209e5b1a74ed6755d8a9..c87f6d13e02ec5aa191027ce3f5795c6352df639 100644 (file)
@@ -325,9 +325,8 @@ typedef_hash_table::find_global_typedef (const struct type_print_options *flags,
 
   if (applied != NULL)
     {
-      new_tf->name
-       = (const char *) obstack_copy0 (&flags->global_typedefs->m_storage,
-                                       applied, strlen (applied));
+      new_tf->name = obstack_strdup (&flags->global_typedefs->m_storage,
+                                    applied);
       xfree (applied);
     }
 
index f4892a8054f1e384f0849f2c237f70662ae8b4c7..0dacea44d12799238cb409be9969355bbff12578 100644 (file)
@@ -1539,8 +1539,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
 
 
 #define        SYMNAME_ALLOC(NAME, ALLOCED)    \
-  ((ALLOCED) ? (NAME) : obstack_copy0 (&objfile->objfile_obstack, \
-                                      (NAME), strlen (NAME)))
+  ((ALLOCED) ? (NAME) : obstack_strdup (&objfile->objfile_obstack, \
+                                       (NAME)))
 
 
 /* process one xcoff symbol.  */
@@ -1586,8 +1586,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
          will be patched with the type from its stab entry later on in
          patch_block_stabs (), unless the file was compiled without -g.  */
 
-      SYMBOL_SET_LINKAGE_NAME (sym, ((const char *)
-                                    SYMNAME_ALLOC (name, symname_alloced)));
+      SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
       SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
 
       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;