[DTrace-devel] [PATCH 16/47] Introduce -xdisasm=n option
Kris Van Hees
kris.van.hees at oracle.com
Sun May 3 20:17:15 PDT 2020
In order to prepare for more functionality for the disassembler in
DTrace an option is being added for specifying which disassembly
listings should be printed if the '-S' option is supplied.
The following listings can be selected:
No. | Value | Description
----+-------+------------
1 | 1 | After compilation and assembly of a program
2 | 2 | After linking in precompiled BPF functions
3 | 4 | After final relocation processing (final program)
The new option is specified as "-xdisasm=n" where n is the bitwise OR of
the values listed in the table above. The default is 1.
Orabug: 31220524
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_cc.c | 30 ++++++++++++++++++------------
libdtrace/dt_impl.h | 14 ++++++++++++++
libdtrace/dt_open.c | 3 ++-
libdtrace/dt_options.c | 18 ++++++++++++++++--
4 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index e0dbe465..625bf4c9 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -2186,12 +2186,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 *
@@ -2200,12 +2203,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..69e76903 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 listings are:
+ * 1 After compilation and assembly of a program.
+ * 2 After linking in precompiled BPF functions (dependencies).
+ * 3 After final relocation processing (final program).
+ */
+#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..42e15bac 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, 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.
*/
@@ -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..74a1e8fc 100644
--- a/libdtrace/dt_options.c
+++ b/libdtrace/dt_options.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2020, 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.
*/
@@ -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