From fbb8f2990ccfa180274ab4a578818fe247823540 Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Fri, 10 Jul 2009 10:35:17 +0000 Subject: 2009-07-10 Phil Muldoon * python/python-internal.h (apply_varobj_pretty_printer): Update definition. (python_string_to_target_python_string): Add definition. * python/python-utils.c (unicode_to_encoded_python_string) (unicode_to_target_python_string) (python_string_to_target_python_string): New Functions. * python/python-prettyprint.c (pretty_print_one_value): Likewise. (print_string_repr): Refactor to logic to account for PyObject returned strings. (apply_varobj_pretty_printer): Likewise. * python/python-value.c (valpy_string): Parse length keyword. Use length keyword in LA_GET_STRING. * varobj.c (value_get_print_value): Refactor logic to account for PyObject returned strings. * c-lang.c (c_get_string): If the length parameter is specified, use that. Return value in characters. Update comments. * language.h: Update c_get_string prototype comments. 2009-07-10 Phil Muldoon * gdb.texinfo (Values From Inferior): Add length parameter description. 2009-07-10 Phil Muldoon * gdb.python/python-prettyprint.c: Add counted null string structure. * gdb.python/python-prettyprint.exp: Print null string. Test for embedded nulls. * gdb.python/python-prettyprint.py (pp_ns): New Function. * gdb.python/python-value.exp (test_value_in_inferior): Add variable length string fetch tests. * gdb.python/python-value.c (main): Add strings for string fetch tests. --- gdb/varobj.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'gdb/varobj.c') diff --git a/gdb/varobj.c b/gdb/varobj.c index dac0413..5d69743 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2221,8 +2221,9 @@ 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 len = 0; if (value == NULL) return NULL; @@ -2238,6 +2239,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format, char *hint; struct value *replacement; int string_print = 0; + PyObject *output = NULL; hint = gdbpy_get_display_hint (value_formatter); if (hint) @@ -2247,8 +2249,20 @@ value_get_print_value (struct value *value, enum varobj_display_formats format, xfree (hint); } - thevalue = apply_varobj_pretty_printer (value_formatter, - &replacement); + output = apply_varobj_pretty_printer (value_formatter, + &replacement); + if (output) + { + 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); + Py_DECREF (py_str); + } + Py_DECREF (output); + } if (thevalue && !string_print) { do_cleanups (back_to); @@ -2272,8 +2286,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format, struct gdbarch *gdbarch = get_type_arch (value_type (value)); make_cleanup (xfree, thevalue); LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char, - (gdb_byte *) thevalue, strlen (thevalue), - 0, &opts); + thevalue, len, 0, &opts); } else common_val_print (value, stb, 0, &opts, current_language); -- cgit v1.1