2010-04-14 Phil Muldoon <pmuldoon@redhat.com>
PR python/11381 * python/py-prettyprint.c (pretty_print_one_value): Test for Py_None. (print_string_repr): Test for Py_None. Set flags accordingly. Return value depending on return type. (print_children): Take a value indicating whether data was printed before this function was called. Alter output accordingly. (apply_val_pretty_printer): Capture return value from print_string_repr and pass to print_children. 2010-04-14 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-prettyprint.py (NoStringContainerPrinter): New printer. * gdb.python/py-prettyprint.c: Add justchildren struct, typedefs. * gdb.python/py-prettyprint.exp: New test for to_string returning None. * gdb.python/py-mi.exp: New test for to_string returning None. 2010-04-14 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Pretty Printing): Document behaviour when to_string returns None.
This commit is contained in:
parent
d594eacc9e
commit
79f283fe85
9 changed files with 180 additions and 47 deletions
|
@ -61,6 +61,16 @@ mi_list_varobj_children container {
|
|||
|
||||
mi_delete_varobj container "delete varobj"
|
||||
|
||||
mi_create_dynamic_varobj nscont nstype \
|
||||
"create nscont varobj, no pretty-printing"
|
||||
|
||||
mi_list_varobj_children nscont {
|
||||
{ nscont.len len 0 int }
|
||||
{ nscont.elements elements 1 "int ." }
|
||||
} "examine nscont children=0, no pretty-printing"
|
||||
|
||||
mi_delete_varobj nscont "delete varobj"
|
||||
|
||||
mi_gdb_test "-enable-pretty-printing" ""
|
||||
|
||||
mi_create_varobj_checked string string_1 \
|
||||
|
@ -239,4 +249,29 @@ mi_continue_to_line \
|
|||
|
||||
mi_varobj_update_with_type_change container int 0 "update after type change"
|
||||
|
||||
|
||||
mi_continue_to_line \
|
||||
[gdb_get_line_number {break to inspect struct and union} ${testfile}.c] \
|
||||
"step to outer breakpoint"
|
||||
|
||||
mi_create_dynamic_varobj nscont nstype \
|
||||
"create nstype varobj"
|
||||
|
||||
mi_list_varobj_children nscont {
|
||||
{ {nscont.\[0\]} {\[0\]} 0 int }
|
||||
{ {nscont.\[1\]} {\[1\]} 0 int }
|
||||
} "list children after setting update range"
|
||||
|
||||
mi_gdb_test "-var-set-visualizer nscont None" \
|
||||
"\\^done" \
|
||||
"clear visualizer"
|
||||
|
||||
mi_gdb_test "-var-update nscont" \
|
||||
"\\^done,changelist=\\\[\\\]" \
|
||||
"varobj update after clearing"
|
||||
|
||||
mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
|
||||
"\\^done" \
|
||||
"choose default visualizer"
|
||||
|
||||
remote_file host delete ${remote_python_file}
|
||||
|
|
|
@ -119,6 +119,15 @@ typedef struct string_repr
|
|||
|
||||
/* This lets us avoid malloc. */
|
||||
int array[100];
|
||||
int narray[10];
|
||||
|
||||
struct justchildren
|
||||
{
|
||||
int len;
|
||||
int *elements;
|
||||
};
|
||||
|
||||
typedef struct justchildren nostring_type;
|
||||
|
||||
struct container
|
||||
{
|
||||
|
@ -196,7 +205,9 @@ main ()
|
|||
const struct string_repr cstring = { { "const string" } };
|
||||
/* Clearing by being `static' could invoke an other GDB C++ bug. */
|
||||
struct nullstr nullstr;
|
||||
|
||||
nostring_type nstype;
|
||||
nstype.elements = narray;
|
||||
nstype.len = 0;
|
||||
|
||||
init_ss(&ss, 1, 2);
|
||||
init_ss(ssa+0, 3, 4);
|
||||
|
@ -249,5 +260,9 @@ main ()
|
|||
do_nothing ();
|
||||
#endif
|
||||
|
||||
nstype.elements[0] = 7;
|
||||
nstype.elements[1] = 42;
|
||||
nstype.len = 2;
|
||||
|
||||
return 0; /* break to inspect struct and union */
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ proc run_lang_tests {lang} {
|
|||
gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
|
||||
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
|
||||
|
||||
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
|
||||
gdb_test "continue" "Program exited normally\."
|
||||
|
||||
remote_file host delete ${remote_python_file}
|
||||
|
|
|
@ -53,6 +53,33 @@ class ContainerPrinter:
|
|||
def children(self):
|
||||
return self._iterator(self.val['elements'], self.val['len'])
|
||||
|
||||
# Test a printer where to_string is None
|
||||
class NoStringContainerPrinter:
|
||||
class _iterator:
|
||||
def __init__ (self, pointer, len):
|
||||
self.start = pointer
|
||||
self.pointer = pointer
|
||||
self.end = pointer + len
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if self.pointer == self.end:
|
||||
raise StopIteration
|
||||
result = self.pointer
|
||||
self.pointer = self.pointer + 1
|
||||
return ('[%d]' % int (result - self.start), result.dereference())
|
||||
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
return None
|
||||
|
||||
def children(self):
|
||||
return self._iterator(self.val['elements'], self.val['len'])
|
||||
|
||||
class pp_s:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
@ -190,8 +217,10 @@ def register_pretty_printers ():
|
|||
# both the C and C++ cases.
|
||||
pretty_printers_dict[re.compile ('^struct string_repr$')] = string_print
|
||||
pretty_printers_dict[re.compile ('^struct container$')] = ContainerPrinter
|
||||
pretty_printers_dict[re.compile ('^struct justchildren$')] = NoStringContainerPrinter
|
||||
pretty_printers_dict[re.compile ('^string_repr$')] = string_print
|
||||
pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
|
||||
pretty_printers_dict[re.compile ('^justchildren$')] = NoStringContainerPrinter
|
||||
|
||||
pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns
|
||||
pretty_printers_dict[re.compile ('^ns$')] = pp_ns
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue