Skip to content

Commit ecef9d7

Browse files
jgkamatosandov
authored andcommitted
libdrgn: get rid of arrays embedded in drgn_type
For C++ support, we need to add an array of template parameters to struct drgn_type. struct drgn_type already has arrays for members, enumerators, and parameters embedded at the end of the structure, because no type needs more than one of those. However, struct, union, and class types may need members and template parameters. We could add a separate array of templates, but then it gets confusing having two methods of storing arrays in struct drgn_type. Let's make these arrays separate instead of embedding them.
1 parent 35bb024 commit ecef9d7

File tree

5 files changed

+250
-298
lines changed

5 files changed

+250
-298
lines changed

libdrgn/drgn.h.in

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,12 @@ struct drgn_type {
446446
size_t num_members;
447447
struct drgn_type *type;
448448
};
449+
union {
450+
struct drgn_type_member *members;
451+
struct drgn_type_enumerator *enumerators;
452+
struct drgn_type_parameter *parameters;
453+
};
449454
} _private;
450-
/*
451-
* An array of struct drgn_type_member, struct drgn_type_enumerator, or
452-
* struct drgn_type_parameter may follow. We can't use flexible array
453-
* members for these because they are not allowed in a union or nested
454-
* structure; we can't use GCC's zero length array extension because
455-
* that triggers false positives in Clang's AddressSanitizer. Instead,
456-
* these are accessed internally with drgn_type_payload().
457-
*/
458455
};
459456

460457
/**
@@ -606,11 +603,6 @@ static inline const char *drgn_type_tag(struct drgn_type *type)
606603
return type->_private.tag;
607604
}
608605

609-
static inline void *drgn_type_payload(struct drgn_type *type)
610-
{
611-
return (char *)type + sizeof(*type);
612-
}
613-
614606
/**
615607
* Get whether a kind of type has members. This is true for structure, union,
616608
* and class types.
@@ -633,7 +625,7 @@ static inline bool drgn_type_has_members(struct drgn_type *type)
633625
static inline struct drgn_type_member *drgn_type_members(struct drgn_type *type)
634626
{
635627
assert(drgn_type_has_members(type));
636-
return drgn_type_payload(type);
628+
return type->_private.members;
637629
}
638630
/**
639631
* Get the number of members of a type. @ref drgn_type_has_members() must be
@@ -710,7 +702,7 @@ static inline struct drgn_type_enumerator *
710702
drgn_type_enumerators(struct drgn_type *type)
711703
{
712704
assert(drgn_type_has_enumerators(type));
713-
return drgn_type_payload(type);
705+
return type->_private.enumerators;
714706
}
715707
/**
716708
* Get the number of enumerators of a type. @ref drgn_type_has_enumerators()
@@ -761,7 +753,7 @@ static inline bool drgn_type_has_parameters(struct drgn_type *type)
761753
static inline struct drgn_type_parameter *drgn_type_parameters(struct drgn_type *type)
762754
{
763755
assert(drgn_type_has_parameters(type));
764-
return drgn_type_payload(type);
756+
return type->_private.parameters;
765757
}
766758
/**
767759
* Get the number of parameters of a type. @ref drgn_type_has_parameters() must

0 commit comments

Comments
 (0)