Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Phil Muldoon <pmuldoon@redhat.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [patch][python] Add symbol, symbol table and frame block support  to GDB API
Date: Thu, 04 Feb 2010 23:25:00 -0000	[thread overview]
Message-ID: <m3r5p0inxy.fsf@fleche.redhat.com> (raw)
In-Reply-To: <4B66DA35.7080701@redhat.com> (Phil Muldoon's message of "Mon, 01 	Feb 2010 13:42:13 +0000")

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> This patch adds symbol, symbol table and block support to the
Phil> Python GDB API.  It also reconstitutes several functions missing
Phil> from py-frame, and adds the glue back into python.c to make these
Phil> code segments work together.  This is for the most part a merge of
Phil> the code that has existed in the archer repository for sometime.
Phil> OK?

Thanks for doing this.

The code bits look mostly ok to me.  There are a few formatting nits, of
course ;-), but also a more substantial issue.

Phil> +typedef struct {
Phil> +  PyObject_HEAD
Phil> +  struct block *block;
Phil> +} block_object;

When an objfile is destroyed, so are blocks coming from that objfile.
However, this module doesn't take that into account.  That means it can
lead to crashes.

One possible fix would be to have a notion of an "invalid" Block object,
where the block field is ==NULL.  Then each method of Block would check
validity right away, throwing an error if it is invalid.  Then, arrange
to clear these fields when an objfile is destroyed.  See py-type.c for
an example of how the latter is done -- Types can't be invalidated this
way but they are instead copied to the heap when the objfile disappears.

This same problem affects symtabs and I suppose sals and block iterators
as well, by extension.

Phil> +static PyObject *
Phil> +blpy_get_superblock (PyObject *self, void *closure)
Phil> +{
[...]

Phil> +PyObject *
Phil> +block_to_block_object (struct block *block)
Phil> +{

I'm sorry to foist this off on you, but I think exported functions like
block_to_block_object should have header comments.  Functions like
blpy_get_superblock, which are just methods, don't need comments (IMO).

Phil> +static PyObject *
Phil> +blpy_block_syms_iter (PyObject *self)
Phil> +{
Phil> +  return self;

Does this need a Py_INCREF?

Phil> +  return (sym == NULL)? NULL : symbol_to_symbol_object (sym);

Space before the "?"

Phil> +  ret = asprintf (&s, "symbol for %s",
Phil> +		  SYMBOL_PRINT_NAME (((symbol_object *) self)->symbol));

Use xstrprintf instead.

Phil> +  return PyBool_FromLong (!SYMBOL_IS_ARGUMENT (self_sym->symbol)
Phil> +      && (class == LOC_LOCAL || class == LOC_REGISTER || class == LOC_STATIC
Phil> +	  || class == LOC_COMPUTED || class == LOC_OPTIMIZED_OUT));

The indentation looks weird here.

Phil> +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)

Newline before gdbpy_lookup_symbol.

Phil> +  ret_tuple = PyTuple_New (2);
Phil> +  if (!ret_tuple)
Phil> +    {
Phil> +      PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object.");
Phil> +      return NULL;
Phil> +    }

If ret_tuple==NULL, you don't need to call PyErr_SetString, just return
NULL; PyTuple_New will have set the error.

Phil> +  ret = asprintf (&s, "symbol table for %s",
Phil> +		  ((symtab_object *) self)->symtab->filename);

xstrprintf

Phil> +static PyObject *
Phil> +stpy_get_filename (PyObject *self, void *closure)
Phil> +{
Phil> +  symtab_object *self_symtab = (symtab_object *) self;
Phil> +  PyObject *str_obj;
Phil> +
Phil> +  /* FIXME: Can symtab->filename really be NULL?  */
Phil> +  if (self_symtab->symtab->filename)

Could you take a quick look through other parts of gdb and see if
anything else does this check?  I'd prefer we eliminate this FIXME
before it goes in.

Phil> +  filename = (sal_obj->symtab == (symtab_object *) Py_None)? "<unknown>" :
Phil> +					   sal_obj->symtab->symtab->filename;

Formatting looks weird.

Phil> +  ret = asprintf (&s, "symbol and line for %s, line %d", filename,
Phil> +		  sal_obj->sal->line);

xstrprintf

Phil> +  sal_obj->sal = (struct symtab_and_line *)
Phil> +				    xmalloc (sizeof (struct symtab_and_line));
Phil> +  *(sal_obj->sal) = sal;

This assignment looks weird; just use xmemdup instead.

Tom


  parent reply	other threads:[~2010-02-04 23:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 13:42 Phil Muldoon
2010-02-01 20:54 ` Eli Zaretskii
2010-02-02 10:24   ` Phil Muldoon
2010-02-02 20:14     ` Eli Zaretskii
2010-02-03 20:55       ` Phil Muldoon
2010-02-05 10:53         ` Phil Muldoon
2010-02-05 18:06           ` Eli Zaretskii
2010-02-05 11:05         ` Eli Zaretskii
2010-02-04 23:25 ` Tom Tromey [this message]
2010-02-15 15:15   ` Phil Muldoon
2010-02-15 18:45     ` Eli Zaretskii
2010-02-15 23:39       ` Phil Muldoon
2010-02-16  4:12         ` Eli Zaretskii
2010-02-18  2:50     ` Tom Tromey
2010-02-19 14:15       ` Phil Muldoon
2010-02-19 14:28         ` Eli Zaretskii
2010-02-19 15:13           ` Phil Muldoon
2010-02-23 23:05         ` Tom Tromey
2010-02-24 16:58           ` Phil Muldoon
2010-02-24 17:22             ` Tom Tromey
2010-02-24 21:49               ` Phil Muldoon
2010-02-24 18:43             ` Eli Zaretskii
2010-02-23 23:09         ` 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=m3r5p0inxy.fsf@fleche.redhat.com \
    --to=tromey@redhat.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