[DTrace-devel] [PATCH 2/4] Store strings in the trace output buffer without length prefixes

Kris Van Hees kris.van.hees at oracle.com
Wed Jan 26 16:28:59 UTC 2022


There is no need to store string length prefixes in the output buffer.

This change affects various tests that explicitly compare the raw bytes
in the output buffer for strings.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cg.c                             | 27 ++++++++-----------
 libdtrace/dt_consume.c                        |  5 ++--
 libdtrace/dt_printf.c                         |  3 +--
 test/unittest/codegen/tst.str_const_length.r  |  2 +-
 test/unittest/codegen/tst.str_data_size.r     |  2 +-
 test/unittest/codegen/tst.str_store_var.r     |  4 +--
 .../funcs/strjoin/tst.strjoin-bordercases.r   | 18 ++++++-------
 .../funcs/strjoin/tst.strjoin-capped-size-2.r |  6 ++---
 .../funcs/strjoin/tst.strjoin-capped-size-3.r |  6 ++---
 .../funcs/strjoin/tst.strjoin-capped-size.r   |  2 +-
 .../funcs/substr/tst.substr-stored-len.r      |  6 ++---
 .../funcs/substr/tst.substr-strsize.r         | 10 +++----
 12 files changed, 42 insertions(+), 49 deletions(-)

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 0225832d..78818c24 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -922,8 +922,8 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 
 	if (dt_node_is_scalar(dnp) || dt_node_is_float(dnp) ||
 	    dnp->dn_kind == DT_NODE_AGG) {
-		off = dt_rec_add(dtp, dt_cg_fill_gap, kind,
-				 size, size, pfp, arg);
+		off = dt_rec_add(dtp, dt_cg_fill_gap, kind, size, size, pfp,
+				 arg);
 
 		assert(size > 0 && size <= 8 && (size & (size - 1)) == 0);
 
@@ -932,34 +932,29 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 
 		return 0;
 	} else if (dt_node_is_string(dnp)) {
+		size_t	strsize = pcb->pcb_hdl->dt_options[DTRACEOPT_STRSIZE];
+
 		dt_cg_check_notnull(dlp, drp, dnp->dn_reg);
 
 		TRACE_REGSET("store_val(): Begin ");
-		off = dt_rec_add(pcb->pcb_hdl, dt_cg_fill_gap, kind,
-				 size + DT_STRLEN_BYTES + 1, 1, pfp, arg);
-
-		/*
-		 * Copy the length of the string from the source string as a
-		 * half-word (2 bytes) into the buffer at [%r9 + off].
-		 */
-		emit(dlp, BPF_LOAD(BPF_H, BPF_REG_0, dnp->dn_reg, 0));
-		emit(dlp, BPF_STORE(BPF_H, BPF_REG_9, off, BPF_REG_0));
+		off = dt_rec_add(pcb->pcb_hdl, dt_cg_fill_gap, kind, size + 1,
+				 1, pfp, arg);
 
 		/*
 		 * Copy the string data (no more than STRSIZE + 1 bytes) to the
-		 * buffer at [%r9 + off + DT_STRLEN_BYTES].  We (ab)use the
-		 * fact that probe_read_str) stops at the terminating NUL byte.
+		 * buffer at (%r9 + off).  We depend on the fact that
+		 * probe_read_str() stops at the terminating NUL byte.
 		 */
 		if (dt_regset_xalloc_args(drp) == -1)
 			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
 
 		emit(dlp, BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
-		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off + DT_STRLEN_BYTES));
-		emit(dlp, BPF_MOV_IMM(BPF_REG_2, size + 1));
+		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
+		emit(dlp, BPF_MOV_IMM(BPF_REG_2, strsize + 1));
 		emit(dlp, BPF_MOV_REG(BPF_REG_3, dnp->dn_reg));
+		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_STRLEN_BYTES));
 		dt_regset_free(drp, dnp->dn_reg);
 		dt_cg_tstring_free(pcb, dnp);
-		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_STRLEN_BYTES));
 		dt_regset_xalloc(drp, BPF_REG_0);
 		emit(dlp, BPF_CALL_HELPER(BPF_FUNC_probe_read_str));
 		dt_regset_free_args(drp);
diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index 35a6cc96..dbfcf9de 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2022, 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.
  */
@@ -1928,8 +1928,7 @@ dt_print_trace(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
 		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 += DT_STRLEN_BYTES;
+		/* We have a string.  Print it. */
 		if (quiet)
 			return dt_printf(dtp, fp, "%s", s);
 		else
diff --git a/libdtrace/dt_printf.c b/libdtrace/dt_printf.c
index 5c6fcd49..7e9c0982 100644
--- a/libdtrace/dt_printf.c
+++ b/libdtrace/dt_printf.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2022, 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.
  */
@@ -489,7 +489,6 @@ pfprint_cstr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
 
 	memcpy(s, addr, size);
 	s[size] = '\0';
-	s += DT_STRLEN_BYTES;
 	return dt_printf(dtp, fp, format, s);
 }
 
diff --git a/test/unittest/codegen/tst.str_const_length.r b/test/unittest/codegen/tst.str_const_length.r
index b6991a71..bf76a52c 100644
--- a/test/unittest/codegen/tst.str_const_length.r
+++ b/test/unittest/codegen/tst.str_const_length.r
@@ -1,4 +1,4 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 61 62 63 64 65 00                          ..abcde.
+         0: 61 62 63 64 65 00                                abcde.
 
diff --git a/test/unittest/codegen/tst.str_data_size.r b/test/unittest/codegen/tst.str_data_size.r
index 60483d74..f134e586 100644
--- a/test/unittest/codegen/tst.str_data_size.r
+++ b/test/unittest/codegen/tst.str_data_size.r
@@ -1,4 +1,4 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 64 74 72 61 63 00                          ..dtrac.
+         0: 64 74 72 61 63 00                                dtrac.
 
diff --git a/test/unittest/codegen/tst.str_store_var.r b/test/unittest/codegen/tst.str_store_var.r
index 05932535..ffc3ff5a 100644
--- a/test/unittest/codegen/tst.str_store_var.r
+++ b/test/unittest/codegen/tst.str_store_var.r
@@ -1,7 +1,7 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 61 62 63 64 65 66 00                       ..abcdef.
+         0: 61 62 63 64 65 66 00                             abcdef.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 02 31 32 00 00 00 00 00                       ..12.....
+         0: 31 32 00 00 00 00 00                             12.....
 
diff --git a/test/unittest/funcs/strjoin/tst.strjoin-bordercases.r b/test/unittest/funcs/strjoin/tst.strjoin-bordercases.r
index e2f995be..96544b24 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin-bordercases.r
+++ b/test/unittest/funcs/strjoin/tst.strjoin-bordercases.r
@@ -1,28 +1,28 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 03 31 32 33 00 00 00                          ..123...
+         0: 31 32 33 00 00 00                                123...
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 61 62 00                          ..123ab.
+         0: 31 32 33 61 62 00                                123ab.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 03 31 32 33 00 00 00                          ..123...
+         0: 31 32 33 00 00 00                                123...
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 31 32 33 34 35 00                          ..12345.
+         0: 31 32 33 34 35 00                                12345.
 
diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.r b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.r
index 1d2fe98a..7b90fab5 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.r
+++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.r
@@ -1,10 +1,10 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 64 74 72 61 63 65 00                       ..dtrace.
+         0: 64 74 72 61 63 65 00                             dtrace.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 05 42 45 47 49 4e 00 00                       ..BEGIN..
+         0: 42 45 47 49 4e 00 00                             BEGIN..
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 64 74 72 61 63 65 00                       ..dtrace.
+         0: 64 74 72 61 63 65 00                             dtrace.
 
diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.r b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.r
index b34857bd..d496470f 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.r
+++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.r
@@ -1,10 +1,10 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 64 74 72 61 63 65 00                       ..dtrace.
+         0: 64 74 72 61 63 65 00                             dtrace.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 64 74 72 61 63 65 00                       ..dtrace.
+         0: 64 74 72 61 63 65 00                             dtrace.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 06 64 74 72 61 63 65 00                       ..dtrace.
+         0: 64 74 72 61 63 65 00                             dtrace.
 
diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size.r b/test/unittest/funcs/strjoin/tst.strjoin-capped-size.r
index 97ae26eb..ba224659 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size.r
+++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size.r
@@ -1,4 +1,4 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0a 64 74 72 61 63 65 42 45 47 49 00           ..dtraceBEGI.
+         0: 64 74 72 61 63 65 42 45 47 49 00                 dtraceBEGI.
 
diff --git a/test/unittest/funcs/substr/tst.substr-stored-len.r b/test/unittest/funcs/substr/tst.substr-stored-len.r
index c29f54ba..c0bdb669 100644
--- a/test/unittest/funcs/substr/tst.substr-stored-len.r
+++ b/test/unittest/funcs/substr/tst.substr-stored-len.r
@@ -1,10 +1,10 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 07 63 64 65 66 44 45 46 00 00 00 00 00 00 00  ..cdefDEF.......
+         0: 63 64 65 66 44 45 46 00 00 00 00 00 00 00        cdefDEF.......
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 04 63 64 65 66 00 00 00 00 00 00 00 00 00 00  ..cdef..........
+         0: 63 64 65 66 00 00 00 00 00 00 00 00 00 00        cdef..........
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 03 44 45 46 00 00 00 00 00 00 00 00 00 00 00  ..DEF...........
+         0: 44 45 46 00 00 00 00 00 00 00 00 00 00 00        DEF...........
 
diff --git a/test/unittest/funcs/substr/tst.substr-strsize.r b/test/unittest/funcs/substr/tst.substr-strsize.r
index d96d12f6..f55ef637 100644
--- a/test/unittest/funcs/substr/tst.substr-strsize.r
+++ b/test/unittest/funcs/substr/tst.substr-strsize.r
@@ -1,16 +1,16 @@
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0d 31 32 33 34 35 36 37 38 39 30 31 32 33 00  ..1234567890123.
+         0: 31 32 33 34 35 36 37 38 39 30 31 32 33 00        1234567890123.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0d 31 32 33 34 35 36 37 38 39 30 31 32 33 00  ..1234567890123.
+         0: 31 32 33 34 35 36 37 38 39 30 31 32 33 00        1234567890123.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0c 31 32 33 34 35 36 37 38 39 30 31 32 00 00  ..123456789012..
+         0: 31 32 33 34 35 36 37 38 39 30 31 32 00 00        123456789012..
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0d 31 32 33 34 35 36 37 38 39 30 31 32 33 00  ..1234567890123.
+         0: 31 32 33 34 35 36 37 38 39 30 31 32 33 00        1234567890123.
 
              0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
-         0: 00 0d 31 32 33 34 35 36 37 38 39 30 31 32 33 00  ..1234567890123.
+         0: 31 32 33 34 35 36 37 38 39 30 31 32 33 00        1234567890123.
 
-- 
2.34.1




More information about the DTrace-devel mailing list