This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] New python function gdb.lookup_objfile.
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Doug Evans <dje at google dot com>, gdb-patches at sourceware dot org, eliz at gnu dot org
- Date: Tue, 09 Dec 2014 10:49:56 +0000
- Subject: Re: [PATCH] New python function gdb.lookup_objfile.
- Authentication-results: sourceware.org; auth=none
- References: <yjt2sigp4kd3 dot fsf at ruffy dot mtv dot corp dot google dot com>
On 09/12/14 02:39, Doug Evans wrote:
> Hi.
>
> This patch implements a new python function gdb.lookup_objfile.
> It provides the ability to look up an objfile given a file name
> or build id.
>
> While one could call gdb.objfiles() and then scan over that,
> it requires construction of the list, and with *lots* of objfiles
> it is a bit cumbersome.
>
> Regression tested on amd64-linux.
Thanks.
> +@findex gdb.lookup_objfile
> +@defun gdb.lookup_objfile (name @r{[}, by_build_id{]})
> +Look up @var{name}, which is a file name, in the list of objfiles
> +for the current program space (@pxref{Progspaces In Python}).
> +If the objfile is not found then a Python @code{ValueError} exception
> +is thrown.
Do wildcard or partial matches work? It would be excellent if they
did, and if so, a note in the documentation. If not, how much work do
you think it would be to have this functionality?
A soft objection. Not a fan of functions that return an Exception on
"item not found" personally. I prefer to return None, and save
exceptions for errors. But I understand that in some projects this
paradigm is used.
> +{
> + static char *keywords[] = { "name", "by_build_id", NULL };
> + const char *name;
> + PyObject *by_build_id_obj = NULL;
> + int by_build_id;
> + struct objfile *objfile;
> +
> + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
> + &name, &PyBool_Type, &by_build_id_obj))
> + return NULL;
If "name" is an empty string should we just immediately return an
exception here? There are some operations later that depend on
strlen. I had a quick look, and it seems none of the functions have a
real hard issue with zero string lookups, but it might be best to
check here first.
Cheers
Phil