From patchwork Fri Feb 14 16:25:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 38070 Received: (qmail 92935 invoked by alias); 14 Feb 2020 16:25:37 -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 92926 invoked by uid 89); 14 Feb 2020 16:25:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2020 16:25:35 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4C6A256090; Fri, 14 Feb 2020 11:25:33 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8J8HMTCbXCo8; Fri, 14 Feb 2020 11:25:33 -0500 (EST) Received: from murgatroyd.Home (75-166-123-50.hlrn.qwest.net [75.166.123.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 07FC25608F; Fri, 14 Feb 2020 11:25:32 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Return unique_xmalloc_ptr from call_site_find_chain Date: Fri, 14 Feb 2020 09:25:31 -0700 Message-Id: <20200214162531.2807-1-tromey@adacore.com> MIME-Version: 1.0 call_site_find_chain returns a pointer that the caller must deallocated. It seemed better here to return a unique_xmalloc_ptr instead. gdb/ChangeLog 2020-02-14 Tom Tromey * dwarf2/frame-tailcall.c (dwarf2_tailcall_sniffer_first): Update. * dwarf2/loc.h (call_site_find_chain): Return unique_xmalloc_ptr. * dwarf2/loc.c (call_site_find_chain_1): Return unique_xmalloc_ptr. (call_site_find_chain): Likewise. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2/frame-tailcall.c | 11 ++++------- gdb/dwarf2/loc.c | 16 +++++++--------- gdb/dwarf2/loc.h | 5 ++--- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/gdb/dwarf2/frame-tailcall.c b/gdb/dwarf2/frame-tailcall.c index 3dc300df60a..2d219f13f9d 100644 --- a/gdb/dwarf2/frame-tailcall.c +++ b/gdb/dwarf2/frame-tailcall.c @@ -368,7 +368,7 @@ dwarf2_tailcall_sniffer_first (struct frame_info *this_frame, int prev_sp_p = 0; CORE_ADDR this_pc; struct gdbarch *prev_gdbarch; - struct call_site_chain *chain = NULL; + gdb::unique_xmalloc_ptr chain; struct tailcall_cache *cache; gdb_assert (*tailcall_cachep == NULL); @@ -409,16 +409,13 @@ dwarf2_tailcall_sniffer_first (struct frame_info *this_frame, /* Ambiguous unwind or unambiguous unwind verified as matching. */ if (chain == NULL || chain->length == 0) - { - xfree (chain); - return; - } + return; cache = cache_new_ref1 (this_frame); *tailcall_cachep = cache; - cache->chain = chain; + cache->chain = chain.release (); cache->prev_pc = prev_pc; - cache->chain_levels = pretended_chain_levels (chain); + cache->chain_levels = pretended_chain_levels (cache->chain); cache->prev_sp_p = prev_sp_p; if (cache->prev_sp_p) { diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 7f27e453b30..a9523e9f7ee 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1091,11 +1091,10 @@ chain_candidate (struct gdbarch *gdbarch, /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the assumed frames between them use GDBARCH. Use depth first search so we can keep single CHAIN of call_site's back to CALLER_PC. Function recursion - would have needless GDB stack overhead. Caller is responsible for xfree of - the returned result. Any unreliability results in thrown - NO_ENTRY_VALUE_ERROR. */ + would have needless GDB stack overhead. Any unreliability results + in thrown NO_ENTRY_VALUE_ERROR. */ -static struct call_site_chain * +static gdb::unique_xmalloc_ptr call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc, CORE_ADDR callee_pc) { @@ -1210,19 +1209,18 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc, paddress (gdbarch, callee_pc)); } - return retval.release (); + return retval; } /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the assumed frames between them use GDBARCH. If valid call_site_chain cannot be - constructed return NULL. Caller is responsible for xfree of the returned - result. */ + constructed return NULL. */ -struct call_site_chain * +gdb::unique_xmalloc_ptr call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc, CORE_ADDR callee_pc) { - struct call_site_chain *retval = NULL; + gdb::unique_xmalloc_ptr retval; try { diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index 2cc7e066a33..8fff663ebf9 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -277,9 +277,8 @@ struct call_site_chain }; struct call_site_stuff; -extern struct call_site_chain *call_site_find_chain (struct gdbarch *gdbarch, - CORE_ADDR caller_pc, - CORE_ADDR callee_pc); +extern gdb::unique_xmalloc_ptr call_site_find_chain + (struct gdbarch *gdbarch, CORE_ADDR caller_pc, CORE_ADDR callee_pc); /* A helper function to convert a DWARF register to an arch register. ARCH is the architecture.