[DTrace-devel] [PATCH] Introduce -xdisasm=n option

Kris Van Hees kris.van.hees at oracle.com
Wed Apr 8 08:00:23 PDT 2020


In order to prepare for more functionality for the disassembler in
DTrace, an option is being added to be able to specify a bitmap that
indicates which disassembly listings the user wishes to have printed
if '-S' is supplied as command line option.

The default is 1 which indicates that the disassembler listing should
be printed after program compilation.

The comment describing -xdisasm=n documents two additional bits that
are not yet implemented:

	2 = disassembler listing after the program is linked
	3 = disassembler listing right before loading the program

Since the vlaue supplied to -xdisasm is a bitmap, any combination of
disassembler listings can be requested.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cc.c      | 30 ++++++++++++++++++------------
 libdtrace/dt_impl.h    | 14 ++++++++++++++
 libdtrace/dt_open.c    |  1 +
 libdtrace/dt_options.c | 16 +++++++++++++++-
 4 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index ab987fc7..c8c6dd0c 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -2184,12 +2184,15 @@ dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
 {
 	dtrace_prog_t *rv;
 
-	if ((rv = dt_compile(dtp, DT_CTX_DPROG,
-		    spec, NULL, cflags, argc, argv, NULL, s)) != NULL) {
-		if (cflags & DTRACE_C_DIFV)
-			dt_dis_program(dtp, rv, stderr);
-	}
-	return (rv);
+	rv = dt_compile(dtp, DT_CTX_DPROG, spec, NULL, cflags,
+			argc, argv, NULL, s);
+	if (rv == NULL)
+		return NULL;
+
+	if (cflags & DTRACE_C_DIFV && DT_DISASM(dtp, 1))
+		dt_dis_program(dtp, rv, stderr);
+
+	return rv;
 }
 
 dtrace_prog_t *
@@ -2198,12 +2201,15 @@ dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp,
 {
 	dtrace_prog_t *rv;
 
-	if ((rv = dt_compile(dtp, DT_CTX_DPROG,
-		    DTRACE_PROBESPEC_NAME, NULL, cflags, argc, argv, fp, NULL)) != NULL) {
-		if (cflags & DTRACE_C_DIFV)
-			dt_dis_program(dtp, rv, stderr);
-	}
-	return (rv);
+	rv = dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL, cflags,
+			argc, argv, fp, NULL);
+	if (rv == NULL)
+		return NULL;
+
+	if (cflags & DTRACE_C_DIFV && DT_DISASM(dtp, 1))
+		dt_dis_program(dtp, rv, stderr);
+
+	return rv;
 }
 
 int
diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
index 536b1745..ca8b7851 100644
--- a/libdtrace/dt_impl.h
+++ b/libdtrace/dt_impl.h
@@ -326,6 +326,7 @@ struct dtrace_hdl {
 	uint_t dt_xlatemode;	/* dtrace translator linking mode (see below) */
 	uint_t dt_stdcmode;	/* dtrace stdc compatibility mode (see below) */
 	uint_t dt_treedump;	/* dtrace tree debug bitmap (see below) */
+	uint_t dt_disasm;	/* dtrace disassembler bitmap (see below) */
 	uint64_t dt_options[DTRACEOPT_MAX]; /* dtrace run-time options */
 	int dt_version;		/* library version requested by client */
 	int dt_ctferr;		/* error resulting from last CTF failure */
@@ -413,6 +414,19 @@ struct dtrace_hdl {
  */
 #define	DT_TREEDUMP_PASS(dtp, p)	((dtp)->dt_treedump & (1 << ((p) - 1)))
 
+/*
+ * Macro to test whether a given disassembler bit is set in the dt_disasm
+ * bit-vector.  If the bit for mode 'm' is set, the D disassembler will be
+ * invoked for that specific mode.  The '-S' option must also be supplied in
+ * order for disassembler output to be generated.
+ *
+ * Supported modes are:
+ *	0	Print disassembler listing for each compiled clause.
+ *	1	Print disassembler listing for the final linked program.
+ *	2	Print disassembler listing for the program right before loading.
+ */
+#define	DT_DISASM(dtp, m)		((dtp)->dt_disasm & (1 << ((m) - 1)))
+
 /*
  * Macros for accessing the cached CTF container and type ID for the common
  * types "int", "string", and <DYN>, which we need to use frequently in the D
diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 6b0ba71d..ab60a803 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -709,6 +709,7 @@ dt_vopen(int version, int flags, int *errp,
 	dtp->dt_linktype = DT_LTYP_ELF;
 	dtp->dt_xlatemode = DT_XL_STATIC;
 	dtp->dt_stdcmode = DT_STDC_XA;
+	dtp->dt_disasm = 1;
 	dtp->dt_version = version;
 	dtp->dt_cdefs_fd = -1;
 	dtp->dt_ddefs_fd = -1;
diff --git a/libdtrace/dt_options.c b/libdtrace/dt_options.c
index a199cfdb..8c6e0e42 100644
--- a/libdtrace/dt_options.c
+++ b/libdtrace/dt_options.c
@@ -397,6 +397,19 @@ dt_opt_module_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 	return (0);
 }
 
+/*ARGSUSED*/
+static int
+dt_opt_disasm(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
+{
+	int m;
+
+	if (arg == NULL || (m = atoi(arg)) <= 0)
+		return (dt_set_errno(dtp, EDT_BADOPTVAL));
+
+	dtp->dt_disasm = m;
+	return (0);
+}
+
 /*ARGSUSED*/
 static int
 dt_opt_evaltime(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
@@ -1032,11 +1045,12 @@ static const dt_option_t _dtrace_ctoptions[] = {
 	{ "ctypes", dt_opt_ctypes },
 	{ "ctfpath", dt_opt_ctfa_path },
 	{ "defaultargs", dt_opt_cflags, DTRACE_C_DEFARG },
-	{ "dtypes", dt_opt_dtypes },
 	{ "debug", dt_opt_debug },
 	{ "debugassert", dt_opt_debug_assert },
 	{ "define", dt_opt_cpp_opts, (uintptr_t)"-D" },
+	{ "disasm", dt_opt_disasm },
 	{ "droptags", dt_opt_droptags },
+	{ "dtypes", dt_opt_dtypes },
 	{ "empty", dt_opt_cflags, DTRACE_C_EMPTY },
 	{ "errtags", dt_opt_cflags, DTRACE_C_ETAGS },
 	{ "evaltime", dt_opt_evaltime },
-- 
2.26.0




More information about the DTrace-devel mailing list