From patchwork Thu May 3 18:41:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 27088 Received: (qmail 43813 invoked by alias); 3 May 2018 18:41:58 -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 43777 invoked by uid 89); 3 May 2018 18:41:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4636, shadowing X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 May 2018 18:41:56 +0000 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0573830B8FAA for ; Thu, 3 May 2018 18:41:55 +0000 (UTC) Received: from theo.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B9030012A5 for ; Thu, 3 May 2018 18:41:54 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 1/8] Return unique_xmalloc_ptr for generate_c_for_variable_locations Date: Thu, 3 May 2018 11:41:46 -0700 Message-Id: <20180503184153.31183-2-keiths@redhat.com> In-Reply-To: <20180503184153.31183-1-keiths@redhat.com> References: <20180503184153.31183-1-keiths@redhat.com> X-IsSubscribed: yes This patch eliminates two cleanups in compile/ by changing generate_c_for_variable_locations so that it returns a unique_ptr. gdb/ChangeLog: * compile/compile-c-support.c (c_compute_program): Use unique_xmalloc_ptr to eliminate cleanup. * compile/compile-c-symbols.c (generate_c_for_variable_locations): Return a unique_xmalloc_ptr and eliminate cleanup. * compile/compile-internal.h (generate_c_for_variable_locations): Return unique_xmalloc_ptr and update description. --- gdb/compile/compile-c-support.c | 10 ++++------ gdb/compile/compile-c-symbols.c | 11 ++++------- gdb/compile/compile-internal.h | 9 +++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index e694648288..696bb9fced 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -351,17 +351,15 @@ c_compute_program (struct compile_instance *inst, and the user's code may only refer to globals. */ if (inst->scope != COMPILE_I_RAW_SCOPE) { - unsigned char *registers_used; int i; /* Generate the code to compute variable locations, but do it before generating the function header, so we can define the register struct before the function body. This requires a temporary stream. */ - registers_used = generate_c_for_variable_locations (context, - var_stream, gdbarch, - expr_block, expr_pc); - make_cleanup (xfree, registers_used); + gdb::unique_xmalloc_ptr registers_used + = generate_c_for_variable_locations (context, var_stream, gdbarch, + expr_block, expr_pc); buf.puts ("typedef unsigned int" " __attribute__ ((__mode__(__pointer__)))" @@ -382,7 +380,7 @@ c_compute_program (struct compile_instance *inst, mode, mode); } - generate_register_struct (&buf, gdbarch, registers_used); + generate_register_struct (&buf, gdbarch, registers_used.get ()); } add_code_header (inst->scope, &buf); diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 43de7df024..6987fa375e 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -708,24 +708,22 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler, /* See compile-internal.h. */ -unsigned char * +gdb::unique_xmalloc_ptr generate_c_for_variable_locations (struct compile_c_instance *compiler, string_file &stream, struct gdbarch *gdbarch, const struct block *block, CORE_ADDR pc) { - struct cleanup *outer; const struct block *static_block = block_static_block (block); - unsigned char *registers_used; /* If we're already in the static or global block, there is nothing to write. */ if (static_block == NULL || block == static_block) return NULL; - registers_used = XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch)); - outer = make_cleanup (xfree, registers_used); + gdb::unique_xmalloc_ptr registers_used + (XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch))); /* Ensure that a given name is only entered once. This reflects the reality of shadowing. */ @@ -745,7 +743,7 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler, { if (!symbol_seen (symhash.get (), sym)) generate_c_for_for_one_variable (compiler, stream, gdbarch, - registers_used, pc, sym); + registers_used.get (), pc, sym); } /* If we just finished the outermost block of a function, we're @@ -755,6 +753,5 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler, block = BLOCK_SUPERBLOCK (block); } - discard_cleanups (outer); return registers_used; } diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h index c92cb645f6..01beb1dddd 100644 --- a/gdb/compile/compile-internal.h +++ b/gdb/compile/compile-internal.h @@ -128,11 +128,12 @@ extern gcc_c_symbol_address_function gcc_symbol_address; extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe); /* Emit code to compute the address for all the local variables in - scope at PC in BLOCK. Returns a malloc'd vector, indexed by gdb - register number, where each element indicates if the corresponding - register is needed to compute a local variable. */ + scope at PC in BLOCK. Returns a vector, indexed by gdb register + number, where each element indicates if the corresponding register + is needed to compute a local variable. */ -extern unsigned char *generate_c_for_variable_locations +extern gdb::unique_xmalloc_ptr + generate_c_for_variable_locations (struct compile_c_instance *compiler, string_file &stream, struct gdbarch *gdbarch,