public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 6/7] Move language stuff out of varobj.c
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
  2013-09-18 13:55 ` [PATCH 1/7] Remove field language in struct language_specific Yao Qi
  2013-09-18 13:55 ` [PATCH 5/7] New lang-varobj.h Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-11  8:20   ` Yao Qi
  2013-09-18 13:55 ` [PATCH 7/7] Remove ada-varobj.h Yao Qi
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

This patch moves language-related stuff out of varobj.c into
c-varobj.c, jv-varobj.c and ada-varobj.c respectively.  This patch
also makes some static functions extern and add "varobj_" prefix.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add c-varobj.c and jv-varobj.c.
	(COMMON_OBS): Add c-varobj.o and jv-varobj.o.
	* ada-varobj.c: Include "lang-varobj.h".
	(ada_number_of_children): New.  Moved from varobj.c.
	(ada_name_of_variable, ada_name_of_child): Likewise.
	(ada_path_expr_of_child, ada_value_of_child): Likewise.
	(ada_type_of_child, ada_value_of_variable): Likewise.
	(ada_value_is_changeable_p, ada_value_has_mutated): Likewise.
	(ada_varobj_ops): New.
	* c-varobj.c, jv-varobj.c: New file.  Moved from varobj.c.
	* gdbtypes.c (get_target_type): New.  Moved from varobj.c.
	* gdbtypes.h (get_target_type): Declare.
	* lang-varobj.h (c_varobj_ops, cplus_varobj_ops): Declare.
	(java_varobj_ops, ada_varobj_ops): Declare.
	* varobj.c: Remove the inclusion of "ada-varobj.h" and
	"ada-lang.h".
	(ANONYMOUS_STRUCT_NAME): Move it to c-varobj.c.
	(ANONYMOUS_UNION_NAME): Likewise.
	(get_type, get_value_type, get_target_type): Remove declarations.
	(value_get_print_value, varobj_value_get_print_value): Likewise.
	(c_number_of_children, c_name_of_variable): Likewise.
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable, java_number_of_children): Likewise.
	(java_name_of_variable, java_name_of_child): Likewise.
	(java_path_expr_of_child, java_value_of_child): Likewise.
	(java_type_of_child, java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Likewise.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	(CPLUS_FAKE_CHILD): Move it to varobj.h.
	(restrict_range): Rename it varobj_restrict_range.  Make it extern.
	Callers update.
	(get_path_expr_parent): Rename it to varobj_get_path_expr_parent.
	Make it extern.
	(is_anonymous_child): Move it to c-varobj.c and rename to
	varobj_is_anonymous_child.  Caller update.
	(get_type): Move it to c-varobj.c.
	(get_value_type): Rename it varobj_get_value_type.  Make it
	extern.
	(get_target_type): Move it gdbtypes.c.
	(varobj_formatted_print_options): New function.
	(value_get_print_value): Rename it to
	varobj_value_get_print_value and make it extern.
	(varobj_value_is_changeable_p): Make it extern.
	(adjust_value_for_child_access): Move it to c-varobj.c.
	(default_value_is_changeable_p): Rename it to
	varobj_default_value_is_changeable_p.  Make it extern.
	(c_number_of_children, c_name_of_variable): Move it to c-varobj.c
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable): Likewise.
	(java_number_of_children, java_name_of_variable): Move it to jv-varobj.c.
	(java_name_of_child, java_path_expr_of_child): Likewise.
	(java_value_of_child, java_type_of_child): Likewise.
	(java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Move it to ada-varobj.c.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	* varobj.h (CPLUS_FAKE_CHILD): New macro, moved from varobj.c.
	(varobj_default_value_is_changeable_p): Declare.
	(varobj_value_is_changeable_p): Declare.
	(varobj_get_value_type, varobj_is_anonymous_child): Declare.
	(varobj_get_path_expr_parent): Declare.
	(varobj_value_get_print_value): Declare.
	(varobj_formatted_print_options): Declare.
	(varobj_restrict_range): Declare.
---
 gdb/Makefile.in   |    8 +-
 gdb/ada-varobj.c  |  135 ++++++
 gdb/c-varobj.c    |  902 +++++++++++++++++++++++++++++++++++++
 gdb/gdbtypes.c    |   16 +
 gdb/gdbtypes.h    |    4 +
 gdb/jv-varobj.c   |  104 +++++
 gdb/lang-varobj.h |    5 +
 gdb/varobj.c      | 1270 ++---------------------------------------------------
 gdb/varobj.h      |   22 +
 9 files changed, 1233 insertions(+), 1233 deletions(-)
 create mode 100644 gdb/c-varobj.c
 create mode 100644 gdb/jv-varobj.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 3081e1d..73715b5 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -718,7 +718,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	block.c blockframe.c \
 	breakpoint.c break-catch-sig.c break-catch-throw.c \
 	buildsym.c \
-	c-exp.y c-lang.c c-typeprint.c c-valprint.c \
+	c-exp.y c-lang.c c-typeprint.c c-valprint.c c-varobj.c \
 	charset.c cleanups.c cli-out.c coffread.c coff-pe-read.c \
 	complaints.c completer.c continuations.c corefile.c corelow.c \
 	cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \
@@ -739,7 +739,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	infcmd.c inflow.c infrun.c \
 	inline-frame.c \
 	interps.c \
-	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c \
+	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c jv-varobj.c \
 	language.c linespec.c minidebug.c \
 	m2-exp.y m2-lang.c m2-typeprint.c m2-valprint.c \
 	macrotab.c macroexp.c macrocmd.c macroscope.c main.c maint.c \
@@ -920,11 +920,11 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	dwarf2read.o mipsread.o stabsread.o corefile.o \
 	dwarf2expr.o dwarf2loc.o dwarf2-frame.o dwarf2-frame-tailcall.o \
 	ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \
-	ada-tasks.o ada-varobj.o \
+	ada-tasks.o ada-varobj.o c-varobj.o \
 	ui-out.o cli-out.o \
 	varobj.o vec.o \
 	go-lang.o go-valprint.o go-typeprint.o \
-	jv-lang.o jv-valprint.o jv-typeprint.o \
+	jv-lang.o jv-valprint.o jv-typeprint.o jv-varobj.o \
 	m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 53d8a9c..3b01209 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -20,6 +20,7 @@
 #include "defs.h"
 #include "ada-varobj.h"
 #include "ada-lang.h"
+#include "lang-varobj.h"
 #include "language.h"
 #include "valprint.h"
 
@@ -885,4 +886,138 @@ ada_varobj_get_value_of_variable (struct value *value,
   return result;
 }
 
+/* Ada specific callbacks for VAROBJs.  */
 
+static int
+ada_number_of_children (struct varobj *var)
+{
+  return ada_varobj_get_number_of_children (var->value, var->type);
+}
+
+static char *
+ada_name_of_variable (struct varobj *parent)
+{
+  return c_varobj_ops.name_of_variable (parent);
+}
+
+static char *
+ada_name_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_name_of_child (parent->value, parent->type,
+				       parent->name, index);
+}
+
+static char*
+ada_path_expr_of_child (struct varobj *child)
+{
+  struct varobj *parent = child->parent;
+  const char *parent_path_expr = varobj_get_path_expr (parent);
+
+  return ada_varobj_get_path_expr_of_child (parent->value,
+					    parent->type,
+					    parent->name,
+					    parent_path_expr,
+					    child->index);
+}
+
+static struct value *
+ada_value_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_value_of_child (parent->value, parent->type,
+					parent->name, index);
+}
+
+static struct type *
+ada_type_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_type_of_child (parent->value, parent->type,
+				       index);
+}
+
+static char *
+ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  struct value_print_options opts;
+
+  varobj_formatted_print_options (&opts, format);
+
+  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
+}
+
+/* Implement the "value_is_changeable_p" routine for Ada.  */
+
+static int
+ada_value_is_changeable_p (struct varobj *var)
+{
+  struct type *type = var->value ? value_type (var->value) : var->type;
+
+  if (ada_is_array_descriptor_type (type)
+      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+    {
+      /* This is in reality a pointer to an unconstrained array.
+	 its value is changeable.  */
+      return 1;
+    }
+
+  if (ada_is_string_type (type))
+    {
+      /* We display the contents of the string in the array's
+	 "value" field.  The contents can change, so consider
+	 that the array is changeable.  */
+      return 1;
+    }
+
+  return varobj_default_value_is_changeable_p (var);
+}
+
+/* Implement the "value_has_mutated" routine for Ada.  */
+
+static int
+ada_value_has_mutated (struct varobj *var, struct value *new_val,
+		       struct type *new_type)
+{
+  int i;
+  int from = -1;
+  int to = -1;
+
+  /* If the number of fields have changed, then for sure the type
+     has mutated.  */
+  if (ada_varobj_get_number_of_children (new_val, new_type)
+      != var->num_children)
+    return 1;
+
+  /* If the number of fields have remained the same, then we need
+     to check the name of each field.  If they remain the same,
+     then chances are the type hasn't mutated.  This is technically
+     an incomplete test, as the child's type might have changed
+     despite the fact that the name remains the same.  But we'll
+     handle this situation by saying that the child has mutated,
+     not this value.
+
+     If only part (or none!) of the children have been fetched,
+     then only check the ones we fetched.  It does not matter
+     to the frontend whether a child that it has not fetched yet
+     has mutated or not. So just assume it hasn't.  */
+
+  varobj_restrict_range (var->children, &from, &to);
+  for (i = from; i < to; i++)
+    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
+					      var->name, i),
+		VEC_index (varobj_p, var->children, i)->name) != 0)
+      return 1;
+
+  return 0;
+}
+
+const struct lang_varobj_ops ada_varobj_ops =
+{
+  ada_number_of_children,
+  ada_name_of_variable,
+  ada_name_of_child,
+  ada_path_expr_of_child,
+  ada_value_of_child,
+  ada_type_of_child,
+  ada_value_of_variable,
+  ada_value_is_changeable_p,
+  ada_value_has_mutated
+};
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
new file mode 100644
index 0000000..23a078b
--- /dev/null
+++ b/gdb/c-varobj.c
@@ -0,0 +1,902 @@
+/* varobj support for C and C++.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "value.h"
+#include "varobj.h"
+#include "lang-varobj.h"
+#include "gdbthread.h"
+#include "valprint.h"
+
+static void cplus_class_num_children (struct type *type, int children[3]);
+
+/* The names of varobjs representing anonymous structs or unions.  */
+#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
+#define ANONYMOUS_UNION_NAME _("<anonymous union>")
+
+/* Does CHILD represent a child with no name?  This happens when
+   the child is an anonmous struct or union and it has no field name
+   in its parent variable.
+
+   This has already been determined by *_describe_child. The easiest
+   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
+
+int
+varobj_is_anonymous_child (struct varobj *child)
+{
+  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
+	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
+}
+
+/* Given the value and the type of a variable object,
+   adjust the value and type to those necessary
+   for getting children of the variable object.
+   This includes dereferencing top-level references
+   to all types and dereferencing pointers to
+   structures.
+
+   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
+   value will be fetched and if it differs from static type
+   the value will be casted to it.
+
+   Both TYPE and *TYPE should be non-null.  VALUE
+   can be null if we want to only translate type.
+   *VALUE can be null as well -- if the parent
+   value is not known.
+
+   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
+   depending on whether pointer was dereferenced
+   in this function.  */
+static void
+adjust_value_for_child_access (struct value **value,
+				  struct type **type,
+				  int *was_ptr,
+				  int lookup_actual_type)
+{
+  gdb_assert (type && *type);
+
+  if (was_ptr)
+    *was_ptr = 0;
+
+  *type = check_typedef (*type);
+  
+  /* The type of value stored in varobj, that is passed
+     to us, is already supposed to be
+     reference-stripped.  */
+
+  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
+
+  /* Pointers to structures are treated just like
+     structures when accessing children.  Don't
+     dererences pointers to other types.  */
+  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
+    {
+      struct type *target_type = get_target_type (*type);
+      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
+	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
+	{
+	  if (value && *value)
+	    {
+	      volatile struct gdb_exception except;
+
+	      TRY_CATCH (except, RETURN_MASK_ERROR)
+		{
+		  *value = value_ind (*value);
+		}
+
+	      if (except.reason < 0)
+		*value = NULL;
+	    }
+	  *type = target_type;
+	  if (was_ptr)
+	    *was_ptr = 1;
+	}
+    }
+
+  /* The 'get_target_type' function calls check_typedef on
+     result, so we can immediately check type code.  No
+     need to call check_typedef here.  */
+
+  /* Access a real type of the value (if necessary and possible).  */
+  if (value && *value && lookup_actual_type)
+    {
+      struct type *enclosing_type;
+      int real_type_found = 0;
+
+      enclosing_type = value_actual_type (*value, 1, &real_type_found);
+      if (real_type_found)
+        {
+          *type = enclosing_type;
+          *value = value_cast (enclosing_type, *value);
+        }
+    }
+}
+
+/* C */
+
+static int
+c_number_of_children (struct varobj *var)
+{
+  struct type *type = varobj_get_value_type (var);
+  int children = 0;
+  struct type *target;
+
+  adjust_value_for_child_access (NULL, &type, NULL, 0);
+  target = get_target_type (type);
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
+	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
+      else
+	/* If we don't know how many elements there are, don't display
+	   any.  */
+	children = 0;
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      children = TYPE_NFIELDS (type);
+      break;
+
+    case TYPE_CODE_PTR:
+      /* The type here is a pointer to non-struct.  Typically, pointers
+	 have one child, except for function ptrs, which have no children,
+	 and except for void*, as we don't know what to show.
+
+         We can show char* so we allow it to be dereferenced.  If you decide
+         to test for it, please mind that a little magic is necessary to
+         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
+         TYPE_NAME == "char".  */
+      if (TYPE_CODE (target) == TYPE_CODE_FUNC
+	  || TYPE_CODE (target) == TYPE_CODE_VOID)
+	children = 0;
+      else
+	children = 1;
+      break;
+
+    default:
+      /* Other types have no children.  */
+      break;
+    }
+
+  return children;
+}
+
+static char *
+c_name_of_variable (struct varobj *parent)
+{
+  return xstrdup (parent->name);
+}
+
+/* Return the value of element TYPE_INDEX of a structure
+   value VALUE.  VALUE's type should be a structure,
+   or union, or a typedef to struct/union.
+
+   Returns NULL if getting the value fails.  Never throws.  */
+static struct value *
+value_struct_element_index (struct value *value, int type_index)
+{
+  struct value *result = NULL;
+  volatile struct gdb_exception e;
+  struct type *type = value_type (value);
+
+  type = check_typedef (type);
+
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
+	      || TYPE_CODE (type) == TYPE_CODE_UNION);
+
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      if (field_is_static (&TYPE_FIELD (type, type_index)))
+	result = value_static_field (type, type_index);
+      else
+	result = value_primitive_field (value, 0, type_index, type);
+    }
+  if (e.reason < 0)
+    {
+      return NULL;
+    }
+  else
+    {
+      return result;
+    }
+}
+
+/* Obtain the information about child INDEX of the variable
+   object PARENT.
+   If CNAME is not null, sets *CNAME to the name of the child relative
+   to the parent.
+   If CVALUE is not null, sets *CVALUE to the value of the child.
+   If CTYPE is not null, sets *CTYPE to the type of the child.
+
+   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
+   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
+   to NULL.  */
+static void 
+c_describe_child (struct varobj *parent, int index,
+		  char **cname, struct value **cvalue, struct type **ctype,
+		  char **cfull_expression)
+{
+  struct value *value = parent->value;
+  struct type *type = varobj_get_value_type (parent);
+  char *parent_expression = NULL;
+  int was_ptr;
+  volatile struct gdb_exception except;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    {
+      *cfull_expression = NULL;
+      parent_expression
+	= varobj_get_path_expr (varobj_get_path_expr_parent (parent));
+    }
+  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
+      
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (cname)
+	*cname
+	  = xstrdup (int_string (index 
+				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				 10, 1, 0, 0));
+
+      if (cvalue && value)
+	{
+	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
+
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_subscript (value, real_index);
+	    }
+	}
+
+      if (ctype)
+	*ctype = get_target_type (type);
+
+      if (cfull_expression)
+	*cfull_expression = 
+	  xstrprintf ("(%s)[%s]", parent_expression, 
+		      int_string (index
+				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				  10, 1, 0, 0));
+
+
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      {
+	const char *field_name;
+
+	/* If the type is anonymous and the field has no name,
+	   set an appropriate name.  */
+	field_name = TYPE_FIELD_NAME (type, index);
+	if (field_name == NULL || *field_name == '\0')
+	  {
+	    if (cname)
+	      {
+		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
+		    == TYPE_CODE_STRUCT)
+		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		else
+		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
+	      }
+
+	    if (cfull_expression)
+	      *cfull_expression = xstrdup ("");
+	  }
+	else
+	  {
+	    if (cname)
+	      *cname = xstrdup (field_name);
+
+	    if (cfull_expression)
+	      {
+		char *join = was_ptr ? "->" : ".";
+
+		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
+						join, field_name);
+	      }
+	  }
+
+	if (cvalue && value)
+	  {
+	    /* For C, varobj index is the same as type index.  */
+	    *cvalue = value_struct_element_index (value, index);
+	  }
+
+	if (ctype)
+	  *ctype = TYPE_FIELD_TYPE (type, index);
+      }
+      break;
+
+    case TYPE_CODE_PTR:
+      if (cname)
+	*cname = xstrprintf ("*%s", parent->name);
+
+      if (cvalue && value)
+	{
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_ind (value);
+	    }
+
+	  if (except.reason < 0)
+	    *cvalue = NULL;
+	}
+
+      /* Don't use get_target_type because it calls
+	 check_typedef and here, we want to show the true
+	 declared type of the variable.  */
+      if (ctype)
+	*ctype = TYPE_TARGET_TYPE (type);
+
+      if (cfull_expression)
+	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
+      
+      break;
+
+    default:
+      /* This should not happen.  */
+      if (cname)
+	*cname = xstrdup ("???");
+      if (cfull_expression)
+	*cfull_expression = xstrdup ("???");
+      /* Don't set value and type, we don't know then.  */
+    }
+}
+
+static char *
+c_name_of_child (struct varobj *parent, int index)
+{
+  char *name;
+
+  c_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+c_path_expr_of_child (struct varobj *child)
+{
+  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+		    &child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+c_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  c_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+c_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  c_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+/* This returns the type of the variable.  It also skips past typedefs
+   to return the real type of the variable.  */
+
+static struct type *
+get_type (struct varobj *var)
+{
+  struct type *type;
+
+  type = var->type;
+  if (type != NULL)
+    type = check_typedef (type);
+
+  return type;
+}
+
+static char *
+c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  /* BOGUS: if val_print sees a struct/class, or a reference to one,
+     it will print out its children instead of "{...}".  So we need to
+     catch that case explicitly.  */
+  struct type *type = get_type (var);
+
+  /* Strip top-level references.  */
+  while (TYPE_CODE (type) == TYPE_CODE_REF)
+    type = check_typedef (TYPE_TARGET_TYPE (type));
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      return xstrdup ("{...}");
+      /* break; */
+
+    case TYPE_CODE_ARRAY:
+      {
+	char *number;
+
+	number = xstrprintf ("[%d]", var->num_children);
+	return (number);
+      }
+      /* break; */
+
+    default:
+      {
+	if (var->value == NULL)
+	  {
+	    /* This can happen if we attempt to get the value of a struct
+	       member when the parent is an invalid pointer.  This is an
+	       error condition, so we should tell the caller.  */
+	    return NULL;
+	  }
+	else
+	  {
+	    if (var->not_fetched && value_lazy (var->value))
+	      /* Frozen variable and no value yet.  We don't
+		 implicitly fetch the value.  MI response will
+		 use empty string for the value, which is OK.  */
+	      return NULL;
+
+	    gdb_assert (varobj_value_is_changeable_p (var));
+	    gdb_assert (!value_lazy (var->value));
+	    
+	    /* If the specified format is the current one,
+	       we can reuse print_value.  */
+	    if (format == var->format)
+	      return xstrdup (var->print_value);
+	    else
+	      return varobj_value_get_print_value (var->value, format, var);
+	  }
+      }
+    }
+}
+\f
+
+const struct lang_varobj_ops c_varobj_ops =
+{
+   c_number_of_children,
+   c_name_of_variable,
+   c_name_of_child,
+   c_path_expr_of_child,
+   c_value_of_child,
+   c_type_of_child,
+   c_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+/* A little convenience enum for dealing with C++/Java.  */
+enum vsections
+{
+  v_public = 0, v_private, v_protected
+};
+
+/* C++ */
+
+static int
+cplus_number_of_children (struct varobj *var)
+{
+  struct value *value = NULL;
+  struct type *type;
+  int children, dont_know;
+  int lookup_actual_type = 0;
+  struct value_print_options opts;
+
+  dont_know = 1;
+  children = 0;
+
+  get_user_print_options (&opts);
+
+  if (!CPLUS_FAKE_CHILD (var))
+    {
+      type = varobj_get_value_type (var);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+          value = var->value;
+          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
+	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
+	{
+	  int kids[3];
+
+	  cplus_class_num_children (type, kids);
+	  if (kids[v_public] != 0)
+	    children++;
+	  if (kids[v_private] != 0)
+	    children++;
+	  if (kids[v_protected] != 0)
+	    children++;
+
+	  /* Add any baseclasses.  */
+	  children += TYPE_N_BASECLASSES (type);
+	  dont_know = 0;
+
+	  /* FIXME: save children in var.  */
+	}
+    }
+  else
+    {
+      int kids[3];
+
+      type = varobj_get_value_type (var->parent);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+	  struct varobj *parent = var->parent;
+
+	  value = parent->value;
+	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
+				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      cplus_class_num_children (type, kids);
+      if (strcmp (var->name, "public") == 0)
+	children = kids[v_public];
+      else if (strcmp (var->name, "private") == 0)
+	children = kids[v_private];
+      else
+	children = kids[v_protected];
+      dont_know = 0;
+    }
+
+  if (dont_know)
+    children = c_number_of_children (var);
+
+  return children;
+}
+
+/* Compute # of public, private, and protected variables in this class.
+   That means we need to descend into all baseclasses and find out
+   how many are there, too.  */
+static void
+cplus_class_num_children (struct type *type, int children[3])
+{
+  int i, vptr_fieldno;
+  struct type *basetype = NULL;
+
+  children[v_public] = 0;
+  children[v_private] = 0;
+  children[v_protected] = 0;
+
+  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+    {
+      /* If we have a virtual table pointer, omit it.  Even if virtual
+	 table pointers are not specifically marked in the debug info,
+	 they should be artificial.  */
+      if ((type == basetype && i == vptr_fieldno)
+	  || TYPE_FIELD_ARTIFICIAL (type, i))
+	continue;
+
+      if (TYPE_FIELD_PROTECTED (type, i))
+	children[v_protected]++;
+      else if (TYPE_FIELD_PRIVATE (type, i))
+	children[v_private]++;
+      else
+	children[v_public]++;
+    }
+}
+
+static char *
+cplus_name_of_variable (struct varobj *parent)
+{
+  return c_name_of_variable (parent);
+}
+
+enum accessibility { private_field, protected_field, public_field };
+
+/* Check if field INDEX of TYPE has the specified accessibility.
+   Return 0 if so and 1 otherwise.  */
+static int 
+match_accessibility (struct type *type, int index, enum accessibility acc)
+{
+  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
+    return 1;
+  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
+	   && !TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else
+    return 0;
+}
+
+static void
+cplus_describe_child (struct varobj *parent, int index,
+		      char **cname, struct value **cvalue, struct type **ctype,
+		      char **cfull_expression)
+{
+  struct value *value;
+  struct type *type;
+  int was_ptr;
+  int lookup_actual_type = 0;
+  char *parent_expression = NULL;
+  struct varobj *var;
+  struct value_print_options opts;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    *cfull_expression = NULL;
+
+  get_user_print_options (&opts);
+
+  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
+  if (opts.objectprint)
+    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
+  value = var->value;
+  type = varobj_get_value_type (var);
+  if (cfull_expression)
+    parent_expression
+      = varobj_get_path_expr (varobj_get_path_expr_parent (var));
+
+  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
+
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+      || TYPE_CODE (type) == TYPE_CODE_UNION)
+    {
+      char *join = was_ptr ? "->" : ".";
+
+      if (CPLUS_FAKE_CHILD (parent))
+	{
+	  /* The fields of the class type are ordered as they
+	     appear in the class.  We are given an index for a
+	     particular access control type ("public","protected",
+	     or "private").  We must skip over fields that don't
+	     have the access control we are looking for to properly
+	     find the indexed field.  */
+	  int type_index = TYPE_N_BASECLASSES (type);
+	  enum accessibility acc = public_field;
+	  int vptr_fieldno;
+	  struct type *basetype = NULL;
+	  const char *field_name;
+
+	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+	  if (strcmp (parent->name, "private") == 0)
+	    acc = private_field;
+	  else if (strcmp (parent->name, "protected") == 0)
+	    acc = protected_field;
+
+	  while (index >= 0)
+	    {
+	      if ((type == basetype && type_index == vptr_fieldno)
+		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
+		; /* ignore vptr */
+	      else if (match_accessibility (type, type_index, acc))
+		    --index;
+		  ++type_index;
+	    }
+	  --type_index;
+
+	  /* If the type is anonymous and the field has no name,
+	     set an appopriate name.  */
+	  field_name = TYPE_FIELD_NAME (type, type_index);
+	  if (field_name == NULL || *field_name == '\0')
+	    {
+	      if (cname)
+		{
+		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+		      == TYPE_CODE_STRUCT)
+		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+			   == TYPE_CODE_UNION)
+		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
+		}
+
+	      if (cfull_expression)
+		*cfull_expression = xstrdup ("");
+	    }
+	  else
+	    {
+	      if (cname)
+		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
+
+	      if (cfull_expression)
+		*cfull_expression
+		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
+				field_name);
+	    }
+
+	  if (cvalue && value)
+	    *cvalue = value_struct_element_index (value, type_index);
+
+	  if (ctype)
+	    *ctype = TYPE_FIELD_TYPE (type, type_index);
+	}
+      else if (index < TYPE_N_BASECLASSES (type))
+	{
+	  /* This is a baseclass.  */
+	  if (cname)
+	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
+
+	  if (cvalue && value)
+	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
+
+	  if (ctype)
+	    {
+	      *ctype = TYPE_FIELD_TYPE (type, index);
+	    }
+
+	  if (cfull_expression)
+	    {
+	      char *ptr = was_ptr ? "*" : "";
+
+	      /* Cast the parent to the base' type.  Note that in gdb,
+		 expression like 
+		         (Base1)d
+		 will create an lvalue, for all appearences, so we don't
+		 need to use more fancy:
+		         *(Base1*)(&d)
+		 construct.
+
+		 When we are in the scope of the base class or of one
+		 of its children, the type field name will be interpreted
+		 as a constructor, if it exists.  Therefore, we must
+		 indicate that the name is a class name by using the
+		 'class' keyword.  See PR mi/11912  */
+	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
+					      ptr, 
+					      TYPE_FIELD_NAME (type, index),
+					      ptr,
+					      parent_expression);
+	    }
+	}
+      else
+	{
+	  char *access = NULL;
+	  int children[3];
+
+	  cplus_class_num_children (type, children);
+
+	  /* Everything beyond the baseclasses can
+	     only be "public", "private", or "protected"
+
+	     The special "fake" children are always output by varobj in
+	     this order.  So if INDEX == 2, it MUST be "protected".  */
+	  index -= TYPE_N_BASECLASSES (type);
+	  switch (index)
+	    {
+	    case 0:
+	      if (children[v_public] > 0)
+	 	access = "public";
+	      else if (children[v_private] > 0)
+	 	access = "private";
+	      else 
+	 	access = "protected";
+	      break;
+	    case 1:
+	      if (children[v_public] > 0)
+		{
+		  if (children[v_private] > 0)
+		    access = "private";
+		  else
+		    access = "protected";
+		}
+	      else if (children[v_private] > 0)
+	 	access = "protected";
+	      break;
+	    case 2:
+	      /* Must be protected.  */
+	      access = "protected";
+	      break;
+	    default:
+	      /* error!  */
+	      break;
+	    }
+
+	  gdb_assert (access);
+	  if (cname)
+	    *cname = xstrdup (access);
+
+	  /* Value and type and full expression are null here.  */
+	}
+    }
+  else
+    {
+      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
+    }  
+}
+
+static char *
+cplus_name_of_child (struct varobj *parent, int index)
+{
+  char *name = NULL;
+
+  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+cplus_path_expr_of_child (struct varobj *child)
+{
+  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+			&child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+cplus_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+cplus_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+static char *
+cplus_value_of_variable (struct varobj *var, 
+			 enum varobj_display_formats format)
+{
+
+  /* If we have one of our special types, don't print out
+     any value.  */
+  if (CPLUS_FAKE_CHILD (var))
+    return xstrdup ("");
+
+  return c_value_of_variable (var, format);
+}
+\f
+
+const struct lang_varobj_ops cplus_varobj_ops =
+{
+   cplus_number_of_children,
+   cplus_name_of_variable,
+   cplus_name_of_child,
+   cplus_path_expr_of_child,
+   cplus_value_of_child,
+   cplus_type_of_child,
+   cplus_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+\f
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index dd2ef96..25f0e23 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -239,6 +239,22 @@ get_type_arch (const struct type *type)
     return TYPE_OWNER (type).gdbarch;
 }
 
+/* This returns the target type (or NULL) of TYPE, also skipping
+   past typedefs.  */
+
+struct type *
+get_target_type (struct type *type)
+{
+  if (type != NULL)
+    {
+      type = TYPE_TARGET_TYPE (type);
+      if (type != NULL)
+	type = check_typedef (type);
+    }
+
+  return type;
+}
+
 /* Alloc a new type instance structure, fill it with some defaults,
    and point it at OLDTYPE.  Allocate the new type instance from the
    same place as OLDTYPE.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 0ca7a87..3380dbc 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1431,6 +1431,10 @@ extern struct type *alloc_type_copy (const struct type *);
    objfile's architecture is returned.  */
 extern struct gdbarch *get_type_arch (const struct type *);
 
+/* This returns the target type (or NULL) of TYPE, also skipping
+   past typedefs.  */
+extern struct type *get_target_type (struct type *type);
+
 /* Helper function to construct objfile-owned types.  */
 extern struct type *init_type (enum type_code, int, int, const char *,
 			       struct objfile *);
diff --git a/gdb/jv-varobj.c b/gdb/jv-varobj.c
new file mode 100644
index 0000000..4cc71a3
--- /dev/null
+++ b/gdb/jv-varobj.c
@@ -0,0 +1,104 @@
+/* varobj support for Java.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "varobj.h"
+#include "lang-varobj.h"
+
+/* Java */
+
+static int
+java_number_of_children (struct varobj *var)
+{
+  return cplus_varobj_ops.number_of_children (var);
+}
+
+static char *
+java_name_of_variable (struct varobj *parent)
+{
+  char *p, *name;
+
+  name = cplus_varobj_ops.name_of_variable (parent);
+  /* If  the name has "-" in it, it is because we
+     needed to escape periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '-')
+	*p = '.';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_name_of_child (struct varobj *parent, int index)
+{
+  char *name, *p;
+
+  name = cplus_varobj_ops.name_of_child (parent, index);
+  /* Escape any periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '.')
+	*p = '-';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_path_expr_of_child (struct varobj *child)
+{
+  return NULL;
+}
+
+static struct value *
+java_value_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.value_of_child (parent, index);
+}
+
+static struct type *
+java_type_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.type_of_child (parent, index);
+}
+
+static char *
+java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  return cplus_varobj_ops.value_of_variable (var, format);
+}
+
+const struct lang_varobj_ops java_varobj_ops =
+{
+   java_number_of_children,
+   java_name_of_variable,
+   java_name_of_child,
+   java_path_expr_of_child,
+   java_value_of_child,
+   java_type_of_child,
+   java_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
diff --git a/gdb/lang-varobj.h b/gdb/lang-varobj.h
index b49e42a..2be50bc 100644
--- a/gdb/lang-varobj.h
+++ b/gdb/lang-varobj.h
@@ -71,4 +71,9 @@ struct lang_varobj_ops
 			    struct type *new_type);
 };
 
+const struct lang_varobj_ops c_varobj_ops;
+const struct lang_varobj_ops cplus_varobj_ops;
+const struct lang_varobj_ops java_varobj_ops;
+const struct lang_varobj_ops ada_varobj_ops;
+
 #endif /* LANG_VAROBJ_H */
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 43d5dbf..7ada5a7 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -33,8 +33,6 @@
 #include "vec.h"
 #include "gdbthread.h"
 #include "inferior.h"
-#include "ada-varobj.h"
-#include "ada-lang.h"
 #include "lang-varobj.h"
 
 #if HAVE_PYTHON
@@ -44,10 +42,6 @@
 typedef int PyObject;
 #endif
 
-/* The names of varobjs representing anonymous structs or unions.  */
-#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
-#define ANONYMOUS_UNION_NAME _("<anonymous union>")
-
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
 unsigned int varobjdebug = 0;
@@ -194,12 +188,6 @@ static void free_variable (struct varobj *var);
 
 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
 
-static struct type *get_type (struct varobj *var);
-
-static struct type *get_value_type (struct varobj *var);
-
-static struct type *get_target_type (struct type *);
-
 static enum varobj_display_formats variable_default_display (struct varobj *);
 
 static void cppush (struct cpstack **pstack, char *name);
@@ -229,12 +217,6 @@ static struct value *value_of_child (struct varobj *parent, int index);
 static char *my_value_of_variable (struct varobj *var,
 				   enum varobj_display_formats format);
 
-static char *value_get_print_value (struct value *value,
-				    enum varobj_display_formats format,
-				    struct varobj *var);
-
-static int varobj_value_is_changeable_p (struct varobj *var);
-
 static int is_root_p (struct varobj *var);
 
 #if HAVE_PYTHON
@@ -245,137 +227,12 @@ static struct varobj *varobj_add_child (struct varobj *var,
 
 #endif /* HAVE_PYTHON */
 
-static int default_value_is_changeable_p (struct varobj *var);
-
-/* C implementation */
-
-static int c_number_of_children (struct varobj *var);
-
-static char *c_name_of_variable (struct varobj *parent);
-
-static char *c_name_of_child (struct varobj *parent, int index);
-
-static char *c_path_expr_of_child (struct varobj *child);
-
-static struct value *c_value_of_child (struct varobj *parent, int index);
-
-static struct type *c_type_of_child (struct varobj *parent, int index);
-
-static char *c_value_of_variable (struct varobj *var,
-				  enum varobj_display_formats format);
-
-/* C++ implementation */
-
-static int cplus_number_of_children (struct varobj *var);
-
-static void cplus_class_num_children (struct type *type, int children[3]);
-
-static char *cplus_name_of_variable (struct varobj *parent);
-
-static char *cplus_name_of_child (struct varobj *parent, int index);
-
-static char *cplus_path_expr_of_child (struct varobj *child);
-
-static struct value *cplus_value_of_child (struct varobj *parent, int index);
-
-static struct type *cplus_type_of_child (struct varobj *parent, int index);
-
-static char *cplus_value_of_variable (struct varobj *var,
-				      enum varobj_display_formats format);
-
-/* Java implementation */
-
-static int java_number_of_children (struct varobj *var);
-
-static char *java_name_of_variable (struct varobj *parent);
-
-static char *java_name_of_child (struct varobj *parent, int index);
-
-static char *java_path_expr_of_child (struct varobj *child);
-
-static struct value *java_value_of_child (struct varobj *parent, int index);
-
-static struct type *java_type_of_child (struct varobj *parent, int index);
-
-static char *java_value_of_variable (struct varobj *var,
-				     enum varobj_display_formats format);
-
-/* Ada implementation */
-
-static int ada_number_of_children (struct varobj *var);
-
-static char *ada_name_of_variable (struct varobj *parent);
-
-static char *ada_name_of_child (struct varobj *parent, int index);
-
-static char *ada_path_expr_of_child (struct varobj *child);
-
-static struct value *ada_value_of_child (struct varobj *parent, int index);
-
-static struct type *ada_type_of_child (struct varobj *parent, int index);
-
-static char *ada_value_of_variable (struct varobj *var,
-				    enum varobj_display_formats format);
-
-static int ada_value_is_changeable_p (struct varobj *var);
-
-static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
-				  struct type *new_type);
-
 /* Array of known source language routines.  */
-static struct lang_varobj_ops languages[vlang_end] = {
-  /* C */
-  {
-   c_number_of_children,
-   c_name_of_variable,
-   c_name_of_child,
-   c_path_expr_of_child,
-   c_value_of_child,
-   c_type_of_child,
-   c_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* C++ */
-  {
-   cplus_number_of_children,
-   cplus_name_of_variable,
-   cplus_name_of_child,
-   cplus_path_expr_of_child,
-   cplus_value_of_child,
-   cplus_type_of_child,
-   cplus_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* Java */
-  {
-   java_number_of_children,
-   java_name_of_variable,
-   java_name_of_child,
-   java_path_expr_of_child,
-   java_value_of_child,
-   java_type_of_child,
-   java_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */},
-  /* Ada */
-  {
-   ada_number_of_children,
-   ada_name_of_variable,
-   ada_name_of_child,
-   ada_path_expr_of_child,
-   ada_value_of_child,
-   ada_type_of_child,
-   ada_value_of_variable,
-   ada_value_is_changeable_p,
-   ada_value_has_mutated}
-};
-
-/* A little convenience enum for dealing with C++/Java.  */
-enum vsections
-{
-  v_public = 0, v_private, v_protected
+static const struct lang_varobj_ops *languages[vlang_end] = {
+  &c_varobj_ops,
+  &cplus_varobj_ops,
+  &java_varobj_ops,
+  &ada_varobj_ops,
 };
 
 /* Private data */
@@ -393,9 +250,6 @@ static struct varobj_root *rootlist;
 /* Pointer to the varobj hash table (built at run time).  */
 static struct vlist **varobj_table;
 
-/* Is the variable X one of our "fake" children?  */
-#define CPLUS_FAKE_CHILD(x) \
-((x) != NULL && (x)->type == NULL && (x)->value == NULL)
 \f
 
 /* API Implementation */
@@ -583,7 +437,7 @@ varobj_create (char *objname,
 
       /* Set language info */
       lang = variable_language (var);
-      var->root->lang = &languages[lang];
+      var->root->lang = (struct lang_varobj_ops *) languages[lang];
 
       install_new_value (var, value, 1 /* Initial assignment */);
 
@@ -763,7 +617,8 @@ varobj_set_display_format (struct varobj *var,
       && var->value && !value_lazy (var->value))
     {
       xfree (var->print_value);
-      var->print_value = value_get_print_value (var->value, var->format, var);
+      var->print_value = varobj_value_get_print_value (var->value,
+						       var->format, var);
     }
 
   return var->format;
@@ -846,8 +701,8 @@ varobj_get_frozen (struct varobj *var)
    of FROM and TO -- if either is negative, the entire range is
    used.  */
 
-static void
-restrict_range (VEC (varobj_p) *children, int *from, int *to)
+void
+varobj_restrict_range (VEC (varobj_p) *children, int *from, int *to)
 {
   if (*from < 0 || *to < 0)
     {
@@ -1157,7 +1012,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	 varobj twice is not something a sane frontend would do.  */
       update_dynamic_varobj_children (var_dyn, NULL, NULL, NULL, NULL,
 				      &children_changed, 0, 0, *to);
-      restrict_range (var->children, from, to);
+      varobj_restrict_range (var->children, from, to);
       return var->children;
     }
 
@@ -1188,7 +1043,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	}
     }
 
-  restrict_range (var->children, from, to);
+  varobj_restrict_range (var->children, from, to);
   return var->children;
 }
 
@@ -1242,7 +1097,7 @@ is_path_expr_parent (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   /* Anonymous unions and structs are also not path_expr parents.  */
   return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
@@ -1252,8 +1107,8 @@ is_path_expr_parent (struct varobj *var)
 
 /* Return the path expression parent for VAR.  */
 
-static struct varobj *
-get_path_expr_parent (struct varobj *var)
+struct varobj *
+varobj_get_path_expr_parent (struct varobj *var)
 {
   struct varobj *parent = var;
 
@@ -1648,7 +1503,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      lazy -- if it is, the code above has decided that the value
      should not be fetched.  */
   if (value && !value_lazy (value) && var_dyn->pretty_printer == NULL)
-    print_value = value_get_print_value (value, var->format, var);
+    print_value = varobj_value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
      If this is the initial assignment, we don't have any old value
@@ -1722,7 +1577,8 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   if (var_dyn->pretty_printer != NULL)
     {
       xfree (print_value);
-      print_value = value_get_print_value (var->value, var->format, var);
+      print_value = varobj_value_get_print_value (var->value, var->format,
+						  var);
       if ((var->print_value == NULL && print_value != NULL)
 	  || (var->print_value != NULL && print_value == NULL)
 	  || (var->print_value != NULL && print_value != NULL
@@ -2271,20 +2127,6 @@ create_child (struct varobj *parent, int index, char *name)
 				  value_of_child (parent, index));
 }
 
-/* Does CHILD represent a child with no name?  This happens when
-   the child is an anonmous struct or union and it has no field name
-   in its parent variable.
-
-   This has already been determined by *_describe_child. The easiest
-   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
-
-static int
-is_anonymous_child (struct varobj *child)
-{
-  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
-	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
-}
-
 static struct varobj *
 create_child_with_value (struct varobj *parent, int index, const char *name,
 			 struct value *value)
@@ -2301,7 +2143,7 @@ create_child_with_value (struct varobj *parent, int index, const char *name,
   child->parent = parent;
   child->root = parent->root;
 
-  if (is_anonymous_child (child))
+  if (varobj_is_anonymous_child (child))
     childs_name = xstrprintf ("%s.%d_anonymous", parent->obj_name, index);
   else
     childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
@@ -2427,23 +2269,6 @@ make_cleanup_free_variable (struct varobj *var)
   return make_cleanup (do_free_variable_cleanup, var);
 }
 
-/* This returns the type of the variable.  It also skips past typedefs
-   to return the real type of the variable.
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_type (struct varobj *var)
-{
-  struct type *type;
-
-  type = var->type;
-  if (type != NULL)
-    type = check_typedef (type);
-
-  return type;
-}
-
 /* Return the type of the value that's stored in VAR,
    or that would have being stored there if the
    value were accessible.
@@ -2455,8 +2280,8 @@ get_type (struct varobj *var)
    the values and for comparing previous and new values.
 
    For example, top-level references are always stripped.  */
-static struct type *
-get_value_type (struct varobj *var)
+struct type *
+varobj_get_value_type (struct varobj *var)
 {
   struct type *type;
 
@@ -2475,24 +2300,6 @@ get_value_type (struct varobj *var)
   return type;
 }
 
-/* This returns the target type (or NULL) of TYPE, also skipping
-   past typedefs, just like get_type ().
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_target_type (struct type *type)
-{
-  if (type != NULL)
-    {
-      type = TYPE_TARGET_TYPE (type);
-      if (type != NULL)
-	type = check_typedef (type);
-    }
-
-  return type;
-}
-
 /* What is the default display for this variable? We assume that
    everything is "natural".  Any exceptions?  */
 static enum varobj_display_formats
@@ -2785,16 +2592,26 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
   if (var->root->is_valid)
     {
       if (((struct varobj_dynamic *) var)->pretty_printer)
-	return value_get_print_value (var->value, var->format, var);
+	return varobj_value_get_print_value (var->value, var->format, var);
       return (*var->root->lang->value_of_variable) (var, format);
     }
   else
     return NULL;
 }
 
-static char *
-value_get_print_value (struct value *value, enum varobj_display_formats format,
-		       struct varobj *var)
+void
+varobj_formatted_print_options (struct value_print_options *opts,
+				enum varobj_display_formats format)
+{
+  get_formatted_print_options (opts, format_code[(int) format]);
+  opts->deref_ref = 0;
+  opts->raw = 1;
+}
+
+char *
+varobj_value_get_print_value (struct value *value,
+			      enum varobj_display_formats format,
+			      struct varobj *var)
 {
   struct ui_file *stb;
   struct cleanup *old_chain;
@@ -2906,9 +2723,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
     }
 #endif
 
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
+  varobj_formatted_print_options (&opts, format);
 
   /* If the THEVALUE has contents, it is a regular string.  */
   if (thevalue)
@@ -2935,7 +2750,7 @@ varobj_editable_p (struct varobj *var)
   if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -2955,7 +2770,7 @@ varobj_editable_p (struct varobj *var)
 
 /* Call VAR's value_is_changeable_p language-specific callback.  */
 
-static int
+int
 varobj_value_is_changeable_p (struct varobj *var)
 {
   return var->root->lang->value_is_changeable_p (var);
@@ -2970,95 +2785,11 @@ varobj_floating_p (struct varobj *var)
   return var->root->floating;
 }
 
-/* Given the value and the type of a variable object,
-   adjust the value and type to those necessary
-   for getting children of the variable object.
-   This includes dereferencing top-level references
-   to all types and dereferencing pointers to
-   structures.
-
-   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
-   value will be fetched and if it differs from static type
-   the value will be casted to it.
-
-   Both TYPE and *TYPE should be non-null.  VALUE
-   can be null if we want to only translate type.
-   *VALUE can be null as well -- if the parent
-   value is not known.
-
-   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
-   depending on whether pointer was dereferenced
-   in this function.  */
-static void
-adjust_value_for_child_access (struct value **value,
-				  struct type **type,
-				  int *was_ptr,
-				  int lookup_actual_type)
-{
-  gdb_assert (type && *type);
-
-  if (was_ptr)
-    *was_ptr = 0;
-
-  *type = check_typedef (*type);
-  
-  /* The type of value stored in varobj, that is passed
-     to us, is already supposed to be
-     reference-stripped.  */
-
-  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
-
-  /* Pointers to structures are treated just like
-     structures when accessing children.  Don't
-     dererences pointers to other types.  */
-  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
-    {
-      struct type *target_type = get_target_type (*type);
-      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
-	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
-	{
-	  if (value && *value)
-	    {
-	      volatile struct gdb_exception except;
-
-	      TRY_CATCH (except, RETURN_MASK_ERROR)
-		{
-		  *value = value_ind (*value);
-		}
-
-	      if (except.reason < 0)
-		*value = NULL;
-	    }
-	  *type = target_type;
-	  if (was_ptr)
-	    *was_ptr = 1;
-	}
-    }
-
-  /* The 'get_target_type' function calls check_typedef on
-     result, so we can immediately check type code.  No
-     need to call check_typedef here.  */
-
-  /* Access a real type of the value (if necessary and possible).  */
-  if (value && *value && lookup_actual_type)
-    {
-      struct type *enclosing_type;
-      int real_type_found = 0;
-
-      enclosing_type = value_actual_type (*value, 1, &real_type_found);
-      if (real_type_found)
-        {
-          *type = enclosing_type;
-          *value = value_cast (enclosing_type, *value);
-        }
-    }
-}
-
 /* Implement the "value_is_changeable_p" varobj callback for most
    languages.  */
 
-static int
-default_value_is_changeable_p (struct varobj *var)
+int
+varobj_default_value_is_changeable_p (struct varobj *var)
 {
   int r;
   struct type *type;
@@ -3066,7 +2797,7 @@ default_value_is_changeable_p (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -3083,925 +2814,6 @@ default_value_is_changeable_p (struct varobj *var)
   return r;
 }
 
-/* C */
-
-static int
-c_number_of_children (struct varobj *var)
-{
-  struct type *type = get_value_type (var);
-  int children = 0;
-  struct type *target;
-
-  adjust_value_for_child_access (NULL, &type, NULL, 0);
-  target = get_target_type (type);
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
-	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
-      else
-	/* If we don't know how many elements there are, don't display
-	   any.  */
-	children = 0;
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      children = TYPE_NFIELDS (type);
-      break;
-
-    case TYPE_CODE_PTR:
-      /* The type here is a pointer to non-struct.  Typically, pointers
-	 have one child, except for function ptrs, which have no children,
-	 and except for void*, as we don't know what to show.
-
-         We can show char* so we allow it to be dereferenced.  If you decide
-         to test for it, please mind that a little magic is necessary to
-         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
-         TYPE_NAME == "char".  */
-      if (TYPE_CODE (target) == TYPE_CODE_FUNC
-	  || TYPE_CODE (target) == TYPE_CODE_VOID)
-	children = 0;
-      else
-	children = 1;
-      break;
-
-    default:
-      /* Other types have no children.  */
-      break;
-    }
-
-  return children;
-}
-
-static char *
-c_name_of_variable (struct varobj *parent)
-{
-  return xstrdup (parent->name);
-}
-
-/* Return the value of element TYPE_INDEX of a structure
-   value VALUE.  VALUE's type should be a structure,
-   or union, or a typedef to struct/union.
-
-   Returns NULL if getting the value fails.  Never throws.  */
-static struct value *
-value_struct_element_index (struct value *value, int type_index)
-{
-  struct value *result = NULL;
-  volatile struct gdb_exception e;
-  struct type *type = value_type (value);
-
-  type = check_typedef (type);
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
-	      || TYPE_CODE (type) == TYPE_CODE_UNION);
-
-  TRY_CATCH (e, RETURN_MASK_ERROR)
-    {
-      if (field_is_static (&TYPE_FIELD (type, type_index)))
-	result = value_static_field (type, type_index);
-      else
-	result = value_primitive_field (value, 0, type_index, type);
-    }
-  if (e.reason < 0)
-    {
-      return NULL;
-    }
-  else
-    {
-      return result;
-    }
-}
-
-/* Obtain the information about child INDEX of the variable
-   object PARENT.
-   If CNAME is not null, sets *CNAME to the name of the child relative
-   to the parent.
-   If CVALUE is not null, sets *CVALUE to the value of the child.
-   If CTYPE is not null, sets *CTYPE to the type of the child.
-
-   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
-   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
-   to NULL.  */
-static void 
-c_describe_child (struct varobj *parent, int index,
-		  char **cname, struct value **cvalue, struct type **ctype,
-		  char **cfull_expression)
-{
-  struct value *value = parent->value;
-  struct type *type = get_value_type (parent);
-  char *parent_expression = NULL;
-  int was_ptr;
-  volatile struct gdb_exception except;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    {
-      *cfull_expression = NULL;
-      parent_expression = varobj_get_path_expr (get_path_expr_parent (parent));
-    }
-  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
-      
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (cname)
-	*cname
-	  = xstrdup (int_string (index 
-				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				 10, 1, 0, 0));
-
-      if (cvalue && value)
-	{
-	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
-
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_subscript (value, real_index);
-	    }
-	}
-
-      if (ctype)
-	*ctype = get_target_type (type);
-
-      if (cfull_expression)
-	*cfull_expression = 
-	  xstrprintf ("(%s)[%s]", parent_expression, 
-		      int_string (index
-				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				  10, 1, 0, 0));
-
-
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      {
-	const char *field_name;
-
-	/* If the type is anonymous and the field has no name,
-	   set an appropriate name.  */
-	field_name = TYPE_FIELD_NAME (type, index);
-	if (field_name == NULL || *field_name == '\0')
-	  {
-	    if (cname)
-	      {
-		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
-		    == TYPE_CODE_STRUCT)
-		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		else
-		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
-	      }
-
-	    if (cfull_expression)
-	      *cfull_expression = xstrdup ("");
-	  }
-	else
-	  {
-	    if (cname)
-	      *cname = xstrdup (field_name);
-
-	    if (cfull_expression)
-	      {
-		char *join = was_ptr ? "->" : ".";
-
-		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
-						join, field_name);
-	      }
-	  }
-
-	if (cvalue && value)
-	  {
-	    /* For C, varobj index is the same as type index.  */
-	    *cvalue = value_struct_element_index (value, index);
-	  }
-
-	if (ctype)
-	  *ctype = TYPE_FIELD_TYPE (type, index);
-      }
-      break;
-
-    case TYPE_CODE_PTR:
-      if (cname)
-	*cname = xstrprintf ("*%s", parent->name);
-
-      if (cvalue && value)
-	{
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_ind (value);
-	    }
-
-	  if (except.reason < 0)
-	    *cvalue = NULL;
-	}
-
-      /* Don't use get_target_type because it calls
-	 check_typedef and here, we want to show the true
-	 declared type of the variable.  */
-      if (ctype)
-	*ctype = TYPE_TARGET_TYPE (type);
-
-      if (cfull_expression)
-	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
-      
-      break;
-
-    default:
-      /* This should not happen.  */
-      if (cname)
-	*cname = xstrdup ("???");
-      if (cfull_expression)
-	*cfull_expression = xstrdup ("???");
-      /* Don't set value and type, we don't know then.  */
-    }
-}
-
-static char *
-c_name_of_child (struct varobj *parent, int index)
-{
-  char *name;
-
-  c_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-c_path_expr_of_child (struct varobj *child)
-{
-  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-		    &child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-c_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  c_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-c_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  c_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  /* BOGUS: if val_print sees a struct/class, or a reference to one,
-     it will print out its children instead of "{...}".  So we need to
-     catch that case explicitly.  */
-  struct type *type = get_type (var);
-
-  /* Strip top-level references.  */
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
-    type = check_typedef (TYPE_TARGET_TYPE (type));
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      return xstrdup ("{...}");
-      /* break; */
-
-    case TYPE_CODE_ARRAY:
-      {
-	char *number;
-
-	number = xstrprintf ("[%d]", var->num_children);
-	return (number);
-      }
-      /* break; */
-
-    default:
-      {
-	if (var->value == NULL)
-	  {
-	    /* This can happen if we attempt to get the value of a struct
-	       member when the parent is an invalid pointer.  This is an
-	       error condition, so we should tell the caller.  */
-	    return NULL;
-	  }
-	else
-	  {
-	    if (var->not_fetched && value_lazy (var->value))
-	      /* Frozen variable and no value yet.  We don't
-		 implicitly fetch the value.  MI response will
-		 use empty string for the value, which is OK.  */
-	      return NULL;
-
-	    gdb_assert (varobj_value_is_changeable_p (var));
-	    gdb_assert (!value_lazy (var->value));
-	    
-	    /* If the specified format is the current one,
-	       we can reuse print_value.  */
-	    if (format == var->format)
-	      return xstrdup (var->print_value);
-	    else
-	      return value_get_print_value (var->value, format, var);
-	  }
-      }
-    }
-}
-\f
-
-/* C++ */
-
-static int
-cplus_number_of_children (struct varobj *var)
-{
-  struct value *value = NULL;
-  struct type *type;
-  int children, dont_know;
-  int lookup_actual_type = 0;
-  struct value_print_options opts;
-
-  dont_know = 1;
-  children = 0;
-
-  get_user_print_options (&opts);
-
-  if (!CPLUS_FAKE_CHILD (var))
-    {
-      type = get_value_type (var);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-          value = var->value;
-          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
-	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
-	{
-	  int kids[3];
-
-	  cplus_class_num_children (type, kids);
-	  if (kids[v_public] != 0)
-	    children++;
-	  if (kids[v_private] != 0)
-	    children++;
-	  if (kids[v_protected] != 0)
-	    children++;
-
-	  /* Add any baseclasses.  */
-	  children += TYPE_N_BASECLASSES (type);
-	  dont_know = 0;
-
-	  /* FIXME: save children in var.  */
-	}
-    }
-  else
-    {
-      int kids[3];
-
-      type = get_value_type (var->parent);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-	  struct varobj *parent = var->parent;
-
-	  value = parent->value;
-	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
-				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      cplus_class_num_children (type, kids);
-      if (strcmp (var->name, "public") == 0)
-	children = kids[v_public];
-      else if (strcmp (var->name, "private") == 0)
-	children = kids[v_private];
-      else
-	children = kids[v_protected];
-      dont_know = 0;
-    }
-
-  if (dont_know)
-    children = c_number_of_children (var);
-
-  return children;
-}
-
-/* Compute # of public, private, and protected variables in this class.
-   That means we need to descend into all baseclasses and find out
-   how many are there, too.  */
-static void
-cplus_class_num_children (struct type *type, int children[3])
-{
-  int i, vptr_fieldno;
-  struct type *basetype = NULL;
-
-  children[v_public] = 0;
-  children[v_private] = 0;
-  children[v_protected] = 0;
-
-  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
-    {
-      /* If we have a virtual table pointer, omit it.  Even if virtual
-	 table pointers are not specifically marked in the debug info,
-	 they should be artificial.  */
-      if ((type == basetype && i == vptr_fieldno)
-	  || TYPE_FIELD_ARTIFICIAL (type, i))
-	continue;
-
-      if (TYPE_FIELD_PROTECTED (type, i))
-	children[v_protected]++;
-      else if (TYPE_FIELD_PRIVATE (type, i))
-	children[v_private]++;
-      else
-	children[v_public]++;
-    }
-}
-
-static char *
-cplus_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-enum accessibility { private_field, protected_field, public_field };
-
-/* Check if field INDEX of TYPE has the specified accessibility.
-   Return 0 if so and 1 otherwise.  */
-static int 
-match_accessibility (struct type *type, int index, enum accessibility acc)
-{
-  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
-    return 1;
-  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
-	   && !TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else
-    return 0;
-}
-
-static void
-cplus_describe_child (struct varobj *parent, int index,
-		      char **cname, struct value **cvalue, struct type **ctype,
-		      char **cfull_expression)
-{
-  struct value *value;
-  struct type *type;
-  int was_ptr;
-  int lookup_actual_type = 0;
-  char *parent_expression = NULL;
-  struct varobj *var;
-  struct value_print_options opts;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    *cfull_expression = NULL;
-
-  get_user_print_options (&opts);
-
-  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
-  if (opts.objectprint)
-    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
-  value = var->value;
-  type = get_value_type (var);
-  if (cfull_expression)
-    parent_expression = varobj_get_path_expr (get_path_expr_parent (var));
-
-  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
-
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (type) == TYPE_CODE_UNION)
-    {
-      char *join = was_ptr ? "->" : ".";
-
-      if (CPLUS_FAKE_CHILD (parent))
-	{
-	  /* The fields of the class type are ordered as they
-	     appear in the class.  We are given an index for a
-	     particular access control type ("public","protected",
-	     or "private").  We must skip over fields that don't
-	     have the access control we are looking for to properly
-	     find the indexed field.  */
-	  int type_index = TYPE_N_BASECLASSES (type);
-	  enum accessibility acc = public_field;
-	  int vptr_fieldno;
-	  struct type *basetype = NULL;
-	  const char *field_name;
-
-	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-	  if (strcmp (parent->name, "private") == 0)
-	    acc = private_field;
-	  else if (strcmp (parent->name, "protected") == 0)
-	    acc = protected_field;
-
-	  while (index >= 0)
-	    {
-	      if ((type == basetype && type_index == vptr_fieldno)
-		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
-		; /* ignore vptr */
-	      else if (match_accessibility (type, type_index, acc))
-		    --index;
-		  ++type_index;
-	    }
-	  --type_index;
-
-	  /* If the type is anonymous and the field has no name,
-	     set an appopriate name.  */
-	  field_name = TYPE_FIELD_NAME (type, type_index);
-	  if (field_name == NULL || *field_name == '\0')
-	    {
-	      if (cname)
-		{
-		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-		      == TYPE_CODE_STRUCT)
-		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-			   == TYPE_CODE_UNION)
-		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
-		}
-
-	      if (cfull_expression)
-		*cfull_expression = xstrdup ("");
-	    }
-	  else
-	    {
-	      if (cname)
-		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
-
-	      if (cfull_expression)
-		*cfull_expression
-		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
-				field_name);
-	    }
-
-	  if (cvalue && value)
-	    *cvalue = value_struct_element_index (value, type_index);
-
-	  if (ctype)
-	    *ctype = TYPE_FIELD_TYPE (type, type_index);
-	}
-      else if (index < TYPE_N_BASECLASSES (type))
-	{
-	  /* This is a baseclass.  */
-	  if (cname)
-	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
-
-	  if (cvalue && value)
-	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
-
-	  if (ctype)
-	    {
-	      *ctype = TYPE_FIELD_TYPE (type, index);
-	    }
-
-	  if (cfull_expression)
-	    {
-	      char *ptr = was_ptr ? "*" : "";
-
-	      /* Cast the parent to the base' type.  Note that in gdb,
-		 expression like 
-		         (Base1)d
-		 will create an lvalue, for all appearences, so we don't
-		 need to use more fancy:
-		         *(Base1*)(&d)
-		 construct.
-
-		 When we are in the scope of the base class or of one
-		 of its children, the type field name will be interpreted
-		 as a constructor, if it exists.  Therefore, we must
-		 indicate that the name is a class name by using the
-		 'class' keyword.  See PR mi/11912  */
-	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
-					      ptr, 
-					      TYPE_FIELD_NAME (type, index),
-					      ptr,
-					      parent_expression);
-	    }
-	}
-      else
-	{
-	  char *access = NULL;
-	  int children[3];
-
-	  cplus_class_num_children (type, children);
-
-	  /* Everything beyond the baseclasses can
-	     only be "public", "private", or "protected"
-
-	     The special "fake" children are always output by varobj in
-	     this order.  So if INDEX == 2, it MUST be "protected".  */
-	  index -= TYPE_N_BASECLASSES (type);
-	  switch (index)
-	    {
-	    case 0:
-	      if (children[v_public] > 0)
-	 	access = "public";
-	      else if (children[v_private] > 0)
-	 	access = "private";
-	      else 
-	 	access = "protected";
-	      break;
-	    case 1:
-	      if (children[v_public] > 0)
-		{
-		  if (children[v_private] > 0)
-		    access = "private";
-		  else
-		    access = "protected";
-		}
-	      else if (children[v_private] > 0)
-	 	access = "protected";
-	      break;
-	    case 2:
-	      /* Must be protected.  */
-	      access = "protected";
-	      break;
-	    default:
-	      /* error!  */
-	      break;
-	    }
-
-	  gdb_assert (access);
-	  if (cname)
-	    *cname = xstrdup (access);
-
-	  /* Value and type and full expression are null here.  */
-	}
-    }
-  else
-    {
-      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
-    }  
-}
-
-static char *
-cplus_name_of_child (struct varobj *parent, int index)
-{
-  char *name = NULL;
-
-  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-cplus_path_expr_of_child (struct varobj *child)
-{
-  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-			&child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-cplus_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-cplus_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-cplus_value_of_variable (struct varobj *var, 
-			 enum varobj_display_formats format)
-{
-
-  /* If we have one of our special types, don't print out
-     any value.  */
-  if (CPLUS_FAKE_CHILD (var))
-    return xstrdup ("");
-
-  return c_value_of_variable (var, format);
-}
-\f
-/* Java */
-
-static int
-java_number_of_children (struct varobj *var)
-{
-  return cplus_number_of_children (var);
-}
-
-static char *
-java_name_of_variable (struct varobj *parent)
-{
-  char *p, *name;
-
-  name = cplus_name_of_variable (parent);
-  /* If  the name has "-" in it, it is because we
-     needed to escape periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '-')
-	*p = '.';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_name_of_child (struct varobj *parent, int index)
-{
-  char *name, *p;
-
-  name = cplus_name_of_child (parent, index);
-  /* Escape any periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '.')
-	*p = '-';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_path_expr_of_child (struct varobj *child)
-{
-  return NULL;
-}
-
-static struct value *
-java_value_of_child (struct varobj *parent, int index)
-{
-  return cplus_value_of_child (parent, index);
-}
-
-static struct type *
-java_type_of_child (struct varobj *parent, int index)
-{
-  return cplus_type_of_child (parent, index);
-}
-
-static char *
-java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  return cplus_value_of_variable (var, format);
-}
-
-/* Ada specific callbacks for VAROBJs.  */
-
-static int
-ada_number_of_children (struct varobj *var)
-{
-  return ada_varobj_get_number_of_children (var->value, var->type);
-}
-
-static char *
-ada_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-static char *
-ada_name_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_name_of_child (parent->value, parent->type,
-				       parent->name, index);
-}
-
-static char*
-ada_path_expr_of_child (struct varobj *child)
-{
-  struct varobj *parent = child->parent;
-  const char *parent_path_expr = varobj_get_path_expr (parent);
-
-  return ada_varobj_get_path_expr_of_child (parent->value,
-					    parent->type,
-					    parent->name,
-					    parent_path_expr,
-					    child->index);
-}
-
-static struct value *
-ada_value_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_value_of_child (parent->value, parent->type,
-					parent->name, index);
-}
-
-static struct type *
-ada_type_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_type_of_child (parent->value, parent->type,
-				       index);
-}
-
-static char *
-ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  struct value_print_options opts;
-
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
-
-  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
-}
-
-/* Implement the "value_is_changeable_p" routine for Ada.  */
-
-static int
-ada_value_is_changeable_p (struct varobj *var)
-{
-  struct type *type = var->value ? value_type (var->value) : var->type;
-
-  if (ada_is_array_descriptor_type (type)
-      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
-    {
-      /* This is in reality a pointer to an unconstrained array.
-	 its value is changeable.  */
-      return 1;
-    }
-
-  if (ada_is_string_type (type))
-    {
-      /* We display the contents of the string in the array's
-	 "value" field.  The contents can change, so consider
-	 that the array is changeable.  */
-      return 1;
-    }
-
-  return default_value_is_changeable_p (var);
-}
-
-/* Implement the "value_has_mutated" routine for Ada.  */
-
-static int
-ada_value_has_mutated (struct varobj *var, struct value *new_val,
-		       struct type *new_type)
-{
-  int i;
-  int from = -1;
-  int to = -1;
-
-  /* If the number of fields have changed, then for sure the type
-     has mutated.  */
-  if (ada_varobj_get_number_of_children (new_val, new_type)
-      != var->num_children)
-    return 1;
-
-  /* If the number of fields have remained the same, then we need
-     to check the name of each field.  If they remain the same,
-     then chances are the type hasn't mutated.  This is technically
-     an incomplete test, as the child's type might have changed
-     despite the fact that the name remains the same.  But we'll
-     handle this situation by saying that the child has mutated,
-     not this value.
-
-     If only part (or none!) of the children have been fetched,
-     then only check the ones we fetched.  It does not matter
-     to the frontend whether a child that it has not fetched yet
-     has mutated or not. So just assume it hasn't.  */
-
-  restrict_range (var->children, &from, &to);
-  for (i = from; i < to; i++)
-    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
-					      var->name, i),
-		VEC_index (varobj_p, var->children, i)->name) != 0)
-      return 1;
-
-  return 0;
-}
-
 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
    with an arbitrary caller supplied DATA pointer.  */
 
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 894ba03..5f6eb88 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -162,6 +162,10 @@ struct varobj
   int to;
 };
 
+/* Is the variable X one of our "fake" children?  */
+#define CPLUS_FAKE_CHILD(x) \
+((x) != NULL && (x)->type == NULL && (x)->value == NULL)
+
 /* API functions */
 
 extern struct varobj *varobj_create (char *objname,
@@ -249,4 +253,22 @@ extern int varobj_has_more (struct varobj *var, int to);
 
 extern int varobj_pretty_printed_p (struct varobj *var);
 
+extern int varobj_default_value_is_changeable_p (struct varobj *var);
+extern int varobj_value_is_changeable_p (struct varobj *var);
+
+extern struct type *varobj_get_value_type (struct varobj *var);
+
+extern int varobj_is_anonymous_child (struct varobj *child);
+
+extern struct varobj *varobj_get_path_expr_parent (struct varobj *var);
+
+extern char *varobj_value_get_print_value (struct value *value,
+					   enum varobj_display_formats format,
+					   struct varobj *var);
+
+extern void varobj_formatted_print_options (struct value_print_options *opts,
+					    enum varobj_display_formats format);
+
+extern void varobj_restrict_range (VEC (varobj_p) *children, int *from,
+				   int *to);
 #endif /* VAROBJ_H */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 5/7] New lang-varobj.h
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
  2013-09-18 13:55 ` [PATCH 1/7] Remove field language in struct language_specific Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-02 17:18   ` Doug Evans
  2013-09-18 13:55 ` [PATCH 6/7] Move language stuff out of varobj.c Yao Qi
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

This patch moves 'struct language_specific' out of varobj.c to a new file
'lang-varobj.h'.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add lang-varobj.h.
	* lang-varobj.h: New.
	* varobj.c: Include "lang-varobj.h".
	(struct varobj_root): <lang>: Update its type.
	(struct language_specific): Move it to lang-varobj.h.
---
 gdb/Makefile.in   |    2 +-
 gdb/lang-varobj.h |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/varobj.c      |   61 +++----------------------------------------
 3 files changed, 80 insertions(+), 57 deletions(-)
 create mode 100644 gdb/lang-varobj.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 93a3d6a..3081e1d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -827,7 +827,7 @@ m68k-tdep.h spu-tdep.h jv-lang.h environ.h solib-irix.h amd64-tdep.h \
 doublest.h regset.h hppa-tdep.h ppc-linux-tdep.h ppc64-tdep.h \
 rs6000-tdep.h rs6000-aix-tdep.h \
 common/gdb_locale.h common/gdb_dirent.h arch-utils.h trad-frame.h gnu-nat.h \
-language.h nbsd-tdep.h solib-svr4.h \
+language.h lang-varobj.h nbsd-tdep.h solib-svr4.h \
 macroexp.h ui-file.h regcache.h tracepoint.h i386-tdep.h \
 inf-child.h p-lang.h event-top.h gdbtypes.h user-regs.h \
 regformats/regdef.h config/alpha/nm-osf3.h  config/i386/nm-i386gnu.h \
diff --git a/gdb/lang-varobj.h b/gdb/lang-varobj.h
new file mode 100644
index 0000000..b49e42a
--- /dev/null
+++ b/gdb/lang-varobj.h
@@ -0,0 +1,74 @@
+/* Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef LANG_VAROBJ_H
+#define LANG_VAROBJ_H 1
+
+#include "varobj.h"
+
+/* The language specific vector */
+
+struct lang_varobj_ops
+{
+  /* The number of children of PARENT.  */
+  int (*number_of_children) (struct varobj * parent);
+
+  /* The name (expression) of a root varobj.  */
+  char *(*name_of_variable) (struct varobj * parent);
+
+  /* The name of the INDEX'th child of PARENT.  */
+  char *(*name_of_child) (struct varobj * parent, int index);
+
+  /* Returns the rooted expression of CHILD, which is a variable
+     obtain that has some parent.  */
+  char *(*path_expr_of_child) (struct varobj * child);
+
+  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
+  struct value *(*value_of_child) (struct varobj * parent, int index);
+
+  /* The type of the INDEX'th child of PARENT.  */
+  struct type *(*type_of_child) (struct varobj * parent, int index);
+
+  /* The current value of VAR.  */
+  char *(*value_of_variable) (struct varobj * var,
+			      enum varobj_display_formats format);
+
+  /* Return non-zero if changes in value of VAR must be detected and
+     reported by -var-update.  Return zero if -var-update should never
+     report changes of such values.  This makes sense for structures
+     (since the changes in children values will be reported separately),
+     or for artifical objects (like 'public' pseudo-field in C++).
+
+     Return value of 0 means that gdb need not call value_fetch_lazy
+     for the value of this variable object.  */
+  int (*value_is_changeable_p) (struct varobj *var);
+
+  /* Return nonzero if the type of VAR has mutated.
+
+     VAR's value is still the varobj's previous value, while NEW_VALUE
+     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
+     may be NULL indicating that there is no value available (the varobj
+     may be out of scope, of may be the child of a null pointer, for
+     instance).  NEW_TYPE, on the other hand, must never be NULL.
+
+     This function should also be able to assume that var's number of
+     children is set (not < 0).
+
+     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);
+};
+
+#endif /* LANG_VAROBJ_H */
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 672d246..43d5dbf 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -35,6 +35,7 @@
 #include "inferior.h"
 #include "ada-varobj.h"
 #include "ada-lang.h"
+#include "lang-varobj.h"
 
 #if HAVE_PYTHON
 #include "python/python.h"
@@ -106,8 +107,9 @@ struct varobj_root
      to symbols that do not exist anymore.  */
   int is_valid;
 
-  /* Language info for this variable and its children.  */
-  struct language_specific *lang;
+  /* Language-related operations for this variable and its
+     children.  */
+  struct lang_varobj_ops *lang;
 
   /* The varobj for this root node.  */
   struct varobj *rootvar;
@@ -320,61 +322,8 @@ static int ada_value_is_changeable_p (struct varobj *var);
 static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
 				  struct type *new_type);
 
-/* The language specific vector */
-
-struct language_specific
-{
-  /* The number of children of PARENT.  */
-  int (*number_of_children) (struct varobj * parent);
-
-  /* The name (expression) of a root varobj.  */
-  char *(*name_of_variable) (struct varobj * parent);
-
-  /* The name of the INDEX'th child of PARENT.  */
-  char *(*name_of_child) (struct varobj * parent, int index);
-
-  /* Returns the rooted expression of CHILD, which is a variable
-     obtain that has some parent.  */
-  char *(*path_expr_of_child) (struct varobj * child);
-
-  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
-  struct value *(*value_of_child) (struct varobj * parent, int index);
-
-  /* The type of the INDEX'th child of PARENT.  */
-  struct type *(*type_of_child) (struct varobj * parent, int index);
-
-  /* The current value of VAR.  */
-  char *(*value_of_variable) (struct varobj * var,
-			      enum varobj_display_formats format);
-
-  /* Return non-zero if changes in value of VAR must be detected and
-     reported by -var-update.  Return zero if -var-update should never
-     report changes of such values.  This makes sense for structures
-     (since the changes in children values will be reported separately),
-     or for artifical objects (like 'public' pseudo-field in C++).
-
-     Return value of 0 means that gdb need not call value_fetch_lazy
-     for the value of this variable object.  */
-  int (*value_is_changeable_p) (struct varobj *var);
-
-  /* Return nonzero if the type of VAR has mutated.
-
-     VAR's value is still the varobj's previous value, while NEW_VALUE
-     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
-     may be NULL indicating that there is no value available (the varobj
-     may be out of scope, of may be the child of a null pointer, for
-     instance).  NEW_TYPE, on the other hand, must never be NULL.
-
-     This function should also be able to assume that var's number of
-     children is set (not < 0).
-
-     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);
-};
-
 /* Array of known source language routines.  */
-static struct language_specific languages[vlang_end] = {
+static struct lang_varobj_ops languages[vlang_end] = {
   /* C */
   {
    c_number_of_children,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 4/7] Move struct varobj to varobj.h.
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
                   ` (3 preceding siblings ...)
  2013-09-18 13:55 ` [PATCH 7/7] Remove ada-varobj.h Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-02  9:46   ` Joel Brobecker
  2013-09-18 13:55 ` [PATCH 3/7] Remove field value_of_root Yao Qi
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

Hi,
This patch moves most of the fields of struct varobj to varobj.h, and
continue to name it 'struct varobj.h' there.  New struct
varobj_dynamic 'extends' struct varobj in varobj.c.

Move part of struct varobj to varobj.h

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* varobj.c (struct varobj): Move most of the fields to
	varobj.h.
	(struct varobj_dynamic): New struct.
	(varobj_get_display_hint) [HAVE_PYTHON]: Cast 'var' to type
	'struct varobj_dynamic'.
	(varobj_has_more): Likewise.
	(dynamic_varobj_has_child_method): Change type of parameter
	'var' to 'struct varobj_dynamic *'.
	(update_dynamic_varobj_children): Likewise.
	(install_visualizer): Likewise.
	(install_default_visualizer, construct_visualizer): Likewise.
	(varobj_get_num_children): Likewise.
	(dynamic_varobj_has_child_method): Adjust.
	(varobj_list_children, varobj_get_attributes): Likewise.
	(varobj_set_value, install_new_value): Likewise.
	(varobj_update, new_variable): Likewise.
	(my_value_of_variable, value_get_print_value): Likewise.
	* varobj.h (struct varobj): Moved from varobj.c.
---
 gdb/varobj.c |  239 +++++++++++++++++++++++-----------------------------------
 gdb/varobj.h |   74 ++++++++++++++++++
 2 files changed, 167 insertions(+), 146 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3ecf702..672d246 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -116,48 +116,11 @@ struct varobj_root
   struct varobj_root *next;
 };
 
-/* Every variable in the system has a structure of this type defined
-   for it.  This structure holds all information necessary to manipulate
-   a particular object variable.  Members which must be freed are noted.  */
-struct varobj
-{
-
-  /* Alloc'd name of the variable for this object.  If this variable is a
-     child, then this name will be the child's source name.
-     (bar, not foo.bar).  */
-  /* NOTE: This is the "expression".  */
-  char *name;
-
-  /* Alloc'd expression for this child.  Can be used to create a
-     root variable corresponding to this child.  */
-  char *path_expr;
-
-  /* The alloc'd name for this variable's object.  This is here for
-     convenience when constructing this object's children.  */
-  char *obj_name;
-
-  /* Index of this variable in its parent or -1.  */
-  int index;
-
-  /* The type of this variable.  This can be NULL
-     for artifial variable objects -- currently, the "accessibility" 
-     variable objects in C++.  */
-  struct type *type;
+/* Dynamic varobj.  */
 
-  /* The value of this expression or subexpression.  A NULL value
-     indicates there was an error getting this value.
-     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
-     the value is either NULL, or not lazy.  */
-  struct value *value;
-
-  /* The number of (immediate) children this variable has.  */
-  int num_children;
-
-  /* If this object is a child, this points to its immediate parent.  */
-  struct varobj *parent;
-
-  /* Children of this object.  */
-  VEC (varobj_p) *children;
+struct varobj_dynamic
+{
+  struct varobj base;
 
   /* Whether the children of this varobj were requested.  This field is
      used to decide if dynamic varobj should recompute their children.
@@ -165,35 +128,6 @@ struct varobj
      can avoid that.  */
   int children_requested;
 
-  /* Description of the root variable.  Points to root variable for
-     children.  */
-  struct varobj_root *root;
-
-  /* The format of the output for this object.  */
-  enum varobj_display_formats format;
-
-  /* Was this variable updated via a varobj_set_value operation.  */
-  int updated;
-
-  /* Last print value.  */
-  char *print_value;
-
-  /* Is this variable frozen.  Frozen variables are never implicitly
-     updated by -var-update * 
-     or -var-update <direct-or-indirect-parent>.  */
-  int frozen;
-
-  /* Is the value of this variable intentionally not fetched?  It is
-     not fetched if either the variable is frozen, or any parents is
-     frozen.  */
-  int not_fetched;
-
-  /* Sub-range of children which the MI consumer has requested.  If
-     FROM < 0 or TO < 0, means that all children have been
-     requested.  */
-  int from;
-  int to;
-
   /* The pretty-printer constructor.  If NULL, then the default
      pretty-printer will be looked up.  If None, then no
      pretty-printer will be installed.  */
@@ -899,14 +833,15 @@ varobj_get_display_hint (struct varobj *var)
 
 #if HAVE_PYTHON
   struct cleanup *back_to;
+  PyObject *pretty_printer = ((struct varobj_dynamic *) var)->pretty_printer;
 
   if (!gdb_python_initialized)
     return NULL;
 
   back_to = varobj_ensure_python_env (var);
 
-  if (var->pretty_printer)
-    result = gdbpy_get_display_hint (var->pretty_printer);
+  if (pretty_printer != NULL)
+    result = gdbpy_get_display_hint (pretty_printer);
 
   do_cleanups (back_to);
 #endif
@@ -922,7 +857,7 @@ varobj_has_more (struct varobj *var, int to)
   if (VEC_length (varobj_p, var->children) > to)
     return 1;
   return ((to == -1 || VEC_length (varobj_p, var->children) == to)
-	  && var->saved_item != NULL);
+	  && ((struct varobj_dynamic *) var)->saved_item != NULL);
 }
 
 /* If the variable object is bound to a specific thread, that
@@ -1029,7 +964,7 @@ install_dynamic_child (struct varobj *var,
 }
 
 static int
-dynamic_varobj_has_child_method (struct varobj *var)
+dynamic_varobj_has_child_method (struct varobj_dynamic *var)
 {
   struct cleanup *back_to;
   PyObject *printer = var->pretty_printer;
@@ -1038,7 +973,7 @@ dynamic_varobj_has_child_method (struct varobj *var)
   if (!gdb_python_initialized)
     return 0;
 
-  back_to = varobj_ensure_python_env (var);
+  back_to = varobj_ensure_python_env ((struct varobj *) var);
   result = PyObject_HasAttr (printer, gdbpy_children_cst);
   do_cleanups (back_to);
   return result;
@@ -1047,7 +982,7 @@ dynamic_varobj_has_child_method (struct varobj *var)
 #endif
 
 static int
-update_dynamic_varobj_children (struct varobj *var,
+update_dynamic_varobj_children (struct varobj_dynamic *var,
 				VEC (varobj_p) **changed,
 				VEC (varobj_p) **type_changed,
 				VEC (varobj_p) **new,
@@ -1066,7 +1001,7 @@ update_dynamic_varobj_children (struct varobj *var,
   if (!gdb_python_initialized)
     return 0;
 
-  back_to = varobj_ensure_python_env (var);
+  back_to = varobj_ensure_python_env ((struct varobj *) var);
 
   *cchanged = 0;
   if (!PyObject_HasAttr (printer, gdbpy_children_cst))
@@ -1102,7 +1037,7 @@ update_dynamic_varobj_children (struct varobj *var,
       i = 0;
     }
   else
-    i = VEC_length (varobj_p, var->children);
+    i = VEC_length (varobj_p, var->base.children);
 
   /* We ask for one extra child, so that MI can report whether there
      are more children.  */
@@ -1184,7 +1119,8 @@ update_dynamic_varobj_children (struct varobj *var,
 	  v = convert_value_from_python (py_v);
 	  if (v == NULL)
 	    gdbpy_print_stack ();
-	  install_dynamic_child (var, can_mention ? changed : NULL,
+	  install_dynamic_child ((struct varobj *) var,
+				 can_mention ? changed : NULL,
 				 can_mention ? type_changed : NULL,
 				 can_mention ? new : NULL,
 				 can_mention ? unchanged : NULL,
@@ -1205,22 +1141,22 @@ update_dynamic_varobj_children (struct varobj *var,
 	break;
     }
 
-  if (i < VEC_length (varobj_p, var->children))
+  if (i < VEC_length (varobj_p, var->base.children))
     {
       int j;
 
       *cchanged = 1;
-      for (j = i; j < VEC_length (varobj_p, var->children); ++j)
-	varobj_delete (VEC_index (varobj_p, var->children, j), NULL, 0);
-      VEC_truncate (varobj_p, var->children, i);
+      for (j = i; j < VEC_length (varobj_p, var->base.children); ++j)
+	varobj_delete (VEC_index (varobj_p, var->base.children, j), NULL, 0);
+      VEC_truncate (varobj_p, var->base.children, i);
     }
 
   /* If there are fewer children than requested, note that the list of
      children changed.  */
-  if (to >= 0 && VEC_length (varobj_p, var->children) < to)
+  if (to >= 0 && VEC_length (varobj_p, var->base.children) < to)
     *cchanged = 1;
 
-  var->num_children = VEC_length (varobj_p, var->children);
+  var->base.num_children = VEC_length (varobj_p, var->base.children);
  
   do_cleanups (back_to);
 
@@ -1235,14 +1171,16 @@ varobj_get_num_children (struct varobj *var)
 {
   if (var->num_children == -1)
     {
-      if (var->pretty_printer)
+      struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
+
+      if (var_dyn->pretty_printer)
 	{
 	  int dummy;
 
 	  /* If we have a dynamic varobj, don't report -1 children.
 	     So, try to fetch some children first.  */
-	  update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL, &dummy,
-					  0, 0, 0);
+	  update_dynamic_varobj_children (var_dyn, NULL, NULL, NULL,
+					  NULL, &dummy, 0, 0, 0);
 	}
       else
 	var->num_children = number_of_children (var);
@@ -1259,15 +1197,16 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 {
   char *name;
   int i, children_changed;
+  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
 
-  var->children_requested = 1;
+  var_dyn->children_requested = 1;
 
-  if (var->pretty_printer)
+  if (var_dyn->pretty_printer)
     {
       /* This, in theory, can result in the number of children changing without
 	 frontend noticing.  But well, calling -var-list-children on the same
 	 varobj twice is not something a sane frontend would do.  */
-      update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL,
+      update_dynamic_varobj_children (var_dyn, NULL, NULL, NULL, NULL,
 				      &children_changed, 0, 0, *to);
       restrict_range (var->children, from, to);
       return var->children;
@@ -1413,7 +1352,7 @@ varobj_get_attributes (struct varobj *var)
 int
 varobj_pretty_printed_p (struct varobj *var)
 {
-  return var->pretty_printer != NULL;
+  return ((struct varobj_dynamic *) var)->pretty_printer != NULL;
 }
 
 char *
@@ -1504,7 +1443,7 @@ varobj_set_value (struct varobj *var, char *expression)
    in a varobj.  */
 
 static void
-install_visualizer (struct varobj *var, PyObject *constructor,
+install_visualizer (struct varobj_dynamic *var, PyObject *constructor,
 		    PyObject *visualizer)
 {
   Py_XDECREF (var->constructor);
@@ -1520,19 +1459,19 @@ install_visualizer (struct varobj *var, PyObject *constructor,
 /* Install the default visualizer for VAR.  */
 
 static void
-install_default_visualizer (struct varobj *var)
+install_default_visualizer (struct varobj_dynamic *var)
 {
   /* Do not install a visualizer on a CPLUS_FAKE_CHILD.  */
-  if (CPLUS_FAKE_CHILD (var))
+  if (CPLUS_FAKE_CHILD (&var->base))
     return;
 
   if (pretty_printing)
     {
       PyObject *pretty_printer = NULL;
 
-      if (var->value)
+      if (var->base.value != NULL)
 	{
-	  pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
+	  pretty_printer = gdbpy_get_varobj_pretty_printer (var->base.value);
 	  if (! pretty_printer)
 	    {
 	      gdbpy_print_stack ();
@@ -1554,12 +1493,12 @@ install_default_visualizer (struct varobj *var)
    make a new object.  */
 
 static void
-construct_visualizer (struct varobj *var, PyObject *constructor)
+construct_visualizer (struct varobj_dynamic *var, PyObject *constructor)
 {
   PyObject *pretty_printer;
 
   /* Do not install a visualizer on a CPLUS_FAKE_CHILD.  */
-  if (CPLUS_FAKE_CHILD (var))
+  if (CPLUS_FAKE_CHILD (&var->base))
     return;
 
   Py_INCREF (constructor);
@@ -1567,7 +1506,8 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
     pretty_printer = NULL;
   else
     {
-      pretty_printer = instantiate_pretty_printer (constructor, var->value);
+      pretty_printer = instantiate_pretty_printer (constructor,
+						   var->base.value);
       if (! pretty_printer)
 	{
 	  gdbpy_print_stack ();
@@ -1592,7 +1532,7 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
    a visualizer for VAR, if appropriate.  */
 
 static void
-install_new_value_visualizer (struct varobj *var)
+install_new_value_visualizer (struct varobj_dynamic *var)
 {
 #if HAVE_PYTHON
   /* If the constructor is None, then we want the raw value.  If VAR
@@ -1600,13 +1540,13 @@ install_new_value_visualizer (struct varobj *var)
   if (!gdb_python_initialized)
     return;
 
-  if (var->constructor != Py_None && var->value)
+  if (var->constructor != Py_None && var->base.value)
     {
       struct cleanup *cleanup;
 
-      cleanup = varobj_ensure_python_env (var);
+      cleanup = varobj_ensure_python_env ((struct varobj *) var);
 
-      if (!var->constructor)
+      if (var->constructor == NULL)
 	install_default_visualizer (var);
       else
 	construct_visualizer (var, var->constructor);
@@ -1676,6 +1616,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   int changed = 0;
   int intentionally_not_fetched = 0;
   char *print_value = NULL;
+  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
 
   /* We need to know the varobj's type to decide if the value should
      be fetched or not.  C++ fake children (public/protected/private)
@@ -1686,7 +1627,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   /* If the type has custom visualizer, we consider it to be always
      changeable.  FIXME: need to make sure this behaviour will not
      mess up read-sensitive values.  */
-  if (var->pretty_printer)
+  if (var_dyn->pretty_printer != NULL)
     changeable = 1;
 
   need_to_fetch = changeable;
@@ -1757,7 +1698,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      values.  Don't get string rendering if the value is
      lazy -- if it is, the code above has decided that the value
      should not be fetched.  */
-  if (value && !value_lazy (value) && !var->pretty_printer)
+  if (value && !value_lazy (value) && var_dyn->pretty_printer == NULL)
     print_value = value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
@@ -1774,7 +1715,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
 	{
 	  changed = 1;
 	}
-      else if (! var->pretty_printer)
+      else if (var_dyn->pretty_printer == NULL)
 	{
 	  /* Try to compare the values.  That requires that both
 	     values are non-lazy.  */
@@ -1825,11 +1766,11 @@ install_new_value (struct varobj *var, struct value *value, int initial)
     var->not_fetched = 0;
   var->updated = 0;
 
-  install_new_value_visualizer (var);
+  install_new_value_visualizer (var_dyn);
 
   /* If we installed a pretty-printer, re-compare the printed version
      to see if the variable changed.  */
-  if (var->pretty_printer)
+  if (var_dyn->pretty_printer != NULL)
     {
       xfree (print_value);
       print_value = value_get_print_value (var->value, var->format, var);
@@ -1894,7 +1835,7 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
       error (_("Could not evaluate visualizer expression: %s"), visualizer);
     }
 
-  construct_visualizer (var, constructor);
+  construct_visualizer ((struct varobj_dynamic *) var, constructor);
   Py_XDECREF (constructor);
 
   /* If there are any children now, wipe them.  */
@@ -2019,6 +1960,7 @@ varobj_update (struct varobj **varp, int explicit)
     {
       varobj_update_result r = *(VEC_last (varobj_update_result, stack));
       struct varobj *v = r.varobj;
+      struct varobj_dynamic *v_dyn = (struct varobj_dynamic *) v;
 
       VEC_pop (varobj_update_result, stack);
 
@@ -2058,7 +2000,7 @@ varobj_update (struct varobj **varp, int explicit)
       /* We probably should not get children of a varobj that has a
 	 pretty-printer, but for which -var-list-children was never
 	 invoked.  */
-      if (v->pretty_printer)
+      if (v_dyn->pretty_printer != NULL)
 	{
 	  VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
 	  VEC (varobj_p) *new = 0;
@@ -2067,7 +2009,7 @@ varobj_update (struct varobj **varp, int explicit)
 	  if (v->frozen)
 	    continue;
 
-	  if (!v->children_requested)
+	  if (!v_dyn->children_requested)
 	    {
 	      int dummy;
 
@@ -2079,8 +2021,8 @@ varobj_update (struct varobj **varp, int explicit)
 		 it.  */
 	      if (!varobj_has_more (v, 0))
 		{
-		  update_dynamic_varobj_children (v, NULL, NULL, NULL, NULL,
-						  &dummy, 0, 0, 0);
+		  update_dynamic_varobj_children (v_dyn, NULL, NULL, NULL,
+						  NULL, &dummy, 0, 0, 0);
 		  if (varobj_has_more (v, 0))
 		    r.changed = 1;
 		}
@@ -2093,9 +2035,10 @@ varobj_update (struct varobj **varp, int explicit)
 
 	  /* If update_dynamic_varobj_children returns 0, then we have
 	     a non-conforming pretty-printer, so we skip it.  */
-	  if (update_dynamic_varobj_children (v, &changed, &type_changed, &new,
-					      &unchanged, &children_changed, 1,
-					      v->from, v->to))
+	  if (update_dynamic_varobj_children (v_dyn, &changed, &type_changed,
+					      &new, &unchanged,
+					      &children_changed, 1, v->from,
+					      v->to))
 	    {
 	      if (children_changed || new)
 		{
@@ -2441,33 +2384,33 @@ create_child_with_value (struct varobj *parent, int index, const char *name,
 static struct varobj *
 new_variable (void)
 {
-  struct varobj *var;
-
-  var = (struct varobj *) xmalloc (sizeof (struct varobj));
-  var->name = NULL;
-  var->path_expr = NULL;
-  var->obj_name = NULL;
-  var->index = -1;
-  var->type = NULL;
-  var->value = NULL;
-  var->num_children = -1;
-  var->parent = NULL;
-  var->children = NULL;
-  var->format = 0;
-  var->root = NULL;
-  var->updated = 0;
-  var->print_value = NULL;
-  var->frozen = 0;
-  var->not_fetched = 0;
+  struct varobj_dynamic *var;
+
+  var = (struct varobj_dynamic *) xmalloc (sizeof (struct varobj_dynamic));
+  var->base.name = NULL;
+  var->base.path_expr = NULL;
+  var->base.obj_name = NULL;
+  var->base.index = -1;
+  var->base.type = NULL;
+  var->base.value = NULL;
+  var->base.num_children = -1;
+  var->base.parent = NULL;
+  var->base.children = NULL;
+  var->base.format = 0;
+  var->base.root = NULL;
+  var->base.updated = 0;
+  var->base.print_value = NULL;
+  var->base.frozen = 0;
+  var->base.not_fetched = 0;
   var->children_requested = 0;
-  var->from = -1;
-  var->to = -1;
+  var->base.from = -1;
+  var->base.to = -1;
   var->constructor = 0;
   var->pretty_printer = 0;
   var->child_iter = 0;
   var->saved_item = 0;
 
-  return var;
+  return (struct varobj *) var;
 }
 
 /* Allocate memory and initialize a new root variable.  */
@@ -2493,13 +2436,16 @@ static void
 free_variable (struct varobj *var)
 {
 #if HAVE_PYTHON
-  if (var->pretty_printer)
+  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
+
+  if (var_dyn->pretty_printer)
     {
       struct cleanup *cleanup = varobj_ensure_python_env (var);
-      Py_XDECREF (var->constructor);
-      Py_XDECREF (var->pretty_printer);
-      Py_XDECREF (var->child_iter);
-      Py_XDECREF (var->saved_item);
+
+      Py_XDECREF (var_dyn->constructor);
+      Py_XDECREF (var_dyn->pretty_printer);
+      Py_XDECREF (var_dyn->child_iter);
+      Py_XDECREF (var_dyn->saved_item);
       do_cleanups (cleanup);
     }
 #endif
@@ -2889,7 +2835,7 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
 {
   if (var->root->is_valid)
     {
-      if (var->pretty_printer)
+      if (((struct varobj_dynamic *) var)->pretty_printer)
 	return value_get_print_value (var->value, var->format, var);
       return (*var->root->lang->value_of_variable) (var, format);
     }
@@ -2923,7 +2869,8 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
 #if HAVE_PYTHON
   if (gdb_python_initialized)
     {
-      PyObject *value_formatter = var->pretty_printer;
+      PyObject *value_formatter
+	= ((struct varobj_dynamic *) var)->pretty_printer;
 
       varobj_ensure_python_env (var);
 
@@ -2931,7 +2878,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
 	{
 	  /* First check to see if we have any children at all.  If so,
 	     we simply return {...}.  */
-	  if (dynamic_varobj_has_child_method (var))
+	  if (dynamic_varobj_has_child_method ((struct varobj_dynamic *) var))
 	    {
 	      do_cleanups (old_chain);
 	      return xstrdup ("{...}");
diff --git a/gdb/varobj.h b/gdb/varobj.h
index d4abb99..894ba03 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -88,6 +88,80 @@ typedef struct varobj_update_result_t
 
 DEF_VEC_O (varobj_update_result);
 
+struct varobj_root;
+
+/* Every variable in the system has a structure of this type defined
+   for it.  This structure holds all information necessary to manipulate
+   a particular object variable.  Members which must be freed are noted.  */
+struct varobj
+{
+  /* Alloc'd name of the variable for this object.  If this variable is a
+     child, then this name will be the child's source name.
+     (bar, not foo.bar).  */
+  /* NOTE: This is the "expression".  */
+  char *name;
+
+  /* Alloc'd expression for this child.  Can be used to create a
+     root variable corresponding to this child.  */
+  char *path_expr;
+
+  /* The alloc'd name for this variable's object.  This is here for
+     convenience when constructing this object's children.  */
+  char *obj_name;
+
+  /* Index of this variable in its parent or -1.  */
+  int index;
+
+  /* The type of this variable.  This can be NULL
+     for artifial variable objects -- currently, the "accessibility" 
+     variable objects in C++.  */
+  struct type *type;
+
+  /* The value of this expression or subexpression.  A NULL value
+     indicates there was an error getting this value.
+     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
+     the value is either NULL, or not lazy.  */
+  struct value *value;
+
+  /* The number of (immediate) children this variable has.  */
+  int num_children;
+
+  /* If this object is a child, this points to its immediate parent.  */
+  struct varobj *parent;
+
+  /* Children of this object.  */
+  VEC (varobj_p) *children;
+
+  /* Description of the root variable.  Points to root variable for
+     children.  */
+  struct varobj_root *root;
+
+  /* The format of the output for this object.  */
+  enum varobj_display_formats format;
+
+  /* Was this variable updated via a varobj_set_value operation.  */
+  int updated;
+
+  /* Last print value.  */
+  char *print_value;
+
+  /* Is this variable frozen.  Frozen variables are never implicitly
+     updated by -var-update * 
+     or -var-update <direct-or-indirect-parent>.  */
+  int frozen;
+
+  /* Is the value of this variable intentionally not fetched?  It is
+     not fetched if either the variable is frozen, or any parents is
+     frozen.  */
+  int not_fetched;
+
+  /* Sub-range of children which the MI consumer has requested.  If
+     FROM < 0 or TO < 0, means that all children have been
+     requested.  */
+  int from;
+  int to;
+};
+
 /* API functions */
 
 extern struct varobj *varobj_create (char *objname,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 3/7] Remove field value_of_root
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
                   ` (4 preceding siblings ...)
  2013-09-18 13:55 ` [PATCH 4/7] Move struct varobj to varobj.h Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-01 10:16   ` Joel Brobecker
  2013-09-18 13:55 ` [PATCH 2/7] Remove vlang_unknown Yao Qi
  2013-09-28  0:56 ` [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

c_value_of_root is used for all languages, so it is unnecessary to
have a field 'value_of_root' any more in 'struct language_specific'.
This patch removes the field 'value_of_root' and use c_value_of_root.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* varobj.c (c_value_of_root): Remove declaration.
	(cplus_value_of_root, java_value_of_root): Likewise.
	(ada_value_of_root): Likewise.
	(struct language_specific) <value_of_root>: Remove.
	(languages): Update initialization.
	(check_scope): Moved earlier.
	(c_value_of_root): Renamed to ...
	(value_of_root_1): ... this.
	(value_of_root): Caller update.
	(cplus_value_of_root, java_value_of_root): Remove.
	(ada_value_of_root): Remove.
---
 gdb/varobj.c |  191 ++++++++++++++++++++++++----------------------------------
 1 files changed, 80 insertions(+), 111 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index bcf62dc..3ecf702 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -321,8 +321,6 @@ static char *c_name_of_child (struct varobj *parent, int index);
 
 static char *c_path_expr_of_child (struct varobj *child);
 
-static struct value *c_value_of_root (struct varobj **var_handle);
-
 static struct value *c_value_of_child (struct varobj *parent, int index);
 
 static struct type *c_type_of_child (struct varobj *parent, int index);
@@ -342,8 +340,6 @@ static char *cplus_name_of_child (struct varobj *parent, int index);
 
 static char *cplus_path_expr_of_child (struct varobj *child);
 
-static struct value *cplus_value_of_root (struct varobj **var_handle);
-
 static struct value *cplus_value_of_child (struct varobj *parent, int index);
 
 static struct type *cplus_type_of_child (struct varobj *parent, int index);
@@ -361,8 +357,6 @@ static char *java_name_of_child (struct varobj *parent, int index);
 
 static char *java_path_expr_of_child (struct varobj *child);
 
-static struct value *java_value_of_root (struct varobj **var_handle);
-
 static struct value *java_value_of_child (struct varobj *parent, int index);
 
 static struct type *java_type_of_child (struct varobj *parent, int index);
@@ -380,8 +374,6 @@ static char *ada_name_of_child (struct varobj *parent, int index);
 
 static char *ada_path_expr_of_child (struct varobj *child);
 
-static struct value *ada_value_of_root (struct varobj **var_handle);
-
 static struct value *ada_value_of_child (struct varobj *parent, int index);
 
 static struct type *ada_type_of_child (struct varobj *parent, int index);
@@ -411,9 +403,6 @@ struct language_specific
      obtain that has some parent.  */
   char *(*path_expr_of_child) (struct varobj * child);
 
-  /* The ``struct value *'' of the root variable ROOT.  */
-  struct value *(*value_of_root) (struct varobj ** root_handle);
-
   /* The ``struct value *'' of the INDEX'th child of PARENT.  */
   struct value *(*value_of_child) (struct varobj * parent, int index);
 
@@ -458,7 +447,6 @@ static struct language_specific languages[vlang_end] = {
    c_name_of_variable,
    c_name_of_child,
    c_path_expr_of_child,
-   c_value_of_root,
    c_value_of_child,
    c_type_of_child,
    c_value_of_variable,
@@ -471,7 +459,6 @@ static struct language_specific languages[vlang_end] = {
    cplus_name_of_variable,
    cplus_name_of_child,
    cplus_path_expr_of_child,
-   cplus_value_of_root,
    cplus_value_of_child,
    cplus_type_of_child,
    cplus_value_of_variable,
@@ -484,7 +471,6 @@ static struct language_specific languages[vlang_end] = {
    java_name_of_variable,
    java_name_of_child,
    java_path_expr_of_child,
-   java_value_of_root,
    java_value_of_child,
    java_type_of_child,
    java_value_of_variable,
@@ -496,7 +482,6 @@ static struct language_specific languages[vlang_end] = {
    ada_name_of_variable,
    ada_name_of_child,
    ada_path_expr_of_child,
-   ada_value_of_root,
    ada_value_of_child,
    ada_type_of_child,
    ada_value_of_variable,
@@ -2710,6 +2695,85 @@ name_of_child (struct varobj *var, int index)
   return (*var->root->lang->name_of_child) (var, index);
 }
 
+/* If frame associated with VAR can be found, switch
+   to it and return 1.  Otherwise, return 0.  */
+static int
+check_scope (struct varobj *var)
+{
+  struct frame_info *fi;
+  int scope;
+
+  fi = frame_find_by_id (var->root->frame);
+  scope = fi != NULL;
+
+  if (fi)
+    {
+      CORE_ADDR pc = get_frame_pc (fi);
+
+      if (pc <  BLOCK_START (var->root->valid_block) ||
+	  pc >= BLOCK_END (var->root->valid_block))
+	scope = 0;
+      else
+	select_frame (fi);
+    }
+  return scope;
+}
+
+/* Helper function to value_of_root.  */
+
+static struct value *
+value_of_root_1 (struct varobj **var_handle)
+{
+  struct value *new_val = NULL;
+  struct varobj *var = *var_handle;
+  int within_scope = 0;
+  struct cleanup *back_to;
+								 
+  /*  Only root variables can be updated...  */
+  if (!is_root_p (var))
+    /* Not a root var.  */
+    return NULL;
+
+  back_to = make_cleanup_restore_current_thread ();
+
+  /* Determine whether the variable is still around.  */
+  if (var->root->valid_block == NULL || var->root->floating)
+    within_scope = 1;
+  else if (var->root->thread_id == 0)
+    {
+      /* The program was single-threaded when the variable object was
+	 created.  Technically, it's possible that the program became
+	 multi-threaded since then, but we don't support such
+	 scenario yet.  */
+      within_scope = check_scope (var);	  
+    }
+  else
+    {
+      ptid_t ptid = thread_id_to_pid (var->root->thread_id);
+      if (in_thread_list (ptid))
+	{
+	  switch_to_thread (ptid);
+	  within_scope = check_scope (var);
+	}
+    }
+
+  if (within_scope)
+    {
+      volatile struct gdb_exception except;
+
+      /* We need to catch errors here, because if evaluate
+         expression fails we want to just return NULL.  */
+      TRY_CATCH (except, RETURN_MASK_ERROR)
+	{
+	  new_val = evaluate_expression (var->root->exp);
+	}
+    }
+
+  do_cleanups (back_to);
+
+  return new_val;
+}
+
 /* What is the ``struct value *'' of the root variable VAR?
    For floating variable object, evaluation can get us a value
    of different type from what is stored in varobj already.  In
@@ -2787,7 +2851,7 @@ value_of_root (struct varobj **var_handle, int *type_changed)
   {
     struct value *value;
 
-    value = (*var->root->lang->value_of_root) (var_handle);
+    value = value_of_root_1 (var_handle);
     if (var->value == NULL || value == NULL)
       {
 	/* For root varobj-s, a NULL value indicates a scoping issue.
@@ -3382,83 +3446,6 @@ c_path_expr_of_child (struct varobj *child)
   return child->path_expr;
 }
 
-/* If frame associated with VAR can be found, switch
-   to it and return 1.  Otherwise, return 0.  */
-static int
-check_scope (struct varobj *var)
-{
-  struct frame_info *fi;
-  int scope;
-
-  fi = frame_find_by_id (var->root->frame);
-  scope = fi != NULL;
-
-  if (fi)
-    {
-      CORE_ADDR pc = get_frame_pc (fi);
-
-      if (pc <  BLOCK_START (var->root->valid_block) ||
-	  pc >= BLOCK_END (var->root->valid_block))
-	scope = 0;
-      else
-	select_frame (fi);
-    }
-  return scope;
-}
-
-static struct value *
-c_value_of_root (struct varobj **var_handle)
-{
-  struct value *new_val = NULL;
-  struct varobj *var = *var_handle;
-  int within_scope = 0;
-  struct cleanup *back_to;
-								 
-  /*  Only root variables can be updated...  */
-  if (!is_root_p (var))
-    /* Not a root var.  */
-    return NULL;
-
-  back_to = make_cleanup_restore_current_thread ();
-
-  /* Determine whether the variable is still around.  */
-  if (var->root->valid_block == NULL || var->root->floating)
-    within_scope = 1;
-  else if (var->root->thread_id == 0)
-    {
-      /* The program was single-threaded when the variable object was
-	 created.  Technically, it's possible that the program became
-	 multi-threaded since then, but we don't support such
-	 scenario yet.  */
-      within_scope = check_scope (var);	  
-    }
-  else
-    {
-      ptid_t ptid = thread_id_to_pid (var->root->thread_id);
-      if (in_thread_list (ptid))
-	{
-	  switch_to_thread (ptid);
-	  within_scope = check_scope (var);
-	}
-    }
-
-  if (within_scope)
-    {
-      volatile struct gdb_exception except;
-
-      /* We need to catch errors here, because if evaluate
-         expression fails we want to just return NULL.  */
-      TRY_CATCH (except, RETURN_MASK_ERROR)
-	{
-	  new_val = evaluate_expression (var->root->exp);
-	}
-    }
-
-  do_cleanups (back_to);
-
-  return new_val;
-}
-
 static struct value *
 c_value_of_child (struct varobj *parent, int index)
 {
@@ -3893,12 +3880,6 @@ cplus_path_expr_of_child (struct varobj *child)
 }
 
 static struct value *
-cplus_value_of_root (struct varobj **var_handle)
-{
-  return c_value_of_root (var_handle);
-}
-
-static struct value *
 cplus_value_of_child (struct varobj *parent, int index)
 {
   struct value *value = NULL;
@@ -3983,12 +3964,6 @@ java_path_expr_of_child (struct varobj *child)
 }
 
 static struct value *
-java_value_of_root (struct varobj **var_handle)
-{
-  return cplus_value_of_root (var_handle);
-}
-
-static struct value *
 java_value_of_child (struct varobj *parent, int index)
 {
   return cplus_value_of_child (parent, index);
@@ -4041,12 +4016,6 @@ ada_path_expr_of_child (struct varobj *child)
 }
 
 static struct value *
-ada_value_of_root (struct varobj **var_handle)
-{
-  return c_value_of_root (var_handle);
-}
-
-static struct value *
 ada_value_of_child (struct varobj *parent, int index)
 {
   return ada_varobj_get_value_of_child (parent->value, parent->type,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [RFC 0/7] Move language-related stuff out of varobj.c
@ 2013-09-18 13:55 Yao Qi
  2013-09-18 13:55 ` [PATCH 1/7] Remove field language in struct language_specific Yao Qi
                   ` (7 more replies)
  0 siblings, 8 replies; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

This patch series is to move language-related stuff out of varobj.c
to ada-varobj.c, c-varobj.c and jv-varobj.c.  This will shorten
varobj.c, and make it easier for varobj support for new languages.

Nowadays, we have 'struct language_specific' which is about language
operations in varobj.  This can be moved out of varobj.c and shared
for different languages.  This is what patch 5/7 does.  Operations
of each language need to know 'struct varobj', so 'struct varobj'
should be moved to varobj.h.  This is what patch 4/7 does.  Note
that we don't move all 'struct varobj' to varobj.h because some fields
are related to dynamic varobj, and make no sense to expose them.
I move basic part of 'struct varobj' to varobj.h, and define a new
struct varobj_dynamic to extend 'struct varobj'.

Then, we can move language related operations out of varobj.c to
c-varobj.c, ada-varobj.c and jv-varobj.c respectively.  This is
done by patch 6/7.

Patch 1/7 - 3/7 are cleanups, to remove unused bits in varobj.c.
Patch 7/7 is a cleanup too.

Note that static array 'languages' is still used in varobj.c, which
is not really necessary.  We can remove it and move each
'struct lang_varobj_ops *' to be a field of 'struct language_defn'.
I don't include this change in this series because I'd like to post
patches for review before I go too far away.

The whole series is tested on x86_64-linux.  Comments?

*** BLURB HERE ***

Yao Qi (7):
  Remove field language in struct language_specific
  Remove vlang_unknown
  Remove field value_of_root
  Move struct varobj to varobj.h.
  New lang-varobj.h
  Move language stuff out of varobj.c
  Remove ada-varobj.h.

 gdb/Makefile.in   |   12 +-
 gdb/ada-varobj.c  |  151 +++++-
 gdb/ada-varobj.h  |   55 --
 gdb/c-varobj.c    |  902 +++++++++++++++++++++++++++
 gdb/gdbtypes.c    |   16 +
 gdb/gdbtypes.h    |    4 +
 gdb/jv-varobj.c   |  104 ++++
 gdb/lang-varobj.h |   79 +++
 gdb/varobj.c      | 1783 +++++++----------------------------------------------
 gdb/varobj.h      |   98 +++-
 10 files changed, 1571 insertions(+), 1633 deletions(-)
 delete mode 100644 gdb/ada-varobj.h
 create mode 100644 gdb/c-varobj.c
 create mode 100644 gdb/jv-varobj.c
 create mode 100644 gdb/lang-varobj.h

-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 7/7] Remove ada-varobj.h.
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
                   ` (2 preceding siblings ...)
  2013-09-18 13:55 ` [PATCH 6/7] Move language stuff out of varobj.c Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-17  5:46   ` Joel Brobecker
  2013-09-18 13:55 ` [PATCH 4/7] Move struct varobj to varobj.h Yao Qi
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

As a result of previous patch, extern functions in ada-varobj.c can be
made static, and ada-varobj.h can be removed too.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
	* ada-varobj.c: Remove the include of ada-varobj.h.
	(ada_varobj_get_number_of_children): Declare.
	(ada_varobj_get_name_of_child): Make it static.
	(ada_varobj_get_path_expr_of_child): Likewise.
	(ada_varobj_get_value_of_child): Likewise.
	(ada_varobj_get_type_of_child): Likewise.
	(ada_varobj_get_value_of_array_variable): Likewise.
	* ada-varobj.h: Remove.
---
 gdb/Makefile.in  |    2 +-
 gdb/ada-varobj.c |   16 ++++++++------
 gdb/ada-varobj.h |   55 ------------------------------------------------------
 3 files changed, 10 insertions(+), 63 deletions(-)
 delete mode 100644 gdb/ada-varobj.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 73715b5..5c2874c 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -792,7 +792,7 @@ proc-utils.h aarch64-tdep.h arm-tdep.h ax-gdb.h ppcfbsd-tdep.h \
 ppcnbsd-tdep.h cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
 exec.h m32r-tdep.h osabi.h gdbcore.h solib-som.h amd64bsd-nat.h \
 i386bsd-nat.h xml-support.h xml-tdesc.h alphabsd-tdep.h gdb_obstack.h \
-ia64-tdep.h ada-lang.h ada-varobj.h varobj.h frv-tdep.h nto-tdep.h serial.h \
+ia64-tdep.h ada-lang.h varobj.h frv-tdep.h nto-tdep.h serial.h \
 c-lang.h d-lang.h go-lang.h frame.h event-loop.h block.h cli/cli-setshow.h \
 cli/cli-decode.h cli/cli-cmds.h cli/cli-utils.h \
 cli/cli-script.h macrotab.h symtab.h common/version.h \
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 3b01209..f921c67 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -18,7 +18,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "ada-varobj.h"
 #include "ada-lang.h"
 #include "lang-varobj.h"
 #include "language.h"
@@ -57,6 +56,9 @@
 
    The results are written in place.  */
 
+static int ada_varobj_get_number_of_children (struct value *parent_value,
+					      struct type *parent_type);
+
 static void
 ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
 {
@@ -324,7 +326,7 @@ ada_varobj_get_ptr_number_of_children (struct value *parent_value,
 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE)
    pair.  */
 
-int
+static int
 ada_varobj_get_number_of_children (struct value *parent_value,
 				   struct type *parent_type)
 {
@@ -722,7 +724,7 @@ ada_varobj_describe_child (struct value *parent_value,
 
    The result should be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_name_of_child (struct value *parent_value,
 			      struct type *parent_type,
 			      const char *parent_name, int child_index)
@@ -742,7 +744,7 @@ ada_varobj_get_name_of_child (struct value *parent_value,
 
    The result must be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_path_expr_of_child (struct value *parent_value,
 				   struct type *parent_type,
 				   const char *parent_name,
@@ -761,7 +763,7 @@ ada_varobj_get_path_expr_of_child (struct value *parent_value,
 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  PARENT_NAME is the name of the parent.  */
 
-struct value *
+static struct value *
 ada_varobj_get_value_of_child (struct value *parent_value,
 			       struct type *parent_type,
 			       const char *parent_name, int child_index)
@@ -778,7 +780,7 @@ ada_varobj_get_value_of_child (struct value *parent_value,
 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  */
 
-struct type *
+static struct type *
 ada_varobj_get_type_of_child (struct value *parent_value,
 			      struct type *parent_type,
 			      int child_index)
@@ -857,7 +859,7 @@ ada_varobj_get_value_of_array_variable (struct value *value,
 /* Return a string representation of the (VALUE, TYPE) pair, using
    the given print options OPTS as our formatting options.  */
 
-char *
+static char *
 ada_varobj_get_value_of_variable (struct value *value,
 				  struct type *type,
 				  struct value_print_options *opts)
diff --git a/gdb/ada-varobj.h b/gdb/ada-varobj.h
deleted file mode 100644
index 924997d..0000000
--- a/gdb/ada-varobj.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* varobj support for Ada.
-
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef ADA_VAROBJ_H
-#define ADA_VAROBJ_H
-
-#include "varobj.h"
-
-struct value;
-struct value_print_options;
-
-extern int ada_varobj_get_number_of_children (struct value *parent_value,
-					      struct type *parent_type);
-
-extern char *ada_varobj_get_name_of_child (struct value *parent_value,
-					   struct type *parent_type,
-					   const char *parent_name,
-					   int child_index);
-
-extern char *ada_varobj_get_path_expr_of_child (struct value *parent_value,
-						struct type *parent_type,
-						const char *parent_name,
-						const char *parent_path_expr,
-						int child_index);
-
-extern struct value *ada_varobj_get_value_of_child (struct value *parent_value,
-						    struct type *parent_type,
-						    const char *parent_name,
-						    int child_index);
-
-extern struct type *ada_varobj_get_type_of_child (struct value *parent_value,
-						  struct type *parent_type,
-						  int child_index);
-
-extern char *ada_varobj_get_value_of_variable
-  (struct value *value, struct type *type,
-   struct value_print_options *opts);
-
-#endif /* ADA_VAROBJ_H */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 1/7] Remove field language in struct language_specific
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-01 10:03   ` Joel Brobecker
  2013-09-18 13:55 ` [PATCH 5/7] New lang-varobj.h Yao Qi
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

Field 'language' in struct language_specific is not used.  This patch
is to remove it.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* varobj.c (struct language_specific) <language>: Remove.
	(languages): Update the initialization.
---
 gdb/varobj.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index ced3e2d..f613b1b 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -398,10 +398,6 @@ static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
 
 struct language_specific
 {
-
-  /* The language of this variable.  */
-  enum varobj_languages language;
-
   /* The number of children of PARENT.  */
   int (*number_of_children) (struct varobj * parent);
 
@@ -458,7 +454,6 @@ struct language_specific
 static struct language_specific languages[vlang_end] = {
   /* Unknown (try treating as C).  */
   {
-   vlang_unknown,
    c_number_of_children,
    c_name_of_variable,
    c_name_of_child,
@@ -472,7 +467,6 @@ static struct language_specific languages[vlang_end] = {
   ,
   /* C */
   {
-   vlang_c,
    c_number_of_children,
    c_name_of_variable,
    c_name_of_child,
@@ -486,7 +480,6 @@ static struct language_specific languages[vlang_end] = {
   ,
   /* C++ */
   {
-   vlang_cplus,
    cplus_number_of_children,
    cplus_name_of_variable,
    cplus_name_of_child,
@@ -500,7 +493,6 @@ static struct language_specific languages[vlang_end] = {
   ,
   /* Java */
   {
-   vlang_java,
    java_number_of_children,
    java_name_of_variable,
    java_name_of_child,
@@ -513,7 +505,6 @@ static struct language_specific languages[vlang_end] = {
    NULL /* value_has_mutated */},
   /* Ada */
   {
-   vlang_ada,
    ada_number_of_children,
    ada_name_of_variable,
    ada_name_of_child,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 2/7] Remove vlang_unknown
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
                   ` (5 preceding siblings ...)
  2013-09-18 13:55 ` [PATCH 3/7] Remove field value_of_root Yao Qi
@ 2013-09-18 13:55 ` Yao Qi
  2013-10-01 10:07   ` Joel Brobecker
  2013-09-28  0:56 ` [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
  7 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-09-18 13:55 UTC (permalink / raw)
  To: gdb-patches

'vlang_unknown' is not used at all.  This patch is to remove it.

gdb:

2013-09-18  Yao Qi  <yao@codesourcery.com>

	* varobj.c (varobj_format_string): Remove "unknown".
	(languages): Remove the first element.
	* varobj.h (enum varobj_languages): Remove vlang_c.
---
 gdb/varobj.c |   15 +--------------
 gdb/varobj.h |    2 +-
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index f613b1b..bcf62dc 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -62,7 +62,7 @@ char *varobj_format_string[] =
   { "natural", "binary", "decimal", "hexadecimal", "octal" };
 
 /* String representations of gdb's known languages.  */
-char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
+char *varobj_language_string[] = { "C", "C++", "Java" };
 
 /* True if we want to allow Python-based pretty-printing.  */
 static int pretty_printing = 0;
@@ -452,19 +452,6 @@ struct language_specific
 
 /* Array of known source language routines.  */
 static struct language_specific languages[vlang_end] = {
-  /* Unknown (try treating as C).  */
-  {
-   c_number_of_children,
-   c_name_of_variable,
-   c_name_of_child,
-   c_path_expr_of_child,
-   c_value_of_root,
-   c_value_of_child,
-   c_type_of_child,
-   c_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
   /* C */
   {
    c_number_of_children,
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 05b2c94..d4abb99 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -55,7 +55,7 @@ extern char *varobj_format_string[];
 /* Languages supported by this variable objects system.  */
 enum varobj_languages
   {
-    vlang_unknown = 0, vlang_c, vlang_cplus, vlang_java, vlang_ada, vlang_end
+    vlang_c = 0, vlang_cplus, vlang_java, vlang_ada, vlang_end
   };
 
 /* String representations of gdb's known languages (defined in varobj.c).  */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC 0/7] Move language-related stuff out of varobj.c
  2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
                   ` (6 preceding siblings ...)
  2013-09-18 13:55 ` [PATCH 2/7] Remove vlang_unknown Yao Qi
@ 2013-09-28  0:56 ` Yao Qi
  7 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-09-28  0:56 UTC (permalink / raw)
  To: gdb-patches

On 09/18/2013 09:54 PM, Yao Qi wrote:
> This patch series is to move language-related stuff out of varobj.c
> to ada-varobj.c, c-varobj.c and jv-varobj.c.  This will shorten
> varobj.c, and make it easier for varobj support for new languages.
>
> Nowadays, we have 'struct language_specific' which is about language
> operations in varobj.  This can be moved out of varobj.c and shared
> for different languages.  This is what patch 5/7 does.  Operations
> of each language need to know 'struct varobj', so 'struct varobj'
> should be moved to varobj.h.  This is what patch 4/7 does.  Note
> that we don't move all 'struct varobj' to varobj.h because some fields
> are related to dynamic varobj, and make no sense to expose them.
> I move basic part of 'struct varobj' to varobj.h, and define a new
> struct varobj_dynamic to extend 'struct varobj'.
>
> Then, we can move language related operations out of varobj.c to
> c-varobj.c, ada-varobj.c and jv-varobj.c respectively.  This is
> done by patch 6/7.
>
> Patch 1/7 - 3/7 are cleanups, to remove unused bits in varobj.c.
> Patch 7/7 is a cleanup too.
>
> Note that static array 'languages' is still used in varobj.c, which
> is not really necessary.  We can remove it and move each
> 'struct lang_varobj_ops *' to be a field of 'struct language_defn'.
> I don't include this change in this series because I'd like to post
> patches for review before I go too far away.
>
> The whole series is tested on x86_64-linux.  Comments?

Ping.  https://sourceware.org/ml/gdb-patches/2013-09/msg00591.html

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 1/7] Remove field language in struct language_specific
  2013-09-18 13:55 ` [PATCH 1/7] Remove field language in struct language_specific Yao Qi
@ 2013-10-01 10:03   ` Joel Brobecker
  2013-10-01 13:35     ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-01 10:03 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> 2013-09-18  Yao Qi  <yao@codesourcery.com>
> 
> 	* varobj.c (struct language_specific) <language>: Remove.
> 	(languages): Update the initialization.

This patch is OK.

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 2/7] Remove vlang_unknown
  2013-09-18 13:55 ` [PATCH 2/7] Remove vlang_unknown Yao Qi
@ 2013-10-01 10:07   ` Joel Brobecker
  2013-10-01 13:34     ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-01 10:07 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> 2013-09-18  Yao Qi  <yao@codesourcery.com>
> 
> 	* varobj.c (varobj_format_string): Remove "unknown".
> 	(languages): Remove the first element.
> 	* varobj.h (enum varobj_languages): Remove vlang_c.

Overall, looks good to me.

> diff --git a/gdb/varobj.h b/gdb/varobj.h
> index 05b2c94..d4abb99 100644
> --- a/gdb/varobj.h
> +++ b/gdb/varobj.h
> @@ -55,7 +55,7 @@ extern char *varobj_format_string[];
>  /* Languages supported by this variable objects system.  */
>  enum varobj_languages
>    {
> -    vlang_unknown = 0, vlang_c, vlang_cplus, vlang_java, vlang_ada, vlang_end
> +    vlang_c = 0, vlang_cplus, vlang_java, vlang_ada, vlang_end

I am not really sure why the first enum would need to be zero.
If we cannot find an answer to that question, I propose you leave
the "= 0" out of this patch.

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 3/7] Remove field value_of_root
  2013-09-18 13:55 ` [PATCH 3/7] Remove field value_of_root Yao Qi
@ 2013-10-01 10:16   ` Joel Brobecker
  2013-10-01 13:52     ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-01 10:16 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> c_value_of_root is used for all languages, so it is unnecessary to
> have a field 'value_of_root' any more in 'struct language_specific'.
> This patch removes the field 'value_of_root' and use c_value_of_root.
> 
> gdb:
> 
> 2013-09-18  Yao Qi  <yao@codesourcery.com>
> 
> 	* varobj.c (c_value_of_root): Remove declaration.
> 	(cplus_value_of_root, java_value_of_root): Likewise.
> 	(ada_value_of_root): Likewise.
> 	(struct language_specific) <value_of_root>: Remove.
> 	(languages): Update initialization.
> 	(check_scope): Moved earlier.
> 	(c_value_of_root): Renamed to ...
> 	(value_of_root_1): ... this.
> 	(value_of_root): Caller update.
> 	(cplus_value_of_root, java_value_of_root): Remove.
> 	(ada_value_of_root): Remove.

I think it's a step in the right direction, as I don't see how
we would want a language-specific value-of-root. So, LGTM, but
could you also add an empty line after the description of function
check_scope? Also, Could you mention that "c_value_of_root" was
moved earlier as well (ie: "Move earlier and renamed to...").

> +/* If frame associated with VAR can be found, switch
> +   to it and return 1.  Otherwise, return 0.  */
> +static int
> +check_scope (struct varobj *var)

Thanks,
-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 2/7] Remove vlang_unknown
  2013-10-01 10:07   ` Joel Brobecker
@ 2013-10-01 13:34     ` Yao Qi
  2013-10-02  0:19       ` Doug Evans
  0 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-10-01 13:34 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/01/2013 06:07 PM, Joel Brobecker wrote:
> I am not really sure why the first enum would need to be zero.
> If we cannot find an answer to that question, I propose you leave
> the "= 0" out of this patch.

In varobj.c:varobj_create, variable_language returns
'enum varobj_languages', and use it as an index to array
languages.

       /* Set language info */
       lang = variable_language (var);
       var->root->lang = &languages[lang];

that is the reason the first enum should be zero.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 1/7] Remove field language in struct language_specific
  2013-10-01 10:03   ` Joel Brobecker
@ 2013-10-01 13:35     ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-01 13:35 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/01/2013 06:03 PM, Joel Brobecker wrote:
>> 2013-09-18  Yao Qi  <yao@codesourcery.com>
>>
>> 	* varobj.c (struct language_specific) <language>: Remove.
>> 	(languages): Update the initialization.
>
> This patch is OK.
>

Patch is committed.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 3/7] Remove field value_of_root
  2013-10-01 10:16   ` Joel Brobecker
@ 2013-10-01 13:52     ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-01 13:52 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/01/2013 06:16 PM, Joel Brobecker wrote:
> I think it's a step in the right direction, as I don't see how
> we would want a language-specific value-of-root. So, LGTM, but
> could you also add an empty line after the description of function
> check_scope? Also, Could you mention that "c_value_of_root" was
> moved earlier as well (ie: "Move earlier and renamed to...").

Add this sentence into changelog entry.

>
>> >+/* If frame associated with VAR can be found, switch
>> >+   to it and return 1.  Otherwise, return 0.  */
>> >+static int
>> >+check_scope (struct varobj *var)

Fixed.

Patch below is committed.

-- 
Yao (齐尧)

gdb:

2013-10-01  Yao Qi  <yao@codesourcery.com>

	* varobj.c (c_value_of_root): Remove declaration.
	(cplus_value_of_root, java_value_of_root): Likewise.
	(ada_value_of_root): Likewise.
	(struct language_specific) <value_of_root>: Remove.
	(languages): Update initialization.
	(check_scope): Move earlier.
	(c_value_of_root): Move earlier and rename to ...
	(value_of_root_1): ... this.
	(value_of_root): Caller update.
	(cplus_value_of_root, java_value_of_root): Remove.
	(ada_value_of_root): Remove.
---
  gdb/varobj.c |  192 
++++++++++++++++++++++++---------------------------------
  1 files changed, 81 insertions(+), 111 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index bcf62dc..007574f 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -321,8 +321,6 @@ static char *c_name_of_child (struct varobj *parent, 
int index);

  static char *c_path_expr_of_child (struct varobj *child);

-static struct value *c_value_of_root (struct varobj **var_handle);
-
  static struct value *c_value_of_child (struct varobj *parent, int index);

  static struct type *c_type_of_child (struct varobj *parent, int index);
@@ -342,8 +340,6 @@ static char *cplus_name_of_child (struct varobj 
*parent, int index);

  static char *cplus_path_expr_of_child (struct varobj *child);

-static struct value *cplus_value_of_root (struct varobj **var_handle);
-
  static struct value *cplus_value_of_child (struct varobj *parent, int 
index);

  static struct type *cplus_type_of_child (struct varobj *parent, int 
index);
@@ -361,8 +357,6 @@ static char *java_name_of_child (struct varobj 
*parent, int index);

  static char *java_path_expr_of_child (struct varobj *child);

-static struct value *java_value_of_root (struct varobj **var_handle);
-
  static struct value *java_value_of_child (struct varobj *parent, int 
index);

  static struct type *java_type_of_child (struct varobj *parent, int index);
@@ -380,8 +374,6 @@ static char *ada_name_of_child (struct varobj 
*parent, int index);

  static char *ada_path_expr_of_child (struct varobj *child);

-static struct value *ada_value_of_root (struct varobj **var_handle);
-
  static struct value *ada_value_of_child (struct varobj *parent, int 
index);

  static struct type *ada_type_of_child (struct varobj *parent, int index);
@@ -411,9 +403,6 @@ struct language_specific
       obtain that has some parent.  */
    char *(*path_expr_of_child) (struct varobj * child);

-  /* The ``struct value *'' of the root variable ROOT.  */
-  struct value *(*value_of_root) (struct varobj ** root_handle);
-
    /* The ``struct value *'' of the INDEX'th child of PARENT.  */
    struct value *(*value_of_child) (struct varobj * parent, int index);

@@ -458,7 +447,6 @@ static struct language_specific languages[vlang_end] = {
     c_name_of_variable,
     c_name_of_child,
     c_path_expr_of_child,
-   c_value_of_root,
     c_value_of_child,
     c_type_of_child,
     c_value_of_variable,
@@ -471,7 +459,6 @@ static struct language_specific languages[vlang_end] = {
     cplus_name_of_variable,
     cplus_name_of_child,
     cplus_path_expr_of_child,
-   cplus_value_of_root,
     cplus_value_of_child,
     cplus_type_of_child,
     cplus_value_of_variable,
@@ -484,7 +471,6 @@ static struct language_specific languages[vlang_end] = {
     java_name_of_variable,
     java_name_of_child,
     java_path_expr_of_child,
-   java_value_of_root,
     java_value_of_child,
     java_type_of_child,
     java_value_of_variable,
@@ -496,7 +482,6 @@ static struct language_specific languages[vlang_end] = {
     ada_name_of_variable,
     ada_name_of_child,
     ada_path_expr_of_child,
-   ada_value_of_root,
     ada_value_of_child,
     ada_type_of_child,
     ada_value_of_variable,
@@ -2710,6 +2695,86 @@ name_of_child (struct varobj *var, int index)
    return (*var->root->lang->name_of_child) (var, index);
  }

+/* If frame associated with VAR can be found, switch
+   to it and return 1.  Otherwise, return 0.  */
+
+static int
+check_scope (struct varobj *var)
+{
+  struct frame_info *fi;
+  int scope;
+
+  fi = frame_find_by_id (var->root->frame);
+  scope = fi != NULL;
+
+  if (fi)
+    {
+      CORE_ADDR pc = get_frame_pc (fi);
+
+      if (pc <  BLOCK_START (var->root->valid_block) ||
+	  pc >= BLOCK_END (var->root->valid_block))
+	scope = 0;
+      else
+	select_frame (fi);
+    }
+  return scope;
+}
+
+/* Helper function to value_of_root.  */
+
+static struct value *
+value_of_root_1 (struct varobj **var_handle)
+{
+  struct value *new_val = NULL;
+  struct varobj *var = *var_handle;
+  int within_scope = 0;
+  struct cleanup *back_to;
+								
+  /*  Only root variables can be updated...  */
+  if (!is_root_p (var))
+    /* Not a root var.  */
+    return NULL;
+
+  back_to = make_cleanup_restore_current_thread ();
+
+  /* Determine whether the variable is still around.  */
+  if (var->root->valid_block == NULL || var->root->floating)
+    within_scope = 1;
+  else if (var->root->thread_id == 0)
+    {
+      /* The program was single-threaded when the variable object was
+	 created.  Technically, it's possible that the program became
+	 multi-threaded since then, but we don't support such
+	 scenario yet.  */
+      within_scope = check_scope (var);	
+    }
+  else
+    {
+      ptid_t ptid = thread_id_to_pid (var->root->thread_id);
+      if (in_thread_list (ptid))
+	{
+	  switch_to_thread (ptid);
+	  within_scope = check_scope (var);
+	}
+    }
+
+  if (within_scope)
+    {
+      volatile struct gdb_exception except;
+
+      /* We need to catch errors here, because if evaluate
+         expression fails we want to just return NULL.  */
+      TRY_CATCH (except, RETURN_MASK_ERROR)
+	{
+	  new_val = evaluate_expression (var->root->exp);
+	}
+    }
+
+  do_cleanups (back_to);
+
+  return new_val;
+}
+
  /* What is the ``struct value *'' of the root variable VAR?
     For floating variable object, evaluation can get us a value
     of different type from what is stored in varobj already.  In
@@ -2787,7 +2852,7 @@ value_of_root (struct varobj **var_handle, int 
*type_changed)
    {
      struct value *value;

-    value = (*var->root->lang->value_of_root) (var_handle);
+    value = value_of_root_1 (var_handle);
      if (var->value == NULL || value == NULL)
        {
  	/* For root varobj-s, a NULL value indicates a scoping issue.
@@ -3382,83 +3447,6 @@ c_path_expr_of_child (struct varobj *child)
    return child->path_expr;
  }

-/* If frame associated with VAR can be found, switch
-   to it and return 1.  Otherwise, return 0.  */
-static int
-check_scope (struct varobj *var)
-{
-  struct frame_info *fi;
-  int scope;
-
-  fi = frame_find_by_id (var->root->frame);
-  scope = fi != NULL;
-
-  if (fi)
-    {
-      CORE_ADDR pc = get_frame_pc (fi);
-
-      if (pc <  BLOCK_START (var->root->valid_block) ||
-	  pc >= BLOCK_END (var->root->valid_block))
-	scope = 0;
-      else
-	select_frame (fi);
-    }
-  return scope;
-}
-
-static struct value *
-c_value_of_root (struct varobj **var_handle)
-{
-  struct value *new_val = NULL;
-  struct varobj *var = *var_handle;
-  int within_scope = 0;
-  struct cleanup *back_to;
-								
-  /*  Only root variables can be updated...  */
-  if (!is_root_p (var))
-    /* Not a root var.  */
-    return NULL;
-
-  back_to = make_cleanup_restore_current_thread ();
-
-  /* Determine whether the variable is still around.  */
-  if (var->root->valid_block == NULL || var->root->floating)
-    within_scope = 1;
-  else if (var->root->thread_id == 0)
-    {
-      /* The program was single-threaded when the variable object was
-	 created.  Technically, it's possible that the program became
-	 multi-threaded since then, but we don't support such
-	 scenario yet.  */
-      within_scope = check_scope (var);	
-    }
-  else
-    {
-      ptid_t ptid = thread_id_to_pid (var->root->thread_id);
-      if (in_thread_list (ptid))
-	{
-	  switch_to_thread (ptid);
-	  within_scope = check_scope (var);
-	}
-    }
-
-  if (within_scope)
-    {
-      volatile struct gdb_exception except;
-
-      /* We need to catch errors here, because if evaluate
-         expression fails we want to just return NULL.  */
-      TRY_CATCH (except, RETURN_MASK_ERROR)
-	{
-	  new_val = evaluate_expression (var->root->exp);
-	}
-    }
-
-  do_cleanups (back_to);
-
-  return new_val;
-}
-
  static struct value *
  c_value_of_child (struct varobj *parent, int index)
  {
@@ -3893,12 +3881,6 @@ cplus_path_expr_of_child (struct varobj *child)
  }

  static struct value *
-cplus_value_of_root (struct varobj **var_handle)
-{
-  return c_value_of_root (var_handle);
-}
-
-static struct value *
  cplus_value_of_child (struct varobj *parent, int index)
  {
    struct value *value = NULL;
@@ -3983,12 +3965,6 @@ java_path_expr_of_child (struct varobj *child)
  }

  static struct value *
-java_value_of_root (struct varobj **var_handle)
-{
-  return cplus_value_of_root (var_handle);
-}
-
-static struct value *
  java_value_of_child (struct varobj *parent, int index)
  {
    return cplus_value_of_child (parent, index);
@@ -4041,12 +4017,6 @@ ada_path_expr_of_child (struct varobj *child)
  }

  static struct value *
-ada_value_of_root (struct varobj **var_handle)
-{
-  return c_value_of_root (var_handle);
-}
-
-static struct value *
  ada_value_of_child (struct varobj *parent, int index)
  {
    return ada_varobj_get_value_of_child (parent->value, parent->type,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 2/7] Remove vlang_unknown
  2013-10-01 13:34     ` Yao Qi
@ 2013-10-02  0:19       ` Doug Evans
  2013-10-02  9:32         ` Joel Brobecker
  0 siblings, 1 reply; 35+ messages in thread
From: Doug Evans @ 2013-10-02  0:19 UTC (permalink / raw)
  To: Yao Qi; +Cc: Joel Brobecker, gdb-patches

On Tue, Oct 1, 2013 at 6:32 AM, Yao Qi <yao@codesourcery.com> wrote:
> On 10/01/2013 06:07 PM, Joel Brobecker wrote:
>>
>> I am not really sure why the first enum would need to be zero.
>> If we cannot find an answer to that question, I propose you leave
>> the "= 0" out of this patch.
>
>
> In varobj.c:varobj_create, variable_language returns
> 'enum varobj_languages', and use it as an index to array
> languages.
>
>       /* Set language info */
>       lang = variable_language (var);
>       var->root->lang = &languages[lang];
>
> that is the reason the first enum should be zero.

While we know enums begin at zero, making it explicit is fine with me.

But if there's a reason that needed explaining, a comment in the code
explaining "Why things are the way they are"
is most welcome.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 2/7] Remove vlang_unknown
  2013-10-02  0:19       ` Doug Evans
@ 2013-10-02  9:32         ` Joel Brobecker
  2013-10-04  8:31           ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-02  9:32 UTC (permalink / raw)
  To: Doug Evans; +Cc: Yao Qi, gdb-patches

> > In varobj.c:varobj_create, variable_language returns
> > 'enum varobj_languages', and use it as an index to array
> > languages.
> >
> >       /* Set language info */
> >       lang = variable_language (var);
> >       var->root->lang = &languages[lang];
> >
> > that is the reason the first enum should be zero.
> 
> While we know enums begin at zero, making it explicit is fine with me.
> 
> But if there's a reason that needed explaining, a comment in the code
> explaining "Why things are the way they are"
> is most welcome.

I agree. I think the patch is OK to go with a quick comment added,
explaining that we want to be able to index arrays using this enum,
so we make its first enum explicitly zero (despite the fact that
this is the default, this prevents someone else just accidently
setting the first enum's value to nonzero for other reasons).

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-09-18 13:55 ` [PATCH 4/7] Move struct varobj to varobj.h Yao Qi
@ 2013-10-02  9:46   ` Joel Brobecker
  2013-10-02 19:32     ` Doug Evans
  2013-10-06  6:33     ` Yao Qi
  0 siblings, 2 replies; 35+ messages in thread
From: Joel Brobecker @ 2013-10-02  9:46 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> This patch moves most of the fields of struct varobj to varobj.h, and
> continue to name it 'struct varobj.h' there.  New struct
> varobj_dynamic 'extends' struct varobj in varobj.c.
> 
> Move part of struct varobj to varobj.h
> 
> gdb:
> 
> 2013-09-18  Yao Qi  <yao@codesourcery.com>
> 
> 	* varobj.c (struct varobj): Move most of the fields to
> 	varobj.h.
> 	(struct varobj_dynamic): New struct.
> 	(varobj_get_display_hint) [HAVE_PYTHON]: Cast 'var' to type
> 	'struct varobj_dynamic'.
> 	(varobj_has_more): Likewise.
> 	(dynamic_varobj_has_child_method): Change type of parameter
> 	'var' to 'struct varobj_dynamic *'.
> 	(update_dynamic_varobj_children): Likewise.
> 	(install_visualizer): Likewise.
> 	(install_default_visualizer, construct_visualizer): Likewise.
> 	(varobj_get_num_children): Likewise.
> 	(dynamic_varobj_has_child_method): Adjust.
> 	(varobj_list_children, varobj_get_attributes): Likewise.
> 	(varobj_set_value, install_new_value): Likewise.
> 	(varobj_update, new_variable): Likewise.
> 	(my_value_of_variable, value_get_print_value): Likewise.
> 	* varobj.h (struct varobj): Moved from varobj.c.

Overall, I like the direction that the whole series is taking.
But this is a patch that makes me a little uncomfortable, because
I am not sure really want to introduce this kind of polymorphism
where we cast struct varobj into struct varobj_dynamic. I would
need to think about it some more - it seems to me that at the root
of things, we are always manipulating a varobj_dynamic so it is
always safe to cast it.  But this then begs the question why not
declare them as struct varobj_dynamic in the first place. The answer
is probably that we don't want to expose too much of struct varobj,
and in particular the part dealing with dynamicity and pretty-printers.

Perhaps, and this is thinking out loud, another approach would be
to make this data part of the public struct varobj, but inside
an opaque structure?

I'd really like feedback from other maintainers who have experience
in this area...


> ---
>  gdb/varobj.c |  239 +++++++++++++++++++++++-----------------------------------
>  gdb/varobj.h |   74 ++++++++++++++++++
>  2 files changed, 167 insertions(+), 146 deletions(-)
> 
> diff --git a/gdb/varobj.c b/gdb/varobj.c
> index 3ecf702..672d246 100644
> --- a/gdb/varobj.c
> +++ b/gdb/varobj.c
> @@ -116,48 +116,11 @@ struct varobj_root
>    struct varobj_root *next;
>  };
>  
> -/* Every variable in the system has a structure of this type defined
> -   for it.  This structure holds all information necessary to manipulate
> -   a particular object variable.  Members which must be freed are noted.  */
> -struct varobj
> -{
> -
> -  /* Alloc'd name of the variable for this object.  If this variable is a
> -     child, then this name will be the child's source name.
> -     (bar, not foo.bar).  */
> -  /* NOTE: This is the "expression".  */
> -  char *name;
> -
> -  /* Alloc'd expression for this child.  Can be used to create a
> -     root variable corresponding to this child.  */
> -  char *path_expr;
> -
> -  /* The alloc'd name for this variable's object.  This is here for
> -     convenience when constructing this object's children.  */
> -  char *obj_name;
> -
> -  /* Index of this variable in its parent or -1.  */
> -  int index;
> -
> -  /* The type of this variable.  This can be NULL
> -     for artifial variable objects -- currently, the "accessibility" 
> -     variable objects in C++.  */
> -  struct type *type;
> +/* Dynamic varobj.  */
>  
> -  /* The value of this expression or subexpression.  A NULL value
> -     indicates there was an error getting this value.
> -     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
> -     the value is either NULL, or not lazy.  */
> -  struct value *value;
> -
> -  /* The number of (immediate) children this variable has.  */
> -  int num_children;
> -
> -  /* If this object is a child, this points to its immediate parent.  */
> -  struct varobj *parent;
> -
> -  /* Children of this object.  */
> -  VEC (varobj_p) *children;
> +struct varobj_dynamic
> +{
> +  struct varobj base;
>  
>    /* Whether the children of this varobj were requested.  This field is
>       used to decide if dynamic varobj should recompute their children.
> @@ -165,35 +128,6 @@ struct varobj
>       can avoid that.  */
>    int children_requested;
>  
> -  /* Description of the root variable.  Points to root variable for
> -     children.  */
> -  struct varobj_root *root;
> -
> -  /* The format of the output for this object.  */
> -  enum varobj_display_formats format;
> -
> -  /* Was this variable updated via a varobj_set_value operation.  */
> -  int updated;
> -
> -  /* Last print value.  */
> -  char *print_value;
> -
> -  /* Is this variable frozen.  Frozen variables are never implicitly
> -     updated by -var-update * 
> -     or -var-update <direct-or-indirect-parent>.  */
> -  int frozen;
> -
> -  /* Is the value of this variable intentionally not fetched?  It is
> -     not fetched if either the variable is frozen, or any parents is
> -     frozen.  */
> -  int not_fetched;
> -
> -  /* Sub-range of children which the MI consumer has requested.  If
> -     FROM < 0 or TO < 0, means that all children have been
> -     requested.  */
> -  int from;
> -  int to;
> -
>    /* The pretty-printer constructor.  If NULL, then the default
>       pretty-printer will be looked up.  If None, then no
>       pretty-printer will be installed.  */
> @@ -899,14 +833,15 @@ varobj_get_display_hint (struct varobj *var)
>  
>  #if HAVE_PYTHON
>    struct cleanup *back_to;
> +  PyObject *pretty_printer = ((struct varobj_dynamic *) var)->pretty_printer;
>  
>    if (!gdb_python_initialized)
>      return NULL;
>  
>    back_to = varobj_ensure_python_env (var);
>  
> -  if (var->pretty_printer)
> -    result = gdbpy_get_display_hint (var->pretty_printer);
> +  if (pretty_printer != NULL)
> +    result = gdbpy_get_display_hint (pretty_printer);
>  
>    do_cleanups (back_to);
>  #endif
> @@ -922,7 +857,7 @@ varobj_has_more (struct varobj *var, int to)
>    if (VEC_length (varobj_p, var->children) > to)
>      return 1;
>    return ((to == -1 || VEC_length (varobj_p, var->children) == to)
> -	  && var->saved_item != NULL);
> +	  && ((struct varobj_dynamic *) var)->saved_item != NULL);
>  }
>  
>  /* If the variable object is bound to a specific thread, that
> @@ -1029,7 +964,7 @@ install_dynamic_child (struct varobj *var,
>  }
>  
>  static int
> -dynamic_varobj_has_child_method (struct varobj *var)
> +dynamic_varobj_has_child_method (struct varobj_dynamic *var)
>  {
>    struct cleanup *back_to;
>    PyObject *printer = var->pretty_printer;
> @@ -1038,7 +973,7 @@ dynamic_varobj_has_child_method (struct varobj *var)
>    if (!gdb_python_initialized)
>      return 0;
>  
> -  back_to = varobj_ensure_python_env (var);
> +  back_to = varobj_ensure_python_env ((struct varobj *) var);
>    result = PyObject_HasAttr (printer, gdbpy_children_cst);
>    do_cleanups (back_to);
>    return result;
> @@ -1047,7 +982,7 @@ dynamic_varobj_has_child_method (struct varobj *var)
>  #endif
>  
>  static int
> -update_dynamic_varobj_children (struct varobj *var,
> +update_dynamic_varobj_children (struct varobj_dynamic *var,
>  				VEC (varobj_p) **changed,
>  				VEC (varobj_p) **type_changed,
>  				VEC (varobj_p) **new,
> @@ -1066,7 +1001,7 @@ update_dynamic_varobj_children (struct varobj *var,
>    if (!gdb_python_initialized)
>      return 0;
>  
> -  back_to = varobj_ensure_python_env (var);
> +  back_to = varobj_ensure_python_env ((struct varobj *) var);
>  
>    *cchanged = 0;
>    if (!PyObject_HasAttr (printer, gdbpy_children_cst))
> @@ -1102,7 +1037,7 @@ update_dynamic_varobj_children (struct varobj *var,
>        i = 0;
>      }
>    else
> -    i = VEC_length (varobj_p, var->children);
> +    i = VEC_length (varobj_p, var->base.children);
>  
>    /* We ask for one extra child, so that MI can report whether there
>       are more children.  */
> @@ -1184,7 +1119,8 @@ update_dynamic_varobj_children (struct varobj *var,
>  	  v = convert_value_from_python (py_v);
>  	  if (v == NULL)
>  	    gdbpy_print_stack ();
> -	  install_dynamic_child (var, can_mention ? changed : NULL,
> +	  install_dynamic_child ((struct varobj *) var,
> +				 can_mention ? changed : NULL,
>  				 can_mention ? type_changed : NULL,
>  				 can_mention ? new : NULL,
>  				 can_mention ? unchanged : NULL,
> @@ -1205,22 +1141,22 @@ update_dynamic_varobj_children (struct varobj *var,
>  	break;
>      }
>  
> -  if (i < VEC_length (varobj_p, var->children))
> +  if (i < VEC_length (varobj_p, var->base.children))
>      {
>        int j;
>  
>        *cchanged = 1;
> -      for (j = i; j < VEC_length (varobj_p, var->children); ++j)
> -	varobj_delete (VEC_index (varobj_p, var->children, j), NULL, 0);
> -      VEC_truncate (varobj_p, var->children, i);
> +      for (j = i; j < VEC_length (varobj_p, var->base.children); ++j)
> +	varobj_delete (VEC_index (varobj_p, var->base.children, j), NULL, 0);
> +      VEC_truncate (varobj_p, var->base.children, i);
>      }
>  
>    /* If there are fewer children than requested, note that the list of
>       children changed.  */
> -  if (to >= 0 && VEC_length (varobj_p, var->children) < to)
> +  if (to >= 0 && VEC_length (varobj_p, var->base.children) < to)
>      *cchanged = 1;
>  
> -  var->num_children = VEC_length (varobj_p, var->children);
> +  var->base.num_children = VEC_length (varobj_p, var->base.children);
>   
>    do_cleanups (back_to);
>  
> @@ -1235,14 +1171,16 @@ varobj_get_num_children (struct varobj *var)
>  {
>    if (var->num_children == -1)
>      {
> -      if (var->pretty_printer)
> +      struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
> +
> +      if (var_dyn->pretty_printer)
>  	{
>  	  int dummy;
>  
>  	  /* If we have a dynamic varobj, don't report -1 children.
>  	     So, try to fetch some children first.  */
> -	  update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL, &dummy,
> -					  0, 0, 0);
> +	  update_dynamic_varobj_children (var_dyn, NULL, NULL, NULL,
> +					  NULL, &dummy, 0, 0, 0);
>  	}
>        else
>  	var->num_children = number_of_children (var);
> @@ -1259,15 +1197,16 @@ varobj_list_children (struct varobj *var, int *from, int *to)
>  {
>    char *name;
>    int i, children_changed;
> +  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
>  
> -  var->children_requested = 1;
> +  var_dyn->children_requested = 1;
>  
> -  if (var->pretty_printer)
> +  if (var_dyn->pretty_printer)
>      {
>        /* This, in theory, can result in the number of children changing without
>  	 frontend noticing.  But well, calling -var-list-children on the same
>  	 varobj twice is not something a sane frontend would do.  */
> -      update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL,
> +      update_dynamic_varobj_children (var_dyn, NULL, NULL, NULL, NULL,
>  				      &children_changed, 0, 0, *to);
>        restrict_range (var->children, from, to);
>        return var->children;
> @@ -1413,7 +1352,7 @@ varobj_get_attributes (struct varobj *var)
>  int
>  varobj_pretty_printed_p (struct varobj *var)
>  {
> -  return var->pretty_printer != NULL;
> +  return ((struct varobj_dynamic *) var)->pretty_printer != NULL;
>  }
>  
>  char *
> @@ -1504,7 +1443,7 @@ varobj_set_value (struct varobj *var, char *expression)
>     in a varobj.  */
>  
>  static void
> -install_visualizer (struct varobj *var, PyObject *constructor,
> +install_visualizer (struct varobj_dynamic *var, PyObject *constructor,
>  		    PyObject *visualizer)
>  {
>    Py_XDECREF (var->constructor);
> @@ -1520,19 +1459,19 @@ install_visualizer (struct varobj *var, PyObject *constructor,
>  /* Install the default visualizer for VAR.  */
>  
>  static void
> -install_default_visualizer (struct varobj *var)
> +install_default_visualizer (struct varobj_dynamic *var)
>  {
>    /* Do not install a visualizer on a CPLUS_FAKE_CHILD.  */
> -  if (CPLUS_FAKE_CHILD (var))
> +  if (CPLUS_FAKE_CHILD (&var->base))
>      return;
>  
>    if (pretty_printing)
>      {
>        PyObject *pretty_printer = NULL;
>  
> -      if (var->value)
> +      if (var->base.value != NULL)
>  	{
> -	  pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
> +	  pretty_printer = gdbpy_get_varobj_pretty_printer (var->base.value);
>  	  if (! pretty_printer)
>  	    {
>  	      gdbpy_print_stack ();
> @@ -1554,12 +1493,12 @@ install_default_visualizer (struct varobj *var)
>     make a new object.  */
>  
>  static void
> -construct_visualizer (struct varobj *var, PyObject *constructor)
> +construct_visualizer (struct varobj_dynamic *var, PyObject *constructor)
>  {
>    PyObject *pretty_printer;
>  
>    /* Do not install a visualizer on a CPLUS_FAKE_CHILD.  */
> -  if (CPLUS_FAKE_CHILD (var))
> +  if (CPLUS_FAKE_CHILD (&var->base))
>      return;
>  
>    Py_INCREF (constructor);
> @@ -1567,7 +1506,8 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
>      pretty_printer = NULL;
>    else
>      {
> -      pretty_printer = instantiate_pretty_printer (constructor, var->value);
> +      pretty_printer = instantiate_pretty_printer (constructor,
> +						   var->base.value);
>        if (! pretty_printer)
>  	{
>  	  gdbpy_print_stack ();
> @@ -1592,7 +1532,7 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
>     a visualizer for VAR, if appropriate.  */
>  
>  static void
> -install_new_value_visualizer (struct varobj *var)
> +install_new_value_visualizer (struct varobj_dynamic *var)
>  {
>  #if HAVE_PYTHON
>    /* If the constructor is None, then we want the raw value.  If VAR
> @@ -1600,13 +1540,13 @@ install_new_value_visualizer (struct varobj *var)
>    if (!gdb_python_initialized)
>      return;
>  
> -  if (var->constructor != Py_None && var->value)
> +  if (var->constructor != Py_None && var->base.value)
>      {
>        struct cleanup *cleanup;
>  
> -      cleanup = varobj_ensure_python_env (var);
> +      cleanup = varobj_ensure_python_env ((struct varobj *) var);
>  
> -      if (!var->constructor)
> +      if (var->constructor == NULL)
>  	install_default_visualizer (var);
>        else
>  	construct_visualizer (var, var->constructor);
> @@ -1676,6 +1616,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
>    int changed = 0;
>    int intentionally_not_fetched = 0;
>    char *print_value = NULL;
> +  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
>  
>    /* We need to know the varobj's type to decide if the value should
>       be fetched or not.  C++ fake children (public/protected/private)
> @@ -1686,7 +1627,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
>    /* If the type has custom visualizer, we consider it to be always
>       changeable.  FIXME: need to make sure this behaviour will not
>       mess up read-sensitive values.  */
> -  if (var->pretty_printer)
> +  if (var_dyn->pretty_printer != NULL)
>      changeable = 1;
>  
>    need_to_fetch = changeable;
> @@ -1757,7 +1698,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
>       values.  Don't get string rendering if the value is
>       lazy -- if it is, the code above has decided that the value
>       should not be fetched.  */
> -  if (value && !value_lazy (value) && !var->pretty_printer)
> +  if (value && !value_lazy (value) && var_dyn->pretty_printer == NULL)
>      print_value = value_get_print_value (value, var->format, var);
>  
>    /* If the type is changeable, compare the old and the new values.
> @@ -1774,7 +1715,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
>  	{
>  	  changed = 1;
>  	}
> -      else if (! var->pretty_printer)
> +      else if (var_dyn->pretty_printer == NULL)
>  	{
>  	  /* Try to compare the values.  That requires that both
>  	     values are non-lazy.  */
> @@ -1825,11 +1766,11 @@ install_new_value (struct varobj *var, struct value *value, int initial)
>      var->not_fetched = 0;
>    var->updated = 0;
>  
> -  install_new_value_visualizer (var);
> +  install_new_value_visualizer (var_dyn);
>  
>    /* If we installed a pretty-printer, re-compare the printed version
>       to see if the variable changed.  */
> -  if (var->pretty_printer)
> +  if (var_dyn->pretty_printer != NULL)
>      {
>        xfree (print_value);
>        print_value = value_get_print_value (var->value, var->format, var);
> @@ -1894,7 +1835,7 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
>        error (_("Could not evaluate visualizer expression: %s"), visualizer);
>      }
>  
> -  construct_visualizer (var, constructor);
> +  construct_visualizer ((struct varobj_dynamic *) var, constructor);
>    Py_XDECREF (constructor);
>  
>    /* If there are any children now, wipe them.  */
> @@ -2019,6 +1960,7 @@ varobj_update (struct varobj **varp, int explicit)
>      {
>        varobj_update_result r = *(VEC_last (varobj_update_result, stack));
>        struct varobj *v = r.varobj;
> +      struct varobj_dynamic *v_dyn = (struct varobj_dynamic *) v;
>  
>        VEC_pop (varobj_update_result, stack);
>  
> @@ -2058,7 +2000,7 @@ varobj_update (struct varobj **varp, int explicit)
>        /* We probably should not get children of a varobj that has a
>  	 pretty-printer, but for which -var-list-children was never
>  	 invoked.  */
> -      if (v->pretty_printer)
> +      if (v_dyn->pretty_printer != NULL)
>  	{
>  	  VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
>  	  VEC (varobj_p) *new = 0;
> @@ -2067,7 +2009,7 @@ varobj_update (struct varobj **varp, int explicit)
>  	  if (v->frozen)
>  	    continue;
>  
> -	  if (!v->children_requested)
> +	  if (!v_dyn->children_requested)
>  	    {
>  	      int dummy;
>  
> @@ -2079,8 +2021,8 @@ varobj_update (struct varobj **varp, int explicit)
>  		 it.  */
>  	      if (!varobj_has_more (v, 0))
>  		{
> -		  update_dynamic_varobj_children (v, NULL, NULL, NULL, NULL,
> -						  &dummy, 0, 0, 0);
> +		  update_dynamic_varobj_children (v_dyn, NULL, NULL, NULL,
> +						  NULL, &dummy, 0, 0, 0);
>  		  if (varobj_has_more (v, 0))
>  		    r.changed = 1;
>  		}
> @@ -2093,9 +2035,10 @@ varobj_update (struct varobj **varp, int explicit)
>  
>  	  /* If update_dynamic_varobj_children returns 0, then we have
>  	     a non-conforming pretty-printer, so we skip it.  */
> -	  if (update_dynamic_varobj_children (v, &changed, &type_changed, &new,
> -					      &unchanged, &children_changed, 1,
> -					      v->from, v->to))
> +	  if (update_dynamic_varobj_children (v_dyn, &changed, &type_changed,
> +					      &new, &unchanged,
> +					      &children_changed, 1, v->from,
> +					      v->to))
>  	    {
>  	      if (children_changed || new)
>  		{
> @@ -2441,33 +2384,33 @@ create_child_with_value (struct varobj *parent, int index, const char *name,
>  static struct varobj *
>  new_variable (void)
>  {
> -  struct varobj *var;
> -
> -  var = (struct varobj *) xmalloc (sizeof (struct varobj));
> -  var->name = NULL;
> -  var->path_expr = NULL;
> -  var->obj_name = NULL;
> -  var->index = -1;
> -  var->type = NULL;
> -  var->value = NULL;
> -  var->num_children = -1;
> -  var->parent = NULL;
> -  var->children = NULL;
> -  var->format = 0;
> -  var->root = NULL;
> -  var->updated = 0;
> -  var->print_value = NULL;
> -  var->frozen = 0;
> -  var->not_fetched = 0;
> +  struct varobj_dynamic *var;
> +
> +  var = (struct varobj_dynamic *) xmalloc (sizeof (struct varobj_dynamic));
> +  var->base.name = NULL;
> +  var->base.path_expr = NULL;
> +  var->base.obj_name = NULL;
> +  var->base.index = -1;
> +  var->base.type = NULL;
> +  var->base.value = NULL;
> +  var->base.num_children = -1;
> +  var->base.parent = NULL;
> +  var->base.children = NULL;
> +  var->base.format = 0;
> +  var->base.root = NULL;
> +  var->base.updated = 0;
> +  var->base.print_value = NULL;
> +  var->base.frozen = 0;
> +  var->base.not_fetched = 0;
>    var->children_requested = 0;
> -  var->from = -1;
> -  var->to = -1;
> +  var->base.from = -1;
> +  var->base.to = -1;
>    var->constructor = 0;
>    var->pretty_printer = 0;
>    var->child_iter = 0;
>    var->saved_item = 0;
>  
> -  return var;
> +  return (struct varobj *) var;
>  }
>  
>  /* Allocate memory and initialize a new root variable.  */
> @@ -2493,13 +2436,16 @@ static void
>  free_variable (struct varobj *var)
>  {
>  #if HAVE_PYTHON
> -  if (var->pretty_printer)
> +  struct varobj_dynamic *var_dyn = (struct varobj_dynamic *) var;
> +
> +  if (var_dyn->pretty_printer)
>      {
>        struct cleanup *cleanup = varobj_ensure_python_env (var);
> -      Py_XDECREF (var->constructor);
> -      Py_XDECREF (var->pretty_printer);
> -      Py_XDECREF (var->child_iter);
> -      Py_XDECREF (var->saved_item);
> +
> +      Py_XDECREF (var_dyn->constructor);
> +      Py_XDECREF (var_dyn->pretty_printer);
> +      Py_XDECREF (var_dyn->child_iter);
> +      Py_XDECREF (var_dyn->saved_item);
>        do_cleanups (cleanup);
>      }
>  #endif
> @@ -2889,7 +2835,7 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
>  {
>    if (var->root->is_valid)
>      {
> -      if (var->pretty_printer)
> +      if (((struct varobj_dynamic *) var)->pretty_printer)
>  	return value_get_print_value (var->value, var->format, var);
>        return (*var->root->lang->value_of_variable) (var, format);
>      }
> @@ -2923,7 +2869,8 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
>  #if HAVE_PYTHON
>    if (gdb_python_initialized)
>      {
> -      PyObject *value_formatter = var->pretty_printer;
> +      PyObject *value_formatter
> +	= ((struct varobj_dynamic *) var)->pretty_printer;
>  
>        varobj_ensure_python_env (var);
>  
> @@ -2931,7 +2878,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
>  	{
>  	  /* First check to see if we have any children at all.  If so,
>  	     we simply return {...}.  */
> -	  if (dynamic_varobj_has_child_method (var))
> +	  if (dynamic_varobj_has_child_method ((struct varobj_dynamic *) var))
>  	    {
>  	      do_cleanups (old_chain);
>  	      return xstrdup ("{...}");
> diff --git a/gdb/varobj.h b/gdb/varobj.h
> index d4abb99..894ba03 100644
> --- a/gdb/varobj.h
> +++ b/gdb/varobj.h
> @@ -88,6 +88,80 @@ typedef struct varobj_update_result_t
>  
>  DEF_VEC_O (varobj_update_result);
>  
> +struct varobj_root;
> +
> +/* Every variable in the system has a structure of this type defined
> +   for it.  This structure holds all information necessary to manipulate
> +   a particular object variable.  Members which must be freed are noted.  */
> +struct varobj
> +{
> +  /* Alloc'd name of the variable for this object.  If this variable is a
> +     child, then this name will be the child's source name.
> +     (bar, not foo.bar).  */
> +  /* NOTE: This is the "expression".  */
> +  char *name;
> +
> +  /* Alloc'd expression for this child.  Can be used to create a
> +     root variable corresponding to this child.  */
> +  char *path_expr;
> +
> +  /* The alloc'd name for this variable's object.  This is here for
> +     convenience when constructing this object's children.  */
> +  char *obj_name;
> +
> +  /* Index of this variable in its parent or -1.  */
> +  int index;
> +
> +  /* The type of this variable.  This can be NULL
> +     for artifial variable objects -- currently, the "accessibility" 
> +     variable objects in C++.  */
> +  struct type *type;
> +
> +  /* The value of this expression or subexpression.  A NULL value
> +     indicates there was an error getting this value.
> +     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
> +     the value is either NULL, or not lazy.  */
> +  struct value *value;
> +
> +  /* The number of (immediate) children this variable has.  */
> +  int num_children;
> +
> +  /* If this object is a child, this points to its immediate parent.  */
> +  struct varobj *parent;
> +
> +  /* Children of this object.  */
> +  VEC (varobj_p) *children;
> +
> +  /* Description of the root variable.  Points to root variable for
> +     children.  */
> +  struct varobj_root *root;
> +
> +  /* The format of the output for this object.  */
> +  enum varobj_display_formats format;
> +
> +  /* Was this variable updated via a varobj_set_value operation.  */
> +  int updated;
> +
> +  /* Last print value.  */
> +  char *print_value;
> +
> +  /* Is this variable frozen.  Frozen variables are never implicitly
> +     updated by -var-update * 
> +     or -var-update <direct-or-indirect-parent>.  */
> +  int frozen;
> +
> +  /* Is the value of this variable intentionally not fetched?  It is
> +     not fetched if either the variable is frozen, or any parents is
> +     frozen.  */
> +  int not_fetched;
> +
> +  /* Sub-range of children which the MI consumer has requested.  If
> +     FROM < 0 or TO < 0, means that all children have been
> +     requested.  */
> +  int from;
> +  int to;
> +};
> +
>  /* API functions */
>  
>  extern struct varobj *varobj_create (char *objname,
> -- 
> 1.7.7.6

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5/7] New lang-varobj.h
  2013-09-18 13:55 ` [PATCH 5/7] New lang-varobj.h Yao Qi
@ 2013-10-02 17:18   ` Doug Evans
  2013-10-08  4:59     ` Joel Brobecker
  0 siblings, 1 reply; 35+ messages in thread
From: Doug Evans @ 2013-10-02 17:18 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi writes:
 > This patch moves 'struct language_specific' out of varobj.c to a new file
 > 'lang-varobj.h'.
 > 
 > gdb:
 > 
 > 2013-09-18  Yao Qi  <yao@codesourcery.com>
 > 
 > 	* Makefile.in (HFILES_NO_SRCDIR): Add lang-varobj.h.
 > 	* lang-varobj.h: New.
 > 	* varobj.c: Include "lang-varobj.h".
 > 	(struct varobj_root): <lang>: Update its type.
 > 	(struct language_specific): Move it to lang-varobj.h.

Hi.

How about move lang-varobj.h into varobj.h?

[setting aside general discussions of the approach for a different thread ...]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-02  9:46   ` Joel Brobecker
@ 2013-10-02 19:32     ` Doug Evans
  2013-10-06  6:33     ` Yao Qi
  1 sibling, 0 replies; 35+ messages in thread
From: Doug Evans @ 2013-10-02 19:32 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, gdb-patches

Joel Brobecker writes:
 > > This patch moves most of the fields of struct varobj to varobj.h, and
 > > continue to name it 'struct varobj.h' there.  New struct
 > > varobj_dynamic 'extends' struct varobj in varobj.c.
 > > 
 > > Move part of struct varobj to varobj.h
 > > 
 > > gdb:
 > > 
 > > 2013-09-18  Yao Qi  <yao@codesourcery.com>
 > > 
 > > 	* varobj.c (struct varobj): Move most of the fields to
 > > 	varobj.h.
 > > 	(struct varobj_dynamic): New struct.
 > > 	(varobj_get_display_hint) [HAVE_PYTHON]: Cast 'var' to type
 > > 	'struct varobj_dynamic'.
 > > 	(varobj_has_more): Likewise.
 > > 	(dynamic_varobj_has_child_method): Change type of parameter
 > > 	'var' to 'struct varobj_dynamic *'.
 > > 	(update_dynamic_varobj_children): Likewise.
 > > 	(install_visualizer): Likewise.
 > > 	(install_default_visualizer, construct_visualizer): Likewise.
 > > 	(varobj_get_num_children): Likewise.
 > > 	(dynamic_varobj_has_child_method): Adjust.
 > > 	(varobj_list_children, varobj_get_attributes): Likewise.
 > > 	(varobj_set_value, install_new_value): Likewise.
 > > 	(varobj_update, new_variable): Likewise.
 > > 	(my_value_of_variable, value_get_print_value): Likewise.
 > > 	* varobj.h (struct varobj): Moved from varobj.c.
 > 
 > Overall, I like the direction that the whole series is taking.

Me too.

 > But this is a patch that makes me a little uncomfortable, because
 > I am not sure really want to introduce this kind of polymorphism
 > where we cast struct varobj into struct varobj_dynamic.

Me too. :-)

 > I would
 > need to think about it some more - it seems to me that at the root
 > of things, we are always manipulating a varobj_dynamic so it is
 > always safe to cast it.  But this then begs the question why not
 > declare them as struct varobj_dynamic in the first place. The answer
 > is probably that we don't want to expose too much of struct varobj,
 > and in particular the part dealing with dynamicity and pretty-printers.

We don't have "private" but, heh, Python doesn't either except by convention.
So ... we *could* have a similar convention.
Just a thought for discussion's sake ... :-)
[If C++ is around the corner one might punt, though it couldn't hurt
to document (in some way) what's private and what's not today.]

 > Perhaps, and this is thinking out loud, another approach would be
 > to make this data part of the public struct varobj, but inside
 > an opaque structure?

"works for me"
There's only one constructor (I think), it could handle the details.

 > I'd really like feedback from other maintainers who have experience
 > in this area...

IWBN to have something that didn't use casting alright.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 2/7] Remove vlang_unknown
  2013-10-02  9:32         ` Joel Brobecker
@ 2013-10-04  8:31           ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-04  8:31 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Doug Evans, gdb-patches

On 10/02/2013 05:32 PM, Joel Brobecker wrote:
> I agree. I think the patch is OK to go with a quick comment added,
> explaining that we want to be able to index arrays using this enum,
> so we make its first enum explicitly zero (despite the fact that
> this is the default, this prevents someone else just accidently
> setting the first enum's value to nonzero for other reasons).

Comments are added in the patch below.  It is obvious to me, and I'll
commit it.

-- 
Yao (齐尧)

gdb:

2013-10-04  Yao Qi  <yao@codesourcery.com>

	* varobj.h: Add comments to enum varobj_languages.
---
 gdb/varobj.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/gdb/varobj.h b/gdb/varobj.h
index 5f6eb88..c794085 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -52,7 +52,8 @@ enum varobj_scope_status
 /* String representations of gdb's format codes (defined in varobj.c).  */
 extern char *varobj_format_string[];
 
-/* Languages supported by this variable objects system.  */
+/* Languages supported by this variable objects system.  This enum is used
+   to index arrays so we make its first enum explicitly zero.  */
 enum varobj_languages
   {
     vlang_c = 0, vlang_cplus, vlang_java, vlang_ada, vlang_end
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-02  9:46   ` Joel Brobecker
  2013-10-02 19:32     ` Doug Evans
@ 2013-10-06  6:33     ` Yao Qi
  2013-10-08  4:56       ` Joel Brobecker
  1 sibling, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-10-06  6:33 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/02/2013 05:46 PM, Joel Brobecker wrote:
> Perhaps, and this is thinking out loud, another approach would be
> to make this data part of the public struct varobj, but inside
> an opaque structure?

How about this?

-- 
Yao (齐尧)

gdb:

2013-10-06  Yao Qi  <yao@codesourcery.com>

	* varobj.c (struct varobj): Move most of the fields to
	varobj.h.
	(struct varobj_dynamic): New struct.
	(varobj_get_display_hint) [HAVE_PYTHON]: Adjust.
	(varobj_has_more): Likewise.
	(dynamic_varobj_has_child_method): Likewise.
	(update_dynamic_varobj_children): Likewise.
	(varobj_get_num_children): Likewise.
	(varobj_list_children, varobj_pretty_printed_p): Likewise.
	(install_new_value_visualizer): Likewise.
	(install_new_value_visualizer, install_new_value): Likewise.
	(varobj_update, new_variable, free_variable): Likewise.
	(my_value_of_variable, value_get_print_value): Likewise.
	(install_visualizer): Change the type of parameter 'var' to
	'struct varobjd_dynamic *'.  Callers update.
	* varobj.h (struct varobj): Moved from varobj.c.
	(struct varobj) <dynamic>: New field.
---
 gdb/varobj.c |  171 ++++++++++++++++++---------------------------------------
 gdb/varobj.h |   78 ++++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 117 deletions(-)

diff --git a/gdb/varobj.c b/gdb/varobj.c
index 5c30e52..b3ba56b 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -116,84 +116,16 @@ struct varobj_root
   struct varobj_root *next;
 };
 
-/* Every variable in the system has a structure of this type defined
-   for it.  This structure holds all information necessary to manipulate
-   a particular object variable.  Members which must be freed are noted.  */
-struct varobj
-{
-
-  /* Alloc'd name of the variable for this object.  If this variable is a
-     child, then this name will be the child's source name.
-     (bar, not foo.bar).  */
-  /* NOTE: This is the "expression".  */
-  char *name;
-
-  /* Alloc'd expression for this child.  Can be used to create a
-     root variable corresponding to this child.  */
-  char *path_expr;
-
-  /* The alloc'd name for this variable's object.  This is here for
-     convenience when constructing this object's children.  */
-  char *obj_name;
-
-  /* Index of this variable in its parent or -1.  */
-  int index;
-
-  /* The type of this variable.  This can be NULL
-     for artifial variable objects -- currently, the "accessibility" 
-     variable objects in C++.  */
-  struct type *type;
-
-  /* The value of this expression or subexpression.  A NULL value
-     indicates there was an error getting this value.
-     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
-     the value is either NULL, or not lazy.  */
-  struct value *value;
-
-  /* The number of (immediate) children this variable has.  */
-  int num_children;
-
-  /* If this object is a child, this points to its immediate parent.  */
-  struct varobj *parent;
-
-  /* Children of this object.  */
-  VEC (varobj_p) *children;
+/* Dynamic part of varobj.  */
 
+struct varobj_dynamic
+{
   /* Whether the children of this varobj were requested.  This field is
      used to decide if dynamic varobj should recompute their children.
      In the event that the frontend never asked for the children, we
      can avoid that.  */
   int children_requested;
 
-  /* Description of the root variable.  Points to root variable for
-     children.  */
-  struct varobj_root *root;
-
-  /* The format of the output for this object.  */
-  enum varobj_display_formats format;
-
-  /* Was this variable updated via a varobj_set_value operation.  */
-  int updated;
-
-  /* Last print value.  */
-  char *print_value;
-
-  /* Is this variable frozen.  Frozen variables are never implicitly
-     updated by -var-update * 
-     or -var-update <direct-or-indirect-parent>.  */
-  int frozen;
-
-  /* Is the value of this variable intentionally not fetched?  It is
-     not fetched if either the variable is frozen, or any parents is
-     frozen.  */
-  int not_fetched;
-
-  /* Sub-range of children which the MI consumer has requested.  If
-     FROM < 0 or TO < 0, means that all children have been
-     requested.  */
-  int from;
-  int to;
-
   /* The pretty-printer constructor.  If NULL, then the default
      pretty-printer will be looked up.  If None, then no
      pretty-printer will be installed.  */
@@ -905,8 +837,8 @@ varobj_get_display_hint (struct varobj *var)
 
   back_to = varobj_ensure_python_env (var);
 
-  if (var->pretty_printer)
-    result = gdbpy_get_display_hint (var->pretty_printer);
+  if (var->dynamic->pretty_printer != NULL)
+    result = gdbpy_get_display_hint (var->dynamic->pretty_printer);
 
   do_cleanups (back_to);
 #endif
@@ -922,7 +854,7 @@ varobj_has_more (struct varobj *var, int to)
   if (VEC_length (varobj_p, var->children) > to)
     return 1;
   return ((to == -1 || VEC_length (varobj_p, var->children) == to)
-	  && var->saved_item != NULL);
+	  && (var->dynamic->saved_item != NULL));
 }
 
 /* If the variable object is bound to a specific thread, that
@@ -1032,7 +964,7 @@ static int
 dynamic_varobj_has_child_method (struct varobj *var)
 {
   struct cleanup *back_to;
-  PyObject *printer = var->pretty_printer;
+  PyObject *printer = var->dynamic->pretty_printer;
   int result;
 
   if (!gdb_python_initialized)
@@ -1061,7 +993,7 @@ update_dynamic_varobj_children (struct varobj *var,
   struct cleanup *back_to;
   PyObject *children;
   int i;
-  PyObject *printer = var->pretty_printer;
+  PyObject *printer = var->dynamic->pretty_printer;
 
   if (!gdb_python_initialized)
     return 0;
@@ -1075,7 +1007,7 @@ update_dynamic_varobj_children (struct varobj *var,
       return 0;
     }
 
-  if (update_children || !var->child_iter)
+  if (update_children || var->dynamic->child_iter == NULL)
     {
       children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
 					     NULL);
@@ -1088,16 +1020,16 @@ update_dynamic_varobj_children (struct varobj *var,
 
       make_cleanup_py_decref (children);
 
-      Py_XDECREF (var->child_iter);
-      var->child_iter = PyObject_GetIter (children);
-      if (!var->child_iter)
+      Py_XDECREF (var->dynamic->child_iter);
+      var->dynamic->child_iter = PyObject_GetIter (children);
+      if (var->dynamic->child_iter == NULL)
 	{
 	  gdbpy_print_stack ();
 	  error (_("Could not get children iterator"));
 	}
 
-      Py_XDECREF (var->saved_item);
-      var->saved_item = NULL;
+      Py_XDECREF (var->dynamic->saved_item);
+      var->dynamic->saved_item = NULL;
 
       i = 0;
     }
@@ -1112,13 +1044,13 @@ update_dynamic_varobj_children (struct varobj *var,
       int force_done = 0;
 
       /* See if there was a leftover from last time.  */
-      if (var->saved_item)
+      if (var->dynamic->saved_item)
 	{
-	  item = var->saved_item;
-	  var->saved_item = NULL;
+	  item = var->dynamic->saved_item;
+	  var->dynamic->saved_item = NULL;
 	}
       else
-	item = PyIter_Next (var->child_iter);
+	item = PyIter_Next (var->dynamic->child_iter);
 
       if (!item)
 	{
@@ -1194,8 +1126,8 @@ update_dynamic_varobj_children (struct varobj *var,
 	}
       else
 	{
-	  Py_XDECREF (var->saved_item);
-	  var->saved_item = item;
+	  Py_XDECREF (var->dynamic->saved_item);
+	  var->dynamic->saved_item = item;
 
 	  /* We want to truncate the child list just before this
 	     element.  */
@@ -1236,7 +1168,7 @@ varobj_get_num_children (struct varobj *var)
 {
   if (var->num_children == -1)
     {
-      if (var->pretty_printer)
+      if (var->dynamic->pretty_printer != NULL)
 	{
 	  int dummy;
 
@@ -1261,9 +1193,9 @@ varobj_list_children (struct varobj *var, int *from, int *to)
   char *name;
   int i, children_changed;
 
-  var->children_requested = 1;
+  var->dynamic->children_requested = 1;
 
-  if (var->pretty_printer)
+  if (var->dynamic->pretty_printer != NULL)
     {
       /* This, in theory, can result in the number of children changing without
 	 frontend noticing.  But well, calling -var-list-children on the same
@@ -1414,7 +1346,7 @@ varobj_get_attributes (struct varobj *var)
 int
 varobj_pretty_printed_p (struct varobj *var)
 {
-  return var->pretty_printer != NULL;
+  return var->dynamic->pretty_printer != NULL;
 }
 
 char *
@@ -1502,10 +1434,10 @@ varobj_set_value (struct varobj *var, char *expression)
 #if HAVE_PYTHON
 
 /* A helper function to install a constructor function and visualizer
-   in a varobj.  */
+   in a varobj_dynamic.  */
 
 static void
-install_visualizer (struct varobj *var, PyObject *constructor,
+install_visualizer (struct varobj_dynamic *var, PyObject *constructor,
 		    PyObject *visualizer)
 {
   Py_XDECREF (var->constructor);
@@ -1547,7 +1479,7 @@ install_default_visualizer (struct varobj *var)
 	  pretty_printer = NULL;
 	}
   
-      install_visualizer (var, NULL, pretty_printer);
+      install_visualizer (var->dynamic, NULL, pretty_printer);
     }
 }
 
@@ -1584,7 +1516,7 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
 	}
     }
 
-  install_visualizer (var, constructor, pretty_printer);
+  install_visualizer (var->dynamic, constructor, pretty_printer);
 }
 
 #endif /* HAVE_PYTHON */
@@ -1601,16 +1533,16 @@ install_new_value_visualizer (struct varobj *var)
   if (!gdb_python_initialized)
     return;
 
-  if (var->constructor != Py_None && var->value)
+  if (var->dynamic->constructor != Py_None && var->value != NULL)
     {
       struct cleanup *cleanup;
 
       cleanup = varobj_ensure_python_env (var);
 
-      if (!var->constructor)
+      if (var->dynamic->constructor == NULL)
 	install_default_visualizer (var);
       else
-	construct_visualizer (var, var->constructor);
+	construct_visualizer (var, var->dynamic->constructor);
 
       do_cleanups (cleanup);
     }
@@ -1687,7 +1619,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   /* If the type has custom visualizer, we consider it to be always
      changeable.  FIXME: need to make sure this behaviour will not
      mess up read-sensitive values.  */
-  if (var->pretty_printer)
+  if (var->dynamic->pretty_printer != NULL)
     changeable = 1;
 
   need_to_fetch = changeable;
@@ -1758,7 +1690,8 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      values.  Don't get string rendering if the value is
      lazy -- if it is, the code above has decided that the value
      should not be fetched.  */
-  if (value && !value_lazy (value) && !var->pretty_printer)
+  if (value != NULL && !value_lazy (value)
+      && var->dynamic->pretty_printer == NULL)
     print_value = value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
@@ -1775,7 +1708,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
 	{
 	  changed = 1;
 	}
-      else if (! var->pretty_printer)
+      else if (var->dynamic->pretty_printer == NULL)
 	{
 	  /* Try to compare the values.  That requires that both
 	     values are non-lazy.  */
@@ -1830,7 +1763,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
 
   /* If we installed a pretty-printer, re-compare the printed version
      to see if the variable changed.  */
-  if (var->pretty_printer)
+  if (var->dynamic->pretty_printer != NULL)
     {
       xfree (print_value);
       print_value = value_get_print_value (var->value, var->format, var);
@@ -2059,7 +1992,7 @@ varobj_update (struct varobj **varp, int explicit)
       /* We probably should not get children of a varobj that has a
 	 pretty-printer, but for which -var-list-children was never
 	 invoked.  */
-      if (v->pretty_printer)
+      if (v->dynamic->pretty_printer != NULL)
 	{
 	  VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
 	  VEC (varobj_p) *new = 0;
@@ -2068,7 +2001,7 @@ varobj_update (struct varobj **varp, int explicit)
 	  if (v->frozen)
 	    continue;
 
-	  if (!v->children_requested)
+	  if (!v->dynamic->children_requested)
 	    {
 	      int dummy;
 
@@ -2459,13 +2392,15 @@ new_variable (void)
   var->print_value = NULL;
   var->frozen = 0;
   var->not_fetched = 0;
-  var->children_requested = 0;
+  var->dynamic
+    = (struct varobj_dynamic *) xmalloc (sizeof (struct varobj_dynamic));
+  var->dynamic->children_requested = 0;
   var->from = -1;
   var->to = -1;
-  var->constructor = 0;
-  var->pretty_printer = 0;
-  var->child_iter = 0;
-  var->saved_item = 0;
+  var->dynamic->constructor = 0;
+  var->dynamic->pretty_printer = 0;
+  var->dynamic->child_iter = 0;
+  var->dynamic->saved_item = 0;
 
   return var;
 }
@@ -2493,13 +2428,14 @@ static void
 free_variable (struct varobj *var)
 {
 #if HAVE_PYTHON
-  if (var->pretty_printer)
+  if (var->dynamic->pretty_printer != NULL)
     {
       struct cleanup *cleanup = varobj_ensure_python_env (var);
-      Py_XDECREF (var->constructor);
-      Py_XDECREF (var->pretty_printer);
-      Py_XDECREF (var->child_iter);
-      Py_XDECREF (var->saved_item);
+
+      Py_XDECREF (var->dynamic->constructor);
+      Py_XDECREF (var->dynamic->pretty_printer);
+      Py_XDECREF (var->dynamic->child_iter);
+      Py_XDECREF (var->dynamic->saved_item);
       do_cleanups (cleanup);
     }
 #endif
@@ -2517,6 +2453,7 @@ free_variable (struct varobj *var)
   xfree (var->obj_name);
   xfree (var->print_value);
   xfree (var->path_expr);
+  xfree (var->dynamic);
   xfree (var);
 }
 
@@ -2890,7 +2827,7 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
 {
   if (var->root->is_valid)
     {
-      if (var->pretty_printer)
+      if (var->dynamic->pretty_printer != NULL)
 	return value_get_print_value (var->value, var->format, var);
       return (*var->root->lang->value_of_variable) (var, format);
     }
@@ -2924,7 +2861,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
 #if HAVE_PYTHON
   if (gdb_python_initialized)
     {
-      PyObject *value_formatter = var->pretty_printer;
+      PyObject *value_formatter=  var->dynamic->pretty_printer;
 
       varobj_ensure_python_env (var);
 
diff --git a/gdb/varobj.h b/gdb/varobj.h
index b29e499..ea6e09b 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -89,6 +89,84 @@ typedef struct varobj_update_result_t
 
 DEF_VEC_O (varobj_update_result);
 
+struct varobj_root;
+struct varobj_dynamic;
+
+/* Every variable in the system has a structure of this type defined
+   for it.  This structure holds all information necessary to manipulate
+   a particular object variable.  Members which must be freed are noted.  */
+struct varobj
+{
+  /* Alloc'd name of the variable for this object.  If this variable is a
+     child, then this name will be the child's source name.
+     (bar, not foo.bar).  */
+  /* NOTE: This is the "expression".  */
+  char *name;
+
+  /* Alloc'd expression for this child.  Can be used to create a
+     root variable corresponding to this child.  */
+  char *path_expr;
+
+  /* The alloc'd name for this variable's object.  This is here for
+     convenience when constructing this object's children.  */
+  char *obj_name;
+
+  /* Index of this variable in its parent or -1.  */
+  int index;
+
+  /* The type of this variable.  This can be NULL
+     for artifial variable objects -- currently, the "accessibility" 
+     variable objects in C++.  */
+  struct type *type;
+
+  /* The value of this expression or subexpression.  A NULL value
+     indicates there was an error getting this value.
+     Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
+     the value is either NULL, or not lazy.  */
+  struct value *value;
+
+  /* The number of (immediate) children this variable has.  */
+  int num_children;
+
+  /* If this object is a child, this points to its immediate parent.  */
+  struct varobj *parent;
+
+  /* Children of this object.  */
+  VEC (varobj_p) *children;
+
+  /* Description of the root variable.  Points to root variable for
+     children.  */
+  struct varobj_root *root;
+
+  /* The format of the output for this object.  */
+  enum varobj_display_formats format;
+
+  /* Was this variable updated via a varobj_set_value operation.  */
+  int updated;
+
+  /* Last print value.  */
+  char *print_value;
+
+  /* Is this variable frozen.  Frozen variables are never implicitly
+     updated by -var-update * 
+     or -var-update <direct-or-indirect-parent>.  */
+  int frozen;
+
+  /* Is the value of this variable intentionally not fetched?  It is
+     not fetched if either the variable is frozen, or any parents is
+     frozen.  */
+  int not_fetched;
+
+  /* Sub-range of children which the MI consumer has requested.  If
+     FROM < 0 or TO < 0, means that all children have been
+     requested.  */
+  int from;
+  int to;
+
+  /* Dynamic part of varobj.  */
+  struct varobj_dynamic *dynamic;
+};
+
 /* API functions */
 
 extern struct varobj *varobj_create (char *objname,
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-06  6:33     ` Yao Qi
@ 2013-10-08  4:56       ` Joel Brobecker
  2013-10-08 21:03         ` Doug Evans
                           ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Joel Brobecker @ 2013-10-08  4:56 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> How about this?

It does look a lot better to me, FWIW.  The only possibly contentious
question left would be making struct varobj public, when I personally
tend to prefer opaque structures. But I'm fine with this step, as it
helps achieve the goal of moving the language-specific stuff out of
varobj.c. I think Doug also pretty much agreed to that change. I would
give the patch, say, until the end of the week, JIC others want to
comment in.

How does this new patch affect the rest of the patch series? No effect?
If not, we can continue reviewing the remainder.  Otherwise, can you
post an update?  Sorry it's taking so long. I just don't have much time.
But as I said, I like the direction this is taking.

Thanks!

> 2013-10-06  Yao Qi  <yao@codesourcery.com>
> 
> 	* varobj.c (struct varobj): Move most of the fields to
> 	varobj.h.
> 	(struct varobj_dynamic): New struct.
> 	(varobj_get_display_hint) [HAVE_PYTHON]: Adjust.
> 	(varobj_has_more): Likewise.
> 	(dynamic_varobj_has_child_method): Likewise.
> 	(update_dynamic_varobj_children): Likewise.
> 	(varobj_get_num_children): Likewise.
> 	(varobj_list_children, varobj_pretty_printed_p): Likewise.
> 	(install_new_value_visualizer): Likewise.
> 	(install_new_value_visualizer, install_new_value): Likewise.
> 	(varobj_update, new_variable, free_variable): Likewise.
> 	(my_value_of_variable, value_get_print_value): Likewise.
> 	(install_visualizer): Change the type of parameter 'var' to
> 	'struct varobjd_dynamic *'.  Callers update.
> 	* varobj.h (struct varobj): Moved from varobj.c.
> 	(struct varobj) <dynamic>: New field.

> @@ -2924,7 +2861,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
>  #if HAVE_PYTHON
>    if (gdb_python_initialized)
>      {
> -      PyObject *value_formatter = var->pretty_printer;
> +      PyObject *value_formatter=  var->dynamic->pretty_printer;

You accidently removed a space before '='.

> +/* Every variable in the system has a structure of this type defined
> +   for it.  This structure holds all information necessary to manipulate
> +   a particular object variable.  Members which must be freed are noted.  */
> +struct varobj
> +{

Not sure if there is a rule for it, or not. But I tend to prefer an
empty line between documentation and structure as well (same as with
subprograms). Add it if you agree, or else feel free to ignore. This
is just an arbitrary preference, AFAIK, and it really does not matter
much to me.

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5/7] New lang-varobj.h
  2013-10-02 17:18   ` Doug Evans
@ 2013-10-08  4:59     ` Joel Brobecker
  2013-10-09 23:51       ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-08  4:59 UTC (permalink / raw)
  To: Doug Evans; +Cc: Yao Qi, gdb-patches

>  > 2013-09-18  Yao Qi  <yao@codesourcery.com>
>  > 
>  > 	* Makefile.in (HFILES_NO_SRCDIR): Add lang-varobj.h.
>  > 	* lang-varobj.h: New.
>  > 	* varobj.c: Include "lang-varobj.h".
>  > 	(struct varobj_root): <lang>: Update its type.
>  > 	(struct language_specific): Move it to lang-varobj.h.
> 
> Hi.
> 
> How about move lang-varobj.h into varobj.h?

Not very important in the grand scheme of things, but I tend to agree
with the suggestion. If we had a lang-varobj.c, things might be
different. But for a simple definition of the language-specific ops
directly related to varobj, I'd keep things simple, inside varobj.h.

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-08  4:56       ` Joel Brobecker
@ 2013-10-08 21:03         ` Doug Evans
  2013-10-09  0:28         ` Yao Qi
  2013-10-14  8:19         ` Yao Qi
  2 siblings, 0 replies; 35+ messages in thread
From: Doug Evans @ 2013-10-08 21:03 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Yao Qi, gdb-patches

Joel Brobecker writes:
 > > How about this?
 > 
 > It does look a lot better to me, FWIW.  The only possibly contentious
 > question left would be making struct varobj public, when I personally
 > tend to prefer opaque structures. But I'm fine with this step, as it
 > helps achieve the goal of moving the language-specific stuff out of
 > varobj.c. I think Doug also pretty much agreed to that change. I would
 > give the patch, say, until the end of the week, JIC others want to
 > comment in.

Yeah, except for the nits you found, looks good to me.

[I can image more structs will get moved into headers in a c++ world,
thus this doesn't bother me.]

 > How does this new patch affect the rest of the patch series? No effect?
 > If not, we can continue reviewing the remainder.  Otherwise, can you
 > post an update?  Sorry it's taking so long. I just don't have much time.
 > But as I said, I like the direction this is taking.
 > 
 > Thanks!
 > 
 > > 2013-10-06  Yao Qi  <yao@codesourcery.com>
 > > 
 > > 	* varobj.c (struct varobj): Move most of the fields to
 > > 	varobj.h.
 > > 	(struct varobj_dynamic): New struct.
 > > 	(varobj_get_display_hint) [HAVE_PYTHON]: Adjust.
 > > 	(varobj_has_more): Likewise.
 > > 	(dynamic_varobj_has_child_method): Likewise.
 > > 	(update_dynamic_varobj_children): Likewise.
 > > 	(varobj_get_num_children): Likewise.
 > > 	(varobj_list_children, varobj_pretty_printed_p): Likewise.
 > > 	(install_new_value_visualizer): Likewise.
 > > 	(install_new_value_visualizer, install_new_value): Likewise.
 > > 	(varobj_update, new_variable, free_variable): Likewise.
 > > 	(my_value_of_variable, value_get_print_value): Likewise.
 > > 	(install_visualizer): Change the type of parameter 'var' to
 > > 	'struct varobjd_dynamic *'.  Callers update.
 > > 	* varobj.h (struct varobj): Moved from varobj.c.
 > > 	(struct varobj) <dynamic>: New field.
 > 
 > > @@ -2924,7 +2861,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
 > >  #if HAVE_PYTHON
 > >    if (gdb_python_initialized)
 > >      {
 > > -      PyObject *value_formatter = var->pretty_printer;
 > > +      PyObject *value_formatter=  var->dynamic->pretty_printer;
 > 
 > You accidently removed a space before '='.
 > 
 > > +/* Every variable in the system has a structure of this type defined
 > > +   for it.  This structure holds all information necessary to manipulate
 > > +   a particular object variable.  Members which must be freed are noted.  */
 > > +struct varobj
 > > +{
 > 
 > Not sure if there is a rule for it, or not. But I tend to prefer an
 > empty line between documentation and structure as well (same as with
 > subprograms). Add it if you agree, or else feel free to ignore. This
 > is just an arbitrary preference, AFAIK, and it really does not matter
 > much to me.

The more lines of code that follow, the more I like the blank line.

For something like:

/* blah blah blah ... */
int foo = 42;

I think the blank line is unnecessary.
[even if the comment itself is several lines]

But for a struct definition where more lines of code are involved, I like
the blank line.
[There is such a rule for function comments.  Whether it was originally
created because functions tend to involve several lines ... I'm not sure,
but I do like it, and am glad we're now enforcing it!]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-08  4:56       ` Joel Brobecker
  2013-10-08 21:03         ` Doug Evans
@ 2013-10-09  0:28         ` Yao Qi
  2013-10-14  8:19         ` Yao Qi
  2 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-09  0:28 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/08/2013 12:56 PM, Joel Brobecker wrote:
> It does look a lot better to me, FWIW.  The only possibly contentious
> question left would be making struct varobj public, when I personally
> tend to prefer opaque structures. But I'm fine with this step, as it
> helps achieve the goal of moving the language-specific stuff out of
> varobj.c. I think Doug also pretty much agreed to that change. I would
> give the patch, say, until the end of the week, JIC others want to
> comment in.

OK.

>
> How does this new patch affect the rest of the patch series? No effect?
> If not, we can continue reviewing the remainder.  Otherwise, can you
> post an update?  Sorry it's taking so long. I just don't have much time.
> But as I said, I like the direction this is taking.

It affects patch 6/7.  I'll post an update.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5/7] New lang-varobj.h
  2013-10-08  4:59     ` Joel Brobecker
@ 2013-10-09 23:51       ` Yao Qi
  2013-10-09 23:56         ` Doug Evans
  0 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-10-09 23:51 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Doug Evans, gdb-patches

On 10/08/2013 12:59 PM, Joel Brobecker wrote:
>> >How about move lang-varobj.h into varobj.h?
> Not very important in the grand scheme of things, but I tend to agree
> with the suggestion. If we had a lang-varobj.c, things might be
> different. But for a simple definition of the language-specific ops
> directly related to varobj, I'd keep things simple, inside varobj.h.

We don't have lang-varobj.c, but we'll have c-varobj.c, jv-varobj.c and
ada-varobj.c [done by patch 6/7].  Is it strong enough to justify 
creating new file lang-varobj.h?

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5/7] New lang-varobj.h
  2013-10-09 23:51       ` Yao Qi
@ 2013-10-09 23:56         ` Doug Evans
  2013-10-10  0:19           ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Doug Evans @ 2013-10-09 23:56 UTC (permalink / raw)
  To: Yao Qi; +Cc: Joel Brobecker, gdb-patches

On Wed, Oct 9, 2013 at 4:50 PM, Yao Qi <yao@codesourcery.com> wrote:
> On 10/08/2013 12:59 PM, Joel Brobecker wrote:
>>>
>>> >How about move lang-varobj.h into varobj.h?
>>
>> Not very important in the grand scheme of things, but I tend to agree
>> with the suggestion. If we had a lang-varobj.c, things might be
>> different. But for a simple definition of the language-specific ops
>> directly related to varobj, I'd keep things simple, inside varobj.h.
>
>
> We don't have lang-varobj.c, but we'll have c-varobj.c, jv-varobj.c and
> ada-varobj.c [done by patch 6/7].  Is it strong enough to justify creating
> new file lang-varobj.h?

"Well ..."

All it has is one struct, there's not much point to it right now.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5/7] New lang-varobj.h
  2013-10-09 23:56         ` Doug Evans
@ 2013-10-10  0:19           ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-10  0:19 UTC (permalink / raw)
  To: Doug Evans; +Cc: Joel Brobecker, gdb-patches

On 10/10/2013 07:56 AM, Doug Evans wrote:
> "Well ..."
>
> All it has is one struct, there's not much point to it right now.

All right, I'll drop this patch.  Probably we can revisit this patch
when it is necessary to move.

-- 
Yao (齐尧)

P.S. I prefer to 'slice' sources having multiple modules and move each 
module into each single source file, even some file is quite simple.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 6/7] Move language stuff out of varobj.c
  2013-09-18 13:55 ` [PATCH 6/7] Move language stuff out of varobj.c Yao Qi
@ 2013-10-11  8:20   ` Yao Qi
  2013-10-17  5:40     ` Joel Brobecker
  0 siblings, 1 reply; 35+ messages in thread
From: Yao Qi @ 2013-10-11  8:20 UTC (permalink / raw)
  To: gdb-patches

On 09/18/2013 09:54 PM, Yao Qi wrote:
> This patch moves language-related stuff out of varobj.c into
> c-varobj.c, jv-varobj.c and ada-varobj.c respectively.  This patch
> also makes some static functions extern and add "varobj_" prefix.

The new patch 4/7 affects this patch.  I post the updated one.  Patch
7/7 is not affected, so it can be reviewed too.

-- 
Yao (齐尧)

gdb:

2013-10-11  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add c-varobj.c and jv-varobj.c.
	(COMMON_OBS): Add c-varobj.o and jv-varobj.o.
	* ada-varobj.c: Include "varobj.h".
	(ada_number_of_children): New.  Moved from varobj.c.
	(ada_name_of_variable, ada_name_of_child): Likewise.
	(ada_path_expr_of_child, ada_value_of_child): Likewise.
	(ada_type_of_child, ada_value_of_variable): Likewise.
	(ada_value_is_changeable_p, ada_value_has_mutated): Likewise.
	(ada_varobj_ops): New.
	* c-varobj.c, jv-varobj.c: New file.  Moved from varobj.c.
	* gdbtypes.c (get_target_type): New.  Moved from varobj.c.
	* gdbtypes.h (get_target_type): Declare.
	* varobj.c: Remove the inclusion of "ada-varobj.h" and
	"ada-lang.h".
	(ANONYMOUS_STRUCT_NAME): Move it to c-varobj.c.
	(ANONYMOUS_UNION_NAME): Likewise.
	(get_type, get_value_type, get_target_type): Remove declarations.
	(value_get_print_value, varobj_value_get_print_value): Likewise.
	(c_number_of_children, c_name_of_variable): Likewise.
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable, java_number_of_children): Likewise.
	(java_name_of_variable, java_name_of_child): Likewise.
	(java_path_expr_of_child, java_value_of_child): Likewise.
	(java_type_of_child, java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Likewise.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	(struct language_specific): Move it to varobj.h.
	(CPLUS_FAKE_CHILD): Move it to varobj.h.
	(restrict_range): Rename it varobj_restrict_range.  Make it extern.
	Callers update.
	(get_path_expr_parent): Rename it to varobj_get_path_expr_parent.
	Make it extern.
	(is_anonymous_child): Move it to c-varobj.c and rename to
	varobj_is_anonymous_child.  Caller update.
	(get_type): Move it to c-varobj.c.
	(get_value_type): Rename it varobj_get_value_type.  Make it
	extern.
	(get_target_type): Move it gdbtypes.c.
	(varobj_formatted_print_options): New function.
	(value_get_print_value): Rename it to
	varobj_value_get_print_value and make it extern.
	(varobj_value_is_changeable_p): Make it extern.
	(adjust_value_for_child_access): Move it to c-varobj.c.
	(default_value_is_changeable_p): Rename it to
	varobj_default_value_is_changeable_p.  Make it extern.
	(c_number_of_children, c_name_of_variable): Move it to c-varobj.c
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable): Likewise.
	(java_number_of_children, java_name_of_variable): Move it to jv-varobj.c.
	(java_name_of_child, java_path_expr_of_child): Likewise.
	(java_value_of_child, java_type_of_child): Likewise.
	(java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Move it to ada-varobj.c.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	* varobj.h (CPLUS_FAKE_CHILD): New macro, moved from varobj.c.
	(struct lang_varobj_ops): New.  Renamed by 'struct language_specific'.
	(c_varobj_ops, cplus_varobj_ops): Declare.
	(java_varobj_ops, ada_varobj_ops): Declare.
	(varobj_default_value_is_changeable_p): Declare.
	(varobj_value_is_changeable_p): Declare.
	(varobj_get_value_type, varobj_is_anonymous_child): Declare.
	(varobj_get_path_expr_parent): Declare.
	(varobj_value_get_print_value): Declare.
	(varobj_formatted_print_options): Declare.
	(varobj_restrict_range): Declare.
---
 gdb/Makefile.in  |    8 +-
 gdb/ada-varobj.c |  137 ++++++
 gdb/c-varobj.c   |  910 +++++++++++++++++++++++++++++++++++++
 gdb/gdbtypes.c   |   16 +
 gdb/gdbtypes.h   |    4 +
 gdb/jv-varobj.c  |  105 +++++
 gdb/varobj.c     | 1328 ++----------------------------------------------------
 gdb/varobj.h     |   80 ++++
 8 files changed, 1300 insertions(+), 1288 deletions(-)
 create mode 100644 gdb/c-varobj.c
 create mode 100644 gdb/jv-varobj.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 2aa8134..c2d9b71 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -718,7 +718,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	block.c blockframe.c \
 	breakpoint.c break-catch-sig.c break-catch-throw.c \
 	build-id.c buildsym.c \
-	c-exp.y c-lang.c c-typeprint.c c-valprint.c \
+	c-exp.y c-lang.c c-typeprint.c c-valprint.c c-varobj.c \
 	charset.c cleanups.c cli-out.c coffread.c coff-pe-read.c \
 	complaints.c completer.c continuations.c corefile.c corelow.c \
 	cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \
@@ -739,7 +739,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	infcmd.c inflow.c infrun.c \
 	inline-frame.c \
 	interps.c \
-	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c \
+	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c jv-varobj.c \
 	language.c linespec.c minidebug.c \
 	m2-exp.y m2-lang.c m2-typeprint.c m2-valprint.c \
 	macrotab.c macroexp.c macrocmd.c macroscope.c main.c maint.c \
@@ -923,11 +923,11 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	dwarf2read.o mipsread.o stabsread.o corefile.o \
 	dwarf2expr.o dwarf2loc.o dwarf2-frame.o dwarf2-frame-tailcall.o \
 	ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \
-	ada-tasks.o ada-varobj.o \
+	ada-tasks.o ada-varobj.o c-varobj.o \
 	ui-out.o cli-out.o \
 	varobj.o vec.o \
 	go-lang.o go-valprint.o go-typeprint.o \
-	jv-lang.o jv-valprint.o jv-typeprint.o \
+	jv-lang.o jv-valprint.o jv-typeprint.o jv-varobj.o \
 	m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 53d8a9c..52c7687 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -20,6 +20,7 @@
 #include "defs.h"
 #include "ada-varobj.h"
 #include "ada-lang.h"
+#include "varobj.h"
 #include "language.h"
 #include "valprint.h"
 
@@ -885,4 +886,140 @@ ada_varobj_get_value_of_variable (struct value *value,
   return result;
 }
 
+/* Ada specific callbacks for VAROBJs.  */
 
+static int
+ada_number_of_children (struct varobj *var)
+{
+  return ada_varobj_get_number_of_children (var->value, var->type);
+}
+
+static char *
+ada_name_of_variable (struct varobj *parent)
+{
+  return c_varobj_ops.name_of_variable (parent);
+}
+
+static char *
+ada_name_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_name_of_child (parent->value, parent->type,
+				       parent->name, index);
+}
+
+static char*
+ada_path_expr_of_child (struct varobj *child)
+{
+  struct varobj *parent = child->parent;
+  const char *parent_path_expr = varobj_get_path_expr (parent);
+
+  return ada_varobj_get_path_expr_of_child (parent->value,
+					    parent->type,
+					    parent->name,
+					    parent_path_expr,
+					    child->index);
+}
+
+static struct value *
+ada_value_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_value_of_child (parent->value, parent->type,
+					parent->name, index);
+}
+
+static struct type *
+ada_type_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_type_of_child (parent->value, parent->type,
+				       index);
+}
+
+static char *
+ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  struct value_print_options opts;
+
+  varobj_formatted_print_options (&opts, format);
+
+  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
+}
+
+/* Implement the "value_is_changeable_p" routine for Ada.  */
+
+static int
+ada_value_is_changeable_p (struct varobj *var)
+{
+  struct type *type = var->value ? value_type (var->value) : var->type;
+
+  if (ada_is_array_descriptor_type (type)
+      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+    {
+      /* This is in reality a pointer to an unconstrained array.
+	 its value is changeable.  */
+      return 1;
+    }
+
+  if (ada_is_string_type (type))
+    {
+      /* We display the contents of the string in the array's
+	 "value" field.  The contents can change, so consider
+	 that the array is changeable.  */
+      return 1;
+    }
+
+  return varobj_default_value_is_changeable_p (var);
+}
+
+/* Implement the "value_has_mutated" routine for Ada.  */
+
+static int
+ada_value_has_mutated (struct varobj *var, struct value *new_val,
+		       struct type *new_type)
+{
+  int i;
+  int from = -1;
+  int to = -1;
+
+  /* If the number of fields have changed, then for sure the type
+     has mutated.  */
+  if (ada_varobj_get_number_of_children (new_val, new_type)
+      != var->num_children)
+    return 1;
+
+  /* If the number of fields have remained the same, then we need
+     to check the name of each field.  If they remain the same,
+     then chances are the type hasn't mutated.  This is technically
+     an incomplete test, as the child's type might have changed
+     despite the fact that the name remains the same.  But we'll
+     handle this situation by saying that the child has mutated,
+     not this value.
+
+     If only part (or none!) of the children have been fetched,
+     then only check the ones we fetched.  It does not matter
+     to the frontend whether a child that it has not fetched yet
+     has mutated or not. So just assume it hasn't.  */
+
+  varobj_restrict_range (var->children, &from, &to);
+  for (i = from; i < to; i++)
+    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
+					      var->name, i),
+		VEC_index (varobj_p, var->children, i)->name) != 0)
+      return 1;
+
+  return 0;
+}
+
+/* varobj operations for ada.  */
+
+const struct lang_varobj_ops ada_varobj_ops =
+{
+  ada_number_of_children,
+  ada_name_of_variable,
+  ada_name_of_child,
+  ada_path_expr_of_child,
+  ada_value_of_child,
+  ada_type_of_child,
+  ada_value_of_variable,
+  ada_value_is_changeable_p,
+  ada_value_has_mutated
+};
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
new file mode 100644
index 0000000..73e785c
--- /dev/null
+++ b/gdb/c-varobj.c
@@ -0,0 +1,910 @@
+/* varobj support for C and C++.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "value.h"
+#include "varobj.h"
+#include "gdbthread.h"
+#include "valprint.h"
+
+static void cplus_class_num_children (struct type *type, int children[3]);
+
+/* The names of varobjs representing anonymous structs or unions.  */
+#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
+#define ANONYMOUS_UNION_NAME _("<anonymous union>")
+
+/* Does CHILD represent a child with no name?  This happens when
+   the child is an anonmous struct or union and it has no field name
+   in its parent variable.
+
+   This has already been determined by *_describe_child. The easiest
+   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
+
+int
+varobj_is_anonymous_child (struct varobj *child)
+{
+  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
+	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
+}
+
+/* Given the value and the type of a variable object,
+   adjust the value and type to those necessary
+   for getting children of the variable object.
+   This includes dereferencing top-level references
+   to all types and dereferencing pointers to
+   structures.
+
+   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
+   value will be fetched and if it differs from static type
+   the value will be casted to it.
+
+   Both TYPE and *TYPE should be non-null.  VALUE
+   can be null if we want to only translate type.
+   *VALUE can be null as well -- if the parent
+   value is not known.
+
+   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
+   depending on whether pointer was dereferenced
+   in this function.  */
+
+static void
+adjust_value_for_child_access (struct value **value,
+				  struct type **type,
+				  int *was_ptr,
+				  int lookup_actual_type)
+{
+  gdb_assert (type && *type);
+
+  if (was_ptr)
+    *was_ptr = 0;
+
+  *type = check_typedef (*type);
+  
+  /* The type of value stored in varobj, that is passed
+     to us, is already supposed to be
+     reference-stripped.  */
+
+  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
+
+  /* Pointers to structures are treated just like
+     structures when accessing children.  Don't
+     dererences pointers to other types.  */
+  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
+    {
+      struct type *target_type = get_target_type (*type);
+      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
+	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
+	{
+	  if (value && *value)
+	    {
+	      volatile struct gdb_exception except;
+
+	      TRY_CATCH (except, RETURN_MASK_ERROR)
+		{
+		  *value = value_ind (*value);
+		}
+
+	      if (except.reason < 0)
+		*value = NULL;
+	    }
+	  *type = target_type;
+	  if (was_ptr)
+	    *was_ptr = 1;
+	}
+    }
+
+  /* The 'get_target_type' function calls check_typedef on
+     result, so we can immediately check type code.  No
+     need to call check_typedef here.  */
+
+  /* Access a real type of the value (if necessary and possible).  */
+  if (value && *value && lookup_actual_type)
+    {
+      struct type *enclosing_type;
+      int real_type_found = 0;
+
+      enclosing_type = value_actual_type (*value, 1, &real_type_found);
+      if (real_type_found)
+        {
+          *type = enclosing_type;
+          *value = value_cast (enclosing_type, *value);
+        }
+    }
+}
+
+/* C */
+
+static int
+c_number_of_children (struct varobj *var)
+{
+  struct type *type = varobj_get_value_type (var);
+  int children = 0;
+  struct type *target;
+
+  adjust_value_for_child_access (NULL, &type, NULL, 0);
+  target = get_target_type (type);
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
+	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
+      else
+	/* If we don't know how many elements there are, don't display
+	   any.  */
+	children = 0;
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      children = TYPE_NFIELDS (type);
+      break;
+
+    case TYPE_CODE_PTR:
+      /* The type here is a pointer to non-struct.  Typically, pointers
+	 have one child, except for function ptrs, which have no children,
+	 and except for void*, as we don't know what to show.
+
+         We can show char* so we allow it to be dereferenced.  If you decide
+         to test for it, please mind that a little magic is necessary to
+         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
+         TYPE_NAME == "char".  */
+      if (TYPE_CODE (target) == TYPE_CODE_FUNC
+	  || TYPE_CODE (target) == TYPE_CODE_VOID)
+	children = 0;
+      else
+	children = 1;
+      break;
+
+    default:
+      /* Other types have no children.  */
+      break;
+    }
+
+  return children;
+}
+
+static char *
+c_name_of_variable (struct varobj *parent)
+{
+  return xstrdup (parent->name);
+}
+
+/* Return the value of element TYPE_INDEX of a structure
+   value VALUE.  VALUE's type should be a structure,
+   or union, or a typedef to struct/union.
+
+   Returns NULL if getting the value fails.  Never throws.  */
+
+static struct value *
+value_struct_element_index (struct value *value, int type_index)
+{
+  struct value *result = NULL;
+  volatile struct gdb_exception e;
+  struct type *type = value_type (value);
+
+  type = check_typedef (type);
+
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
+	      || TYPE_CODE (type) == TYPE_CODE_UNION);
+
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      if (field_is_static (&TYPE_FIELD (type, type_index)))
+	result = value_static_field (type, type_index);
+      else
+	result = value_primitive_field (value, 0, type_index, type);
+    }
+  if (e.reason < 0)
+    {
+      return NULL;
+    }
+  else
+    {
+      return result;
+    }
+}
+
+/* Obtain the information about child INDEX of the variable
+   object PARENT.
+   If CNAME is not null, sets *CNAME to the name of the child relative
+   to the parent.
+   If CVALUE is not null, sets *CVALUE to the value of the child.
+   If CTYPE is not null, sets *CTYPE to the type of the child.
+
+   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
+   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
+   to NULL.  */
+
+static void 
+c_describe_child (struct varobj *parent, int index,
+		  char **cname, struct value **cvalue, struct type **ctype,
+		  char **cfull_expression)
+{
+  struct value *value = parent->value;
+  struct type *type = varobj_get_value_type (parent);
+  char *parent_expression = NULL;
+  int was_ptr;
+  volatile struct gdb_exception except;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    {
+      *cfull_expression = NULL;
+      parent_expression
+	= varobj_get_path_expr (varobj_get_path_expr_parent (parent));
+    }
+  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
+      
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (cname)
+	*cname
+	  = xstrdup (int_string (index 
+				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				 10, 1, 0, 0));
+
+      if (cvalue && value)
+	{
+	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
+
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_subscript (value, real_index);
+	    }
+	}
+
+      if (ctype)
+	*ctype = get_target_type (type);
+
+      if (cfull_expression)
+	*cfull_expression = 
+	  xstrprintf ("(%s)[%s]", parent_expression, 
+		      int_string (index
+				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				  10, 1, 0, 0));
+
+
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      {
+	const char *field_name;
+
+	/* If the type is anonymous and the field has no name,
+	   set an appropriate name.  */
+	field_name = TYPE_FIELD_NAME (type, index);
+	if (field_name == NULL || *field_name == '\0')
+	  {
+	    if (cname)
+	      {
+		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
+		    == TYPE_CODE_STRUCT)
+		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		else
+		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
+	      }
+
+	    if (cfull_expression)
+	      *cfull_expression = xstrdup ("");
+	  }
+	else
+	  {
+	    if (cname)
+	      *cname = xstrdup (field_name);
+
+	    if (cfull_expression)
+	      {
+		char *join = was_ptr ? "->" : ".";
+
+		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
+						join, field_name);
+	      }
+	  }
+
+	if (cvalue && value)
+	  {
+	    /* For C, varobj index is the same as type index.  */
+	    *cvalue = value_struct_element_index (value, index);
+	  }
+
+	if (ctype)
+	  *ctype = TYPE_FIELD_TYPE (type, index);
+      }
+      break;
+
+    case TYPE_CODE_PTR:
+      if (cname)
+	*cname = xstrprintf ("*%s", parent->name);
+
+      if (cvalue && value)
+	{
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_ind (value);
+	    }
+
+	  if (except.reason < 0)
+	    *cvalue = NULL;
+	}
+
+      /* Don't use get_target_type because it calls
+	 check_typedef and here, we want to show the true
+	 declared type of the variable.  */
+      if (ctype)
+	*ctype = TYPE_TARGET_TYPE (type);
+
+      if (cfull_expression)
+	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
+      
+      break;
+
+    default:
+      /* This should not happen.  */
+      if (cname)
+	*cname = xstrdup ("???");
+      if (cfull_expression)
+	*cfull_expression = xstrdup ("???");
+      /* Don't set value and type, we don't know then.  */
+    }
+}
+
+static char *
+c_name_of_child (struct varobj *parent, int index)
+{
+  char *name;
+
+  c_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+c_path_expr_of_child (struct varobj *child)
+{
+  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+		    &child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+c_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  c_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+c_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  c_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+/* This returns the type of the variable.  It also skips past typedefs
+   to return the real type of the variable.  */
+
+static struct type *
+get_type (struct varobj *var)
+{
+  struct type *type;
+
+  type = var->type;
+  if (type != NULL)
+    type = check_typedef (type);
+
+  return type;
+}
+
+static char *
+c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  /* BOGUS: if val_print sees a struct/class, or a reference to one,
+     it will print out its children instead of "{...}".  So we need to
+     catch that case explicitly.  */
+  struct type *type = get_type (var);
+
+  /* Strip top-level references.  */
+  while (TYPE_CODE (type) == TYPE_CODE_REF)
+    type = check_typedef (TYPE_TARGET_TYPE (type));
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      return xstrdup ("{...}");
+      /* break; */
+
+    case TYPE_CODE_ARRAY:
+      {
+	char *number;
+
+	number = xstrprintf ("[%d]", var->num_children);
+	return (number);
+      }
+      /* break; */
+
+    default:
+      {
+	if (var->value == NULL)
+	  {
+	    /* This can happen if we attempt to get the value of a struct
+	       member when the parent is an invalid pointer.  This is an
+	       error condition, so we should tell the caller.  */
+	    return NULL;
+	  }
+	else
+	  {
+	    if (var->not_fetched && value_lazy (var->value))
+	      /* Frozen variable and no value yet.  We don't
+		 implicitly fetch the value.  MI response will
+		 use empty string for the value, which is OK.  */
+	      return NULL;
+
+	    gdb_assert (varobj_value_is_changeable_p (var));
+	    gdb_assert (!value_lazy (var->value));
+	    
+	    /* If the specified format is the current one,
+	       we can reuse print_value.  */
+	    if (format == var->format)
+	      return xstrdup (var->print_value);
+	    else
+	      return varobj_value_get_print_value (var->value, format, var);
+	  }
+      }
+    }
+}
+\f
+
+/* varobj operations for c.  */
+
+const struct lang_varobj_ops c_varobj_ops =
+{
+   c_number_of_children,
+   c_name_of_variable,
+   c_name_of_child,
+   c_path_expr_of_child,
+   c_value_of_child,
+   c_type_of_child,
+   c_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+/* A little convenience enum for dealing with C++/Java.  */
+enum vsections
+{
+  v_public = 0, v_private, v_protected
+};
+
+/* C++ */
+
+static int
+cplus_number_of_children (struct varobj *var)
+{
+  struct value *value = NULL;
+  struct type *type;
+  int children, dont_know;
+  int lookup_actual_type = 0;
+  struct value_print_options opts;
+
+  dont_know = 1;
+  children = 0;
+
+  get_user_print_options (&opts);
+
+  if (!CPLUS_FAKE_CHILD (var))
+    {
+      type = varobj_get_value_type (var);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+          value = var->value;
+          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
+	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
+	{
+	  int kids[3];
+
+	  cplus_class_num_children (type, kids);
+	  if (kids[v_public] != 0)
+	    children++;
+	  if (kids[v_private] != 0)
+	    children++;
+	  if (kids[v_protected] != 0)
+	    children++;
+
+	  /* Add any baseclasses.  */
+	  children += TYPE_N_BASECLASSES (type);
+	  dont_know = 0;
+
+	  /* FIXME: save children in var.  */
+	}
+    }
+  else
+    {
+      int kids[3];
+
+      type = varobj_get_value_type (var->parent);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+	  struct varobj *parent = var->parent;
+
+	  value = parent->value;
+	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
+				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      cplus_class_num_children (type, kids);
+      if (strcmp (var->name, "public") == 0)
+	children = kids[v_public];
+      else if (strcmp (var->name, "private") == 0)
+	children = kids[v_private];
+      else
+	children = kids[v_protected];
+      dont_know = 0;
+    }
+
+  if (dont_know)
+    children = c_number_of_children (var);
+
+  return children;
+}
+
+/* Compute # of public, private, and protected variables in this class.
+   That means we need to descend into all baseclasses and find out
+   how many are there, too.  */
+
+static void
+cplus_class_num_children (struct type *type, int children[3])
+{
+  int i, vptr_fieldno;
+  struct type *basetype = NULL;
+
+  children[v_public] = 0;
+  children[v_private] = 0;
+  children[v_protected] = 0;
+
+  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+    {
+      /* If we have a virtual table pointer, omit it.  Even if virtual
+	 table pointers are not specifically marked in the debug info,
+	 they should be artificial.  */
+      if ((type == basetype && i == vptr_fieldno)
+	  || TYPE_FIELD_ARTIFICIAL (type, i))
+	continue;
+
+      if (TYPE_FIELD_PROTECTED (type, i))
+	children[v_protected]++;
+      else if (TYPE_FIELD_PRIVATE (type, i))
+	children[v_private]++;
+      else
+	children[v_public]++;
+    }
+}
+
+static char *
+cplus_name_of_variable (struct varobj *parent)
+{
+  return c_name_of_variable (parent);
+}
+
+enum accessibility { private_field, protected_field, public_field };
+
+/* Check if field INDEX of TYPE has the specified accessibility.
+   Return 0 if so and 1 otherwise.  */
+
+static int 
+match_accessibility (struct type *type, int index, enum accessibility acc)
+{
+  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
+    return 1;
+  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
+	   && !TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else
+    return 0;
+}
+
+static void
+cplus_describe_child (struct varobj *parent, int index,
+		      char **cname, struct value **cvalue, struct type **ctype,
+		      char **cfull_expression)
+{
+  struct value *value;
+  struct type *type;
+  int was_ptr;
+  int lookup_actual_type = 0;
+  char *parent_expression = NULL;
+  struct varobj *var;
+  struct value_print_options opts;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    *cfull_expression = NULL;
+
+  get_user_print_options (&opts);
+
+  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
+  if (opts.objectprint)
+    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
+  value = var->value;
+  type = varobj_get_value_type (var);
+  if (cfull_expression)
+    parent_expression
+      = varobj_get_path_expr (varobj_get_path_expr_parent (var));
+
+  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
+
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+      || TYPE_CODE (type) == TYPE_CODE_UNION)
+    {
+      char *join = was_ptr ? "->" : ".";
+
+      if (CPLUS_FAKE_CHILD (parent))
+	{
+	  /* The fields of the class type are ordered as they
+	     appear in the class.  We are given an index for a
+	     particular access control type ("public","protected",
+	     or "private").  We must skip over fields that don't
+	     have the access control we are looking for to properly
+	     find the indexed field.  */
+	  int type_index = TYPE_N_BASECLASSES (type);
+	  enum accessibility acc = public_field;
+	  int vptr_fieldno;
+	  struct type *basetype = NULL;
+	  const char *field_name;
+
+	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+	  if (strcmp (parent->name, "private") == 0)
+	    acc = private_field;
+	  else if (strcmp (parent->name, "protected") == 0)
+	    acc = protected_field;
+
+	  while (index >= 0)
+	    {
+	      if ((type == basetype && type_index == vptr_fieldno)
+		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
+		; /* ignore vptr */
+	      else if (match_accessibility (type, type_index, acc))
+		    --index;
+		  ++type_index;
+	    }
+	  --type_index;
+
+	  /* If the type is anonymous and the field has no name,
+	     set an appopriate name.  */
+	  field_name = TYPE_FIELD_NAME (type, type_index);
+	  if (field_name == NULL || *field_name == '\0')
+	    {
+	      if (cname)
+		{
+		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+		      == TYPE_CODE_STRUCT)
+		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+			   == TYPE_CODE_UNION)
+		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
+		}
+
+	      if (cfull_expression)
+		*cfull_expression = xstrdup ("");
+	    }
+	  else
+	    {
+	      if (cname)
+		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
+
+	      if (cfull_expression)
+		*cfull_expression
+		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
+				field_name);
+	    }
+
+	  if (cvalue && value)
+	    *cvalue = value_struct_element_index (value, type_index);
+
+	  if (ctype)
+	    *ctype = TYPE_FIELD_TYPE (type, type_index);
+	}
+      else if (index < TYPE_N_BASECLASSES (type))
+	{
+	  /* This is a baseclass.  */
+	  if (cname)
+	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
+
+	  if (cvalue && value)
+	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
+
+	  if (ctype)
+	    {
+	      *ctype = TYPE_FIELD_TYPE (type, index);
+	    }
+
+	  if (cfull_expression)
+	    {
+	      char *ptr = was_ptr ? "*" : "";
+
+	      /* Cast the parent to the base' type.  Note that in gdb,
+		 expression like 
+		         (Base1)d
+		 will create an lvalue, for all appearences, so we don't
+		 need to use more fancy:
+		         *(Base1*)(&d)
+		 construct.
+
+		 When we are in the scope of the base class or of one
+		 of its children, the type field name will be interpreted
+		 as a constructor, if it exists.  Therefore, we must
+		 indicate that the name is a class name by using the
+		 'class' keyword.  See PR mi/11912  */
+	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
+					      ptr, 
+					      TYPE_FIELD_NAME (type, index),
+					      ptr,
+					      parent_expression);
+	    }
+	}
+      else
+	{
+	  char *access = NULL;
+	  int children[3];
+
+	  cplus_class_num_children (type, children);
+
+	  /* Everything beyond the baseclasses can
+	     only be "public", "private", or "protected"
+
+	     The special "fake" children are always output by varobj in
+	     this order.  So if INDEX == 2, it MUST be "protected".  */
+	  index -= TYPE_N_BASECLASSES (type);
+	  switch (index)
+	    {
+	    case 0:
+	      if (children[v_public] > 0)
+	 	access = "public";
+	      else if (children[v_private] > 0)
+	 	access = "private";
+	      else 
+	 	access = "protected";
+	      break;
+	    case 1:
+	      if (children[v_public] > 0)
+		{
+		  if (children[v_private] > 0)
+		    access = "private";
+		  else
+		    access = "protected";
+		}
+	      else if (children[v_private] > 0)
+	 	access = "protected";
+	      break;
+	    case 2:
+	      /* Must be protected.  */
+	      access = "protected";
+	      break;
+	    default:
+	      /* error!  */
+	      break;
+	    }
+
+	  gdb_assert (access);
+	  if (cname)
+	    *cname = xstrdup (access);
+
+	  /* Value and type and full expression are null here.  */
+	}
+    }
+  else
+    {
+      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
+    }  
+}
+
+static char *
+cplus_name_of_child (struct varobj *parent, int index)
+{
+  char *name = NULL;
+
+  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+cplus_path_expr_of_child (struct varobj *child)
+{
+  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+			&child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+cplus_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+cplus_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+static char *
+cplus_value_of_variable (struct varobj *var, 
+			 enum varobj_display_formats format)
+{
+
+  /* If we have one of our special types, don't print out
+     any value.  */
+  if (CPLUS_FAKE_CHILD (var))
+    return xstrdup ("");
+
+  return c_value_of_variable (var, format);
+}
+\f
+
+/* varobj operations for c++.  */
+
+const struct lang_varobj_ops cplus_varobj_ops =
+{
+   cplus_number_of_children,
+   cplus_name_of_variable,
+   cplus_name_of_child,
+   cplus_path_expr_of_child,
+   cplus_value_of_child,
+   cplus_type_of_child,
+   cplus_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+\f
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6c809a4..4da6ca2 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -239,6 +239,22 @@ get_type_arch (const struct type *type)
     return TYPE_OWNER (type).gdbarch;
 }
 
+/* This returns the target type (or NULL) of TYPE, also skipping
+   past typedefs.  */
+
+struct type *
+get_target_type (struct type *type)
+{
+  if (type != NULL)
+    {
+      type = TYPE_TARGET_TYPE (type);
+      if (type != NULL)
+	type = check_typedef (type);
+    }
+
+  return type;
+}
+
 /* Alloc a new type instance structure, fill it with some defaults,
    and point it at OLDTYPE.  Allocate the new type instance from the
    same place as OLDTYPE.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 5e8d1e7..d7fdedf 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1431,6 +1431,10 @@ extern struct type *alloc_type_copy (const struct type *);
    objfile's architecture is returned.  */
 extern struct gdbarch *get_type_arch (const struct type *);
 
+/* This returns the target type (or NULL) of TYPE, also skipping
+   past typedefs.  */
+extern struct type *get_target_type (struct type *type);
+
 /* Helper function to construct objfile-owned types.  */
 extern struct type *init_type (enum type_code, int, int, const char *,
 			       struct objfile *);
diff --git a/gdb/jv-varobj.c b/gdb/jv-varobj.c
new file mode 100644
index 0000000..e70aa28
--- /dev/null
+++ b/gdb/jv-varobj.c
@@ -0,0 +1,105 @@
+/* varobj support for Java.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "varobj.h"
+
+/* Java */
+
+static int
+java_number_of_children (struct varobj *var)
+{
+  return cplus_varobj_ops.number_of_children (var);
+}
+
+static char *
+java_name_of_variable (struct varobj *parent)
+{
+  char *p, *name;
+
+  name = cplus_varobj_ops.name_of_variable (parent);
+  /* If  the name has "-" in it, it is because we
+     needed to escape periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '-')
+	*p = '.';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_name_of_child (struct varobj *parent, int index)
+{
+  char *name, *p;
+
+  name = cplus_varobj_ops.name_of_child (parent, index);
+  /* Escape any periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '.')
+	*p = '-';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_path_expr_of_child (struct varobj *child)
+{
+  return NULL;
+}
+
+static struct value *
+java_value_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.value_of_child (parent, index);
+}
+
+static struct type *
+java_type_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.type_of_child (parent, index);
+}
+
+static char *
+java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  return cplus_varobj_ops.value_of_variable (var, format);
+}
+
+/* varobj operations for java.  */
+
+const struct lang_varobj_ops java_varobj_ops =
+{
+   java_number_of_children,
+   java_name_of_variable,
+   java_name_of_child,
+   java_path_expr_of_child,
+   java_value_of_child,
+   java_type_of_child,
+   java_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
diff --git a/gdb/varobj.c b/gdb/varobj.c
index b3ba56b..a215358 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -33,8 +33,6 @@
 #include "vec.h"
 #include "gdbthread.h"
 #include "inferior.h"
-#include "ada-varobj.h"
-#include "ada-lang.h"
 
 #if HAVE_PYTHON
 #include "python/python.h"
@@ -43,10 +41,6 @@
 typedef int PyObject;
 #endif
 
-/* The names of varobjs representing anonymous structs or unions.  */
-#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
-#define ANONYMOUS_UNION_NAME _("<anonymous union>")
-
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
 unsigned int varobjdebug = 0;
@@ -106,8 +100,9 @@ struct varobj_root
      to symbols that do not exist anymore.  */
   int is_valid;
 
-  /* Language info for this variable and its children.  */
-  struct language_specific *lang;
+  /* Language-related operations for this variable and its
+     children.  */
+  struct lang_varobj_ops *lang;
 
   /* The varobj for this root node.  */
   struct varobj *rootvar;
@@ -190,12 +185,6 @@ static void free_variable (struct varobj *var);
 
 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
 
-static struct type *get_type (struct varobj *var);
-
-static struct type *get_value_type (struct varobj *var);
-
-static struct type *get_target_type (struct type *);
-
 static enum varobj_display_formats variable_default_display (struct varobj *);
 
 static void cppush (struct cpstack **pstack, char *name);
@@ -225,12 +214,6 @@ static struct value *value_of_child (struct varobj *parent, int index);
 static char *my_value_of_variable (struct varobj *var,
 				   enum varobj_display_formats format);
 
-static char *value_get_print_value (struct value *value,
-				    enum varobj_display_formats format,
-				    struct varobj *var);
-
-static int varobj_value_is_changeable_p (struct varobj *var);
-
 static int is_root_p (struct varobj *var);
 
 #if HAVE_PYTHON
@@ -241,190 +224,12 @@ static struct varobj *varobj_add_child (struct varobj *var,
 
 #endif /* HAVE_PYTHON */
 
-static int default_value_is_changeable_p (struct varobj *var);
-
-/* C implementation */
-
-static int c_number_of_children (struct varobj *var);
-
-static char *c_name_of_variable (struct varobj *parent);
-
-static char *c_name_of_child (struct varobj *parent, int index);
-
-static char *c_path_expr_of_child (struct varobj *child);
-
-static struct value *c_value_of_child (struct varobj *parent, int index);
-
-static struct type *c_type_of_child (struct varobj *parent, int index);
-
-static char *c_value_of_variable (struct varobj *var,
-				  enum varobj_display_formats format);
-
-/* C++ implementation */
-
-static int cplus_number_of_children (struct varobj *var);
-
-static void cplus_class_num_children (struct type *type, int children[3]);
-
-static char *cplus_name_of_variable (struct varobj *parent);
-
-static char *cplus_name_of_child (struct varobj *parent, int index);
-
-static char *cplus_path_expr_of_child (struct varobj *child);
-
-static struct value *cplus_value_of_child (struct varobj *parent, int index);
-
-static struct type *cplus_type_of_child (struct varobj *parent, int index);
-
-static char *cplus_value_of_variable (struct varobj *var,
-				      enum varobj_display_formats format);
-
-/* Java implementation */
-
-static int java_number_of_children (struct varobj *var);
-
-static char *java_name_of_variable (struct varobj *parent);
-
-static char *java_name_of_child (struct varobj *parent, int index);
-
-static char *java_path_expr_of_child (struct varobj *child);
-
-static struct value *java_value_of_child (struct varobj *parent, int index);
-
-static struct type *java_type_of_child (struct varobj *parent, int index);
-
-static char *java_value_of_variable (struct varobj *var,
-				     enum varobj_display_formats format);
-
-/* Ada implementation */
-
-static int ada_number_of_children (struct varobj *var);
-
-static char *ada_name_of_variable (struct varobj *parent);
-
-static char *ada_name_of_child (struct varobj *parent, int index);
-
-static char *ada_path_expr_of_child (struct varobj *child);
-
-static struct value *ada_value_of_child (struct varobj *parent, int index);
-
-static struct type *ada_type_of_child (struct varobj *parent, int index);
-
-static char *ada_value_of_variable (struct varobj *var,
-				    enum varobj_display_formats format);
-
-static int ada_value_is_changeable_p (struct varobj *var);
-
-static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
-				  struct type *new_type);
-
-/* The language specific vector */
-
-struct language_specific
-{
-  /* The number of children of PARENT.  */
-  int (*number_of_children) (struct varobj * parent);
-
-  /* The name (expression) of a root varobj.  */
-  char *(*name_of_variable) (struct varobj * parent);
-
-  /* The name of the INDEX'th child of PARENT.  */
-  char *(*name_of_child) (struct varobj * parent, int index);
-
-  /* Returns the rooted expression of CHILD, which is a variable
-     obtain that has some parent.  */
-  char *(*path_expr_of_child) (struct varobj * child);
-
-  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
-  struct value *(*value_of_child) (struct varobj * parent, int index);
-
-  /* The type of the INDEX'th child of PARENT.  */
-  struct type *(*type_of_child) (struct varobj * parent, int index);
-
-  /* The current value of VAR.  */
-  char *(*value_of_variable) (struct varobj * var,
-			      enum varobj_display_formats format);
-
-  /* Return non-zero if changes in value of VAR must be detected and
-     reported by -var-update.  Return zero if -var-update should never
-     report changes of such values.  This makes sense for structures
-     (since the changes in children values will be reported separately),
-     or for artifical objects (like 'public' pseudo-field in C++).
-
-     Return value of 0 means that gdb need not call value_fetch_lazy
-     for the value of this variable object.  */
-  int (*value_is_changeable_p) (struct varobj *var);
-
-  /* Return nonzero if the type of VAR has mutated.
-
-     VAR's value is still the varobj's previous value, while NEW_VALUE
-     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
-     may be NULL indicating that there is no value available (the varobj
-     may be out of scope, of may be the child of a null pointer, for
-     instance).  NEW_TYPE, on the other hand, must never be NULL.
-
-     This function should also be able to assume that var's number of
-     children is set (not < 0).
-
-     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);
-};
-
 /* Array of known source language routines.  */
-static struct language_specific languages[vlang_end] = {
-  /* C */
-  {
-   c_number_of_children,
-   c_name_of_variable,
-   c_name_of_child,
-   c_path_expr_of_child,
-   c_value_of_child,
-   c_type_of_child,
-   c_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* C++ */
-  {
-   cplus_number_of_children,
-   cplus_name_of_variable,
-   cplus_name_of_child,
-   cplus_path_expr_of_child,
-   cplus_value_of_child,
-   cplus_type_of_child,
-   cplus_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* Java */
-  {
-   java_number_of_children,
-   java_name_of_variable,
-   java_name_of_child,
-   java_path_expr_of_child,
-   java_value_of_child,
-   java_type_of_child,
-   java_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */},
-  /* Ada */
-  {
-   ada_number_of_children,
-   ada_name_of_variable,
-   ada_name_of_child,
-   ada_path_expr_of_child,
-   ada_value_of_child,
-   ada_type_of_child,
-   ada_value_of_variable,
-   ada_value_is_changeable_p,
-   ada_value_has_mutated}
-};
-
-/* A little convenience enum for dealing with C++/Java.  */
-enum vsections
-{
-  v_public = 0, v_private, v_protected
+static const struct lang_varobj_ops *languages[vlang_end] = {
+  &c_varobj_ops,
+  &cplus_varobj_ops,
+  &java_varobj_ops,
+  &ada_varobj_ops,
 };
 
 /* Private data */
@@ -442,9 +247,6 @@ static struct varobj_root *rootlist;
 /* Pointer to the varobj hash table (built at run time).  */
 static struct vlist **varobj_table;
 
-/* Is the variable X one of our "fake" children?  */
-#define CPLUS_FAKE_CHILD(x) \
-((x) != NULL && (x)->type == NULL && (x)->value == NULL)
 \f
 
 /* API Implementation */
@@ -632,7 +434,7 @@ varobj_create (char *objname,
 
       /* Set language info */
       lang = variable_language (var);
-      var->root->lang = &languages[lang];
+      var->root->lang = (struct lang_varobj_ops *) languages[lang];
 
       install_new_value (var, value, 1 /* Initial assignment */);
 
@@ -812,7 +614,8 @@ varobj_set_display_format (struct varobj *var,
       && var->value && !value_lazy (var->value))
     {
       xfree (var->print_value);
-      var->print_value = value_get_print_value (var->value, var->format, var);
+      var->print_value = varobj_value_get_print_value (var->value,
+						       var->format, var);
     }
 
   return var->format;
@@ -894,8 +697,8 @@ varobj_get_frozen (struct varobj *var)
    of FROM and TO -- if either is negative, the entire range is
    used.  */
 
-static void
-restrict_range (VEC (varobj_p) *children, int *from, int *to)
+void
+varobj_restrict_range (VEC (varobj_p) *children, int *from, int *to)
 {
   if (*from < 0 || *to < 0)
     {
@@ -1202,7 +1005,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	 varobj twice is not something a sane frontend would do.  */
       update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL,
 				      &children_changed, 0, 0, *to);
-      restrict_range (var->children, from, to);
+      varobj_restrict_range (var->children, from, to);
       return var->children;
     }
 
@@ -1233,7 +1036,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	}
     }
 
-  restrict_range (var->children, from, to);
+  varobj_restrict_range (var->children, from, to);
   return var->children;
 }
 
@@ -1287,7 +1090,7 @@ is_path_expr_parent (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   /* Anonymous unions and structs are also not path_expr parents.  */
   return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
@@ -1297,8 +1100,8 @@ is_path_expr_parent (struct varobj *var)
 
 /* Return the path expression parent for VAR.  */
 
-static struct varobj *
-get_path_expr_parent (struct varobj *var)
+struct varobj *
+varobj_get_path_expr_parent (struct varobj *var)
 {
   struct varobj *parent = var;
 
@@ -1692,7 +1495,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      should not be fetched.  */
   if (value != NULL && !value_lazy (value)
       && var->dynamic->pretty_printer == NULL)
-    print_value = value_get_print_value (value, var->format, var);
+    print_value = varobj_value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
      If this is the initial assignment, we don't have any old value
@@ -1766,7 +1569,8 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   if (var->dynamic->pretty_printer != NULL)
     {
       xfree (print_value);
-      print_value = value_get_print_value (var->value, var->format, var);
+      print_value = varobj_value_get_print_value (var->value, var->format,
+						  var);
       if ((var->print_value == NULL && print_value != NULL)
 	  || (var->print_value != NULL && print_value == NULL)
 	  || (var->print_value != NULL && print_value != NULL
@@ -2313,20 +2117,6 @@ create_child (struct varobj *parent, int index, char *name)
 				  value_of_child (parent, index));
 }
 
-/* Does CHILD represent a child with no name?  This happens when
-   the child is an anonmous struct or union and it has no field name
-   in its parent variable.
-
-   This has already been determined by *_describe_child. The easiest
-   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
-
-static int
-is_anonymous_child (struct varobj *child)
-{
-  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
-	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
-}
-
 static struct varobj *
 create_child_with_value (struct varobj *parent, int index, char *name,
 			 struct value *value)
@@ -2342,7 +2132,7 @@ create_child_with_value (struct varobj *parent, int index, char *name,
   child->parent = parent;
   child->root = parent->root;
 
-  if (is_anonymous_child (child))
+  if (varobj_is_anonymous_child (child))
     childs_name = xstrprintf ("%s.%d_anonymous", parent->obj_name, index);
   else
     childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
@@ -2469,23 +2259,6 @@ make_cleanup_free_variable (struct varobj *var)
   return make_cleanup (do_free_variable_cleanup, var);
 }
 
-/* This returns the type of the variable.  It also skips past typedefs
-   to return the real type of the variable.
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_type (struct varobj *var)
-{
-  struct type *type;
-
-  type = var->type;
-  if (type != NULL)
-    type = check_typedef (type);
-
-  return type;
-}
-
 /* Return the type of the value that's stored in VAR,
    or that would have being stored there if the
    value were accessible.
@@ -2497,8 +2270,8 @@ get_type (struct varobj *var)
    the values and for comparing previous and new values.
 
    For example, top-level references are always stripped.  */
-static struct type *
-get_value_type (struct varobj *var)
+struct type *
+varobj_get_value_type (struct varobj *var)
 {
   struct type *type;
 
@@ -2517,24 +2290,6 @@ get_value_type (struct varobj *var)
   return type;
 }
 
-/* This returns the target type (or NULL) of TYPE, also skipping
-   past typedefs, just like get_type ().
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_target_type (struct type *type)
-{
-  if (type != NULL)
-    {
-      type = TYPE_TARGET_TYPE (type);
-      if (type != NULL)
-	type = check_typedef (type);
-    }
-
-  return type;
-}
-
 /* What is the default display for this variable? We assume that
    everything is "natural".  Any exceptions?  */
 static enum varobj_display_formats
@@ -2828,16 +2583,26 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
   if (var->root->is_valid)
     {
       if (var->dynamic->pretty_printer != NULL)
-	return value_get_print_value (var->value, var->format, var);
+	return varobj_value_get_print_value (var->value, var->format, var);
       return (*var->root->lang->value_of_variable) (var, format);
     }
   else
     return NULL;
 }
 
-static char *
-value_get_print_value (struct value *value, enum varobj_display_formats format,
-		       struct varobj *var)
+void
+varobj_formatted_print_options (struct value_print_options *opts,
+				enum varobj_display_formats format)
+{
+  get_formatted_print_options (opts, format_code[(int) format]);
+  opts->deref_ref = 0;
+  opts->raw = 1;
+}
+
+char *
+varobj_value_get_print_value (struct value *value,
+			      enum varobj_display_formats format,
+			      struct varobj *var)
 {
   struct ui_file *stb;
   struct cleanup *old_chain;
@@ -2948,9 +2713,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
     }
 #endif
 
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
+  varobj_formatted_print_options (&opts, format);
 
   /* If the THEVALUE has contents, it is a regular string.  */
   if (thevalue)
@@ -2977,7 +2740,7 @@ varobj_editable_p (struct varobj *var)
   if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -2997,7 +2760,7 @@ varobj_editable_p (struct varobj *var)
 
 /* Call VAR's value_is_changeable_p language-specific callback.  */
 
-static int
+int
 varobj_value_is_changeable_p (struct varobj *var)
 {
   return var->root->lang->value_is_changeable_p (var);
@@ -3012,95 +2775,11 @@ varobj_floating_p (struct varobj *var)
   return var->root->floating;
 }
 
-/* Given the value and the type of a variable object,
-   adjust the value and type to those necessary
-   for getting children of the variable object.
-   This includes dereferencing top-level references
-   to all types and dereferencing pointers to
-   structures.
-
-   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
-   value will be fetched and if it differs from static type
-   the value will be casted to it.
-
-   Both TYPE and *TYPE should be non-null.  VALUE
-   can be null if we want to only translate type.
-   *VALUE can be null as well -- if the parent
-   value is not known.
-
-   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
-   depending on whether pointer was dereferenced
-   in this function.  */
-static void
-adjust_value_for_child_access (struct value **value,
-				  struct type **type,
-				  int *was_ptr,
-				  int lookup_actual_type)
-{
-  gdb_assert (type && *type);
-
-  if (was_ptr)
-    *was_ptr = 0;
-
-  *type = check_typedef (*type);
-  
-  /* The type of value stored in varobj, that is passed
-     to us, is already supposed to be
-     reference-stripped.  */
-
-  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
-
-  /* Pointers to structures are treated just like
-     structures when accessing children.  Don't
-     dererences pointers to other types.  */
-  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
-    {
-      struct type *target_type = get_target_type (*type);
-      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
-	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
-	{
-	  if (value && *value)
-	    {
-	      volatile struct gdb_exception except;
-
-	      TRY_CATCH (except, RETURN_MASK_ERROR)
-		{
-		  *value = value_ind (*value);
-		}
-
-	      if (except.reason < 0)
-		*value = NULL;
-	    }
-	  *type = target_type;
-	  if (was_ptr)
-	    *was_ptr = 1;
-	}
-    }
-
-  /* The 'get_target_type' function calls check_typedef on
-     result, so we can immediately check type code.  No
-     need to call check_typedef here.  */
-
-  /* Access a real type of the value (if necessary and possible).  */
-  if (value && *value && lookup_actual_type)
-    {
-      struct type *enclosing_type;
-      int real_type_found = 0;
-
-      enclosing_type = value_actual_type (*value, 1, &real_type_found);
-      if (real_type_found)
-        {
-          *type = enclosing_type;
-          *value = value_cast (enclosing_type, *value);
-        }
-    }
-}
-
 /* Implement the "value_is_changeable_p" varobj callback for most
    languages.  */
 
-static int
-default_value_is_changeable_p (struct varobj *var)
+int
+varobj_default_value_is_changeable_p (struct varobj *var)
 {
   int r;
   struct type *type;
@@ -3108,7 +2787,7 @@ default_value_is_changeable_p (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -3125,925 +2804,6 @@ default_value_is_changeable_p (struct varobj *var)
   return r;
 }
 
-/* C */
-
-static int
-c_number_of_children (struct varobj *var)
-{
-  struct type *type = get_value_type (var);
-  int children = 0;
-  struct type *target;
-
-  adjust_value_for_child_access (NULL, &type, NULL, 0);
-  target = get_target_type (type);
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
-	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
-      else
-	/* If we don't know how many elements there are, don't display
-	   any.  */
-	children = 0;
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      children = TYPE_NFIELDS (type);
-      break;
-
-    case TYPE_CODE_PTR:
-      /* The type here is a pointer to non-struct.  Typically, pointers
-	 have one child, except for function ptrs, which have no children,
-	 and except for void*, as we don't know what to show.
-
-         We can show char* so we allow it to be dereferenced.  If you decide
-         to test for it, please mind that a little magic is necessary to
-         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
-         TYPE_NAME == "char".  */
-      if (TYPE_CODE (target) == TYPE_CODE_FUNC
-	  || TYPE_CODE (target) == TYPE_CODE_VOID)
-	children = 0;
-      else
-	children = 1;
-      break;
-
-    default:
-      /* Other types have no children.  */
-      break;
-    }
-
-  return children;
-}
-
-static char *
-c_name_of_variable (struct varobj *parent)
-{
-  return xstrdup (parent->name);
-}
-
-/* Return the value of element TYPE_INDEX of a structure
-   value VALUE.  VALUE's type should be a structure,
-   or union, or a typedef to struct/union.
-
-   Returns NULL if getting the value fails.  Never throws.  */
-static struct value *
-value_struct_element_index (struct value *value, int type_index)
-{
-  struct value *result = NULL;
-  volatile struct gdb_exception e;
-  struct type *type = value_type (value);
-
-  type = check_typedef (type);
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
-	      || TYPE_CODE (type) == TYPE_CODE_UNION);
-
-  TRY_CATCH (e, RETURN_MASK_ERROR)
-    {
-      if (field_is_static (&TYPE_FIELD (type, type_index)))
-	result = value_static_field (type, type_index);
-      else
-	result = value_primitive_field (value, 0, type_index, type);
-    }
-  if (e.reason < 0)
-    {
-      return NULL;
-    }
-  else
-    {
-      return result;
-    }
-}
-
-/* Obtain the information about child INDEX of the variable
-   object PARENT.
-   If CNAME is not null, sets *CNAME to the name of the child relative
-   to the parent.
-   If CVALUE is not null, sets *CVALUE to the value of the child.
-   If CTYPE is not null, sets *CTYPE to the type of the child.
-
-   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
-   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
-   to NULL.  */
-static void 
-c_describe_child (struct varobj *parent, int index,
-		  char **cname, struct value **cvalue, struct type **ctype,
-		  char **cfull_expression)
-{
-  struct value *value = parent->value;
-  struct type *type = get_value_type (parent);
-  char *parent_expression = NULL;
-  int was_ptr;
-  volatile struct gdb_exception except;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    {
-      *cfull_expression = NULL;
-      parent_expression = varobj_get_path_expr (get_path_expr_parent (parent));
-    }
-  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
-      
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (cname)
-	*cname
-	  = xstrdup (int_string (index 
-				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				 10, 1, 0, 0));
-
-      if (cvalue && value)
-	{
-	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
-
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_subscript (value, real_index);
-	    }
-	}
-
-      if (ctype)
-	*ctype = get_target_type (type);
-
-      if (cfull_expression)
-	*cfull_expression = 
-	  xstrprintf ("(%s)[%s]", parent_expression, 
-		      int_string (index
-				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				  10, 1, 0, 0));
-
-
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      {
-	const char *field_name;
-
-	/* If the type is anonymous and the field has no name,
-	   set an appropriate name.  */
-	field_name = TYPE_FIELD_NAME (type, index);
-	if (field_name == NULL || *field_name == '\0')
-	  {
-	    if (cname)
-	      {
-		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
-		    == TYPE_CODE_STRUCT)
-		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		else
-		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
-	      }
-
-	    if (cfull_expression)
-	      *cfull_expression = xstrdup ("");
-	  }
-	else
-	  {
-	    if (cname)
-	      *cname = xstrdup (field_name);
-
-	    if (cfull_expression)
-	      {
-		char *join = was_ptr ? "->" : ".";
-
-		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
-						join, field_name);
-	      }
-	  }
-
-	if (cvalue && value)
-	  {
-	    /* For C, varobj index is the same as type index.  */
-	    *cvalue = value_struct_element_index (value, index);
-	  }
-
-	if (ctype)
-	  *ctype = TYPE_FIELD_TYPE (type, index);
-      }
-      break;
-
-    case TYPE_CODE_PTR:
-      if (cname)
-	*cname = xstrprintf ("*%s", parent->name);
-
-      if (cvalue && value)
-	{
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_ind (value);
-	    }
-
-	  if (except.reason < 0)
-	    *cvalue = NULL;
-	}
-
-      /* Don't use get_target_type because it calls
-	 check_typedef and here, we want to show the true
-	 declared type of the variable.  */
-      if (ctype)
-	*ctype = TYPE_TARGET_TYPE (type);
-
-      if (cfull_expression)
-	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
-      
-      break;
-
-    default:
-      /* This should not happen.  */
-      if (cname)
-	*cname = xstrdup ("???");
-      if (cfull_expression)
-	*cfull_expression = xstrdup ("???");
-      /* Don't set value and type, we don't know then.  */
-    }
-}
-
-static char *
-c_name_of_child (struct varobj *parent, int index)
-{
-  char *name;
-
-  c_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-c_path_expr_of_child (struct varobj *child)
-{
-  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-		    &child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-c_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  c_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-c_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  c_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  /* BOGUS: if val_print sees a struct/class, or a reference to one,
-     it will print out its children instead of "{...}".  So we need to
-     catch that case explicitly.  */
-  struct type *type = get_type (var);
-
-  /* Strip top-level references.  */
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
-    type = check_typedef (TYPE_TARGET_TYPE (type));
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      return xstrdup ("{...}");
-      /* break; */
-
-    case TYPE_CODE_ARRAY:
-      {
-	char *number;
-
-	number = xstrprintf ("[%d]", var->num_children);
-	return (number);
-      }
-      /* break; */
-
-    default:
-      {
-	if (var->value == NULL)
-	  {
-	    /* This can happen if we attempt to get the value of a struct
-	       member when the parent is an invalid pointer.  This is an
-	       error condition, so we should tell the caller.  */
-	    return NULL;
-	  }
-	else
-	  {
-	    if (var->not_fetched && value_lazy (var->value))
-	      /* Frozen variable and no value yet.  We don't
-		 implicitly fetch the value.  MI response will
-		 use empty string for the value, which is OK.  */
-	      return NULL;
-
-	    gdb_assert (varobj_value_is_changeable_p (var));
-	    gdb_assert (!value_lazy (var->value));
-	    
-	    /* If the specified format is the current one,
-	       we can reuse print_value.  */
-	    if (format == var->format)
-	      return xstrdup (var->print_value);
-	    else
-	      return value_get_print_value (var->value, format, var);
-	  }
-      }
-    }
-}
-\f
-
-/* C++ */
-
-static int
-cplus_number_of_children (struct varobj *var)
-{
-  struct value *value = NULL;
-  struct type *type;
-  int children, dont_know;
-  int lookup_actual_type = 0;
-  struct value_print_options opts;
-
-  dont_know = 1;
-  children = 0;
-
-  get_user_print_options (&opts);
-
-  if (!CPLUS_FAKE_CHILD (var))
-    {
-      type = get_value_type (var);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-          value = var->value;
-          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
-	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
-	{
-	  int kids[3];
-
-	  cplus_class_num_children (type, kids);
-	  if (kids[v_public] != 0)
-	    children++;
-	  if (kids[v_private] != 0)
-	    children++;
-	  if (kids[v_protected] != 0)
-	    children++;
-
-	  /* Add any baseclasses.  */
-	  children += TYPE_N_BASECLASSES (type);
-	  dont_know = 0;
-
-	  /* FIXME: save children in var.  */
-	}
-    }
-  else
-    {
-      int kids[3];
-
-      type = get_value_type (var->parent);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-	  struct varobj *parent = var->parent;
-
-	  value = parent->value;
-	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
-				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      cplus_class_num_children (type, kids);
-      if (strcmp (var->name, "public") == 0)
-	children = kids[v_public];
-      else if (strcmp (var->name, "private") == 0)
-	children = kids[v_private];
-      else
-	children = kids[v_protected];
-      dont_know = 0;
-    }
-
-  if (dont_know)
-    children = c_number_of_children (var);
-
-  return children;
-}
-
-/* Compute # of public, private, and protected variables in this class.
-   That means we need to descend into all baseclasses and find out
-   how many are there, too.  */
-static void
-cplus_class_num_children (struct type *type, int children[3])
-{
-  int i, vptr_fieldno;
-  struct type *basetype = NULL;
-
-  children[v_public] = 0;
-  children[v_private] = 0;
-  children[v_protected] = 0;
-
-  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
-    {
-      /* If we have a virtual table pointer, omit it.  Even if virtual
-	 table pointers are not specifically marked in the debug info,
-	 they should be artificial.  */
-      if ((type == basetype && i == vptr_fieldno)
-	  || TYPE_FIELD_ARTIFICIAL (type, i))
-	continue;
-
-      if (TYPE_FIELD_PROTECTED (type, i))
-	children[v_protected]++;
-      else if (TYPE_FIELD_PRIVATE (type, i))
-	children[v_private]++;
-      else
-	children[v_public]++;
-    }
-}
-
-static char *
-cplus_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-enum accessibility { private_field, protected_field, public_field };
-
-/* Check if field INDEX of TYPE has the specified accessibility.
-   Return 0 if so and 1 otherwise.  */
-static int 
-match_accessibility (struct type *type, int index, enum accessibility acc)
-{
-  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
-    return 1;
-  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
-	   && !TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else
-    return 0;
-}
-
-static void
-cplus_describe_child (struct varobj *parent, int index,
-		      char **cname, struct value **cvalue, struct type **ctype,
-		      char **cfull_expression)
-{
-  struct value *value;
-  struct type *type;
-  int was_ptr;
-  int lookup_actual_type = 0;
-  char *parent_expression = NULL;
-  struct varobj *var;
-  struct value_print_options opts;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    *cfull_expression = NULL;
-
-  get_user_print_options (&opts);
-
-  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
-  if (opts.objectprint)
-    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
-  value = var->value;
-  type = get_value_type (var);
-  if (cfull_expression)
-    parent_expression = varobj_get_path_expr (get_path_expr_parent (var));
-
-  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
-
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (type) == TYPE_CODE_UNION)
-    {
-      char *join = was_ptr ? "->" : ".";
-
-      if (CPLUS_FAKE_CHILD (parent))
-	{
-	  /* The fields of the class type are ordered as they
-	     appear in the class.  We are given an index for a
-	     particular access control type ("public","protected",
-	     or "private").  We must skip over fields that don't
-	     have the access control we are looking for to properly
-	     find the indexed field.  */
-	  int type_index = TYPE_N_BASECLASSES (type);
-	  enum accessibility acc = public_field;
-	  int vptr_fieldno;
-	  struct type *basetype = NULL;
-	  const char *field_name;
-
-	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-	  if (strcmp (parent->name, "private") == 0)
-	    acc = private_field;
-	  else if (strcmp (parent->name, "protected") == 0)
-	    acc = protected_field;
-
-	  while (index >= 0)
-	    {
-	      if ((type == basetype && type_index == vptr_fieldno)
-		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
-		; /* ignore vptr */
-	      else if (match_accessibility (type, type_index, acc))
-		    --index;
-		  ++type_index;
-	    }
-	  --type_index;
-
-	  /* If the type is anonymous and the field has no name,
-	     set an appopriate name.  */
-	  field_name = TYPE_FIELD_NAME (type, type_index);
-	  if (field_name == NULL || *field_name == '\0')
-	    {
-	      if (cname)
-		{
-		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-		      == TYPE_CODE_STRUCT)
-		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-			   == TYPE_CODE_UNION)
-		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
-		}
-
-	      if (cfull_expression)
-		*cfull_expression = xstrdup ("");
-	    }
-	  else
-	    {
-	      if (cname)
-		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
-
-	      if (cfull_expression)
-		*cfull_expression
-		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
-				field_name);
-	    }
-
-	  if (cvalue && value)
-	    *cvalue = value_struct_element_index (value, type_index);
-
-	  if (ctype)
-	    *ctype = TYPE_FIELD_TYPE (type, type_index);
-	}
-      else if (index < TYPE_N_BASECLASSES (type))
-	{
-	  /* This is a baseclass.  */
-	  if (cname)
-	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
-
-	  if (cvalue && value)
-	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
-
-	  if (ctype)
-	    {
-	      *ctype = TYPE_FIELD_TYPE (type, index);
-	    }
-
-	  if (cfull_expression)
-	    {
-	      char *ptr = was_ptr ? "*" : "";
-
-	      /* Cast the parent to the base' type.  Note that in gdb,
-		 expression like 
-		         (Base1)d
-		 will create an lvalue, for all appearences, so we don't
-		 need to use more fancy:
-		         *(Base1*)(&d)
-		 construct.
-
-		 When we are in the scope of the base class or of one
-		 of its children, the type field name will be interpreted
-		 as a constructor, if it exists.  Therefore, we must
-		 indicate that the name is a class name by using the
-		 'class' keyword.  See PR mi/11912  */
-	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
-					      ptr, 
-					      TYPE_FIELD_NAME (type, index),
-					      ptr,
-					      parent_expression);
-	    }
-	}
-      else
-	{
-	  char *access = NULL;
-	  int children[3];
-
-	  cplus_class_num_children (type, children);
-
-	  /* Everything beyond the baseclasses can
-	     only be "public", "private", or "protected"
-
-	     The special "fake" children are always output by varobj in
-	     this order.  So if INDEX == 2, it MUST be "protected".  */
-	  index -= TYPE_N_BASECLASSES (type);
-	  switch (index)
-	    {
-	    case 0:
-	      if (children[v_public] > 0)
-	 	access = "public";
-	      else if (children[v_private] > 0)
-	 	access = "private";
-	      else 
-	 	access = "protected";
-	      break;
-	    case 1:
-	      if (children[v_public] > 0)
-		{
-		  if (children[v_private] > 0)
-		    access = "private";
-		  else
-		    access = "protected";
-		}
-	      else if (children[v_private] > 0)
-	 	access = "protected";
-	      break;
-	    case 2:
-	      /* Must be protected.  */
-	      access = "protected";
-	      break;
-	    default:
-	      /* error!  */
-	      break;
-	    }
-
-	  gdb_assert (access);
-	  if (cname)
-	    *cname = xstrdup (access);
-
-	  /* Value and type and full expression are null here.  */
-	}
-    }
-  else
-    {
-      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
-    }  
-}
-
-static char *
-cplus_name_of_child (struct varobj *parent, int index)
-{
-  char *name = NULL;
-
-  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-cplus_path_expr_of_child (struct varobj *child)
-{
-  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-			&child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-cplus_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-cplus_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-cplus_value_of_variable (struct varobj *var, 
-			 enum varobj_display_formats format)
-{
-
-  /* If we have one of our special types, don't print out
-     any value.  */
-  if (CPLUS_FAKE_CHILD (var))
-    return xstrdup ("");
-
-  return c_value_of_variable (var, format);
-}
-\f
-/* Java */
-
-static int
-java_number_of_children (struct varobj *var)
-{
-  return cplus_number_of_children (var);
-}
-
-static char *
-java_name_of_variable (struct varobj *parent)
-{
-  char *p, *name;
-
-  name = cplus_name_of_variable (parent);
-  /* If  the name has "-" in it, it is because we
-     needed to escape periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '-')
-	*p = '.';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_name_of_child (struct varobj *parent, int index)
-{
-  char *name, *p;
-
-  name = cplus_name_of_child (parent, index);
-  /* Escape any periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '.')
-	*p = '-';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_path_expr_of_child (struct varobj *child)
-{
-  return NULL;
-}
-
-static struct value *
-java_value_of_child (struct varobj *parent, int index)
-{
-  return cplus_value_of_child (parent, index);
-}
-
-static struct type *
-java_type_of_child (struct varobj *parent, int index)
-{
-  return cplus_type_of_child (parent, index);
-}
-
-static char *
-java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  return cplus_value_of_variable (var, format);
-}
-
-/* Ada specific callbacks for VAROBJs.  */
-
-static int
-ada_number_of_children (struct varobj *var)
-{
-  return ada_varobj_get_number_of_children (var->value, var->type);
-}
-
-static char *
-ada_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-static char *
-ada_name_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_name_of_child (parent->value, parent->type,
-				       parent->name, index);
-}
-
-static char*
-ada_path_expr_of_child (struct varobj *child)
-{
-  struct varobj *parent = child->parent;
-  const char *parent_path_expr = varobj_get_path_expr (parent);
-
-  return ada_varobj_get_path_expr_of_child (parent->value,
-					    parent->type,
-					    parent->name,
-					    parent_path_expr,
-					    child->index);
-}
-
-static struct value *
-ada_value_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_value_of_child (parent->value, parent->type,
-					parent->name, index);
-}
-
-static struct type *
-ada_type_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_type_of_child (parent->value, parent->type,
-				       index);
-}
-
-static char *
-ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  struct value_print_options opts;
-
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
-
-  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
-}
-
-/* Implement the "value_is_changeable_p" routine for Ada.  */
-
-static int
-ada_value_is_changeable_p (struct varobj *var)
-{
-  struct type *type = var->value ? value_type (var->value) : var->type;
-
-  if (ada_is_array_descriptor_type (type)
-      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
-    {
-      /* This is in reality a pointer to an unconstrained array.
-	 its value is changeable.  */
-      return 1;
-    }
-
-  if (ada_is_string_type (type))
-    {
-      /* We display the contents of the string in the array's
-	 "value" field.  The contents can change, so consider
-	 that the array is changeable.  */
-      return 1;
-    }
-
-  return default_value_is_changeable_p (var);
-}
-
-/* Implement the "value_has_mutated" routine for Ada.  */
-
-static int
-ada_value_has_mutated (struct varobj *var, struct value *new_val,
-		       struct type *new_type)
-{
-  int i;
-  int from = -1;
-  int to = -1;
-
-  /* If the number of fields have changed, then for sure the type
-     has mutated.  */
-  if (ada_varobj_get_number_of_children (new_val, new_type)
-      != var->num_children)
-    return 1;
-
-  /* If the number of fields have remained the same, then we need
-     to check the name of each field.  If they remain the same,
-     then chances are the type hasn't mutated.  This is technically
-     an incomplete test, as the child's type might have changed
-     despite the fact that the name remains the same.  But we'll
-     handle this situation by saying that the child has mutated,
-     not this value.
-
-     If only part (or none!) of the children have been fetched,
-     then only check the ones we fetched.  It does not matter
-     to the frontend whether a child that it has not fetched yet
-     has mutated or not. So just assume it hasn't.  */
-
-  restrict_range (var->children, &from, &to);
-  for (i = from; i < to; i++)
-    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
-					      var->name, i),
-		VEC_index (varobj_p, var->children, i)->name) != 0)
-      return 1;
-
-  return 0;
-}
-
 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
    with an arbitrary caller supplied DATA pointer.  */
 
diff --git a/gdb/varobj.h b/gdb/varobj.h
index ea6e09b..c8ba0ad 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -167,6 +167,68 @@ struct varobj
   struct varobj_dynamic *dynamic;
 };
 
+/* Is the variable X one of our "fake" children?  */
+#define CPLUS_FAKE_CHILD(x) \
+((x) != NULL && (x)->type == NULL && (x)->value == NULL)
+
+/* The language specific vector */
+
+struct lang_varobj_ops
+{
+  /* The number of children of PARENT.  */
+  int (*number_of_children) (struct varobj * parent);
+
+  /* The name (expression) of a root varobj.  */
+  char *(*name_of_variable) (struct varobj * parent);
+
+  /* The name of the INDEX'th child of PARENT.  */
+  char *(*name_of_child) (struct varobj * parent, int index);
+
+  /* Returns the rooted expression of CHILD, which is a variable
+     obtain that has some parent.  */
+  char *(*path_expr_of_child) (struct varobj * child);
+
+  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
+  struct value *(*value_of_child) (struct varobj * parent, int index);
+
+  /* The type of the INDEX'th child of PARENT.  */
+  struct type *(*type_of_child) (struct varobj * parent, int index);
+
+  /* The current value of VAR.  */
+  char *(*value_of_variable) (struct varobj * var,
+			      enum varobj_display_formats format);
+
+  /* Return non-zero if changes in value of VAR must be detected and
+     reported by -var-update.  Return zero if -var-update should never
+     report changes of such values.  This makes sense for structures
+     (since the changes in children values will be reported separately),
+     or for artifical objects (like 'public' pseudo-field in C++).
+
+     Return value of 0 means that gdb need not call value_fetch_lazy
+     for the value of this variable object.  */
+  int (*value_is_changeable_p) (struct varobj *var);
+
+  /* Return nonzero if the type of VAR has mutated.
+
+     VAR's value is still the varobj's previous value, while NEW_VALUE
+     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
+     may be NULL indicating that there is no value available (the varobj
+     may be out of scope, of may be the child of a null pointer, for
+     instance).  NEW_TYPE, on the other hand, must never be NULL.
+
+     This function should also be able to assume that var's number of
+     children is set (not < 0).
+
+     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);
+};
+
+const struct lang_varobj_ops c_varobj_ops;
+const struct lang_varobj_ops cplus_varobj_ops;
+const struct lang_varobj_ops java_varobj_ops;
+const struct lang_varobj_ops ada_varobj_ops;
+
 /* API functions */
 
 extern struct varobj *varobj_create (char *objname,
@@ -254,4 +316,22 @@ extern int varobj_has_more (struct varobj *var, int to);
 
 extern int varobj_pretty_printed_p (struct varobj *var);
 
+extern int varobj_default_value_is_changeable_p (struct varobj *var);
+extern int varobj_value_is_changeable_p (struct varobj *var);
+
+extern struct type *varobj_get_value_type (struct varobj *var);
+
+extern int varobj_is_anonymous_child (struct varobj *child);
+
+extern struct varobj *varobj_get_path_expr_parent (struct varobj *var);
+
+extern char *varobj_value_get_print_value (struct value *value,
+					   enum varobj_display_formats format,
+					   struct varobj *var);
+
+extern void varobj_formatted_print_options (struct value_print_options *opts,
+					    enum varobj_display_formats format);
+
+extern void varobj_restrict_range (VEC (varobj_p) *children, int *from,
+				   int *to);
 #endif /* VAROBJ_H */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 4/7] Move struct varobj to varobj.h.
  2013-10-08  4:56       ` Joel Brobecker
  2013-10-08 21:03         ` Doug Evans
  2013-10-09  0:28         ` Yao Qi
@ 2013-10-14  8:19         ` Yao Qi
  2 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-14  8:19 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/08/2013 12:56 PM, Joel Brobecker wrote:
> It does look a lot better to me, FWIW.  The only possibly contentious
> question left would be making struct varobj public, when I personally
> tend to prefer opaque structures. But I'm fine with this step, as it
> helps achieve the goal of moving the language-specific stuff out of
> varobj.c. I think Doug also pretty much agreed to that change. I would
> give the patch, say, until the end of the week, JIC others want to
> comment in.
>

>> >  #if HAVE_PYTHON
>> >    if (gdb_python_initialized)
>> >      {
>> >-      PyObject *value_formatter = var->pretty_printer;
>> >+      PyObject *value_formatter=  var->dynamic->pretty_printer;
> You accidently removed a space before '='.
>

Oh, fixed.

>> >+/* Every variable in the system has a structure of this type defined
>> >+   for it.  This structure holds all information necessary to manipulate
>> >+   a particular object variable.  Members which must be freed are noted.  */
>> >+struct varobj
>> >+{
> Not sure if there is a rule for it, or not. But I tend to prefer an
> empty line between documentation and structure as well (same as with
> subprograms). Add it if you agree, or else feel free to ignore. This
> is just an arbitrary preference, AFAIK, and it really does not matter
> much to me.

I am fine to add a blank between doc and structure.  Patch is committed.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 6/7] Move language stuff out of varobj.c
  2013-10-11  8:20   ` Yao Qi
@ 2013-10-17  5:40     ` Joel Brobecker
  2013-10-17 13:33       ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-17  5:40 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Sorry for the delay in reviewing this...

> The new patch 4/7 affects this patch.  I post the updated one.  Patch
> 7/7 is not affected, so it can be reviewed too.
> 
> -- 
> Yao (齐尧)
> 
> gdb:
> 
> 2013-10-11  Yao Qi  <yao@codesourcery.com>
> 
> 	* Makefile.in (SFILES): Add c-varobj.c and jv-varobj.c.
> 	(COMMON_OBS): Add c-varobj.o and jv-varobj.o.
> 	* ada-varobj.c: Include "varobj.h".
> 	(ada_number_of_children): New.  Moved from varobj.c.
> 	(ada_name_of_variable, ada_name_of_child): Likewise.
> 	(ada_path_expr_of_child, ada_value_of_child): Likewise.
> 	(ada_type_of_child, ada_value_of_variable): Likewise.
> 	(ada_value_is_changeable_p, ada_value_has_mutated): Likewise.
> 	(ada_varobj_ops): New.
> 	* c-varobj.c, jv-varobj.c: New file.  Moved from varobj.c.
> 	* gdbtypes.c (get_target_type): New.  Moved from varobj.c.
> 	* gdbtypes.h (get_target_type): Declare.
> 	* varobj.c: Remove the inclusion of "ada-varobj.h" and
> 	"ada-lang.h".
> 	(ANONYMOUS_STRUCT_NAME): Move it to c-varobj.c.
> 	(ANONYMOUS_UNION_NAME): Likewise.
> 	(get_type, get_value_type, get_target_type): Remove declarations.
> 	(value_get_print_value, varobj_value_get_print_value): Likewise.
> 	(c_number_of_children, c_name_of_variable): Likewise.
> 	(c_name_of_child, c_path_expr_of_child): Likewise.
> 	(c_value_of_child, c_type_of_child): Likewise.
> 	(c_value_of_variable, cplus_number_of_children): Likewise.
> 	(cplus_class_num_children, cplus_name_of_variable): Likewise.
> 	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
> 	(cplus_value_of_child, cplus_type_of_child): Likewise.
> 	(cplus_value_of_variable, java_number_of_children): Likewise.
> 	(java_name_of_variable, java_name_of_child): Likewise.
> 	(java_path_expr_of_child, java_value_of_child): Likewise.
> 	(java_type_of_child, java_value_of_variable): Likewise.
> 	(ada_number_of_children, ada_name_of_variable): Likewise.
> 	(ada_name_of_child, ada_path_expr_of_child): Likewise.
> 	(ada_value_of_child, ada_type_of_child): Likewise.
> 	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
> 	(ada_value_has_mutated): Likewise.
> 	(struct language_specific): Move it to varobj.h.
> 	(CPLUS_FAKE_CHILD): Move it to varobj.h.
> 	(restrict_range): Rename it varobj_restrict_range.  Make it extern.
> 	Callers update.
> 	(get_path_expr_parent): Rename it to varobj_get_path_expr_parent.
> 	Make it extern.
> 	(is_anonymous_child): Move it to c-varobj.c and rename to
> 	varobj_is_anonymous_child.  Caller update.
> 	(get_type): Move it to c-varobj.c.
> 	(get_value_type): Rename it varobj_get_value_type.  Make it
> 	extern.
> 	(get_target_type): Move it gdbtypes.c.
> 	(varobj_formatted_print_options): New function.
> 	(value_get_print_value): Rename it to
> 	varobj_value_get_print_value and make it extern.
> 	(varobj_value_is_changeable_p): Make it extern.
> 	(adjust_value_for_child_access): Move it to c-varobj.c.
> 	(default_value_is_changeable_p): Rename it to
> 	varobj_default_value_is_changeable_p.  Make it extern.
> 	(c_number_of_children, c_name_of_variable): Move it to c-varobj.c
> 	(c_name_of_child, c_path_expr_of_child): Likewise.
> 	(c_value_of_child, c_type_of_child): Likewise.
> 	(c_value_of_variable, cplus_number_of_children): Likewise.
> 	(cplus_class_num_children, cplus_name_of_variable): Likewise.
> 	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
> 	(cplus_value_of_child, cplus_type_of_child): Likewise.
> 	(cplus_value_of_variable): Likewise.
> 	(java_number_of_children, java_name_of_variable): Move it to jv-varobj.c.
> 	(java_name_of_child, java_path_expr_of_child): Likewise.
> 	(java_value_of_child, java_type_of_child): Likewise.
> 	(java_value_of_variable): Likewise.
> 	(ada_number_of_children, ada_name_of_variable): Move it to ada-varobj.c.
> 	(ada_name_of_child, ada_path_expr_of_child): Likewise.
> 	(ada_value_of_child, ada_type_of_child): Likewise.
> 	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
> 	(ada_value_has_mutated): Likewise.
> 	* varobj.h (CPLUS_FAKE_CHILD): New macro, moved from varobj.c.
> 	(struct lang_varobj_ops): New.  Renamed by 'struct language_specific'.
> 	(c_varobj_ops, cplus_varobj_ops): Declare.
> 	(java_varobj_ops, ada_varobj_ops): Declare.
> 	(varobj_default_value_is_changeable_p): Declare.
> 	(varobj_value_is_changeable_p): Declare.
> 	(varobj_get_value_type, varobj_is_anonymous_child): Declare.
> 	(varobj_get_path_expr_parent): Declare.
> 	(varobj_value_get_print_value): Declare.
> 	(varobj_formatted_print_options): Declare.
> 	(varobj_restrict_range): Declare.

Overall, this looks pretty good to me. Just a few nits.

> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 6c809a4..4da6ca2 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -239,6 +239,22 @@ get_type_arch (const struct type *type)
>      return TYPE_OWNER (type).gdbarch;
>  }
>  
> +/* This returns the target type (or NULL) of TYPE, also skipping
> +   past typedefs.  */
> +
> +struct type *
> +get_target_type (struct type *type)

I noticed you documented this function twice, once in the header,
and ones in the body. Can you you only document it once? You have
two options: Remove the documentation in the header entirely, or
replace the documentation in the body by "See gdbtype.h" or some
such. I can't remember exactly the style that TomT introduced for
that - perhaps seem minsyms.h, IIRC.

> -  /* Language info for this variable and its children.  */
> -  struct language_specific *lang;
> +  /* Language-related operations for this variable and its
> +     children.  */
> +  struct lang_varobj_ops *lang;

Please make that field a "const". That way...

> @@ -632,7 +434,7 @@ varobj_create (char *objname,
>  
>        /* Set language info */
>        lang = variable_language (var);
> -      var->root->lang = &languages[lang];
> +      var->root->lang = (struct lang_varobj_ops *) languages[lang];

... we can get rid of the cast here.

Approved with those changes.

Thanks,
-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 7/7] Remove ada-varobj.h.
  2013-09-18 13:55 ` [PATCH 7/7] Remove ada-varobj.h Yao Qi
@ 2013-10-17  5:46   ` Joel Brobecker
  2013-10-17 13:34     ` Yao Qi
  0 siblings, 1 reply; 35+ messages in thread
From: Joel Brobecker @ 2013-10-17  5:46 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> As a result of previous patch, extern functions in ada-varobj.c can be
> made static, and ada-varobj.h can be removed too.
> 
> gdb:
> 
> 2013-09-18  Yao Qi  <yao@codesourcery.com>
> 
> 	* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
> 	* ada-varobj.c: Remove the include of ada-varobj.h.
> 	(ada_varobj_get_number_of_children): Declare.
> 	(ada_varobj_get_name_of_child): Make it static.
> 	(ada_varobj_get_path_expr_of_child): Likewise.
> 	(ada_varobj_get_value_of_child): Likewise.
> 	(ada_varobj_get_type_of_child): Likewise.
> 	(ada_varobj_get_value_of_array_variable): Likewise.
> 	* ada-varobj.h: Remove.

Thank you. OK to commit with one minor nit:

> @@ -57,6 +56,9 @@
>  
>     The results are written in place.  */
>  
> +static int ada_varobj_get_number_of_children (struct value *parent_value,
> +					      struct type *parent_type);
> +
>  static void
>  ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
>  {

That declaration needs to be inserted _before_ the comment describing
ada_varobj_decode_var.

-- 
Joel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 6/7] Move language stuff out of varobj.c
  2013-10-17  5:40     ` Joel Brobecker
@ 2013-10-17 13:33       ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-17 13:33 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/17/2013 01:40 PM, Joel Brobecker wrote:
>> +/* This returns the target type (or NULL) of TYPE, also skipping
>> >+   past typedefs.  */
>> >+
>> >+struct type *
>> >+get_target_type (struct type *type)
> I noticed you documented this function twice, once in the header,
> and ones in the body. Can you you only document it once? You have
> two options: Remove the documentation in the header entirely, or
> replace the documentation in the body by "See gdbtype.h" or some
> such. I can't remember exactly the style that TomT introduced for
> that - perhaps seem minsyms.h, IIRC.
> 

I did the latter.

>> >-  /* Language info for this variable and its children.  */
>> >-  struct language_specific *lang;
>> >+  /* Language-related operations for this variable and its
>> >+     children.  */
>> >+  struct lang_varobj_ops *lang;
> Please make that field a "const". That way...
> 
>> >@@ -632,7 +434,7 @@ varobj_create (char *objname,
>> >  
>> >        /* Set language info */
>> >        lang = variable_language (var);
>> >-      var->root->lang = &languages[lang];
>> >+      var->root->lang = (struct lang_varobj_ops *) languages[lang];
> ... we can get rid of the cast here.
> 

Fixed.

> Approved with those changes.

Patch is committed.

-- 
Yao (齐尧)

gdb:

2013-10-17  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add c-varobj.c and jv-varobj.c.
	(COMMON_OBS): Add c-varobj.o and jv-varobj.o.
	* ada-varobj.c: Include "lang-varobj.h".
	(ada_number_of_children): New.  Moved from varobj.c.
	(ada_name_of_variable, ada_name_of_child): Likewise.
	(ada_path_expr_of_child, ada_value_of_child): Likewise.
	(ada_type_of_child, ada_value_of_variable): Likewise.
	(ada_value_is_changeable_p, ada_value_has_mutated): Likewise.
	(ada_varobj_ops): New.
	* c-varobj.c, jv-varobj.c: New file.  Moved from varobj.c.
	* gdbtypes.c (get_target_type): New.  Moved from varobj.c.
	* gdbtypes.h (get_target_type): Declare.
	* lang-varobj.h (c_varobj_ops, cplus_varobj_ops): Declare.
	(java_varobj_ops, ada_varobj_ops): Declare.
	* varobj.c: Remove the inclusion of "ada-varobj.h" and
	"ada-lang.h".
	(ANONYMOUS_STRUCT_NAME): Move it to c-varobj.c.
	(ANONYMOUS_UNION_NAME): Likewise.
	(get_type, get_value_type, get_target_type): Remove declarations.
	(value_get_print_value, varobj_value_get_print_value): Likewise.
	(c_number_of_children, c_name_of_variable): Likewise.
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable, java_number_of_children): Likewise.
	(java_name_of_variable, java_name_of_child): Likewise.
	(java_path_expr_of_child, java_value_of_child): Likewise.
	(java_type_of_child, java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Likewise.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	(struct language_specific): Move it to varobj.h.
	(CPLUS_FAKE_CHILD): Move it to varobj.h.
	(restrict_range): Rename it varobj_restrict_range.  Make it extern.
	Callers update.
	(get_path_expr_parent): Rename it to varobj_get_path_expr_parent.
	Make it extern.
	(is_anonymous_child): Move it to c-varobj.c and rename to
	varobj_is_anonymous_child.  Caller update.
	(get_type): Move it to c-varobj.c.
	(get_value_type): Rename it varobj_get_value_type.  Make it
	extern.
	(get_target_type): Move it gdbtypes.c.
	(varobj_formatted_print_options): New function.
	(value_get_print_value): Rename it to
	varobj_value_get_print_value and make it extern.
	(varobj_value_is_changeable_p): Make it extern.
	(adjust_value_for_child_access): Move it to c-varobj.c.
	(default_value_is_changeable_p): Rename it to
	varobj_default_value_is_changeable_p.  Make it extern.
	(c_number_of_children, c_name_of_variable): Move it to c-varobj.c
	(c_name_of_child, c_path_expr_of_child): Likewise.
	(c_value_of_child, c_type_of_child): Likewise.
	(c_value_of_variable, cplus_number_of_children): Likewise.
	(cplus_class_num_children, cplus_name_of_variable): Likewise.
	(cplus_name_of_child, cplus_path_expr_of_child): Likewise.
	(cplus_value_of_child, cplus_type_of_child): Likewise.
	(cplus_value_of_variable): Likewise.
	(java_number_of_children, java_name_of_variable): Move it to jv-varobj.c.
	(java_name_of_child, java_path_expr_of_child): Likewise.
	(java_value_of_child, java_type_of_child): Likewise.
	(java_value_of_variable): Likewise.
	(ada_number_of_children, ada_name_of_variable): Move it to ada-varobj.c.
	(ada_name_of_child, ada_path_expr_of_child): Likewise.
	(ada_value_of_child, ada_type_of_child): Likewise.
	(ada_value_of_variable, ada_value_is_changeable_p): Likewise.
	(ada_value_has_mutated): Likewise.
	* varobj.h (CPLUS_FAKE_CHILD): New macro, moved from varobj.c.
	(struct lang_varobj_ops): New.  Renamed by 'struct language_specific'.
	(varobj_default_value_is_changeable_p): Declare.
	(varobj_value_is_changeable_p): Declare.
	(varobj_get_value_type, varobj_is_anonymous_child): Declare.
	(varobj_get_path_expr_parent): Declare.
	(varobj_value_get_print_value): Declare.
	(varobj_formatted_print_options): Declare.
	(varobj_restrict_range): Declare.
---
 gdb/Makefile.in  |    8 +-
 gdb/ada-varobj.c |  137 ++++++
 gdb/c-varobj.c   |  910 +++++++++++++++++++++++++++++++++++++
 gdb/gdbtypes.c   |   15 +
 gdb/gdbtypes.h   |    4 +
 gdb/jv-varobj.c  |  105 +++++
 gdb/varobj.c     | 1328 ++----------------------------------------------------
 gdb/varobj.h     |   80 ++++
 8 files changed, 1299 insertions(+), 1288 deletions(-)
 create mode 100644 gdb/c-varobj.c
 create mode 100644 gdb/jv-varobj.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f13e5c6..f8abb35 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -721,7 +721,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	block.c blockframe.c \
 	breakpoint.c break-catch-sig.c break-catch-throw.c \
 	build-id.c buildsym.c \
-	c-exp.y c-lang.c c-typeprint.c c-valprint.c \
+	c-exp.y c-lang.c c-typeprint.c c-valprint.c c-varobj.c \
 	charset.c cleanups.c cli-out.c coffread.c coff-pe-read.c \
 	complaints.c completer.c continuations.c corefile.c corelow.c \
 	cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \
@@ -742,7 +742,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	infcmd.c inflow.c infrun.c \
 	inline-frame.c \
 	interps.c \
-	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c \
+	jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c jv-varobj.c \
 	language.c linespec.c minidebug.c \
 	m2-exp.y m2-lang.c m2-typeprint.c m2-valprint.c \
 	macrotab.c macroexp.c macrocmd.c macroscope.c main.c maint.c \
@@ -926,11 +926,11 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	dwarf2read.o mipsread.o stabsread.o corefile.o \
 	dwarf2expr.o dwarf2loc.o dwarf2-frame.o dwarf2-frame-tailcall.o \
 	ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \
-	ada-tasks.o ada-varobj.o \
+	ada-tasks.o ada-varobj.o c-varobj.o \
 	ui-out.o cli-out.o \
 	varobj.o vec.o \
 	go-lang.o go-valprint.o go-typeprint.o \
-	jv-lang.o jv-valprint.o jv-typeprint.o \
+	jv-lang.o jv-valprint.o jv-typeprint.o jv-varobj.o \
 	m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 53d8a9c..52c7687 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -20,6 +20,7 @@
 #include "defs.h"
 #include "ada-varobj.h"
 #include "ada-lang.h"
+#include "varobj.h"
 #include "language.h"
 #include "valprint.h"
 
@@ -885,4 +886,140 @@ ada_varobj_get_value_of_variable (struct value *value,
   return result;
 }
 
+/* Ada specific callbacks for VAROBJs.  */
 
+static int
+ada_number_of_children (struct varobj *var)
+{
+  return ada_varobj_get_number_of_children (var->value, var->type);
+}
+
+static char *
+ada_name_of_variable (struct varobj *parent)
+{
+  return c_varobj_ops.name_of_variable (parent);
+}
+
+static char *
+ada_name_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_name_of_child (parent->value, parent->type,
+				       parent->name, index);
+}
+
+static char*
+ada_path_expr_of_child (struct varobj *child)
+{
+  struct varobj *parent = child->parent;
+  const char *parent_path_expr = varobj_get_path_expr (parent);
+
+  return ada_varobj_get_path_expr_of_child (parent->value,
+					    parent->type,
+					    parent->name,
+					    parent_path_expr,
+					    child->index);
+}
+
+static struct value *
+ada_value_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_value_of_child (parent->value, parent->type,
+					parent->name, index);
+}
+
+static struct type *
+ada_type_of_child (struct varobj *parent, int index)
+{
+  return ada_varobj_get_type_of_child (parent->value, parent->type,
+				       index);
+}
+
+static char *
+ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  struct value_print_options opts;
+
+  varobj_formatted_print_options (&opts, format);
+
+  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
+}
+
+/* Implement the "value_is_changeable_p" routine for Ada.  */
+
+static int
+ada_value_is_changeable_p (struct varobj *var)
+{
+  struct type *type = var->value ? value_type (var->value) : var->type;
+
+  if (ada_is_array_descriptor_type (type)
+      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+    {
+      /* This is in reality a pointer to an unconstrained array.
+	 its value is changeable.  */
+      return 1;
+    }
+
+  if (ada_is_string_type (type))
+    {
+      /* We display the contents of the string in the array's
+	 "value" field.  The contents can change, so consider
+	 that the array is changeable.  */
+      return 1;
+    }
+
+  return varobj_default_value_is_changeable_p (var);
+}
+
+/* Implement the "value_has_mutated" routine for Ada.  */
+
+static int
+ada_value_has_mutated (struct varobj *var, struct value *new_val,
+		       struct type *new_type)
+{
+  int i;
+  int from = -1;
+  int to = -1;
+
+  /* If the number of fields have changed, then for sure the type
+     has mutated.  */
+  if (ada_varobj_get_number_of_children (new_val, new_type)
+      != var->num_children)
+    return 1;
+
+  /* If the number of fields have remained the same, then we need
+     to check the name of each field.  If they remain the same,
+     then chances are the type hasn't mutated.  This is technically
+     an incomplete test, as the child's type might have changed
+     despite the fact that the name remains the same.  But we'll
+     handle this situation by saying that the child has mutated,
+     not this value.
+
+     If only part (or none!) of the children have been fetched,
+     then only check the ones we fetched.  It does not matter
+     to the frontend whether a child that it has not fetched yet
+     has mutated or not. So just assume it hasn't.  */
+
+  varobj_restrict_range (var->children, &from, &to);
+  for (i = from; i < to; i++)
+    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
+					      var->name, i),
+		VEC_index (varobj_p, var->children, i)->name) != 0)
+      return 1;
+
+  return 0;
+}
+
+/* varobj operations for ada.  */
+
+const struct lang_varobj_ops ada_varobj_ops =
+{
+  ada_number_of_children,
+  ada_name_of_variable,
+  ada_name_of_child,
+  ada_path_expr_of_child,
+  ada_value_of_child,
+  ada_type_of_child,
+  ada_value_of_variable,
+  ada_value_is_changeable_p,
+  ada_value_has_mutated
+};
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
new file mode 100644
index 0000000..73e785c
--- /dev/null
+++ b/gdb/c-varobj.c
@@ -0,0 +1,910 @@
+/* varobj support for C and C++.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "value.h"
+#include "varobj.h"
+#include "gdbthread.h"
+#include "valprint.h"
+
+static void cplus_class_num_children (struct type *type, int children[3]);
+
+/* The names of varobjs representing anonymous structs or unions.  */
+#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
+#define ANONYMOUS_UNION_NAME _("<anonymous union>")
+
+/* Does CHILD represent a child with no name?  This happens when
+   the child is an anonmous struct or union and it has no field name
+   in its parent variable.
+
+   This has already been determined by *_describe_child. The easiest
+   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
+
+int
+varobj_is_anonymous_child (struct varobj *child)
+{
+  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
+	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
+}
+
+/* Given the value and the type of a variable object,
+   adjust the value and type to those necessary
+   for getting children of the variable object.
+   This includes dereferencing top-level references
+   to all types and dereferencing pointers to
+   structures.
+
+   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
+   value will be fetched and if it differs from static type
+   the value will be casted to it.
+
+   Both TYPE and *TYPE should be non-null.  VALUE
+   can be null if we want to only translate type.
+   *VALUE can be null as well -- if the parent
+   value is not known.
+
+   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
+   depending on whether pointer was dereferenced
+   in this function.  */
+
+static void
+adjust_value_for_child_access (struct value **value,
+				  struct type **type,
+				  int *was_ptr,
+				  int lookup_actual_type)
+{
+  gdb_assert (type && *type);
+
+  if (was_ptr)
+    *was_ptr = 0;
+
+  *type = check_typedef (*type);
+  
+  /* The type of value stored in varobj, that is passed
+     to us, is already supposed to be
+     reference-stripped.  */
+
+  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
+
+  /* Pointers to structures are treated just like
+     structures when accessing children.  Don't
+     dererences pointers to other types.  */
+  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
+    {
+      struct type *target_type = get_target_type (*type);
+      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
+	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
+	{
+	  if (value && *value)
+	    {
+	      volatile struct gdb_exception except;
+
+	      TRY_CATCH (except, RETURN_MASK_ERROR)
+		{
+		  *value = value_ind (*value);
+		}
+
+	      if (except.reason < 0)
+		*value = NULL;
+	    }
+	  *type = target_type;
+	  if (was_ptr)
+	    *was_ptr = 1;
+	}
+    }
+
+  /* The 'get_target_type' function calls check_typedef on
+     result, so we can immediately check type code.  No
+     need to call check_typedef here.  */
+
+  /* Access a real type of the value (if necessary and possible).  */
+  if (value && *value && lookup_actual_type)
+    {
+      struct type *enclosing_type;
+      int real_type_found = 0;
+
+      enclosing_type = value_actual_type (*value, 1, &real_type_found);
+      if (real_type_found)
+        {
+          *type = enclosing_type;
+          *value = value_cast (enclosing_type, *value);
+        }
+    }
+}
+
+/* C */
+
+static int
+c_number_of_children (struct varobj *var)
+{
+  struct type *type = varobj_get_value_type (var);
+  int children = 0;
+  struct type *target;
+
+  adjust_value_for_child_access (NULL, &type, NULL, 0);
+  target = get_target_type (type);
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
+	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
+      else
+	/* If we don't know how many elements there are, don't display
+	   any.  */
+	children = 0;
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      children = TYPE_NFIELDS (type);
+      break;
+
+    case TYPE_CODE_PTR:
+      /* The type here is a pointer to non-struct.  Typically, pointers
+	 have one child, except for function ptrs, which have no children,
+	 and except for void*, as we don't know what to show.
+
+         We can show char* so we allow it to be dereferenced.  If you decide
+         to test for it, please mind that a little magic is necessary to
+         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
+         TYPE_NAME == "char".  */
+      if (TYPE_CODE (target) == TYPE_CODE_FUNC
+	  || TYPE_CODE (target) == TYPE_CODE_VOID)
+	children = 0;
+      else
+	children = 1;
+      break;
+
+    default:
+      /* Other types have no children.  */
+      break;
+    }
+
+  return children;
+}
+
+static char *
+c_name_of_variable (struct varobj *parent)
+{
+  return xstrdup (parent->name);
+}
+
+/* Return the value of element TYPE_INDEX of a structure
+   value VALUE.  VALUE's type should be a structure,
+   or union, or a typedef to struct/union.
+
+   Returns NULL if getting the value fails.  Never throws.  */
+
+static struct value *
+value_struct_element_index (struct value *value, int type_index)
+{
+  struct value *result = NULL;
+  volatile struct gdb_exception e;
+  struct type *type = value_type (value);
+
+  type = check_typedef (type);
+
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
+	      || TYPE_CODE (type) == TYPE_CODE_UNION);
+
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      if (field_is_static (&TYPE_FIELD (type, type_index)))
+	result = value_static_field (type, type_index);
+      else
+	result = value_primitive_field (value, 0, type_index, type);
+    }
+  if (e.reason < 0)
+    {
+      return NULL;
+    }
+  else
+    {
+      return result;
+    }
+}
+
+/* Obtain the information about child INDEX of the variable
+   object PARENT.
+   If CNAME is not null, sets *CNAME to the name of the child relative
+   to the parent.
+   If CVALUE is not null, sets *CVALUE to the value of the child.
+   If CTYPE is not null, sets *CTYPE to the type of the child.
+
+   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
+   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
+   to NULL.  */
+
+static void 
+c_describe_child (struct varobj *parent, int index,
+		  char **cname, struct value **cvalue, struct type **ctype,
+		  char **cfull_expression)
+{
+  struct value *value = parent->value;
+  struct type *type = varobj_get_value_type (parent);
+  char *parent_expression = NULL;
+  int was_ptr;
+  volatile struct gdb_exception except;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    {
+      *cfull_expression = NULL;
+      parent_expression
+	= varobj_get_path_expr (varobj_get_path_expr_parent (parent));
+    }
+  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
+      
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+      if (cname)
+	*cname
+	  = xstrdup (int_string (index 
+				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				 10, 1, 0, 0));
+
+      if (cvalue && value)
+	{
+	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
+
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_subscript (value, real_index);
+	    }
+	}
+
+      if (ctype)
+	*ctype = get_target_type (type);
+
+      if (cfull_expression)
+	*cfull_expression = 
+	  xstrprintf ("(%s)[%s]", parent_expression, 
+		      int_string (index
+				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+				  10, 1, 0, 0));
+
+
+      break;
+
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      {
+	const char *field_name;
+
+	/* If the type is anonymous and the field has no name,
+	   set an appropriate name.  */
+	field_name = TYPE_FIELD_NAME (type, index);
+	if (field_name == NULL || *field_name == '\0')
+	  {
+	    if (cname)
+	      {
+		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
+		    == TYPE_CODE_STRUCT)
+		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		else
+		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
+	      }
+
+	    if (cfull_expression)
+	      *cfull_expression = xstrdup ("");
+	  }
+	else
+	  {
+	    if (cname)
+	      *cname = xstrdup (field_name);
+
+	    if (cfull_expression)
+	      {
+		char *join = was_ptr ? "->" : ".";
+
+		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
+						join, field_name);
+	      }
+	  }
+
+	if (cvalue && value)
+	  {
+	    /* For C, varobj index is the same as type index.  */
+	    *cvalue = value_struct_element_index (value, index);
+	  }
+
+	if (ctype)
+	  *ctype = TYPE_FIELD_TYPE (type, index);
+      }
+      break;
+
+    case TYPE_CODE_PTR:
+      if (cname)
+	*cname = xstrprintf ("*%s", parent->name);
+
+      if (cvalue && value)
+	{
+	  TRY_CATCH (except, RETURN_MASK_ERROR)
+	    {
+	      *cvalue = value_ind (value);
+	    }
+
+	  if (except.reason < 0)
+	    *cvalue = NULL;
+	}
+
+      /* Don't use get_target_type because it calls
+	 check_typedef and here, we want to show the true
+	 declared type of the variable.  */
+      if (ctype)
+	*ctype = TYPE_TARGET_TYPE (type);
+
+      if (cfull_expression)
+	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
+      
+      break;
+
+    default:
+      /* This should not happen.  */
+      if (cname)
+	*cname = xstrdup ("???");
+      if (cfull_expression)
+	*cfull_expression = xstrdup ("???");
+      /* Don't set value and type, we don't know then.  */
+    }
+}
+
+static char *
+c_name_of_child (struct varobj *parent, int index)
+{
+  char *name;
+
+  c_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+c_path_expr_of_child (struct varobj *child)
+{
+  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+		    &child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+c_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  c_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+c_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  c_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+/* This returns the type of the variable.  It also skips past typedefs
+   to return the real type of the variable.  */
+
+static struct type *
+get_type (struct varobj *var)
+{
+  struct type *type;
+
+  type = var->type;
+  if (type != NULL)
+    type = check_typedef (type);
+
+  return type;
+}
+
+static char *
+c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  /* BOGUS: if val_print sees a struct/class, or a reference to one,
+     it will print out its children instead of "{...}".  So we need to
+     catch that case explicitly.  */
+  struct type *type = get_type (var);
+
+  /* Strip top-level references.  */
+  while (TYPE_CODE (type) == TYPE_CODE_REF)
+    type = check_typedef (TYPE_TARGET_TYPE (type));
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      return xstrdup ("{...}");
+      /* break; */
+
+    case TYPE_CODE_ARRAY:
+      {
+	char *number;
+
+	number = xstrprintf ("[%d]", var->num_children);
+	return (number);
+      }
+      /* break; */
+
+    default:
+      {
+	if (var->value == NULL)
+	  {
+	    /* This can happen if we attempt to get the value of a struct
+	       member when the parent is an invalid pointer.  This is an
+	       error condition, so we should tell the caller.  */
+	    return NULL;
+	  }
+	else
+	  {
+	    if (var->not_fetched && value_lazy (var->value))
+	      /* Frozen variable and no value yet.  We don't
+		 implicitly fetch the value.  MI response will
+		 use empty string for the value, which is OK.  */
+	      return NULL;
+
+	    gdb_assert (varobj_value_is_changeable_p (var));
+	    gdb_assert (!value_lazy (var->value));
+	    
+	    /* If the specified format is the current one,
+	       we can reuse print_value.  */
+	    if (format == var->format)
+	      return xstrdup (var->print_value);
+	    else
+	      return varobj_value_get_print_value (var->value, format, var);
+	  }
+      }
+    }
+}
+\f
+
+/* varobj operations for c.  */
+
+const struct lang_varobj_ops c_varobj_ops =
+{
+   c_number_of_children,
+   c_name_of_variable,
+   c_name_of_child,
+   c_path_expr_of_child,
+   c_value_of_child,
+   c_type_of_child,
+   c_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+/* A little convenience enum for dealing with C++/Java.  */
+enum vsections
+{
+  v_public = 0, v_private, v_protected
+};
+
+/* C++ */
+
+static int
+cplus_number_of_children (struct varobj *var)
+{
+  struct value *value = NULL;
+  struct type *type;
+  int children, dont_know;
+  int lookup_actual_type = 0;
+  struct value_print_options opts;
+
+  dont_know = 1;
+  children = 0;
+
+  get_user_print_options (&opts);
+
+  if (!CPLUS_FAKE_CHILD (var))
+    {
+      type = varobj_get_value_type (var);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+          value = var->value;
+          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
+	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
+	{
+	  int kids[3];
+
+	  cplus_class_num_children (type, kids);
+	  if (kids[v_public] != 0)
+	    children++;
+	  if (kids[v_private] != 0)
+	    children++;
+	  if (kids[v_protected] != 0)
+	    children++;
+
+	  /* Add any baseclasses.  */
+	  children += TYPE_N_BASECLASSES (type);
+	  dont_know = 0;
+
+	  /* FIXME: save children in var.  */
+	}
+    }
+  else
+    {
+      int kids[3];
+
+      type = varobj_get_value_type (var->parent);
+
+      /* It is necessary to access a real type (via RTTI).  */
+      if (opts.objectprint)
+        {
+	  struct varobj *parent = var->parent;
+
+	  value = parent->value;
+	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
+				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
+        }
+      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
+
+      cplus_class_num_children (type, kids);
+      if (strcmp (var->name, "public") == 0)
+	children = kids[v_public];
+      else if (strcmp (var->name, "private") == 0)
+	children = kids[v_private];
+      else
+	children = kids[v_protected];
+      dont_know = 0;
+    }
+
+  if (dont_know)
+    children = c_number_of_children (var);
+
+  return children;
+}
+
+/* Compute # of public, private, and protected variables in this class.
+   That means we need to descend into all baseclasses and find out
+   how many are there, too.  */
+
+static void
+cplus_class_num_children (struct type *type, int children[3])
+{
+  int i, vptr_fieldno;
+  struct type *basetype = NULL;
+
+  children[v_public] = 0;
+  children[v_private] = 0;
+  children[v_protected] = 0;
+
+  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+    {
+      /* If we have a virtual table pointer, omit it.  Even if virtual
+	 table pointers are not specifically marked in the debug info,
+	 they should be artificial.  */
+      if ((type == basetype && i == vptr_fieldno)
+	  || TYPE_FIELD_ARTIFICIAL (type, i))
+	continue;
+
+      if (TYPE_FIELD_PROTECTED (type, i))
+	children[v_protected]++;
+      else if (TYPE_FIELD_PRIVATE (type, i))
+	children[v_private]++;
+      else
+	children[v_public]++;
+    }
+}
+
+static char *
+cplus_name_of_variable (struct varobj *parent)
+{
+  return c_name_of_variable (parent);
+}
+
+enum accessibility { private_field, protected_field, public_field };
+
+/* Check if field INDEX of TYPE has the specified accessibility.
+   Return 0 if so and 1 otherwise.  */
+
+static int 
+match_accessibility (struct type *type, int index, enum accessibility acc)
+{
+  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
+    return 1;
+  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
+	   && !TYPE_FIELD_PROTECTED (type, index))
+    return 1;
+  else
+    return 0;
+}
+
+static void
+cplus_describe_child (struct varobj *parent, int index,
+		      char **cname, struct value **cvalue, struct type **ctype,
+		      char **cfull_expression)
+{
+  struct value *value;
+  struct type *type;
+  int was_ptr;
+  int lookup_actual_type = 0;
+  char *parent_expression = NULL;
+  struct varobj *var;
+  struct value_print_options opts;
+
+  if (cname)
+    *cname = NULL;
+  if (cvalue)
+    *cvalue = NULL;
+  if (ctype)
+    *ctype = NULL;
+  if (cfull_expression)
+    *cfull_expression = NULL;
+
+  get_user_print_options (&opts);
+
+  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
+  if (opts.objectprint)
+    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
+  value = var->value;
+  type = varobj_get_value_type (var);
+  if (cfull_expression)
+    parent_expression
+      = varobj_get_path_expr (varobj_get_path_expr_parent (var));
+
+  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
+
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+      || TYPE_CODE (type) == TYPE_CODE_UNION)
+    {
+      char *join = was_ptr ? "->" : ".";
+
+      if (CPLUS_FAKE_CHILD (parent))
+	{
+	  /* The fields of the class type are ordered as they
+	     appear in the class.  We are given an index for a
+	     particular access control type ("public","protected",
+	     or "private").  We must skip over fields that don't
+	     have the access control we are looking for to properly
+	     find the indexed field.  */
+	  int type_index = TYPE_N_BASECLASSES (type);
+	  enum accessibility acc = public_field;
+	  int vptr_fieldno;
+	  struct type *basetype = NULL;
+	  const char *field_name;
+
+	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
+	  if (strcmp (parent->name, "private") == 0)
+	    acc = private_field;
+	  else if (strcmp (parent->name, "protected") == 0)
+	    acc = protected_field;
+
+	  while (index >= 0)
+	    {
+	      if ((type == basetype && type_index == vptr_fieldno)
+		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
+		; /* ignore vptr */
+	      else if (match_accessibility (type, type_index, acc))
+		    --index;
+		  ++type_index;
+	    }
+	  --type_index;
+
+	  /* If the type is anonymous and the field has no name,
+	     set an appopriate name.  */
+	  field_name = TYPE_FIELD_NAME (type, type_index);
+	  if (field_name == NULL || *field_name == '\0')
+	    {
+	      if (cname)
+		{
+		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+		      == TYPE_CODE_STRUCT)
+		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
+		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+			   == TYPE_CODE_UNION)
+		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
+		}
+
+	      if (cfull_expression)
+		*cfull_expression = xstrdup ("");
+	    }
+	  else
+	    {
+	      if (cname)
+		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
+
+	      if (cfull_expression)
+		*cfull_expression
+		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
+				field_name);
+	    }
+
+	  if (cvalue && value)
+	    *cvalue = value_struct_element_index (value, type_index);
+
+	  if (ctype)
+	    *ctype = TYPE_FIELD_TYPE (type, type_index);
+	}
+      else if (index < TYPE_N_BASECLASSES (type))
+	{
+	  /* This is a baseclass.  */
+	  if (cname)
+	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
+
+	  if (cvalue && value)
+	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
+
+	  if (ctype)
+	    {
+	      *ctype = TYPE_FIELD_TYPE (type, index);
+	    }
+
+	  if (cfull_expression)
+	    {
+	      char *ptr = was_ptr ? "*" : "";
+
+	      /* Cast the parent to the base' type.  Note that in gdb,
+		 expression like 
+		         (Base1)d
+		 will create an lvalue, for all appearences, so we don't
+		 need to use more fancy:
+		         *(Base1*)(&d)
+		 construct.
+
+		 When we are in the scope of the base class or of one
+		 of its children, the type field name will be interpreted
+		 as a constructor, if it exists.  Therefore, we must
+		 indicate that the name is a class name by using the
+		 'class' keyword.  See PR mi/11912  */
+	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
+					      ptr, 
+					      TYPE_FIELD_NAME (type, index),
+					      ptr,
+					      parent_expression);
+	    }
+	}
+      else
+	{
+	  char *access = NULL;
+	  int children[3];
+
+	  cplus_class_num_children (type, children);
+
+	  /* Everything beyond the baseclasses can
+	     only be "public", "private", or "protected"
+
+	     The special "fake" children are always output by varobj in
+	     this order.  So if INDEX == 2, it MUST be "protected".  */
+	  index -= TYPE_N_BASECLASSES (type);
+	  switch (index)
+	    {
+	    case 0:
+	      if (children[v_public] > 0)
+	 	access = "public";
+	      else if (children[v_private] > 0)
+	 	access = "private";
+	      else 
+	 	access = "protected";
+	      break;
+	    case 1:
+	      if (children[v_public] > 0)
+		{
+		  if (children[v_private] > 0)
+		    access = "private";
+		  else
+		    access = "protected";
+		}
+	      else if (children[v_private] > 0)
+	 	access = "protected";
+	      break;
+	    case 2:
+	      /* Must be protected.  */
+	      access = "protected";
+	      break;
+	    default:
+	      /* error!  */
+	      break;
+	    }
+
+	  gdb_assert (access);
+	  if (cname)
+	    *cname = xstrdup (access);
+
+	  /* Value and type and full expression are null here.  */
+	}
+    }
+  else
+    {
+      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
+    }  
+}
+
+static char *
+cplus_name_of_child (struct varobj *parent, int index)
+{
+  char *name = NULL;
+
+  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
+  return name;
+}
+
+static char *
+cplus_path_expr_of_child (struct varobj *child)
+{
+  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
+			&child->path_expr);
+  return child->path_expr;
+}
+
+static struct value *
+cplus_value_of_child (struct varobj *parent, int index)
+{
+  struct value *value = NULL;
+
+  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
+  return value;
+}
+
+static struct type *
+cplus_type_of_child (struct varobj *parent, int index)
+{
+  struct type *type = NULL;
+
+  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
+  return type;
+}
+
+static char *
+cplus_value_of_variable (struct varobj *var, 
+			 enum varobj_display_formats format)
+{
+
+  /* If we have one of our special types, don't print out
+     any value.  */
+  if (CPLUS_FAKE_CHILD (var))
+    return xstrdup ("");
+
+  return c_value_of_variable (var, format);
+}
+\f
+
+/* varobj operations for c++.  */
+
+const struct lang_varobj_ops cplus_varobj_ops =
+{
+   cplus_number_of_children,
+   cplus_name_of_variable,
+   cplus_name_of_child,
+   cplus_path_expr_of_child,
+   cplus_value_of_child,
+   cplus_type_of_child,
+   cplus_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
+
+\f
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6c809a4..9069a11 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -239,6 +239,21 @@ get_type_arch (const struct type *type)
     return TYPE_OWNER (type).gdbarch;
 }
 
+/* See gdbtypes.h.  */
+
+struct type *
+get_target_type (struct type *type)
+{
+  if (type != NULL)
+    {
+      type = TYPE_TARGET_TYPE (type);
+      if (type != NULL)
+	type = check_typedef (type);
+    }
+
+  return type;
+}
+
 /* Alloc a new type instance structure, fill it with some defaults,
    and point it at OLDTYPE.  Allocate the new type instance from the
    same place as OLDTYPE.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 5e8d1e7..d7fdedf 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1431,6 +1431,10 @@ extern struct type *alloc_type_copy (const struct type *);
    objfile's architecture is returned.  */
 extern struct gdbarch *get_type_arch (const struct type *);
 
+/* This returns the target type (or NULL) of TYPE, also skipping
+   past typedefs.  */
+extern struct type *get_target_type (struct type *type);
+
 /* Helper function to construct objfile-owned types.  */
 extern struct type *init_type (enum type_code, int, int, const char *,
 			       struct objfile *);
diff --git a/gdb/jv-varobj.c b/gdb/jv-varobj.c
new file mode 100644
index 0000000..e70aa28
--- /dev/null
+++ b/gdb/jv-varobj.c
@@ -0,0 +1,105 @@
+/* varobj support for Java.
+
+   Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "varobj.h"
+
+/* Java */
+
+static int
+java_number_of_children (struct varobj *var)
+{
+  return cplus_varobj_ops.number_of_children (var);
+}
+
+static char *
+java_name_of_variable (struct varobj *parent)
+{
+  char *p, *name;
+
+  name = cplus_varobj_ops.name_of_variable (parent);
+  /* If  the name has "-" in it, it is because we
+     needed to escape periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '-')
+	*p = '.';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_name_of_child (struct varobj *parent, int index)
+{
+  char *name, *p;
+
+  name = cplus_varobj_ops.name_of_child (parent, index);
+  /* Escape any periods in the name...  */
+  p = name;
+
+  while (*p != '\000')
+    {
+      if (*p == '.')
+	*p = '-';
+      p++;
+    }
+
+  return name;
+}
+
+static char *
+java_path_expr_of_child (struct varobj *child)
+{
+  return NULL;
+}
+
+static struct value *
+java_value_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.value_of_child (parent, index);
+}
+
+static struct type *
+java_type_of_child (struct varobj *parent, int index)
+{
+  return cplus_varobj_ops.type_of_child (parent, index);
+}
+
+static char *
+java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+{
+  return cplus_varobj_ops.value_of_variable (var, format);
+}
+
+/* varobj operations for java.  */
+
+const struct lang_varobj_ops java_varobj_ops =
+{
+   java_number_of_children,
+   java_name_of_variable,
+   java_name_of_child,
+   java_path_expr_of_child,
+   java_value_of_child,
+   java_type_of_child,
+   java_value_of_variable,
+   varobj_default_value_is_changeable_p,
+   NULL /* value_has_mutated */
+};
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 1967842..01cf3d2 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -33,8 +33,6 @@
 #include "vec.h"
 #include "gdbthread.h"
 #include "inferior.h"
-#include "ada-varobj.h"
-#include "ada-lang.h"
 
 #if HAVE_PYTHON
 #include "python/python.h"
@@ -43,10 +41,6 @@
 typedef int PyObject;
 #endif
 
-/* The names of varobjs representing anonymous structs or unions.  */
-#define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
-#define ANONYMOUS_UNION_NAME _("<anonymous union>")
-
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
 unsigned int varobjdebug = 0;
@@ -106,8 +100,9 @@ struct varobj_root
      to symbols that do not exist anymore.  */
   int is_valid;
 
-  /* Language info for this variable and its children.  */
-  struct language_specific *lang;
+  /* Language-related operations for this variable and its
+     children.  */
+  const struct lang_varobj_ops *lang;
 
   /* The varobj for this root node.  */
   struct varobj *rootvar;
@@ -190,12 +185,6 @@ static void free_variable (struct varobj *var);
 
 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
 
-static struct type *get_type (struct varobj *var);
-
-static struct type *get_value_type (struct varobj *var);
-
-static struct type *get_target_type (struct type *);
-
 static enum varobj_display_formats variable_default_display (struct varobj *);
 
 static void cppush (struct cpstack **pstack, char *name);
@@ -225,12 +214,6 @@ static struct value *value_of_child (struct varobj *parent, int index);
 static char *my_value_of_variable (struct varobj *var,
 				   enum varobj_display_formats format);
 
-static char *value_get_print_value (struct value *value,
-				    enum varobj_display_formats format,
-				    struct varobj *var);
-
-static int varobj_value_is_changeable_p (struct varobj *var);
-
 static int is_root_p (struct varobj *var);
 
 #if HAVE_PYTHON
@@ -241,190 +224,12 @@ static struct varobj *varobj_add_child (struct varobj *var,
 
 #endif /* HAVE_PYTHON */
 
-static int default_value_is_changeable_p (struct varobj *var);
-
-/* C implementation */
-
-static int c_number_of_children (struct varobj *var);
-
-static char *c_name_of_variable (struct varobj *parent);
-
-static char *c_name_of_child (struct varobj *parent, int index);
-
-static char *c_path_expr_of_child (struct varobj *child);
-
-static struct value *c_value_of_child (struct varobj *parent, int index);
-
-static struct type *c_type_of_child (struct varobj *parent, int index);
-
-static char *c_value_of_variable (struct varobj *var,
-				  enum varobj_display_formats format);
-
-/* C++ implementation */
-
-static int cplus_number_of_children (struct varobj *var);
-
-static void cplus_class_num_children (struct type *type, int children[3]);
-
-static char *cplus_name_of_variable (struct varobj *parent);
-
-static char *cplus_name_of_child (struct varobj *parent, int index);
-
-static char *cplus_path_expr_of_child (struct varobj *child);
-
-static struct value *cplus_value_of_child (struct varobj *parent, int index);
-
-static struct type *cplus_type_of_child (struct varobj *parent, int index);
-
-static char *cplus_value_of_variable (struct varobj *var,
-				      enum varobj_display_formats format);
-
-/* Java implementation */
-
-static int java_number_of_children (struct varobj *var);
-
-static char *java_name_of_variable (struct varobj *parent);
-
-static char *java_name_of_child (struct varobj *parent, int index);
-
-static char *java_path_expr_of_child (struct varobj *child);
-
-static struct value *java_value_of_child (struct varobj *parent, int index);
-
-static struct type *java_type_of_child (struct varobj *parent, int index);
-
-static char *java_value_of_variable (struct varobj *var,
-				     enum varobj_display_formats format);
-
-/* Ada implementation */
-
-static int ada_number_of_children (struct varobj *var);
-
-static char *ada_name_of_variable (struct varobj *parent);
-
-static char *ada_name_of_child (struct varobj *parent, int index);
-
-static char *ada_path_expr_of_child (struct varobj *child);
-
-static struct value *ada_value_of_child (struct varobj *parent, int index);
-
-static struct type *ada_type_of_child (struct varobj *parent, int index);
-
-static char *ada_value_of_variable (struct varobj *var,
-				    enum varobj_display_formats format);
-
-static int ada_value_is_changeable_p (struct varobj *var);
-
-static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
-				  struct type *new_type);
-
-/* The language specific vector */
-
-struct language_specific
-{
-  /* The number of children of PARENT.  */
-  int (*number_of_children) (struct varobj * parent);
-
-  /* The name (expression) of a root varobj.  */
-  char *(*name_of_variable) (struct varobj * parent);
-
-  /* The name of the INDEX'th child of PARENT.  */
-  char *(*name_of_child) (struct varobj * parent, int index);
-
-  /* Returns the rooted expression of CHILD, which is a variable
-     obtain that has some parent.  */
-  char *(*path_expr_of_child) (struct varobj * child);
-
-  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
-  struct value *(*value_of_child) (struct varobj * parent, int index);
-
-  /* The type of the INDEX'th child of PARENT.  */
-  struct type *(*type_of_child) (struct varobj * parent, int index);
-
-  /* The current value of VAR.  */
-  char *(*value_of_variable) (struct varobj * var,
-			      enum varobj_display_formats format);
-
-  /* Return non-zero if changes in value of VAR must be detected and
-     reported by -var-update.  Return zero if -var-update should never
-     report changes of such values.  This makes sense for structures
-     (since the changes in children values will be reported separately),
-     or for artifical objects (like 'public' pseudo-field in C++).
-
-     Return value of 0 means that gdb need not call value_fetch_lazy
-     for the value of this variable object.  */
-  int (*value_is_changeable_p) (struct varobj *var);
-
-  /* Return nonzero if the type of VAR has mutated.
-
-     VAR's value is still the varobj's previous value, while NEW_VALUE
-     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
-     may be NULL indicating that there is no value available (the varobj
-     may be out of scope, of may be the child of a null pointer, for
-     instance).  NEW_TYPE, on the other hand, must never be NULL.
-
-     This function should also be able to assume that var's number of
-     children is set (not < 0).
-
-     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);
-};
-
 /* Array of known source language routines.  */
-static struct language_specific languages[vlang_end] = {
-  /* C */
-  {
-   c_number_of_children,
-   c_name_of_variable,
-   c_name_of_child,
-   c_path_expr_of_child,
-   c_value_of_child,
-   c_type_of_child,
-   c_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* C++ */
-  {
-   cplus_number_of_children,
-   cplus_name_of_variable,
-   cplus_name_of_child,
-   cplus_path_expr_of_child,
-   cplus_value_of_child,
-   cplus_type_of_child,
-   cplus_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */}
-  ,
-  /* Java */
-  {
-   java_number_of_children,
-   java_name_of_variable,
-   java_name_of_child,
-   java_path_expr_of_child,
-   java_value_of_child,
-   java_type_of_child,
-   java_value_of_variable,
-   default_value_is_changeable_p,
-   NULL /* value_has_mutated */},
-  /* Ada */
-  {
-   ada_number_of_children,
-   ada_name_of_variable,
-   ada_name_of_child,
-   ada_path_expr_of_child,
-   ada_value_of_child,
-   ada_type_of_child,
-   ada_value_of_variable,
-   ada_value_is_changeable_p,
-   ada_value_has_mutated}
-};
-
-/* A little convenience enum for dealing with C++/Java.  */
-enum vsections
-{
-  v_public = 0, v_private, v_protected
+static const struct lang_varobj_ops *languages[vlang_end] = {
+  &c_varobj_ops,
+  &cplus_varobj_ops,
+  &java_varobj_ops,
+  &ada_varobj_ops,
 };
 
 /* Private data */
@@ -442,9 +247,6 @@ static struct varobj_root *rootlist;
 /* Pointer to the varobj hash table (built at run time).  */
 static struct vlist **varobj_table;
 
-/* Is the variable X one of our "fake" children?  */
-#define CPLUS_FAKE_CHILD(x) \
-((x) != NULL && (x)->type == NULL && (x)->value == NULL)
 \f
 
 /* API Implementation */
@@ -632,7 +434,7 @@ varobj_create (char *objname,
 
       /* Set language info */
       lang = variable_language (var);
-      var->root->lang = &languages[lang];
+      var->root->lang = languages[lang];
 
       install_new_value (var, value, 1 /* Initial assignment */);
 
@@ -812,7 +614,8 @@ varobj_set_display_format (struct varobj *var,
       && var->value && !value_lazy (var->value))
     {
       xfree (var->print_value);
-      var->print_value = value_get_print_value (var->value, var->format, var);
+      var->print_value = varobj_value_get_print_value (var->value,
+						       var->format, var);
     }
 
   return var->format;
@@ -894,8 +697,8 @@ varobj_get_frozen (struct varobj *var)
    of FROM and TO -- if either is negative, the entire range is
    used.  */
 
-static void
-restrict_range (VEC (varobj_p) *children, int *from, int *to)
+void
+varobj_restrict_range (VEC (varobj_p) *children, int *from, int *to)
 {
   if (*from < 0 || *to < 0)
     {
@@ -1202,7 +1005,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	 varobj twice is not something a sane frontend would do.  */
       update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL,
 				      &children_changed, 0, 0, *to);
-      restrict_range (var->children, from, to);
+      varobj_restrict_range (var->children, from, to);
       return var->children;
     }
 
@@ -1233,7 +1036,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 	}
     }
 
-  restrict_range (var->children, from, to);
+  varobj_restrict_range (var->children, from, to);
   return var->children;
 }
 
@@ -1287,7 +1090,7 @@ is_path_expr_parent (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   /* Anonymous unions and structs are also not path_expr parents.  */
   return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
@@ -1297,8 +1100,8 @@ is_path_expr_parent (struct varobj *var)
 
 /* Return the path expression parent for VAR.  */
 
-static struct varobj *
-get_path_expr_parent (struct varobj *var)
+struct varobj *
+varobj_get_path_expr_parent (struct varobj *var)
 {
   struct varobj *parent = var;
 
@@ -1692,7 +1495,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      should not be fetched.  */
   if (value != NULL && !value_lazy (value)
       && var->dynamic->pretty_printer == NULL)
-    print_value = value_get_print_value (value, var->format, var);
+    print_value = varobj_value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
      If this is the initial assignment, we don't have any old value
@@ -1766,7 +1569,8 @@ install_new_value (struct varobj *var, struct value *value, int initial)
   if (var->dynamic->pretty_printer != NULL)
     {
       xfree (print_value);
-      print_value = value_get_print_value (var->value, var->format, var);
+      print_value = varobj_value_get_print_value (var->value, var->format,
+						  var);
       if ((var->print_value == NULL && print_value != NULL)
 	  || (var->print_value != NULL && print_value == NULL)
 	  || (var->print_value != NULL && print_value != NULL
@@ -2313,20 +2117,6 @@ create_child (struct varobj *parent, int index, char *name)
 				  value_of_child (parent, index));
 }
 
-/* Does CHILD represent a child with no name?  This happens when
-   the child is an anonmous struct or union and it has no field name
-   in its parent variable.
-
-   This has already been determined by *_describe_child. The easiest
-   thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
-
-static int
-is_anonymous_child (struct varobj *child)
-{
-  return (strcmp (child->name, ANONYMOUS_STRUCT_NAME) == 0
-	  || strcmp (child->name, ANONYMOUS_UNION_NAME) == 0);
-}
-
 static struct varobj *
 create_child_with_value (struct varobj *parent, int index, char *name,
 			 struct value *value)
@@ -2342,7 +2132,7 @@ create_child_with_value (struct varobj *parent, int index, char *name,
   child->parent = parent;
   child->root = parent->root;
 
-  if (is_anonymous_child (child))
+  if (varobj_is_anonymous_child (child))
     childs_name = xstrprintf ("%s.%d_anonymous", parent->obj_name, index);
   else
     childs_name = xstrprintf ("%s.%s", parent->obj_name, name);
@@ -2469,23 +2259,6 @@ make_cleanup_free_variable (struct varobj *var)
   return make_cleanup (do_free_variable_cleanup, var);
 }
 
-/* This returns the type of the variable.  It also skips past typedefs
-   to return the real type of the variable.
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_type (struct varobj *var)
-{
-  struct type *type;
-
-  type = var->type;
-  if (type != NULL)
-    type = check_typedef (type);
-
-  return type;
-}
-
 /* Return the type of the value that's stored in VAR,
    or that would have being stored there if the
    value were accessible.
@@ -2497,8 +2270,8 @@ get_type (struct varobj *var)
    the values and for comparing previous and new values.
 
    For example, top-level references are always stripped.  */
-static struct type *
-get_value_type (struct varobj *var)
+struct type *
+varobj_get_value_type (struct varobj *var)
 {
   struct type *type;
 
@@ -2517,24 +2290,6 @@ get_value_type (struct varobj *var)
   return type;
 }
 
-/* This returns the target type (or NULL) of TYPE, also skipping
-   past typedefs, just like get_type ().
-
-   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
-   except within get_target_type and get_type.  */
-static struct type *
-get_target_type (struct type *type)
-{
-  if (type != NULL)
-    {
-      type = TYPE_TARGET_TYPE (type);
-      if (type != NULL)
-	type = check_typedef (type);
-    }
-
-  return type;
-}
-
 /* What is the default display for this variable? We assume that
    everything is "natural".  Any exceptions?  */
 static enum varobj_display_formats
@@ -2828,16 +2583,26 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
   if (var->root->is_valid)
     {
       if (var->dynamic->pretty_printer != NULL)
-	return value_get_print_value (var->value, var->format, var);
+	return varobj_value_get_print_value (var->value, var->format, var);
       return (*var->root->lang->value_of_variable) (var, format);
     }
   else
     return NULL;
 }
 
-static char *
-value_get_print_value (struct value *value, enum varobj_display_formats format,
-		       struct varobj *var)
+void
+varobj_formatted_print_options (struct value_print_options *opts,
+				enum varobj_display_formats format)
+{
+  get_formatted_print_options (opts, format_code[(int) format]);
+  opts->deref_ref = 0;
+  opts->raw = 1;
+}
+
+char *
+varobj_value_get_print_value (struct value *value,
+			      enum varobj_display_formats format,
+			      struct varobj *var)
 {
   struct ui_file *stb;
   struct cleanup *old_chain;
@@ -2948,9 +2713,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
     }
 #endif
 
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
+  varobj_formatted_print_options (&opts, format);
 
   /* If the THEVALUE has contents, it is a regular string.  */
   if (thevalue)
@@ -2977,7 +2740,7 @@ varobj_editable_p (struct varobj *var)
   if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -2997,7 +2760,7 @@ varobj_editable_p (struct varobj *var)
 
 /* Call VAR's value_is_changeable_p language-specific callback.  */
 
-static int
+int
 varobj_value_is_changeable_p (struct varobj *var)
 {
   return var->root->lang->value_is_changeable_p (var);
@@ -3012,95 +2775,11 @@ varobj_floating_p (struct varobj *var)
   return var->root->floating;
 }
 
-/* Given the value and the type of a variable object,
-   adjust the value and type to those necessary
-   for getting children of the variable object.
-   This includes dereferencing top-level references
-   to all types and dereferencing pointers to
-   structures.
-
-   If LOOKUP_ACTUAL_TYPE is set the enclosing type of the
-   value will be fetched and if it differs from static type
-   the value will be casted to it.
-
-   Both TYPE and *TYPE should be non-null.  VALUE
-   can be null if we want to only translate type.
-   *VALUE can be null as well -- if the parent
-   value is not known.
-
-   If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1
-   depending on whether pointer was dereferenced
-   in this function.  */
-static void
-adjust_value_for_child_access (struct value **value,
-				  struct type **type,
-				  int *was_ptr,
-				  int lookup_actual_type)
-{
-  gdb_assert (type && *type);
-
-  if (was_ptr)
-    *was_ptr = 0;
-
-  *type = check_typedef (*type);
-  
-  /* The type of value stored in varobj, that is passed
-     to us, is already supposed to be
-     reference-stripped.  */
-
-  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
-
-  /* Pointers to structures are treated just like
-     structures when accessing children.  Don't
-     dererences pointers to other types.  */
-  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
-    {
-      struct type *target_type = get_target_type (*type);
-      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
-	  || TYPE_CODE (target_type) == TYPE_CODE_UNION)
-	{
-	  if (value && *value)
-	    {
-	      volatile struct gdb_exception except;
-
-	      TRY_CATCH (except, RETURN_MASK_ERROR)
-		{
-		  *value = value_ind (*value);
-		}
-
-	      if (except.reason < 0)
-		*value = NULL;
-	    }
-	  *type = target_type;
-	  if (was_ptr)
-	    *was_ptr = 1;
-	}
-    }
-
-  /* The 'get_target_type' function calls check_typedef on
-     result, so we can immediately check type code.  No
-     need to call check_typedef here.  */
-
-  /* Access a real type of the value (if necessary and possible).  */
-  if (value && *value && lookup_actual_type)
-    {
-      struct type *enclosing_type;
-      int real_type_found = 0;
-
-      enclosing_type = value_actual_type (*value, 1, &real_type_found);
-      if (real_type_found)
-        {
-          *type = enclosing_type;
-          *value = value_cast (enclosing_type, *value);
-        }
-    }
-}
-
 /* Implement the "value_is_changeable_p" varobj callback for most
    languages.  */
 
-static int
-default_value_is_changeable_p (struct varobj *var)
+int
+varobj_default_value_is_changeable_p (struct varobj *var)
 {
   int r;
   struct type *type;
@@ -3108,7 +2787,7 @@ default_value_is_changeable_p (struct varobj *var)
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 
-  type = get_value_type (var);
+  type = varobj_get_value_type (var);
 
   switch (TYPE_CODE (type))
     {
@@ -3125,925 +2804,6 @@ default_value_is_changeable_p (struct varobj *var)
   return r;
 }
 
-/* C */
-
-static int
-c_number_of_children (struct varobj *var)
-{
-  struct type *type = get_value_type (var);
-  int children = 0;
-  struct type *target;
-
-  adjust_value_for_child_access (NULL, &type, NULL, 0);
-  target = get_target_type (type);
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
-	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
-      else
-	/* If we don't know how many elements there are, don't display
-	   any.  */
-	children = 0;
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      children = TYPE_NFIELDS (type);
-      break;
-
-    case TYPE_CODE_PTR:
-      /* The type here is a pointer to non-struct.  Typically, pointers
-	 have one child, except for function ptrs, which have no children,
-	 and except for void*, as we don't know what to show.
-
-         We can show char* so we allow it to be dereferenced.  If you decide
-         to test for it, please mind that a little magic is necessary to
-         properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
-         TYPE_NAME == "char".  */
-      if (TYPE_CODE (target) == TYPE_CODE_FUNC
-	  || TYPE_CODE (target) == TYPE_CODE_VOID)
-	children = 0;
-      else
-	children = 1;
-      break;
-
-    default:
-      /* Other types have no children.  */
-      break;
-    }
-
-  return children;
-}
-
-static char *
-c_name_of_variable (struct varobj *parent)
-{
-  return xstrdup (parent->name);
-}
-
-/* Return the value of element TYPE_INDEX of a structure
-   value VALUE.  VALUE's type should be a structure,
-   or union, or a typedef to struct/union.
-
-   Returns NULL if getting the value fails.  Never throws.  */
-static struct value *
-value_struct_element_index (struct value *value, int type_index)
-{
-  struct value *result = NULL;
-  volatile struct gdb_exception e;
-  struct type *type = value_type (value);
-
-  type = check_typedef (type);
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
-	      || TYPE_CODE (type) == TYPE_CODE_UNION);
-
-  TRY_CATCH (e, RETURN_MASK_ERROR)
-    {
-      if (field_is_static (&TYPE_FIELD (type, type_index)))
-	result = value_static_field (type, type_index);
-      else
-	result = value_primitive_field (value, 0, type_index, type);
-    }
-  if (e.reason < 0)
-    {
-      return NULL;
-    }
-  else
-    {
-      return result;
-    }
-}
-
-/* Obtain the information about child INDEX of the variable
-   object PARENT.
-   If CNAME is not null, sets *CNAME to the name of the child relative
-   to the parent.
-   If CVALUE is not null, sets *CVALUE to the value of the child.
-   If CTYPE is not null, sets *CTYPE to the type of the child.
-
-   If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding
-   information cannot be determined, set *CNAME, *CVALUE, or *CTYPE
-   to NULL.  */
-static void 
-c_describe_child (struct varobj *parent, int index,
-		  char **cname, struct value **cvalue, struct type **ctype,
-		  char **cfull_expression)
-{
-  struct value *value = parent->value;
-  struct type *type = get_value_type (parent);
-  char *parent_expression = NULL;
-  int was_ptr;
-  volatile struct gdb_exception except;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    {
-      *cfull_expression = NULL;
-      parent_expression = varobj_get_path_expr (get_path_expr_parent (parent));
-    }
-  adjust_value_for_child_access (&value, &type, &was_ptr, 0);
-      
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_ARRAY:
-      if (cname)
-	*cname
-	  = xstrdup (int_string (index 
-				 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				 10, 1, 0, 0));
-
-      if (cvalue && value)
-	{
-	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
-
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_subscript (value, real_index);
-	    }
-	}
-
-      if (ctype)
-	*ctype = get_target_type (type);
-
-      if (cfull_expression)
-	*cfull_expression = 
-	  xstrprintf ("(%s)[%s]", parent_expression, 
-		      int_string (index
-				  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
-				  10, 1, 0, 0));
-
-
-      break;
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      {
-	const char *field_name;
-
-	/* If the type is anonymous and the field has no name,
-	   set an appropriate name.  */
-	field_name = TYPE_FIELD_NAME (type, index);
-	if (field_name == NULL || *field_name == '\0')
-	  {
-	    if (cname)
-	      {
-		if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
-		    == TYPE_CODE_STRUCT)
-		  *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		else
-		  *cname = xstrdup (ANONYMOUS_UNION_NAME);
-	      }
-
-	    if (cfull_expression)
-	      *cfull_expression = xstrdup ("");
-	  }
-	else
-	  {
-	    if (cname)
-	      *cname = xstrdup (field_name);
-
-	    if (cfull_expression)
-	      {
-		char *join = was_ptr ? "->" : ".";
-
-		*cfull_expression = xstrprintf ("(%s)%s%s", parent_expression,
-						join, field_name);
-	      }
-	  }
-
-	if (cvalue && value)
-	  {
-	    /* For C, varobj index is the same as type index.  */
-	    *cvalue = value_struct_element_index (value, index);
-	  }
-
-	if (ctype)
-	  *ctype = TYPE_FIELD_TYPE (type, index);
-      }
-      break;
-
-    case TYPE_CODE_PTR:
-      if (cname)
-	*cname = xstrprintf ("*%s", parent->name);
-
-      if (cvalue && value)
-	{
-	  TRY_CATCH (except, RETURN_MASK_ERROR)
-	    {
-	      *cvalue = value_ind (value);
-	    }
-
-	  if (except.reason < 0)
-	    *cvalue = NULL;
-	}
-
-      /* Don't use get_target_type because it calls
-	 check_typedef and here, we want to show the true
-	 declared type of the variable.  */
-      if (ctype)
-	*ctype = TYPE_TARGET_TYPE (type);
-
-      if (cfull_expression)
-	*cfull_expression = xstrprintf ("*(%s)", parent_expression);
-      
-      break;
-
-    default:
-      /* This should not happen.  */
-      if (cname)
-	*cname = xstrdup ("???");
-      if (cfull_expression)
-	*cfull_expression = xstrdup ("???");
-      /* Don't set value and type, we don't know then.  */
-    }
-}
-
-static char *
-c_name_of_child (struct varobj *parent, int index)
-{
-  char *name;
-
-  c_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-c_path_expr_of_child (struct varobj *child)
-{
-  c_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-		    &child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-c_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  c_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-c_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  c_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  /* BOGUS: if val_print sees a struct/class, or a reference to one,
-     it will print out its children instead of "{...}".  So we need to
-     catch that case explicitly.  */
-  struct type *type = get_type (var);
-
-  /* Strip top-level references.  */
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
-    type = check_typedef (TYPE_TARGET_TYPE (type));
-
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      return xstrdup ("{...}");
-      /* break; */
-
-    case TYPE_CODE_ARRAY:
-      {
-	char *number;
-
-	number = xstrprintf ("[%d]", var->num_children);
-	return (number);
-      }
-      /* break; */
-
-    default:
-      {
-	if (var->value == NULL)
-	  {
-	    /* This can happen if we attempt to get the value of a struct
-	       member when the parent is an invalid pointer.  This is an
-	       error condition, so we should tell the caller.  */
-	    return NULL;
-	  }
-	else
-	  {
-	    if (var->not_fetched && value_lazy (var->value))
-	      /* Frozen variable and no value yet.  We don't
-		 implicitly fetch the value.  MI response will
-		 use empty string for the value, which is OK.  */
-	      return NULL;
-
-	    gdb_assert (varobj_value_is_changeable_p (var));
-	    gdb_assert (!value_lazy (var->value));
-	    
-	    /* If the specified format is the current one,
-	       we can reuse print_value.  */
-	    if (format == var->format)
-	      return xstrdup (var->print_value);
-	    else
-	      return value_get_print_value (var->value, format, var);
-	  }
-      }
-    }
-}
-\f
-
-/* C++ */
-
-static int
-cplus_number_of_children (struct varobj *var)
-{
-  struct value *value = NULL;
-  struct type *type;
-  int children, dont_know;
-  int lookup_actual_type = 0;
-  struct value_print_options opts;
-
-  dont_know = 1;
-  children = 0;
-
-  get_user_print_options (&opts);
-
-  if (!CPLUS_FAKE_CHILD (var))
-    {
-      type = get_value_type (var);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-          value = var->value;
-          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
-	  ((TYPE_CODE (type)) == TYPE_CODE_UNION))
-	{
-	  int kids[3];
-
-	  cplus_class_num_children (type, kids);
-	  if (kids[v_public] != 0)
-	    children++;
-	  if (kids[v_private] != 0)
-	    children++;
-	  if (kids[v_protected] != 0)
-	    children++;
-
-	  /* Add any baseclasses.  */
-	  children += TYPE_N_BASECLASSES (type);
-	  dont_know = 0;
-
-	  /* FIXME: save children in var.  */
-	}
-    }
-  else
-    {
-      int kids[3];
-
-      type = get_value_type (var->parent);
-
-      /* It is necessary to access a real type (via RTTI).  */
-      if (opts.objectprint)
-        {
-	  struct varobj *parent = var->parent;
-
-	  value = parent->value;
-	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
-				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
-        }
-      adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
-
-      cplus_class_num_children (type, kids);
-      if (strcmp (var->name, "public") == 0)
-	children = kids[v_public];
-      else if (strcmp (var->name, "private") == 0)
-	children = kids[v_private];
-      else
-	children = kids[v_protected];
-      dont_know = 0;
-    }
-
-  if (dont_know)
-    children = c_number_of_children (var);
-
-  return children;
-}
-
-/* Compute # of public, private, and protected variables in this class.
-   That means we need to descend into all baseclasses and find out
-   how many are there, too.  */
-static void
-cplus_class_num_children (struct type *type, int children[3])
-{
-  int i, vptr_fieldno;
-  struct type *basetype = NULL;
-
-  children[v_public] = 0;
-  children[v_private] = 0;
-  children[v_protected] = 0;
-
-  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
-    {
-      /* If we have a virtual table pointer, omit it.  Even if virtual
-	 table pointers are not specifically marked in the debug info,
-	 they should be artificial.  */
-      if ((type == basetype && i == vptr_fieldno)
-	  || TYPE_FIELD_ARTIFICIAL (type, i))
-	continue;
-
-      if (TYPE_FIELD_PROTECTED (type, i))
-	children[v_protected]++;
-      else if (TYPE_FIELD_PRIVATE (type, i))
-	children[v_private]++;
-      else
-	children[v_public]++;
-    }
-}
-
-static char *
-cplus_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-enum accessibility { private_field, protected_field, public_field };
-
-/* Check if field INDEX of TYPE has the specified accessibility.
-   Return 0 if so and 1 otherwise.  */
-static int 
-match_accessibility (struct type *type, int index, enum accessibility acc)
-{
-  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
-    return 1;
-  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
-	   && !TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else
-    return 0;
-}
-
-static void
-cplus_describe_child (struct varobj *parent, int index,
-		      char **cname, struct value **cvalue, struct type **ctype,
-		      char **cfull_expression)
-{
-  struct value *value;
-  struct type *type;
-  int was_ptr;
-  int lookup_actual_type = 0;
-  char *parent_expression = NULL;
-  struct varobj *var;
-  struct value_print_options opts;
-
-  if (cname)
-    *cname = NULL;
-  if (cvalue)
-    *cvalue = NULL;
-  if (ctype)
-    *ctype = NULL;
-  if (cfull_expression)
-    *cfull_expression = NULL;
-
-  get_user_print_options (&opts);
-
-  var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
-  if (opts.objectprint)
-    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
-  value = var->value;
-  type = get_value_type (var);
-  if (cfull_expression)
-    parent_expression = varobj_get_path_expr (get_path_expr_parent (var));
-
-  adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
-
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (type) == TYPE_CODE_UNION)
-    {
-      char *join = was_ptr ? "->" : ".";
-
-      if (CPLUS_FAKE_CHILD (parent))
-	{
-	  /* The fields of the class type are ordered as they
-	     appear in the class.  We are given an index for a
-	     particular access control type ("public","protected",
-	     or "private").  We must skip over fields that don't
-	     have the access control we are looking for to properly
-	     find the indexed field.  */
-	  int type_index = TYPE_N_BASECLASSES (type);
-	  enum accessibility acc = public_field;
-	  int vptr_fieldno;
-	  struct type *basetype = NULL;
-	  const char *field_name;
-
-	  vptr_fieldno = get_vptr_fieldno (type, &basetype);
-	  if (strcmp (parent->name, "private") == 0)
-	    acc = private_field;
-	  else if (strcmp (parent->name, "protected") == 0)
-	    acc = protected_field;
-
-	  while (index >= 0)
-	    {
-	      if ((type == basetype && type_index == vptr_fieldno)
-		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
-		; /* ignore vptr */
-	      else if (match_accessibility (type, type_index, acc))
-		    --index;
-		  ++type_index;
-	    }
-	  --type_index;
-
-	  /* If the type is anonymous and the field has no name,
-	     set an appopriate name.  */
-	  field_name = TYPE_FIELD_NAME (type, type_index);
-	  if (field_name == NULL || *field_name == '\0')
-	    {
-	      if (cname)
-		{
-		  if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-		      == TYPE_CODE_STRUCT)
-		    *cname = xstrdup (ANONYMOUS_STRUCT_NAME);
-		  else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
-			   == TYPE_CODE_UNION)
-		    *cname = xstrdup (ANONYMOUS_UNION_NAME);
-		}
-
-	      if (cfull_expression)
-		*cfull_expression = xstrdup ("");
-	    }
-	  else
-	    {
-	      if (cname)
-		*cname = xstrdup (TYPE_FIELD_NAME (type, type_index));
-
-	      if (cfull_expression)
-		*cfull_expression
-		  = xstrprintf ("((%s)%s%s)", parent_expression, join,
-				field_name);
-	    }
-
-	  if (cvalue && value)
-	    *cvalue = value_struct_element_index (value, type_index);
-
-	  if (ctype)
-	    *ctype = TYPE_FIELD_TYPE (type, type_index);
-	}
-      else if (index < TYPE_N_BASECLASSES (type))
-	{
-	  /* This is a baseclass.  */
-	  if (cname)
-	    *cname = xstrdup (TYPE_FIELD_NAME (type, index));
-
-	  if (cvalue && value)
-	    *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value);
-
-	  if (ctype)
-	    {
-	      *ctype = TYPE_FIELD_TYPE (type, index);
-	    }
-
-	  if (cfull_expression)
-	    {
-	      char *ptr = was_ptr ? "*" : "";
-
-	      /* Cast the parent to the base' type.  Note that in gdb,
-		 expression like 
-		         (Base1)d
-		 will create an lvalue, for all appearences, so we don't
-		 need to use more fancy:
-		         *(Base1*)(&d)
-		 construct.
-
-		 When we are in the scope of the base class or of one
-		 of its children, the type field name will be interpreted
-		 as a constructor, if it exists.  Therefore, we must
-		 indicate that the name is a class name by using the
-		 'class' keyword.  See PR mi/11912  */
-	      *cfull_expression = xstrprintf ("(%s(class %s%s) %s)", 
-					      ptr, 
-					      TYPE_FIELD_NAME (type, index),
-					      ptr,
-					      parent_expression);
-	    }
-	}
-      else
-	{
-	  char *access = NULL;
-	  int children[3];
-
-	  cplus_class_num_children (type, children);
-
-	  /* Everything beyond the baseclasses can
-	     only be "public", "private", or "protected"
-
-	     The special "fake" children are always output by varobj in
-	     this order.  So if INDEX == 2, it MUST be "protected".  */
-	  index -= TYPE_N_BASECLASSES (type);
-	  switch (index)
-	    {
-	    case 0:
-	      if (children[v_public] > 0)
-	 	access = "public";
-	      else if (children[v_private] > 0)
-	 	access = "private";
-	      else 
-	 	access = "protected";
-	      break;
-	    case 1:
-	      if (children[v_public] > 0)
-		{
-		  if (children[v_private] > 0)
-		    access = "private";
-		  else
-		    access = "protected";
-		}
-	      else if (children[v_private] > 0)
-	 	access = "protected";
-	      break;
-	    case 2:
-	      /* Must be protected.  */
-	      access = "protected";
-	      break;
-	    default:
-	      /* error!  */
-	      break;
-	    }
-
-	  gdb_assert (access);
-	  if (cname)
-	    *cname = xstrdup (access);
-
-	  /* Value and type and full expression are null here.  */
-	}
-    }
-  else
-    {
-      c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression);
-    }  
-}
-
-static char *
-cplus_name_of_child (struct varobj *parent, int index)
-{
-  char *name = NULL;
-
-  cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
-  return name;
-}
-
-static char *
-cplus_path_expr_of_child (struct varobj *child)
-{
-  cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, 
-			&child->path_expr);
-  return child->path_expr;
-}
-
-static struct value *
-cplus_value_of_child (struct varobj *parent, int index)
-{
-  struct value *value = NULL;
-
-  cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
-  return value;
-}
-
-static struct type *
-cplus_type_of_child (struct varobj *parent, int index)
-{
-  struct type *type = NULL;
-
-  cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
-  return type;
-}
-
-static char *
-cplus_value_of_variable (struct varobj *var, 
-			 enum varobj_display_formats format)
-{
-
-  /* If we have one of our special types, don't print out
-     any value.  */
-  if (CPLUS_FAKE_CHILD (var))
-    return xstrdup ("");
-
-  return c_value_of_variable (var, format);
-}
-\f
-/* Java */
-
-static int
-java_number_of_children (struct varobj *var)
-{
-  return cplus_number_of_children (var);
-}
-
-static char *
-java_name_of_variable (struct varobj *parent)
-{
-  char *p, *name;
-
-  name = cplus_name_of_variable (parent);
-  /* If  the name has "-" in it, it is because we
-     needed to escape periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '-')
-	*p = '.';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_name_of_child (struct varobj *parent, int index)
-{
-  char *name, *p;
-
-  name = cplus_name_of_child (parent, index);
-  /* Escape any periods in the name...  */
-  p = name;
-
-  while (*p != '\000')
-    {
-      if (*p == '.')
-	*p = '-';
-      p++;
-    }
-
-  return name;
-}
-
-static char *
-java_path_expr_of_child (struct varobj *child)
-{
-  return NULL;
-}
-
-static struct value *
-java_value_of_child (struct varobj *parent, int index)
-{
-  return cplus_value_of_child (parent, index);
-}
-
-static struct type *
-java_type_of_child (struct varobj *parent, int index)
-{
-  return cplus_type_of_child (parent, index);
-}
-
-static char *
-java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  return cplus_value_of_variable (var, format);
-}
-
-/* Ada specific callbacks for VAROBJs.  */
-
-static int
-ada_number_of_children (struct varobj *var)
-{
-  return ada_varobj_get_number_of_children (var->value, var->type);
-}
-
-static char *
-ada_name_of_variable (struct varobj *parent)
-{
-  return c_name_of_variable (parent);
-}
-
-static char *
-ada_name_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_name_of_child (parent->value, parent->type,
-				       parent->name, index);
-}
-
-static char*
-ada_path_expr_of_child (struct varobj *child)
-{
-  struct varobj *parent = child->parent;
-  const char *parent_path_expr = varobj_get_path_expr (parent);
-
-  return ada_varobj_get_path_expr_of_child (parent->value,
-					    parent->type,
-					    parent->name,
-					    parent_path_expr,
-					    child->index);
-}
-
-static struct value *
-ada_value_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_value_of_child (parent->value, parent->type,
-					parent->name, index);
-}
-
-static struct type *
-ada_type_of_child (struct varobj *parent, int index)
-{
-  return ada_varobj_get_type_of_child (parent->value, parent->type,
-				       index);
-}
-
-static char *
-ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
-{
-  struct value_print_options opts;
-
-  get_formatted_print_options (&opts, format_code[(int) format]);
-  opts.deref_ref = 0;
-  opts.raw = 1;
-
-  return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
-}
-
-/* Implement the "value_is_changeable_p" routine for Ada.  */
-
-static int
-ada_value_is_changeable_p (struct varobj *var)
-{
-  struct type *type = var->value ? value_type (var->value) : var->type;
-
-  if (ada_is_array_descriptor_type (type)
-      && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
-    {
-      /* This is in reality a pointer to an unconstrained array.
-	 its value is changeable.  */
-      return 1;
-    }
-
-  if (ada_is_string_type (type))
-    {
-      /* We display the contents of the string in the array's
-	 "value" field.  The contents can change, so consider
-	 that the array is changeable.  */
-      return 1;
-    }
-
-  return default_value_is_changeable_p (var);
-}
-
-/* Implement the "value_has_mutated" routine for Ada.  */
-
-static int
-ada_value_has_mutated (struct varobj *var, struct value *new_val,
-		       struct type *new_type)
-{
-  int i;
-  int from = -1;
-  int to = -1;
-
-  /* If the number of fields have changed, then for sure the type
-     has mutated.  */
-  if (ada_varobj_get_number_of_children (new_val, new_type)
-      != var->num_children)
-    return 1;
-
-  /* If the number of fields have remained the same, then we need
-     to check the name of each field.  If they remain the same,
-     then chances are the type hasn't mutated.  This is technically
-     an incomplete test, as the child's type might have changed
-     despite the fact that the name remains the same.  But we'll
-     handle this situation by saying that the child has mutated,
-     not this value.
-
-     If only part (or none!) of the children have been fetched,
-     then only check the ones we fetched.  It does not matter
-     to the frontend whether a child that it has not fetched yet
-     has mutated or not. So just assume it hasn't.  */
-
-  restrict_range (var->children, &from, &to);
-  for (i = from; i < to; i++)
-    if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
-					      var->name, i),
-		VEC_index (varobj_p, var->children, i)->name) != 0)
-      return 1;
-
-  return 0;
-}
-
 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
    with an arbitrary caller supplied DATA pointer.  */
 
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 4a4dd75..e32c6ef 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -168,6 +168,68 @@ struct varobj
   struct varobj_dynamic *dynamic;
 };
 
+/* Is the variable X one of our "fake" children?  */
+#define CPLUS_FAKE_CHILD(x) \
+((x) != NULL && (x)->type == NULL && (x)->value == NULL)
+
+/* The language specific vector */
+
+struct lang_varobj_ops
+{
+  /* The number of children of PARENT.  */
+  int (*number_of_children) (struct varobj * parent);
+
+  /* The name (expression) of a root varobj.  */
+  char *(*name_of_variable) (struct varobj * parent);
+
+  /* The name of the INDEX'th child of PARENT.  */
+  char *(*name_of_child) (struct varobj * parent, int index);
+
+  /* Returns the rooted expression of CHILD, which is a variable
+     obtain that has some parent.  */
+  char *(*path_expr_of_child) (struct varobj * child);
+
+  /* The ``struct value *'' of the INDEX'th child of PARENT.  */
+  struct value *(*value_of_child) (struct varobj * parent, int index);
+
+  /* The type of the INDEX'th child of PARENT.  */
+  struct type *(*type_of_child) (struct varobj * parent, int index);
+
+  /* The current value of VAR.  */
+  char *(*value_of_variable) (struct varobj * var,
+			      enum varobj_display_formats format);
+
+  /* Return non-zero if changes in value of VAR must be detected and
+     reported by -var-update.  Return zero if -var-update should never
+     report changes of such values.  This makes sense for structures
+     (since the changes in children values will be reported separately),
+     or for artifical objects (like 'public' pseudo-field in C++).
+
+     Return value of 0 means that gdb need not call value_fetch_lazy
+     for the value of this variable object.  */
+  int (*value_is_changeable_p) (struct varobj *var);
+
+  /* Return nonzero if the type of VAR has mutated.
+
+     VAR's value is still the varobj's previous value, while NEW_VALUE
+     is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
+     may be NULL indicating that there is no value available (the varobj
+     may be out of scope, of may be the child of a null pointer, for
+     instance).  NEW_TYPE, on the other hand, must never be NULL.
+
+     This function should also be able to assume that var's number of
+     children is set (not < 0).
+
+     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);
+};
+
+const struct lang_varobj_ops c_varobj_ops;
+const struct lang_varobj_ops cplus_varobj_ops;
+const struct lang_varobj_ops java_varobj_ops;
+const struct lang_varobj_ops ada_varobj_ops;
+
 /* API functions */
 
 extern struct varobj *varobj_create (char *objname,
@@ -255,4 +317,22 @@ extern int varobj_has_more (struct varobj *var, int to);
 
 extern int varobj_pretty_printed_p (struct varobj *var);
 
+extern int varobj_default_value_is_changeable_p (struct varobj *var);
+extern int varobj_value_is_changeable_p (struct varobj *var);
+
+extern struct type *varobj_get_value_type (struct varobj *var);
+
+extern int varobj_is_anonymous_child (struct varobj *child);
+
+extern struct varobj *varobj_get_path_expr_parent (struct varobj *var);
+
+extern char *varobj_value_get_print_value (struct value *value,
+					   enum varobj_display_formats format,
+					   struct varobj *var);
+
+extern void varobj_formatted_print_options (struct value_print_options *opts,
+					    enum varobj_display_formats format);
+
+extern void varobj_restrict_range (VEC (varobj_p) *children, int *from,
+				   int *to);
 #endif /* VAROBJ_H */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 7/7] Remove ada-varobj.h.
  2013-10-17  5:46   ` Joel Brobecker
@ 2013-10-17 13:34     ` Yao Qi
  0 siblings, 0 replies; 35+ messages in thread
From: Yao Qi @ 2013-10-17 13:34 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On 10/17/2013 01:46 PM, Joel Brobecker wrote:
>> +static int ada_varobj_get_number_of_children (struct value *parent_value,
>> >+					      struct type *parent_type);
>> >+
>> >  static void
>> >  ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
>> >  {
> That declaration needs to be inserted_before_  the comment describing
> ada_varobj_decode_var.

Fixed.  Patch is committed.  Thanks for the review.

-- 
Yao (齐尧)

gdb:

2013-10-17  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
	* ada-varobj.c: Remove the include of ada-varobj.h.
	(ada_varobj_get_number_of_children): Declare.
	(ada_varobj_get_name_of_child): Make it static.
	(ada_varobj_get_path_expr_of_child): Likewise.
	(ada_varobj_get_value_of_child): Likewise.
	(ada_varobj_get_type_of_child): Likewise.
	(ada_varobj_get_value_of_array_variable): Likewise.
	* ada-varobj.h: Remove.
---
 gdb/Makefile.in  |    2 +-
 gdb/ada-varobj.c |   16 ++++++++------
 gdb/ada-varobj.h |   55 ------------------------------------------------------
 3 files changed, 10 insertions(+), 63 deletions(-)
 delete mode 100644 gdb/ada-varobj.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f8abb35..fc2a3af 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -795,7 +795,7 @@ proc-utils.h aarch64-tdep.h arm-tdep.h ax-gdb.h ppcfbsd-tdep.h \
 ppcnbsd-tdep.h cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
 exec.h m32r-tdep.h osabi.h gdbcore.h solib-som.h amd64bsd-nat.h \
 i386bsd-nat.h xml-support.h xml-tdesc.h alphabsd-tdep.h gdb_obstack.h \
-ia64-tdep.h ada-lang.h ada-varobj.h varobj.h frv-tdep.h nto-tdep.h serial.h \
+ia64-tdep.h ada-lang.h varobj.h frv-tdep.h nto-tdep.h serial.h \
 c-lang.h d-lang.h go-lang.h frame.h event-loop.h block.h cli/cli-setshow.h \
 cli/cli-decode.h cli/cli-cmds.h cli/cli-utils.h \
 cli/cli-script.h macrotab.h symtab.h common/version.h \
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 52c7687..62454b8 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -18,7 +18,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "ada-varobj.h"
 #include "ada-lang.h"
 #include "varobj.h"
 #include "language.h"
@@ -49,6 +48,9 @@
    it allows the code to use the type without having to worry about
    it being set or not.  It makes the code clearer.  */
 
+static int ada_varobj_get_number_of_children (struct value *parent_value,
+					      struct type *parent_type);
+
 /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple:
    If there is a value (*VALUE_PTR not NULL), then perform the decoding
    using it, and compute the associated type from the resulting value.
@@ -324,7 +326,7 @@ ada_varobj_get_ptr_number_of_children (struct value *parent_value,
 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE)
    pair.  */
 
-int
+static int
 ada_varobj_get_number_of_children (struct value *parent_value,
 				   struct type *parent_type)
 {
@@ -722,7 +724,7 @@ ada_varobj_describe_child (struct value *parent_value,
 
    The result should be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_name_of_child (struct value *parent_value,
 			      struct type *parent_type,
 			      const char *parent_name, int child_index)
@@ -742,7 +744,7 @@ ada_varobj_get_name_of_child (struct value *parent_value,
 
    The result must be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_path_expr_of_child (struct value *parent_value,
 				   struct type *parent_type,
 				   const char *parent_name,
@@ -761,7 +763,7 @@ ada_varobj_get_path_expr_of_child (struct value *parent_value,
 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  PARENT_NAME is the name of the parent.  */
 
-struct value *
+static struct value *
 ada_varobj_get_value_of_child (struct value *parent_value,
 			       struct type *parent_type,
 			       const char *parent_name, int child_index)
@@ -778,7 +780,7 @@ ada_varobj_get_value_of_child (struct value *parent_value,
 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  */
 
-struct type *
+static struct type *
 ada_varobj_get_type_of_child (struct value *parent_value,
 			      struct type *parent_type,
 			      int child_index)
@@ -857,7 +859,7 @@ ada_varobj_get_value_of_array_variable (struct value *value,
 /* Return a string representation of the (VALUE, TYPE) pair, using
    the given print options OPTS as our formatting options.  */
 
-char *
+static char *
 ada_varobj_get_value_of_variable (struct value *value,
 				  struct type *type,
 				  struct value_print_options *opts)
diff --git a/gdb/ada-varobj.h b/gdb/ada-varobj.h
deleted file mode 100644
index 924997d..0000000
--- a/gdb/ada-varobj.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* varobj support for Ada.
-
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef ADA_VAROBJ_H
-#define ADA_VAROBJ_H
-
-#include "varobj.h"
-
-struct value;
-struct value_print_options;
-
-extern int ada_varobj_get_number_of_children (struct value *parent_value,
-					      struct type *parent_type);
-
-extern char *ada_varobj_get_name_of_child (struct value *parent_value,
-					   struct type *parent_type,
-					   const char *parent_name,
-					   int child_index);
-
-extern char *ada_varobj_get_path_expr_of_child (struct value *parent_value,
-						struct type *parent_type,
-						const char *parent_name,
-						const char *parent_path_expr,
-						int child_index);
-
-extern struct value *ada_varobj_get_value_of_child (struct value *parent_value,
-						    struct type *parent_type,
-						    const char *parent_name,
-						    int child_index);
-
-extern struct type *ada_varobj_get_type_of_child (struct value *parent_value,
-						  struct type *parent_type,
-						  int child_index);
-
-extern char *ada_varobj_get_value_of_variable
-  (struct value *value, struct type *type,
-   struct value_print_options *opts);
-
-#endif /* ADA_VAROBJ_H */
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2013-10-17 13:34 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-18 13:55 [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi
2013-09-18 13:55 ` [PATCH 1/7] Remove field language in struct language_specific Yao Qi
2013-10-01 10:03   ` Joel Brobecker
2013-10-01 13:35     ` Yao Qi
2013-09-18 13:55 ` [PATCH 5/7] New lang-varobj.h Yao Qi
2013-10-02 17:18   ` Doug Evans
2013-10-08  4:59     ` Joel Brobecker
2013-10-09 23:51       ` Yao Qi
2013-10-09 23:56         ` Doug Evans
2013-10-10  0:19           ` Yao Qi
2013-09-18 13:55 ` [PATCH 6/7] Move language stuff out of varobj.c Yao Qi
2013-10-11  8:20   ` Yao Qi
2013-10-17  5:40     ` Joel Brobecker
2013-10-17 13:33       ` Yao Qi
2013-09-18 13:55 ` [PATCH 7/7] Remove ada-varobj.h Yao Qi
2013-10-17  5:46   ` Joel Brobecker
2013-10-17 13:34     ` Yao Qi
2013-09-18 13:55 ` [PATCH 4/7] Move struct varobj to varobj.h Yao Qi
2013-10-02  9:46   ` Joel Brobecker
2013-10-02 19:32     ` Doug Evans
2013-10-06  6:33     ` Yao Qi
2013-10-08  4:56       ` Joel Brobecker
2013-10-08 21:03         ` Doug Evans
2013-10-09  0:28         ` Yao Qi
2013-10-14  8:19         ` Yao Qi
2013-09-18 13:55 ` [PATCH 3/7] Remove field value_of_root Yao Qi
2013-10-01 10:16   ` Joel Brobecker
2013-10-01 13:52     ` Yao Qi
2013-09-18 13:55 ` [PATCH 2/7] Remove vlang_unknown Yao Qi
2013-10-01 10:07   ` Joel Brobecker
2013-10-01 13:34     ` Yao Qi
2013-10-02  0:19       ` Doug Evans
2013-10-02  9:32         ` Joel Brobecker
2013-10-04  8:31           ` Yao Qi
2013-09-28  0:56 ` [RFC 0/7] Move language-related stuff out of varobj.c Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).