public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom de Vries <tdevries@suse.de>
Cc: Simon Marchi <simon.marchi@ericsson.com>,
	 gdb-patches@sourceware.org,  Phil Muldoon <pmuldoon@redhat.com>,
	 Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH][gdb/python] Add interface to access minimal_symbols
Date: Thu, 29 Nov 2018 22:32:00 -0000	[thread overview]
Message-ID: <878t1ba51b.fsf@tromey.com> (raw)
In-Reply-To: <211c4746-389a-93b7-faf9-c8f9b6245541@suse.de> (Tom de Vries's	message of "Wed, 31 Oct 2018 17:59:15 +0100")

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> This patch adds a new gdb.MinSymbol object to export the minimal_symbol
Tom> interface.

I hate to bikeshed the name to start with, but I'm going to anyway.  Why
the abbreviated name rather than gdb.MinimalSymbol?  Or alternatively
why not something less "gdb-ish", like gdb.LinkerSymbol?

Tom> +Typical symbols like functions, variables, etc are represented by
Tom> +@code{gdb.Symbol} objects in Python.  Some symbols are defined with less
Tom> +information associated with them, like linker script variables
Tom> +or assembly labels.  Python represents these minimal symbols in @value{GDBN}
Tom> +with the @code{gdb.MinSymbol} object.

I think this is mildly misleading and perhaps should also mention that
linker symbols will generally end up in here.

Tom> +@defvar MinSymbol.filename
Tom> +The file name of the source file where the minimal symbol is defined.

As mentioned elsewhere in the thread, I think this field is largely not
useful.  I feel like we once considered removing it from minsyms
entirely.  So, I tend to think this one should just be dropped, unless
you have some specific need for it (which would be interesting to hear
about).

Tom> +@defvar MinSymbol.section_name
Tom> +The name of the section in the object file containing this minimal symbol.

Are there platforms where sections do not have names?
What will happen to this on those?

Tom> +  return PyString_FromString (minsym->filename);

I suspect filename can be NULL here.
But see above.

Tom> +  if (section != NULL)
Tom> +    {
Tom> +      name = bfd_section_name (objfile->obfd, section->the_bfd_section);
Tom> +      if (name != NULL)
Tom> +	return PyString_FromString (name);
Tom> +    }
Tom> +
Tom> +  Py_RETURN_NONE;

Ok, I see the answer to my question here.  This should be documented.

Tom> +  type = builtin_type (minsym_gdbarch (self))->builtin_func_ptr;
Tom> +
Tom> +  if (minsym_type (self) == type)
Tom> +    Py_RETURN_TRUE;

This seems kind of roundabout to me.

Tom> +  type = builtin_type (minsym_gdbarch (self))->builtin_data_ptr;
Tom> +
Tom> +  if (minsym_type (self) == type)
Tom> +    Py_RETURN_TRUE;

Same here.

Tom> +  minsym_object *minsym_obj = (minsym_object *)self;

Space after the ")".

Tom> +static void
Tom> +set_symbol (minsym_object *obj, struct bound_minimal_symbol *bound)

I think a const reference for "bound" would be more natural here.

Tom> +static PyObject *
Tom> +bound_minsym_to_minsym_object (struct bound_minimal_symbol *bound)

Here too.

Tom> +  if (sfile_obj != NULL && sfile_obj != Py_None)
Tom> +    {
Tom> +      sfile_tmp = gdbpy_obj_to_string (sfile_obj);

If this returns NULL then this function should early-return as well.

Tom> +  if (bound_minsym.minsym != NULL)
Tom> +    msym_obj = bound_minsym_to_minsym_object (&bound_minsym);

If bound_minsym_to_minsym_object returns NULL, then an exception has
been set, so this function must return NULL.  But:

Tom> +  if (msym_obj != NULL)
Tom> +    return msym_obj;

... that isn't happening.

So the logic needs a bit of reordering here.

Tom> +/* Initialize gdb.MinSymbol.  Return -1 on error, 0 on success.  */
Tom> +
Tom> +int
Tom> +gdbpy_initialize_minsymbols (void)

Don't need the "void" here any more.

Tom> +/* Return struct objfile reference that is wrapped by the SELF object.  */
Tom> +
Tom> +struct objfile *
Tom> +objectfile_object_to_objfile (PyObject *self)

I think this should be named objfile_object_to_objfile instead.

Tom> +++ b/gdb/testsuite/gdb.python/py-minsymbol.exp

Some of the lines here are too long and can reasonably be split.

I think it would also make sense to check for the minsym for "main"
itself.

Tom

  parent reply	other threads:[~2018-11-29 22:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 21:11 Tom de Vries
2018-10-05  4:43 ` Simon Marchi
2018-10-31 16:59   ` Tom de Vries
2018-11-26 11:17     ` [PING][PATCH][gdb/python] " Tom de Vries
2018-11-26 21:31     ` [PATCH][gdb/python] " Simon Marchi
2018-11-27 18:10       ` Matt Rice
2018-11-29 22:32     ` Tom Tromey [this message]
2018-11-29 22:12   ` Tom Tromey
2018-10-05  6:46 ` Eli Zaretskii
2018-10-31 17:02   ` Tom de Vries

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=878t1ba51b.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    --cc=simon.marchi@ericsson.com \
    --cc=tdevries@suse.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).