summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Cantrill <bryan@joyent.com>2013-04-15 05:51:24 +0000
committerBryan Cantrill <bryan@joyent.com>2013-04-15 05:51:24 +0000
commit0c21344f0ef77770fea38c544d2f5d0e33f9a9dc (patch)
tree3206f0af8b309803191a1c75c99bf650db258812
parent44ac4e4af990271145543aaa44f59e0d910f52c3 (diff)
downloadillumos-joyent-0c21344f0ef77770fea38c544d2f5d0e33f9a9dc.tar.gz
OS-2131 dtrace(1M) should never create DOF with empty probes section
-rw-r--r--usr/src/cmd/dtrace/test/tst/common/usdt/tst.noprobes.ksh59
-rw-r--r--usr/src/lib/libdtrace/common/dt_dof.c22
-rw-r--r--usr/src/lib/libdtrace/common/dt_error.c4
-rw-r--r--usr/src/lib/libdtrace/common/dt_impl.h5
-rw-r--r--usr/src/pkg/manifests/system-dtrace-tests.mf1
5 files changed, 83 insertions, 8 deletions
diff --git a/usr/src/cmd/dtrace/test/tst/common/usdt/tst.noprobes.ksh b/usr/src/cmd/dtrace/test/tst/common/usdt/tst.noprobes.ksh
new file mode 100644
index 0000000000..a43970f560
--- /dev/null
+++ b/usr/src/cmd/dtrace/test/tst/common/usdt/tst.noprobes.ksh
@@ -0,0 +1,59 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2013, Joyent, Inc. All rights reserved.
+#
+
+if [ $# != 1 ]; then
+ echo expected one argument: '<'dtrace-path'>'
+ exit 2
+fi
+
+dtrace=$1
+DIR=/var/tmp/dtest.$$
+
+mkdir $DIR
+cd $DIR
+
+cat > test.c <<EOF
+void
+foo()
+{}
+EOF
+
+cat > doogle.d <<EOF
+provider doogle {
+ probe bagnoogle();
+};
+EOF
+
+cc -c test.c
+$dtrace -G -32 -s doogle.d test.o -o doogle.d.o
+
+if [ $? -eq 0 ]; then
+ print -u2 "dtrace succeeded despite having no probe sites"
+ exit 1
+fi
+
+cd /
+/usr/bin/rm -rf $DIR
+exit 0
diff --git a/usr/src/lib/libdtrace/common/dt_dof.c b/usr/src/lib/libdtrace/common/dt_dof.c
index 04c4c89cdb..c1f5dc827e 100644
--- a/usr/src/lib/libdtrace/common/dt_dof.c
+++ b/usr/src/lib/libdtrace/common/dt_dof.c
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
#include <sys/types.h>
@@ -482,7 +483,7 @@ dof_add_probe(dt_idhash_t *dhp, dt_ident_t *idp, void *data)
return (0);
}
-static void
+static int
dof_add_provider(dt_dof_t *ddo, const dt_provider_t *pvp)
{
dtrace_hdl_t *dtp = ddo->ddo_hdl;
@@ -493,8 +494,12 @@ dof_add_provider(dt_dof_t *ddo, const dt_provider_t *pvp)
size_t sz;
id_t i;
- if (pvp->pv_flags & DT_PROVIDER_IMPL)
- return; /* ignore providers that are exported by dtrace(7D) */
+ if (pvp->pv_flags & DT_PROVIDER_IMPL) {
+ /*
+ * ignore providers that are exported by dtrace(7D)
+ */
+ return (0);
+ }
nxr = dt_popcb(pvp->pv_xrefs, pvp->pv_xrmax);
dofs = alloca(sizeof (dof_secidx_t) * (nxr + 1));
@@ -521,6 +526,9 @@ dof_add_provider(dt_dof_t *ddo, const dt_provider_t *pvp)
(void) dt_idhash_iter(pvp->pv_probes, dof_add_probe, ddo);
+ if (dt_buf_len(&ddo->ddo_probes) == 0)
+ return (dt_set_errno(dtp, EDT_NOPROBES));
+
dofpv.dofpv_probes = dof_add_lsect(ddo, NULL, DOF_SECT_PROBES,
sizeof (uint64_t), 0, sizeof (dof_probe_t),
dt_buf_len(&ddo->ddo_probes));
@@ -575,6 +583,8 @@ dof_add_provider(dt_dof_t *ddo, const dt_provider_t *pvp)
sizeof (dof_secidx_t), 0, sizeof (dof_secidx_t),
sizeof (dof_secidx_t) * (nxr + 1));
}
+
+ return (0);
}
static int
@@ -818,8 +828,10 @@ dtrace_dof_create(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t flags)
*/
if (flags & DTRACE_D_PROBES) {
for (pvp = dt_list_next(&dtp->dt_provlist);
- pvp != NULL; pvp = dt_list_next(pvp))
- dof_add_provider(ddo, pvp);
+ pvp != NULL; pvp = dt_list_next(pvp)) {
+ if (dof_add_provider(ddo, pvp) != 0)
+ return (NULL);
+ }
}
/*
diff --git a/usr/src/lib/libdtrace/common/dt_error.c b/usr/src/lib/libdtrace/common/dt_error.c
index 9c1cbd73bc..f7ad28ebae 100644
--- a/usr/src/lib/libdtrace/common/dt_error.c
+++ b/usr/src/lib/libdtrace/common/dt_error.c
@@ -26,6 +26,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
#include <strings.h>
@@ -108,7 +109,8 @@ static const struct {
{ EDT_BADSTACKPC, "Invalid stack program counter size" },
{ EDT_BADAGGVAR, "Invalid aggregation variable identifier" },
{ EDT_OVERSION, "Client requested deprecated version of library" },
- { EDT_ENABLING_ERR, "Failed to enable probe" }
+ { EDT_ENABLING_ERR, "Failed to enable probe" },
+ { EDT_NOPROBES, "No probe sites found for declared provider" }
};
static const int _dt_nerr = sizeof (_dt_errlist) / sizeof (_dt_errlist[0]);
diff --git a/usr/src/lib/libdtrace/common/dt_impl.h b/usr/src/lib/libdtrace/common/dt_impl.h
index 60413d7e3b..6420524701 100644
--- a/usr/src/lib/libdtrace/common/dt_impl.h
+++ b/usr/src/lib/libdtrace/common/dt_impl.h
@@ -25,7 +25,7 @@
*/
/*
- * Copyright (c) 2011, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
*/
@@ -513,7 +513,8 @@ enum {
EDT_BADSTACKPC, /* invalid stack program counter size */
EDT_BADAGGVAR, /* invalid aggregation variable identifier */
EDT_OVERSION, /* client is requesting deprecated version */
- EDT_ENABLING_ERR /* failed to enable probe */
+ EDT_ENABLING_ERR, /* failed to enable probe */
+ EDT_NOPROBES /* no probes sites for declared provider */
};
/*
diff --git a/usr/src/pkg/manifests/system-dtrace-tests.mf b/usr/src/pkg/manifests/system-dtrace-tests.mf
index e686d5d1f8..97a35330ef 100644
--- a/usr/src/pkg/manifests/system-dtrace-tests.mf
+++ b/usr/src/pkg/manifests/system-dtrace-tests.mf
@@ -2012,6 +2012,7 @@ file path=opt/SUNWdtrt/tst/common/usdt/tst.multiple.ksh.out mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.multiprov.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.multiprov.ksh.out mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.nodtrace.ksh mode=0444
+file path=opt/SUNWdtrt/tst/common/usdt/tst.noprobes.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.noreap.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.noreapring.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.onlyenabled.ksh mode=0444