Print this page
3597 dtrace probe lookup ignores provider, asserts on conflict


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <sys/types.h>
  30 #include <sys/sysmacros.h>
  31 
  32 #include <assert.h>
  33 #include <limits.h>
  34 #include <strings.h>
  35 #include <stdlib.h>
  36 #include <alloca.h>
  37 #include <unistd.h>
  38 #include <errno.h>
  39 
  40 #include <dt_provider.h>
  41 #include <dt_module.h>
  42 #include <dt_string.h>
  43 #include <dt_list.h>
  44 
  45 static dt_provider_t *
  46 dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h)
  47 {
  48         dt_list_append(&dtp->dt_provlist, pvp);


 343         return (prp);
 344 }
 345 
 346 /*
 347  * Lookup a probe declaration based on a known provider and full or partially
 348  * specified module, function, and name.  If the probe is not known to us yet,
 349  * ask dtrace(7D) to match the description and then cache any useful results.
 350  */
 351 dt_probe_t *
 352 dt_probe_lookup(dt_provider_t *pvp, const char *s)
 353 {
 354         dtrace_hdl_t *dtp = pvp->pv_hdl;
 355         dtrace_probedesc_t pd;
 356         dt_ident_t *idp;
 357         size_t keylen;
 358         char *key;
 359 
 360         if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, s, &pd) != 0)
 361                 return (NULL); /* dt_errno is set for us */
 362 












 363         keylen = dt_probe_keylen(&pd);
 364         key = dt_probe_key(&pd, alloca(keylen));
 365 
 366         /*
 367          * If the probe is already declared, then return the dt_probe_t from
 368          * the existing identifier.  This could come from a static declaration
 369          * or it could have been cached from an earlier call to this function.
 370          */
 371         if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL)
 372                 return (idp->di_data);
 373 
 374         /*
 375          * If the probe isn't known, use the probe description computed above
 376          * to ask dtrace(7D) to find the first matching probe.
 377          */
 378         if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0)
 379                 return (dt_probe_discover(pvp, &pd));
 380 
 381         if (errno == ESRCH || errno == EBADF)
 382                 (void) dt_set_errno(dtp, EDT_NOPROBE);




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 


  27 #include <sys/types.h>
  28 #include <sys/sysmacros.h>
  29 
  30 #include <assert.h>
  31 #include <limits.h>
  32 #include <strings.h>
  33 #include <stdlib.h>
  34 #include <alloca.h>
  35 #include <unistd.h>
  36 #include <errno.h>
  37 
  38 #include <dt_provider.h>
  39 #include <dt_module.h>
  40 #include <dt_string.h>
  41 #include <dt_list.h>
  42 
  43 static dt_provider_t *
  44 dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h)
  45 {
  46         dt_list_append(&dtp->dt_provlist, pvp);


 341         return (prp);
 342 }
 343 
 344 /*
 345  * Lookup a probe declaration based on a known provider and full or partially
 346  * specified module, function, and name.  If the probe is not known to us yet,
 347  * ask dtrace(7D) to match the description and then cache any useful results.
 348  */
 349 dt_probe_t *
 350 dt_probe_lookup(dt_provider_t *pvp, const char *s)
 351 {
 352         dtrace_hdl_t *dtp = pvp->pv_hdl;
 353         dtrace_probedesc_t pd;
 354         dt_ident_t *idp;
 355         size_t keylen;
 356         char *key;
 357 
 358         if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, s, &pd) != 0)
 359                 return (NULL); /* dt_errno is set for us */
 360 
 361         /*
 362          * Make sure the probe is fully specified as being in this provider,
 363          * even if the name is missing that part of the specification,
 364          * otherwise our lookups may match in the wrong provider when we ask
 365          * dtrace(7D).
 366          *
 367          * We always do this because we are explicitly searching _this_
 368          * provider.
 369          */
 370         bcopy(pvp->pv_desc.dtvd_name, pd.dtpd_provider,
 371             DTRACE_PROVNAMELEN);
 372 
 373         keylen = dt_probe_keylen(&pd);
 374         key = dt_probe_key(&pd, alloca(keylen));
 375 
 376         /*
 377          * If the probe is already declared, then return the dt_probe_t from
 378          * the existing identifier.  This could come from a static declaration
 379          * or it could have been cached from an earlier call to this function.
 380          */
 381         if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL)
 382                 return (idp->di_data);
 383 
 384         /*
 385          * If the probe isn't known, use the probe description computed above
 386          * to ask dtrace(7D) to find the first matching probe.
 387          */
 388         if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0)
 389                 return (dt_probe_discover(pvp, &pd));
 390 
 391         if (errno == ESRCH || errno == EBADF)
 392                 (void) dt_set_errno(dtp, EDT_NOPROBE);