I am writing some GDB extension using GDB Python API to be used for C++ applications.
I need to write some index over detected types in debugged process/coredump.
gdb.Type
class has __eq__
defined but is not hashable thus can not be used as a key in dict
or set
.
The workaround I am trying to implement is to get unique identifiers for gdb.Type
objects. str(gdb_type)
looks very good but this solution is not bulletproof as some types are nameless, for instance take a loot at this one:
typedef struct {
} typedeffed_enum;
For this one expression str(gdb.lookup_type('typedeffed_enum').strip_typedefs())
will evaluate to 'struct {...}'
(at least for my compiler and gdb
) which is totally not unique.
Such types also have gdb_type.name is None
names so this is not perfect too.
id(gdb_type)
may give different values for same types as gdb.Type
objects are not unique for each C++ type. So this does not work at all.
Another idea was to get the location (filename and line number) where a type was defined but I could not find a way to get a type's symbol. If you know how to do it, please share.
Is there any way to identify a gdb.Type
with compareable and hasheble value?
PS Edited little bit to make the example more precise.