2011-07-28 Phil Muldoon <pmuldoon@redhat.com>
* varobj.c (value_get_print_value): Move hint check later into the function. Comment function. Free thevalue before reusing it. 2011-07-28 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-mi.exp: Test printers returning string hint, and also not returning a value. * gdb.python/py-prettyprint.c: Add testcase for above. * gdb.python/py-prettyprint.py: Add test printer for above.
This commit is contained in:
parent
e89702a8bd
commit
00bd41d6bc
6 changed files with 71 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2011-07-28 Phil Muldoon <pmuldoon@redhat.com>
|
||||||
|
|
||||||
|
* varobj.c (value_get_print_value): Move hint check later into the
|
||||||
|
function. Comment function. Free thevalue before reusing it.
|
||||||
|
|
||||||
2011-07-27 Jan Kratochvil <jan.kratochvil@redhat.com>
|
2011-07-27 Jan Kratochvil <jan.kratochvil@redhat.com>
|
||||||
Pedro Alves <pedro@codesourcery.com>
|
Pedro Alves <pedro@codesourcery.com>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
2011-07-28 Phil Muldoon <pmuldoon@redhat.com>
|
||||||
|
|
||||||
|
* gdb.python/py-mi.exp: Test printers returning string hint, and
|
||||||
|
also not returning a value.
|
||||||
|
* gdb.python/py-prettyprint.c: Add testcase for above.
|
||||||
|
* gdb.python/py-prettyprint.py: Add test printer for above.
|
||||||
|
|
||||||
2011-07-27 Jan Kratochvil <jan.kratochvil@redhat.com>
|
2011-07-27 Jan Kratochvil <jan.kratochvil@redhat.com>
|
||||||
|
|
||||||
* gdb.dwarf2/dw2-simple-locdesc.S: Change DWARF version to 3.
|
* gdb.dwarf2/dw2-simple-locdesc.S: Change DWARF version to 3.
|
||||||
|
|
|
@ -284,6 +284,13 @@ mi_list_varobj_children nstype2 {
|
||||||
{ {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
|
{ {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
|
||||||
} "list children after setting exception flag"
|
} "list children after setting exception flag"
|
||||||
|
|
||||||
|
mi_create_varobj me me \
|
||||||
|
"create me varobj"
|
||||||
|
|
||||||
|
mi_gdb_test "-var-evaluate-expression me" \
|
||||||
|
"\\^done,value=\"<error reading variable: Cannot access memory.>.*\"" \
|
||||||
|
"evaluate me varobj"
|
||||||
|
|
||||||
# C++ MI tests
|
# C++ MI tests
|
||||||
gdb_exit
|
gdb_exit
|
||||||
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
|
||||||
|
|
|
@ -149,6 +149,11 @@ struct justchildren
|
||||||
|
|
||||||
typedef struct justchildren nostring_type;
|
typedef struct justchildren nostring_type;
|
||||||
|
|
||||||
|
struct memory_error
|
||||||
|
{
|
||||||
|
const char *s;
|
||||||
|
};
|
||||||
|
|
||||||
struct container
|
struct container
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
|
@ -227,6 +232,7 @@ main ()
|
||||||
/* Clearing by being `static' could invoke an other GDB C++ bug. */
|
/* Clearing by being `static' could invoke an other GDB C++ bug. */
|
||||||
struct nullstr nullstr;
|
struct nullstr nullstr;
|
||||||
nostring_type nstype, nstype2;
|
nostring_type nstype, nstype2;
|
||||||
|
struct memory_error me;
|
||||||
struct ns ns, ns2;
|
struct ns ns, ns2;
|
||||||
struct lazystring estring, estring2;
|
struct lazystring estring, estring2;
|
||||||
struct hint_error hint_error;
|
struct hint_error hint_error;
|
||||||
|
@ -234,6 +240,8 @@ main ()
|
||||||
nstype.elements = narray;
|
nstype.elements = narray;
|
||||||
nstype.len = 0;
|
nstype.len = 0;
|
||||||
|
|
||||||
|
me.s = "blah";
|
||||||
|
|
||||||
init_ss(&ss, 1, 2);
|
init_ss(&ss, 1, 2);
|
||||||
init_ss(ssa+0, 3, 4);
|
init_ss(ssa+0, 3, 4);
|
||||||
init_ss(ssa+1, 5, 6);
|
init_ss(ssa+1, 5, 6);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
# printers.
|
# printers.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import gdb
|
||||||
|
|
||||||
# Test returning a Value from a printer.
|
# Test returning a Value from a printer.
|
||||||
class string_print:
|
class string_print:
|
||||||
|
@ -186,6 +187,18 @@ class pp_outer:
|
||||||
yield 's', self.val['s']
|
yield 's', self.val['s']
|
||||||
yield 'x', self.val['x']
|
yield 'x', self.val['x']
|
||||||
|
|
||||||
|
class MemoryErrorString:
|
||||||
|
"Raise an error"
|
||||||
|
|
||||||
|
def __init__(self, val):
|
||||||
|
self.val = val
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
raise gdb.MemoryError ("Cannot access memory.");
|
||||||
|
|
||||||
|
def display_hint (self):
|
||||||
|
return 'string'
|
||||||
|
|
||||||
def lookup_function (val):
|
def lookup_function (val):
|
||||||
"Look-up and return a pretty-printer that can print val."
|
"Look-up and return a pretty-printer that can print val."
|
||||||
|
|
||||||
|
@ -261,6 +274,8 @@ def register_pretty_printers ():
|
||||||
pretty_printers_dict[re.compile ('^struct hint_error$')] = pp_hint_error
|
pretty_printers_dict[re.compile ('^struct hint_error$')] = pp_hint_error
|
||||||
pretty_printers_dict[re.compile ('^hint_error$')] = pp_hint_error
|
pretty_printers_dict[re.compile ('^hint_error$')] = pp_hint_error
|
||||||
|
|
||||||
|
pretty_printers_dict[re.compile ('^memory_error$')] = MemoryErrorString
|
||||||
|
|
||||||
pretty_printers_dict = {}
|
pretty_printers_dict = {}
|
||||||
|
|
||||||
register_pretty_printers ()
|
register_pretty_printers ()
|
||||||
|
|
38
gdb/varobj.c
38
gdb/varobj.c
|
@ -2610,25 +2610,21 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
|
||||||
|
|
||||||
if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
|
if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
|
||||||
{
|
{
|
||||||
char *hint;
|
|
||||||
struct value *replacement;
|
struct value *replacement;
|
||||||
PyObject *output = NULL;
|
PyObject *output = NULL;
|
||||||
|
|
||||||
hint = gdbpy_get_display_hint (value_formatter);
|
|
||||||
if (hint)
|
|
||||||
{
|
|
||||||
if (!strcmp (hint, "string"))
|
|
||||||
string_print = 1;
|
|
||||||
xfree (hint);
|
|
||||||
}
|
|
||||||
|
|
||||||
output = apply_varobj_pretty_printer (value_formatter,
|
output = apply_varobj_pretty_printer (value_formatter,
|
||||||
&replacement,
|
&replacement,
|
||||||
stb);
|
stb);
|
||||||
|
|
||||||
|
/* If we have string like output ... */
|
||||||
if (output)
|
if (output)
|
||||||
{
|
{
|
||||||
make_cleanup_py_decref (output);
|
make_cleanup_py_decref (output);
|
||||||
|
|
||||||
|
/* If this is a lazy string, extract it. For lazy
|
||||||
|
strings we always print as a string, so set
|
||||||
|
string_print. */
|
||||||
if (gdbpy_is_lazy_string (output))
|
if (gdbpy_is_lazy_string (output))
|
||||||
{
|
{
|
||||||
gdbpy_extract_lazy_string (output, &str_addr, &type,
|
gdbpy_extract_lazy_string (output, &str_addr, &type,
|
||||||
|
@ -2638,12 +2634,27 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* If it is a regular (non-lazy) string, extract
|
||||||
|
it and copy the contents into THEVALUE. If the
|
||||||
|
hint says to print it as a string, set
|
||||||
|
string_print. Otherwise just return the extracted
|
||||||
|
string as a value. */
|
||||||
|
|
||||||
PyObject *py_str
|
PyObject *py_str
|
||||||
= python_string_to_target_python_string (output);
|
= python_string_to_target_python_string (output);
|
||||||
|
|
||||||
if (py_str)
|
if (py_str)
|
||||||
{
|
{
|
||||||
char *s = PyString_AsString (py_str);
|
char *s = PyString_AsString (py_str);
|
||||||
|
char *hint;
|
||||||
|
|
||||||
|
hint = gdbpy_get_display_hint (value_formatter);
|
||||||
|
if (hint)
|
||||||
|
{
|
||||||
|
if (!strcmp (hint, "string"))
|
||||||
|
string_print = 1;
|
||||||
|
xfree (hint);
|
||||||
|
}
|
||||||
|
|
||||||
len = PyString_Size (py_str);
|
len = PyString_Size (py_str);
|
||||||
thevalue = xmemdup (s, len + 1, len + 1);
|
thevalue = xmemdup (s, len + 1, len + 1);
|
||||||
|
@ -2662,6 +2673,9 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* If the printer returned a replacement value, set VALUE
|
||||||
|
to REPLACEMENT. If there is not a replacement value,
|
||||||
|
just use the value passed to this function. */
|
||||||
if (replacement)
|
if (replacement)
|
||||||
value = replacement;
|
value = replacement;
|
||||||
}
|
}
|
||||||
|
@ -2672,12 +2686,18 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
|
||||||
get_formatted_print_options (&opts, format_code[(int) format]);
|
get_formatted_print_options (&opts, format_code[(int) format]);
|
||||||
opts.deref_ref = 0;
|
opts.deref_ref = 0;
|
||||||
opts.raw = 1;
|
opts.raw = 1;
|
||||||
|
|
||||||
|
/* If the THEVALUE has contents, it is a regular string. */
|
||||||
if (thevalue)
|
if (thevalue)
|
||||||
LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
|
LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
|
||||||
else if (string_print)
|
else if (string_print)
|
||||||
|
/* Otherwise, if string_print is set, and it is not a regular
|
||||||
|
string, it is a lazy string. */
|
||||||
val_print_string (type, encoding, str_addr, len, stb, &opts);
|
val_print_string (type, encoding, str_addr, len, stb, &opts);
|
||||||
else
|
else
|
||||||
|
/* All other cases. */
|
||||||
common_val_print (value, stb, 0, &opts, current_language);
|
common_val_print (value, stb, 0, &opts, current_language);
|
||||||
|
|
||||||
thevalue = ui_file_xstrdup (stb, NULL);
|
thevalue = ui_file_xstrdup (stb, NULL);
|
||||||
|
|
||||||
do_cleanups (old_chain);
|
do_cleanups (old_chain);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue