Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Peter Linss <peter@elemental.software>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix usage of to_string() for pretty-printers with children
Date: Thu, 25 May 2017 17:51:00 -0000	[thread overview]
Message-ID: <33B79B83-FB3D-4385-8B13-3BC10F8C58D1@elemental.software> (raw)
In-Reply-To: <83shjtkmo8.fsf@gnu.org>


> On May 25, 2017, at 7:59 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Peter Linss <peter@elemental.software>
>> Date: Wed, 24 May 2017 19:33:41 -0700
>> 
>> 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 examine the
>> 
>> @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.
>                                    ^
> Please add back the comma removed here.
> 
> The documentation part is approved with this gotcha fixed.
> 
> Thanks.


Revised patch with comma restored (not sure if you want a new email thread for small patch revisions like this):

—

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9fb70f6d2a..ff2992e433 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -29444,8 +29444,9 @@ reliable for a dynamic varobj.  Instead, you must examine the
 
 @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}.
 
 @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,
     }
 }
 
-#if HAVE_PYTHON
-
-static int
-dynamic_varobj_has_child_method (const struct varobj *var)
-{
-  PyObject *printer = 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.  */
 
@@ -2420,11 +2405,6 @@ varobj_value_get_print_value (struct value *value,
 
       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 = 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


  reply	other threads:[~2017-05-25 17:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25  2:33 Peter Linss
2017-05-25 10:06 ` Phil Muldoon
2017-05-25 17:42   ` Peter Linss
2017-06-14  2:36     ` Peter Linss
2017-05-25 14:59 ` Eli Zaretskii
2017-05-25 17:51   ` Peter Linss [this message]
2017-05-25 18:13     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33B79B83-FB3D-4385-8B13-3BC10F8C58D1@elemental.software \
    --to=peter@elemental.software \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox