aboutsummaryrefslogtreecommitdiff
path: root/gdb/varobj.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-10-15 18:54:13 +0000
committerTom Tromey <tromey@redhat.com>2010-10-15 18:54:13 +0000
commit09ca9e2e34b93e8e12d6a0a4bad469b2b4c2f415 (patch)
tree27415ab68602f61368e4773b277271eda76fb144 /gdb/varobj.c
parent92163a10dcb34785a2fc74a05c3e890fbe700731 (diff)
downloadgdb-09ca9e2e34b93e8e12d6a0a4bad469b2b4c2f415.zip
gdb-09ca9e2e34b93e8e12d6a0a4bad469b2b4c2f415.tar.gz
gdb-09ca9e2e34b93e8e12d6a0a4bad469b2b4c2f415.tar.bz2
PR python/11948:
* varobj.c (value_get_print_value): Use val_print_string to print lazy strings. * python/py-prettyprint.c (print_string_repr): Use val_print_string to print lazy strings. Fix cleanup logic. (print_children): Likewise. * python/python-internal.h (gdbpy_extract_lazy_string): Update. * python/py-lazy-string.c (gdbpy_extract_lazy_string): Rewrite. Change return type to 'void', add 'addr' argument. * value.h (val_print_string): Update. * valprint.c (val_print_string): Add 'encoding' argument. * printcmd.c (print_formatted): Update. * p-valprint.c (pascal_val_print): Update. * m2-valprint.c (print_unpacked_pointer): Update. (m2_print_array_contents): Likewise. * jv-valprint.c (java_value_print): Update. * f-valprint.c (f_val_print): Update. * c-valprint.c (c_val_print): Update. * auxv.c (fprint_target_auxv): Update.
Diffstat (limited to 'gdb/varobj.c')
-rw-r--r--gdb/varobj.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/gdb/varobj.c b/gdb/varobj.c
index e56bbf7..2eacfa2 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2479,13 +2479,15 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
struct varobj *var)
{
struct ui_file *stb;
- struct cleanup *old_chain;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
gdb_byte *thevalue = NULL;
struct value_print_options opts;
struct type *type = NULL;
long len = 0;
char *encoding = NULL;
struct gdbarch *gdbarch = NULL;
+ CORE_ADDR str_addr;
+ int string_print = 0;
if (value == NULL)
return NULL;
@@ -2493,9 +2495,10 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
{
- struct cleanup *back_to = varobj_ensure_python_env (var);
PyObject *value_formatter = var->pretty_printer;
+ varobj_ensure_python_env (var);
+
if (value_formatter)
{
/* First check to see if we have any children at all. If so,
@@ -2507,7 +2510,6 @@ 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);
@@ -2522,10 +2524,13 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
&replacement);
if (output)
{
+ make_cleanup_py_decref (output);
+
if (gdbpy_is_lazy_string (output))
{
- thevalue = gdbpy_extract_lazy_string (output, &type,
- &len, &encoding);
+ gdbpy_extract_lazy_string (output, &str_addr, &type,
+ &len, &encoding);
+ make_cleanup (free_current_contents, &encoding);
string_print = 1;
}
else
@@ -2541,38 +2546,36 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
thevalue = xmemdup (s, len + 1, len + 1);
type = builtin_type (gdbarch)->builtin_char;
Py_DECREF (py_str);
+
+ if (!string_print)
+ {
+ do_cleanups (old_chain);
+ return thevalue;
+ }
+
+ make_cleanup (xfree, thevalue);
}
else
gdbpy_print_stack ();
}
- Py_DECREF (output);
- }
- if (thevalue && !string_print)
- {
- do_cleanups (back_to);
- xfree (encoding);
- return thevalue;
}
if (replacement)
value = replacement;
}
}
- do_cleanups (back_to);
}
#endif
stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ make_cleanup_ui_file_delete (stb);
get_formatted_print_options (&opts, format_code[(int) format]);
opts.deref_ref = 0;
opts.raw = 1;
if (thevalue)
- {
- make_cleanup (xfree, thevalue);
- make_cleanup (xfree, encoding);
- LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
- }
+ LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
+ else if (string_print)
+ val_print_string (type, encoding, str_addr, len, stb, &opts);
else
common_val_print (value, stb, 0, &opts, current_language);
thevalue = ui_file_xstrdup (stb, NULL);