From: Oliver Buchtala <oliver.buchtala@googlemail.com>
To: Phil Muldoon <pmuldoon@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: patch for #14363
Date: Mon, 06 Aug 2012 11:12:00 -0000 [thread overview]
Message-ID: <501FA677.6030404@googlemail.com> (raw)
In-Reply-To: <501F9FA1.9060203@redhat.com>
On 06.08.2012 12:42, Phil Muldoon wrote:
> On 08/02/2012 05:21 PM, Oliver Buchtala wrote:
>> From 05a921d423793db93dfead59c9fe12d342f55d75 Mon Sep 17 00:00:00 2001
>> From: Oliver Buchtala <oliver.buchtala@googlemail.com>
>> Date: Wed, 1 Aug 2012 21:59:43 +0200
>> Subject: [PATCH] Adapt py-prettyprint to inform pretty-printer about current
>> recursion level.
>>
>> ---
>> gdb/python/py-prettyprint.c | 3 +++
>> gdb/python/python-internal.h | 1 +
>> gdb/python/python.c | 2 ++
>> 3 files changed, 6 insertions(+)
> Thanks.
>
> Needs a GNU style ChangeLog, testcase and documentation
> additions.
>
> I am having trouble understanding what you are doing with "recurse"
> attribute. From valprint.c, in the GDB sources (which calls
> apply_val_pretty_printer, among others):
>
> "RECURSE indicates the amount of indentation to supply before
> continuation lines; this amount is roughly twice the value of
> RECURSE."
>
> So I am not sure that this is the value you want? Anyway, I think you
> want the number of recursions for that printer, not the recurse value
> being supplied to apply_val_pretty_printer. A testcase would help
> here to understand your intention.
>
>> diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
>> index 86d4f2c..d5c6b66 100644
>> --- a/gdb/python/py-prettyprint.c
>> +++ b/gdb/python/py-prettyprint.c
>> @@ -476,6 +476,9 @@ print_children (PyObject *printer, const char *hint,
>> if (! PyObject_HasAttr (printer, gdbpy_children_cst))
>> return;
>>
>> + if ( PyObject_HasAttr (printer, gdbpy_level_cst))
>> + PyObject_SetAttr(printer, gdbpy_level_cst, PyInt_FromLong((long) recurse));
>> +
> There are a few issues with this patch hunk:
>
> * It is not clear in the documentation, but PyInt_FromLong can raise a
> PyErr_NoMemory exception, so you need to NULL check the return and
> dispatch the exception appropriately.
>
> * This leaks a reference from PyInt_FromLong. PyObject_SetAttr
> increments the reference count of the right side of "=" Python
> equivalent (IE foo.bar = baz), which in this case is the integer. So
> the transient reference from PyInt_FromLong will last forever. You
> you need to assign the results of PyInt_FromLong to a variable and
> call Py_DECREF on it after the "PyObject_SetAttr" call.
>
> * PyObject_SetAttr can fail, so the code needs to deal with this
> contingency.
>
> * Why PyInt_FromLong over PyLong_FromLong?
>
> Beyond the patch fixes, is it not possible to count the recursion
> level by some internal bookkeeping in the printer? I have no problem
> with including the attribute if it is helpful, or clearer to solve the
> problem, but I am curious if you have tried the alternative, if
> possible?
>
> Cheers,
>
> Phil
Thanks,
I see there are lots of deficiencies with my patch. Sorry for that.
You are right in all your points.
I was not aware that recurse == indentation. (misnaming? ;) )
For the second proposal, I need a set data structure for longs.
Do you have such a data structure in gdb somewhere? Or which should I use?
Then I would offer a prototype implementation.
Regards,
Oliver
next prev parent reply other threads:[~2012-08-06 11:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-02 16:21 Oliver Buchtala
2012-08-06 10:43 ` Phil Muldoon
2012-08-06 11:12 ` Oliver Buchtala [this message]
2012-08-06 11:19 ` Sergio Durigan Junior
2012-09-12 17:40 ` Tom Tromey
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=501FA677.6030404@googlemail.com \
--to=oliver.buchtala@googlemail.com \
--cc=gdb-patches@sourceware.org \
--cc=pmuldoon@redhat.com \
/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