[DTrace-devel] [PATCH] Add support for built-in variable execname
Kris Van Hees
kris.van.hees at oracle.com
Thu Jan 27 19:08:58 UTC 2022
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
bpf/get_bvar.c | 21 +++++++++++++++++++++
libdtrace/dt_bpf.c | 4 ++++
libdtrace/dt_state.h | 2 ++
test/unittest/variables/bvar/tst.execname.d | 3 +--
test/unittest/variables/bvar/tst.execname.r | 1 +
5 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 test/unittest/variables/bvar/tst.execname.r
diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
index 67346014..f8b03487 100644
--- a/bpf/get_bvar.c
+++ b/bpf/get_bvar.c
@@ -133,6 +133,27 @@ noinline uint64_t dt_get_bvar(const dt_dctx_t *dctx, uint32_t id)
return val & 0x00000000ffffffffUL;
}
+ case DIF_VAR_EXECNAME: {
+ uint64_t ptr;
+ uint32_t key;
+ uint32_t *comm_off;
+
+ /*
+ * In the "state" map, look up the "struct task_struct" offset
+ * of "comm".
+ */
+ key = DT_STATE_TASK_COMM_OFF;
+ comm_off = bpf_map_lookup_elem(&state, &key);
+ if (comm_off == NULL)
+ return 0;
+
+ /* &(current->comm) */
+ ptr = bpf_get_current_task();
+ if (ptr == 0)
+ return error(dctx, DTRACEFLT_BADADDR, ptr);
+
+ return (uint64_t)ptr + *comm_off;
+ }
case DIF_VAR_WALLTIMESTAMP:
return bpf_ktime_get_ns() + ((uint64_t)&BOOTTM);
case DIF_VAR_PPID: {
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index 4fa447da..8b551354 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -153,6 +153,10 @@ set_task_offsets(dtrace_hdl_t *dtp)
return -1;
dt_state_set_offtgid(dtp, ctm.ctm_offset / NBBY);
+ if (ctf_member_info(cfp, type, "comm", &ctm) == CTF_ERR)
+ return -1;
+ dt_state_set_offcomm(dtp, ctm.ctm_offset / NBBY);
+
return 0;
}
diff --git a/libdtrace/dt_state.h b/libdtrace/dt_state.h
index 68ea6337..d48082e9 100644
--- a/libdtrace/dt_state.h
+++ b/libdtrace/dt_state.h
@@ -23,6 +23,7 @@ typedef enum dt_state_elem {
DT_STATE_ENDEDON, /* cpu END probe executed on */
DT_STATE_TASK_PARENT_OFF, /* offsetof(struct task_struct, real_parent) */
DT_STATE_TASK_TGID_OFF, /* offsetof(struct task_struct, tgid) */
+ DT_STATE_TASK_COMM_OFF, /* offsetof(struct task_struct, comm) */
DT_STATE_NUM_ELEMS
} dt_state_elem_t;
@@ -66,6 +67,7 @@ dt_state_set(dtrace_hdl_t *dtp, uint32_t key, uint32_t val)
# define dt_state_set_offparent(dtp, x) dt_state_set(dtp, DT_STATE_TASK_PARENT_OFF, (x))
# define dt_state_set_offtgid(dtp, x) dt_state_set(dtp, DT_STATE_TASK_TGID_OFF, (x))
+# define dt_state_set_offcomm(dtp, x) dt_state_set(dtp, DT_STATE_TASK_COMM_OFF, (x))
#endif
#endif /* _DT_STATE_H */
diff --git a/test/unittest/variables/bvar/tst.execname.d b/test/unittest/variables/bvar/tst.execname.d
index 8bb89b54..d0b1853d 100644
--- a/test/unittest/variables/bvar/tst.execname.d
+++ b/test/unittest/variables/bvar/tst.execname.d
@@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
-/* @@xfail: dtv2 */
/*
* ASSERTION: The 'execname' variable can be accessed and is not -1.
@@ -16,7 +15,7 @@
BEGIN {
trace(execname);
- exit(execname != -1 ? 0 : 1);
+ exit(0);
}
ERROR {
diff --git a/test/unittest/variables/bvar/tst.execname.r b/test/unittest/variables/bvar/tst.execname.r
new file mode 100644
index 00000000..d60e7352
--- /dev/null
+++ b/test/unittest/variables/bvar/tst.execname.r
@@ -0,0 +1 @@
+dtrace
--
2.34.1
More information about the DTrace-devel
mailing list