From patchwork Sun Aug 4 02:51:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33952 Received: (qmail 18551 invoked by alias); 4 Aug 2019 02:51:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18424 invoked by uid 89); 4 Aug 2019 02:51:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=3259, *die X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.198.13) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Aug 2019 02:51:14 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 97D93400C7C16 for ; Sat, 3 Aug 2019 21:15:37 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id u6c4hmPwqdnCeu6c4hElMp; Sat, 03 Aug 2019 21:51:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=D9VIFj4Ogice4p3w4alz2ecrLOg6fo7yaKW8rxDwRPE=; b=fG+bJDsror8PXaPugAwnilZDVu Sg0punrEBDTTatVpCFIyAH7vDNdzT45DQy2WAAe91kOvT0/GcjyJtlDvElM7+Nu1NoBWUm4cVOT4K VKpHZ7z66caEFFbu8M693eCYk; Received: from 97-122-178-82.hlrn.qwest.net ([97.122.178.82]:38564 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hu6c4-002jdI-Ff; Sat, 03 Aug 2019 21:51:12 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/4] Use obstack_strdup more Date: Sat, 3 Aug 2019 20:51:07 -0600 Message-Id: <20190804025110.15135-2-tom@tromey.com> In-Reply-To: <20190804025110.15135-1-tom@tromey.com> References: <20190804025110.15135-1-tom@tromey.com> This changes gdb to use obstack_strdup when appropriate, rather than the wordier obstack_copy0. gdb/ChangeLog 2019-08-03 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/ada-lang.c b/gdb/ada-lang.c index 15a7a902b82..badd3a33e31 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 3d90d632891..c688d199d53 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -9823,9 +9823,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; @@ -11087,9 +11085,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; } @@ -18999,10 +18995,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; @@ -19084,10 +19078,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); } } @@ -22742,9 +22733,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 c70a5ce34eb..4a429dad1ab 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;