From 8084e579e114e607cb65482c43566e2c5c844bf6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 14 Feb 2020 09:24:42 -0700 Subject: [PATCH] Return unique_xmalloc_ptr from call_site_find_chain 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 * 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/ChangeLog b/gdb/ChangeLog index a79aabcbeed..0999ae23751 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +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. + 2020-02-14 Richard Biener * dwarf2/read.c (lnp_state_machine::handle_special_opcode): Apply CSE 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. -- 2.30.2