This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch 2/4] hw watchpoints across fork()


> Date: Mon, 6 Dec 2010 12:13:01 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> 
> --- a/gdb/i386-nat.c
> +++ b/gdb/i386-nat.c
> @@ -220,16 +220,50 @@ static int i386_handle_nonaligned_watchpoint (i386_wp_op_t what,
>  
>  /* Implementation.  */
>  
> +/* Per-inferior data key.  */
> +static const struct inferior_data *i386_inferior_data;
> +
> +struct i386_inferior_data
> +  {
> +    /* Copy of i386 hardware debug registers for performance reasons.  */
> +    struct dr_mirror dr_mirror;
> +  };
> +
> +static struct i386_inferior_data *
> +i386_inferior_data_get (void)
> +{
> +  static struct i386_inferior_data inf_data_local;
> +  struct inferior *inf = current_inferior ();
> +  struct i386_inferior_data *inf_data = &inf_data_local;
> +  static struct i386_inferior_data *detached_inf_data;
> +  static int detached_inf_pid = -1;

The whole dance with inf_data seems unecessarily complicated to me.
Why not...

> +
> +  if (inf->pid != ptid_get_pid (inferior_ptid))
> +    {
> +      if (detached_inf_pid != ptid_get_pid (inferior_ptid))
> +	{
> +	  xfree (detached_inf_data);
> +	  detached_inf_pid = ptid_get_pid (inferior_ptid);
> +	  detached_inf_data = xmalloc (sizeof (*detached_inf_data));

Huh, free and immediately malloc?

> +
> +	  /* Forked processes get a copy of the debug registers.  */
> +	  memcpy (detached_inf_data, inf_data, sizeof (*detached_inf_data));
> +	}
> +
> +      gdb_assert (detached_inf_data != NULL);
> +      inf_data = detached_inf_data;

Simply return detached_inf_data here.

> +    }
> +
> +  return inf_data;

And return &inf_data_local here?  But why are you returning pointers
to static storage in the first place?  I'm abviously missing the point
of this function.  Can you explain?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]