+2014-07-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * ada-varobj.c (ada_varobj_ops): Fill in is_path_expr_parent
+ field.
+ * c-varobj.c (c_is_path_expr_parent): New function, moved core
+ from varobj.c, with additional checks.
+ (c_varobj_ops): Fill in is_path_expr_parent field.
+ (cplus_varobj_ops): Fill in is_path_expr_parent field.
+ * jv-varobj.c (java_varobj_ops): Fill in is_path_expr_parent
+ field.
+ * varobj.c (is_path_expr_parent): Call is_path_expr_parent varobj
+ ops method.
+ (varobj_default_is_path_expr_parent): New function.
+ * varobj.h (lang_varobj_ops): Add is_path_expr_parent field.
+ (varobj_default_is_path_expr_parent): Declare new function.
+
2014-07-08 Markus Metzger <markus.t.metzger@intel.com>
* infcmd.c (finish_backward): Turn internal error into normal error.
ada_type_of_child,
ada_value_of_variable,
ada_value_is_changeable_p,
- ada_value_has_mutated
+ ada_value_has_mutated,
+ varobj_default_is_path_expr_parent
};
}
}
+/* Is VAR a path expression parent, i.e., can it be used to construct
+ a valid path expression? */
+
+static int
+c_is_path_expr_parent (struct varobj *var)
+{
+ struct type *type;
+
+ /* "Fake" children are not path_expr parents. */
+ if (CPLUS_FAKE_CHILD (var))
+ return 0;
+
+ type = varobj_get_gdb_type (var);
+
+ /* Anonymous unions and structs are also not path_expr parents. */
+ if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION)
+ && TYPE_NAME (type) == NULL
+ && TYPE_TAG_NAME (type) == NULL)
+ {
+ struct varobj *parent = var->parent;
+
+ while (parent != NULL && CPLUS_FAKE_CHILD (parent))
+ parent = parent->parent;
+
+ if (parent != NULL)
+ {
+ struct type *parent_type;
+ int was_ptr;
+
+ parent_type = varobj_get_value_type (parent);
+ adjust_value_for_child_access (NULL, &parent_type, &was_ptr, 0);
+
+ if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (parent_type) == TYPE_CODE_UNION)
+ {
+ const char *field_name;
+
+ gdb_assert (var->index < TYPE_NFIELDS (parent_type));
+ field_name = TYPE_FIELD_NAME (parent_type, var->index);
+ return !(field_name == NULL || *field_name == '\0');
+ }
+ }
+
+ return 0;
+ }
+
+ return 1;
+}
+
/* C */
static int
c_type_of_child,
c_value_of_variable,
varobj_default_value_is_changeable_p,
- NULL /* value_has_mutated */
+ NULL, /* value_has_mutated */
+ c_is_path_expr_parent /* is_path_expr_parent */
};
/* A little convenience enum for dealing with C++/Java. */
cplus_type_of_child,
cplus_value_of_variable,
varobj_default_value_is_changeable_p,
- NULL /* value_has_mutated */
+ NULL, /* value_has_mutated */
+ c_is_path_expr_parent /* is_path_expr_parent */
};
\f
java_type_of_child,
java_value_of_variable,
varobj_default_value_is_changeable_p,
- NULL /* value_has_mutated */
+ NULL, /* value_has_mutated */
+ varobj_default_is_path_expr_parent
};
+2014-07-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.mi/var-cmd.c (do_nested_struct_union_tests): New function
+ setting up test structures.
+ (main): Call new test function.
+ * gdb.mi/mi2-var-child.exp: Create additional breakpoint in new
+ test function, continue into test function and walk test
+ structures.
+
2014-07-02 Yao Qi <yao@codesourcery.com>
* gdb.trace/entry-values.c: Define labels 'foo_start' and
"$srcfile:$lineno" "break in do_anonymous_type_tests" \
-disp keep -func do_anonymous_type_tests \
-file ".*var-cmd.c" -line $lineno
+
+set lineno [gdb_get_line_number "nested struct union tests breakpoint"]
+mi_create_breakpoint \
+ "$srcfile:$lineno" "break in do_nested_struct_union_tests" \
+ -disp keep -func do_nested_struct_union_tests \
+ -file ".*var-cmd.c" -line $lineno
+
mi_execute_to "exec-continue" "breakpoint-hit" "do_anonymous_type_tests" ""\
".*" ".*" {"" "disp=\"keep\""} \
"continue to do_anonymous_type_tests breakpoint"
mi_walk_varobj_tree c $tree verify_everything
+mi_send_resuming_command "exec-continue" \
+ "continuing execution to enter do_nested_struct_union_tests"
+mi_expect_stop "breakpoint-hit" "do_nested_struct_union_tests" ".*" ".*" ".*" \
+ {.* disp="keep"} "Run till MI stops in do_nested_struct_union_tests"
+
+set struct_ss_tree {
+ {struct s_a} a1 {
+ int a {}
+ }
+ {struct s_b} b1 {
+ int b {}
+ }
+ {union u_ab} u1 {
+ {struct s_a} a {
+ int a {}
+ }
+ {struct s_b} b {
+ int b {}
+ }
+ }
+ anonymous union {
+ {struct s_a} a2 {
+ int a {}
+ }
+ {struct s_b} b2 {
+ int b {}
+ }
+ }
+ {union {...}} u2 {
+ {struct s_a} a3 {
+ int a {}
+ }
+ {struct s_b} b3 {
+ int b {}
+ }
+ }
+ }
+
+set tree "
+ {struct ss} var {
+ $struct_ss_tree
+ }
+"
+
+mi_walk_varobj_tree c $tree verify_everything
+
+set tree {
+ {struct {...}} var2 {
+ {td_u_ab} ab {
+ {td_s_a} a {
+ int a {}
+ }
+ {td_s_b} b {
+ int b {}
+ }
+ }
+ }
+}
+
+mi_walk_varobj_tree c $tree verify_everything
+
+set tree "
+ {struct ss *} ss_ptr {
+ $struct_ss_tree
+ }
+"
+
+mi_walk_varobj_tree c $tree verify_everything
+
mi_gdb_exit
return 0
return; /* anonymous type tests breakpoint */
}
+void
+do_nested_struct_union_tests (void)
+{
+ struct s_a
+ {
+ int a;
+ };
+ struct s_b
+ {
+ int b;
+ };
+ union u_ab
+ {
+ struct s_a a;
+ struct s_b b;
+ };
+ struct ss
+ {
+ struct s_a a1;
+ struct s_b b1;
+ union u_ab u1;
+
+ /* Anonymous union. */
+ union
+ {
+ struct s_a a2;
+ struct s_b b2;
+ };
+
+ union
+ {
+ struct s_a a3;
+ struct s_b b3;
+ } u2;
+ };
+
+ typedef struct
+ {
+ int a;
+ } td_s_a;
+
+ typedef struct
+ {
+ int b;
+ } td_s_b;
+
+ typedef union
+ {
+ td_s_a a;
+ td_s_b b;
+ } td_u_ab;
+
+ struct ss var;
+ struct
+ {
+ td_u_ab ab;
+ } var2;
+
+ struct ss *ss_ptr;
+
+ memset (&var, 0, sizeof (var));
+ memset (&var2, 0, sizeof (var2));
+ ss_ptr = &var;
+
+ return; /* nested struct union tests breakpoint */
+}
+
int
main (int argc, char *argv [])
{
do_at_tests ();
do_bitfield_tests ();
do_anonymous_type_tests ();
+ do_nested_struct_union_tests ();
exit (0);
}
static int
is_path_expr_parent (struct varobj *var)
{
- struct type *type;
-
- /* "Fake" children are not path_expr parents. */
- if (CPLUS_FAKE_CHILD (var))
- return 0;
+ gdb_assert (var->root->lang_ops->is_path_expr_parent != NULL);
+ return var->root->lang_ops->is_path_expr_parent (var);
+}
- type = varobj_get_value_type (var);
+/* Is VAR a path expression parent, i.e., can it be used to construct
+ a valid path expression? By default we assume any VAR can be a path
+ parent. */
- /* Anonymous unions and structs are also not path_expr parents. */
- return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
- || TYPE_CODE (type) == TYPE_CODE_UNION)
- && TYPE_NAME (type) == NULL);
+int
+varobj_default_is_path_expr_parent (struct varobj *var)
+{
+ return 1;
}
/* Return the path expression parent for VAR. */
Languages where types do not mutate can set this to NULL. */
int (*value_has_mutated) (struct varobj *var, struct value *new_value,
struct type *new_type);
+
+ /* Return nonzero if VAR is a suitable path expression parent.
+
+ For C like languages with anonymous structures and unions an anonymous
+ structure or union is not a suitable parent. */
+ int (*is_path_expr_parent) (struct varobj *var);
};
extern const struct lang_varobj_ops c_varobj_ops;
extern void varobj_restrict_range (VEC (varobj_p) *children, int *from,
int *to);
+
+extern int varobj_default_is_path_expr_parent (struct varobj *var);
+
#endif /* VAROBJ_H */