From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3214 invoked by alias); 25 May 2017 02:33:46 -0000 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 Received: (qmail 3184 invoked by uid 89); 25 May 2017 02:33:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=in-house, inhouse, isn, isn=e2?= X-HELO: smtp.elemental.software Received: from smtp.elemental.software (HELO smtp.elemental.software) (45.33.60.119) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 May 2017 02:33:43 +0000 Received: from [IPv6:2001:470:879a::d847:c47a:9f25:c1a] (unknown [IPv6:2001:470:879a:0:d847:c47a:9f25:c1a]) (Authenticated sender: peter@elemental.software) by smtp.elemental.software (Postfix) with ESMTPSA id D0079265DE for ; Wed, 24 May 2017 19:33:45 -0700 (PDT) From: Peter Linss Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] Fix usage of to_string() for pretty-printers with children Message-Id: Date: Thu, 25 May 2017 02:33:00 -0000 To: gdb-patches@sourceware.org X-SW-Source: 2017-05/txt/msg00533.txt.bz2 Currently when using python pretty-printers that have children in the mi in= terpreter, the value of the variable object will always return =E2=80=9C{..= .}=E2=80=9D, this change will return the result of the pretty-printer=E2=80= =99s to_string() method if present. If the pretty-printer has children but = doesn=E2=80=99t have a to_string() method, then =E2=80=9C{...}=E2=80=9D wil= l still be returned. This allows pretty-printers to optionally return a brief summary of the var= iable in addition to the expanded list of children and makes the behavior u= nder the mi interpreter match that of the regular interpreter. This fixes bug 11335. I also removed the dynamic_varobj_has_child_method function as it wasn't do= ing anything that hadn=E2=80=99t already been done in the varobj_value_get_= print_value function and isn=E2=80=99t used elsewhere. Tested with Eclipse and the libstdc++-v3 pretty-printer as well as custom p= retty-printers for an in-house project and SublimeGDB (SublimeGDB required = some additional changes to properly support pretty-printers but those are n= ot related to this change). gdb/ChangeLog: * varobj.c (varobj_value_get_print_value): Call pretty-printer to_string method for value if present even when children=20 method is available. (dynamic_varobj_has_child_method) Remove unused function. gdb/doc/ChangeLog: * gdb.texinfo (Variable Objects, Result): Update description of value to reflect to_string output. --- diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9fb70f6d2a..05e5b868ed 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -29444,8 +29444,9 @@ reliable for a dynamic varobj. Instead, you must e= xamine the =20 @item value The varobj's scalar value. For a varobj whose type is some sort of -aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value -will not be interesting. +aggregate (e.g., a @code{struct}) this value will not be interesting. +For a dynamic varobj, this value comes from the Python pretty-printer +object's @code{to_string} method, if present. @xref{Pretty Printing API}. =20 @item type The varobj's type. This is a string representation of the type, as diff --git a/gdb/varobj.c b/gdb/varobj.c index 7bd549d45c..925c6318a8 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -686,21 +686,6 @@ install_dynamic_child (struct varobj *var, } } =20 -#if HAVE_PYTHON - -static int -dynamic_varobj_has_child_method (const struct varobj *var) -{ - PyObject *printer =3D var->dynamic->pretty_printer; - - if (!gdb_python_initialized) - return 0; - - gdbpy_enter_varobj enter_py (var); - return PyObject_HasAttr (printer, gdbpy_children_cst); -} -#endif - /* A factory for creating dynamic varobj's iterators. Returns an iterator object suitable for iterating over VAR's children. */ =20 @@ -2420,11 +2405,6 @@ varobj_value_get_print_value (struct value *value, =20 if (value_formatter) { - /* First check to see if we have any children at all. If so, - we simply return {...}. */ - if (dynamic_varobj_has_child_method (var)) - return "{...}"; - if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst)) { struct value *replacement; @@ -2486,6 +2466,13 @@ varobj_value_get_print_value (struct value *value, if (replacement) value =3D replacement; } + else + { + /* If we don't have to_string but we have children, + we simply return {...}. */ + if (PyObject_HasAttr (value_formatter, gdbpy_children_cst)) + return "{...}"; + } } } #endif --