* [PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types
@ 2026-04-14 6:27 Kris Van Hees
2026-04-17 17:05 ` Nick Alcock
0 siblings, 1 reply; 3+ messages in thread
From: Kris Van Hees @ 2026-04-14 6:27 UTC (permalink / raw)
To: dtrace, dtrace-devel
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 <kris.van.hees@oracle.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types
2026-04-14 6:27 [PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types Kris Van Hees
@ 2026-04-17 17:05 ` Nick Alcock
2026-04-17 19:00 ` Kris Van Hees
0 siblings, 1 reply; 3+ messages in thread
From: Nick Alcock @ 2026-04-17 17:05 UTC (permalink / raw)
To: Kris Van Hees; +Cc: dtrace, dtrace-devel
On 14 Apr 2026, Kris Van Hees said:
> 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.
Perhaps dt_btf_resolve_type(), for consistency with the libctf function
naming?
Other than that...
> ---
> 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:
Probably this should traverse BTF_KIND_RESTRICT as well. (The kernel
*does* use restrict qualifiers in some places. I was surprised too.)
--
NULL && (void)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types
2026-04-17 17:05 ` Nick Alcock
@ 2026-04-17 19:00 ` Kris Van Hees
0 siblings, 0 replies; 3+ messages in thread
From: Kris Van Hees @ 2026-04-17 19:00 UTC (permalink / raw)
To: Nick Alcock; +Cc: Kris Van Hees, dtrace, dtrace-devel
On Fri, Apr 17, 2026 at 06:05:19PM +0100, Nick Alcock wrote:
> On 14 Apr 2026, Kris Van Hees said:
>
> > 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.
>
> Perhaps dt_btf_resolve_type(), for consistency with the libctf function
> naming?
Hm, no, I don't think that would be what we want here because I think they
do have slightly different semantics.
> Other than that...
>
> > ---
> > 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:
>
> Probably this should traverse BTF_KIND_RESTRICT as well. (The kernel
> *does* use restrict qualifiers in some places. I was surprised too.)
Ah yes, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-17 19:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 6:27 [PATCH 2/4] btf: use dt_btf_real_type_by_id() to resolve types Kris Van Hees
2026-04-17 17:05 ` Nick Alcock
2026-04-17 19:00 ` Kris Van Hees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox