[DTrace-devel] [PATCH v3] Refactor the versioning handling system (consolidate data)

Eugene Loh eugene.loh at oracle.com
Tue Aug 19 02:58:19 UTC 2025


Reviewed-by: Eugene Loh <eugene.loh at oracle.com>

On 8/18/25 18:19, Kris Van Hees via DTrace-devel wrote:
> Rather than having multiple data items that need to be updated whenever
> a new version is released, a single entry in versions.list will now be
> all that is needed.  The mkvers script generates the necessary defines,
> and is also used to return the most recent release version to be used
> in GNUmakefile.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>   GNUmakefile                                  |  2 +-
>   libdtrace/.gitignore                         |  1 +
>   libdtrace/Build                              |  8 +-
>   libdtrace/dt_version.h                       | 82 +-------------------
>   libdtrace/mkvers                             | 67 ++++++++++++++++
>   libdtrace/versions.list                      | 67 ++++++++++++++++
>   test/unittest/dtrace-util/tst.APIVersion.d   | 11 +--
>   test/unittest/dtrace-util/tst.APIVersion.r   |  2 +-
>   test/unittest/dtrace-util/tst.APIVersion.r.p | 12 +++
>   test/unittest/options/tst.version.r          |  1 -
>   test/unittest/options/tst.version.sh         |  3 +-
>   11 files changed, 163 insertions(+), 93 deletions(-)
>   create mode 100755 libdtrace/mkvers
>   create mode 100644 libdtrace/versions.list
>   create mode 100755 test/unittest/dtrace-util/tst.APIVersion.r.p
>
> diff --git a/GNUmakefile b/GNUmakefile
> index 7ad857f88..38ae54236 100644
> --- a/GNUmakefile
> +++ b/GNUmakefile
> @@ -14,7 +14,7 @@
>   SHELL = /bin/bash
>   
>   PROJECT := dtrace
> -VERSION := 2.0.3
> +VERSION := $(shell ./libdtrace/mkvers -vcurrent=t libdtrace/versions.list)
>   
>   # Verify supported hardware.
>   
> diff --git a/libdtrace/.gitignore b/libdtrace/.gitignore
> index cf124ba1d..ebf6ac9b2 100644
> --- a/libdtrace/.gitignore
> +++ b/libdtrace/.gitignore
> @@ -3,6 +3,7 @@ dt_errtags.c
>   dt_grammar.[ch]
>   dt_lex.c
>   dt_names.c
> +dt_versions_defs.h
>   errno.d
>   regs.d
>   signal.d
> diff --git a/libdtrace/Build b/libdtrace/Build
> index 164023bbc..3540d1c12 100644
> --- a/libdtrace/Build
> +++ b/libdtrace/Build
> @@ -73,7 +73,8 @@ libdtrace-build_SOURCES = dt_aggregate.c \
>   			  dt_work.c \
>   			  dt_xlator.c
>   
> -libdtrace-build_SRCDEPS := dt_grammar.h $(objdir)/dt_git_version.h
> +libdtrace-build_SRCDEPS := dt_grammar.h dt_versions_defs.h \
> +			   $(objdir)/dt_git_version.h
>   
>   SHLIBS += libdtrace
>   
> @@ -129,6 +130,10 @@ SHORTKERNELS := $(foreach kernel,$(KERNELS),$(shell printf %s $(kernel) | sed -e
>   $(libdtrace-build_DIR)dt_errtags.c: $(libdtrace-build_DIR)dt_errtags.h $(libdtrace-build_DIR)/mkerrtags.sh
>   	sh $(libdtrace-build_DIR)mkerrtags.sh < $(libdtrace-build_DIR)dt_errtags.h | sed -e 's/\\n/\n/g' > $@
>   
> +$(libdtrace-build_DIR)dt_versions_defs.h: $(libdtrace-build_DIR)versions.list
> +	$(call describe-target,MKVERS,$@)
> +	$(libdtrace-build_DIR)mkvers $< > $@
> +
>   $(libdtrace-build_DIR)%.h $(libdtrace-build_DIR)%.c: $(libdtrace-build_DIR)%.y
>   	$(call describe-target,YACC,$(libdtrace-build_DIR)$*.c)
>   	bison -o $(libdtrace-build_DIR)$*.c -d $(libdtrace-build_DIR)$*.y
> @@ -279,6 +284,7 @@ clean::
>   	rm -f $(libdtrace-build_DIR)dt_errtags.c
>   	rm -f $(libdtrace-build_DIR)dt_grammar.h $(libdtrace-build_DIR)dt_grammar.c
>   	rm -f $(libdtrace-build_DIR)dt_lex.c
> +	rm -f $(libdtrace-build_DIR)dt_versions_defs.h
>   	rm -f $(addprefix $(libdtrace-build_DIR),$(BUILD_DLIBS))
>   
>   install::
> diff --git a/libdtrace/dt_version.h b/libdtrace/dt_version.h
> index 8dd252b08..527087db3 100644
> --- a/libdtrace/dt_version.h
> +++ b/libdtrace/dt_version.h
> @@ -13,83 +13,7 @@ extern "C" {
>   #endif
>   
>   #include <dt_ident.h>
> -
> -/*
> - * Versioning definitions
> - *
> - * 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).
> - *
> - * Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an
> - * explanation of these DTrace features and their values.
> - *
> - * When adding a new version:
> - *  - Add a new DT_VERS_* macro
> - *  - Add the new DT_VERS_* macro at the end of the DTRACE_VERSIONS macro
> - *  - Set DT_VERS_LATEST to the new DT_VERS_*
> - *  - Update DT_VERS_STRING to reflect the new version
> - *
> - * 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.
> - *       All versions are assumed to strictly inherit from one another.  If
> - *       we ever need to provide divergent interfaces, this will need work.
> - *
> - * The version number should be increased for every customer visible release
> - * of DTrace.
> - *  - The major number should be incremented when a fundamental change has been
> - *    made that would affect all consumers, and would reflect sweeping changes
> - *    to DTrace or the D language.
> - *  - The minor number should be incremented when a change is introduced that
> - *    could break scripts that had previously worked; for example, adding a new
> - *    built-in variable could break a script which was already using that
> - *    identifier.
> - *  - The micro number should be changed when introducing functionality changes
> - *    or major bug fixes that do not affect backward compatibility -- this is
> - *    merely to make capabilities easily determined from the version number.
> - *    Minor bugs do not require any modification to the version number.
> - */
> -#define	DT_VERS_1_0	DT_VERSION_NUMBER(1, 0, 0)
> -#define	DT_VERS_1_1	DT_VERSION_NUMBER(1, 1, 0)
> -#define	DT_VERS_1_2	DT_VERSION_NUMBER(1, 2, 0)
> -#define	DT_VERS_1_2_1	DT_VERSION_NUMBER(1, 2, 1)
> -#define	DT_VERS_1_2_2	DT_VERSION_NUMBER(1, 2, 2)
> -#define	DT_VERS_1_3	DT_VERSION_NUMBER(1, 3, 0)
> -#define	DT_VERS_1_4	DT_VERSION_NUMBER(1, 4, 0)
> -#define	DT_VERS_1_4_1	DT_VERSION_NUMBER(1, 4, 1)
> -#define	DT_VERS_1_5	DT_VERSION_NUMBER(1, 5, 0)
> -#define	DT_VERS_1_6	DT_VERSION_NUMBER(1, 6, 0)
> -#define	DT_VERS_1_6_1	DT_VERSION_NUMBER(1, 6, 1)
> -#define	DT_VERS_1_6_2	DT_VERSION_NUMBER(1, 6, 2)
> -#define	DT_VERS_1_6_3	DT_VERSION_NUMBER(1, 6, 3)
> -#define	DT_VERS_1_6_4	DT_VERSION_NUMBER(1, 6, 4)
> -#define	DT_VERS_2_0	DT_VERSION_NUMBER(2, 0, 0)
> -#define	DT_VERS_2_0_1	DT_VERSION_NUMBER(2, 0, 1)
> -
> -#define DTRACE_VERSIONS	{ \
> -	DT_VERS_1_0,	/* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ \
> -	DT_VERS_1_1,	/* D API 1.1.0 Solaris Express 6/05 */ \
> -	DT_VERS_1_2,	/* D API 1.2.0 Solaris 10 Update 1 */ \
> -	DT_VERS_1_2_1,	/* D API 1.2.1 Solaris Express 4/06 */ \
> -	DT_VERS_1_2_2,	/* D API 1.2.2 Solaris Express 6/06 */ \
> -	DT_VERS_1_3,	/* D API 1.3 Solaris Express 10/06 */ \
> -	DT_VERS_1_4,	/* D API 1.4 Solaris Express 2/07 */ \
> -	DT_VERS_1_4_1,	/* D API 1.4.1 Solaris Express 4/07 */ \
> -	DT_VERS_1_5,	/* D API 1.5 Solaris Express 7/07 */ \
> -	DT_VERS_1_6,	/* D API 1.6 */ \
> -	DT_VERS_1_6_1,	/* D API 1.6.1 */ \
> -	DT_VERS_1_6_2,	/* D API 1.6.2 */ \
> -	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 */ \
> -}
> -
> -#define	DT_VERS_LATEST	DT_VERS_2_0_1
> -#define	DT_VERS_STRING	"Oracle D 2.0"
> +#include "dt_versions_defs.h"
>   
>   /*
>    * Interfaces for parsing and handling DTrace version strings.  Version binding
> @@ -112,8 +36,8 @@ extern "C" {
>   
>   typedef uint32_t dt_version_t;
>   
> -extern const dt_version_t _dtrace_versions[];
> -extern const char *const _dtrace_version;
> +extern const dt_version_t	_dtrace_versions[];
> +extern const char *const	_dtrace_version;
>   
>   extern char *dt_version_num2str(dt_version_t, char *, size_t);
>   extern int dt_version_str2num(const char *, dt_version_t *);
> diff --git a/libdtrace/mkvers b/libdtrace/mkvers
> new file mode 100755
> index 000000000..82295b152
> --- /dev/null
> +++ b/libdtrace/mkvers
> @@ -0,0 +1,67 @@
> +#!/usr/bin/gawk -f
> +#
> +# 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.
> +#
> +
> +/^\s*#/ { next; }
> +NF == 0 { next; }
> +
> +{
> +	if (match($1, /^[1-9][0-9]*(\.[0-9]*){1,2}$/) == 0) {
> +		print "E: Invalid version string: " $1 >"/dev/stderr";
> +		exit 1
> +	}
> +
> +	n = split($1, arr, /\./);
> +	if (n == 2)
> +		arr[3] = 0;
> +
> +	code = arr[1] * 0x1000000 + arr[2] * 0x1000 + arr[3];
> +	versions[code] = arr[1] " " arr[2] " " arr[3];
> +	next;
> +}
> +
> +END {
> +	n = asorti(versions, idx);
> +
> +	if (current) {
> +		$0 = versions[idx[n]];
> +		if ($3 == 0)
> +			printf "%s.%s", $1, $2;
> +		else
> +			printf "%s.%s.%s", $1, $2, $3;
> +
> +		exit(0);
> +	}
> +
> +	for (i = 1; i <= n; i++) {
> +		$0 = versions[idx[i]];
> +		if ($3 == 0)
> +			printf "#define DT_VERS_%d_%d\tDT_VERSION_NUMBER(%d, %d, 0)\n",\
> +			       $1, $2, $1, $2;
> +		else
> +			printf "#define DT_VERS_%d_%d_%d\tDT_VERSION_NUMBER(%d, %d, %d)\n",\
> +			       $1, $2, $3, $1, $2, $3;
> +	}
> +
> +	print "\n#define DTRACE_VERSIONS { \\";
> +	for (i = 1; i <= n; i++) {
> +		$0 = versions[idx[i]];
> +		if ($3 == 0)
> +			printf "\t\tDT_VERS_%d_%d, \\\n", $1, $2, $1, $2;
> +		else
> +			printf "\t\tDT_VERS_%d_%d_%d, \\\n", $1, $2, $3, $1, $2, $3;
> +	}
> +	print "}";
> +
> +	if ($3 == 0) {
> +		printf "\n#define DT_VERS_LATEST\tDT_VERS_%d_%d\n", $1, $2;
> +		printf "#define DT_VERS_STRING\t\"Oracle D %d.%d\"\n", $1, $2;
> +	} else {
> +		printf "\n#define DT_VERS_LATEST\tDT_VERS_%d_%d_%d\n", $1, $2, $3;
> +		printf "#define DT_VERS_STRING\t\"Oracle D %d.%d.%d\"\n", $1, $2, $3;
> +	}
> +}
> diff --git a/libdtrace/versions.list b/libdtrace/versions.list
> new file mode 100644
> index 000000000..8986d2007
> --- /dev/null
> +++ b/libdtrace/versions.list
> @@ -0,0 +1,67 @@
> +#
> +# 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.
> +#
> +
> +#
> +# Version definitions
> +#
> +# These definitions are used to generate dt_versions_defs.h.
> +#
> +# The generated file contains:
> +#  - DT_VERS_* defines that are used in identifier tables to fill in the
> +#    version fields associated with each identifier.
> +#
> +#  - DTRACE_VERSIONS which is used in dt_versions.c to populate the array of
> +#    valid DTrace versions
> +#
> +#  - DT_VERS_LATEST which has the value of the most recent DT_VERS_* define
> +#
> +#  - DT_VERS_STRING which provides a string representation of the most recent
> +#    DTrace version
> +#
> +# Refer to the Solaris Dynamic Tracing Guide Versioning chapter for an
> +# explanation of these DTrace features and their values.
> +#
> +# 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.
> +#       All versions are assumed to strictly inherit from one another.  If
> +#       we ever need to provide divergent interfaces, this will need work.
> +#
> +# The version number should be increased for every customer visible release
> +# of DTrace.
> +#  - The major number should be incremented when a fundamental change has been
> +#    made that would affect all consumers, and would reflect sweeping changes
> +#    to DTrace or the D language.
> +#  - The minor number should be incremented when a change is introduced that
> +#    could break scripts that had previously worked; for example, adding a new
> +#    built-in variable could break a script which was already using that
> +#    identifier.
> +#  - The micro number should be changed when introducing functionality changes
> +#    or major bug fixes that do not affect backward compatibility -- this is
> +#    merely to make capabilities easily determined from the version number.
> +#    Minor bugs do not require any modification to the version number.
> +#
> +
> +# Ver	Description
> +1.0	D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS
> +1.1	D API 1.1.0 Solaris Express 6/05
> +1.2	D API 1.2.0 Solaris 10 Update 1
> +1.2.1	D API 1.2.1 Solaris Express 4/06
> +1.2.2	D API 1.2.2 Solaris Express 6/06
> +1.3	D API 1.3 Solaris Express 10/06
> +1.4	D API 1.4 Solaris Express 2/07
> +1.4.1	D API 1.4.1 Solaris Express 4/07
> +1.5	D API 1.5 Solaris Express 7/07
> +1.6	D API 1.6
> +1.6.1	D API 1.6.1
> +1.6.2	D API 1.6.2
> +1.6.3	D API 1.6.3
> +1.6.4	D API 1.6.4
> +2.0	D API 2.0 Linux (BPF)
> +2.0.1	D API 2.0.1 Linux (BPF)
> +2.0.2	D API 2.0.2 Linux (BPF)
> +2.0.3	D API 2.0.3 Linux (BPF)
> diff --git a/test/unittest/dtrace-util/tst.APIVersion.d b/test/unittest/dtrace-util/tst.APIVersion.d
> index 85108c027..3b2baaa60 100644
> --- a/test/unittest/dtrace-util/tst.APIVersion.d
> +++ b/test/unittest/dtrace-util/tst.APIVersion.d
> @@ -1,18 +1,13 @@
>   /*
>    * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 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:
> - * Use the -V option to printout API version.
> +/* ASSERTION: Use the -V option to printout API version.
>    *
> - * SECTION:
> - *	dtrace Utility/-V Option
> - *
> - * NOTES:
> - * Use /usr/sbin/dtrace -V on command line.
> + * SECTION: dtrace Utility/-V Option
>    */
>   
>   /* @@runtest-opts: -V */
> diff --git a/test/unittest/dtrace-util/tst.APIVersion.r b/test/unittest/dtrace-util/tst.APIVersion.r
> index 6bc7b9d72..0d88b694e 100644
> --- a/test/unittest/dtrace-util/tst.APIVersion.r
> +++ b/test/unittest/dtrace-util/tst.APIVersion.r
> @@ -1 +1 @@
> -dtrace: Oracle D 2.0
> +dtrace: Oracle D x.y.z
> diff --git a/test/unittest/dtrace-util/tst.APIVersion.r.p b/test/unittest/dtrace-util/tst.APIVersion.r.p
> new file mode 100755
> index 000000000..8da4f22c1
> --- /dev/null
> +++ b/test/unittest/dtrace-util/tst.APIVersion.r.p
> @@ -0,0 +1,12 @@
> +#!/usr/bin/gawk -f
> +
> +# We do not care about the actual version number - we just want to ensure that
> +# a version using the correct format is reported.
> +/dtrace:/ {
> +	sub(/[1-9][0-9]*\.[0-9]+\.[0-9]+/, "x.y.z");
> +	sub(/[1-9][0-9]*\.[0-9]+/, "x.y.z");
> +}
> +
> +{
> +	print;
> +}
> diff --git a/test/unittest/options/tst.version.r b/test/unittest/options/tst.version.r
> index 15010b3db..8b1378917 100644
> --- a/test/unittest/options/tst.version.r
> +++ b/test/unittest/options/tst.version.r
> @@ -1,2 +1 @@
> -version is 2.0
>   
> diff --git a/test/unittest/options/tst.version.sh b/test/unittest/options/tst.version.sh
> index ffffcdd8b..37fb6f752 100755
> --- a/test/unittest/options/tst.version.sh
> +++ b/test/unittest/options/tst.version.sh
> @@ -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,6 @@
>   dtrace=$1
>   
>   myversion=`$dtrace $dt_flags -V | gawk '{ print $NF }'`
> -echo version is $myversion
>   
>   $dtrace $dt_flags -xversion=$myversion -qn 'BEGIN { exit(0) }'
>   exit $?



More information about the DTrace-devel mailing list