Skip to content

Commit

Permalink
Store strings in the trace output buffer without length prefixes
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Feb 8, 2022
1 parent e042483 commit f0b8973
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 49 deletions.
27 changes: 11 additions & 16 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,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);

Expand All @@ -951,34 +951,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);
Expand Down
5 changes: 2 additions & 3 deletions libdtrace/dt_consume.c
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions libdtrace/dt_printf.c
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/unittest/codegen/tst.str_const_length.r
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion test/unittest/codegen/tst.str_data_size.r
Original file line number Diff line number Diff line change
@@ -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.

4 changes: 2 additions & 2 deletions test/unittest/codegen/tst.str_store_var.r
Original file line number Diff line number Diff line change
@@ -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.....

18 changes: 9 additions & 9 deletions test/unittest/funcs/strjoin/tst.strjoin-bordercases.r
Original file line number Diff line number Diff line change
@@ -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.

6 changes: 3 additions & 3 deletions test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.r
Original file line number Diff line number Diff line change
@@ -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.

6 changes: 3 additions & 3 deletions test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.r
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion test/unittest/funcs/strjoin/tst.strjoin-capped-size.r
Original file line number Diff line number Diff line change
@@ -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.

6 changes: 3 additions & 3 deletions test/unittest/funcs/substr/tst.substr-stored-len.r
Original file line number Diff line number Diff line change
@@ -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...........

10 changes: 5 additions & 5 deletions test/unittest/funcs/substr/tst.substr-strsize.r
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f0b8973

Please sign in to comment.