PR mi/10586
authorKeith Seitz <keiths@redhat.com>
Thu, 12 Jan 2012 22:50:49 +0000 (22:50 +0000)
committerKeith Seitz <keiths@redhat.com>
Thu, 12 Jan 2012 22:50:49 +0000 (22:50 +0000)
* gdb.mi/var-cmd.c (struct anonymous): New structure.
(do_anonymous_type_tests): New function.
(main): Call do_anonymous_type_tests.
* gdb.mi/mi2-var-child.exp: Add anonymous type tests.
(verify_everything): New procedure.
* gdb.mi/mi-var-cp.cc (class A): New class.
(anonymous_structs_and_unions): New function.
(main): Call anonymous_structs_and_unions.
* gdb.mi/mi-var-cp.exp: Add anonymous type tests.
(verify_everything): New procedure.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-var-cp.cc
gdb/testsuite/gdb.mi/mi-var-cp.exp
gdb/testsuite/gdb.mi/mi2-var-child.exp
gdb/testsuite/gdb.mi/var-cmd.c

index 9e3fff47b0bd0e2f98bd959c9944ad969244a426..fa4141ebc199a6eae655027a7f18abbdfca2d6b0 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-12  Keith Seitz  <keiths@redhat.com>
+
+       PR mi/10586
+       * gdb.mi/var-cmd.c (struct anonymous): New structure.
+       (do_anonymous_type_tests): New function.
+       (main): Call do_anonymous_type_tests.
+       * gdb.mi/mi2-var-child.exp: Add anonymous type tests.
+       (verify_everything): New procedure.
+       * gdb.mi/mi-var-cp.cc (class A): New class.
+       (anonymous_structs_and_unions): New function.
+       (main): Call anonymous_structs_and_unions.
+       * gdb.mi/mi-var-cp.exp: Add anonymous type tests.
+       (verify_everything): New procedure.
+
 2012-01-12  Keith Seitz  <keiths@redhat.com>
 
        * lib/mi-support.exp: Expand comments about PATH_EXPR.
index f23913b13bb1e50d9a4df7ca151a3baf01933ec6..abdee9f67741756fee36f2b02077912e3d67253b 100644 (file)
@@ -205,6 +205,51 @@ int path_expression ()
   /*: END: path_expression :*/
 }
 
+class Anonymous
+{
+public:
+  struct { /* index: 0 */
+    int b;
+  };
+  struct { /* index: 1 */
+    int c;
+  };
+  struct { /* index: 2 */
+    int d;
+    struct { /* index: 1 */
+      int e;
+      struct { /* index: 0 */
+        int f;
+        union { /* index: 0 */
+          int g;
+          char h;
+        };
+      };
+      union { /* index: 0 */
+        int i;
+        char j;
+      };
+    };
+  };
+};
+
+/* Test anonymous structs and unions.  */
+int
+anonymous_structs_and_unions (void)
+{
+  Anonymous a;
+  a.b = 1;
+  a.c = 2;
+  a.d = 3;
+  a.e = 4;
+  a.f = 5;
+  a.g = 6;
+  a.h = '7';
+  a.i = 8;
+  a.j = '8';
+  return 0;  /* anonymous_structs_and_unions */
+}
+
 int main ()
 {
   reference_update_tests ();
@@ -212,5 +257,6 @@ int main ()
   reference_to_pointer ();
   reference_to_struct ();
   path_expression ();
+  anonymous_structs_and_unions ();
   return 0;
 }
index 01204e454c5b9fbd8599dbedb2fe465ebdec74ab..9efc08810968494c75fce0689cd4d2a926556df5 100644 (file)
@@ -46,5 +46,78 @@ mi_run_inline_test reference_to_pointer
 mi_run_inline_test reference_to_struct
 mi_run_inline_test path_expression
 
+set lineno [gdb_get_line_number "/* anonymous_structs_and_unions */"]
+mi_create_breakpoint \
+    "$srcfile:$lineno" {[0-9]+} keep {anonymous_structs_and_unions\(\)} \
+    ".*mi-var-cp.cc" $lineno $hex "break in anonymous_structs_and_unions"
+mi_execute_to "exec-continue" "breakpoint-hit" \
+    "anonymous_structs_and_unions" "" ".*" ".*" {"" "disp=\"keep\""} \
+    "continue to anonymous_structs breakpoint"
+
+set tree {
+  Anonymous a {
+    {} public {
+      anonymous struct {
+        {} public {
+          int b {}
+        }
+      }
+      anonymous struct {
+        {} public {
+          int c {}
+        }
+      }
+      anonymous struct {
+        {} public {
+          int d {}
+          anonymous struct {
+            {} public {
+              int e {}
+              anonymous struct {
+                {} public {
+                  int f {}
+                  anonymous union {
+                    {} public {
+                      int g {}
+                      char h {}
+                    }
+                  }
+                }
+              }
+             anonymous union {
+               {} public {
+                 int i {}
+                 char j {}
+               }
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+}
+
+proc verify_everything {variable_name} {
+  # Test -var-list-children
+  mi_varobj_tree_test_children_callback $variable_name
+
+  # Bring the variable named by VARIABLE_NAME into the current scope
+  # in VAROBJ.
+  upvar #0 $variable_name varobj
+
+  # Test -var-info-path-expression
+  mi_gdb_test "-var-info-path-expression $varobj(obj_name)" \
+      "\\^done,path_expr=\"[string_to_regexp $varobj(path_expr)]\"" \
+      "path expression for $varobj(obj_name)"
+
+  # Test -var-info-expression
+  mi_gdb_test "-var-info-expression $varobj(obj_name)" \
+      "\\^done,lang=\"C\\+\\+\",exp=\"[string_to_regexp $varobj(display_name)]\"" \
+      "expression for $varobj(obj_name)"
+}
+
+mi_walk_varobj_tree c++ $tree verify_everything
+
 mi_gdb_exit
 return 0
index 2e7b3950567d83b8b5cb8be507718536b42f1285..8bc88e913fd6ea3d337884a253204783b20c21cd 100644 (file)
@@ -1139,7 +1139,102 @@ mi_gdb_test "-var-update *" \
        "update all vars psnp->next->next->long_ptr (and 2.long_ptr) changed"
 
 
+# Anonymous type tests
+proc verify_everything {variable_name} {
+  # Test -var-list-children
+  mi_varobj_tree_test_children_callback $variable_name
+
+  # Bring the variable named by VARIABLE_NAME into the current scope
+  # in VAROBJ.
+  upvar #0 $variable_name varobj
+
+  # Test -var-info-path-expression
+  mi_gdb_test "-var-info-path-expression $varobj(obj_name)" \
+      "\\^done,path_expr=\"[string_to_regexp $varobj(path_expr)]\"" \
+      "path expression for $varobj(obj_name)"
+
+  # Test -var-info-expression
+  mi_gdb_test "-var-info-expression $varobj(obj_name)" \
+      "\\^done,lang=\"C\",exp=\"[string_to_regexp $varobj(display_name)]\"" \
+      "expression for $varobj(obj_name)"
+}
+
+set lineno [gdb_get_line_number "anonymous type tests breakpoint"]
+mi_create_breakpoint \
+    "$srcfile:$lineno" {[0-9]+} keep {do_anonymous_type_tests} \
+    ".*var-cmd.c" $lineno $hex "break in do_anonymous_type_tests"
+mi_execute_to "exec-continue" "breakpoint-hit" "do_anonymous_type_tests" ""\
+    ".*" ".*" {"" "disp=\"keep\""} \
+    "continue to do_anonymous_type_tests breakpoint"
+
+# Run the varobj tree on variable "ptr".
+set tree {
+  {struct anonymous **} ptr {
+    {struct anonymous *} {*ptr} {
+      int a {}
+      anonymous struct {
+       int b {}
+       {char *} c {
+         char {*c} {}
+       }
+       anonymous union {
+         int d {}
+         {void *} e {}
+         char f {}
+         anonymous struct {
+           char g {}
+           {const char **} h {
+             {const char *} {*h} {
+               {const char} {**h} {}
+             }
+           }
+           {simpleton ***} simple {
+             {simpleton **} {*simple} {
+               {simpleton *} {**simple} {
+                 int integer {}
+                 {unsigned int} unsigned_integer {}
+                 char character {}
+                 {signed char} signed_character {}
+                 {char *} char_ptr {
+                   char {*char_ptr} {}
+                 }
+                 {int [10]} array_of_10 {
+                   int 0 {}
+                   int 1 {}
+                   int 2 {}
+                   int 3 {}
+                   int 4 {}
+                   int 5 {}
+                   int 6 {}
+                   int 7 {}
+                   int 8 {}
+                   int 9 {}
+                 }
+               }
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+}
+
+mi_walk_varobj_tree c $tree verify_everything
+
+set tree {
+  {struct {...}} v {
+    int x {}
+    anonymous struct {
+      int a {}
+    }
+    anonymous struct {
+      int b {}
+    }
+  }
+}
 
+mi_walk_varobj_tree c $tree verify_everything
 
 mi_gdb_exit
 return 0
index 1482cddb6371d0c386f749da1505a528f8f53986..0a993a18c7a616030fe54a5809e29e6409d650dc 100644 (file)
@@ -91,6 +91,24 @@ struct _struct_n_pointer {
   struct _struct_n_pointer *next;
 };
 
+struct anonymous {
+  int a;
+  struct {
+    int b;
+    char *c;
+    union {
+      int d;
+      void *e;
+      char f;
+      struct {
+       char g;
+       const char **h;
+       simpleton ***simple;
+      };
+    };
+  };
+};
+
 void do_locals_tests (void);
 void do_block_tests (void);
 void subroutine1 (int, long *);
@@ -502,6 +520,38 @@ void do_bitfield_tests ()
   /*: END: bitfield :*/  
 }
 
+void
+do_anonymous_type_tests (void)
+{
+  struct anonymous *anon;
+  struct anonymous **ptr;
+  struct
+  {
+    int x;
+    struct
+    {
+      int a;
+    };
+    struct
+    {
+      int b;
+    };
+  } v = {1, {2}, {3}};
+
+  anon = malloc (sizeof (struct anonymous));
+  anon->a = 1;
+  anon->b = 2;
+  anon->c = (char *) 3;
+  anon->d = 4;
+  anon->g = '5';
+  anon->h = (const char **) 6;
+  anon->simple = (simpleton ***) 7;
+
+  ptr = &anon;
+  free (anon);
+  return; /* anonymous type tests breakpoint */
+}
+
 int
 main (int argc, char *argv [])
 {
@@ -512,6 +562,7 @@ main (int argc, char *argv [])
   do_frozen_tests ();
   do_at_tests ();
   do_bitfield_tests ();
+  do_anonymous_type_tests ();
   exit (0);
 }