From patchwork Sun Aug 4 02:51:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33951 Received: (qmail 18440 invoked by alias); 4 Aug 2019 02:51:17 -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 18379 invoked by uid 89); 4 Aug 2019 02:51:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.1 spammy=finder, Duplicate, *die X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.196.18) 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 gateway30.websitewelcome.com (Postfix) with ESMTP id 794D44268 for ; Sat, 3 Aug 2019 21:51:13 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id u6c5hmPx6dnCeu6c5hElN5; Sat, 03 Aug 2019 21:51:13 -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=zg4fI33D1uCFkie4N0U9WYOTd7Io85hv8iewRqfVvQ4=; b=eHpLb24PLBD8g6YA0RVC4EE+Y+ s6vnGWAkyvUJzG3B/drfAgJfLXuDlsf+ZaOQDm7pVnvvmrBzXe/3+8vdkQtYRnRgqfEX7Kqjsq2+e u84bf1MykeKNt+VdAPAEQ/oMU; 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 1hu6c5-002jdI-8g; Sat, 03 Aug 2019 21:51:13 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/4] Add obstack_strdup overload taking a std::string Date: Sat, 3 Aug 2019 20:51:09 -0600 Message-Id: <20190804025110.15135-4-tom@tromey.com> In-Reply-To: <20190804025110.15135-1-tom@tromey.com> References: <20190804025110.15135-1-tom@tromey.com> This adds an overload overload that takes a std::string, and changes a few spots in gdb to use it. 2019-08-03 Tom Tromey * symfile.c (reread_symbols): Use obstack_strdup. * stabsread.c (read_type): Use obstack_strdup. * gdb_obstack.h (obstack_strdup): New overload. * dwarf2read.c (dwarf2_compute_name, create_dwo_unit_in_dwp_v1) (create_dwo_unit_in_dwp_v2, build_error_marker_type) (dwarf2_canonicalize_name): Use obstack_strdup. * dbxread.c (read_dbx_symtab): Use obstack_strdup. * cp-support.c (inspect_type, replace_typedefs_qualified_name): Use obstack_strdup. --- gdb/ChangeLog | 12 ++++++++++++ gdb/cp-support.c | 10 +++------- gdb/dbxread.c | 5 ++--- gdb/dwarf2read.c | 25 ++++++++----------------- gdb/gdb_obstack.h | 10 ++++++++++ gdb/stabsread.c | 8 ++------ gdb/symfile.c | 4 +--- 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 562c6f155c7..b8b0fcc0ae2 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -244,7 +244,7 @@ inspect_type (struct demangle_parse_info *info, } len = buf.size (); - name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len); + name = obstack_strdup (&info->obstack, buf.string ()); /* Turn the result into a new tree. Note that this tree will contain pointers into NAME, so NAME cannot @@ -315,9 +315,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len); newobj.type = DEMANGLE_COMPONENT_NAME; - newobj.u.s_name.s - = (char *) obstack_copy0 (&info->obstack, - buf.c_str (), buf.size ()); + newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); newobj.u.s_name.len = buf.size (); if (inspect_type (info, &newobj, finder, data)) { @@ -379,9 +377,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, with a DEMANGLE_COMPONENT_NAME node containing the whole name. */ ret_comp->type = DEMANGLE_COMPONENT_NAME; - ret_comp->u.s_name.s - = (char *) obstack_copy0 (&info->obstack, - buf.c_str (), buf.size ()); + ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); ret_comp->u.s_name.len = buf.size (); inspect_type (info, ret_comp, finder, data); } diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 00eeb317dc4..0b370cd2e33 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -1440,9 +1440,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile) if (!new_name.empty ()) { sym_len = new_name.length (); - sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack, - new_name.c_str (), - sym_len); + sym_name = obstack_strdup (&objfile->objfile_obstack, + new_name); } } diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index c688d199d53..0f7ca54715b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10962,10 +10962,8 @@ dwarf2_compute_name (const char *name, INTERMEDIATE_NAME is already canonical, then we need to copy it to the appropriate obstack. */ if (canonical_name == NULL || canonical_name == intermediate_name.c_str ()) - name = ((const char *) - obstack_copy0 (&objfile->per_bfd->storage_obstack, - intermediate_name.c_str (), - intermediate_name.length ())); + name = obstack_strdup (&objfile->per_bfd->storage_obstack, + intermediate_name); else name = canonical_name; } @@ -12433,10 +12431,8 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name - = (const char *) obstack_copy0 (&objfile->objfile_obstack, - virtual_dwo_name.c_str (), - virtual_dwo_name.size ()); + dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, + virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = sections.abbrev; dwo_file->sections.line = sections.line; @@ -12631,10 +12627,8 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name - = (const char *) obstack_copy0 (&objfile->objfile_obstack, - virtual_dwo_name.c_str (), - virtual_dwo_name.size ()); + dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, + virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.abbrev, @@ -22118,8 +22112,7 @@ build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die) objfile_name (objfile), sect_offset_str (cu->header.sect_off), sect_offset_str (die->sect_off)); - saved = (char *) obstack_copy0 (&objfile->objfile_obstack, - message.c_str (), message.length ()); + saved = obstack_strdup (&objfile->objfile_obstack, message); return init_type (objfile, TYPE_CODE_ERROR, 0, saved); } @@ -22655,9 +22648,7 @@ dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, if (!canon_name.empty ()) { if (canon_name != name) - name = (const char *) obstack_copy0 (obstack, - canon_name.c_str (), - canon_name.length ()); + name = obstack_strdup (obstack, canon_name); } } diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h index 829e2f959c4..db849a06444 100644 --- a/gdb/gdb_obstack.h +++ b/gdb/gdb_obstack.h @@ -95,6 +95,16 @@ obstack_strdup (struct obstack *obstackp, const char *string) return (char *) obstack_copy0 (obstackp, string, strlen (string)); } +/* Duplicate STRING, returning an equivalent string that's allocated on the + obstack OBSTACKP. */ + +static inline char * +obstack_strdup (struct obstack *obstackp, const std::string &string) +{ + return (char *) obstack_copy0 (obstackp, string.c_str (), + string.size ()); +} + /* An obstack that frees itself on scope exit. */ struct auto_obstack : obstack { diff --git a/gdb/stabsread.c b/gdb/stabsread.c index b7524e71a35..23da5f94ebb 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1654,12 +1654,8 @@ again: std::string new_name = cp_canonicalize_string (name); if (!new_name.empty ()) - { - type_name - = (char *) obstack_copy0 (&objfile->objfile_obstack, - new_name.c_str (), - new_name.length ()); - } + type_name = obstack_strdup (&objfile->objfile_obstack, + new_name); } if (type_name == NULL) { diff --git a/gdb/symfile.c b/gdb/symfile.c index 4a429dad1ab..47d1919baa5 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2596,9 +2596,7 @@ reread_symbols (void) set_objfile_per_bfd (objfile); objfile->original_name - = (char *) obstack_copy0 (&objfile->objfile_obstack, - original_name.c_str (), - original_name.size ()); + = obstack_strdup (&objfile->objfile_obstack, original_name); /* Reset the sym_fns pointer. The ELF reader can change it based on whether .gdb_index is present, and we need it to