[DTrace-devel] [PATCH 02/20] Fix alignment of global and local variables

Kris Van Hees kris.van.hees at oracle.com
Tue Jun 1 22:47:39 PDT 2021


Storage for global and local variables was allocated at a 8-byte
boundary regardless of the dattype of the variables.  We now use
the proper alignment for each specific variable based on its
datatype.

This patch also corrects the expected output for the tst.basics.d
arithmetic test.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cg.c                             | 88 +++++++------------
 libdtrace/dt_dis.c                            |  8 +-
 libdtrace/dt_parser.c                         | 57 ++++++++++--
 test/unittest/arithmetic/tst.basics.r         |  4 +-
 .../variables/gvar/tst.alignment-array.r      |  2 +
 .../variables/gvar/tst.alignment-array.sh     | 53 +++++++++++
 .../variables/gvar/tst.alignment-char.r       |  2 +
 .../variables/gvar/tst.alignment-char.sh      | 52 +++++++++++
 .../variables/gvar/tst.alignment-int.r        |  2 +
 .../variables/gvar/tst.alignment-int.sh       | 52 +++++++++++
 .../variables/gvar/tst.alignment-long.r       |  2 +
 .../variables/gvar/tst.alignment-long.sh      | 52 +++++++++++
 .../variables/gvar/tst.alignment-ptr.r        |  2 +
 .../variables/gvar/tst.alignment-ptr.sh       | 52 +++++++++++
 .../variables/gvar/tst.alignment-short.r      |  2 +
 .../variables/gvar/tst.alignment-short.sh     | 52 +++++++++++
 .../variables/gvar/tst.alignment-struct-2.r   |  2 +
 .../variables/gvar/tst.alignment-struct-2.sh  | 53 +++++++++++
 .../variables/gvar/tst.alignment-struct.r     |  2 +
 .../variables/gvar/tst.alignment-struct.sh    | 53 +++++++++++
 test/unittest/variables/gvar/tst.store-char.d | 28 ++++++
 test/unittest/variables/gvar/tst.store-char.r |  1 +
 .../variables/lvar/tst.alignment-array.r      |  2 +
 .../variables/lvar/tst.alignment-array.sh     | 53 +++++++++++
 .../variables/lvar/tst.alignment-char.r       |  2 +
 .../variables/lvar/tst.alignment-char.sh      | 52 +++++++++++
 .../variables/lvar/tst.alignment-int.r        |  2 +
 .../variables/lvar/tst.alignment-int.sh       | 52 +++++++++++
 .../variables/lvar/tst.alignment-long.r       |  2 +
 .../variables/lvar/tst.alignment-long.sh      | 52 +++++++++++
 .../variables/lvar/tst.alignment-ptr.r        |  2 +
 .../variables/lvar/tst.alignment-ptr.sh       | 52 +++++++++++
 .../variables/lvar/tst.alignment-short.r      |  2 +
 .../variables/lvar/tst.alignment-short.sh     | 52 +++++++++++
 .../variables/lvar/tst.alignment-struct-2.r   |  2 +
 .../variables/lvar/tst.alignment-struct-2.sh  | 53 +++++++++++
 .../variables/lvar/tst.alignment-struct.r     |  2 +
 .../variables/lvar/tst.alignment-struct.sh    | 53 +++++++++++
 test/unittest/variables/lvar/tst.store-char.d | 28 ++++++
 test/unittest/variables/lvar/tst.store-char.r |  1 +
 40 files changed, 1019 insertions(+), 66 deletions(-)
 create mode 100644 test/unittest/variables/gvar/tst.alignment-array.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-array.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-char.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-char.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-int.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-int.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-long.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-long.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-ptr.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-ptr.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-short.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-short.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-struct-2.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-struct-2.sh
 create mode 100644 test/unittest/variables/gvar/tst.alignment-struct.r
 create mode 100755 test/unittest/variables/gvar/tst.alignment-struct.sh
 create mode 100644 test/unittest/variables/gvar/tst.store-char.d
 create mode 100644 test/unittest/variables/gvar/tst.store-char.r
 create mode 100644 test/unittest/variables/lvar/tst.alignment-array.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-array.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-char.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-char.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-int.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-int.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-long.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-long.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-ptr.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-ptr.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-short.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-short.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-struct-2.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-struct-2.sh
 create mode 100644 test/unittest/variables/lvar/tst.alignment-struct.r
 create mode 100755 test/unittest/variables/lvar/tst.alignment-struct.sh
 create mode 100644 test/unittest/variables/lvar/tst.store-char.d
 create mode 100644 test/unittest/variables/lvar/tst.store-char.r

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index f111165a..c51e515c 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -691,6 +691,12 @@ dt_cg_spill_load(int reg)
 	emit(dlp, BPF_LOAD(BPF_DW, reg, BPF_REG_FP, DT_STK_SPILL(reg)));
 }
 
+static const uint_t	ldstw[] = {
+					0,
+					BPF_B,	BPF_H,	0, BPF_W,
+					0,	0,	0, BPF_DW,
+				};
+
 static int
 dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		dt_pfargv_t *pfp, int arg)
@@ -699,6 +705,7 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 	dt_irlist_t		*dlp = &pcb->pcb_ir;
 	dt_regset_t		*drp = pcb->pcb_regs;
 	uint_t			off;
+	size_t			size;
 
 	/*
 	 * Special case for aggregations: we store the aggregation id.  We
@@ -708,36 +715,21 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1)
 			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
 		emit(dlp, BPF_MOV_IMM(dnp->dn_reg, dnp->dn_ident->di_id));
-		vtype.dtdt_size = sizeof(dnp->dn_ident->di_id);
+		size = sizeof(dnp->dn_ident->di_id);
 	} else {
 		dt_cg_node(dnp, &pcb->pcb_ir, drp);
 		dt_node_diftype(pcb->pcb_hdl, dnp, &vtype);
+		size = vtype.dtdt_size;
 	}
 
 	if (dt_node_is_scalar(dnp) || dt_node_is_float(dnp) ||
 	    dnp->dn_kind == DT_NODE_AGG) {
-		int	sz = 8;
-
 		off = dt_rec_add(pcb->pcb_hdl, dt_cg_fill_gap, kind,
-				 vtype.dtdt_size, vtype.dtdt_size, pfp,
-				 arg);
+				 size, size, pfp, arg);
 
-		switch (vtype.dtdt_size) {
-		case sizeof(uint64_t):
-			sz = BPF_DW;
-			break;
-		case sizeof(uint32_t):
-			sz = BPF_W;
-			break;
-		case sizeof(uint16_t):
-			sz = BPF_H;
-			break;
-		case sizeof(uint8_t):
-			sz = BPF_B;
-			break;
-		}
+		assert(size > 0 && size <= 8 && (size & (size - 1)) == 0);
 
-		emit(dlp, BPF_STORE(sz, BPF_REG_9, off, dnp->dn_reg));
+		emit(dlp, BPF_STORE(ldstw[size], BPF_REG_9, off, dnp->dn_reg));
 		dt_regset_free(drp, dnp->dn_reg);
 
 		return 0;
@@ -1586,11 +1578,6 @@ static uint_t
 dt_cg_load(dt_node_t *dnp, ctf_file_t *ctfp, ctf_id_t type)
 {
 #if 1
-	static const uint_t ops[] = {
-		BPF_B,	BPF_H,	0,	BPF_W,
-		0,	0,	0,	BPF_DW,
-	};
-
 	ctf_encoding_t e;
 	ssize_t size;
 
@@ -1610,9 +1597,7 @@ dt_cg_load(dt_node_t *dnp, ctf_file_t *ctfp, ctf_id_t type)
 		    "size %ld when passed by value\n", (long)size);
 	}
 
-	size--; /* convert size to 3-bit index */
-
-	return ops[size];
+	return ldstw[size];
 #else
 	static const uint_t ops[] = {
 		DIF_OP_LDUB,	DIF_OP_LDUH,	0,	DIF_OP_LDUW,
@@ -1664,7 +1649,8 @@ dt_cg_load_var(dt_node_t *dst, dt_irlist_t *dlp, dt_regset_t *drp)
 
 	/* global and local variables (not thread-local or built-in) */
 	if ((idp->di_flags & DT_IDFLG_LOCAL) ||
-	    (!(idp->di_flags & DT_IDFLG_TLS) && idp->di_id >= DIF_VAR_OTHER_UBASE)) {
+	    (!(idp->di_flags & DT_IDFLG_TLS) &&
+	     idp->di_id >= DIF_VAR_OTHER_UBASE)) {
 		if ((dst->dn_reg = dt_regset_alloc(drp)) == -1)
 			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
 
@@ -1678,8 +1664,14 @@ dt_cg_load_var(dt_node_t *dst, dt_irlist_t *dlp, dt_regset_t *drp)
 		/* load the variable value or address */
 		if (dst->dn_flags & DT_NF_REF)
 			emit(dlp, BPF_ALU64_IMM(BPF_ADD, dst->dn_reg, idp->di_offset));
-		else
-			emit(dlp, BPF_LOAD(BPF_DW, dst->dn_reg, dst->dn_reg, idp->di_offset));
+		else {
+			size_t	size = dt_node_type_size(dst);
+
+			assert(size > 0 && size <= 8 &&
+			       (size & (size - 1)) == 0);
+
+			emit(dlp, BPF_LOAD(ldstw[size], dst->dn_reg, dst->dn_reg, idp->di_offset));
+		}
 
 		return;
 	}
@@ -1900,37 +1892,19 @@ dt_cg_store(dt_node_t *src, dt_irlist_t *dlp, dt_regset_t *drp, dt_node_t *dst)
 	    ctf_type_encoding(dst->dn_ctfp, dst->dn_type, &e) != CTF_ERR)
 		size = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY);
 	else
-		size = dt_node_type_size(src);
+		size = dt_node_type_size(dst);
 
 	if (src->dn_flags & DT_NF_REF)
 		dt_cg_memcpy(dlp, drp, dst->dn_reg, src->dn_reg, size);
 	else {
-		uint8_t	sz;
-
 		if (dst->dn_flags & DT_NF_BITFIELD)
 			reg = dt_cg_field_set(src, dlp, drp, dst);
 		else
 			reg = src->dn_reg;
 
-		switch (size) {
-		case 1:
-			sz = BPF_B;
-			break;
-		case 2:
-			sz = BPF_H;
-			break;
-		case 4:
-			sz = BPF_W;
-			break;
-		case 8:
-			sz = BPF_DW;
-			break;
-		default:
-			xyerror(D_UNKNOWN, "internal error -- cg cannot store "
-			    "size %lu when passed by value\n", (ulong_t)size);
-		}
+		assert(size > 0 && size <= 8 && (size & (size - 1)) == 0);
 
-		emit(dlp, BPF_STORE(sz, dst->dn_reg, 0, reg));
+		emit(dlp, BPF_STORE(ldstw[size], dst->dn_reg, 0, reg));
 
 		if (dst->dn_flags & DT_NF_BITFIELD)
 			dt_regset_free(drp, reg);
@@ -1963,8 +1937,14 @@ dt_cg_store_var(dt_node_t *src, dt_irlist_t *dlp, dt_regset_t *drp,
 		if (src->dn_flags & DT_NF_REF) {
 			emit(dlp, BPF_ALU64_IMM(BPF_ADD, reg, idp->di_offset));
 			dt_cg_memcpy(dlp, drp, reg, src->dn_reg, idp->di_size);
-		} else
-			emit(dlp, BPF_STORE(BPF_DW, reg, idp->di_offset, src->dn_reg));
+		} else {
+			size_t	size = idp->di_size;
+
+			assert(size > 0 && size <= 8 &&
+			       (size & (size - 1)) == 0);
+
+			emit(dlp, BPF_STORE(ldstw[size], reg, idp->di_offset, src->dn_reg));
+		}
 
 		dt_regset_free(drp, reg);
 		return;
diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
index 7b7c39f9..a8c4e1ca 100644
--- a/libdtrace/dt_dis.c
+++ b/libdtrace/dt_dis.c
@@ -102,7 +102,6 @@ dt_dis_varname(const dtrace_difo_t *dp, const struct bpf_insn *in, uint_t addr,
 	       int n, FILE *fp)
 {
 	__u8		ldcode = BPF_LDX | BPF_MEM | BPF_DW;
-	__u8		stcode = BPF_STX | BPF_MEM | BPF_DW;
 	__u8		addcode = BPF_ALU64 | BPF_ADD | BPF_K;
 	int		dst, scope, var_offset = -1;
 	const char	*vname;
@@ -135,9 +134,12 @@ dt_dis_varname(const dtrace_difo_t *dp, const struct bpf_insn *in, uint_t addr,
 	/* check the current instruction and read var_offset */
 	if (in->dst_reg != dst)
 		goto out;
-	if (in->code == ldcode && in->src_reg == dst && in->imm == 0)
+	if (BPF_CLASS(in->code) == BPF_LDX && BPF_MODE(in->code) == BPF_MEM &&
+	    in->src_reg == dst && in->imm == 0)
 		var_offset = in->off;
-	else if (in->code == stcode && in->src_reg != dst && in->imm == 0)
+	else if (BPF_CLASS(in->code) == BPF_STX &&
+		 BPF_MODE(in->code) == BPF_MEM &&
+		 in->src_reg != dst && in->imm == 0)
 		var_offset = in->off;
 	else if (in->code == addcode && in->src_reg == 0 && in->off == 0)
 		var_offset = in->imm;
diff --git a/libdtrace/dt_parser.c b/libdtrace/dt_parser.c
index 9d71cd43..e65dd9a0 100644
--- a/libdtrace/dt_parser.c
+++ b/libdtrace/dt_parser.c
@@ -1484,12 +1484,11 @@ dt_node_decl(void)
 		break;
 
 	default: {
-		ctf_encoding_t cte;
 		dt_idhash_t *dhp;
 		dt_ident_t *idp;
 		dt_node_t idn;
 		int assc, idkind;
-		uint_t id, kind;
+		uint_t id;
 		ushort_t idflags;
 
 		switch (class) {
@@ -1619,19 +1618,53 @@ dt_node_decl(void)
 			}
 
 		} else if (idp == NULL) {
+			ctf_encoding_t cte;
+			ctf_arinfo_t r;
+			ctf_id_t etype;
+			uint_t kind;
+			uint_t alignment = 8;
+
 			type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
 			kind = ctf_type_kind(dtt.dtt_ctfp, type);
 
 			switch (kind) {
+			case CTF_K_ENUM:
 			case CTF_K_INTEGER:
 				if (ctf_type_encoding(dtt.dtt_ctfp, type,
-				    &cte) == 0 && IS_VOID(cte)) {
-					xyerror(D_DECL_VOIDOBJ, "cannot have "
-					    "void object: %s\n", dsp->ds_ident);
+						      &cte) == 0 &&
+				    IS_VOID(cte))
+					xyerror(D_DECL_VOIDOBJ,
+						"cannot have void object: %s\n",
+						dsp->ds_ident);
+				/*FALLTHRU*/
+			case CTF_K_POINTER:
+				alignment = ctf_type_size(dtt.dtt_ctfp,
+							  dtt.dtt_type);
+				break;
+			case CTF_K_ARRAY:
+				/* Special case: D type 'string' */
+				if (dtt.dtt_ctfp ==
+						DT_STR_CTFP(yypcb->pcb_hdl) &&
+				    dtt.dtt_type ==
+						DT_STR_TYPE(yypcb->pcb_hdl)) {
+					alignment = 1;
+					break;
 				}
+
+				alignment = 8;
+				if (ctf_array_info(dtt.dtt_ctfp, dtt.dtt_type,
+						   &r) != 0)
+					break;
+				etype = ctf_type_resolve(dtt.dtt_ctfp,
+							 r.ctr_contents);
+				if (etype == CTF_ERR)
+					break;
+
+				alignment = ctf_type_size(dtt.dtt_ctfp, etype);
 				break;
 			case CTF_K_STRUCT:
 			case CTF_K_UNION:
+				alignment = sizeof(uint64_t);
 				if (ctf_type_size(dtt.dtt_ctfp, type) != 0)
 					break; /* proceed to declaring */
 				/*FALLTHRU*/
@@ -1662,7 +1695,7 @@ dt_node_decl(void)
 				longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
 
 			dt_ident_type_assign(idp, dtt.dtt_ctfp, dtt.dtt_type);
-			dt_ident_set_storage(idp, 8,
+			dt_ident_set_storage(idp, alignment,
 					     ctf_type_size(dtt.dtt_ctfp,
 							   dtt.dtt_type));
 
@@ -3481,9 +3514,19 @@ dt_cook_op2(dt_node_t *dnp, uint_t idflags)
 		 */
 		if (lp->dn_kind == DT_NODE_VAR &&
 		    dt_ident_unref(lp->dn_ident)) {
+			uint_t alignment;
+
 			dt_node_type_assign(lp, ctfp, type);
+
+			if (dt_node_is_scalar(lp))
+				alignment = ctf_type_size(ctfp, type);
+			else if (dt_node_is_string(lp))
+				alignment = 1;
+			else
+				alignment = 9;
+
 			dt_ident_type_assign(lp->dn_ident, ctfp, type);
-			dt_ident_set_storage(lp->dn_ident, 8,
+			dt_ident_set_storage(lp->dn_ident, alignment,
 					     ctf_type_size(ctfp, type));
 
 			if (uref) {
diff --git a/test/unittest/arithmetic/tst.basics.r b/test/unittest/arithmetic/tst.basics.r
index bd7690b5..603591e6 100644
--- a/test/unittest/arithmetic/tst.basics.r
+++ b/test/unittest/arithmetic/tst.basics.r
@@ -3,8 +3,8 @@ The value of i is 18
 The value of i is 72
 The value of i is 25920
 The value of i is 935761216
-The value of i is -91738734
-The value of i is -91738729
+The value of i is 1319599982
+The value of i is 1319599979
 ~ deadbeef is 21524110
 ~ beef is ffff4110
 ~ deadbeefdeadbeef is 2152411021524110
diff --git a/test/unittest/variables/gvar/tst.alignment-array.r b/test/unittest/variables/gvar/tst.alignment-array.r
new file mode 100644
index 00000000..72aab868
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-array.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              2      scl glb r    D type (array) by ref (size 10)
diff --git a/test/unittest/variables/gvar/tst.alignment-array.sh b/test/unittest/variables/gvar/tst.alignment-array.sh
new file mode 100755
index 00000000..9422af15
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-array.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+short var[5];
+
+BEGIN
+{
+	var[3] = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-char.r b/test/unittest/variables/gvar/tst.alignment-char.r
new file mode 100644
index 00000000..d9ad9456
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-char.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              1      scl glb w    D type (integer) (size 1)
diff --git a/test/unittest/variables/gvar/tst.alignment-char.sh b/test/unittest/variables/gvar/tst.alignment-char.sh
new file mode 100755
index 00000000..ea4b5932
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-char.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype char should be aligned on a byte boundary
+#
+# SECTION: Variables/Scalar Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+char var;
+
+BEGIN
+{
+	var = 0x12;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-int.r b/test/unittest/variables/gvar/tst.alignment-int.r
new file mode 100644
index 00000000..ad5cc526
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-int.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              4      scl glb w    D type (integer) (size 4)
diff --git a/test/unittest/variables/gvar/tst.alignment-int.sh b/test/unittest/variables/gvar/tst.alignment-int.sh
new file mode 100755
index 00000000..2c948b71
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-int.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype int should be aligned on a 4-byte boundary
+#
+# SECTION: Variables/Scalar Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+int var;
+
+BEGIN
+{
+	var = 0x12345678;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-long.r b/test/unittest/variables/gvar/tst.alignment-long.r
new file mode 100644
index 00000000..c0ef576a
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-long.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl glb w    D type (integer) (size 8)
diff --git a/test/unittest/variables/gvar/tst.alignment-long.sh b/test/unittest/variables/gvar/tst.alignment-long.sh
new file mode 100755
index 00000000..c7dde5f5
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-long.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype long should be aligned on a 8-byte boundary
+#
+# SECTION: Variables/Scalar Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+long var;
+
+BEGIN
+{
+	var = 0x1234567887654321ull;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-ptr.r b/test/unittest/variables/gvar/tst.alignment-ptr.r
new file mode 100644
index 00000000..9dc6a3cc
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-ptr.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl glb w    D type (pointer) (size 8)
diff --git a/test/unittest/variables/gvar/tst.alignment-ptr.sh b/test/unittest/variables/gvar/tst.alignment-ptr.sh
new file mode 100755
index 00000000..7c82b5ed
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-ptr.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of pointer type should be aligned on a 8-byte boundary
+#
+# SECTION: Variables/Scalar Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+char *var;
+
+BEGIN
+{
+	var = 0;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-short.r b/test/unittest/variables/gvar/tst.alignment-short.r
new file mode 100644
index 00000000..1f2c2f92
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-short.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              2      scl glb w    D type (integer) (size 2)
diff --git a/test/unittest/variables/gvar/tst.alignment-short.sh b/test/unittest/variables/gvar/tst.alignment-short.sh
new file mode 100755
index 00000000..41f97371
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-short.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype short should be aligned on a 2-byte boundary
+#
+# SECTION: Variables/Scalar Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+short var;
+
+BEGIN
+{
+	var = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-struct-2.r b/test/unittest/variables/gvar/tst.alignment-struct-2.r
new file mode 100644
index 00000000..8e3f9a8f
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-struct-2.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl glb r    D type (struct) by ref (size 18)
diff --git a/test/unittest/variables/gvar/tst.alignment-struct-2.sh b/test/unittest/variables/gvar/tst.alignment-struct-2.sh
new file mode 100755
index 00000000..80c17436
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-struct-2.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+struct { int u; long v; short w; } var;
+
+BEGIN
+{
+	var.w = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.alignment-struct.r b/test/unittest/variables/gvar/tst.alignment-struct.r
new file mode 100644
index 00000000..2a2e531c
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-struct.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl glb r    D type (struct) by ref (size 4)
diff --git a/test/unittest/variables/gvar/tst.alignment-struct.sh b/test/unittest/variables/gvar/tst.alignment-struct.sh
new file mode 100755
index 00000000..dbc3ef6d
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.alignment-struct.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+char dummy;
+struct { short u, v; } var;
+
+BEGIN
+{
+	var.u = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/gvar/tst.store-char.d b/test/unittest/variables/gvar/tst.store-char.d
new file mode 100644
index 00000000..0349e8a5
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.store-char.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2021, 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: Storing an integer to a 'char' global variable does not store
+ *	      more than a single byte.
+ *
+ * SECTION: Variables/Scalar Variables
+ */
+
+#pragma D option quiet
+
+char a, b;
+
+BEGIN
+{
+	b = 4;
+	a = 5;
+
+	trace(a);
+	trace(b);
+
+	exit(0);
+}
diff --git a/test/unittest/variables/gvar/tst.store-char.r b/test/unittest/variables/gvar/tst.store-char.r
new file mode 100644
index 00000000..fb1e7bc8
--- /dev/null
+++ b/test/unittest/variables/gvar/tst.store-char.r
@@ -0,0 +1 @@
+54
diff --git a/test/unittest/variables/lvar/tst.alignment-array.r b/test/unittest/variables/lvar/tst.alignment-array.r
new file mode 100644
index 00000000..9ef126f4
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-array.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              2      scl loc r    D type (array) by ref (size 10)
diff --git a/test/unittest/variables/lvar/tst.alignment-array.sh b/test/unittest/variables/lvar/tst.alignment-array.sh
new file mode 100755
index 00000000..2b6d115e
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-array.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this short var[5];
+
+BEGIN
+{
+	this->var[3] = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-char.r b/test/unittest/variables/lvar/tst.alignment-char.r
new file mode 100644
index 00000000..099a67cb
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-char.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              1      scl loc w    D type (integer) (size 1)
diff --git a/test/unittest/variables/lvar/tst.alignment-char.sh b/test/unittest/variables/lvar/tst.alignment-char.sh
new file mode 100755
index 00000000..320c71d9
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-char.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype char should be aligned on a byte boundary
+#
+# SECTION: Variables/Clause-Local Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this char var;
+
+BEGIN
+{
+	this->var = 0x12;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-int.r b/test/unittest/variables/lvar/tst.alignment-int.r
new file mode 100644
index 00000000..e822a836
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-int.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              4      scl loc w    D type (integer) (size 4)
diff --git a/test/unittest/variables/lvar/tst.alignment-int.sh b/test/unittest/variables/lvar/tst.alignment-int.sh
new file mode 100755
index 00000000..f819ab1b
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-int.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype int should be aligned on a 4-byte boundary
+#
+# SECTION: Variables/Clause-Local Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this int var;
+
+BEGIN
+{
+	this->var = 0x12345678;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-long.r b/test/unittest/variables/lvar/tst.alignment-long.r
new file mode 100644
index 00000000..172b6ba4
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-long.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl loc w    D type (integer) (size 8)
diff --git a/test/unittest/variables/lvar/tst.alignment-long.sh b/test/unittest/variables/lvar/tst.alignment-long.sh
new file mode 100755
index 00000000..cf465ae6
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-long.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype long should be aligned on a 8-byte boundary
+#
+# SECTION: Variables/Clause-Local Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this long var;
+
+BEGIN
+{
+	this->var = 0x1234567887654321ull;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-ptr.r b/test/unittest/variables/lvar/tst.alignment-ptr.r
new file mode 100644
index 00000000..31463ee9
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-ptr.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl loc w    D type (pointer) (size 8)
diff --git a/test/unittest/variables/lvar/tst.alignment-ptr.sh b/test/unittest/variables/lvar/tst.alignment-ptr.sh
new file mode 100755
index 00000000..5a9ccbd2
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-ptr.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of pointer type should be aligned on a 8-byte boundary
+#
+# SECTION: Variables/Clause-Local Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this char *var;
+
+BEGIN
+{
+	this->var = 0;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-short.r b/test/unittest/variables/lvar/tst.alignment-short.r
new file mode 100644
index 00000000..67094c27
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-short.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              2      scl loc w    D type (integer) (size 2)
diff --git a/test/unittest/variables/lvar/tst.alignment-short.sh b/test/unittest/variables/lvar/tst.alignment-short.sh
new file mode 100755
index 00000000..54b64b8e
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-short.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of datatype short should be aligned on a 2-byte boundary
+#
+# SECTION: Variables/Clause-Local Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this short var;
+
+BEGIN
+{
+	this->var = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-struct-2.r b/test/unittest/variables/lvar/tst.alignment-struct-2.r
new file mode 100644
index 00000000..8273dc01
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-struct-2.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl loc r    D type (struct) by ref (size 18)
diff --git a/test/unittest/variables/lvar/tst.alignment-struct-2.sh b/test/unittest/variables/lvar/tst.alignment-struct-2.sh
new file mode 100755
index 00000000..9acb564f
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-struct-2.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this struct { int u; long v; short w; } var;
+
+BEGIN
+{
+	this->var.w = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.alignment-struct.r b/test/unittest/variables/lvar/tst.alignment-struct.r
new file mode 100644
index 00000000..3954df51
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-struct.r
@@ -0,0 +1,2 @@
+NAME             OFFSET KND SCP FLAG TYPE
+var              8      scl loc r    D type (struct) by ref (size 4)
diff --git a/test/unittest/variables/lvar/tst.alignment-struct.sh b/test/unittest/variables/lvar/tst.alignment-struct.sh
new file mode 100755
index 00000000..b5523e65
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.alignment-struct.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: Variables of array type should be aligned based on their element
+#            datatype
+#
+# SECTION: Variables
+#
+##
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+this char dummy;
+this struct { short u, v; } var;
+
+BEGIN
+{
+	this->var.u = 0x1234;
+	exit(0);
+}
+' 2>&1 | awk '
+BEGIN {
+	rc = 1;
+}
+
+/^NAME/ && /KND SCP/ {
+	printf "%-16s %-6s %-3s %-3s %-4s %s\n",
+	       "NAME", "OFFSET", "KND", "SCP","FLAG", "TYPE";
+	while (getline == 1 && NF > 0) {
+		$2 = $6 = "";
+		gsub(/ +/, " ");
+		printf "%-16s %-6s %-3s %-3s %-4s", $1, $2, $3, $4, $5;
+		$1 = $2 = $3 = $4 = $5 = "";
+		gsub(/ +/, " ");
+		print $0;
+		rc = 0;
+	}
+}
+
+END {
+	exit(rc);
+}
+'
+
+exit $?
diff --git a/test/unittest/variables/lvar/tst.store-char.d b/test/unittest/variables/lvar/tst.store-char.d
new file mode 100644
index 00000000..741b93cb
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.store-char.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2021, 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: Storing an integer to a 'char' local variable does not store
+ *	      more than a single byte.
+ *
+ * SECTION: Variables/Scalar Variables
+ */
+
+#pragma D option quiet
+
+this char a, b;
+
+BEGIN
+{
+	this->b = 4;
+	this->a = 5;
+
+	trace(this->a);
+	trace(this->b);
+
+	exit(0);
+}
diff --git a/test/unittest/variables/lvar/tst.store-char.r b/test/unittest/variables/lvar/tst.store-char.r
new file mode 100644
index 00000000..fb1e7bc8
--- /dev/null
+++ b/test/unittest/variables/lvar/tst.store-char.r
@@ -0,0 +1 @@
+54
-- 
2.31.1




More information about the DTrace-devel mailing list