common/
[deliverable/binutils-gdb.git] / gdb / varobj.c
index 8f22156e2600761e465f232aded9d740b87efa56..6ec87b34333f14b64f373249d19ddfb02f1c4b6e 100644 (file)
@@ -1,7 +1,7 @@
 /* Implementation of the GDB variable objects API.
 
    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   2009, 2010 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
@@ -293,9 +293,13 @@ static int varobj_value_is_changeable_p (struct varobj *var);
 
 static int is_root_p (struct varobj *var);
 
+#if HAVE_PYTHON
+
 static struct varobj *
 varobj_add_child (struct varobj *var, const char *name, struct value *value);
 
+#endif /* HAVE_PYTHON */
+
 /* C implementation */
 
 static int c_number_of_children (struct varobj *var);
@@ -759,12 +763,13 @@ varobj_delete (struct varobj *var, char ***dellist, int only_children)
   return delcount;
 }
 
+#if HAVE_PYTHON
+
 /* Convenience function for varobj_set_visualizer.  Instantiate a
    pretty-printer for a given value.  */
 static PyObject *
 instantiate_pretty_printer (PyObject *constructor, struct value *value)
 {
-#if HAVE_PYTHON
   PyObject *val_obj = NULL; 
   PyObject *printer;
 
@@ -775,10 +780,11 @@ instantiate_pretty_printer (PyObject *constructor, struct value *value)
   printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
   Py_DECREF (val_obj);
   return printer;
-#endif
   return NULL;
 }
 
+#endif
+
 /* Set/Get variable object display format */
 
 enum varobj_display_formats
@@ -899,6 +905,8 @@ restrict_range (VEC (varobj_p) *children, int *from, int *to)
     }
 }
 
+#if HAVE_PYTHON
+
 /* A helper for update_dynamic_varobj_children that installs a new
    child when needed.  */
 
@@ -935,8 +943,6 @@ install_dynamic_child (struct varobj *var,
     }
 }
 
-#if HAVE_PYTHON
-
 static int
 dynamic_varobj_has_child_method (struct varobj *var)
 {
@@ -1158,6 +1164,8 @@ varobj_list_children (struct varobj *var, int *from, int *to)
   return var->children;
 }
 
+#if HAVE_PYTHON
+
 static struct varobj *
 varobj_add_child (struct varobj *var, const char *name, struct value *value)
 {
@@ -1168,6 +1176,8 @@ varobj_add_child (struct varobj *var, const char *name, struct value *value)
   return v;
 }
 
+#endif /* HAVE_PYTHON */
+
 /* Obtain the type of an object Variable as a string similar to the one gdb
    prints on the console */
 
@@ -2453,11 +2463,15 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
   struct cleanup *old_chain;
   gdb_byte *thevalue = NULL;
   struct value_print_options opts;
-  int len = 0;
+  struct type *type = NULL;
+  long len = 0;
+  char *encoding = NULL;
+  struct gdbarch *gdbarch = NULL;
 
   if (value == NULL)
     return NULL;
 
+  gdbarch = get_type_arch (value_type (value));
 #if HAVE_PYTHON
   {
     struct cleanup *back_to = varobj_ensure_python_env (var);
@@ -2489,20 +2503,31 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
                                                  &replacement);
            if (output)
              {
-               PyObject *py_str
-                 = python_string_to_target_python_string (output);
-               if (py_str)
+               if (gdbpy_is_lazy_string (output))
+                 {
+                   thevalue = gdbpy_extract_lazy_string (output, &type,
+                                                         &len, &encoding);
+                   string_print = 1;
+                 }
+               else
                  {
-                   char *s = PyString_AsString (py_str);
-                   len = PyString_Size (py_str);
-                   thevalue = xmemdup (s, len + 1, len + 1);
-                   Py_DECREF (py_str);
+                   PyObject *py_str
+                     = python_string_to_target_python_string (output);
+                   if (py_str)
+                     {
+                       char *s = PyString_AsString (py_str);
+                       len = PyString_Size (py_str);
+                       thevalue = xmemdup (s, len + 1, len + 1);
+                       type = builtin_type (gdbarch)->builtin_char;
+                       Py_DECREF (py_str);
+                     }
                  }
                Py_DECREF (output);
              }
            if (thevalue && !string_print)
              {
                do_cleanups (back_to);
+               xfree (encoding);
                return thevalue;
              }
            if (replacement)
@@ -2521,10 +2546,9 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
   opts.raw = 1;
   if (thevalue)
     {
-      struct gdbarch *gdbarch = get_type_arch (value_type (value));
       make_cleanup (xfree, thevalue);
-      LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
-                      thevalue, len, 0, &opts);
+      make_cleanup (xfree, encoding);
+      LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
     }
   else
     common_val_print (value, stb, 0, &opts, current_language);
@@ -2793,8 +2817,9 @@ c_describe_child (struct varobj *parent, int index,
     {
     case TYPE_CODE_ARRAY:
       if (cname)
-       *cname = xstrprintf ("%d", index
-                            + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+       *cname = xstrdup (int_string (index 
+                                     + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+                                     10, 1, 0, 0));
 
       if (cvalue && value)
        {
@@ -2806,9 +2831,11 @@ c_describe_child (struct varobj *parent, int index,
        *ctype = get_target_type (type);
 
       if (cfull_expression)
-       *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression, 
-                                       index
-                                       + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+       *cfull_expression = 
+         xstrprintf ("(%s)[%s]", parent_expression, 
+                     int_string (index
+                                 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+                                 10, 1, 0, 0));
 
 
       break;
@@ -3103,16 +3130,21 @@ cplus_number_of_children (struct varobj *var)
 static void
 cplus_class_num_children (struct type *type, int children[3])
 {
-  int i;
+  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. */
-      if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (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))
@@ -3199,6 +3231,10 @@ cplus_describe_child (struct varobj *parent, int index,
             find the indexed field. */
          int type_index = TYPE_N_BASECLASSES (type);
          enum accessibility acc = public_field;
+         int vptr_fieldno;
+         struct type *basetype = NULL;
+
+         vptr_fieldno = get_vptr_fieldno (type, &basetype);
          if (strcmp (parent->name, "private") == 0)
            acc = private_field;
          else if (strcmp (parent->name, "protected") == 0)
@@ -3206,8 +3242,8 @@ cplus_describe_child (struct varobj *parent, int index,
 
          while (index >= 0)
            {
-             if (TYPE_VPTR_BASETYPE (type) == type
-                 && type_index == TYPE_VPTR_FIELDNO (type))
+             if ((type == basetype && type_index == vptr_fieldno)
+                 || TYPE_FIELD_ARTIFICIAL (type, type_index))
                ; /* ignore vptr */
              else if (match_accessibility (type, type_index, acc))
                    --index;
This page took 0.028582 seconds and 4 git commands to generate.