1*2633Sahl /* 2*2633Sahl * CDDL HEADER START 3*2633Sahl * 4*2633Sahl * The contents of this file are subject to the terms of the 5*2633Sahl * Common Development and Distribution License (the "License"). 6*2633Sahl * You may not use this file except in compliance with the License. 7*2633Sahl * 8*2633Sahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*2633Sahl * or http://www.opensolaris.org/os/licensing. 10*2633Sahl * See the License for the specific language governing permissions 11*2633Sahl * and limitations under the License. 12*2633Sahl * 13*2633Sahl * When distributing Covered Code, include this CDDL HEADER in each 14*2633Sahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*2633Sahl * If applicable, add the following below this CDDL HEADER, with the 16*2633Sahl * fields enclosed by brackets "[]" replaced with your own identifying 17*2633Sahl * information: Portions Copyright [yyyy] [name of copyright owner] 18*2633Sahl * 19*2633Sahl * CDDL HEADER END 20*2633Sahl */ 21*2633Sahl 22*2633Sahl /* 23*2633Sahl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*2633Sahl * Use is subject to license terms. 25*2633Sahl */ 26*2633Sahl 27*2633Sahl #pragma ident "%Z%%M% %I% %E% SMI" 28*2633Sahl 29*2633Sahl #include <strings.h> 30*2633Sahl #include <unistd.h> 31*2633Sahl #include <dtrace.h> 32*2633Sahl 33*2633Sahl static int g_count; 34*2633Sahl static int g_errs; 35*2633Sahl static int g_fd; 36*2633Sahl static int g_verbose; 37*2633Sahl static int g_errexit; 38*2633Sahl 39*2633Sahl static int 40*2633Sahl probe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *data) 41*2633Sahl { 42*2633Sahl dtrace_probeinfo_t p; 43*2633Sahl dtrace_argdesc_t arg; 44*2633Sahl char buf[BUFSIZ]; 45*2633Sahl int i; 46*2633Sahl 47*2633Sahl (void) printf("\r%6d", ++g_count); 48*2633Sahl (void) fflush(stdout); 49*2633Sahl 50*2633Sahl if (dtrace_probe_info(dtp, pdp, &p) != 0) { 51*2633Sahl (void) printf(" failed to get probe info for " 52*2633Sahl "%s:%s:%s:%s [%d]\n", pdp->dtpd_provider, pdp->dtpd_mod, 53*2633Sahl pdp->dtpd_func, pdp->dtpd_name, pdp->dtpd_id); 54*2633Sahl g_errs++; 55*2633Sahl return (0); 56*2633Sahl } 57*2633Sahl 58*2633Sahl for (i = 0; i < p.dtp_argc; i++) { 59*2633Sahl if (p.dtp_argv[i].dtt_type == CTF_ERR) { 60*2633Sahl bzero(&arg, sizeof (dtrace_argdesc_t)); 61*2633Sahl arg.dtargd_id = pdp->dtpd_id; 62*2633Sahl arg.dtargd_ndx = i; 63*2633Sahl (void) ioctl(g_fd, DTRACEIOC_PROBEARG, &arg); 64*2633Sahl 65*2633Sahl (void) printf(" failed to get types for args[%d] " 66*2633Sahl "of %s:%s:%s:%s [%d]: <%s> -> <%s>\n", i, 67*2633Sahl pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, 68*2633Sahl pdp->dtpd_name, pdp->dtpd_id, 69*2633Sahl arg.dtargd_native, arg.dtargd_xlate); 70*2633Sahl 71*2633Sahl g_errs++; 72*2633Sahl 73*2633Sahl if (g_errexit) 74*2633Sahl return (-1); 75*2633Sahl 76*2633Sahl } else if (g_verbose) { 77*2633Sahl (void) printf("%d args[%d] : %s\n", pdp->dtpd_id, i, 78*2633Sahl ctf_type_name(p.dtp_argv[i].dtt_ctfp, 79*2633Sahl p.dtp_argv[i].dtt_type, buf, sizeof (buf))); 80*2633Sahl } 81*2633Sahl } 82*2633Sahl 83*2633Sahl return (0); 84*2633Sahl } 85*2633Sahl 86*2633Sahl int 87*2633Sahl main(int argc, char *argv[]) 88*2633Sahl { 89*2633Sahl dtrace_probedesc_t pd, *pdp = NULL; 90*2633Sahl dtrace_hdl_t *dtp; 91*2633Sahl int err, c; 92*2633Sahl char *p; 93*2633Sahl 94*2633Sahl if ((dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL) { 95*2633Sahl (void) fprintf(stderr, "%s: failed to open dtrace: %s\n", 96*2633Sahl argv[0], dtrace_errmsg(dtp, err)); 97*2633Sahl return (1); 98*2633Sahl } 99*2633Sahl 100*2633Sahl while ((c = getopt(argc, argv, "evx:")) != -1) { 101*2633Sahl switch (c) { 102*2633Sahl case 'e': 103*2633Sahl g_errexit++; 104*2633Sahl break; 105*2633Sahl case 'v': 106*2633Sahl g_verbose++; 107*2633Sahl break; 108*2633Sahl case 'x': 109*2633Sahl if ((p = strchr(optarg, '=')) != NULL) 110*2633Sahl *p++ = '\0'; 111*2633Sahl 112*2633Sahl if (dtrace_setopt(dtp, optarg, p) != 0) { 113*2633Sahl (void) fprintf(stderr, "%s: failed to set " 114*2633Sahl "option -x %s: %s\n", argv[0], optarg, 115*2633Sahl dtrace_errmsg(dtp, dtrace_errno(dtp))); 116*2633Sahl return (2); 117*2633Sahl } 118*2633Sahl break; 119*2633Sahl 120*2633Sahl default: 121*2633Sahl (void) fprintf(stderr, "Usage: %s [-ev] " 122*2633Sahl "[-x opt[=arg]] [probedesc]\n", argv[0]); 123*2633Sahl return (2); 124*2633Sahl } 125*2633Sahl } 126*2633Sahl 127*2633Sahl argv += optind; 128*2633Sahl argc -= optind; 129*2633Sahl 130*2633Sahl if (argc > 0) { 131*2633Sahl if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, argv[1], &pd)) { 132*2633Sahl (void) fprintf(stderr, "%s: invalid probe description " 133*2633Sahl "%s: %s\n", argv[0], argv[1], 134*2633Sahl dtrace_errmsg(dtp, dtrace_errno(dtp))); 135*2633Sahl return (2); 136*2633Sahl } 137*2633Sahl pdp = &pd; 138*2633Sahl } 139*2633Sahl 140*2633Sahl g_fd = dtrace_ctlfd(dtp); 141*2633Sahl (void) dtrace_probe_iter(dtp, pdp, probe, NULL); 142*2633Sahl dtrace_close(dtp); 143*2633Sahl 144*2633Sahl (void) printf("\nTotal probes: %d\n", g_count); 145*2633Sahl (void) printf("Total errors: %d\n\n", g_errs); 146*2633Sahl 147*2633Sahl return (g_errs != 0); 148*2633Sahl } 149