4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
31 #include <sys/resource.h>
33 #include <sys/types.h>
47 #include <dt_string.h>
50 dt_opt_agg(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
52 dt_aggregate_t *agp = &dtp->dt_aggregate;
55 return (dt_set_errno(dtp, EDT_BADOPTVAL));
57 agp->dtat_flags |= option;
63 dt_opt_amin(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
65 char str[DTRACE_ATTR2STR_MAX];
66 dtrace_attribute_t attr;
68 if (arg == NULL || dtrace_str2attr(arg, &attr) == -1)
69 return (dt_set_errno(dtp, EDT_BADOPTVAL));
71 dt_dprintf("set compiler attribute minimum to %s\n",
72 dtrace_attr2str(attr, str, sizeof (str)));
74 if (dtp->dt_pcb != NULL) {
75 dtp->dt_pcb->pcb_cflags |= DTRACE_C_EATTR;
76 dtp->dt_pcb->pcb_amin = attr;
78 dtp->dt_cflags |= DTRACE_C_EATTR;
88 const char msg[] = "libdtrace DEBUG: [ forcing coredump ]\n";
93 (void) write(STDERR_FILENO, msg, sizeof (msg) - 1);
95 act.sa_handler = SIG_DFL;
98 (void) sigemptyset(&act.sa_mask);
99 (void) sigaction(SIGABRT, &act, NULL);
101 lim.rlim_cur = RLIM_INFINITY;
102 lim.rlim_max = RLIM_INFINITY;
104 (void) setrlimit(RLIMIT_CORE, &lim);
110 dt_opt_core(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
112 static int enabled = 0;
115 return (dt_set_errno(dtp, EDT_BADOPTVAL));
117 if (enabled++ || atexit(dt_coredump) == 0)
120 return (dt_set_errno(dtp, errno));
125 dt_opt_cpp_hdrs(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
128 return (dt_set_errno(dtp, EDT_BADOPTVAL));
130 if (dtp->dt_pcb != NULL)
131 return (dt_set_errno(dtp, EDT_BADOPTCTX));
133 if (dt_cpp_add_arg(dtp, "-H") == NULL)
134 return (dt_set_errno(dtp, EDT_NOMEM));
141 dt_opt_cpp_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
146 return (dt_set_errno(dtp, EDT_BADOPTVAL));
148 if (dtp->dt_pcb != NULL)
149 return (dt_set_errno(dtp, EDT_BADOPTCTX));
151 if ((cpp = strdup(arg)) == NULL)
152 return (dt_set_errno(dtp, EDT_NOMEM));
154 dtp->dt_cpp_argv[0] = (char *)strbasename(cpp);
155 free(dtp->dt_cpp_path);
156 dtp->dt_cpp_path = cpp;
162 dt_opt_cpp_opts(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
166 const char *opt = (const char *)option;
168 if (opt == NULL || arg == NULL)
169 return (dt_set_errno(dtp, EDT_BADOPTVAL));
171 if (dtp->dt_pcb != NULL)
172 return (dt_set_errno(dtp, EDT_BADOPTCTX));
174 len = strlen(opt) + strlen(arg) + 1;
177 (void) strcpy(buf, opt);
178 (void) strcat(buf, arg);
180 if (dt_cpp_add_arg(dtp, buf) == NULL)
181 return (dt_set_errno(dtp, EDT_NOMEM));
188 dt_opt_ctypes(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
193 return (dt_set_errno(dtp, EDT_BADOPTVAL));
195 if ((fd = open64(arg, O_CREAT | O_WRONLY, 0666)) == -1)
196 return (dt_set_errno(dtp, errno));
198 (void) close(dtp->dt_cdefs_fd);
199 dtp->dt_cdefs_fd = fd;
205 dt_opt_droptags(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
207 dtp->dt_droptags = 1;
213 dt_opt_dtypes(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
218 return (dt_set_errno(dtp, EDT_BADOPTVAL));
220 if ((fd = open64(arg, O_CREAT | O_WRONLY, 0666)) == -1)
221 return (dt_set_errno(dtp, errno));
223 (void) close(dtp->dt_ddefs_fd);
224 dtp->dt_ddefs_fd = fd;
230 dt_opt_debug(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
233 return (dt_set_errno(dtp, EDT_BADOPTVAL));
241 dt_opt_iregs(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
245 if (arg == NULL || (n = atoi(arg)) <= 0)
246 return (dt_set_errno(dtp, EDT_BADOPTVAL));
248 dtp->dt_conf.dtc_difintregs = n;
254 dt_opt_lazyload(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
256 dtp->dt_lazyload = 1;
263 dt_opt_ld_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
268 return (dt_set_errno(dtp, EDT_BADOPTVAL));
270 if (dtp->dt_pcb != NULL)
271 return (dt_set_errno(dtp, EDT_BADOPTCTX));
273 if ((ld = strdup(arg)) == NULL)
274 return (dt_set_errno(dtp, EDT_NOMEM));
276 free(dtp->dt_ld_path);
277 dtp->dt_ld_path = ld;
284 dt_opt_libdir(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
289 return (dt_set_errno(dtp, EDT_BADOPTVAL));
291 if ((dp = malloc(sizeof (dt_dirpath_t))) == NULL ||
292 (dp->dir_path = strdup(arg)) == NULL) {
294 return (dt_set_errno(dtp, EDT_NOMEM));
297 dt_list_append(&dtp->dt_lib_path, dp);
303 dt_opt_linkmode(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
306 return (dt_set_errno(dtp, EDT_BADOPTVAL));
308 if (strcmp(arg, "kernel") == 0)
309 dtp->dt_linkmode = DT_LINK_KERNEL;
310 else if (strcmp(arg, "primary") == 0)
311 dtp->dt_linkmode = DT_LINK_PRIMARY;
312 else if (strcmp(arg, "dynamic") == 0)
313 dtp->dt_linkmode = DT_LINK_DYNAMIC;
314 else if (strcmp(arg, "static") == 0)
315 dtp->dt_linkmode = DT_LINK_STATIC;
317 return (dt_set_errno(dtp, EDT_BADOPTVAL));
324 dt_opt_linktype(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
327 return (dt_set_errno(dtp, EDT_BADOPTVAL));
329 if (strcasecmp(arg, "elf") == 0)
330 dtp->dt_linktype = DT_LTYP_ELF;
331 else if (strcasecmp(arg, "dof") == 0)
332 dtp->dt_linktype = DT_LTYP_DOF;
334 return (dt_set_errno(dtp, EDT_BADOPTVAL));
341 dt_opt_evaltime(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
344 return (dt_set_errno(dtp, EDT_BADOPTVAL));
346 if (strcmp(arg, "exec") == 0)
347 dtp->dt_prcmode = DT_PROC_STOP_CREATE;
348 else if (strcmp(arg, "preinit") == 0)
349 dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
350 else if (strcmp(arg, "postinit") == 0)
351 dtp->dt_prcmode = DT_PROC_STOP_POSTINIT;
352 else if (strcmp(arg, "main") == 0)
353 dtp->dt_prcmode = DT_PROC_STOP_MAIN;
355 return (dt_set_errno(dtp, EDT_BADOPTVAL));
362 dt_opt_pgmax(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
366 if (arg == NULL || (n = atoi(arg)) < 0)
367 return (dt_set_errno(dtp, EDT_BADOPTVAL));
369 dtp->dt_procs->dph_lrulim = n;
374 dt_opt_setenv(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
381 * We can't effectively set environment variables from #pragma lines
382 * since the processes have already been spawned.
384 if (dtp->dt_pcb != NULL)
385 return (dt_set_errno(dtp, EDT_BADOPTCTX));
388 return (dt_set_errno(dtp, EDT_BADOPTVAL));
390 if (!option && strchr(arg, '=') != NULL)
391 return (dt_set_errno(dtp, EDT_BADOPTVAL));
393 for (i = 1, p = dtp->dt_proc_env; *p != NULL; i++, p++)
396 for (p = dtp->dt_proc_env; *p != NULL; p++) {
397 var = strchr(*p, '=');
399 var = *p + strlen(*p);
400 if (strncmp(*p, arg, var - *p) == 0) {
402 *p = dtp->dt_proc_env[i - 1];
403 dtp->dt_proc_env[i - 1] = NULL;
409 if ((var = strdup(arg)) == NULL)
410 return (dt_set_errno(dtp, EDT_NOMEM));
412 if ((p = dt_alloc(dtp, sizeof (char *) * (i + 1))) == NULL) {
414 return (dt_set_errno(dtp, EDT_NOMEM));
417 bcopy(dtp->dt_proc_env, p, sizeof (char *) * i);
418 dt_free(dtp, dtp->dt_proc_env);
419 dtp->dt_proc_env = p;
421 dtp->dt_proc_env[i - 1] = var;
422 dtp->dt_proc_env[i] = NULL;
430 dt_opt_stdc(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
433 return (dt_set_errno(dtp, EDT_BADOPTVAL));
435 if (dtp->dt_pcb != NULL)
436 return (dt_set_errno(dtp, EDT_BADOPTCTX));
438 if (strcmp(arg, "a") == 0)
439 dtp->dt_stdcmode = DT_STDC_XA;
440 else if (strcmp(arg, "c") == 0)
441 dtp->dt_stdcmode = DT_STDC_XC;
442 else if (strcmp(arg, "s") == 0)
443 dtp->dt_stdcmode = DT_STDC_XS;
444 else if (strcmp(arg, "t") == 0)
445 dtp->dt_stdcmode = DT_STDC_XT;
447 return (dt_set_errno(dtp, EDT_BADOPTVAL));
454 dt_opt_syslibdir(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
456 dt_dirpath_t *dp = dt_list_next(&dtp->dt_lib_path);
460 return (dt_set_errno(dtp, EDT_BADOPTVAL));
462 if ((path = strdup(arg)) == NULL)
463 return (dt_set_errno(dtp, EDT_NOMEM));
473 dt_opt_tree(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
477 if (arg == NULL || (m = atoi(arg)) <= 0)
478 return (dt_set_errno(dtp, EDT_BADOPTVAL));
480 dtp->dt_treedump = m;
486 dt_opt_tregs(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
490 if (arg == NULL || (n = atoi(arg)) <= 0)
491 return (dt_set_errno(dtp, EDT_BADOPTVAL));
493 dtp->dt_conf.dtc_diftupregs = n;
499 dt_opt_xlate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
502 return (dt_set_errno(dtp, EDT_BADOPTVAL));
504 if (strcmp(arg, "dynamic") == 0)
505 dtp->dt_xlatemode = DT_XL_DYNAMIC;
506 else if (strcmp(arg, "static") == 0)
507 dtp->dt_xlatemode = DT_XL_STATIC;
509 return (dt_set_errno(dtp, EDT_BADOPTVAL));
516 dt_opt_cflags(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
519 return (dt_set_errno(dtp, EDT_BADOPTVAL));
521 if (dtp->dt_pcb != NULL)
522 dtp->dt_pcb->pcb_cflags |= option;
524 dtp->dt_cflags |= option;
530 dt_opt_dflags(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
533 return (dt_set_errno(dtp, EDT_BADOPTVAL));
535 dtp->dt_dflags |= option;
540 dt_opt_invcflags(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
543 return (dt_set_errno(dtp, EDT_BADOPTVAL));
545 if (dtp->dt_pcb != NULL)
546 dtp->dt_pcb->pcb_cflags &= ~option;
548 dtp->dt_cflags &= ~option;
555 dt_opt_version(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
560 return (dt_set_errno(dtp, EDT_BADOPTVAL));
562 if (dt_version_str2num(arg, &v) == -1)
563 return (dt_set_errno(dtp, EDT_VERSINVAL));
565 if (!dt_version_defined(v))
566 return (dt_set_errno(dtp, EDT_VERSUNDEF));
568 return (dt_reduce(dtp, v));
572 dt_opt_runtime(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
575 dtrace_optval_t val = 0;
583 { "enable", "disable" },
584 { "enabled", "disabled" },
592 if (arg[0] == '\0') {
593 val = DTRACEOPT_UNSET;
597 for (i = 0; couples[i].positive != NULL; i++) {
598 if (strcasecmp(couples[i].positive, arg) == 0) {
603 if (strcasecmp(couples[i].negative, arg) == 0) {
604 val = DTRACEOPT_UNSET;
610 val = strtoull(arg, &end, 0);
612 if (*end != '\0' || errno != 0 || val < 0)
613 return (dt_set_errno(dtp, EDT_BADOPTVAL));
617 dtp->dt_options[option] = val;
622 dt_optval_parse(const char *arg, dtrace_optval_t *rval)
624 dtrace_optval_t mul = 1;
631 switch (arg[len - 1]) {
653 *rval = strtoull(arg, &end, 0) * mul;
655 if ((mul > 1 && end != &arg[len - 1]) || (mul == 1 && *end != '\0') ||
656 *rval < 0 || errno != 0)
663 dt_opt_size(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
665 dtrace_optval_t val = 0;
667 if (arg != NULL && dt_optval_parse(arg, &val) != 0)
668 return (dt_set_errno(dtp, EDT_BADOPTVAL));
670 dtp->dt_options[option] = val;
675 dt_opt_rate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
679 dtrace_optval_t mul = 1, val = 0;
685 { "ns", NANOSEC / NANOSEC },
686 { "nsec", NANOSEC / NANOSEC },
687 { "us", NANOSEC / MICROSEC },
688 { "usec", NANOSEC / MICROSEC },
689 { "ms", NANOSEC / MILLISEC },
690 { "msec", NANOSEC / MILLISEC },
691 { "s", NANOSEC / SEC },
692 { "sec", NANOSEC / SEC },
693 { "m", NANOSEC * (hrtime_t)60 },
694 { "min", NANOSEC * (hrtime_t)60 },
695 { "h", NANOSEC * (hrtime_t)60 * (hrtime_t)60 },
696 { "hour", NANOSEC * (hrtime_t)60 * (hrtime_t)60 },
697 { "d", NANOSEC * (hrtime_t)(24 * 60 * 60) },
698 { "day", NANOSEC * (hrtime_t)(24 * 60 * 60) },
705 val = strtoull(arg, &end, 0);
707 for (i = 0; suffix[i].name != NULL; i++) {
708 if (strcasecmp(suffix[i].name, end) == 0) {
714 if (suffix[i].name == NULL && *end != '\0' || val < 0)
715 return (dt_set_errno(dtp, EDT_BADOPTVAL));
719 * The rate has been specified in frequency-per-second.
728 dtp->dt_options[option] = val;
733 * When setting the strsize option, set the option in the dt_options array
734 * using dt_opt_size() as usual, and then update the definition of the CTF
735 * type for the D intrinsic "string" to be an array of the corresponding size.
736 * If any errors occur, reset dt_options[option] to its previous value.
739 dt_opt_strsize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
741 dtrace_optval_t val = dtp->dt_options[option];
742 ctf_file_t *fp = DT_STR_CTFP(dtp);
743 ctf_id_t type = ctf_type_resolve(fp, DT_STR_TYPE(dtp));
746 if (dt_opt_size(dtp, arg, option) != 0)
747 return (-1); /* dt_errno is set for us */
749 if (dtp->dt_options[option] > UINT_MAX) {
750 dtp->dt_options[option] = val;
751 return (dt_set_errno(dtp, EOVERFLOW));
754 if (ctf_array_info(fp, type, &r) == CTF_ERR) {
755 dtp->dt_options[option] = val;
756 dtp->dt_ctferr = ctf_errno(fp);
757 return (dt_set_errno(dtp, EDT_CTF));
760 r.ctr_nelems = (uint_t)dtp->dt_options[option];
762 if (ctf_set_array(fp, type, &r) == CTF_ERR ||
763 ctf_update(fp) == CTF_ERR) {
764 dtp->dt_options[option] = val;
765 dtp->dt_ctferr = ctf_errno(fp);
766 return (dt_set_errno(dtp, EDT_CTF));
772 static const struct {
773 const char *dtbp_name;
775 } _dtrace_bufpolicies[] = {
776 { "ring", DTRACEOPT_BUFPOLICY_RING },
777 { "fill", DTRACEOPT_BUFPOLICY_FILL },
778 { "switch", DTRACEOPT_BUFPOLICY_SWITCH },
784 dt_opt_bufpolicy(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
786 dtrace_optval_t policy = DTRACEOPT_UNSET;
790 return (dt_set_errno(dtp, EDT_BADOPTVAL));
792 for (i = 0; _dtrace_bufpolicies[i].dtbp_name != NULL; i++) {
793 if (strcmp(_dtrace_bufpolicies[i].dtbp_name, arg) == 0) {
794 policy = _dtrace_bufpolicies[i].dtbp_policy;
799 if (policy == DTRACEOPT_UNSET)
800 return (dt_set_errno(dtp, EDT_BADOPTVAL));
802 dtp->dt_options[DTRACEOPT_BUFPOLICY] = policy;
807 static const struct {
808 const char *dtbr_name;
810 } _dtrace_bufresize[] = {
811 { "auto", DTRACEOPT_BUFRESIZE_AUTO },
812 { "manual", DTRACEOPT_BUFRESIZE_MANUAL },
818 dt_opt_bufresize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
820 dtrace_optval_t policy = DTRACEOPT_UNSET;
824 return (dt_set_errno(dtp, EDT_BADOPTVAL));
826 for (i = 0; _dtrace_bufresize[i].dtbr_name != NULL; i++) {
827 if (strcmp(_dtrace_bufresize[i].dtbr_name, arg) == 0) {
828 policy = _dtrace_bufresize[i].dtbr_policy;
833 if (policy == DTRACEOPT_UNSET)
834 return (dt_set_errno(dtp, EDT_BADOPTVAL));
836 dtp->dt_options[DTRACEOPT_BUFRESIZE] = policy;
842 dt_options_load(dtrace_hdl_t *dtp)
850 * To load the option values, we need to ask the kernel to provide its
851 * DOF, which we'll sift through to look for OPTDESC sections.
853 bzero(&hdr, sizeof (dof_hdr_t));
854 hdr.dofh_loadsz = sizeof (dof_hdr_t);
857 if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
860 if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1)
862 return (dt_set_errno(dtp, errno));
864 if (hdr.dofh_loadsz < sizeof (dof_hdr_t))
865 return (dt_set_errno(dtp, EINVAL));
867 dof = alloca(hdr.dofh_loadsz);
868 bzero(dof, sizeof (dof_hdr_t));
869 dof->dofh_loadsz = hdr.dofh_loadsz;
871 for (i = 0; i < DTRACEOPT_MAX; i++)
872 dtp->dt_options[i] = DTRACEOPT_UNSET;
875 if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1)
877 if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &dof) == -1)
879 return (dt_set_errno(dtp, errno));
881 for (i = 0; i < dof->dofh_secnum; i++) {
882 sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof +
883 dof->dofh_secoff + i * dof->dofh_secsize);
885 if (sec->dofs_type != DOF_SECT_OPTDESC)
891 for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) {
892 dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t)
893 ((uintptr_t)dof + sec->dofs_offset + offs);
895 if (opt->dofo_strtab != DOF_SECIDX_NONE)
898 if (opt->dofo_option >= DTRACEOPT_MAX)
901 dtp->dt_options[opt->dofo_option] = opt->dofo_value;
907 typedef struct dt_option {
909 int (*o_func)(dtrace_hdl_t *, const char *, uintptr_t);
914 * Compile-time options.
916 static const dt_option_t _dtrace_ctoptions[] = {
917 { "aggpercpu", dt_opt_agg, DTRACE_A_PERCPU },
918 { "amin", dt_opt_amin },
919 { "argref", dt_opt_cflags, DTRACE_C_ARGREF },
920 { "core", dt_opt_core },
921 { "cpp", dt_opt_cflags, DTRACE_C_CPP },
922 { "cpphdrs", dt_opt_cpp_hdrs },
923 { "cpppath", dt_opt_cpp_path },
924 { "ctypes", dt_opt_ctypes },
925 { "defaultargs", dt_opt_cflags, DTRACE_C_DEFARG },
926 { "dtypes", dt_opt_dtypes },
927 { "debug", dt_opt_debug },
928 { "define", dt_opt_cpp_opts, (uintptr_t)"-D" },
929 { "droptags", dt_opt_droptags },
930 { "empty", dt_opt_cflags, DTRACE_C_EMPTY },
931 { "errtags", dt_opt_cflags, DTRACE_C_ETAGS },
932 { "evaltime", dt_opt_evaltime },
933 { "incdir", dt_opt_cpp_opts, (uintptr_t)"-I" },
934 { "iregs", dt_opt_iregs },
935 { "kdefs", dt_opt_invcflags, DTRACE_C_KNODEF },
936 { "knodefs", dt_opt_cflags, DTRACE_C_KNODEF },
937 { "late", dt_opt_xlate },
938 { "lazyload", dt_opt_lazyload },
939 { "ldpath", dt_opt_ld_path },
940 { "libdir", dt_opt_libdir },
941 { "linkmode", dt_opt_linkmode },
942 { "linktype", dt_opt_linktype },
943 { "nolibs", dt_opt_cflags, DTRACE_C_NOLIBS },
944 { "pgmax", dt_opt_pgmax },
945 { "pspec", dt_opt_cflags, DTRACE_C_PSPEC },
946 { "setenv", dt_opt_setenv, 1 },
947 { "stdc", dt_opt_stdc },
948 { "strip", dt_opt_dflags, DTRACE_D_STRIP },
949 { "syslibdir", dt_opt_syslibdir },
950 { "tree", dt_opt_tree },
951 { "tregs", dt_opt_tregs },
952 { "udefs", dt_opt_invcflags, DTRACE_C_UNODEF },
953 { "undef", dt_opt_cpp_opts, (uintptr_t)"-U" },
954 { "unodefs", dt_opt_cflags, DTRACE_C_UNODEF },
955 { "unsetenv", dt_opt_setenv, 0 },
956 { "verbose", dt_opt_cflags, DTRACE_C_DIFV },
957 { "version", dt_opt_version },
958 { "zdefs", dt_opt_cflags, DTRACE_C_ZDEFS },
965 static const dt_option_t _dtrace_rtoptions[] = {
966 { "aggsize", dt_opt_size, DTRACEOPT_AGGSIZE },
967 { "bufsize", dt_opt_size, DTRACEOPT_BUFSIZE },
968 { "bufpolicy", dt_opt_bufpolicy, DTRACEOPT_BUFPOLICY },
969 { "bufresize", dt_opt_bufresize, DTRACEOPT_BUFRESIZE },
970 { "cleanrate", dt_opt_rate, DTRACEOPT_CLEANRATE },
971 { "cpu", dt_opt_runtime, DTRACEOPT_CPU },
972 { "destructive", dt_opt_runtime, DTRACEOPT_DESTRUCTIVE },
973 { "dynvarsize", dt_opt_size, DTRACEOPT_DYNVARSIZE },
974 { "grabanon", dt_opt_runtime, DTRACEOPT_GRABANON },
975 { "jstackframes", dt_opt_runtime, DTRACEOPT_JSTACKFRAMES },
976 { "jstackstrsize", dt_opt_size, DTRACEOPT_JSTACKSTRSIZE },
977 { "nspec", dt_opt_runtime, DTRACEOPT_NSPEC },
978 { "specsize", dt_opt_size, DTRACEOPT_SPECSIZE },
979 { "stackframes", dt_opt_runtime, DTRACEOPT_STACKFRAMES },
980 { "statusrate", dt_opt_rate, DTRACEOPT_STATUSRATE },
981 { "strsize", dt_opt_strsize, DTRACEOPT_STRSIZE },
982 { "ustackframes", dt_opt_runtime, DTRACEOPT_USTACKFRAMES },
983 { "temporal", dt_opt_runtime, DTRACEOPT_TEMPORAL },
988 * Dynamic run-time options.
990 static const dt_option_t _dtrace_drtoptions[] = {
991 { "aggrate", dt_opt_rate, DTRACEOPT_AGGRATE },
992 { "aggsortkey", dt_opt_runtime, DTRACEOPT_AGGSORTKEY },
993 { "aggsortkeypos", dt_opt_runtime, DTRACEOPT_AGGSORTKEYPOS },
994 { "aggsortpos", dt_opt_runtime, DTRACEOPT_AGGSORTPOS },
995 { "aggsortrev", dt_opt_runtime, DTRACEOPT_AGGSORTREV },
996 { "flowindent", dt_opt_runtime, DTRACEOPT_FLOWINDENT },
997 { "quiet", dt_opt_runtime, DTRACEOPT_QUIET },
998 { "rawbytes", dt_opt_runtime, DTRACEOPT_RAWBYTES },
999 { "stackindent", dt_opt_runtime, DTRACEOPT_STACKINDENT },
1000 { "switchrate", dt_opt_rate, DTRACEOPT_SWITCHRATE },
1005 dtrace_getopt(dtrace_hdl_t *dtp, const char *opt, dtrace_optval_t *val)
1007 const dt_option_t *op;
1010 return (dt_set_errno(dtp, EINVAL));
1013 * We only need to search the run-time options -- it's not legal
1014 * to get the values of compile-time options.
1016 for (op = _dtrace_rtoptions; op->o_name != NULL; op++) {
1017 if (strcmp(op->o_name, opt) == 0) {
1018 *val = dtp->dt_options[op->o_option];
1023 for (op = _dtrace_drtoptions; op->o_name != NULL; op++) {
1024 if (strcmp(op->o_name, opt) == 0) {
1025 *val = dtp->dt_options[op->o_option];
1030 return (dt_set_errno(dtp, EDT_BADOPTNAME));
1034 dtrace_setopt(dtrace_hdl_t *dtp, const char *opt, const char *val)
1036 const dt_option_t *op;
1039 return (dt_set_errno(dtp, EINVAL));
1041 for (op = _dtrace_ctoptions; op->o_name != NULL; op++) {
1042 if (strcmp(op->o_name, opt) == 0)
1043 return (op->o_func(dtp, val, op->o_option));
1046 for (op = _dtrace_drtoptions; op->o_name != NULL; op++) {
1047 if (strcmp(op->o_name, opt) == 0)
1048 return (op->o_func(dtp, val, op->o_option));
1051 for (op = _dtrace_rtoptions; op->o_name != NULL; op++) {
1052 if (strcmp(op->o_name, opt) == 0) {
1054 * Only dynamic run-time options may be set while
1055 * tracing is active.
1058 return (dt_set_errno(dtp, EDT_ACTIVE));
1060 return (op->o_func(dtp, val, op->o_option));
1064 return (dt_set_errno(dtp, EDT_BADOPTNAME));