From patchwork Thu Jan 23 00:56:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37501 Received: (qmail 83001 invoked by alias); 23 Jan 2020 00:57:55 -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 80826 invoked by uid 89); 23 Jan 2020 00:57:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 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 autolearn=ham version=3.3.1 spammy=34107, 107813 X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.119) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:27 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 1296F364D0B6 for ; Wed, 22 Jan 2020 18:57:26 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQoIiNCa09jb7uQoIiTpUq; Wed, 22 Jan 2020 18:57:26 -0600 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=W5NbqIzXihPDSoc2OVAowcMbtJMfL96UL531CBtNVCE=; b=E6GlmAhDhzbSZZw3K2Bx2Bilnm EMmPAvkGNd6qRjJTZ0QrzFcJElwWCYG1Xos945zeMH/C4i+J2jheU9onoSpW72wJ9r+K/CR7F7zN6 15LD5VUj4N1XzMUGWglrp9o4j; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40828 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1iuQoH-004Kmd-Sq; Wed, 22 Jan 2020 17:57:25 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Date: Wed, 22 Jan 2020 17:56:58 -0700 Message-Id: <20200123005710.7978-27-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This changes the two new line_table methods to return unique_xmalloc_ptr. This removes a bit of manual memory management. 2020-01-22 Tom Tromey * dwarf2/read.c (struct line_header) : Return unique_xmalloc_ptr. (line_header::file_file_name): Update. (line_header::file_full_name): Update. (dw2_get_file_names_reader): Update. (macro_start_file): Update. Change-Id: I9442dba43882fb26097d0770a291eea2b03913a4 --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2/read.c | 37 ++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 153faac8238..b33f505362f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1078,13 +1078,14 @@ struct line_header table. Use COMP_DIR as the name of the current directory of the compilation. The result is allocated using xmalloc; the caller is responsible for freeing it. */ - char *file_full_name (int file, const char *comp_dir); + gdb::unique_xmalloc_ptr file_full_name (int file, + const char *comp_dir); /* Return file name relative to the compilation directory of file number I in this object's file name table. The result is allocated using xmalloc; the caller is responsible for freeing it. */ - char *file_file_name (int file); + gdb::unique_xmalloc_ptr file_file_name (int file); private: /* The include_directories table. Note these are observing @@ -3410,7 +3411,8 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, if (offset != 0) qfn->file_names[0] = xstrdup (fnd.name); for (int i = 0; i < lh->file_names_size (); ++i) - qfn->file_names[i + offset] = lh->file_full_name (i + 1, fnd.comp_dir); + qfn->file_names[i + offset] = lh->file_full_name (i + 1, + fnd.comp_dir).release (); qfn->real_names = NULL; lh_cu->v.quick->file_names = qfn; @@ -23797,7 +23799,7 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) /* Macro support. */ -char * +gdb::unique_xmalloc_ptr line_header::file_file_name (int file) { /* Is the file number a valid index into the line header's file name @@ -23810,9 +23812,11 @@ line_header::file_file_name (int file) { const char *dir = fe->include_dir (this); if (dir != NULL) - return concat (dir, SLASH_STRING, fe->name, (char *) NULL); + return gdb::unique_xmalloc_ptr (concat (dir, SLASH_STRING, + fe->name, + (char *) NULL)); } - return xstrdup (fe->name); + return make_unique_xstrdup (fe->name); } else { @@ -23827,23 +23831,24 @@ line_header::file_file_name (int file) complaint (_("bad file number in macro information (%d)"), file); - return xstrdup (fake_name); + return make_unique_xstrdup (fake_name); } } -char * +gdb::unique_xmalloc_ptr line_header::file_full_name (int file, const char *comp_dir) { /* Is the file number a valid index into the line header's file name table? Remember that file numbers start with one, not zero. */ if (is_valid_file_index (file)) { - char *relative = file_file_name (file); + gdb::unique_xmalloc_ptr relative = file_file_name (file); - if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL) + if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL) return relative; - return reconcat (relative, comp_dir, SLASH_STRING, - relative, (char *) NULL); + return gdb::unique_xmalloc_ptr (concat (comp_dir, SLASH_STRING, + relative.get (), + (char *) NULL)); } else return file_file_name (file); @@ -23857,7 +23862,7 @@ macro_start_file (struct dwarf2_cu *cu, struct line_header *lh) { /* File name relative to the compilation directory of this source file. */ - char *file_name = lh->file_file_name (file); + gdb::unique_xmalloc_ptr file_name = lh->file_file_name (file); if (! current_file) { @@ -23867,13 +23872,11 @@ macro_start_file (struct dwarf2_cu *cu, /* If we have no current file, then this must be the start_file directive for the compilation unit's main source file. */ - current_file = macro_set_main (macro_table, file_name); + current_file = macro_set_main (macro_table, file_name.get ()); macro_define_special (macro_table); } else - current_file = macro_include (current_file, line, file_name); - - xfree (file_name); + current_file = macro_include (current_file, line, file_name.get ()); return current_file; }