From: Kris Van Hees <kris.van.hees@oracle.com>
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 2/6] btf: use dt_btf_real_type_by_id() to resolve types
Date: Tue, 28 Apr 2026 19:04:25 +0000 [thread overview]
Message-ID: <e2828289b737fc9b39ec532e617838f3@oracle.com> (raw)
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 | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/libdtrace/dt_btf.c b/libdtrace/dt_btf.c
index d08599192..e392468fb 100644
--- a/libdtrace/dt_btf.c
+++ b/libdtrace/dt_btf.c
@@ -848,6 +848,27 @@ 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_RESTRICT:
+ 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 +999,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
reply other threads:[~2026-04-28 19:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2828289b737fc9b39ec532e617838f3@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox