Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Siva Chandra <sivachandra@google.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC - Python Scripting] New method gdb.Symtab.blocks_iterator - docs included
Date: Tue, 10 Apr 2012 01:38:00 -0000	[thread overview]
Message-ID: <87mx6k4b9t.fsf@fleche.redhat.com> (raw)
In-Reply-To: <CAGyQ6gyCWx3epM2AQQoo9xgY0c52yYuLeGkTN7+P_uK=jpNvHw@mail.gmail.com>	(Siva Chandra's message of "Tue, 10 Apr 2012 00:04:10 +0530")

>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Siva> While the work on Objfile.symtabs (or Objfile.iterator) is pending, I
Siva> want to complete the API for the exploratory path Objfile => Symtabs
Siva> => Blocks => Symbols.  This patch adds the missing link Symtabs =>
Siva> Blocks.  The method Symtab.blocks_iterator returns an iterator to
Siva> iterate over the scope blocks of a symtab.  The patch is attached and
Siva> the ChangeLog is as follows:

Thanks.

Siva> +   ** A new method 'blocks_iterator' on gdb.Symtab objects which returns
Siva> +      an iterator to iterate over the scope blocks (gdb.Block objects) of
Siva> +      the symbol table (gdb.Symtab object).

It seems to me that the Symtab itself could provide the iterator so you
could just write:

    for block in symtab:
      ...

The precedent here is that gdb.Block is also an iterator over symbols.

Alternatively, 'Symtab.blocks'.
I find 'blocks_iterator' a bit too wordy somehow.

What do you think of those?

Siva> +   /* The iterator holds a reference to the symtab_object.  */
Siva> +   Py_INCREF (self);
Siva> + 
Siva> +   iter = PyObject_New (symtab_blocks_iterator_object,
Siva> +                        &symtab_blocks_iterator_object_type);
Siva> +   if (iter)
Siva> +     {
Siva> +       iter->symtab_obj = symtab_obj;
Siva> +       iter->iter_index = 0;
Siva> +     }
Siva> + 
Siva> +   return (PyObject *) iter;

This leaks a reference to 'self' if PyObject_New fails.
Moving the incref into the 'if' would fix it.

Siva> + static void
Siva> + symtab_blocks_iterator_dealloc (PyObject *self)
Siva> + {
Siva> +   symtab_blocks_iterator_object *iter;
Siva> + 
Siva> +   /* Decrement the reference to the symtab_object.  */
Siva> +   if (self)

Can you ever get here with self==NULL?
I expect not, but I am not 100% sure.
If not, remove the if.

Siva> +     {
Siva> +       iter = (symtab_blocks_iterator_object *) self;
Siva> +       Py_DECREF ((PyObject *) iter->symtab_obj);

It might be a little cleaner if symtab_obj is just a plain PyObject*
and you downcast it in the one place that uses it.

Siva> +   block_object = block_to_block_object (block, symtab->objfile);
Siva> +   if (! block_object)
Siva> +     {
Siva> +       PyErr_SetString (PyExc_RuntimeError,
Siva> +                        _("Unable to get the next gdb.Block object."));

If block_to_block_object fails, then the error will already be set.
I think it is generally better to propagate the original exception in
cases like this.  Otherwise, the new exception may obscure some more
fundamental error.

Siva> +   (iter->iter_index)++;

Also I'm curious if an error should invalidate the iterator in some way.

Siva> ! # Proc to setup and get the symbol table in the Python environment.
Siva> ! proc setup_python_env { line_no } {
Siva> !     gdb_breakpoint $line_no
Siva> !     gdb_continue_to_breakpoint "Block break here."
Siva> !     gdb_py_test_silent_cmd "python def func_symbol(block): return block.function" "Define a func to get the function symbols" "0"

If you run the same set of tests twice from a .exp you should use
with_test_prefix to ensure the tests have unique names.

Siva> + # Compile the source file as a C++ file and test again.
Siva> + if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {

We were recently discussing that it is preferable to give each
executable its own name, so that if the test fails it is simpler to
reproduce the problem from outside dejagnu.

So, please choose a new name for the executable here.

Tom


  parent reply	other threads:[~2012-04-10  1:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-09 18:34 Siva Chandra
2012-04-09 20:47 ` Eli Zaretskii
2012-04-10  1:38 ` Tom Tromey [this message]
2012-04-10  7:45   ` Siva Chandra
2012-04-10 17:16     ` Doug Evans
2012-04-10 22:21     ` Tom Tromey
2012-04-11  4:59       ` Siva Chandra
2012-04-11  5:44         ` Doug Evans
2012-04-12 15:20         ` 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=87mx6k4b9t.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sivachandra@google.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