common/
[deliverable/binutils-gdb.git] / gdb / varobj.c
index 1523bf4c21d72baccb36ca3d884608d73810ad18..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);
This page took 0.02519 seconds and 4 git commands to generate.