dwarves: Introduce cu__find_type_by_name
To look at all the 'struct type' descendants, like enums, typedefs,
structs, unions, etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/dwarves.c b/dwarves.c
index d7b39cd..867ccbc 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -732,6 +732,37 @@
}
+struct tag *cu__find_type_by_name(const struct cu *cu, const char *name, const int include_decls, type_id_t *idp)
+{
+ if (cu == NULL || name == NULL)
+ return NULL;
+
+ uint32_t id;
+ struct tag *pos;
+ cu__for_each_type(cu, id, pos) {
+ struct type *type;
+
+ if (!tag__is_type(pos))
+ continue;
+
+ type = tag__type(pos);
+ const char *tname = type__name(type, cu);
+ if (tname && strcmp(tname, name) == 0) {
+ if (!type->declaration)
+ goto found;
+
+ if (include_decls)
+ goto found;
+ }
+ }
+
+ return NULL;
+found:
+ if (idp != NULL)
+ *idp = id;
+ return pos;
+}
+
static struct tag *__cu__find_struct_by_name(const struct cu *cu, const char *name,
const int include_decls, bool unions, type_id_t *idp)
{
diff --git a/dwarves.h b/dwarves.h
index a9fcd9a..a772e57 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -120,6 +120,7 @@
type_id_t *id);
struct tag *cus__find_struct_or_union_by_name(const struct cus *cus, struct cu **cu,
const char *name, const int include_decls, type_id_t *id);
+struct tag *cu__find_type_by_name(const struct cu *cu, const char *name, const int include_decls, type_id_t *idp);
struct function *cus__find_function_at_addr(const struct cus *cus,
uint64_t addr, struct cu **cu);
void cus__for_each_cu(struct cus *cus, int (*iterator)(struct cu *cu, void *cookie),