Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PP?] [PATCH 4/6] Transfer module ownership to do_module_cleanup
Date: Sun, 9 Aug 2020 20:48:46 -0400	[thread overview]
Message-ID: <2be49232-0543-b73a-aa35-477a9f2a7895@simark.ca> (raw)
In-Reply-To: <20200809135258.8207-5-tom@tromey.com>

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  <tom@tromey.com>
> 
> 	* compile/compile-object-run.c (struct do_module_cleanup): Add
> 	parameters to constructor.  Update destructor.
> 	<source_file, scope, scope_data, out_value_type, out_value_addr,
> 	munmap_list_head, objfile_name_string>: Remove.
> 	<module>: 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


  reply	other threads:[~2020-08-10  0:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 13:52 [PATCH 0/6] Avoid manual memory management in gdb/compile/ Tom Tromey
2020-08-09 13:52 ` [PATCH 1/6] Remove some manual memory management from compile interface Tom Tromey
2020-08-09 22:34   ` Simon Marchi
2020-09-19 23:45     ` Tom Tromey
2020-09-19 23:52       ` Simon Marchi
2020-09-23 12:56         ` Tom Tromey
2020-08-09 13:52 ` [PATCH 2/6] Use new/delete for do_module_cleanup Tom Tromey
2020-08-09 22:45   ` [PP?] " Simon Marchi
2020-09-23 13:36     ` Tom Tromey
2020-08-09 13:52 ` [PATCH 3/6] Introduce and use compile_module_up Tom Tromey
2020-08-09 13:52 ` [PATCH 4/6] Transfer module ownership to do_module_cleanup Tom Tromey
2020-08-10  0:48   ` Simon Marchi [this message]
2020-09-23 14:55     ` [PP?] " Tom Tromey
2020-08-09 13:52 ` [PATCH 5/6] Simplify compile_module cleanup Tom Tromey
2020-08-09 13:52 ` [PATCH 6/6] Avoid manual memory management of argv arrays in gdb/compile Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2be49232-0543-b73a-aa35-477a9f2a7895@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox