[DTrace-devel] [PATCH 2/4] Add support for string data to the trace() action

Kris Van Hees kris.van.hees at oracle.com
Tue Jun 8 20:37:19 PDT 2021


Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_consume.c                      | 29 ++++++++++++++++-----
 test/demo/intro/hello.d                     |  3 +--
 test/demo/script/interp.d                   |  3 +--
 test/unittest/actions/trace/tst.str-quiet.d | 20 ++++++++++++++
 test/unittest/actions/trace/tst.str-quiet.r |  1 +
 test/unittest/actions/trace/tst.str.d       |  5 +---
 test/unittest/actions/trace/tst.str.r       |  6 ++++-
 test/unittest/scripting/tst.trace.d         |  3 +--
 test/unittest/trace/tst.misc.d              |  4 +--
 test/unittest/trace/tst.qstring.d           |  3 +--
 test/unittest/trace/tst.string.d            |  3 +--
 11 files changed, 56 insertions(+), 24 deletions(-)
 create mode 100644 test/unittest/actions/trace/tst.str-quiet.d
 create mode 100644 test/unittest/actions/trace/tst.str-quiet.r

diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index f39156df..926a41d3 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -17,6 +17,7 @@
 #include <dt_pcap.h>
 #include <dt_peb.h>
 #include <dt_state.h>
+#include <dt_varint.h>
 #include <libproc.h>
 #include <port.h>
 #include <sys/epoll.h>
@@ -1864,13 +1865,27 @@ static int
 dt_print_trace(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
 	       caddr_t data, int quiet)
 {
+	if (dtp->dt_options[DTRACEOPT_RAWBYTES] != DTRACEOPT_UNSET)
+		return dt_print_rawbytes(dtp, fp, data, rec->dtrd_size);
+
 	/*
-	 * String or any other non-numeric data items are printed as a byte
-	 * stream.
+	 * String data can be recognized as a non-scalar data item with
+	 * alignment == 1.
+	 * Any other non-scalar data items are printed as a byte stream.
 	 */
-	if (rec->dtrd_arg == DT_NF_REF)
-		return dt_print_bytes(dtp, fp, data, rec->dtrd_size, 33,
-				      quiet);
+	if (rec->dtrd_arg == DT_NF_REF) {
+		char	*s = (char *)data;
+
+		if (rec->dtrd_alignment > 1)
+			return dt_print_rawbytes(dtp, fp, data, rec->dtrd_size);
+
+		/* We have a string.  Skip the length prefix and print it. */
+		s = (char *)dt_vint_skip(s);
+		if (quiet)
+			return dt_printf(dtp, fp, "%s", s);
+		else
+			return dt_printf(dtp, fp, "  %-33s", s);
+	}
 
 	/*
 	 * Differentiate between signed and unsigned numeric values.
@@ -1915,9 +1930,9 @@ dt_print_trace(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
 	}
 
 	/*
-	 * We should never get here, but if we do... print bytes.
+	 * We should never get here, but if we do... print raw bytes.
 	 */
-	return dt_print_bytes(dtp, fp, data, rec->dtrd_size, 33, quiet);
+	return dt_print_rawbytes(dtp, fp, data, rec->dtrd_size);
 }
 
 static dtrace_workstatus_t
diff --git a/test/demo/intro/hello.d b/test/demo/intro/hello.d
index 3dbe24dd..24eaa985 100644
--- a/test/demo/intro/hello.d
+++ b/test/demo/intro/hello.d
@@ -1,11 +1,10 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, 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.
  */
 
-/* @@xfail: dtv2 */
 /* @@trigger: none */
 
 BEGIN
diff --git a/test/demo/script/interp.d b/test/demo/script/interp.d
index 36e66680..be690b56 100644
--- a/test/demo/script/interp.d
+++ b/test/demo/script/interp.d
@@ -2,12 +2,11 @@
 
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, 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.
  */
 
-/* @@xfail: dtv2 */
 /* @@trigger: none */
 
 BEGIN
diff --git a/test/unittest/actions/trace/tst.str-quiet.d b/test/unittest/actions/trace/tst.str-quiet.d
new file mode 100644
index 00000000..1dce4046
--- /dev/null
+++ b/test/unittest/actions/trace/tst.str-quiet.d
@@ -0,0 +1,20 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2020, 2021, 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 trace() action accepts a string argument.
+ *
+ * SECTION: Actions and Subroutines/trace()
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	trace("a");
+	exit(0);
+}
diff --git a/test/unittest/actions/trace/tst.str-quiet.r b/test/unittest/actions/trace/tst.str-quiet.r
new file mode 100644
index 00000000..78981922
--- /dev/null
+++ b/test/unittest/actions/trace/tst.str-quiet.r
@@ -0,0 +1 @@
+a
diff --git a/test/unittest/actions/trace/tst.str.d b/test/unittest/actions/trace/tst.str.d
index af38cbc7..97a3c88c 100644
--- a/test/unittest/actions/trace/tst.str.d
+++ b/test/unittest/actions/trace/tst.str.d
@@ -1,10 +1,9 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021, 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.
  */
-/* @@xfail: dtv2 */
 
 /*
  * ASSERTION: The trace() action accepts a string argument.
@@ -12,8 +11,6 @@
  * SECTION: Actions and Subroutines/trace()
  */
 
-#pragma D option quiet
-
 BEGIN
 {
 	trace("a");
diff --git a/test/unittest/actions/trace/tst.str.r b/test/unittest/actions/trace/tst.str.r
index 78981922..ec72d6b1 100644
--- a/test/unittest/actions/trace/tst.str.r
+++ b/test/unittest/actions/trace/tst.str.r
@@ -1 +1,5 @@
-a
+                   FUNCTION:NAME
+                          :BEGIN   a                                
+
+-- @@stderr --
+dtrace: script 'test/unittest/actions/trace/tst.str.d' matched 1 probe
diff --git a/test/unittest/scripting/tst.trace.d b/test/unittest/scripting/tst.trace.d
index cd30e160..148e5c60 100644
--- a/test/unittest/scripting/tst.trace.d
+++ b/test/unittest/scripting/tst.trace.d
@@ -2,11 +2,10 @@
 
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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.
  */
-/* @@xfail: dtv2 */
 
 /*
  * ASSERTION:
diff --git a/test/unittest/trace/tst.misc.d b/test/unittest/trace/tst.misc.d
index fa651697..cbb8a003 100644
--- a/test/unittest/trace/tst.misc.d
+++ b/test/unittest/trace/tst.misc.d
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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.
  */
@@ -32,7 +32,7 @@ tick-1
 	trace(x++);		/* DT_TYPE_INT (derived) */
 	trace(timestamp);	/* DT_TYPE_INT (variable) */
 	trace(`max_pfn);	/* CTF type (by value) */
-	trace(*`sdt_prefix);	/* CTF type (by ref) */
+	trace(*`linux_banner);	/* CTF type (by ref) */
 	i++;
 }
 
diff --git a/test/unittest/trace/tst.qstring.d b/test/unittest/trace/tst.qstring.d
index 308b84dc..3a9608e5 100644
--- a/test/unittest/trace/tst.qstring.d
+++ b/test/unittest/trace/tst.qstring.d
@@ -1,10 +1,9 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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.
  */
-/* @@xfail: dtv2 */
 
 #pragma D option quiet
 
diff --git a/test/unittest/trace/tst.string.d b/test/unittest/trace/tst.string.d
index fd6e7f40..bcbfc02c 100644
--- a/test/unittest/trace/tst.string.d
+++ b/test/unittest/trace/tst.string.d
@@ -1,10 +1,9 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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.
  */
-/* @@xfail: dtv2 */
 
 /*
  * ASSERTION:
-- 
2.31.1




More information about the DTrace-devel mailing list