[DTrace-devel] [PATCH] Remove old printf formats handling code

Kris Van Hees kris.van.hees at oracle.com
Fri Jun 19 00:49:00 PDT 2020


Now that the printff format descriptor data is integrated into the
record descriptor, there is no need to retain the old formats
handling code.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_impl.h |   4 -
 libdtrace/dt_map.c  | 201 --------------------------------------------
 libdtrace/dt_open.c |   1 -
 3 files changed, 206 deletions(-)

diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
index 40603ea8..e769dbbc 100644
--- a/libdtrace/dt_impl.h
+++ b/libdtrace/dt_impl.h
@@ -297,7 +297,6 @@ struct dtrace_hdl {
 	size_t dt_maxagg;	/* max aggregation ID */
 	dtrace_aggdesc_t **dt_aggdesc; /* aggregation descriptions */
 	int dt_maxformat;	/* max format ID */
-	void **dt_formats;	/* pointer to format array */
 	dt_aggregate_t dt_aggregate; /* aggregate */
 	struct dt_pebset *dt_pebset; /* perf event buffers set */
 	struct dt_pfdict *dt_pfdict; /* dictionary of printf conversions */
@@ -794,9 +793,6 @@ extern uint32_t dt_rec_add(dtrace_hdl_t *, dt_cg_gap_f, dtrace_actkind_t,
 extern int dt_aggid_lookup(dtrace_hdl_t *, dtrace_aggid_t, dtrace_aggdesc_t **);
 extern void dt_aggid_destroy(dtrace_hdl_t *);
 
-extern void *dt_format_lookup(dtrace_hdl_t *, int);
-extern void dt_format_destroy(dtrace_hdl_t *);
-
 extern int dt_print_quantize(dtrace_hdl_t *, FILE *,
     const void *, size_t, uint64_t);
 extern int dt_print_lquantize(dtrace_hdl_t *, FILE *,
diff --git a/libdtrace/dt_map.c b/libdtrace/dt_map.c
index f87b4d38..3994ec3a 100644
--- a/libdtrace/dt_map.c
+++ b/libdtrace/dt_map.c
@@ -84,180 +84,6 @@ dt_datadesc_finalize(dtrace_hdl_t *dtp, dtrace_datadesc_t *ddp)
 	return 0;
 }
 
-#if 0
-static int
-dt_epid_add(dtrace_hdl_t *dtp, dtrace_epid_t id)
-{
-	dtrace_id_t max;
-	int rval, i, maxformat;
-	dtrace_datadesc_t *dd, *ndd;
-	dtrace_probedesc_t *probe;
-
-	while (id >= (max = dtp->dt_maxprobe) || dtp->dt_pdesc == NULL) {
-		dtrace_id_t new_max = max ? (max << 1) : 1;
-		size_t nsize = new_max * sizeof (void *);
-		dtrace_probedesc_t **new_pdesc;
-		dtrace_datadesc_t **new_ddesc;
-
-		if ((new_pdesc = malloc(nsize)) == NULL ||
-		    (new_ddesc = malloc(nsize)) == NULL) {
-			free(new_pdesc);
-			return (dt_set_errno(dtp, EDT_NOMEM));
-		}
-
-		memset(new_pdesc, 0, nsize);
-		memset(new_ddesc, 0, nsize);
-
-		if (dtp->dt_pdesc != NULL) {
-			size_t osize = max * sizeof (void *);
-
-			memcpy(new_pdesc, dtp->dt_pdesc, osize);
-			free(dtp->dt_pdesc);
-
-			memcpy(new_ddesc, dtp->dt_ddesc, osize);
-			free(dtp->dt_ddesc);
-		}
-
-		dtp->dt_pdesc = new_pdesc;
-		dtp->dt_ddesc = new_ddesc;
-		dtp->dt_maxprobe = new_max;
-	}
-
-	if (dtp->dt_pdesc[id] != NULL)
-		return (0);
-
-	if ((dd = malloc(sizeof (dtrace_datadesc_t))) == NULL)
-		return (dt_set_errno(dtp, EDT_NOMEM));
-
-	memset(dd, 0, sizeof (dtrace_datadesc_t));
-	dd->dtdd_epid = id;
-	dd->dtdd_nrecs = 1;
-
-	if (dt_ioctl(dtp, DTRACEIOC_EPROBE, dd) == -1) {
-		rval = dt_set_errno(dtp, errno);
-		free(dd);
-		return (rval);
-	}
-
-	if (DTRACE_SIZEOF_EPROBEDESC(dd) != sizeof (*dd)) {
-		/*
-		 * There must be more than one action.  Allocate the
-		 * appropriate amount of space and try again.
-		 */
-		if ((ndd = malloc(DTRACE_SIZEOF_EPROBEDESC(dd))) != NULL)
-			memcpy(ndd, dd, sizeof (*dd));
-
-		free(dd);
-
-		if ((dd = ndd) == NULL)
-			return (dt_set_errno(dtp, EDT_NOMEM));
-
-		rval = dt_ioctl(dtp, DTRACEIOC_EPROBE, dd);
-
-		if (rval == -1) {
-			rval = dt_set_errno(dtp, errno);
-			free(dd);
-			return (rval);
-		}
-	}
-
-	if ((probe = malloc(sizeof (dtrace_probedesc_t))) == NULL) {
-		free(dd);
-		return (dt_set_errno(dtp, EDT_NOMEM));
-	}
-
-	probe->id = dd->dtdd_probeid;
-
-	if (dt_ioctl(dtp, DTRACEIOC_PROBES, probe) == -1) {
-		rval = dt_set_errno(dtp, errno);
-		goto err;
-	}
-
-	for (i = 0; i < dd->dtdd_nrecs; i++) {
-		dtrace_fmtdesc_t fmt;
-		dtrace_recdesc_t *rec = &dd->dtdd_rec[i];
-
-		if (!DTRACEACT_ISPRINTFLIKE(rec->dtrd_action))
-			continue;
-
-		if (rec->dtrd_format == 0)
-			continue;
-
-		if (rec->dtrd_format <= dtp->dt_maxformat &&
-		    dtp->dt_formats[rec->dtrd_format - 1] != NULL)
-			continue;
-
-		memset(&fmt, 0, sizeof (fmt));
-		fmt.dtfd_format = rec->dtrd_format;
-		fmt.dtfd_string = NULL;
-		fmt.dtfd_length = 0;
-
-		if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
-			rval = dt_set_errno(dtp, errno);
-			goto err;
-		}
-
-		if ((fmt.dtfd_string = malloc(fmt.dtfd_length)) == NULL) {
-			rval = dt_set_errno(dtp, EDT_NOMEM);
-			goto err;
-		}
-
-		if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
-			rval = dt_set_errno(dtp, errno);
-			free(fmt.dtfd_string);
-			goto err;
-		}
-
-		while (rec->dtrd_format > (maxformat = dtp->dt_maxformat)) {
-			int new_max = maxformat ? (maxformat << 1) : 1;
-			size_t nsize = new_max * sizeof (void *);
-			size_t osize = maxformat * sizeof (void *);
-			void **new_formats = malloc(nsize);
-
-			if (new_formats == NULL) {
-				rval = dt_set_errno(dtp, EDT_NOMEM);
-				free(fmt.dtfd_string);
-				goto err;
-			}
-
-			memset(new_formats, 0, nsize);
-			memcpy(new_formats, dtp->dt_formats, osize);
-			free(dtp->dt_formats);
-
-			dtp->dt_formats = new_formats;
-			dtp->dt_maxformat = new_max;
-		}
-
-		dtp->dt_formats[rec->dtrd_format - 1] =
-		    rec->dtrd_action == DTRACEACT_PRINTA ?
-		    dtrace_printa_create(dtp, fmt.dtfd_string) :
-		    dtrace_printf_create(dtp, fmt.dtfd_string);
-
-		free(fmt.dtfd_string);
-
-		if (dtp->dt_formats[rec->dtrd_format - 1] == NULL) {
-			rval = -1; /* dt_errno is set for us */
-			goto err;
-		}
-	}
-
-	dtp->dt_pdesc[id] = probe;
-	dtp->dt_ddesc[id] = dd;
-
-	return (0);
-
-err:
-	/*
-	 * If we failed, free our allocated probes.  Note that if we failed
-	 * while allocating formats, we aren't going to free formats that
-	 * we have already allocated.  This is okay; these formats are
-	 * hanging off of dt_formats and will therefore not be leaked.
-	 */
-	free(dd);
-	free(probe);
-	return (rval);
-}
-#else
 /*
  * Associate a probe data description and probe description with an enabled
  * probe ID.  This means that the given ID refers to the program matching the
@@ -307,7 +133,6 @@ dt_epid_add(dtrace_hdl_t *dtp, dtrace_datadesc_t *ddp, dtrace_id_t prid)
 
 	return epid;
 }
-#endif
 
 int
 dt_epid_lookup(dtrace_hdl_t *dtp, dtrace_epid_t epid, dtrace_datadesc_t **ddp,
@@ -406,32 +231,6 @@ dt_rec_add(dtrace_hdl_t *dtp, dt_cg_gap_f gapf, dtrace_actkind_t kind,
 	return off;
 }
 
-void *
-dt_format_lookup(dtrace_hdl_t *dtp, int format)
-{
-	if (format == 0 || format > dtp->dt_maxformat)
-		return (NULL);
-
-	if (dtp->dt_formats == NULL)
-		return (NULL);
-
-	return (dtp->dt_formats[format - 1]);
-}
-
-void
-dt_format_destroy(dtrace_hdl_t *dtp)
-{
-	int i;
-
-	for (i = 0; i < dtp->dt_maxformat; i++) {
-		if (dtp->dt_formats[i] != NULL)
-			dt_printf_destroy(dtp->dt_formats[i]);
-	}
-
-	free(dtp->dt_formats);
-	dtp->dt_formats = NULL;
-}
-
 static int
 dt_aggid_add(dtrace_hdl_t *dtp, dtrace_aggid_t id)
 {
diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 6a1efbfb..5db72e45 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1201,7 +1201,6 @@ dtrace_close(dtrace_hdl_t *dtp)
 
 	dt_epid_destroy(dtp);
 	dt_aggid_destroy(dtp);
-	dt_format_destroy(dtp);
 	dt_buffered_destroy(dtp);
 	dt_aggregate_destroy(dtp);
 	dt_pebs_exit(dtp);
-- 
2.26.0




More information about the DTrace-devel mailing list