[PATCH] vars; ensure 'cwd' and 'root' work and test other inline vars

Kris Van Hees <[email protected]>
Newsgroups dev.linux.lists.dtrace
Message-ID <SJ0PR10MB5672DE6507A2E9026B67D8F3C22DA@SJ0PR10MB5672.namprd10.prod.outlook.com>
Inline variable declarations that provide a tstring value were not
ensuring that tstring data got propagated correctly.

Signed-off-by: Kris Van Hees <[email protected]>
---
 libdtrace/dt_cg.c                             |  8 ++++++
 .../variables/inline/tst.procfs-cwd.d         | 28 +++++++++++++++++++
 .../variables/inline/tst.procfs-root.d        | 28 +++++++++++++++++++
 .../variables/inline/tst.sched-chip.d         | 28 +++++++++++++++++++
 .../unittest/variables/inline/tst.sched-cpu.d | 28 +++++++++++++++++++
 .../variables/inline/tst.sched-lgrp.d         | 28 +++++++++++++++++++
 .../variables/inline/tst.sched-pset.d         | 28 +++++++++++++++++++
 7 files changed, 176 insertions(+)
 create mode 100644 test/unittest/variables/inline/tst.procfs-cwd.d
 create mode 100644 test/unittest/variables/inline/tst.procfs-root.d
 create mode 100644 test/unittest/variables/inline/tst.sched-chip.d
 create mode 100644 test/unittest/variables/inline/tst.sched-cpu.d
 create mode 100644 test/unittest/variables/inline/tst.sched-lgrp.d
 create mode 100644 test/unittest/variables/inline/tst.sched-pset.d

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 27919bbdf..707c3fbe3 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -6954,7 +6954,15 @@ dt_cg_inline(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 	}
 
 	dt_cg_node(inp->din_root, dlp, drp);
+
+	/*
+	 * Copy the result into dnp (register value and tstring).  We need to
+	 * clear the tstring from tnp once we move it to dnp.
+	 */
 	dnp->dn_reg = inp->din_root->dn_reg;
+	dnp->dn_tstring = inp->din_root->dn_tstring;
+	inp->din_root->dn_tstring;
+
 	dt_cg_typecast(inp->din_root, dnp, dlp, drp);
 
 	if (idp->di_kind == DT_IDENT_ARRAY) {
diff --git a/test/unittest/variables/inline/tst.procfs-cwd.d b/test/unittest/variables/inline/tst.procfs-cwd.d
new file mode 100644
index 000000000..c8760f676
--- /dev/null
+++ b/test/unittest/variables/inline/tst.procfs-cwd.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'cwd' inline variable returns the default value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(cwd);
+}
+
+BEGIN
+/cwd == "<unknown>"/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
diff --git a/test/unittest/variables/inline/tst.procfs-root.d b/test/unittest/variables/inline/tst.procfs-root.d
new file mode 100644
index 000000000..276731c24
--- /dev/null
+++ b/test/unittest/variables/inline/tst.procfs-root.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'root' inline variable returns the default value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(root);
+}
+
+BEGIN
+/root == "<unknown>"/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
diff --git a/test/unittest/variables/inline/tst.sched-chip.d b/test/unittest/variables/inline/tst.sched-chip.d
new file mode 100644
index 000000000..c1c314149
--- /dev/null
+++ b/test/unittest/variables/inline/tst.sched-chip.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'chip' inline variable returns the correct value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(chip);
+}
+
+BEGIN
+/chip == curcpu->cpu_chip/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
diff --git a/test/unittest/variables/inline/tst.sched-cpu.d b/test/unittest/variables/inline/tst.sched-cpu.d
new file mode 100644
index 000000000..542cad7a1
--- /dev/null
+++ b/test/unittest/variables/inline/tst.sched-cpu.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'cpu' inline variable returns the correct value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(cpu);
+}
+
+BEGIN
+/cpu == curcpu->cpu_id/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
diff --git a/test/unittest/variables/inline/tst.sched-lgrp.d b/test/unittest/variables/inline/tst.sched-lgrp.d
new file mode 100644
index 000000000..0ddf20180
--- /dev/null
+++ b/test/unittest/variables/inline/tst.sched-lgrp.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'lgrp' inline variable returns the correct value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(lgrp);
+}
+
+BEGIN
+/lgrp == curcpu->cpu_lgrp/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
diff --git a/test/unittest/variables/inline/tst.sched-pset.d b/test/unittest/variables/inline/tst.sched-pset.d
new file mode 100644
index 000000000..a7c946bce
--- /dev/null
+++ b/test/unittest/variables/inline/tst.sched-pset.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The 'pset' inline variable returns the correct value.
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace(pset);
+}
+
+BEGIN
+/pset == curcpu->cpu_pset/
+{
+	exit(0);
+}
+
+BEGIN,
+ERROR {
+	exit(1);
+}
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.