[PATCH 1/1] Add support for gdb.Type initialization from within the Python API

Simon Marchi simark@simark.ca
Fri Jan 6 20:00:46 GMT 2023


Hi,

Unfortunately, I am unable to apply this patch as well, please send it
using git-send-email.

On 1/5/23 18:56, dark.ryu.550--- via Gdb-patches wrote:
> This patch adds support for creating types from within the Python API. It
> does
> 
> so by exposing the `init_*_type` family of functions, defined in
> `gdbtypes.h` to 
> 
> Python and having them return `gdb.Type` objects connected to the newly
> minted
> 
> types.
> 
>  
> 
> These functions are accessible in the root of the gdb module and all require
> 
> a reference to a `gdb.Objfile`. Types created from this API are exclusively 
> 
> objfile-owned.

It would maybe be nice to be able to create arch-owned types too.  For
instance, you could create types just after firing up GDB, without even
having an objfile loaded.  It's not necessary to implement it at the
same time, but does your approach leave us the option to do that at a
later time?

> 
>  
> 
> This patch also adds an extra type - `gdb.FloatFormat` - to support creation
> of 
> 
> floating point types by letting users control the format from within Python.
> It
> 
> is missing, however, a way to specify half formats and validation functions.
> 
>  
> 
> It is important to note that types created using this interface are not
> 
> automatically registered as a symbol, and so, types will become unreachable
> 
> unless used to create a value that otherwise references it or saved in some
> way.
> 
>  
> 
> The main drawback of using the `init_*_type` family over implementing type 
> 
> initialization by hand is that any type that's created gets immediately 
> 
> allocated on its owner objfile's obstack, regardless of what its real
> 
> lifetime requirements are. The main implication of this is that types that 
> 
> become unreachable will leak their memory for the lifetime of the objfile.
>
> Keeping track of the initialization of the type by hand would require a 
> 
> deeper change to the existing type object infrastructure. A bit too
> ambitious
> 
> for a first patch, I'd say.
> 
>  
> 
> if it were to be done though, we would gain the ability to only keep in the 
> 
> obstack types that are known to be referenced in some other way - by
> allocating 
> 
> and copying the data to the obstack as other objects are created that
> reference 
> 
> it (eg. symbols).

I think how you did it is ok, it's better to keep things simple.

Simon


More information about the Gdb-patches mailing list