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 - GDB Python API] New gdb.Architecture class
Date: Mon, 21 Jan 2013 17:09:00 -0000	[thread overview]
Message-ID: <87sj5u31ku.fsf@fleche.redhat.com> (raw)
In-Reply-To: <CAGyQ6gwAU-Qj-jkhj7gA7rG=xQOcZbp=g4Km8A3b6bLfsCWMqg@mail.gmail.com>	(Siva Chandra's message of "Mon, 21 Jan 2013 06:08:14 -0800")

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

Siva> http://sourceware.org/ml/gdb-patches/2013-01/msg00296.html, the
Siva> attached patch adds a new class 'gdb.Architecture' with a single
Siva> method 'name'. I will add tests and docs after we are OK with the code
Siva> changes.

I think the basic idea is fine.
I found a few nits in the patch, nothing too serious.

Siva> +struct gdbarch *
Siva> +arch_object_to_gdbarch (PyObject *obj)
Siva> +{
Siva> +  arch_object *py_arch = (arch_object *) obj;
Siva> +  return py_arch->gdbarch;

Missing newline after declaration.

Siva> +PyObject *
Siva> +gdbarch_to_arch_object (struct gdbarch *gdbarch)
Siva> +{
Siva> +  arch_object *obj = PyObject_New (arch_object, &arch_object_type);
Siva> +  if (obj == NULL)
Siva> +    {
Siva> +      PyErr_SetString (PyExc_MemoryError,
Siva> +                       _("Could not allocate architectire object"));
Siva> +      return NULL;
Siva> +    }
Siva> +
Siva> +  obj->gdbarch = gdbarch;
Siva> +  return (PyObject *) obj;
Siva> +}

Likewise.

Also, I think there's no need to call PyErr_SetString here.
Just return NULL; PyObject_New will have already set the error
appropriately.

One other question is whether we care about object identity.
gdbarch_to_arch_object returns a new object each time.
Either way is fine depending on circumstances -- we do both already in
gdb -- but it ought to be an explicit choice.

Siva> +static PyObject *
Siva> +archpy_name (PyObject *self, PyObject *args) {

Wrong brace placement.

Siva> +  PyObject *py_name = Py_BuildValue ("s", name);
Siva> +
Siva> +  return py_name;

Just use PyString_FromString here.

Siva> +PyObject *
Siva> +gdbpy_current_arch (PyObject *self, PyObject *args) {

Wrong brace placement.

Do we need this function?  The "current arch" is kind of a problematic
feature.  It is semi-exposed to Python right now, but I think we're
mostly agreed that this was an early mistake.

I think the more desirable approach would be to have arch methods on
the appropriate objects -- Frame, but also whatever else, say maybe
objfile or inferior (I'm not really all that sure...).

Anyway, if you do need it:

Siva> +  struct gdbarch *curr_arch = get_current_arch ();

.. then why get_current_arch and not 'python_gdbarch'?

Siva> +static PyObject *
Siva> +frapy_arch (PyObject *self, PyObject *args)
Siva> +{
Siva> +  struct frame_info *frame = NULL;    /* Initialize to appease gcc warning.  */
Siva> +  frame_object *obj = (frame_object *) self;
Siva> +  volatile struct gdb_exception except;
Siva> +  enum unwind_stop_reason stop_reason;

I didn't see a use of stop_reason.

Siva> +extern PyTypeObject arch_object_type;
 
This didn't seem to be used outside of the new file, so it could just be
static there.

Tom


  reply	other threads:[~2013-01-21 17:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21 14:08 Siva Chandra
2013-01-21 17:09 ` Tom Tromey [this message]
2013-01-22 20:40   ` Siva Chandra
2013-01-22 21:17     ` Tom Tromey
2013-01-23 13:53       ` Siva Chandra
2013-01-23 15:35         ` Tom Tromey
2013-01-23 15:59         ` Eli Zaretskii
2013-01-23 21:01           ` Siva Chandra

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=87sj5u31ku.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