gdb:
authorYao Qi <yao@codesourcery.com>
Fri, 2 Nov 2012 00:14:39 +0000 (00:14 +0000)
committerYao Qi <yao@codesourcery.com>
Fri, 2 Nov 2012 00:14:39 +0000 (00:14 +0000)
2012-11-02  Yao Qi  <yao@codesourcery.com>

* std-operator.def: Remove OP_LABELED.
* eval.c: Remove the declaration of 'get_label'.
(get_label): Remove.
(evaluate_struct_tuple): Remove code handling OP_LABELED.
Update comment.
Remove local variable 'variantno' and related code.
Replace 'substruct_type' with 'struct_type'.  Replace 'subfieldno'
with 'fieldno'.
* expprint.c (print_subexp_standard): Likewise.
(dump_subexp_body_standard): Likewise.
* parse.c (operator_length_standard): Likewise.

gdb/testsuite:

2012-11-02  Yao Qi  <yao@codesourcery.com>

* gdb.base/setvar.exp: Test setting nested struct.
* gdb.base/setvar.c (v_struct3): New.

gdb/ChangeLog
gdb/eval.c
gdb/expprint.c
gdb/parse.c
gdb/std-operator.def
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/setvar.c
gdb/testsuite/gdb.base/setvar.exp

index 96000de0a1bc5189b4e5b3747adbf3e87c8cf3e2..adcdb978d98472d7f0bac03d3e3a50ad21c62635 100644 (file)
@@ -1,3 +1,17 @@
+2012-11-02  Yao Qi  <yao@codesourcery.com>
+
+       * std-operator.def: Remove OP_LABELED.
+       * eval.c: Remove the declaration of 'get_label'.
+       (get_label): Remove.
+       (evaluate_struct_tuple): Remove code handling OP_LABELED.
+       Update comment.
+       Remove local variable 'variantno' and related code.
+       Replace 'substruct_type' with 'struct_type'.  Replace 'subfieldno'
+       with 'fieldno'.
+       * expprint.c (print_subexp_standard): Likewise.
+       (dump_subexp_body_standard): Likewise.
+       * parse.c (operator_length_standard): Likewise.
+
 2012-11-01  Pierre Muller  <muller@ics.u-strasbg.fr>
 
        Incorporate ARI web page generator into GDB sources.
index 26e0cc829fa59c892edc2e0484214f6f8985d0ea..f6559577ae1187e02e148077254bead39131fad2 100644 (file)
@@ -56,8 +56,6 @@ static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
 static struct value *evaluate_subexp_for_address (struct expression *,
                                                  int *, enum noside);
 
-static char *get_label (struct expression *, int *);
-
 static struct value *evaluate_struct_tuple (struct value *,
                                            struct expression *, int *,
                                            enum noside, int);
@@ -280,27 +278,8 @@ extract_field_op (struct expression *exp, int *subexp)
   return result;
 }
 
-/* If the next expression is an OP_LABELED, skips past it,
-   returning the label.  Otherwise, does nothing and returns NULL.  */
-
-static char *
-get_label (struct expression *exp, int *pos)
-{
-  if (exp->elts[*pos].opcode == OP_LABELED)
-    {
-      int pc = (*pos)++;
-      char *name = &exp->elts[pc + 2].string;
-      int tem = longest_to_int (exp->elts[pc + 1].longconst);
-
-      (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
-      return name;
-    }
-  else
-    return NULL;
-}
-
-/* This function evaluates tuples (in (the deleted) Chill) or
-   brace-initializers (in C/C++) for structure types.  */
+/* This function evaluates brace-initializers (in C/C++) for
+   structure types.  */
 
 static struct value *
 evaluate_struct_tuple (struct value *struct_val,
@@ -308,143 +287,57 @@ evaluate_struct_tuple (struct value *struct_val,
                       int *pos, enum noside noside, int nargs)
 {
   struct type *struct_type = check_typedef (value_type (struct_val));
-  struct type *substruct_type = struct_type;
   struct type *field_type;
   int fieldno = -1;
-  int variantno = -1;
-  int subfieldno = -1;
 
   while (--nargs >= 0)
     {
-      int pc = *pos;
       struct value *val = NULL;
-      int nlabels = 0;
       int bitpos, bitsize;
       bfd_byte *addr;
 
-      /* Skip past the labels, and count them.  */
-      while (get_label (exp, pos) != NULL)
-       nlabels++;
-
-      do
-       {
-         char *label = get_label (exp, &pc);
-
-         if (label)
-           {
-             for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
-                  fieldno++)
-               {
-                 const char *field_name =
-                   TYPE_FIELD_NAME (struct_type, fieldno);
-
-                 if (field_name != NULL && strcmp (field_name, label) == 0)
-                   {
-                     variantno = -1;
-                     subfieldno = fieldno;
-                     substruct_type = struct_type;
-                     goto found;
-                   }
-               }
-             for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
-                  fieldno++)
-               {
-                 const char *field_name =
-                   TYPE_FIELD_NAME (struct_type, fieldno);
-
-                 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
-                 if ((field_name == 0 || *field_name == '\0')
-                     && TYPE_CODE (field_type) == TYPE_CODE_UNION)
-                   {
-                     variantno = 0;
-                     for (; variantno < TYPE_NFIELDS (field_type);
-                          variantno++)
-                       {
-                         substruct_type
-                           = TYPE_FIELD_TYPE (field_type, variantno);
-                         if (TYPE_CODE (substruct_type) == TYPE_CODE_STRUCT)
-                           {
-                             for (subfieldno = 0;
-                                subfieldno < TYPE_NFIELDS (substruct_type);
-                                  subfieldno++)
-                               {
-                                 if (strcmp(TYPE_FIELD_NAME (substruct_type,
-                                                             subfieldno),
-                                            label) == 0)
-                                   {
-                                     goto found;
-                                   }
-                               }
-                           }
-                       }
-                   }
-               }
-             error (_("there is no field named %s"), label);
-           found:
-             ;
-           }
-         else
-           {
-             /* Unlabelled tuple element - go to next field.  */
-             if (variantno >= 0)
-               {
-                 subfieldno++;
-                 if (subfieldno >= TYPE_NFIELDS (substruct_type))
-                   {
-                     variantno = -1;
-                     substruct_type = struct_type;
-                   }
-               }
-             if (variantno < 0)
-               {
-                 fieldno++;
-                 /* Skip static fields.  */
-                 while (fieldno < TYPE_NFIELDS (struct_type)
-                        && field_is_static (&TYPE_FIELD (struct_type,
-                                                         fieldno)))
-                   fieldno++;
-                 subfieldno = fieldno;
-                 if (fieldno >= TYPE_NFIELDS (struct_type))
-                   error (_("too many initializers"));
-                 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
-                 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
-                     && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
-                   error (_("don't know which variant you want to set"));
-               }
-           }
+      fieldno++;
+      /* Skip static fields.  */
+      while (fieldno < TYPE_NFIELDS (struct_type)
+            && field_is_static (&TYPE_FIELD (struct_type,
+                                             fieldno)))
+       fieldno++;
+      if (fieldno >= TYPE_NFIELDS (struct_type))
+       error (_("too many initializers"));
+      field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
+      if (TYPE_CODE (field_type) == TYPE_CODE_UNION
+         && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
+       error (_("don't know which variant you want to set"));
+
+      /* Here, struct_type is the type of the inner struct,
+        while substruct_type is the type of the inner struct.
+        These are the same for normal structures, but a variant struct
+        contains anonymous union fields that contain substruct fields.
+        The value fieldno is the index of the top-level (normal or
+        anonymous union) field in struct_field, while the value
+        subfieldno is the index of the actual real (named inner) field
+        in substruct_type.  */
+
+      field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
+      if (val == 0)
+       val = evaluate_subexp (field_type, exp, pos, noside);
+
+      /* Now actually set the field in struct_val.  */
+
+      /* Assign val to field fieldno.  */
+      if (value_type (val) != field_type)
+       val = value_cast (field_type, val);
+
+      bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
+      bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
+      addr = value_contents_writeable (struct_val) + bitpos / 8;
+      if (bitsize)
+       modify_field (struct_type, addr,
+                     value_as_long (val), bitpos % 8, bitsize);
+      else
+       memcpy (addr, value_contents (val),
+               TYPE_LENGTH (value_type (val)));
 
-         /* Here, struct_type is the type of the inner struct,
-            while substruct_type is the type of the inner struct.
-            These are the same for normal structures, but a variant struct
-            contains anonymous union fields that contain substruct fields.
-            The value fieldno is the index of the top-level (normal or
-            anonymous union) field in struct_field, while the value
-            subfieldno is the index of the actual real (named inner) field
-            in substruct_type.  */
-
-         field_type = TYPE_FIELD_TYPE (substruct_type, subfieldno);
-         if (val == 0)
-           val = evaluate_subexp (field_type, exp, pos, noside);
-
-         /* Now actually set the field in struct_val.  */
-
-         /* Assign val to field fieldno.  */
-         if (value_type (val) != field_type)
-           val = value_cast (field_type, val);
-
-         bitsize = TYPE_FIELD_BITSIZE (substruct_type, subfieldno);
-         bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
-         if (variantno >= 0)
-           bitpos += TYPE_FIELD_BITPOS (substruct_type, subfieldno);
-         addr = value_contents_writeable (struct_val) + bitpos / 8;
-         if (bitsize)
-           modify_field (struct_type, addr,
-                         value_as_long (val), bitpos % 8, bitsize);
-         else
-           memcpy (addr, value_contents (val),
-                   TYPE_LENGTH (value_type (val)));
-       }
-      while (--nlabels > 0);
     }
   return struct_val;
 }
index baaa08ad14aaaae7522d2298c39548cf7609f075..129dfa70b0b7a9f4901d77dc066b3635ebf748c8 100644 (file)
@@ -328,21 +328,6 @@ print_subexp_standard (struct expression *exp, int *pos,
        }
       return;
 
-    case OP_LABELED:
-      tem = longest_to_int (exp->elts[pc + 1].longconst);
-      (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
-      /* Gcc support both these syntaxes.  Unsure which is preferred.  */
-#if 1
-      fputs_filtered (&exp->elts[pc + 2].string, stream);
-      fputs_filtered (": ", stream);
-#else
-      fputs_filtered (".", stream);
-      fputs_filtered (&exp->elts[pc + 2].string, stream);
-      fputs_filtered ("=", stream);
-#endif
-      print_subexp (exp, pos, stream, PREC_SUFFIX);
-      return;
-
     case TERNOP_COND:
       if ((int) prec > (int) PREC_COMMA)
        fputs_filtered ("(", stream);
@@ -1031,7 +1016,6 @@ dump_subexp_body_standard (struct expression *exp,
     case OP_BOOL:
     case OP_M2_STRING:
     case OP_THIS:
-    case OP_LABELED:
     case OP_NAME:
       fprintf_filtered (stream, "Unknown format");
     }
index 3ec1e25ee854abb1461a97d417611037f07814fd..afe1c18492cd0e796dada72c8752967a8d977d6c 100644 (file)
@@ -951,7 +951,6 @@ operator_length_standard (const struct expression *expr, int endpos,
       oplen++;
       break;
 
-    case OP_LABELED:
     case STRUCTOP_STRUCT:
     case STRUCTOP_PTR:
       args = 1;
index dcba39f15f96e42e2c6f068c942a20c528065975..5df0081f6962bba3c8352dd4b907220088716065 100644 (file)
@@ -286,19 +286,6 @@ OP (OP_OBJC_SELECTOR)
    a string, which, of course, is variable length.  */
 OP (OP_SCOPE)
 
-/* Used to represent named structure field values in brace
-   initializers (or tuples as they are called in (the deleted)
-   Chill).
-
-   The gcc C syntax is NAME:VALUE or .NAME=VALUE, the (the
-   deleted) Chill syntax is .NAME:VALUE.  Multiple labels (as in
-   the (the deleted) Chill syntax .NAME1,.NAME2:VALUE) is
-   represented as if it were .NAME1:(.NAME2:VALUE) (though that is
-   not valid (the deleted) Chill syntax).
-
-   The NAME is represented as for STRUCTOP_STRUCT;  VALUE follows.  */
-OP (OP_LABELED)
-
 /* OP_TYPE is for parsing types, and used with the "ptype" command
    so we can look up types that are qualified by scope, either with
    the GDB "::" operator, or the Modula-2 '.' operator.  */
index ccd49945b31132fb2d24e2119038f6e368ccd46f..650c193ae3a8e17f748212f5259c341115ad5331 100644 (file)
@@ -1,3 +1,8 @@
+2012-11-02  Yao Qi  <yao@codesourcery.com>
+
+       * gdb.base/setvar.exp: Test setting nested struct.
+       * gdb.base/setvar.c (v_struct3): New.
+
 2012-11-01  Doug Evans  <dje@google.com>
 
        * gdb.arch/amd64-pseudo.c (main): Mark registers that the testsuite
index 83509cde00f0bedf6f721aa7db0453edefe59cb2..3a80b227c99a23941c32ed2398808396afede941 100644 (file)
@@ -115,6 +115,13 @@ struct {
     double     v_double_member;
 } v_struct2;
 
+struct
+{
+  long v_long_member;
+  struct t_struct t;
+  char v_char_member;
+} v_struct3;
+
 /**** unions *******/
 
 union t_union {
index 7faa10a65078685bee186214427e3ffcd15df1a0..3c5251f4b87f8f8c115196900b3805c92aec1870 100644 (file)
@@ -383,6 +383,14 @@ test_set "set variable v_struct1 = {'h', 1, 2, 3, 4.0, 5.0}" \
 v_long_member = 3,.*v_float_member = 4,.*v_double_member = 5.*\\}" \
   "set print structure #3"
 
+#
+# test "set variable" for nested struct
+#
+test_set "set variable v_struct3 = {1, {'h', 1, 2, 3, 4.0, 5.0}, 37}" \
+  "print v_struct3" \
+    ".*.\[0-9\]* = \\{.*v_long_member = 1,.*t = \\{.*v_char_member = 104 \'h\',.*v_short_member = 1,.*v_int_member = 2,.*v_long_member = 3,.*v_float_member = 4,.*v_double_member = 5.*\\},.*v_char_member = 37 \'%\'\\}" \
+  "set print structure #4"
+
 set timeout $prev_timeout
 
 # Test printing of enumeration bitfields.
This page took 0.060693 seconds and 4 git commands to generate.