12633Sahl /*
22633Sahl * CDDL HEADER START
32633Sahl *
42633Sahl * The contents of this file are subject to the terms of the
52633Sahl * Common Development and Distribution License (the "License").
62633Sahl * You may not use this file except in compliance with the License.
72633Sahl *
82633Sahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92633Sahl * or http://www.opensolaris.org/os/licensing.
102633Sahl * See the License for the specific language governing permissions
112633Sahl * and limitations under the License.
122633Sahl *
132633Sahl * When distributing Covered Code, include this CDDL HEADER in each
142633Sahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152633Sahl * If applicable, add the following below this CDDL HEADER, with the
162633Sahl * fields enclosed by brackets "[]" replaced with your own identifying
172633Sahl * information: Portions Copyright [yyyy] [name of copyright owner]
182633Sahl *
192633Sahl * CDDL HEADER END
202633Sahl */
212633Sahl
222633Sahl /*
23*9397SJonathan.Haslam@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
242633Sahl * Use is subject to license terms.
252633Sahl */
262633Sahl
272633Sahl #include <strings.h>
282633Sahl #include <unistd.h>
292633Sahl #include <dtrace.h>
302633Sahl
312633Sahl static int g_count;
322633Sahl static int g_errs;
332633Sahl static int g_fd;
342633Sahl static int g_verbose;
352633Sahl static int g_errexit;
36*9397SJonathan.Haslam@Sun.COM static char *g_progname;
372633Sahl
382633Sahl static int
probe(dtrace_hdl_t * dtp,const dtrace_probedesc_t * pdp,void * data)392633Sahl probe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *data)
402633Sahl {
412633Sahl dtrace_probeinfo_t p;
422633Sahl dtrace_argdesc_t arg;
432633Sahl char buf[BUFSIZ];
442633Sahl int i;
452633Sahl
462633Sahl (void) printf("\r%6d", ++g_count);
472633Sahl (void) fflush(stdout);
482633Sahl
492633Sahl if (dtrace_probe_info(dtp, pdp, &p) != 0) {
502633Sahl (void) printf(" failed to get probe info for "
512633Sahl "%s:%s:%s:%s [%d]\n", pdp->dtpd_provider, pdp->dtpd_mod,
522633Sahl pdp->dtpd_func, pdp->dtpd_name, pdp->dtpd_id);
532633Sahl g_errs++;
542633Sahl return (0);
552633Sahl }
562633Sahl
572633Sahl for (i = 0; i < p.dtp_argc; i++) {
582633Sahl if (p.dtp_argv[i].dtt_type == CTF_ERR) {
592633Sahl bzero(&arg, sizeof (dtrace_argdesc_t));
602633Sahl arg.dtargd_id = pdp->dtpd_id;
612633Sahl arg.dtargd_ndx = i;
622633Sahl (void) ioctl(g_fd, DTRACEIOC_PROBEARG, &arg);
632633Sahl
642633Sahl (void) printf(" failed to get types for args[%d] "
652633Sahl "of %s:%s:%s:%s [%d]: <%s> -> <%s>\n", i,
662633Sahl pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func,
672633Sahl pdp->dtpd_name, pdp->dtpd_id,
682633Sahl arg.dtargd_native, arg.dtargd_xlate);
692633Sahl
702633Sahl g_errs++;
712633Sahl
722633Sahl if (g_errexit)
732633Sahl return (-1);
742633Sahl
752633Sahl } else if (g_verbose) {
762633Sahl (void) printf("%d args[%d] : %s\n", pdp->dtpd_id, i,
772633Sahl ctf_type_name(p.dtp_argv[i].dtt_ctfp,
782633Sahl p.dtp_argv[i].dtt_type, buf, sizeof (buf)));
792633Sahl }
802633Sahl }
812633Sahl
822633Sahl return (0);
832633Sahl }
842633Sahl
852633Sahl int
main(int argc,char * argv[])862633Sahl main(int argc, char *argv[])
872633Sahl {
882633Sahl dtrace_probedesc_t pd, *pdp = NULL;
892633Sahl dtrace_hdl_t *dtp;
902633Sahl int err, c;
912633Sahl char *p;
922633Sahl
93*9397SJonathan.Haslam@Sun.COM g_progname = argv[0];
94*9397SJonathan.Haslam@Sun.COM
952633Sahl if ((dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL) {
962633Sahl (void) fprintf(stderr, "%s: failed to open dtrace: %s\n",
97*9397SJonathan.Haslam@Sun.COM g_progname, dtrace_errmsg(dtp, err));
982633Sahl return (1);
992633Sahl }
1002633Sahl
1012633Sahl while ((c = getopt(argc, argv, "evx:")) != -1) {
1022633Sahl switch (c) {
1032633Sahl case 'e':
1042633Sahl g_errexit++;
1052633Sahl break;
1062633Sahl case 'v':
1072633Sahl g_verbose++;
1082633Sahl break;
1092633Sahl case 'x':
1102633Sahl if ((p = strchr(optarg, '=')) != NULL)
1112633Sahl *p++ = '\0';
1122633Sahl
1132633Sahl if (dtrace_setopt(dtp, optarg, p) != 0) {
1142633Sahl (void) fprintf(stderr, "%s: failed to set "
115*9397SJonathan.Haslam@Sun.COM "option -x %s: %s\n", g_progname, optarg,
1162633Sahl dtrace_errmsg(dtp, dtrace_errno(dtp)));
1172633Sahl return (2);
1182633Sahl }
1192633Sahl break;
1202633Sahl
1212633Sahl default:
1222633Sahl (void) fprintf(stderr, "Usage: %s [-ev] "
123*9397SJonathan.Haslam@Sun.COM "[-x opt[=arg]] [probedesc]\n", g_progname);
1242633Sahl return (2);
1252633Sahl }
1262633Sahl }
1272633Sahl
1282633Sahl argv += optind;
1292633Sahl argc -= optind;
1302633Sahl
1312633Sahl if (argc > 0) {
132*9397SJonathan.Haslam@Sun.COM if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, argv[0], &pd)) {
1332633Sahl (void) fprintf(stderr, "%s: invalid probe description "
134*9397SJonathan.Haslam@Sun.COM "%s: %s\n", g_progname, argv[0],
1352633Sahl dtrace_errmsg(dtp, dtrace_errno(dtp)));
1362633Sahl return (2);
1372633Sahl }
1382633Sahl pdp = &pd;
1392633Sahl }
1402633Sahl
1412633Sahl g_fd = dtrace_ctlfd(dtp);
1422633Sahl (void) dtrace_probe_iter(dtp, pdp, probe, NULL);
1432633Sahl dtrace_close(dtp);
1442633Sahl
1452633Sahl (void) printf("\nTotal probes: %d\n", g_count);
1462633Sahl (void) printf("Total errors: %d\n\n", g_errs);
1472633Sahl
1482633Sahl return (g_errs != 0);
1492633Sahl }
150