From 021887d88a040cf39f3afbd7da10bbe3ff1ad6c3 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 18 May 2019 15:56:03 -0600 Subject: [PATCH] Use obstack_strdup more This changes gdb to use obstack_strdup when appropriate, rather than the wordier obstack_copy0. gdb/ChangeLog 2019-08-06 Tom Tromey * 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. --- gdb/ChangeLog | 23 +++++++++++++++++++++++ gdb/ada-lang.c | 3 +-- gdb/buildsym.c | 5 ++--- gdb/c-exp.y | 5 ++--- gdb/coffread.c | 11 +++-------- gdb/dwarf2read.c | 24 +++++++----------------- gdb/jit.c | 6 ++---- gdb/mdebugread.c | 12 ++++-------- gdb/namespace.c | 13 ++++--------- gdb/objfiles.c | 8 ++------ gdb/stabsread.c | 3 +-- gdb/symfile.c | 4 +--- gdb/typeprint.c | 5 ++--- gdb/xcoffread.c | 7 +++---- 14 files changed, 57 insertions(+), 72 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9724858474d..3974808c078 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,26 @@ +2019-08-06 Tom Tromey + + * 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 * unittests/help-doc-selftests.c: New file. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 65c358d4722..21a8e92462f 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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 diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 9a23c8f5254..8e05706c4be 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -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. */ diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 47e82b698b4..439a72a10de 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -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 diff --git a/gdb/coffread.c b/gdb/coffread.c index 0c7c4b58b6f..e24ab8d2f4b 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -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; diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index cde56688b34..ab974a54a32 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -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); diff --git a/gdb/jit.c b/gdb/jit.c index ce73e3fa5b1..87f8d8f8859 100644 --- 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; diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 7d0cbb71a91..18c1d1f7c9e 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -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) diff --git a/gdb/namespace.c b/gdb/namespace.c index 62c7214951a..04b49ef0e34 100644 --- a/gdb/namespace.c +++ b/gdb/namespace.c @@ -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; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 84d9681bf4e..7cbcbbd01b0 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -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 diff --git a/gdb/stabsread.c b/gdb/stabsread.c index a3fe6c99ca3..b7524e71a35 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -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. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index dff626e94d9..b927de5e9bf 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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"; diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 6a052005d4b..c87f6d13e02 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -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); } diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index f4892a8054f..0dacea44d12 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -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; -- 2.30.2