diff mbox

Return unique_xmalloc_ptr from call_site_find_chain

Message ID 20200214162531.2807-1-tromey@adacore.com
State New
Headers show

Commit Message

Tom Tromey Feb. 14, 2020, 4:25 p.m. UTC
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  <tromey@adacore.com>

	* 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(-)

Comments

Simon Marchi Feb. 14, 2020, 7:14 p.m. UTC | #1
On 2020-02-14 11:25 a.m., Tom Tromey wrote:
> call_site_find_chain returns a pointer that the caller must
> deallocated.  It seemed better here to return a unique_xmalloc_ptr

deallocated -> deallocate

Otherwise, LGTM.

Simon
diff mbox

Patch

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<call_site_chain> 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_chain>
 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_chain>
 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<call_site_chain> 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_chain> 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.