1178476Sjb/* 2178476Sjb * CDDL HEADER START 3178476Sjb * 4178476Sjb * The contents of this file are subject to the terms of the 5178476Sjb * Common Development and Distribution License (the "License"). 6178476Sjb * You may not use this file except in compliance with the License. 7178476Sjb * 8178476Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9178476Sjb * or http://www.opensolaris.org/os/licensing. 10178476Sjb * See the License for the specific language governing permissions 11178476Sjb * and limitations under the License. 12178476Sjb * 13178476Sjb * When distributing Covered Code, include this CDDL HEADER in each 14178476Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15178476Sjb * If applicable, add the following below this CDDL HEADER, with the 16178476Sjb * fields enclosed by brackets "[]" replaced with your own identifying 17178476Sjb * information: Portions Copyright [yyyy] [name of copyright owner] 18178476Sjb * 19178476Sjb * CDDL HEADER END 20178476Sjb */ 21178476Sjb 22178476Sjb/* 23210767Srpaulo * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24178476Sjb * Use is subject to license terms. 25178476Sjb */ 26178476Sjb 27178476Sjb#include <strings.h> 28178476Sjb#include <unistd.h> 29178476Sjb#include <dtrace.h> 30178476Sjb 31178476Sjbstatic int g_count; 32178476Sjbstatic int g_errs; 33178476Sjbstatic int g_fd; 34178476Sjbstatic int g_verbose; 35178476Sjbstatic int g_errexit; 36210767Srpaulostatic char *g_progname; 37178476Sjb 38178476Sjbstatic int 39178476Sjbprobe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *data) 40178476Sjb{ 41178476Sjb dtrace_probeinfo_t p; 42178476Sjb dtrace_argdesc_t arg; 43178476Sjb char buf[BUFSIZ]; 44178476Sjb int i; 45178476Sjb 46178476Sjb (void) printf("\r%6d", ++g_count); 47178476Sjb (void) fflush(stdout); 48178476Sjb 49178476Sjb if (dtrace_probe_info(dtp, pdp, &p) != 0) { 50178476Sjb (void) printf(" failed to get probe info for " 51178476Sjb "%s:%s:%s:%s [%d]\n", pdp->dtpd_provider, pdp->dtpd_mod, 52178476Sjb pdp->dtpd_func, pdp->dtpd_name, pdp->dtpd_id); 53178476Sjb g_errs++; 54178476Sjb return (0); 55178476Sjb } 56178476Sjb 57178476Sjb for (i = 0; i < p.dtp_argc; i++) { 58178476Sjb if (p.dtp_argv[i].dtt_type == CTF_ERR) { 59178476Sjb bzero(&arg, sizeof (dtrace_argdesc_t)); 60178476Sjb arg.dtargd_id = pdp->dtpd_id; 61178476Sjb arg.dtargd_ndx = i; 62178476Sjb (void) ioctl(g_fd, DTRACEIOC_PROBEARG, &arg); 63178476Sjb 64178476Sjb (void) printf(" failed to get types for args[%d] " 65178476Sjb "of %s:%s:%s:%s [%d]: <%s> -> <%s>\n", i, 66178476Sjb pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, 67178476Sjb pdp->dtpd_name, pdp->dtpd_id, 68178476Sjb arg.dtargd_native, arg.dtargd_xlate); 69178476Sjb 70178476Sjb g_errs++; 71178476Sjb 72178476Sjb if (g_errexit) 73178476Sjb return (-1); 74178476Sjb 75178476Sjb } else if (g_verbose) { 76178476Sjb (void) printf("%d args[%d] : %s\n", pdp->dtpd_id, i, 77178476Sjb ctf_type_name(p.dtp_argv[i].dtt_ctfp, 78178476Sjb p.dtp_argv[i].dtt_type, buf, sizeof (buf))); 79178476Sjb } 80178476Sjb } 81178476Sjb 82178476Sjb return (0); 83178476Sjb} 84178476Sjb 85178476Sjbint 86178476Sjbmain(int argc, char *argv[]) 87178476Sjb{ 88178476Sjb dtrace_probedesc_t pd, *pdp = NULL; 89178476Sjb dtrace_hdl_t *dtp; 90178476Sjb int err, c; 91178476Sjb char *p; 92178476Sjb 93210767Srpaulo g_progname = argv[0]; 94210767Srpaulo 95178476Sjb if ((dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL) { 96178476Sjb (void) fprintf(stderr, "%s: failed to open dtrace: %s\n", 97210767Srpaulo g_progname, dtrace_errmsg(dtp, err)); 98178476Sjb return (1); 99178476Sjb } 100178476Sjb 101178476Sjb while ((c = getopt(argc, argv, "evx:")) != -1) { 102178476Sjb switch (c) { 103178476Sjb case 'e': 104178476Sjb g_errexit++; 105178476Sjb break; 106178476Sjb case 'v': 107178476Sjb g_verbose++; 108178476Sjb break; 109178476Sjb case 'x': 110178476Sjb if ((p = strchr(optarg, '=')) != NULL) 111178476Sjb *p++ = '\0'; 112178476Sjb 113178476Sjb if (dtrace_setopt(dtp, optarg, p) != 0) { 114178476Sjb (void) fprintf(stderr, "%s: failed to set " 115210767Srpaulo "option -x %s: %s\n", g_progname, optarg, 116178476Sjb dtrace_errmsg(dtp, dtrace_errno(dtp))); 117178476Sjb return (2); 118178476Sjb } 119178476Sjb break; 120178476Sjb 121178476Sjb default: 122178476Sjb (void) fprintf(stderr, "Usage: %s [-ev] " 123210767Srpaulo "[-x opt[=arg]] [probedesc]\n", g_progname); 124178476Sjb return (2); 125178476Sjb } 126178476Sjb } 127178476Sjb 128178476Sjb argv += optind; 129178476Sjb argc -= optind; 130178476Sjb 131178476Sjb if (argc > 0) { 132210767Srpaulo if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, argv[0], &pd)) { 133178476Sjb (void) fprintf(stderr, "%s: invalid probe description " 134210767Srpaulo "%s: %s\n", g_progname, argv[0], 135178476Sjb dtrace_errmsg(dtp, dtrace_errno(dtp))); 136178476Sjb return (2); 137178476Sjb } 138178476Sjb pdp = &pd; 139178476Sjb } 140178476Sjb 141178476Sjb g_fd = dtrace_ctlfd(dtp); 142178476Sjb (void) dtrace_probe_iter(dtp, pdp, probe, NULL); 143178476Sjb dtrace_close(dtp); 144178476Sjb 145178476Sjb (void) printf("\nTotal probes: %d\n", g_count); 146178476Sjb (void) printf("Total errors: %d\n\n", g_errs); 147178476Sjb 148178476Sjb return (g_errs != 0); 149178476Sjb} 150