Skip to content

Commit

Permalink
4248 dtrace(1M) should never create DOF with empty probes section
Browse files Browse the repository at this point in the history
4249 Only probes from the first DTrace object file will be included
Reviewed by: Adam Leventhal <ahl@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information
bcantrill authored and rmustacc committed Nov 6, 2013
1 parent b206134 commit 54a20ab
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 11 deletions.
106 changes: 106 additions & 0 deletions usr/src/cmd/dtrace/test/tst/common/usdt/tst.multiprov.ksh
@@ -0,0 +1,106 @@
#
# 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

echo '#pragma D option quiet' > test.d
echo '#pragma D option aggsortkey' >> test.d

cat > test.c <<EOF
#include <unistd.h>
void
main()
{
EOF

objs=

for oogle in doogle bagnoogle; do
cat > $oogle.c <<EOF
#include <sys/sdt.h>
void
$oogle()
{
DTRACE_PROBE($oogle, knows);
}
EOF

cat > $oogle.d <<EOF
provider $oogle {
probe knows();
};
EOF

cc -c $oogle.c

if [ $? -ne 0 ]; then
print -u2 "failed to compile $oogle.c"
exit 1
fi

$dtrace -G -32 -s $oogle.d $oogle.o -o $oogle.d.o

if [ $? -ne 0 ]; then
print -u2 "failed to process $oogle.d"
exit 1
fi

objs="$objs $oogle.o $oogle.d.o"
echo $oogle'();' >> test.c
echo $oogle'$target:::{@[probefunc] = count()}' >> test.d
done
echo "}" >> test.c
echo 'END{printa("%-10s %@d\\n", @)}' >> test.d
cc -o test test.c $objs
if [ $? -ne 0 ]; then
print -u2 "failed to compile test.c"
exit 1
fi
$dtrace -s ./test.d -Zc ./test
if [ $? -ne 0 ]; then
print -u2 "failed to execute test"
exit 1
fi
cd /
/usr/bin/rm -rf $DIR
exit 0
3 changes: 3 additions & 0 deletions usr/src/cmd/dtrace/test/tst/common/usdt/tst.multiprov.ksh.out
@@ -0,0 +1,3 @@
bagnoogle 1
doogle 1

59 changes: 59 additions & 0 deletions 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
22 changes: 17 additions & 5 deletions usr/src/lib/libdtrace/common/dt_dof.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

/*
Expand Down
4 changes: 3 additions & 1 deletion usr/src/lib/libdtrace/common/dt_error.c
Expand Up @@ -26,6 +26,7 @@

/*
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/

#include <strings.h>
Expand Down Expand Up @@ -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]);
Expand Down
5 changes: 3 additions & 2 deletions usr/src/lib/libdtrace/common/dt_impl.h
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -512,7 +512,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 */
};

/*
Expand Down
3 changes: 3 additions & 0 deletions usr/src/pkg/manifests/system-dtrace-tests.mf
Expand Up @@ -2009,7 +2009,10 @@ file path=opt/SUNWdtrt/tst/common/usdt/tst.linkpriv.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.linkunpriv.ksh mode=0444
file path=opt/SUNWdtrt/tst/common/usdt/tst.multiple.ksh mode=0444
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
Expand Down
6 changes: 3 additions & 3 deletions usr/src/uts/common/dtrace/dtrace.c
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, Joyent, Inc. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
*/

Expand Down Expand Up @@ -13941,8 +13941,8 @@ dtrace_helper_provider_add(dof_helper_t *dofhp, int gen)
* Check to make sure this isn't a duplicate.
*/
for (i = 0; i < help->dthps_nprovs; i++) {
if (dofhp->dofhp_addr ==
help->dthps_provs[i]->dthp_prov.dofhp_addr)
if (dofhp->dofhp_dof ==
help->dthps_provs[i]->dthp_prov.dofhp_dof)
return (EALREADY);
}

Expand Down

1 comment on commit 54a20ab

@indutny
Copy link

@indutny indutny commented on 54a20ab Mar 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, wouldn't it be better to just ignore that provider and do not output it to DOF, instead of erroring?

Please sign in to comment.