This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] fix latest round of MI buglets
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Wed, 26 Aug 2009 14:32:39 -0600
- Subject: [python] fix latest round of MI buglets
- Reply-to: Tom Tromey <tromey at redhat dot com>
I'm checking this in on the python branch.
This adds some test cases for things Vladimir mentioned in his latest
email, and also has fixes for the problems.
I also fixed a crash I found while writing the new tests.
Tom
2009-08-26 Tom Tromey <tromey@redhat.com>
* varobj.c (dynamic_varobj_has_child_method): New function.
(value_get_print_value): Use it.
(install_new_value_visualizer): Do nothing if value==NULL.
2009-08-26 Tom Tromey <tromey@redhat.com>
* gdb.python/python-prettyprint.c (main): Add 'container2'. Add
extra dummy add_item call.
* gdb.python/python-mi.exp: Add new tests. Use
mi_create_dynamic_varobj.
* lib/mi-support.exp (mi_create_dynamic_varobj): New proc.
diff --git a/gdb/testsuite/gdb.python/python-mi.exp b/gdb/testsuite/gdb.python/python-mi.exp
index 095ee78..fc74fcf 100644
--- a/gdb/testsuite/gdb.python/python-mi.exp
+++ b/gdb/testsuite/gdb.python/python-mi.exp
@@ -48,7 +48,7 @@ mi_gdb_test "python execfile ('${srcdir}/${subdir}/${testfile}.py')" ""
mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${testfile}.c] \
"step to breakpoint"
-mi_create_floating_varobj container c \
+mi_create_dynamic_varobj container c \
"create container varobj, no pretty-printing"
mi_list_varobj_children container {
@@ -61,7 +61,7 @@ mi_delete_varobj container "delete varobj"
mi_gdb_test "-enable-pretty-printing" ""
-mi_create_floating_varobj container c \
+mi_create_dynamic_varobj container c \
"create container varobj"
mi_list_varobj_children container {
@@ -150,6 +150,16 @@ mi_list_varobj_children container {
mi_next "next over update 4"
+
+# Regression test: examine an object that has no children, then update
+# it to ensure that we don't print the children.
+mi_create_dynamic_varobj container2 c2 \
+ "create second container varobj"
+
+mi_gdb_test "-var-update container2" \
+ "\\^done,changelist=.." \
+ "update varobj, no children requested"
+
# This should only show the first child, because the update range has
# been set.
mi_varobj_update_dynamic container \
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 6bbbf1d..deca2e9 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -162,6 +162,7 @@ main ()
struct ss ssa[2];
string x = make_string ("this is x");
zzz_type c = make_container ("container");
+ zzz_type c2 = make_container ("container2");
const struct string_repr cstring = { { "const string" } };
/* Clearing by being `static' could invoke an other GDB C++ bug. */
struct nullstr nullstr;
@@ -206,6 +207,7 @@ main ()
add_item (&c, 1011);
c.elements[0] = 1023;
+ add_item (&c, 2222); /* dummy */
do_nothing ();
#endif
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 64bc28e..3a42704 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1214,6 +1214,14 @@ proc mi_create_varobj_checked { name expression type testname } {
$testname
}
+# Same as mi_create_floating_varobj, but assumes the test is creating
+# a dynamic varobj that has children, so the value must be "{...}".
+proc mi_create_dynamic_varobj {name expression testname} {
+ mi_gdb_test "-var-create $name @ $expression" \
+ "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\"{\\.\\.\\.}\",type=.*" \
+ $testname
+}
+
# Deletes the specified NAME.
proc mi_delete_varobj { name testname } {
mi_gdb_test "-var-delete $name" \
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 357c990..cbab433 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -923,6 +923,23 @@ install_dynamic_child (struct varobj *var,
}
}
+#if HAVE_PYTHON
+
+static int
+dynamic_varobj_has_child_method (struct varobj *var)
+{
+ struct cleanup *back_to;
+ PyObject *printer = var->pretty_printer;
+ int result;
+
+ back_to = varobj_ensure_python_env (var);
+ result = PyObject_HasAttr (printer, gdbpy_children_cst);
+ do_cleanups (back_to);
+ return result;
+}
+
+#endif
+
static int
update_dynamic_varobj_children (struct varobj *var,
VEC (varobj_p) **changed,
@@ -1363,8 +1380,9 @@ static void
install_new_value_visualizer (struct varobj *var)
{
#if HAVE_PYTHON
- /* If the constructor is None, then we want the raw value. */
- if (var->constructor != Py_None)
+ /* If the constructor is None, then we want the raw value. If VAR
+ does not have a value, just skip this. */
+ if (var->constructor != Py_None && var->value)
{
struct cleanup *cleanup;
PyObject *pretty_printer = NULL;
@@ -2385,12 +2403,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
{
/* First check to see if we have any children at all. If so,
we simply return {...}. */
- if (var->num_children == -1)
- {
- int dummy;
- update_dynamic_varobj_children (var, NULL, NULL, &dummy, 0, 0);
- }
- if (var->num_children > 0 || var->saved_item)
+ if (dynamic_varobj_has_child_method (var))
return xstrdup ("{...}");
if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))