Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <ghost@cs.msu.su>
To: Nick Roberts <nickrob@snap.net.nz>
Cc: Daniel Jacobowitz <drow@false.org>,  gdb-patches@sources.redhat.com
Subject: Re: [PATCH] MI: lvalues and variable_editable
Date: Sat, 03 Nov 2007 09:48:00 -0000	[thread overview]
Message-ID: <200711031247.54239.ghost@cs.msu.su> (raw)
In-Reply-To: <18220.15856.752225.9086@kahikatea.snap.net.nz>

On Saturday 03 November 2007 12:22:56 Nick Roberts wrote:
>  > > In that case for such a varobj, var->value == NULL must indicate that the
>  > > memory was inaccessible at the _last_ update, or creation, and it may no
>  > > longer be inaccessible.  Describing it as "noneditable" may then be a bit
>  > > misleading.
>  > 
>  > The next time it's -var-update'd it may get a new value; presumably
>  > the IDE does that periodically.
> 
> I guess, in that respect it's no different to -var-evaluate-expression.  Here's
> my latest patch for varobj.c.  I've removed the test for var->value != NULL in
> varobj_set_value as it's already in varobj_editable_p.  I've also moved the
> test for var->root->is_valid from varobj_get_attributes to varobj_editable_p.
> This patch would require two x two changes to the testsuite:
> 
> FAIL: gdb.mi/mi2-var-child.exp: is weird.int_ptr_ptr.*int_ptr_ptr editable
> FAIL: gdb.mi/mi2-var-child.exp: is weird.int_ptr_ptr.*int_ptr_ptr.**int_ptr_ptr 
> editable
> 
> editable -> noneditable
> 
> likewise for mi-var-child.exp
> 
> There's also an independent change to mi_cmd_var_assign in mi-cmd-var.c that I
> think makes it simpler.
> 
> -- 
> Nick                                           http://www.inet.net.nz/~nickrob
> 
> 
> 2007-11-03  Nick Roberts  <nickrob@snap.net.nz>
> 
>         * varobj.c (c_variable_editable, cplus_variable_editable)
>         (java_variable_editable, variable_editable): Delete.
>         (varobj_editable_p): Replace above functions with one language
>         independent function.  Check for an lvalue.
>         (varobj_get_attributes, varobj_set_value): Use varobj_editable_p.
>         (struct language_specific): Delete variable_editable field.
> 
>         * mi-cmd-var.c (mi_cmd_var_assign): Simplify.
> 
> 
> *** varobj.c    27 Oct 2007 09:51:19 +1300      1.96
> --- varobj.c    03 Nov 2007 21:50:19 +1300      

> *************** varobj_set_value (struct varobj *var, ch
> *** 887,940 ****
>     struct value *value;
>     int saved_input_radix = input_radix;
>   
> !   if (var->value != NULL && variable_editable (var))
> !     {
> !       char *s = expression;
> !       int i;
>   
> !       input_radix = 10;               /* ALWAYS reset to decimal temporarily */
> !       exp = parse_exp_1 (&s, 0, 0);
> !       if (!gdb_evaluate_expression (exp, &value))
> !       {
> !         /* We cannot proceed without a valid expression. */
> !         xfree (exp);
> !         return 0;
> !       }
> ! 
> !       /* All types that are editable must also be changeable.  */
> !       gdb_assert (varobj_value_is_changeable_p (var));
> ! 
> !       /* The value of a changeable variable object must not be lazy.  */
> !       gdb_assert (!value_lazy (var->value));
> ! 
> !       /* Need to coerce the input.  We want to check if the
> !        value of the variable object will be different
> !        after assignment, and the first thing value_assign
> !        does is coerce the input.
> !        For example, if we are assigning an array to a pointer variable we
> !        should compare the pointer with the the array's address, not with the
> !        array's content.  */
> !       value = coerce_array (value);
> ! 
> !       /* The new value may be lazy.  gdb_value_assign, or 
> !        rather value_contents, will take care of this.
> !        If fetching of the new value will fail, gdb_value_assign
> !        with catch the exception.  */
> !       if (!gdb_value_assign (var->value, value, &val))
> !       return 0;
> !      
> !       /* If the value has changed, record it, so that next -var-update can
> !        report this change.  If a variable had a value of '1', we've set it
> !        to '333' and then set again to '1', when -var-update will report this
> !        variable as changed -- because the first assignment has set the
> !        'updated' flag.  There's no need to optimize that, because return value
> !        of -var-update should be considered an approximation.  */
> !       var->updated = install_new_value (var, val, 0 /* Compare values. */);
> !       input_radix = saved_input_radix;
> !       return 1;
>       }
>   
> !   return 0;
>   }
>   
>   /* Returns a malloc'ed list with all root variable objects */
> --- 872,920 ----
>     struct value *value;
>     int saved_input_radix = input_radix;

I suggest


	gdb_assert (varobj_is_editable_p (var));

here, so clearly document the assumptions the trailing
code makes.


> !   char *s = expression;
> !   int i;
>   
> !   input_radix = 10;           /* ALWAYS reset to decimal temporarily */
> !   exp = parse_exp_1 (&s, 0, 0);
> !   if (!gdb_evaluate_expression (exp, &value))
> !     {
> !       /* We cannot proceed without a valid expression. */
> !       xfree (exp);
> !       return 0;
>       }
>   
> !   /* All types that are editable must also be changeable.  */
> !   gdb_assert (varobj_value_is_changeable_p (var));
> ! 
> !   /* The value of a changeable variable object must not be lazy.  */
> !   gdb_assert (!value_lazy (var->value));
> ! 
> !   /* Need to coerce the input.  We want to check if the
> !      value of the variable object will be different
> !      after assignment, and the first thing value_assign
> !      does is coerce the input.
> !      For example, if we are assigning an array to a pointer variable we
> !      should compare the pointer with the the array's address, not with the
> !      array's content.  */
> !   value = coerce_array (value);
> ! 
> !   /* The new value may be lazy.  gdb_value_assign, or 
> !      rather value_contents, will take care of this.
> !      If fetching of the new value will fail, gdb_value_assign
> !      with catch the exception.  */
> !   if (!gdb_value_assign (var->value, value, &val))
> !     return 0;
> !      
> !   /* If the value has changed, record it, so that next -var-update can
> !      report this change.  If a variable had a value of '1', we've set it
> !      to '333' and then set again to '1', when -var-update will report this
> !      variable as changed -- because the first assignment has set the
> !      'updated' flag.  There's no need to optimize that, because return value
> !      of -var-update should be considered an approximation.  */
> !   var->updated = install_new_value (var, val, 0 /* Compare values. */);
> !   input_radix = saved_input_radix;
> !   return 1;
>   }
>   
>   /* Returns a malloc'ed list with all root variable objects */

> + int
> + varobj_editable_p (struct varobj *var)
> + {
> +   struct type *type;
> +   struct value *value;
> + 
> +   if (CPLUS_FAKE_CHILD (var))
> +     return 0;
> + 
> +   if (!(var->root->is_valid && var->value && VALUE_LVAL(var->value)))
> +     return 0;

I believe this test captures CPLUS_FAKE_CHILD as well, so you don't
need to have separate test for that.

> +   type = get_value_type (var);
> + 
> +   switch (TYPE_CODE (type))
> +     {
> +     case TYPE_CODE_STRUCT:
> +     case TYPE_CODE_UNION:
> +     case TYPE_CODE_ARRAY:
> +     case TYPE_CODE_FUNC:
> +     case TYPE_CODE_METHOD:
> +       return 0;
> +       break;
> + 
> +     default:
> +       return 1;
> +       break;
> +     }
> + }
> + 
>   /* Return non-zero if changes in value of VAR
>      must be detected and reported by -var-update.
>      Return zero is -var-update should never report


> *** mi-cmd-var.c        03 Nov 2007 22:17:04 +1300      1.40
> --- mi-cmd-var.c        03 Nov 2007 12:24:24 +1300      
> *************** mi_cmd_var_assign (char *command, char *
> *** 512,527 ****
>       error (_("mi_cmd_var_assign: Variable object not found"));
>   
>     /* FIXME: define masks for attributes */
> !   if (!(varobj_get_attributes (var) & 0x00000001))
>       error (_("mi_cmd_var_assign: Variable object is not editable"));
>   
> !   expression = xstrdup (argv[1]);
> ! 
> !   if (!varobj_set_value (var, expression))
> !     error (_("mi_cmd_var_assign: Could not assign expression to variable object"));
>   
> !   ui_out_field_string (uiout, "value", varobj_get_value (var));
> !   return MI_CMD_DONE;
>   }
>   
>   enum mi_cmd_result
> --- 512,529 ----
>       error (_("mi_cmd_var_assign: Variable object not found"));
>   
>     /* FIXME: define masks for attributes */
> !   if (!varobj_editable_p (var))
>       error (_("mi_cmd_var_assign: Variable object is not editable"));

I presume the FIXME is now stale?

> +   else
> +     {
> +       expression = xstrdup (argv[1]);
>   
> !       if (!varobj_set_value (var, expression))
> !       error (_("mi_cmd_var_assign: Could not assign expression to variable object"));
>   
> !       ui_out_field_string (uiout, "value", varobj_get_value (var));
> !       return MI_CMD_DONE;
> !     }
>   }
>   
>   enum mi_cmd_result

Aside from the minor points above, I don't have any objections to this patch. Dan,
what would you say?

- Volodya

 



  reply	other threads:[~2007-11-03  9:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 22:59 Nick Roberts
2007-10-27  6:29 ` Vladimir Prus
2007-10-27 12:15   ` Nick Roberts
2007-10-27 14:22     ` Vladimir Prus
2007-10-30  8:55       ` Nick Roberts
2007-10-30  9:55         ` Vladimir Prus
2007-10-30 11:15           ` Nick Roberts
2007-10-30 13:41             ` Daniel Jacobowitz
2007-10-30 18:30               ` Nick Roberts
2007-10-30 19:26                 ` Daniel Jacobowitz
2007-10-30 19:27                   ` Daniel Jacobowitz
2007-11-01  4:42               ` Nick Roberts
2007-10-31 14:16             ` Vladimir Prus
2007-11-01  4:52               ` Nick Roberts
2007-11-01  7:52                 ` Vladimir Prus
2007-11-01 15:40                   ` Daniel Jacobowitz
2007-11-02  4:23                     ` Nick Roberts
2007-11-02 11:36                       ` Daniel Jacobowitz
2007-11-03  9:23                         ` Nick Roberts
2007-11-03  9:48                           ` Vladimir Prus [this message]
2007-11-03 23:14                             ` Nick Roberts
2007-11-20 13:39                               ` Vladimir Prus
2007-11-03 11:09                           ` Nick Roberts
2007-11-20 13:55                           ` Daniel Jacobowitz
2007-11-20 19:55                             ` Nick Roberts

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=200711031247.54239.ghost@cs.msu.su \
    --to=ghost@cs.msu.su \
    --cc=drow@false.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=nickrob@snap.net.nz \
    /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