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 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 */
30
31 #include <sys/resource.h>
32 #include <sys/mman.h>
33 #include <sys/types.h>
34
35 #include <strings.h>
36 #include <signal.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <limits.h>
40 #include <alloca.h>
41 #include <errno.h>
42 #include <fcntl.h>
43
44 #include <dt_impl.h>
45 #include <dt_string.h>
46
47 static int
319
320 /*ARGSUSED*/
321 static int
322 dt_opt_linktype(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
323 {
324 if (arg == NULL)
325 return (dt_set_errno(dtp, EDT_BADOPTVAL));
326
327 if (strcasecmp(arg, "elf") == 0)
328 dtp->dt_linktype = DT_LTYP_ELF;
329 else if (strcasecmp(arg, "dof") == 0)
330 dtp->dt_linktype = DT_LTYP_DOF;
331 else
332 return (dt_set_errno(dtp, EDT_BADOPTVAL));
333
334 return (0);
335 }
336
337 /*ARGSUSED*/
338 static int
339 dt_opt_evaltime(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
340 {
341 if (arg == NULL)
342 return (dt_set_errno(dtp, EDT_BADOPTVAL));
343
344 if (strcmp(arg, "exec") == 0)
345 dtp->dt_prcmode = DT_PROC_STOP_CREATE;
346 else if (strcmp(arg, "preinit") == 0)
347 dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
348 else if (strcmp(arg, "postinit") == 0)
349 dtp->dt_prcmode = DT_PROC_STOP_POSTINIT;
350 else if (strcmp(arg, "main") == 0)
351 dtp->dt_prcmode = DT_PROC_STOP_MAIN;
352 else
353 return (dt_set_errno(dtp, EDT_BADOPTVAL));
354
355 return (0);
356 }
357
358 /*ARGSUSED*/
900 } dt_option_t;
901
902 /*
903 * Compile-time options.
904 */
905 static const dt_option_t _dtrace_ctoptions[] = {
906 { "aggpercpu", dt_opt_agg, DTRACE_A_PERCPU },
907 { "amin", dt_opt_amin },
908 { "argref", dt_opt_cflags, DTRACE_C_ARGREF },
909 { "core", dt_opt_core },
910 { "cpp", dt_opt_cflags, DTRACE_C_CPP },
911 { "cpphdrs", dt_opt_cpp_hdrs },
912 { "cpppath", dt_opt_cpp_path },
913 { "ctypes", dt_opt_ctypes },
914 { "defaultargs", dt_opt_cflags, DTRACE_C_DEFARG },
915 { "dtypes", dt_opt_dtypes },
916 { "debug", dt_opt_debug },
917 { "define", dt_opt_cpp_opts, (uintptr_t)"-D" },
918 { "droptags", dt_opt_droptags },
919 { "empty", dt_opt_cflags, DTRACE_C_EMPTY },
920 { "errtags", dt_opt_cflags, DTRACE_C_ETAGS },
921 { "evaltime", dt_opt_evaltime },
922 { "incdir", dt_opt_cpp_opts, (uintptr_t)"-I" },
923 { "iregs", dt_opt_iregs },
924 { "kdefs", dt_opt_invcflags, DTRACE_C_KNODEF },
925 { "knodefs", dt_opt_cflags, DTRACE_C_KNODEF },
926 { "late", dt_opt_xlate },
927 { "lazyload", dt_opt_lazyload },
928 { "ldpath", dt_opt_ld_path },
929 { "libdir", dt_opt_libdir },
930 { "linkmode", dt_opt_linkmode },
931 { "linktype", dt_opt_linktype },
932 { "nolibs", dt_opt_cflags, DTRACE_C_NOLIBS },
933 { "pgmax", dt_opt_pgmax },
934 { "pspec", dt_opt_cflags, DTRACE_C_PSPEC },
935 { "setenv", dt_opt_setenv, 1 },
936 { "stdc", dt_opt_stdc },
937 { "strip", dt_opt_dflags, DTRACE_D_STRIP },
938 { "syslibdir", dt_opt_syslibdir },
939 { "tree", dt_opt_tree },
960 { "cpu", dt_opt_runtime, DTRACEOPT_CPU },
961 { "destructive", dt_opt_runtime, DTRACEOPT_DESTRUCTIVE },
962 { "dynvarsize", dt_opt_size, DTRACEOPT_DYNVARSIZE },
963 { "grabanon", dt_opt_runtime, DTRACEOPT_GRABANON },
964 { "jstackframes", dt_opt_runtime, DTRACEOPT_JSTACKFRAMES },
965 { "jstackstrsize", dt_opt_size, DTRACEOPT_JSTACKSTRSIZE },
966 { "nspec", dt_opt_runtime, DTRACEOPT_NSPEC },
967 { "specsize", dt_opt_size, DTRACEOPT_SPECSIZE },
968 { "stackframes", dt_opt_runtime, DTRACEOPT_STACKFRAMES },
969 { "statusrate", dt_opt_rate, DTRACEOPT_STATUSRATE },
970 { "strsize", dt_opt_strsize, DTRACEOPT_STRSIZE },
971 { "ustackframes", dt_opt_runtime, DTRACEOPT_USTACKFRAMES },
972 { "temporal", dt_opt_runtime, DTRACEOPT_TEMPORAL },
973 { NULL }
974 };
975
976 /*
977 * Dynamic run-time options.
978 */
979 static const dt_option_t _dtrace_drtoptions[] = {
980 { "aggrate", dt_opt_rate, DTRACEOPT_AGGRATE },
981 { "aggsortkey", dt_opt_runtime, DTRACEOPT_AGGSORTKEY },
982 { "aggsortkeypos", dt_opt_runtime, DTRACEOPT_AGGSORTKEYPOS },
983 { "aggsortpos", dt_opt_runtime, DTRACEOPT_AGGSORTPOS },
984 { "aggsortrev", dt_opt_runtime, DTRACEOPT_AGGSORTREV },
985 { "flowindent", dt_opt_runtime, DTRACEOPT_FLOWINDENT },
986 { "quiet", dt_opt_runtime, DTRACEOPT_QUIET },
987 { "rawbytes", dt_opt_runtime, DTRACEOPT_RAWBYTES },
988 { "stackindent", dt_opt_runtime, DTRACEOPT_STACKINDENT },
989 { "switchrate", dt_opt_rate, DTRACEOPT_SWITCHRATE },
990 { NULL }
991 };
992
993 int
994 dtrace_getopt(dtrace_hdl_t *dtp, const char *opt, dtrace_optval_t *val)
995 {
996 const dt_option_t *op;
997
998 if (opt == NULL)
999 return (dt_set_errno(dtp, EINVAL));
1000
1001 /*
1002 * We only need to search the run-time options -- it's not legal
1003 * to get the values of compile-time options.
1004 */
|
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 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 * Copyright (c) 2012 by Delphix. All rights reserved.
30 */
31
32 #include <sys/resource.h>
33 #include <sys/mman.h>
34 #include <sys/types.h>
35
36 #include <strings.h>
37 #include <signal.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <limits.h>
41 #include <alloca.h>
42 #include <errno.h>
43 #include <fcntl.h>
44
45 #include <dt_impl.h>
46 #include <dt_string.h>
47
48 static int
320
321 /*ARGSUSED*/
322 static int
323 dt_opt_linktype(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
324 {
325 if (arg == NULL)
326 return (dt_set_errno(dtp, EDT_BADOPTVAL));
327
328 if (strcasecmp(arg, "elf") == 0)
329 dtp->dt_linktype = DT_LTYP_ELF;
330 else if (strcasecmp(arg, "dof") == 0)
331 dtp->dt_linktype = DT_LTYP_DOF;
332 else
333 return (dt_set_errno(dtp, EDT_BADOPTVAL));
334
335 return (0);
336 }
337
338 /*ARGSUSED*/
339 static int
340 dt_opt_encoding(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
341 {
342 if (arg == NULL)
343 return (dt_set_errno(dtp, EDT_BADOPTVAL));
344
345 if (strcmp(arg, "ascii") == 0)
346 dtp->dt_encoding = DT_ENCODING_ASCII;
347 else if (strcmp(arg, "utf8") == 0)
348 dtp->dt_encoding = DT_ENCODING_UTF8;
349 else
350 return (dt_set_errno(dtp, EDT_BADOPTVAL));
351
352 return (0);
353 }
354
355 /*ARGSUSED*/
356 static int
357 dt_opt_evaltime(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
358 {
359 if (arg == NULL)
360 return (dt_set_errno(dtp, EDT_BADOPTVAL));
361
362 if (strcmp(arg, "exec") == 0)
363 dtp->dt_prcmode = DT_PROC_STOP_CREATE;
364 else if (strcmp(arg, "preinit") == 0)
365 dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
366 else if (strcmp(arg, "postinit") == 0)
367 dtp->dt_prcmode = DT_PROC_STOP_POSTINIT;
368 else if (strcmp(arg, "main") == 0)
369 dtp->dt_prcmode = DT_PROC_STOP_MAIN;
370 else
371 return (dt_set_errno(dtp, EDT_BADOPTVAL));
372
373 return (0);
374 }
375
376 /*ARGSUSED*/
918 } dt_option_t;
919
920 /*
921 * Compile-time options.
922 */
923 static const dt_option_t _dtrace_ctoptions[] = {
924 { "aggpercpu", dt_opt_agg, DTRACE_A_PERCPU },
925 { "amin", dt_opt_amin },
926 { "argref", dt_opt_cflags, DTRACE_C_ARGREF },
927 { "core", dt_opt_core },
928 { "cpp", dt_opt_cflags, DTRACE_C_CPP },
929 { "cpphdrs", dt_opt_cpp_hdrs },
930 { "cpppath", dt_opt_cpp_path },
931 { "ctypes", dt_opt_ctypes },
932 { "defaultargs", dt_opt_cflags, DTRACE_C_DEFARG },
933 { "dtypes", dt_opt_dtypes },
934 { "debug", dt_opt_debug },
935 { "define", dt_opt_cpp_opts, (uintptr_t)"-D" },
936 { "droptags", dt_opt_droptags },
937 { "empty", dt_opt_cflags, DTRACE_C_EMPTY },
938 { "encoding", dt_opt_encoding },
939 { "errtags", dt_opt_cflags, DTRACE_C_ETAGS },
940 { "evaltime", dt_opt_evaltime },
941 { "incdir", dt_opt_cpp_opts, (uintptr_t)"-I" },
942 { "iregs", dt_opt_iregs },
943 { "kdefs", dt_opt_invcflags, DTRACE_C_KNODEF },
944 { "knodefs", dt_opt_cflags, DTRACE_C_KNODEF },
945 { "late", dt_opt_xlate },
946 { "lazyload", dt_opt_lazyload },
947 { "ldpath", dt_opt_ld_path },
948 { "libdir", dt_opt_libdir },
949 { "linkmode", dt_opt_linkmode },
950 { "linktype", dt_opt_linktype },
951 { "nolibs", dt_opt_cflags, DTRACE_C_NOLIBS },
952 { "pgmax", dt_opt_pgmax },
953 { "pspec", dt_opt_cflags, DTRACE_C_PSPEC },
954 { "setenv", dt_opt_setenv, 1 },
955 { "stdc", dt_opt_stdc },
956 { "strip", dt_opt_dflags, DTRACE_D_STRIP },
957 { "syslibdir", dt_opt_syslibdir },
958 { "tree", dt_opt_tree },
979 { "cpu", dt_opt_runtime, DTRACEOPT_CPU },
980 { "destructive", dt_opt_runtime, DTRACEOPT_DESTRUCTIVE },
981 { "dynvarsize", dt_opt_size, DTRACEOPT_DYNVARSIZE },
982 { "grabanon", dt_opt_runtime, DTRACEOPT_GRABANON },
983 { "jstackframes", dt_opt_runtime, DTRACEOPT_JSTACKFRAMES },
984 { "jstackstrsize", dt_opt_size, DTRACEOPT_JSTACKSTRSIZE },
985 { "nspec", dt_opt_runtime, DTRACEOPT_NSPEC },
986 { "specsize", dt_opt_size, DTRACEOPT_SPECSIZE },
987 { "stackframes", dt_opt_runtime, DTRACEOPT_STACKFRAMES },
988 { "statusrate", dt_opt_rate, DTRACEOPT_STATUSRATE },
989 { "strsize", dt_opt_strsize, DTRACEOPT_STRSIZE },
990 { "ustackframes", dt_opt_runtime, DTRACEOPT_USTACKFRAMES },
991 { "temporal", dt_opt_runtime, DTRACEOPT_TEMPORAL },
992 { NULL }
993 };
994
995 /*
996 * Dynamic run-time options.
997 */
998 static const dt_option_t _dtrace_drtoptions[] = {
999 { "agghist", dt_opt_runtime, DTRACEOPT_AGGHIST },
1000 { "aggpack", dt_opt_runtime, DTRACEOPT_AGGPACK },
1001 { "aggrate", dt_opt_rate, DTRACEOPT_AGGRATE },
1002 { "aggsortkey", dt_opt_runtime, DTRACEOPT_AGGSORTKEY },
1003 { "aggsortkeypos", dt_opt_runtime, DTRACEOPT_AGGSORTKEYPOS },
1004 { "aggsortpos", dt_opt_runtime, DTRACEOPT_AGGSORTPOS },
1005 { "aggsortrev", dt_opt_runtime, DTRACEOPT_AGGSORTREV },
1006 { "aggzoom", dt_opt_runtime, DTRACEOPT_AGGZOOM },
1007 { "flowindent", dt_opt_runtime, DTRACEOPT_FLOWINDENT },
1008 { "quiet", dt_opt_runtime, DTRACEOPT_QUIET },
1009 { "rawbytes", dt_opt_runtime, DTRACEOPT_RAWBYTES },
1010 { "stackindent", dt_opt_runtime, DTRACEOPT_STACKINDENT },
1011 { "switchrate", dt_opt_rate, DTRACEOPT_SWITCHRATE },
1012 { NULL }
1013 };
1014
1015 int
1016 dtrace_getopt(dtrace_hdl_t *dtp, const char *opt, dtrace_optval_t *val)
1017 {
1018 const dt_option_t *op;
1019
1020 if (opt == NULL)
1021 return (dt_set_errno(dtp, EINVAL));
1022
1023 /*
1024 * We only need to search the run-time options -- it's not legal
1025 * to get the values of compile-time options.
1026 */
|