From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 206D63857C53 for ; Mon, 10 Aug 2020 00:48:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 206D63857C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 531971E554; Sun, 9 Aug 2020 20:48:55 -0400 (EDT) Subject: Re: [PP?] [PATCH 4/6] Transfer module ownership to do_module_cleanup To: Tom Tromey , gdb-patches@sourceware.org References: <20200809135258.8207-1-tom@tromey.com> <20200809135258.8207-5-tom@tromey.com> From: Simon Marchi Message-ID: <2be49232-0543-b73a-aa35-477a9f2a7895@simark.ca> Date: Sun, 9 Aug 2020 20:48:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200809135258.8207-5-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Aug 2020 00:48:57 -0000 On 2020-08-09 9:52 a.m., Tom Tromey wrote: > This changes the do_module_cleanup structure to simply hold on to the > module itself. This lets us remove most members from > do_module_cleanup. > > gdb/ChangeLog > 2020-08-08 Tom Tromey > > * compile/compile-object-run.c (struct do_module_cleanup): Add > parameters to constructor. Update destructor. > munmap_list_head, objfile_name_string>: Remove. > : New member. > (do_module_cleanup): Update. > (compile_object_run): Update. > --- > gdb/ChangeLog | 10 +++++ > gdb/compile/compile-object-run.c | 67 ++++++++++++-------------------- > 2 files changed, 35 insertions(+), 42 deletions(-) > > diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c > index 5a680a6723f..ac0a995fee9 100644 > --- a/gdb/compile/compile-object-run.c > +++ b/gdb/compile/compile-object-run.c > @@ -32,13 +32,16 @@ > > struct do_module_cleanup > { > - do_module_cleanup () = default; > + do_module_cleanup (int *ptr, compile_module_up &&mod) > + : executedp (ptr), > + module (std::move (mod)) > + { > + } > > ~do_module_cleanup () > { > - delete munmap_list_head; > - xfree (source_file); > - xfree (objfile_name_string); > + delete module->munmap_list_head; > + xfree (module->source_file); > } > > DISABLE_COPY_AND_ASSIGN (do_module_cleanup); > @@ -47,22 +50,8 @@ struct do_module_cleanup > The pointer may be NULL. */ > int *executedp; > > - /* .c file OBJFILE was built from. It needs to be xfree-d. */ > - char *source_file; > - > - /* Copy from struct compile_module. */ > - enum compile_i_scope_types scope; > - void *scope_data; > - > - /* Copy from struct compile_module. */ > - struct type *out_value_type; > - CORE_ADDR out_value_addr; > - > - /* Copy from struct compile_module. */ > - struct munmap_list *munmap_list_head; > - > - /* objfile_name of our objfile. */ > - char *objfile_name_string; > + /* The compile module. */ > + compile_module_up module; > }; > > /* Cleanup everything after the inferior function dummy frame gets > @@ -80,22 +69,26 @@ do_module_cleanup (void *arg, int registers_valid) > > /* This code cannot be in compile_object_run as OUT_VALUE_TYPE > no longer exists there. */ > - if (data->scope == COMPILE_I_PRINT_ADDRESS_SCOPE > - || data->scope == COMPILE_I_PRINT_VALUE_SCOPE) > + if (data->module->scope == COMPILE_I_PRINT_ADDRESS_SCOPE > + || data->module->scope == COMPILE_I_PRINT_VALUE_SCOPE) > { > struct value *addr_value; > - struct type *ptr_type = lookup_pointer_type (data->out_value_type); > + struct type *ptr_type > + = lookup_pointer_type (data->module->out_value_type); > > - addr_value = value_from_pointer (ptr_type, data->out_value_addr); > + addr_value = value_from_pointer (ptr_type, > + data->module->out_value_addr); > > /* SCOPE_DATA would be stale unless EXECUTEDP != NULL. */ > - compile_print_value (value_ind (addr_value), data->scope_data); > + compile_print_value (value_ind (addr_value), > + data->module->scope_data); > } > } > > + const char *objfile_name_s = objfile_name (data->module->objfile); > for (objfile *objfile : current_program_space->objfiles ()) > if ((objfile->flags & OBJF_USERLOADED) == 0 > - && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0)) > + && (strcmp (objfile_name (objfile), objfile_name_s) == 0)) > { > objfile->unlink (); > > @@ -106,10 +99,10 @@ do_module_cleanup (void *arg, int registers_valid) > } > > /* Delete the .c file. */ > - unlink (data->source_file); > + unlink (data->module->source_file); > > /* Delete the .o file. */ > - unlink (data->objfile_name_string); > + unlink (objfile_name_s); The objfile gets destroyed when unlinked. Is it guaranteed that objfile_name_s is still alive at that point? Simon