This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python][patch] Preserve string length, and embedded-nulls in pretty-printstring emission.


This patch is the second and final patch for supporting counted/embedded-null strings within the Python pretty-printers.

The first patch thread can be found here:

http://sourceware.org/ml/archer/2009-q2/msg00017.html

This patch focuses on string emission and the preservation of embedded nulls within counted strings. This comprises of preserving the string length as reported from Python, and the avoidance of string library calls like strlen, or xstrdup. The patch is shallow, but touches many parts of the printing code. I elected to alter convert_value_from_python to return the length of a string - if the value is a string - via an out parameter. Also as Tom pointed out previously, the string length has to be captured at conversion and passed back up through the call chain to convert_value_from_python. This touches a lot of Python string convenience functions, but not all of them. In this patch, I choose to convert only the convenience functions that this patch required,. There may be a good argument to convert them all to carry string length as an explicit parameter. For this patch, I decided not to do it for brevity, but will be pleased to do it if the community/maintainer think it would be a good idea.

This patch is tested on x8664, and introduces no known regressions. It applies cleanly to archer-tromey-python branch.

I look forward to your comments.

Regards

Phil

ChangeLog

2009-05-22 Phil Muldoon <pmuldoon@redhat.com>

* python/lib/gdb/libstdcxx/v6/printers.py
(StdStringPrinter.to_string): Extract length from header. Use in
string extraction.
* python/python-frame.c (frapy_read_var): Update
python_string_to_target_string call.
* python//python-function.c (fnpy_call): Update
convert_value_from_python call.
* python/python-inferior.c (add_pattern_element): Likewise.
* python/python-value.c (valpy_new, valpy_getitem, valpy_binop)
(valpy_richcompare): Likewise.
(convert_value_from_python): Add size parameter. Write size
parameter if value conversion is a string.
* python/python-internal.h (convert_value_from_python)
(unicode_to_target_string, python_string_to_target_string)
(apply_varobj_pretty_printer): Update definitions to include
a size parameter.
* python/python-utils.c (unicode_to_encoded_string): Add size to
parameter list. Write size when completed.
(unicode_to_target_string): Likewise.
(python_string_to_target_string): Likewise.
(apply_varobj_pretty_printer): Return a size.
* python/python.c (pretty_print_one_value): Only use
convert_value_from_python with a size.
(print_string_repr): Capture size of string, and refactor to use
a value only approach.
(print_children): Use size of string.
(apply_varobj_pretty_printer): Likewise.
* value.c (value_from_string): New len parameter. Use over
parameter over strlen call.
* value.h (value_from_string): Update definition.
* varobj.c (update_dynamic_varobj_children): Update
convert_value_from_python_call.
(value_get_print_value): Refactor to use returned value length.
Testsuite ChangeLog:


2009-05-22 Phil Muldoon <pmuldoon@redhat.com>

   * gdb.python/python-prettyprint.c: Add counted null string
   variable.
   * gdb.python/python-prettyprint.exp: Print null string. Test for
   embedded nulls.
   * gdb.python/python-prettyprint.py (StdStringPrinter): New
   Function.
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index 2bd2593..0f2d64e 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -465,10 +465,20 @@ class StdStringPrinter:
         # Look up the target encoding as late as possible.
         encoding = self.encoding
         if encoding is None:
-            encoding = gdb.parameter('target-charset')
-        elif isinstance(encoding, WideEncoding):
+            encoding = gdb.parameter ('target-charset')
+        elif isinstance (encoding, WideEncoding):
             encoding = encoding.value
-        return self.val['_M_dataplus']['_M_p'].string(encoding)
+        type = self.val.type
+        if type.code == gdb.TYPE_CODE_REF:
+            type = type.target ()
+
+        ptr = self.val ['_M_dataplus']['_M_p']
+        realtype = type.unqualified ().strip_typedefs ()
+        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
+        header = ptr.cast(reptype) - 1
+        len = header.dereference ()['_M_length']
+
+        return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
 
     def display_hint (self):
         return 'string'
diff --git a/gdb/python/python-frame.c b/gdb/python/python-frame.c
index ad03c46..9615166 100644
--- a/gdb/python/python-frame.c
+++ b/gdb/python/python-frame.c
@@ -395,7 +395,7 @@ frapy_read_var (PyObject *self, PyObject *args)
       struct cleanup *cleanup;
       volatile struct gdb_exception except;
 
-      var_name = python_string_to_target_string (sym_obj);
+      var_name = python_string_to_target_string (sym_obj, NULL);
       if (!var_name)
 	return NULL;
       cleanup = make_cleanup (xfree, var_name);
diff --git a/gdb/python/python-function.c b/gdb/python/python-function.c
index 4a85a33..ac7c3d8 100644
--- a/gdb/python/python-function.c
+++ b/gdb/python/python-function.c
@@ -83,7 +83,7 @@ fnpy_call (void *cookie, int argc, struct value **argv)
       error (_("Error while executing Python code."));
     }
 
-  value = convert_value_from_python (result);
+  value = convert_value_from_python (result, NULL);
   if (value == NULL)
     {
       Py_DECREF (result);
diff --git a/gdb/python/python-inferior.c b/gdb/python/python-inferior.c
index a08be7b..009f1e3 100644
--- a/gdb/python/python-inferior.c
+++ b/gdb/python/python-inferior.c
@@ -625,7 +625,7 @@ add_pattern_element (PyObject *obj, int size, char **pattern_buf,
     {
       /* See if we can convert from a Python object to a GDB value.  */
 
-      struct value *v = convert_value_from_python (obj);
+      struct value *v = convert_value_from_python (obj, NULL);
 
       if (v)
 	add_value_pattern (v, size, pattern_buf, pattern_buf_end,
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 29e55dd..2752930 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -112,7 +112,7 @@ PyObject *objfpy_get_printers (PyObject *, void *);
 struct block *block_object_to_block (PyObject *obj);
 struct symbol *symbol_object_to_symbol (PyObject *obj);
 struct value *value_object_to_value (PyObject *self);
-struct value *convert_value_from_python (PyObject *obj);
+struct value *convert_value_from_python (PyObject *obj, int *size);
 struct type *type_object_to_type (PyObject *obj);
 
 PyObject *gdbpy_get_hook_function (const char *);
@@ -167,8 +167,8 @@ PyObject *gdbpy_parameter_value (enum var_types, void *);
 void gdbpy_print_stack (void);
 
 PyObject *python_string_to_unicode (PyObject *obj);
-char *unicode_to_target_string (PyObject *unicode_str);
-char *python_string_to_target_string (PyObject *obj);
+char *unicode_to_target_string (PyObject *unicode_str, int *size);
+char *python_string_to_target_string (PyObject *obj, int *size);
 char *python_string_to_host_string (PyObject *obj);
 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
 int gdbpy_is_string (PyObject *obj);
@@ -177,7 +177,7 @@ int gdbpy_is_value_object (PyObject *obj);
 
 /* Note that these are declared here, and not in python.h with the
    other pretty-printer functions, because they refer to PyObject.  */
-char *apply_varobj_pretty_printer (PyObject *print_obj,
+int apply_varobj_pretty_printer (PyObject *print_obj,
 				   struct value **replacement);
 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
 PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c
index f9c9486..c4c1139 100644
--- a/gdb/python/python-utils.c
+++ b/gdb/python/python-utils.c
@@ -100,45 +100,57 @@ python_string_to_unicode (PyObject *obj)
 }
 
 /* Returns a newly allocated string with the contents of the given unicode
-   string object converted to a named charset.  If an error occurs during
-   the conversion, NULL will be returned and a python exception will be set.
+   string object converted to a named charset.  The parameter *SIZE
+   will be set to the size of the string.  If *SIZE is NULL no size
+   information will be returned.  If an error occurs during the
+   conversion, NULL will be returned and a python exception will be
+   set.
 
    The caller is responsible for xfree'ing the string.  */
 static char *
-unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
+unicode_to_encoded_string (PyObject *unicode_str, const char *charset, int *size)
 {
-  char *result;
+  char *result = NULL;
   PyObject *string;
+  Py_ssize_t str_size;
 
   /* Translate string to named charset.  */
   string = PyUnicode_AsEncodedString (unicode_str, charset, NULL);
   if (string == NULL)
     return NULL;
 
-  result = xstrdup (PyString_AsString (string));
+  str_size = PyString_Size (string) + 1;
+  result = xmemdup (PyString_AsString (string), str_size, str_size);
+  if (size != NULL)
+    *size = str_size;
 
   Py_DECREF (string);
 
   return result;
 }
 
-/* Returns a newly allocated string with the contents of the given unicode
-   string object converted to the target's charset.  If an error occurs during
-   the conversion, NULL will be returned and a python exception will be set.
+/* Returns a newly allocated string with the contents of the given
+   unicode string object converted to the target's charset.  The
+   parameter *SIZE will be set to the size of the string.  If *SIZE is
+   NULL no size information will be returned.  If an error occurs
+   during the conversion, NULL will be returned and a python exception
+   will be set.
 
    The caller is responsible for xfree'ing the string.  */
 char *
-unicode_to_target_string (PyObject *unicode_str)
+unicode_to_target_string (PyObject *unicode_str, int *size)
 {
-  return unicode_to_encoded_string (unicode_str, target_charset ());
+  return unicode_to_encoded_string (unicode_str, target_charset (), size);
 }
 
 /* Converts a python string (8-bit or unicode) to a target string in
-   the target's charset.  Returns NULL on error, with a python exception set.
+   the target's charset.  The parameter *SIZE will be set to the
+   size of the string.  If *SIZE is NULL no size information will be
+   returned.  Returns NULL on error, with a python exception set.
 
    The caller is responsible for xfree'ing the string.  */
 char *
-python_string_to_target_string (PyObject *obj)
+python_string_to_target_string (PyObject *obj, int *size)
 {
   PyObject *str;
   char *result;
@@ -147,7 +159,7 @@ python_string_to_target_string (PyObject *obj)
   if (str == NULL)
     return NULL;
 
-  result = unicode_to_target_string (str);
+  result = unicode_to_target_string (str, size);
   Py_DECREF (str);
   return result;
 }
@@ -166,7 +178,7 @@ python_string_to_host_string (PyObject *obj)
   if (str == NULL)
     return NULL;
 
-  result = unicode_to_encoded_string (str, host_charset ()); 
+  result = unicode_to_encoded_string (str, host_charset (), NULL);
   Py_DECREF (str);
   return result;
 }
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 743e6a6..eae858f 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -112,7 +112,7 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
       return NULL;
     }
 
-  value = convert_value_from_python (PyTuple_GetItem (args, 0));
+  value = convert_value_from_python (PyTuple_GetItem (args, 0), NULL);
   if (value == NULL)
     {
       subtype->tp_free (value_obj);
@@ -293,7 +293,7 @@ valpy_getitem (PyObject *self, PyObject *key)
 	  /* Assume we are attempting an array access, and let the
 	     value code throw an exception if the index has an invalid
 	     type.  */
-	  struct value *idx = convert_value_from_python (key);
+	  struct value *idx = convert_value_from_python (key, NULL);
 	  if (idx == NULL)
 	    return NULL;
 
@@ -397,11 +397,11 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
 	 to us as the OTHER argument, and SELF will be an entirely different
 	 kind of object, altogether.  Because of this, we can't assume self is
 	 a gdb.Value object and need to convert it from python as well.  */
-      arg1 = convert_value_from_python (self);
+      arg1 = convert_value_from_python (self, NULL);
       if (arg1 == NULL)
 	break;
 
-      arg2 = convert_value_from_python (other);
+      arg2 = convert_value_from_python (other, NULL);
       if (arg2 == NULL)
 	break;
 
@@ -666,7 +666,7 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      value_other = convert_value_from_python (other);
+      value_other = convert_value_from_python (other, NULL);
       if (value_other == NULL)
 	return NULL;
 
@@ -824,10 +824,13 @@ value_object_to_value (PyObject *self)
 }
 
 /* Try to convert a Python value to a gdb value.  If the value cannot
-   be converted, set a Python exception and return NULL.  */
+   be converted, set a Python exception and return NULL.  The
+   parameter *SIZE will be set to the size of the string if the
+   Python value is a string.  If *SIZE is NULL or the value from
+   Python is not a string, the *SIZE  parameter will not be set.  */
 
 struct value *
-convert_value_from_python (PyObject *obj)
+convert_value_from_python (PyObject *obj, int *size)
 {
   struct value *value = NULL; /* -Wall */
   PyObject *target_str, *unicode_str;
@@ -896,14 +899,17 @@ convert_value_from_python (PyObject *obj)
       else if (gdbpy_is_string (obj))
 	{
 	  char *s;
+	  int str_size = 0;
 
-	  s = python_string_to_target_string (obj);
+	  s = python_string_to_target_string (obj, &str_size);
 	  if (s != NULL)
 	    {
 	      old = make_cleanup (xfree, s);
-	      value = value_from_string (s);
+	      value = value_from_string (s, str_size);
 	      do_cleanups (old);
 	    }
+	  if (size != NULL)
+	    *size = str_size;
 	}
       else if (PyObject_TypeCheck (obj, &value_object_type))
 	value = value_copy (((value_object *) obj)->value);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index e97bef8..041f08e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -826,15 +826,15 @@ find_pretty_printer (PyObject *value)
   return function;
 }
 
-/* Pretty-print a single value, via the printer object PRINTER.  If
-   the function returns a string, an xmalloc()d copy is returned.
-   Otherwise, if the function returns a value, a *OUT_VALUE is set to
-   the value, and NULL is returned.  On error, *OUT_VALUE is set to
-   NULL and NULL is returned.  */
-static char *
+/* Pretty-print a single value, via the printer object PRINTER.
+   The value output is written to *OUT_VALUE,  If the written
+   *OUT_VALUE contains a string, the function will return the length
+   of the string.  On error, *OUT_VALUE is set to NULL.  */
+static int
 pretty_print_one_value (PyObject *printer, struct value **out_value)
 {
   char *output = NULL;
+  int size = 0;
   volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ALL)
@@ -844,23 +844,15 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
       result = PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst, NULL);
       if (result)
 	{
-	  if (gdbpy_is_string (result))
-	    output = python_string_to_host_string (result);
-	  else if (PyObject_TypeCheck (result, &value_object_type))
-	    {
-	      /* If we just call convert_value_from_python for this
-		 type, we won't know who owns the result.  For this
-		 one case we need to copy the resulting value.  */
-	      struct value *v = value_object_to_value (result);
-	      *out_value = value_copy (v);
-	    }
-	  else
-	    *out_value = convert_value_from_python (result);
+	  *out_value = convert_value_from_python (result, &size);
+	  if (PyErr_Occurred ())
+	      *out_value = NULL;
+
 	  Py_DECREF (result);
 	}
     }
 
-  return output;
+  return size;
 }
 
 /* Instantiate a pretty-printer given a constructor, CONS, and a
@@ -906,21 +898,24 @@ print_string_repr (PyObject *printer, const char *hint,
 		   const struct value_print_options *options,
 		   const struct language_defn *language)
 {
-  char *output;
+  gdb_byte *output = NULL;
+  int str_length = 0;
   struct value *replacement = NULL;
+  const char *la_encoding = language->la_name;
 
-  output = pretty_print_one_value (printer, &replacement);
-  if (output)
-    {
-      if (hint && !strcmp (hint, "string"))
-	LA_PRINT_STRING (stream, (gdb_byte *) output, strlen (output),
-			 1, 0, options);
-      else
-	fputs_filtered (output, stream);
-      xfree (output);
-    }
-  else if (replacement)
-    common_val_print (replacement, stream, recurse, options, language);
+  str_length = pretty_print_one_value (printer, &replacement);
+  if (replacement)
+    if (str_length > 0)
+      {
+	LA_GET_STRING (replacement, &output, &str_length, &la_encoding);
+	if (hint && !strcmp (hint, "string"))
+	  LA_PRINT_STRING (stream, output, str_length, 1, 0, options);
+	else
+	  fputs_filtered (output, stream);
+	xfree (output);
+      }
+    else
+      common_val_print (replacement, stream, recurse, options, language);
   else
     gdbpy_print_stack ();
 }
@@ -1141,7 +1136,7 @@ print_children (PyObject *printer, const char *hint,
 	}
       else
 	{
-	  struct value *value = convert_value_from_python (py_v);
+	  struct value *value = convert_value_from_python (py_v, NULL);
 
 	  if (value == NULL)
 	    {
@@ -1235,25 +1230,28 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 /* Apply a pretty-printer for the varobj code.  PRINTER_OBJ is the
    print object.  It must have a 'to_string' method (but this is
    checked by varobj, not here) which takes no arguments and
-   returns a string.  This function returns an xmalloc()d string if
-   the printer returns a string.  The printer may return a replacement
-   value instead; in this case *REPLACEMENT is set to the replacement
-   value, and this function returns NULL.  On error, *REPLACEMENT is
-   set to NULL and this function also returns NULL.  */
-char *
+   returns a string.  The printer will return a value and
+   *REPLACEMENT is set to the replacement value. If the replacement
+   value contains a string, this function will return the length of
+   the string.  On error, *REPLACEMENT is set to NULL and
+   this function also returns NULL.  */
+
+int
 apply_varobj_pretty_printer (PyObject *printer_obj,
 			     struct value **replacement)
 {
-  char *result;
+  int size = 0;
   PyGILState_STATE state = PyGILState_Ensure ();
 
   *replacement = NULL;
-  result = pretty_print_one_value (printer_obj, replacement);
-  if (result == NULL);
+  size = pretty_print_one_value (printer_obj, replacement);
+
+  if (replacement == NULL);
     gdbpy_print_stack ();
+
   PyGILState_Release (state);
 
-  return result;
+  return size;
 }
 
 /* Find a pretty-printer object for the varobj module.  Returns a new
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 0d9110d..3cceef0 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -30,6 +30,9 @@ struct ss
 };
 
 #ifdef __cplusplus
+
+#include <string>
+
 struct S : public s {
   int zs;
 };
@@ -75,6 +78,8 @@ class Derived : public Vbase1, public Vbase2, public Vbase3
     }
 };
 
+std::string cplus_str ("embedded\0null\0string",20);
+
 #endif
 
 typedef struct string_repr
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index 47d2fa8..0c5518c 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -75,6 +75,8 @@ proc run_lang_tests {lang} {
 	gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
 	gdb_test "print derived" \
 	    " = \{.*<Vbase1> = pp class name: Vbase1.*<Vbase2> = \{.*<VirtualTest> = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.*<Vbase3> = \{.*members of Vbase3.*members of Derived:.*value = 2.*"
+	gdb_test "print cplus_str" "embedded\\\\000null\\\\000string.*"
+
     }
 
     gdb_test "print x" " = $hex \"this is x\""
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py
index 82e5331..5d74987 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.py
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -99,6 +99,32 @@ class pp_nullstr:
     def to_string(self):
         return self.val['s'].string(gdb.parameter('target-charset'))
 
+class StdStringPrinter:
+    "Print a std::basic_string of some kind"
+
+    def __init__(self, encoding, val):
+        self.encoding = encoding
+        self.val = val
+
+    def to_string(self):
+        # Look up the target encoding as late as possible.
+        encoding = gdb.parameter('target-charset')
+
+        type = self.val.type
+        if type.code == gdb.TYPE_CODE_REF:
+            type = type.target ()
+
+        ptr = self.val['_M_dataplus']['_M_p']
+        realtype = type.unqualified ().strip_typedefs()
+        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
+        header = ptr.cast(reptype) - 1
+        len = header.dereference()['_M_length']
+
+        return self.val['_M_dataplus']['_M_p'].string(encoding, length = len)
+
+    def display_hint (self):
+        return 'string'
+
 def lookup_function (val):
     "Look-up and return a pretty-printer that can print val."
 
@@ -155,6 +181,8 @@ def register_pretty_printers ():
     pretty_printers_dict[re.compile ('^string_repr$')] = string_print
     pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
     
+    pretty_printers_dict[re.compile('^std::basic_string<char,.*>$')] = lambda val: StdStringPrinter(None, val)
+
 pretty_printers_dict = {}
 
 register_pretty_printers ()
diff --git a/gdb/value.c b/gdb/value.c
index fd05f07..5f4731e 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1849,13 +1849,13 @@ value_from_pointer (struct type *type, CORE_ADDR addr)
 /* Create a value for a string constant to be stored locally
    (not in the inferior's memory space, but in GDB memory).
    This is analogous to value_from_longest, which also does not
-   use inferior memory.  String shall NOT contain embedded nulls.  */
+   use inferior memory.  LEN is the length of the string *PTR
+   from which the value will be created.  */
 
 struct value *
-value_from_string (char *ptr)
+value_from_string (char *ptr, int len)
 {
   struct value *val;
-  int len = strlen (ptr);
   int lowbound = current_language->string_lower_bound;
   struct type *string_char_type;
   struct type *rangetype;
diff --git a/gdb/value.h b/gdb/value.h
index fd0d2c9..38c1289 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -295,7 +295,7 @@ extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
 extern struct value *value_from_double (struct type *type, DOUBLEST num);
 extern struct value *value_from_decfloat (struct type *type,
 					  const gdb_byte *decbytes);
-extern struct value *value_from_string (char *string);
+extern struct value *value_from_string (char *string, int len);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 49b4a43..fb2b2b1 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -893,7 +893,7 @@ update_dynamic_varobj_children (struct varobj *var,
 	  v = value_copy (v);
 	}
       else
-	v = convert_value_from_python (py_v);
+	v = convert_value_from_python (py_v, NULL);
 
       /* TODO: This assume the name of the i-th child never changes.  */
 
@@ -2250,9 +2250,10 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
   long dummy;
   struct ui_file *stb;
   struct cleanup *old_chain;
-  char *thevalue = NULL;
+  gdb_byte *thevalue = NULL;
   struct value_print_options opts;
-
+  int length = 0;
+  const char *la_encoding = current_language->la_name;
   if (value == NULL)
     return NULL;
 
@@ -2274,15 +2275,19 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
 	    xfree (hint);
 	  }
 
-	thevalue = apply_varobj_pretty_printer (value_formatter,
+	length = apply_varobj_pretty_printer (value_formatter,
 						&replacement);
-	if (thevalue && !string_print)
-	  {
-	    PyGILState_Release (state);
-	    return thevalue;
-	  }
+
 	if (replacement)
 	  value = replacement;
+
+	if ((length > 0) && (!string_print))
+         {
+	   LA_GET_STRING (value, &thevalue, &length, &la_encoding);
+           PyGILState_Release (state);
+           return thevalue;
+         }
+
       }
     PyGILState_Release (state);
   }
@@ -2294,10 +2299,11 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
   get_formatted_print_options (&opts, format_code[(int) format]);
   opts.deref_ref = 0;
   opts.raw = 1;
-  if (thevalue)
+  if (length > 0)
     {
+      LA_GET_STRING (value, &thevalue, &length, &la_encoding);
       make_cleanup (xfree, thevalue);
-      LA_PRINT_STRING (stb, (gdb_byte *) thevalue, strlen (thevalue),
+      LA_PRINT_STRING (stb, (gdb_byte *) thevalue, length,
 		       1, 0, &opts);
     }
   else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]