Rename _DTRACE_VERSION
PATCH 1/4 Rename _DTRACE_VERSION
From: Eugene Loh <[email protected]>
There are many DTrace version numbers (for version, API version, package version, etc.). Meanwhile, _DTRACE_VERSION is not a version number at all. It's a preprocessor macro in USDT .h header files. Prior to commit e2fb0ecd9
("Ensure multiple passes through dtrace -G work."), it was perhaps not even set. With that commit, it was always set to 1, with the rationale:
Also add an explicit define for _DTRACE__VERSION in the generated header file from 'dtrace -h' invocations. This seems silly, but it is there to give people a skeleton to work with if they want to pre-generate header files and select whether to actually compile on the probes at a later time.
Rename to _DTRACE_HEADER for better clarity. Define it only once per file.
--- libdtrace/dt_program.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
libdtrace/dt_program.c +5 -3
@@ -505,13 +505,12 @@ dt_header_provider(dtrace_hdl_t *dtp, dt_provider_t *pvp, FILE *out) info.dthi_pfname =alloca (strlen (pvp->desc.dtvd_name) +1 + i);dt_header_fmt_func (info.dthi_pfname, pvp->desc.dtvd_name); -if (fprintf (out,"#define _DTRACE_VERSION 1\n\n" -"#if _DTRACE_VERSION\n\n" ) <0 ) +if (fprintf (out,"#if _DTRACE_HEADER\n\n" ) <0 )return dt_set_errno (dtp, errno);if (dt_idhash_iter (pvp->pv_probes, dt_header_probe, &info) !=0 )return -1 ;/* dt_errno is set for us */ -if (fprintf (out,"\n\n" ) <0 ) +if (fprintf (out,"\n" ) <0 )return dt_set_errno (dtp, errno);if (dt_idhash_iter (pvp->pv_probes, dt_header_decl, &info) !=0 )return -1 ;/* dt_errno is set for us */
@@ -560,6 +559,9 @@ dtrace_program_header(dtrace_hdl_t *dtp, FILE *out, const char *fname) "#endif\n\n") < 0)return -1 ; +if (fprintf (out,"#define _DTRACE_HEADER 1\n\n" ) <0 ) +return -1 ; +while ((pvp =dt_htab_next (dtp->dt_provs, &it)) !=NULL ) {if (dt_header_provider (dtp, pvp, out) !=0 ) {dt_htab_next_destroy (it);
Signature · 1 line
2.43.5
PATCH 2/4 Eliminate DT_VERS_LATEST
From: Eugene Loh <[email protected]>
Updating the DTrace version number requires too many distinct changes. Eliminate DT_VERS_LATEST, since it can be determined on the fly.
--- libdtrace/dt_open.c | 3 ++- libdtrace/dt_version.h | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-)
libdtrace/dt_open.c +2 -1
@@ -721,7 +721,8 @@ dt_vopen(int version, int flags, int *errp, dtp->dt_proc_fd =eventfd (0 ,EFD_CLOEXEC |EFD_NONBLOCK );if (dt_aggregate_init (dtp) ==-1 )return set_open_errno (dtp, errp,dtrace_errno (dtp)); - dtp->dt_vmax =DT_VERS_LATEST ; +for (i =0 ; _dtrace_versions[i] !=0 ; i++) + dtp->dt_vmax = _dtrace_versions[i]; dtp->dt_cpp_path =strdup (_dtrace_defcpp); dtp->dt_cpp_argv =malloc (sizeof (char *)); dtp->dt_cpp_argc =1 ;
libdtrace/dt_version.h +5 -9
@@ -38,18 +38,15 @@ extern "C" {* * These #defines are used in identifier tables to fill in the version fields * associated with each identifier. The DT_VERS_* macros declare the encoded -* integer values of all versions used so far. DT_VERS_LATEST must correspond -* to the latest version value among all versions exported by the D compiler. -* DT_VERS_STRING must be an ASCII string that contains DT_VERS_LATEST within -* it along with any suffixes (e.g. Beta). +* integer values of all versions used so far. DT_VERS_STRING must be an ASCII +* string that contains the latest version within it along with any suffixes +* (e.g. Beta). You must update DT_VERS_STRING when adding a new version, +* and then add the new version to the _dtrace_versions[] array declared in +* dt_open.c. * * Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an * explanation of these DTrace features and their values. * -* You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, -* and then add the new version to the _dtrace_versions[] array declared in -* dt_open.c.. -* * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this.
@@ -85,7 +82,6 @@ extern "C" {#define DT_VERS_2_0 DT_VERSION_NUMBER(2, 0, 0)#define DT_VERS_2_0_1 DT_VERSION_NUMBER(2, 0, 1) -#define DT_VERS_LATEST DT_VERS_2_0_1#define DT_VERS_STRING "Oracle D 2.0"#ifdef __cplusplus
Signature · 1 line
2.43.5
Re: [PATCH 2/4] Eliminate DT_VERS_LATEST
Quoted 17 lines · On Sat, Feb 08, 2025 at 02:06:20PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Updating the DTrace version number requires too many distinct changes. Eliminate
DT_VERS_LATEST, since it can be determined on the fly.Signed-off-by Eugene Loh <[email protected]>--- libdtrace/dt_open.c | 3 ++- libdtrace/dt_version.h | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-)libdtrace/dt_open.c +0
-0
libdtrace/dt_open.c dt_vopen(int version, int flags, int *errp, · line 725
Quoted 6 lines
libdtrace/dt_open.c +2
-1@@ -721,7 +721,8 @@ dt_vopen(int version, int flags, int *errp, dtp->dt_proc_fd =eventfd (0 ,EFD_CLOEXEC |EFD_NONBLOCK );if (dt_aggregate_init (dtp) ==-1 )return set_open_errno (dtp, errp,dtrace_errno (dtp)); - dtp->dt_vmax =DT_VERS_LATEST ; +for (i =0 ; _dtrace_versions[i] !=0 ; i++) + dtp->dt_vmax = _dtrace_versions[i];
dtp->dt_vmax = _dtrace_versions[ARRAY_SIZE(_dtrace_versions) - 2];
(-2 to account for the 0 sentinel value)
But this will only be accurate if you also add 2.0.1 to the _dtrace_versions array, and then you should probably add 2.0.2 to it also for accuracy.
Quoted 32 lines
libdtrace/dt_open.c +0
-0dtp->dt_cpp_path =strdup (_dtrace_defcpp); dtp->dt_cpp_argv =malloc (sizeof (char *)); dtp->dt_cpp_argc =1 ;libdtrace/dt_version.h +5
-8@@ -38,18 +38,15 @@ extern "C" {* * These #defines are used in identifier tables to fill in the version fields * associated with each identifier. The DT_VERS_* macros declare the encoded -* integer values of all versions used so far. DT_VERS_LATEST must correspond -* to the latest version value among all versions exported by the D compiler. -* DT_VERS_STRING must be an ASCII string that contains DT_VERS_LATEST within -* it along with any suffixes (e.g. Beta). +* integer values of all versions used so far. DT_VERS_STRING must be an ASCII +* string that contains the latest version within it along with any suffixes +* (e.g. Beta). You must update DT_VERS_STRING when adding a new version, +* and then add the new version to the _dtrace_versions[] array declared in +* dt_open.c. * * Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an * explanation of these DTrace features and their values. * -* You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, -* and then add the new version to the _dtrace_versions[] array declared in -* dt_open.c.. -* * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this.
libdtrace/dt_version.h extern "C" { · line 85
Quoted 5 lines
libdtrace/dt_version.h +0
-1@@ -85,7 +82,6 @@ extern "C" {#define DT_VERS_2_0 DT_VERSION_NUMBER(2, 0, 0)#define DT_VERS_2_0_1 DT_VERSION_NUMBER(2, 0, 1) -#define DT_VERS_LATEST DT_VERS_2_0_1#define DT_VERS_STRING "Oracle D 2.0"
You should add 2.0.2 and update the DT_VERS_STRING also.
Quoted 5 lines
libdtrace/dt_version.h +0
-0#ifdef __cplusplusSignature · 1 line
2.43.5
Re: [DTrace-devel] [PATCH 2/4] Eliminate DT_VERS_LATEST
There is some overlap with the patch that follows this one, and that got me thinking a bit more...
I think that we should rework all this a little bit, and have dt_version.h be the sole source of version number data. We can put macros in there that provide all the version information (strings and codes), and use that to populate everything else, I think. That way we reduce the places where changes need to be made (somewhat).
Let me muse on that a little and I'll follow-up with another email soon with a example of what I am envisioing.
Quoted 82 lines · Kris Van Hees via DTrace-devel
Quoted 17 lines · On Sat, Feb 08, 2025 at 02:06:20PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Updating the DTrace version number requires too many distinct changes. Eliminate
DT_VERS_LATEST, since it can be determined on the fly.Signed-off-by Eugene Loh <[email protected]>--- libdtrace/dt_open.c | 3 ++- libdtrace/dt_version.h | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-)libdtrace/dt_open.c +0
-0libdtrace/dt_open.c dt_vopen(int version, int flags, int *errp, · line 725
Quoted 6 lines
libdtrace/dt_open.c +2
-1@@ -721,7 +721,8 @@ dt_vopen(int version, int flags, int *errp, dtp->dt_proc_fd =eventfd (0 ,EFD_CLOEXEC |EFD_NONBLOCK );if (dt_aggregate_init (dtp) ==-1 )return set_open_errno (dtp, errp,dtrace_errno (dtp)); - dtp->dt_vmax =DT_VERS_LATEST ; +for (i =0 ; _dtrace_versions[i] !=0 ; i++) + dtp->dt_vmax = _dtrace_versions[i];
dtp->dt_vmax= _dtrace_versions[ARRAY_SIZE(_dtrace_versions) - 2];(-2 to account for the 0 sentinel value)
But this will only be accurate if you also add 2.0.1 to the
_dtrace_versionsarray, and then you should probably add 2.0.2 to it also for accuracy.Quoted 32 lines
libdtrace/dt_open.c +0
-0dtp->dt_cpp_path =strdup (_dtrace_defcpp); dtp->dt_cpp_argv =malloc (sizeof (char *)); dtp->dt_cpp_argc =1 ;libdtrace/dt_version.h +5
-8@@ -38,18 +38,15 @@ extern "C" {* * These #defines are used in identifier tables to fill in the version fields * associated with each identifier. The DT_VERS_* macros declare the encoded -* integer values of all versions used so far. DT_VERS_LATEST must correspond -* to the latest version value among all versions exported by the D compiler. -* DT_VERS_STRING must be an ASCII string that contains DT_VERS_LATEST within -* it along with any suffixes (e.g. Beta). +* integer values of all versions used so far. DT_VERS_STRING must be an ASCII +* string that contains the latest version within it along with any suffixes +* (e.g. Beta). You must update DT_VERS_STRING when adding a new version, +* and then add the new version to the _dtrace_versions[] array declared in +* dt_open.c. * * Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an * explanation of these DTrace features and their values. * -* You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, -* and then add the new version to the _dtrace_versions[] array declared in -* dt_open.c.. -* * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this. libdtrace/dt_version.h extern "C" { · line 85
Quoted 5 lines
libdtrace/dt_version.h +0
-1@@ -85,7 +82,6 @@ extern "C" {#define DT_VERS_2_0 DT_VERSION_NUMBER(2, 0, 0)#define DT_VERS_2_0_1 DT_VERSION_NUMBER(2, 0, 1) -#define DT_VERS_LATEST DT_VERS_2_0_1#define DT_VERS_STRING "Oracle D 2.0"You should add 2.0.2 and update the
DT_VERS_STRINGalso.Quoted 5 lines
libdtrace/dt_version.h +0
-0#ifdef __cplusplusSignature · 1 line
2.43.5_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel
Re: [DTrace-devel] [PATCH 2/4] Eliminate DT_VERS_LATEST
Quoted 11 lines · Kris Van Hees
There is some overlap with the patch that follows this one, and that got me thinking a bit more...
I think that we should rework all this a little bit, and have
dt_version.hbe the sole source of version number data. We can put macros in there that provide all the version information (strings and codes), and use that to populate everything else, I think. That way we reduce the places where changes need to be made (somewhat).Let me muse on that a little and I'll follow-up with another email soon with a example of what I am envisioing.
See the patch I just posted:
[PATCH] Refactor the versioning handling system
I think it might accomplish the same thing, i.e. consolidating the places where changes are needed for new versions? I was going to just do some prototype of a possible solution but that one didn't work out (it needed to expose too much of the version handling to other code), and then I came up with this idea.
Open to suggestions/feedback/...
Quoted 83 lines · Kris Van Hees via DTrace-devel
Quoted 82 lines · On Sat, Feb 08, 2025 at 02:06:20PM -0500, [email protected] wrote:
Quoted 17 lines
From: Eugene Loh <[email protected]>
Updating the DTrace version number requires too many distinct changes. Eliminate
DT_VERS_LATEST, since it can be determined on the fly.Signed-off-by Eugene Loh <[email protected]>--- libdtrace/dt_open.c | 3 ++- libdtrace/dt_version.h | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-)libdtrace/dt_open.c +0
-0libdtrace/dt_open.c dt_vopen(int version, int flags, int *errp, · line 725
Quoted 6 lines
libdtrace/dt_open.c +2
-1@@ -721,7 +721,8 @@ dt_vopen(int version, int flags, int *errp, dtp->dt_proc_fd =eventfd (0 ,EFD_CLOEXEC |EFD_NONBLOCK );if (dt_aggregate_init (dtp) ==-1 )return set_open_errno (dtp, errp,dtrace_errno (dtp)); - dtp->dt_vmax =DT_VERS_LATEST ; +for (i =0 ; _dtrace_versions[i] !=0 ; i++) + dtp->dt_vmax = _dtrace_versions[i];
dtp->dt_vmax= _dtrace_versions[ARRAY_SIZE(_dtrace_versions) - 2];(-2 to account for the 0 sentinel value)
But this will only be accurate if you also add 2.0.1 to the
_dtrace_versionsarray, and then you should probably add 2.0.2 to it also for accuracy.Quoted 32 lines
libdtrace/dt_open.c +0
-0dtp->dt_cpp_path =strdup (_dtrace_defcpp); dtp->dt_cpp_argv =malloc (sizeof (char *)); dtp->dt_cpp_argc =1 ;libdtrace/dt_version.h +5
-8@@ -38,18 +38,15 @@ extern "C" {* * These #defines are used in identifier tables to fill in the version fields * associated with each identifier. The DT_VERS_* macros declare the encoded -* integer values of all versions used so far. DT_VERS_LATEST must correspond -* to the latest version value among all versions exported by the D compiler. -* DT_VERS_STRING must be an ASCII string that contains DT_VERS_LATEST within -* it along with any suffixes (e.g. Beta). +* integer values of all versions used so far. DT_VERS_STRING must be an ASCII +* string that contains the latest version within it along with any suffixes +* (e.g. Beta). You must update DT_VERS_STRING when adding a new version, +* and then add the new version to the _dtrace_versions[] array declared in +* dt_open.c. * * Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an * explanation of these DTrace features and their values. * -* You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, -* and then add the new version to the _dtrace_versions[] array declared in -* dt_open.c.. -* * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this. libdtrace/dt_version.h extern "C" { · line 85
Quoted 5 lines
libdtrace/dt_version.h +0
-1@@ -85,7 +82,6 @@ extern "C" {#define DT_VERS_2_0 DT_VERSION_NUMBER(2, 0, 0)#define DT_VERS_2_0_1 DT_VERSION_NUMBER(2, 0, 1) -#define DT_VERS_LATEST DT_VERS_2_0_1#define DT_VERS_STRING "Oracle D 2.0"You should add 2.0.2 and update the
DT_VERS_STRINGalso.Quoted 5 lines
libdtrace/dt_version.h +0
-0#ifdef __cplusplusSignature · 1 line
2.43.5_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel
PATCH 3/4 Sync up the version numbers
In reply to [email protected]From: Eugene Loh <[email protected]>
DTrace has many version numbers -- e.g., for the release, packaging, and API.
In reality, the variations in numbering have become nearly meaningless:
- Packaging numbers -- like the Version in the dtrace*spec RPM spec file and the VERSION in GNUmakefile -- have basically been tracking the DTrace release since 2.0 anyway.
- Stability attributes for idents are haphazard. Generally, they are 1.0 (or sometimes other 1.x), and all the BPFs are 2.0. While this is generally accurate, it is not exactly robust, and idents are sometimes introduced or modified without careful regard to the version number. Further, the stability of user D scripts is likely to depend more on kernel variations -- e.g., the contents of available_filter_functions -- than on D changes.
- Version number updates are susceptible to mistakes, and so there have been version mismatches.
Bring the version numbers into sync for 2.0.2. Clean up the descriptions in dt_version.h.
--- GNUmakefile | 5 +- dtrace.spec | 1 + libdtrace/dt_open.c | 3 ++ libdtrace/dt_version.h | 53 ++++++++++++-------- test/unittest/dtrace-util/tst.APIVersion.r | 2 +- test/unittest/dtrace-util/tst.APIVersion.r.p | 6 +++ test/unittest/options/tst.version.r | 2 +- test/unittest/options/tst.version.sh | 4 +- 8 files changed, 50 insertions(+), 26 deletions(-) create mode 100755 test/unittest/dtrace-util/tst.APIVersion.r.p
GNUmakefile +3 -2
@@ -3,7 +3,7 @@ # Build files in subdirectories are included by this file. # # Oracle Linux DTrace. -# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 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.
@@ -14,7 +14,8 @@ SHELL = /bin/bash PROJECT := dtrace -VERSION := 2.0.1 +# When updating version, see comments in dt_version.h. +VERSION := 2.0.2 # Verify supported hardware.
dtrace.spec +1 -0
@@ -87,6 +87,7 @@ Requires: libdtrace-ctf >= 1.1.0 BuildRequires: libdtrace-ctf-devel >= 1.1.0 %endif Summary: DTrace user interface. +# When updating version, see comments in dt_version.h. Version: 2.0.2 Release: 1%{?dist} Source: dtrace-%{version}.tar.bz2
libdtrace/dt_open.c +3 -0
@@ -58,6 +58,9 @@ const dt_version_t _dtrace_versions[] = {DT_VERS_1_6_3 ,/* D API 1.6.3 */ DT_VERS_1_6_4 ,/* D API 1.6.4 */ DT_VERS_2_0 ,/* D API 2.0 */ +DT_VERS_2_0_1 ,/* D API 2.0.1 */ +DT_VERS_2_0_2 ,/* D API 2.0.2 */ +/* When updating version, see comments in dt_version.h. */ 0 };
libdtrace/dt_version.h +33 -20
73 lines not on this page · raw message
test/unittest/dtrace-util/tst.APIVersion.r +1 -1
@@ -1 +1 @@ -dtrace: Oracle D 2.0 +dtrace: Oracle D 2.0.x
test/unittest/dtrace-util/tst.APIVersion.r.p new file +6 -0
@@ -0,0 +1,6 @@ +#!/usr/bin/gawk -f + +# The test allows the version string to vary in micro number as well as +# other suffixes (like "Beta"). The .r.p and .r files still need to be +# updated for each minor number change. +{ sub("^dtrace: Oracle D 2\\.0\\..*$", "dtrace: Oracle D 2.0.x"); print }
test/unittest/options/tst.version.r +1 -1
@@ -1,2 +1,2 @@ -version is 2.0 +version is 2.0.x
test/unittest/options/tst.version.sh +2 -2
@@ -1,7 +1,7 @@ #!/bin/bash # # Oracle Linux DTrace. -# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2023, 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. #
@@ -9,7 +9,7 @@ dtrace=$1 myversion=`$dtrace $dt_flags -V | gawk '{ print $NF }'` -echo version is $myversion +echo version is $myversion | sed 's:2.0.[0-9]:2.0.x:' $dtrace $dt_flags -xversion=$myversion -qn 'BEGIN { exit(0) }' exit $?
Signature · 1 line
2.43.5
PATCH 4/4 test: Add test for predefined preprocessor definitions
In reply to [email protected]From: Eugene Loh <[email protected]>
Orabug: 28763074
--- COMMANDLINE-OPTIONS | 10 +- test/unittest/preprocessor/tst.predefined.r | 1 + test/unittest/preprocessor/tst.predefined.sh | 119 +++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 test/unittest/preprocessor/tst.predefined.r create mode 100755 test/unittest/preprocessor/tst.predefined.sh
COMMANDLINE-OPTIONS +5 -5
@@ -321,12 +321,12 @@ definitions are always specified and valid in all modes: * __sparcv9 (on SPARC® systems only when 64–bit programs are compiled) * __i386 (on x86 systems only when 32–bit programs are compiled) * __amd64 (on x86 systems only when 64–bit programs are compiled) - * _`uname -s` (for example, __Linux) + * __`uname -s` (for example, __Linux) * __SUNW_D=1 - * _SUNW_D_VERSION=0x_MMmmmuuu (where MM is the Major release value - in hexadecimal, mmm is the Minor release value in hexadecimal, - and uuu is the Micro release value in hexadecimal; see Chapter - 41, Versioning for more information about DTrace versioning) + * _SUNW_D_VERSION=(MM << 24 | mmm << 12 | uuu), where + MM is the Major release value + mmm is the Minor release value + uuu is the Micro release value -Z Permit probe descriptions that match zero probes. If the -Z option is
test/unittest/preprocessor/tst.predefined.r new file +1 -0
@@ -0,0 +1 @@ +success
test/unittest/preprocessor/tst.predefined.sh new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.43.5
Re: [PATCH 4/4] test: Add test for predefined preprocessor definitions
Quoted 4 lines · On Sat, Feb 08, 2025 at 02:06:22PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Orabug: 28763074
Signed-off-by Eugene Loh <[email protected]>
... and incidentally, should we add defines with ORCL instead of SUNW
(but keep SUNW variants for backwards compatibility)? Or some other forms that do not include SUNW. Things like __DTRACE?
Quoted 165 lines
--- COMMANDLINE-OPTIONS | 10 +- test/unittest/preprocessor/tst.predefined.r | 1 + test/unittest/preprocessor/tst.predefined.sh | 119 +++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 test/unittest/preprocessor/tst.predefined.r create mode 100755 test/unittest/preprocessor/tst.predefined.shCOMMANDLINE-OPTIONS +5
-5@@ -321,12 +321,12 @@ definitions are always specified and valid in all modes: * __sparcv9 (on SPARC® systems only when 64–bit programs are compiled) * __i386 (on x86 systems only when 32–bit programs are compiled) * __amd64 (on x86 systems only when 64–bit programs are compiled) - * _`uname -s` (for example, __Linux) + * __`uname -s` (for example, __Linux) * __SUNW_D=1 - * _SUNW_D_VERSION=0x_MMmmmuuu (where MM is the Major release value - in hexadecimal, mmm is the Minor release value in hexadecimal, - and uuu is the Micro release value in hexadecimal; see Chapter - 41, Versioning for more information about DTrace versioning) + * _SUNW_D_VERSION=(MM << 24 | mmm << 12 | uuu), where + MM is the Major release value + mmm is the Minor release value + uuu is the Micro release value -Z Permit probe descriptions that match zero probes. If the -Z option istest/unittest/preprocessor/tst.predefined.r new file +1
-0@@ -0,0 +1 @@ +successtest/unittest/preprocessor/tst.predefined.sh new file +119
-0@@ -0,0 +1,119 @@ +#!/bin/bash +# +# 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. +# +# Confirm preprocessor pre-definitions. + +dtrace=$1 + +DIRNAME=$tmpdir/predefined.$$.$RANDOM +mkdir -p $DIRNAME +cd $DIRNAME + +# Arg 1 is macro that we check is defined. + +function check_defined() { + # Add to script: #ifdef is okay, else is ERROR. + echo '#ifdef' $1 >> D.d + echo 'printf("'$1' okay\n");' >> D.d + echo '#else' >> D.d + echo 'printf("ERROR! missing '$1'\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo $1 okay >> chk.txt +} + +# Arg 1 is macro whose value we check to be arg 2. + +function check_value() { + # Add to script: print value. + echo 'printf("'$1'=%x\n", '$1');' >> D.d + + # Add to check file: expected value. + echo $1=$2 >> chk.txt +} + +# Arg 1 is macro that we check is not defined. + +function check_undef() { + # Add to script: #ifdef is ERROR, else is okay. + echo '#ifdef' $1 >> D.d + echo 'printf("ERROR! found '$1'\n");' >> D.d + echo '#else' >> D.d + echo 'printf("missing '$1' is okay\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo missing $1 is okay >> chk.txt +} + +# Construct version string (major, minor, micro). + +read MM mmm uuu <<< `dtrace -vV | awk '/^This is DTrace / { gsub("\\\.", " "); print $(NF-2), $(NF-1), $NF }'` +vers=`printf "%x" $(($MM << 24 | $mmm << 12 | $uuu))` + +# Start setting up the D script. + +echo 'BEGIN {' > D.d + +# Check for the preprocessor definitions of COMMANDLINE-OPTIONS. + +check_defined __linux +check_defined __unix +check_defined __SVR4 +if [ `uname -m` == x86_64 ]; then +check_defined __amd64 +else +check_undef __amd64 +fi +check_defined __`uname -s` +check_value __SUNW_D 1 +check_value __SUNW_D_VERSION $vers + +# Confirm other preprocessor definitions. + +check_defined __SUNW_D_64 + +# Confirm that __GNUC__ is not present. + +check_undef __GNUC__ + +# Finish setting up the D script. + +echo 'exit(0); }' >> D.d +echo >> chk.txt + +# Run the D script. + +$dtrace $dt_flags -qCs D.d -o out.txt +if [ $? -ne 0 ]; then + echo ERROR: DTrace failed + echo "==== D.d" + cat D.d + echo "==== out.txt" + cat out.txt + exit 1 +fi + +# Check. + +if ! diff -q chk.txt out.txt; then + echo ERROR output disagrees + echo === expect === + cat chk.txt + echo === actual === + cat out.txt + echo === diff === + diff chk.txt out.txt + exit 1 +fi + +# Indicate success. + +echo success + +exit 0Signature · 1 line
2.43.5
Re: [PATCH 4/4] test: Add test for predefined preprocessor definitions
Quoted 10 lines · Kris Van Hees
Quoted 4 lines · On Sat, Feb 08, 2025 at 02:06:22PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Orabug: 28763074
Signed-off-by Eugene Loh <[email protected]>Reviewed-by Kris Van Hees <[email protected]>... and incidentally, should we add defines with ORCL instead of SUNW
(but keep SUNW variants for backwards compatibility)? Or some other forms that do not include SUNW. Things like__DTRACE?
Separate patch, right? And, we need to coordinate documentation.
Quoted 165 lines
Quoted 165 lines
--- COMMANDLINE-OPTIONS | 10 +- test/unittest/preprocessor/tst.predefined.r | 1 + test/unittest/preprocessor/tst.predefined.sh | 119 +++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-)create mode 100644 test/unittest/preprocessor/tst.predefined.r create mode 100755
test/unittest/preprocessor/tst.predefined.shCOMMANDLINE-OPTIONS +5
-5@@ -321,12 +321,12 @@ definitions are always specified and valid in all modes: * __sparcv9 (on SPARC® systems only when 64–bit programs are compiled) * __i386 (on x86 systems only when 32–bit programs are compiled) * __amd64 (on x86 systems only when 64–bit programs are compiled) - * _`uname -s` (for example, __Linux) + * __`uname -s` (for example, __Linux) * __SUNW_D=1 - * _SUNW_D_VERSION=0x_MMmmmuuu (where MM is the Major release value - in hexadecimal, mmm is the Minor release value in hexadecimal, - and uuu is the Micro release value in hexadecimal; see Chapter - 41, Versioning for more information about DTrace versioning) + * _SUNW_D_VERSION=(MM << 24 | mmm << 12 | uuu), where + MM is the Major release value + mmm is the Minor release value + uuu is the Micro release value -Z Permit probe descriptions that match zero probes. If the -Z option istest/unittest/preprocessor/tst.predefined.r new file +1
-0@@ -0,0 +1 @@ +successtest/unittest/preprocessor/tst.predefined.sh new file +119
-0@@ -0,0 +1,119 @@ +#!/bin/bash +# +# 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. +# +# Confirm preprocessor pre-definitions. + +dtrace=$1 + +DIRNAME=$tmpdir/predefined.$$.$RANDOM +mkdir -p $DIRNAME +cd $DIRNAME + +# Arg 1 is macro that we check is defined. + +function check_defined() { + # Add to script: #ifdef is okay, else is ERROR. + echo '#ifdef' $1 >> D.d + echo 'printf("'$1' okay\n");' >> D.d + echo '#else' >> D.d + echo 'printf("ERROR! missing '$1'\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo $1 okay >> chk.txt +} + +# Arg 1 is macro whose value we check to be arg 2. + +function check_value() { + # Add to script: print value. + echo 'printf("'$1'=%x\n", '$1');' >> D.d + + # Add to check file: expected value. + echo $1=$2 >> chk.txt +} + +# Arg 1 is macro that we check is not defined. + +function check_undef() { + # Add to script: #ifdef is ERROR, else is okay. + echo '#ifdef' $1 >> D.d + echo 'printf("ERROR! found '$1'\n");' >> D.d + echo '#else' >> D.d + echo 'printf("missing '$1' is okay\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo missing $1 is okay >> chk.txt +} + +# Construct version string (major, minor, micro). + +read MM mmm uuu <<< `dtrace -vV | awk '/^This is DTrace / { gsub("\\\.", " "); print $(NF-2), $(NF-1), $NF }'` +vers=`printf "%x" $(($MM << 24 | $mmm << 12 | $uuu))` + +# Start setting up the D script. + +echo 'BEGIN {' > D.d + +# Check for the preprocessor definitions of COMMANDLINE-OPTIONS. + +check_defined __linux +check_defined __unix +check_defined __SVR4 +if [ `uname -m` == x86_64 ]; then +check_defined __amd64 +else +check_undef __amd64 +fi +check_defined __`uname -s` +check_value __SUNW_D 1 +check_value __SUNW_D_VERSION $vers + +# Confirm other preprocessor definitions. + +check_defined __SUNW_D_64 + +# Confirm that __GNUC__ is not present. + +check_undef __GNUC__ + +# Finish setting up the D script. + +echo 'exit(0); }' >> D.d +echo >> chk.txt + +# Run the D script. + +$dtrace $dt_flags -qCs D.d -o out.txt +if [ $? -ne 0 ]; then + echo ERROR: DTrace failed + echo "==== D.d" + cat D.d + echo "==== out.txt" + cat out.txt + exit 1 +fi + +# Check. + +if ! diff -q chk.txt out.txt; then + echo ERROR output disagrees + echo === expect === + cat chk.txt + echo === actual === + cat out.txt + echo === diff === + diff chk.txt out.txt + exit 1 +fi + +# Indicate success. + +echo success + +exit 0Signature · 1 line
2.43.5
Re: [PATCH 4/4] test: Add test for predefined preprocessor definitions
Quoted 7 lines · Eugene Loh
Quoted 5 lines · Kris Van Hees
Quoted 4 lines · On Sat, Feb 08, 2025 at 02:06:22PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
Orabug: 28763074
Signed-off-by Eugene Loh <[email protected]>
Quoted 7 lines
Quoted 5 lines
Reviewed-by Kris Van Hees <[email protected]>... and incidentally, should we add defines with ORCL instead of SUNW
(but keep SUNW variants for backwards compatibility)? Or some other forms that do not include SUNW. Things like__DTRACE?Separate patch, right? And, we need to coordinate documentation.
Yes, definitely separate patch.
Quoted 164 lines
Quoted 164 lines
Quoted 164 lines
--- COMMANDLINE-OPTIONS | 10 +- test/unittest/preprocessor/tst.predefined.r | 1 + test/unittest/preprocessor/tst.predefined.sh | 119 +++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-)create mode 100644 test/unittest/preprocessor/tst.predefined.r create mode 100755
test/unittest/preprocessor/tst.predefined.shCOMMANDLINE-OPTIONS +5
-5@@ -321,12 +321,12 @@ definitions are always specified and valid in all modes: * __sparcv9 (on SPARC® systems only when 64???bit programs are compiled) * __i386 (on x86 systems only when 32???bit programs are compiled) * __amd64 (on x86 systems only when 64???bit programs are compiled) - * _`uname -s` (for example, __Linux) + * __`uname -s` (for example, __Linux) * __SUNW_D=1 - * _SUNW_D_VERSION=0x_MMmmmuuu (where MM is the Major release value - in hexadecimal, mmm is the Minor release value in hexadecimal, - and uuu is the Micro release value in hexadecimal; see Chapter - 41, Versioning for more information about DTrace versioning) + * _SUNW_D_VERSION=(MM << 24 | mmm << 12 | uuu), where + MM is the Major release value + mmm is the Minor release value + uuu is the Micro release value -Z Permit probe descriptions that match zero probes. If the -Z option istest/unittest/preprocessor/tst.predefined.r new file +1
-0@@ -0,0 +1 @@ +successtest/unittest/preprocessor/tst.predefined.sh new file +119
-0@@ -0,0 +1,119 @@ +#!/bin/bash +# +# 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. +# +# Confirm preprocessor pre-definitions. + +dtrace=$1 + +DIRNAME=$tmpdir/predefined.$$.$RANDOM +mkdir -p $DIRNAME +cd $DIRNAME + +# Arg 1 is macro that we check is defined. + +function check_defined() { + # Add to script: #ifdef is okay, else is ERROR. + echo '#ifdef' $1 >> D.d + echo 'printf("'$1' okay\n");' >> D.d + echo '#else' >> D.d + echo 'printf("ERROR! missing '$1'\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo $1 okay >> chk.txt +} + +# Arg 1 is macro whose value we check to be arg 2. + +function check_value() { + # Add to script: print value. + echo 'printf("'$1'=%x\n", '$1');' >> D.d + + # Add to check file: expected value. + echo $1=$2 >> chk.txt +} + +# Arg 1 is macro that we check is not defined. + +function check_undef() { + # Add to script: #ifdef is ERROR, else is okay. + echo '#ifdef' $1 >> D.d + echo 'printf("ERROR! found '$1'\n");' >> D.d + echo '#else' >> D.d + echo 'printf("missing '$1' is okay\n");' >> D.d + echo '#endif' >> D.d + + # Add to check file: expect "okay" message. + echo missing $1 is okay >> chk.txt +} + +# Construct version string (major, minor, micro). + +read MM mmm uuu <<< `dtrace -vV | awk '/^This is DTrace / { gsub("\\\.", " "); print $(NF-2), $(NF-1), $NF }'` +vers=`printf "%x" $(($MM << 24 | $mmm << 12 | $uuu))` + +# Start setting up the D script. + +echo 'BEGIN {' > D.d + +# Check for the preprocessor definitions of COMMANDLINE-OPTIONS. + +check_defined __linux +check_defined __unix +check_defined __SVR4 +if [ `uname -m` == x86_64 ]; then +check_defined __amd64 +else +check_undef __amd64 +fi +check_defined __`uname -s` +check_value __SUNW_D 1 +check_value __SUNW_D_VERSION $vers + +# Confirm other preprocessor definitions. + +check_defined __SUNW_D_64 + +# Confirm that __GNUC__ is not present. + +check_undef __GNUC__ + +# Finish setting up the D script. + +echo 'exit(0); }' >> D.d +echo >> chk.txt + +# Run the D script. + +$dtrace $dt_flags -qCs D.d -o out.txt +if [ $? -ne 0 ]; then + echo ERROR: DTrace failed + echo "==== D.d" + cat D.d + echo "==== out.txt" + cat out.txt + exit 1 +fi + +# Check. + +if ! diff -q chk.txt out.txt; then + echo ERROR output disagrees + echo === expect === + cat chk.txt + echo === actual === + cat out.txt + echo === diff === + diff chk.txt out.txt + exit 1 +fi + +# Indicate success. + +echo success + +exit 0Signature · 1 line
2.43.5
Quoted 10 lines · On Sat, Feb 08, 2025 at 02:06:19PM -0500, [email protected] wrote:
From: Eugene Loh <[email protected]>
There are many DTrace version numbers (for version, API version, package version, etc.). Meanwhile,
_DTRACE_VERSIONis not a version number at all. It's a preprocessor macro in USDT .h header files. Prior to commite2fb0ecd9
("Ensure multiple passes through dtrace -G work."), it was perhaps not even set. With that commit, it was always set to 1, with the rationale:
Quoted 8 lines
Also add an explicit define for
_DTRACE__VERSIONin the generated header file from 'dtrace -h' invocations. This seems silly, but it is there to give people a skeleton to work with if they want to pre-generate header files and select whether to actually compile on the probes at a later time.Rename to
_DTRACE_HEADERfor better clarity. Define it only once per file.
Based on the rationale, I would think that something like _DTRACE_USE_USDT or somethng similar would be better? Since the purpose seems to be to allow (after the header file is generated) for someone to change that 1 to 0 to disable the USDT probes to be compiled in.
In fact, if we want to support this in a more developer-friendly way, we might as well change the generted line to be more like:
#ifndef _DTRACE_USE_USDT
# define _DTARCE_USE_USDT 1 #endif
so that a package could e.g. allow a configure option or something to set it to 1 or 0, dypassing the need to manually change the file.
Quoted 38 lines
Signed-off-by Eugene Loh <[email protected]>--- libdtrace/dt_program.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)libdtrace/dt_program.c +5
-3@@ -505,13 +505,12 @@ dt_header_provider(dtrace_hdl_t *dtp, dt_provider_t *pvp, FILE *out) info.dthi_pfname =alloca (strlen (pvp->desc.dtvd_name) +1 + i);dt_header_fmt_func (info.dthi_pfname, pvp->desc.dtvd_name); -if (fprintf (out,"#define _DTRACE_VERSION 1\n\n" -"#if _DTRACE_VERSION\n\n" ) <0 ) +if (fprintf (out,"#if _DTRACE_HEADER\n\n" ) <0 )return dt_set_errno (dtp, errno);if (dt_idhash_iter (pvp->pv_probes, dt_header_probe, &info) !=0 )return -1 ;/* dt_errno is set for us */ -if (fprintf (out,"\n\n" ) <0 ) +if (fprintf (out,"\n" ) <0 )return dt_set_errno (dtp, errno);if (dt_idhash_iter (pvp->pv_probes, dt_header_decl, &info) !=0 )return -1 ;/* dt_errno is set for us */ @@ -560,6 +559,9 @@ dtrace_program_header(dtrace_hdl_t *dtp, FILE *out, const char *fname) "#endif\n\n") < 0)return -1 ; +if (fprintf (out,"#define _DTRACE_HEADER 1\n\n" ) <0 ) +return -1 ; +while ((pvp =dt_htab_next (dtp->dt_provs, &it)) !=NULL ) {if (dt_header_provider (dtp, pvp, out) !=0 ) {dt_htab_next_destroy (it);Signature · 1 line
2.43.5