Re: [PATCH v2 4/7] trace: handle the empty string in a sensible way
Eugene Loh <[email protected]>
| Newsgroups | dev.linux.lists.dtrace |
|---|---|
| Message-ID | <[email protected]> |
Reviewed-by: Eugene Loh <[email protected]> On 8/14/25 16:33, Kris Van Hees wrote: > The trace("") action would dump a series of 0x00 bytes (strsize of > them) rather than printing an empty string. While that is the legacy > behaviour, it does not really make any sense to do so. The trace > action is described as printing data as a string if possible, and a > block of 0-bytes can certainly be printed as an empty string. > > Signed-off-by: Kris Van Hees <[email protected]> > --- > libdtrace/dt_consume.c | 2 +- > test/unittest/actions/trace/tst.str-empty.d | 18 ++++++++++++++++++ > test/unittest/actions/trace/tst.str-empty.r | 5 +++++ > 3 files changed, 24 insertions(+), 1 deletion(-) > create mode 100644 test/unittest/actions/trace/tst.str-empty.d > create mode 100644 test/unittest/actions/trace/tst.str-empty.r > > diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c > index edfe5bbae..2dce69d6d 100644 > --- a/libdtrace/dt_consume.c > +++ b/libdtrace/dt_consume.c > @@ -991,7 +991,7 @@ dt_print_bytes(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr, > c[i] == '\b' || c[i] == '\a') > continue; > > - if (c[i] == '\0' && i > 0) { > + if (c[i] == '\0') { > /* > * This looks like it might be a string. Before we > * assume that it is indeed a string, check the > diff --git a/test/unittest/actions/trace/tst.str-empty.d b/test/unittest/actions/trace/tst.str-empty.d > new file mode 100644 > index 000000000..38fcb8857 > --- /dev/null > +++ b/test/unittest/actions/trace/tst.str-empty.d > @@ -0,0 +1,18 @@ > +/* > + * 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 trace() action prints an empty string value correctly. > + * > + * SECTION: Actions and Subroutines/trace() > + */ > + > +BEGIN > +{ > + trace(""); > + exit(0); > +} > diff --git a/test/unittest/actions/trace/tst.str-empty.r b/test/unittest/actions/trace/tst.str-empty.r > new file mode 100644 > index 000000000..8c15aa7f5 > --- /dev/null > +++ b/test/unittest/actions/trace/tst.str-empty.r > @@ -0,0 +1,5 @@ > + FUNCTION:NAME > + :BEGIN > + > +-- @@stderr -- > +dtrace: script 'test/unittest/actions/trace/tst.str-empty.d' matched 1 probe