[PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types
Kris Van Hees <[email protected]> Tue, 14 Apr 2026 02:27:46 -0400
| Newsgroups | dev.linux.lists.dtrace |
|---|---|
| Message-ID | <IA0PR10MB732561FE075BF04C79C5CA54C2252@IA0PR10MB7325.namprd10.prod.outlook.com> |
Functions that need to check type data operate on the real type rather than a typedef or a type with modifiers. Similarly, when a type of a function is needed, the prototype (BTF type BTF_KIND_PROTO) is what is really needed. Introducing dt_btf_real_type_by_id() removed duplication of code in other functions. Signed-off-by: Kris Van Hees <[email protected]> --- libdtrace/dt_btf.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/libdtrace/dt_btf.c b/libdtrace/dt_btf.c index d08599192..56eb96a4e 100644 --- a/libdtrace/dt_btf.c +++ b/libdtrace/dt_btf.c @@ -848,6 +848,26 @@ dt_btf_type_by_id(dtrace_hdl_t *dtp, const dt_btf_t *btf, int32_t id) return btf->types[id - (dtp->dt_shared_btf->type_cnt - 1)]; } +static btf_type_t * +dt_btf_real_type_by_id(dtrace_hdl_t *dtp, const dt_btf_t *btf, int32_t id) +{ + btf_type_t *type = dt_btf_type_by_id(dtp, btf, id); + + do { + switch (BTF_INFO_KIND(type->info)) { + case BTF_KIND_CONST: + case BTF_KIND_FUNC: + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + type = dt_btf_type_by_id(dtp, btf, type->type); + default: + return type; + } + } while (type != NULL); + + return NULL; +} + const char * dt_btf_get_string(dtrace_hdl_t *dtp, const dt_btf_t *btf, uint32_t off) { @@ -978,29 +998,24 @@ dt_btf_module_fd(const dt_module_t *dmp) int dt_btf_func_argc(dtrace_hdl_t *dtp, const dt_btf_t *btf, uint32_t id) { - btf_type_t *type = dt_btf_type_by_id(dtp, btf, id); + btf_type_t *type = dt_btf_real_type_by_id(dtp, btf, id); - /* For functions, move on to the function prototype. */ - if (BTF_INFO_KIND(type->info) == BTF_KIND_FUNC) - type = dt_btf_type_by_id(dtp, btf, type->type); + if (type == NULL) + return -1; - if (BTF_INFO_KIND(type->info) == BTF_KIND_FUNC_PROTO) - return BTF_INFO_VLEN(type->info); + if (BTF_INFO_KIND(type->info) != BTF_KIND_FUNC_PROTO) + return -1; - return -1; + return BTF_INFO_VLEN(type->info); } int dt_btf_func_is_void(dtrace_hdl_t *dtp, const dt_btf_t *btf, uint32_t id) { - btf_type_t *type = dt_btf_type_by_id(dtp, btf, id); - - /* For functions, move on to the function prototype. */ - if (BTF_INFO_KIND(type->info) == BTF_KIND_FUNC) - type = dt_btf_type_by_id(dtp, btf, type->type); + btf_type_t *type = dt_btf_real_type_by_id(dtp, btf, id); - if (BTF_INFO_KIND(type->info) == BTF_KIND_FUNC_PROTO && - type->type == 0) + if (type != NULL && + BTF_INFO_KIND(type->info) == BTF_KIND_FUNC_PROTO && type->type == 0) return 1; return 0; -- 2.53.0