Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA v2 4/4] Use std::vector in struct catch_syscall_inferior_data
Date: Thu, 20 Jul 2017 16:58:00 -0000	[thread overview]
Message-ID: <87pocvkpu1.fsf@redhat.com> (raw)
In-Reply-To: <20170719203225.6714-5-tom@tromey.com> (Tom Tromey's message of	"Wed, 19 Jul 2017 14:32:25 -0600")

On Wednesday, July 19 2017, Tom Tromey wrote:

> This changes struct catch_syscall_inferior_data to use a std::vector
> rather than a VEC.  It also changes it to be allocated with new and
> destroyed with delete.

Thanks for the patch, Tom :-).

> 2017-07-18  Tom Tromey  <tom@tromey.com>
>
> 	* break-catch-syscall.c (struct catch_syscall_inferior_data)
> 	<syscalls_counts>: Now a std::vector.
> 	(get_catch_syscall_inferior_data): Use "new".
> 	(catch_syscall_inferior_data_cleanup): Use "delete".
> 	(insert_catch_syscall, remove_catch_syscall)
> 	(clear_syscall_counts): Update.
> ---
>  gdb/ChangeLog             |  9 +++++++++
>  gdb/break-catch-syscall.c | 47 ++++++++++++++++-------------------------------
>  2 files changed, 25 insertions(+), 31 deletions(-)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index fb953ed..4372853 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,12 @@
> +2017-07-18  Tom Tromey  <tom@tromey.com>
> +
> +	* break-catch-syscall.c (struct catch_syscall_inferior_data)
> +	<syscalls_counts>: Now a std::vector.
> +	(get_catch_syscall_inferior_data): Use "new".
> +	(catch_syscall_inferior_data_cleanup): Use "delete".
> +	(insert_catch_syscall, remove_catch_syscall)
> +	(clear_syscall_counts): Update.
> +
>  2017-07-17  Tom Tromey  <tom@tromey.com>
>  
>  	* break-catch-syscall.c (syscall_catchpoint)
> diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
> index ff0cb69..3df358b 100644
> --- a/gdb/break-catch-syscall.c
> +++ b/gdb/break-catch-syscall.c
> @@ -54,14 +54,14 @@ struct catch_syscall_inferior_data
>    int any_syscall_count;
>  
>    /* Count of each system call.  */
> -  VEC(int) *syscalls_counts;
> +  std::vector<int> syscalls_counts;
>  
>    /* This counts all syscall catch requests, so we can readily determine
>       if any catching is necessary.  */
>    int total_syscalls_count;
>  };
>  
> -static struct catch_syscall_inferior_data*
> +static struct catch_syscall_inferior_data *
>  get_catch_syscall_inferior_data (struct inferior *inf)
>  {
>    struct catch_syscall_inferior_data *inf_data;
> @@ -70,7 +70,7 @@ get_catch_syscall_inferior_data (struct inferior *inf)
>  	      inferior_data (inf, catch_syscall_inferior_data));
>    if (inf_data == NULL)
>      {
> -      inf_data = XCNEW (struct catch_syscall_inferior_data);
> +      inf_data = new struct catch_syscall_inferior_data ();
>        set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
>      }
>  
> @@ -80,7 +80,9 @@ get_catch_syscall_inferior_data (struct inferior *inf)
>  static void
>  catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
>  {
> -  xfree (arg);
> +  struct catch_syscall_inferior_data *inf_data
> +    = (struct catch_syscall_inferior_data *) arg;
> +  delete inf_data;

Are we still using the "newline between variable declaration and code"
rule?

>  }
>  
>  
> @@ -104,31 +106,17 @@ insert_catch_syscall (struct bp_location *bl)
>  	{
>            int elem;
>  
> -	  if (iter >= VEC_length (int, inf_data->syscalls_counts))
> -	    {
> -              int old_size = VEC_length (int, inf_data->syscalls_counts);
> -              uintptr_t vec_addr_offset
> -		= old_size * ((uintptr_t) sizeof (int));
> -              uintptr_t vec_addr;
> -              VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
> -              vec_addr = ((uintptr_t) VEC_address (int,
> -						  inf_data->syscalls_counts)
> -			  + vec_addr_offset);
> -              memset ((void *) vec_addr, 0,
> -                      (iter + 1 - old_size) * sizeof (int));
> -	    }
> -          elem = VEC_index (int, inf_data->syscalls_counts, iter);
> -          VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
> +	  if (iter >= inf_data->syscalls_counts.size ())
> +	    inf_data->syscalls_counts.resize (iter + 1);
> +	  ++inf_data->syscalls_counts[iter];

Great simplification.

>  	}
>      }
>  
>    return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
>  					inf_data->total_syscalls_count != 0,
>  					inf_data->any_syscall_count,
> -					VEC_length (int,
> -						    inf_data->syscalls_counts),
> -					VEC_address (int,
> -						     inf_data->syscalls_counts));
> +					inf_data->syscalls_counts.size (),
> +					inf_data->syscalls_counts.data ());
>  }
>  
>  /* Implement the "remove" breakpoint_ops method for syscall
> @@ -150,21 +138,18 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
>        for (int iter : c->syscalls_to_be_caught)
>  	{
>            int elem;
> -	  if (iter >= VEC_length (int, inf_data->syscalls_counts))
> +	  if (iter >= inf_data->syscalls_counts.size ())
>  	    /* Shouldn't happen.  */
>  	    continue;
> -          elem = VEC_index (int, inf_data->syscalls_counts, iter);
> -          VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
> +          --inf_data->syscalls_counts[iter];
>          }
>      }
>  
>    return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
>  					inf_data->total_syscalls_count != 0,
>  					inf_data->any_syscall_count,
> -					VEC_length (int,
> -						    inf_data->syscalls_counts),
> -					VEC_address (int,
> -						     inf_data->syscalls_counts));
> +					inf_data->syscalls_counts.size (),
> +					inf_data->syscalls_counts.data ());
>  }
>  
>  /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
> @@ -628,7 +613,7 @@ clear_syscall_counts (struct inferior *inf)
>  
>    inf_data->total_syscalls_count = 0;
>    inf_data->any_syscall_count = 0;
> -  VEC_free (int, inf_data->syscalls_counts);
> +  inf_data->syscalls_counts.clear ();
>  }
>  
>  static void
> -- 
> 2.9.3

LGTM.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


  reply	other threads:[~2017-07-20 16:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-19 20:53 [RFA v2 0/4] C++-ify some breakpoint subclasses a bit more Tom Tromey
2017-07-19 20:51 ` [RFA v2 1/4] C++-ify break-catch-sig Tom Tromey
2017-07-20 18:13   ` Sergio Durigan Junior
2017-07-21 19:53     ` Simon Marchi
2017-07-22  3:53     ` Tom Tromey
2017-07-21 19:43   ` Simon Marchi
2017-07-19 20:53 ` [RFA v2 3/4] Use std::vector in syscall_catchpoint Tom Tromey
2017-07-20 17:55   ` Sergio Durigan Junior
2017-07-21 20:37   ` Simon Marchi
2017-07-19 20:53 ` [RFA v2 2/4] C++-ify break-catch-throw Tom Tromey
2017-07-20 17:57   ` Sergio Durigan Junior
2017-07-21 20:20   ` Simon Marchi
2017-07-19 20:54 ` [RFA v2 4/4] Use std::vector in struct catch_syscall_inferior_data Tom Tromey
2017-07-20 16:58   ` Sergio Durigan Junior [this message]
2017-07-22  3:43     ` Tom Tromey
2017-07-21 20:49   ` Simon Marchi

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=87pocvkpu1.fsf@redhat.com \
    --to=sergiodj@redhat.com \
    --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