From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31774 invoked by alias); 1 Aug 2012 18:11:05 -0000 Received: (qmail 31753 invoked by uid 22791); 1 Aug 2012 18:11:04 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Aug 2012 18:10:46 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q71IA7uM018408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 1 Aug 2012 14:10:46 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q71GgXC1022146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 1 Aug 2012 12:42:34 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Subject: RFC: fix PR 14386 Date: Wed, 01 Aug 2012 18:11:00 -0000 Message-ID: <873946woli.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00029.txt.bz2 This fixes PR python/14386. I'd like to commit this to the trunk and the 7.5 branch; the latter because it is a reasonably obvious, low-risk, and useful bug fix. The bug here is that a certain libstdc++ pretty-printer doesn't work in MI. What is going on is that the printer in question returns a Python list object from its 'children' method. This is perfectly fine. However, the varobj code uses PyIter_Check on the returned object, and this evaluates to false for a list. I think this is arguably a bug in Python, so I filed: http://bugs.python.org/issue15529 Meanwhile, it seems safest not to call PyIter_Check. We certainly don't need to -- the CLI doesn't -- because we can just call PyObject_GetIter and react appropriately if that fails. Built and tested on x86-64 Fedora 16. New test case included. Tom commit 4074f681d23d3ee12c92bbe128e55f9e0d5a142e Author: Tom Tromey Date: Wed Aug 1 10:30:11 2012 -0600 fix PR python/14386 PR python/14386: * varobj.c (update_dynamic_varobj_children): Don't call PyIter_Check. * gdb.python/py-mi.exp: Add test for printer whose children are a list. * gdb.python/py-prettyprint.c (struct children_as_list): New. (main): New variable children_as_list. * gdb.python/py-prettyprint.py (class pp_children_as_list): New. (register_pretty_printers): Register new printer. diff --git a/gdb/testsuite/gdb.python/py-mi.exp b/gdb/testsuite/gdb.python/py-mi.exp index a792e44..e7034a1 100644 --- a/gdb/testsuite/gdb.python/py-mi.exp +++ b/gdb/testsuite/gdb.python/py-mi.exp @@ -289,6 +289,10 @@ mi_gdb_test "-var-evaluate-expression me" \ "\\^done,value=\".*\"" \ "evaluate me varobj" +# Regression test for python/14836. +mi_create_dynamic_varobj children_as_list children_as_list \ + "printer whose children are returned as a list" + # C++ MI tests gdb_exit if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \ diff --git a/gdb/testsuite/gdb.python/py-prettyprint.c b/gdb/testsuite/gdb.python/py-prettyprint.c index 1ff9e05..b1a12b1 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.c +++ b/gdb/testsuite/gdb.python/py-prettyprint.c @@ -48,6 +48,10 @@ struct hint_error { int x; }; +struct children_as_list { + int x; +}; + #ifdef __cplusplus struct S : public s { int zs; @@ -252,6 +256,7 @@ main () struct ns ns, ns2; struct lazystring estring, estring2; struct hint_error hint_error; + struct children_as_list children_as_list; nstype.elements = narray; nstype.len = 0; diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index b02b90f..6e960e6 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -174,6 +174,18 @@ class pp_hint_error: def display_hint (self): raise Exception("hint failed") +class pp_children_as_list: + "Throw error from display_hint" + + def __init__(self, val): + self.val = val + + def to_string(self): + return 'children_as_list_val' + + def children (self): + return [('one', 1)] + class pp_outer: "Print struct outer" @@ -282,6 +294,9 @@ def register_pretty_printers (): 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 ('^struct children_as_list$')] = pp_children_as_list + pretty_printers_dict[re.compile ('^children_as_list$')] = pp_children_as_list + pretty_printers_dict[re.compile ('^memory_error$')] = MemoryErrorString pretty_printers_dict[re.compile ('^eval_type_s$')] = pp_eval_type diff --git a/gdb/varobj.c b/gdb/varobj.c index a75a40d..71b6436 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -1114,9 +1114,6 @@ update_dynamic_varobj_children (struct varobj *var, make_cleanup_py_decref (children); - if (!PyIter_Check (children)) - error (_("Returned value is not iterable")); - Py_XDECREF (var->child_iter); var->child_iter = PyObject_GetIter (children); if (!var->child_iter)