[PATCH] Add gdb.integer_type Python function

Simon Marchi simon.marchi@polymtl.ca
Sat Oct 23 12:36:09 GMT 2021


On 2021-10-22 15:59, Tom Tromey via Gdb-patches wrote:
> This adds a new Python function, gdb.integer_type, which can be used
> to look up an integer type of a given size and signed-ness.  This is
> useful to avoid dependency on debuginfo when a particular integer type
> would be useful.

IIUC, by "avoid dependency on debuginfo", you mean where you would use
gdb.lookup_type instead?

So, gdb.integer_type depends on the current inferior, because it uses
its gdbarch.  Since I'd like to see Python methods depend less on "the
current thing", what about making a method on gdb.Architecture instead?


> ---
>  gdb/NEWS                             |  3 ++
>  gdb/doc/python.texi                  | 15 +++++++++
>  gdb/python/py-type.c                 | 46 ++++++++++++++++++++++++++++
>  gdb/python/python-internal.h         |  1 +
>  gdb/python/python.c                  |  6 ++++
>  gdb/testsuite/gdb.python/py-type.exp | 14 +++++++++
>  6 files changed, 85 insertions(+)
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index d001a03145d..ab095a2601c 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -49,6 +49,9 @@ maint show internal-warning backtrace
>       containing all of the possible Architecture.name() values.  Each
>       entry is a string.
>  
> +  ** New function gdb.integer_type(), which returns an integer type
> +     given a size and a signed-ness.
> +
>  *** Changes in GDB 11
>  
>  * The 'set disassembler-options' command now supports specifying options
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 90214f24238..c6093c4d2ee 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -1125,6 +1125,21 @@ Ordinarily, this function will return an instance of @code{gdb.Type}.
>  If the named type cannot be found, it will throw an exception.
>  @end defun
>  
> +@findex gdb.integer_type
> +@defun gdb.integer_type (size @r{[}, signed@r{]})
> +This function looks up an integer type by its @var{size}, and
> +optionally whether or not it is signed.
> +
> +@var{size} is the size, in bits, of the desired integer type.  Only
> +certain sizes are currently supported: 0, 8, 16, 24, 32, 64, and 128.
> +
> +If @var{signed} is not specified, it defaults to @code{True}.  If
> +@var{signed} is @code{False}, the returned type will be unsigned.
> +
> +If the indicated type cannot be found, this function will throw an
> +exception.

IWBN to document which kind of exception.

Simon


More information about the Gdb-patches mailing list