Return unique_xmalloc_ptr from call_site_find_chain
authorTom Tromey <tromey@adacore.com>
Fri, 14 Feb 2020 16:24:42 +0000 (09:24 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 14 Feb 2020 19:38:04 +0000 (12:38 -0700)
call_site_find_chain returns a pointer that the caller must
deallocate.  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
gdb/dwarf2/frame-tailcall.c
gdb/dwarf2/loc.c
gdb/dwarf2/loc.h

index a79aabcbeed6791d9ee389af766c4b6877fd3580..0999ae237515af3f0f2a1ee44803f3d866ccc32c 100644 (file)
@@ -1,3 +1,12 @@
+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.
+
 2020-02-14  Richard Biener  <rguenther@suse.de>
 
        * dwarf2/read.c (lnp_state_machine::handle_special_opcode): Apply CSE
index 3dc300df60a9faad468db100c9c79eb7c97b5c63..2d219f13f9dddabd7b247de214b3e3a600202e99 100644 (file)
@@ -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)
     {
index 7f27e453b30347e50f9b2673615162f7635c85a3..a9523e9f7ee400a4505443ad489cacba8dc976fa 100644 (file)
@@ -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
     {
index 2cc7e066a339451ef5b10b52ac257f7a02764976..8fff663ebf9cd85a21997e36f7b5e1e859e2a29d 100644 (file)
@@ -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.
This page took 0.031252 seconds and 4 git commands to generate.