diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c index dc68c6ef5f72..162224478ec0 100644 --- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c +++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c @@ -1,2084 +1,2083 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2012 by Delphix. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. * Copyright (c) 2023, Domagoj Stolfa. All rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef illumos #include #endif #include #ifdef illumos #include #endif #ifdef __FreeBSD__ #include #include #endif #undef NORETURN /* needed because libxo redefines it */ #include typedef struct dtrace_cmd { void (*dc_func)(struct dtrace_cmd *); /* function to compile arg */ dtrace_probespec_t dc_spec; /* probe specifier context */ char *dc_arg; /* argument from main argv */ const char *dc_name; /* name for error messages */ const char *dc_desc; /* desc for error messages */ dtrace_prog_t *dc_prog; /* program compiled from arg */ char dc_ofile[PATH_MAX]; /* derived output file name */ } dtrace_cmd_t; #define DMODE_VERS 0 /* display version information and exit (-V) */ #define DMODE_EXEC 1 /* compile program for enabling (-a/e/E) */ #define DMODE_ANON 2 /* compile program for anonymous tracing (-A) */ #define DMODE_LINK 3 /* compile program for linking with ELF (-G) */ #define DMODE_LIST 4 /* compile program and list probes (-l) */ #define DMODE_HEADER 5 /* compile program for headergen (-h) */ #define E_SUCCESS 0 #define E_ERROR 1 #define E_USAGE 2 static const char DTRACE_OPTSTR[] = "3:6:aAb:Bc:CdD:ef:FGhHi:I:lL:m:n:o:Op:P:qs:SU:vVwx:X:Z"; static char **g_argv; static int g_argc; static char **g_objv; static int g_objc; static dtrace_cmd_t *g_cmdv; static int g_cmdc; static struct ps_prochandle **g_psv; static int g_psc; static int g_pslive; static char *g_pname; static int g_quiet; static int g_flowindent; static int g_intr; static int g_impatient; static int g_newline; #ifdef __FreeBSD__ static int g_siginfo; #endif static int g_total; static int g_cflags; static int g_oflags; static int g_verbose; static int g_exec = 1; static int g_mode = DMODE_EXEC; static int g_status = E_SUCCESS; static int g_grabanon = 0; static const char *g_ofile = NULL; static FILE *g_ofp; static dtrace_hdl_t *g_dtp; #ifdef illumos static char *g_etcfile = "/etc/system"; static const char *g_etcbegin = "* vvvv Added by DTrace"; static const char *g_etcend = "* ^^^^ Added by DTrace"; static const char *g_etc[] = { "*", "* The following forceload directives were added by dtrace(1M) to allow for", "* tracing during boot. If these directives are removed, the system will", "* continue to function, but tracing will not occur during boot as desired.", "* To remove these directives (and this block comment) automatically, run", "* \"dtrace -A\" without additional arguments. See the \"Anonymous Tracing\"", "* chapter of the Solaris Dynamic Tracing Guide for details.", "*", NULL }; #endif static int usage(FILE *fp) { static const char predact[] = "[[ predicate ] action ]"; (void) fprintf(fp, "Usage: %s [-32|-64] [-aACdeFGhHlqSvVwZ] " "[-b bufsz] [-c cmd] [-D name[=def]]\n\t[-I path] [-L path] " "[-o output] [-p pid] [-s script] [-U name]\n\t" "[-x opt[=val]] [-X a|c|s|t]\n\n" "\t[-P provider %s]\n" "\t[-m [ provider: ] module %s]\n" "\t[-f [[ provider: ] module: ] func %s]\n" "\t[-n [[[ provider: ] module: ] func: ] name %s]\n" "\t[-i probe-id %s] [ args ... ]\n\n", g_pname, predact, predact, predact, predact, predact); (void) fprintf(fp, "\tpredicate -> '/' D-expression '/'\n"); (void) fprintf(fp, "\t action -> '{' D-statements '}'\n"); (void) fprintf(fp, "\n" "\t-32 generate 32-bit D programs and ELF files\n" "\t-64 generate 64-bit D programs and ELF files\n\n" "\t-a claim anonymous tracing state\n" "\t-A generate driver.conf(4) directives for anonymous tracing\n" "\t-b set trace buffer size\n" "\t-c run specified command and exit upon its completion\n" "\t-C run cpp(1) preprocessor on script files\n" "\t-d dump script after syntactic transformations\n" "\t-D define symbol when invoking preprocessor\n" "\t-e exit after compiling request but prior to enabling probes\n" "\t-f enable or list probes matching the specified function name\n" "\t-F coalesce trace output by function\n" "\t-G generate an ELF file containing embedded dtrace program\n" "\t-h generate a header file with definitions for static probes\n" "\t-H print included files when invoking preprocessor\n" "\t-i enable or list probes matching the specified probe id\n" "\t-I add include directory to preprocessor search path\n" "\t-l list probes matching specified criteria\n" "\t-L add library directory to library search path\n" "\t-m enable or list probes matching the specified module name\n" "\t-n enable or list probes matching the specified probe name\n" "\t-o set output file\n" "\t-O print output upon exiting (specific to oformat)\n" "\t-p grab specified process-ID and cache its symbol tables\n" "\t-P enable or list probes matching the specified provider name\n" "\t-q set quiet mode (only output explicitly traced data)\n" "\t-s enable or list probes according to the specified D script\n" "\t-S print D compiler intermediate code\n" "\t-U undefine symbol when invoking preprocessor\n" "\t-v set verbose mode (report stability attributes, arguments)\n" "\t-V report DTrace API version\n" "\t-w permit destructive actions\n" "\t-x enable or modify compiler and tracing options\n" "\t-X specify ISO C conformance settings for preprocessor\n" "\t-Z permit probe descriptions that match zero probes\n"); return (E_USAGE); } static void verror(const char *fmt, va_list ap) { int error = errno; (void) fprintf(stderr, "%s: ", g_pname); (void) vfprintf(stderr, fmt, ap); if (fmt[strlen(fmt) - 1] != '\n') (void) fprintf(stderr, ": %s\n", strerror(error)); } /*PRINTFLIKE1*/ static void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); verror(fmt, ap); va_end(ap); /* * Close the DTrace handle to ensure that any controlled processes are * correctly restored and continued. */ if (g_dtp) dtrace_close(g_dtp); exit(E_ERROR); } /*PRINTFLIKE1*/ static void dfatal(const char *fmt, ...) { #if !defined(illumos) && defined(NEED_ERRLOC) char *p_errfile = NULL; int errline = 0; #endif va_list ap; va_start(ap, fmt); (void) fprintf(stderr, "%s: ", g_pname); if (fmt != NULL) (void) vfprintf(stderr, fmt, ap); va_end(ap); if (fmt != NULL && fmt[strlen(fmt) - 1] != '\n') { (void) fprintf(stderr, ": %s\n", dtrace_errmsg(g_dtp, dtrace_errno(g_dtp))); } else if (fmt == NULL) { (void) fprintf(stderr, "%s\n", dtrace_errmsg(g_dtp, dtrace_errno(g_dtp))); } #if !defined(illumos) && defined(NEED_ERRLOC) dt_get_errloc(g_dtp, &p_errfile, &errline); if (p_errfile != NULL) printf("File '%s', line %d\n", p_errfile, errline); #endif /* * Close the DTrace handle to ensure that any controlled processes are * correctly restored and continued. */ dtrace_close(g_dtp); exit(E_ERROR); } /*PRINTFLIKE1*/ static void error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); verror(fmt, ap); va_end(ap); } /*PRINTFLIKE1*/ static void notice(const char *fmt, ...) { va_list ap; if (g_quiet) return; /* -q or quiet pragma suppresses notice()s */ va_start(ap, fmt); verror(fmt, ap); va_end(ap); } /*PRINTFLIKE1*/ static void oprintf(const char *fmt, ...) { va_list ap; int n; if (g_ofp == NULL) return; va_start(ap, fmt); n = vfprintf(g_ofp, fmt, ap); va_end(ap); if (n < 0) { if (errno != EINTR) { fatal("failed to write to %s", g_ofile ? g_ofile : ""); } clearerr(g_ofp); } } static char ** make_argv(char *s) { const char *ws = "\f\n\r\t\v "; char **argv = malloc(sizeof (char *) * (strlen(s) / 2 + 1)); int argc = 0; char *p = s; if (argv == NULL) return (NULL); for (p = strtok(s, ws); p != NULL; p = strtok(NULL, ws)) argv[argc++] = p; if (argc == 0) argv[argc++] = s; argv[argc] = NULL; return (argv); } static void dof_prune(const char *fname) { struct stat sbuf; size_t sz, i, j, mark, len; char *buf; int msg = 0, fd; if ((fd = open(fname, O_RDONLY)) == -1) { /* * This is okay only if the file doesn't exist at all. */ if (errno != ENOENT) fatal("failed to open %s", fname); return; } if (fstat(fd, &sbuf) == -1) fatal("failed to fstat %s", fname); if ((buf = malloc((sz = sbuf.st_size) + 1)) == NULL) fatal("failed to allocate memory for %s", fname); if (read(fd, buf, sz) != sz) fatal("failed to read %s", fname); buf[sz] = '\0'; (void) close(fd); if ((fd = open(fname, O_WRONLY | O_TRUNC)) == -1) fatal("failed to open %s for writing", fname); len = strlen("dof-data-"); for (mark = 0, i = 0; i < sz; i++) { if (strncmp(&buf[i], "dof-data-", len) != 0) continue; /* * This is only a match if it's in the 0th column. */ if (i != 0 && buf[i - 1] != '\n') continue; if (msg++ == 0) { error("cleaned up old anonymous " "enabling in %s\n", fname); } /* * We have a match. First write out our data up until now. */ if (i != mark) { if (write(fd, &buf[mark], i - mark) != i - mark) fatal("failed to write to %s", fname); } /* * Now scan forward until we scan past a newline. */ for (j = i; j < sz && buf[j] != '\n'; j++) continue; /* * Reset our mark. */ if ((mark = j + 1) >= sz) break; i = j; } if (mark < sz) { if (write(fd, &buf[mark], sz - mark) != sz - mark) fatal("failed to write to %s", fname); } (void) close(fd); free(buf); } #ifdef __FreeBSD__ /* * Use nextboot(8) to tell the loader to load DTrace kernel modules during * the next boot of the system. The nextboot(8) configuration is removed during * boot, so it will not persist indefinitely. */ static void bootdof_add(void) { char * const nbargv[] = { "nextboot", "-a", "-e", "dtraceall_load=\"YES\"", "-e", "dtrace_dof_load=\"YES\"", "-e", "dtrace_dof_name=\"/boot/dtrace.dof\"", "-e", "dtrace_dof_type=\"dtrace_dof\"", NULL, }; pid_t child; int err, status; err = posix_spawnp(&child, "nextboot", NULL, NULL, nbargv, NULL); if (err != 0) { error("failed to execute nextboot: %s", strerror(err)); exit(E_ERROR); } if (waitpid(child, &status, 0) != child) fatal("waiting for nextboot"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { error("nextboot returned with status %d", status); exit(E_ERROR); } } #else static void etcsystem_prune(void) { struct stat sbuf; size_t sz; char *buf, *start, *end; int fd; char *fname = g_etcfile, *tmpname; if ((fd = open(fname, O_RDONLY)) == -1) fatal("failed to open %s", fname); if (fstat(fd, &sbuf) == -1) fatal("failed to fstat %s", fname); if ((buf = malloc((sz = sbuf.st_size) + 1)) == NULL) fatal("failed to allocate memory for %s", fname); if (read(fd, buf, sz) != sz) fatal("failed to read %s", fname); buf[sz] = '\0'; (void) close(fd); if ((start = strstr(buf, g_etcbegin)) == NULL) goto out; if (strlen(buf) != sz) { fatal("embedded nul byte in %s; manual repair of %s " "required\n", fname, fname); } if (strstr(start + 1, g_etcbegin) != NULL) { fatal("multiple start sentinels in %s; manual repair of %s " "required\n", fname, fname); } if ((end = strstr(buf, g_etcend)) == NULL) { fatal("missing end sentinel in %s; manual repair of %s " "required\n", fname, fname); } if (start > end) { fatal("end sentinel preceeds start sentinel in %s; manual " "repair of %s required\n", fname, fname); } end += strlen(g_etcend) + 1; bcopy(end, start, strlen(end) + 1); tmpname = alloca(sz = strlen(fname) + 80); (void) snprintf(tmpname, sz, "%s.dtrace.%d", fname, getpid()); if ((fd = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, sbuf.st_mode)) == -1) fatal("failed to create %s", tmpname); if (write(fd, buf, strlen(buf)) < strlen(buf)) { (void) unlink(tmpname); fatal("failed to write to %s", tmpname); } (void) close(fd); if (chown(tmpname, sbuf.st_uid, sbuf.st_gid) != 0) { (void) unlink(tmpname); fatal("failed to chown(2) %s to uid %d, gid %d", tmpname, (int)sbuf.st_uid, (int)sbuf.st_gid); } if (rename(tmpname, fname) == -1) fatal("rename of %s to %s failed", tmpname, fname); error("cleaned up forceload directives in %s\n", fname); out: free(buf); } static void etcsystem_add(void) { const char *mods[20]; int nmods, line; if ((g_ofp = fopen(g_ofile = g_etcfile, "a")) == NULL) fatal("failed to open output file '%s'", g_ofile); oprintf("%s\n", g_etcbegin); for (line = 0; g_etc[line] != NULL; line++) oprintf("%s\n", g_etc[line]); nmods = dtrace_provider_modules(g_dtp, mods, sizeof (mods) / sizeof (char *) - 1); if (nmods >= sizeof (mods) / sizeof (char *)) fatal("unexpectedly large number of modules!"); mods[nmods++] = "dtrace"; for (line = 0; line < nmods; line++) oprintf("forceload: drv/%s\n", mods[line]); oprintf("%s\n", g_etcend); if (fclose(g_ofp) == EOF) fatal("failed to close output file '%s'", g_ofile); error("added forceload directives to %s\n", g_ofile); } #endif /* !__FreeBSD__ */ static void print_probe_info(const dtrace_probeinfo_t *p) { char buf[BUFSIZ]; char *user; int i; oprintf("\n\tProbe Description Attributes\n"); oprintf("\t\tIdentifier Names: %s\n", dtrace_stability_name(p->dtp_attr.dtat_name)); oprintf("\t\tData Semantics: %s\n", dtrace_stability_name(p->dtp_attr.dtat_data)); oprintf("\t\tDependency Class: %s\n", dtrace_class_name(p->dtp_attr.dtat_class)); oprintf("\n\tArgument Attributes\n"); oprintf("\t\tIdentifier Names: %s\n", dtrace_stability_name(p->dtp_arga.dtat_name)); oprintf("\t\tData Semantics: %s\n", dtrace_stability_name(p->dtp_arga.dtat_data)); oprintf("\t\tDependency Class: %s\n", dtrace_class_name(p->dtp_arga.dtat_class)); oprintf("\n\tArgument Types\n"); for (i = 0; i < p->dtp_argc; i++) { if (p->dtp_argv[i].dtt_flags & DTT_FL_USER) user = "userland "; else user = ""; if (ctf_type_name(p->dtp_argv[i].dtt_ctfp, p->dtp_argv[i].dtt_type, buf, sizeof (buf)) == NULL) (void) strlcpy(buf, "(unknown)", sizeof (buf)); oprintf("\t\targs[%d]: %s%s\n", i, user, buf); } if (p->dtp_argc == 0) oprintf("\t\tNone\n"); oprintf("\n"); } /*ARGSUSED*/ static int info_stmt(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, dtrace_stmtdesc_t *stp, dtrace_ecbdesc_t **last) { dtrace_ecbdesc_t *edp = stp->dtsd_ecbdesc; dtrace_probedesc_t *pdp = &edp->dted_probe; dtrace_probeinfo_t p; if (edp == *last) return (0); oprintf("\n%s:%s:%s:%s\n", pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); if (dtrace_probe_info(dtp, pdp, &p) == 0) print_probe_info(&p); *last = edp; return (0); } /* * Execute the specified program by enabling the corresponding instrumentation. * If -e has been specified, we get the program info but do not enable it. If * -v has been specified, we print a stability report for the program. */ static void exec_prog(const dtrace_cmd_t *dcp) { dtrace_ecbdesc_t *last = NULL; dtrace_proginfo_t dpi; if (!g_exec) { dtrace_program_info(g_dtp, dcp->dc_prog, &dpi); } else if (dtrace_program_exec(g_dtp, dcp->dc_prog, &dpi) == -1) { dfatal("failed to enable '%s'", dcp->dc_name); } else { notice("%s '%s' matched %u probe%s\n", dcp->dc_desc, dcp->dc_name, dpi.dpi_matches, dpi.dpi_matches == 1 ? "" : "s"); } if (g_verbose) { oprintf("\nStability attributes for %s %s:\n", dcp->dc_desc, dcp->dc_name); oprintf("\n\tMinimum Probe Description Attributes\n"); oprintf("\t\tIdentifier Names: %s\n", dtrace_stability_name(dpi.dpi_descattr.dtat_name)); oprintf("\t\tData Semantics: %s\n", dtrace_stability_name(dpi.dpi_descattr.dtat_data)); oprintf("\t\tDependency Class: %s\n", dtrace_class_name(dpi.dpi_descattr.dtat_class)); oprintf("\n\tMinimum Statement Attributes\n"); oprintf("\t\tIdentifier Names: %s\n", dtrace_stability_name(dpi.dpi_stmtattr.dtat_name)); oprintf("\t\tData Semantics: %s\n", dtrace_stability_name(dpi.dpi_stmtattr.dtat_data)); oprintf("\t\tDependency Class: %s\n", dtrace_class_name(dpi.dpi_stmtattr.dtat_class)); if (!g_exec) { (void) dtrace_stmt_iter(g_dtp, dcp->dc_prog, (dtrace_stmt_f *)info_stmt, &last); } else oprintf("\n"); } g_total += dpi.dpi_matches; } /* * Print out the specified DOF buffer as a set of ASCII bytes appropriate for * storing in a driver.conf(4) file associated with the dtrace driver. */ static void anon_prog(const dtrace_cmd_t *dcp, dof_hdr_t *dof, int n) { const uchar_t *p, *q; if (dof == NULL) dfatal("failed to create DOF image for '%s'", dcp->dc_name); p = (uchar_t *)dof; q = p + dof->dofh_filesz; #ifdef __FreeBSD__ /* * On FreeBSD, the DOF file is read directly during boot - just write * two hex characters per byte. */ oprintf("dof-data-%d=", n); while (p < q) oprintf("%02x", *p++); oprintf("\n"); #else oprintf("dof-data-%d=0x%x", n, *p++); while (p < q) oprintf(",0x%x", *p++); oprintf(";\n"); #endif dtrace_dof_destroy(g_dtp, dof); } /* * Link the specified D program in DOF form into an ELF file for use in either * helpers, userland provider definitions, or both. If -o was specified, that * path is used as the output file name. If -o wasn't specified and the input * program is from a script whose name is %.d, use basename(%.o) as the output * file name. Otherwise we use "d.out" as the default output file name. */ static void link_prog(dtrace_cmd_t *dcp) { char *p; if (g_cmdc == 1 && g_ofile != NULL) { (void) strlcpy(dcp->dc_ofile, g_ofile, sizeof (dcp->dc_ofile)); } else if ((p = strrchr(dcp->dc_arg, '.')) != NULL && strcmp(p, ".d") == 0) { p[0] = '\0'; /* strip .d suffix */ (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), "%s.o", basename(dcp->dc_arg)); } else if (g_cmdc > 1) { (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), "d.out.%td", dcp - g_cmdv); } else { (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), "d.out"); } if (dtrace_program_link(g_dtp, dcp->dc_prog, DTRACE_D_PROBES, dcp->dc_ofile, g_objc, g_objv) != 0) dfatal("failed to link %s %s", dcp->dc_desc, dcp->dc_name); } /*ARGSUSED*/ static int list_probe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *arg) { dtrace_probeinfo_t p; oprintf("%5d %10s %17s %33s %s\n", pdp->dtpd_id, pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); if (g_verbose && dtrace_probe_info(dtp, pdp, &p) == 0) print_probe_info(&p); if (g_intr != 0) return (1); return (0); } /*ARGSUSED*/ static int list_stmt(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, dtrace_stmtdesc_t *stp, dtrace_ecbdesc_t **last) { dtrace_ecbdesc_t *edp = stp->dtsd_ecbdesc; if (edp == *last) return (0); if (dtrace_probe_iter(g_dtp, &edp->dted_probe, list_probe, NULL) != 0) { error("failed to match %s:%s:%s:%s: %s\n", edp->dted_probe.dtpd_provider, edp->dted_probe.dtpd_mod, edp->dted_probe.dtpd_func, edp->dted_probe.dtpd_name, dtrace_errmsg(dtp, dtrace_errno(dtp))); } *last = edp; return (0); } /* * List the probes corresponding to the specified program by iterating over * each statement and then matching probes to the statement probe descriptions. */ static void list_prog(const dtrace_cmd_t *dcp) { dtrace_ecbdesc_t *last = NULL; (void) dtrace_stmt_iter(g_dtp, dcp->dc_prog, (dtrace_stmt_f *)list_stmt, &last); } static void compile_file(dtrace_cmd_t *dcp) { char *arg0; FILE *fp; if ((fp = fopen(dcp->dc_arg, "r")) == NULL) fatal("failed to open %s", dcp->dc_arg); arg0 = g_argv[0]; g_argv[0] = dcp->dc_arg; if ((dcp->dc_prog = dtrace_program_fcompile(g_dtp, fp, g_cflags, g_argc, g_argv)) == NULL) dfatal("failed to compile script %s", dcp->dc_arg); g_argv[0] = arg0; (void) fclose(fp); dcp->dc_desc = "script"; dcp->dc_name = dcp->dc_arg; } static void compile_str(dtrace_cmd_t *dcp) { char *p; if ((dcp->dc_prog = dtrace_program_strcompile(g_dtp, dcp->dc_arg, dcp->dc_spec, g_cflags | DTRACE_C_PSPEC, g_argc, g_argv)) == NULL) dfatal("invalid probe specifier %s", dcp->dc_arg); if ((p = strpbrk(dcp->dc_arg, "{/;")) != NULL) *p = '\0'; /* crop name for reporting */ dcp->dc_desc = "description"; dcp->dc_name = dcp->dc_arg; } /*ARGSUSED*/ static void prochandler(struct ps_prochandle *P, const char *msg, void *arg) { #ifdef illumos const psinfo_t *prp = Ppsinfo(P); int pid = Pstatus(P)->pr_pid; char name[SIG2STR_MAX]; #else int wstatus = proc_getwstat(P); int pid = proc_getpid(P); #endif if (msg != NULL) { notice("pid %d: %s\n", pid, msg); return; } #ifdef illumos switch (Pstate(P)) { #else switch (proc_state(P)) { #endif case PS_UNDEAD: #ifdef illumos /* * Ideally we would like to always report pr_wstat here, but it * isn't possible given current /proc semantics. If we grabbed * the process, Ppsinfo() will either fail or return a zeroed * psinfo_t depending on how far the parent is in reaping it. * When /proc provides a stable pr_wstat in the status file, * this code can be improved by examining this new pr_wstat. */ if (prp != NULL && WIFSIGNALED(prp->pr_wstat)) { notice("pid %d terminated by %s\n", pid, proc_signame(WTERMSIG(prp->pr_wstat), name, sizeof (name))); #else if (WIFSIGNALED(wstatus)) { notice("pid %d terminated by %d\n", pid, WTERMSIG(wstatus)); #endif #ifdef illumos } else if (prp != NULL && WEXITSTATUS(prp->pr_wstat) != 0) { notice("pid %d exited with status %d\n", pid, WEXITSTATUS(prp->pr_wstat)); #else } else if (WEXITSTATUS(wstatus) != 0) { notice("pid %d exited with status %d\n", pid, WEXITSTATUS(wstatus)); #endif } else { notice("pid %d has exited\n", pid); } g_pslive--; break; case PS_LOST: notice("pid %d exec'd a set-id or unobservable program\n", pid); g_pslive--; break; } } /*ARGSUSED*/ static int errhandler(const dtrace_errdata_t *data, void *arg) { error(data->dteda_msg); return (DTRACE_HANDLE_OK); } /*ARGSUSED*/ static int drophandler(const dtrace_dropdata_t *data, void *arg) { if (!dtrace_oformat(g_dtp)) { error(data->dtdda_msg); } return (DTRACE_HANDLE_OK); } /*ARGSUSED*/ static int setopthandler(const dtrace_setoptdata_t *data, void *arg) { if (strcmp(data->dtsda_option, "quiet") == 0) g_quiet = data->dtsda_newval != DTRACEOPT_UNSET; if (strcmp(data->dtsda_option, "flowindent") == 0) g_flowindent = data->dtsda_newval != DTRACEOPT_UNSET; return (DTRACE_HANDLE_OK); } #define BUFDUMPHDR(hdr) \ (void) printf("%s: %s%s\n", g_pname, hdr, strlen(hdr) > 0 ? ":" : ""); #define BUFDUMPSTR(ptr, field) \ (void) printf("%s: %20s => ", g_pname, #field); \ if ((ptr)->field != NULL) { \ const char *c = (ptr)->field; \ (void) printf("\""); \ do { \ if (*c == '\n') { \ (void) printf("\\n"); \ continue; \ } \ \ (void) printf("%c", *c); \ } while (*c++ != '\0'); \ (void) printf("\"\n"); \ } else { \ (void) printf("\n"); \ } #define BUFDUMPASSTR(ptr, field, str) \ (void) printf("%s: %20s => %s\n", g_pname, #field, str); #define BUFDUMP(ptr, field) \ (void) printf("%s: %20s => %lld\n", g_pname, #field, \ (long long)(ptr)->field); #define BUFDUMPPTR(ptr, field) \ (void) printf("%s: %20s => %s\n", g_pname, #field, \ (ptr)->field != NULL ? "" : ""); /*ARGSUSED*/ static int bufhandler(const dtrace_bufdata_t *bufdata, void *arg) { const dtrace_aggdata_t *agg = bufdata->dtbda_aggdata; const dtrace_recdesc_t *rec = bufdata->dtbda_recdesc; const dtrace_probedesc_t *pd; uint32_t flags = bufdata->dtbda_flags; char buf[512], *c = buf, *end = c + sizeof (buf); int i, printed; struct { const char *name; uint32_t value; } flagnames[] = { { "AGGVAL", DTRACE_BUFDATA_AGGVAL }, { "AGGKEY", DTRACE_BUFDATA_AGGKEY }, { "AGGFORMAT", DTRACE_BUFDATA_AGGFORMAT }, { "AGGLAST", DTRACE_BUFDATA_AGGLAST }, { "???", UINT32_MAX }, { NULL } }; if (bufdata->dtbda_probe != NULL) { pd = bufdata->dtbda_probe->dtpda_pdesc; } else if (agg != NULL) { pd = agg->dtada_pdesc; } else { pd = NULL; } BUFDUMPHDR(">>> Called buffer handler"); BUFDUMPHDR(""); BUFDUMPHDR(" dtrace_bufdata"); BUFDUMPSTR(bufdata, dtbda_buffered); BUFDUMPPTR(bufdata, dtbda_probe); BUFDUMPPTR(bufdata, dtbda_aggdata); BUFDUMPPTR(bufdata, dtbda_recdesc); (void) snprintf(c, end - c, "0x%x ", bufdata->dtbda_flags); c += strlen(c); for (i = 0, printed = 0; flagnames[i].name != NULL; i++) { if (!(flags & flagnames[i].value)) continue; (void) snprintf(c, end - c, "%s%s", printed++ ? " | " : "(", flagnames[i].name); c += strlen(c); flags &= ~flagnames[i].value; } if (printed) (void) snprintf(c, end - c, ")"); BUFDUMPASSTR(bufdata, dtbda_flags, buf); BUFDUMPHDR(""); if (pd != NULL) { BUFDUMPHDR(" dtrace_probedesc"); BUFDUMPSTR(pd, dtpd_provider); BUFDUMPSTR(pd, dtpd_mod); BUFDUMPSTR(pd, dtpd_func); BUFDUMPSTR(pd, dtpd_name); BUFDUMPHDR(""); } if (rec != NULL) { BUFDUMPHDR(" dtrace_recdesc"); BUFDUMP(rec, dtrd_action); BUFDUMP(rec, dtrd_size); if (agg != NULL) { uint8_t *data; int lim = rec->dtrd_size; (void) sprintf(buf, "%d (data: ", rec->dtrd_offset); c = buf + strlen(buf); if (lim > sizeof (uint64_t)) lim = sizeof (uint64_t); data = (uint8_t *)agg->dtada_data + rec->dtrd_offset; for (i = 0; i < lim; i++) { (void) snprintf(c, end - c, "%s%02x", i == 0 ? "" : " ", *data++); c += strlen(c); } (void) snprintf(c, end - c, "%s)", lim < rec->dtrd_size ? " ..." : ""); BUFDUMPASSTR(rec, dtrd_offset, buf); } else { BUFDUMP(rec, dtrd_offset); } BUFDUMPHDR(""); } if (agg != NULL) { dtrace_aggdesc_t *desc = agg->dtada_desc; BUFDUMPHDR(" dtrace_aggdesc"); BUFDUMPSTR(desc, dtagd_name); BUFDUMP(desc, dtagd_varid); BUFDUMP(desc, dtagd_id); BUFDUMP(desc, dtagd_nrecs); BUFDUMPHDR(""); } return (DTRACE_HANDLE_OK); } /*ARGSUSED*/ static int chewrec(const dtrace_probedata_t *data, const dtrace_recdesc_t *rec, void *arg) { dtrace_actkind_t act; uintptr_t addr; if (rec == NULL) { /* * We have processed the final record; output the newline if * we're not in quiet mode. */ if (!g_quiet) oprintf("\n"); return (DTRACE_CONSUME_NEXT); } act = rec->dtrd_action; addr = (uintptr_t)data->dtpda_data; if (act == DTRACEACT_EXIT) { g_status = *((uint32_t *)addr); return (DTRACE_CONSUME_NEXT); } return (DTRACE_CONSUME_THIS); } /*ARGSUSED*/ static int chew(const dtrace_probedata_t *data, void *arg) { dtrace_probedesc_t *pd = data->dtpda_pdesc; processorid_t cpu = data->dtpda_cpu; static int heading; if (g_impatient) { g_newline = 0; return (DTRACE_CONSUME_ABORT); } if (heading == 0) { if (!g_flowindent) { if (!g_quiet) { oprintf("%3s %6s %32s\n", "CPU", "ID", "FUNCTION:NAME"); } } else { oprintf("%3s %-41s\n", "CPU", "FUNCTION"); } heading = 1; } if (!g_flowindent) { if (dtrace_oformat(g_dtp)) { dtrace_oformat_probe(g_dtp, data, cpu, pd); } else if (!g_quiet) { char name[DTRACE_FUNCNAMELEN + DTRACE_NAMELEN + 2]; (void) snprintf(name, sizeof (name), "%s:%s", pd->dtpd_func, pd->dtpd_name); oprintf("%3d %6d %32s ", cpu, pd->dtpd_id, name); } } else { int indent = data->dtpda_indent; char *name; size_t len; if (data->dtpda_flow == DTRACEFLOW_NONE) { len = indent + DTRACE_FUNCNAMELEN + DTRACE_NAMELEN + 5; name = alloca(len); (void) snprintf(name, len, "%*s%s%s:%s", indent, "", data->dtpda_prefix, pd->dtpd_func, pd->dtpd_name); } else { len = indent + DTRACE_FUNCNAMELEN + 5; name = alloca(len); (void) snprintf(name, len, "%*s%s%s", indent, "", data->dtpda_prefix, pd->dtpd_func); } oprintf("%3d %-41s ", cpu, name); } return (DTRACE_CONSUME_THIS); } static void go(void) { int i; struct { char *name; char *optname; dtrace_optval_t val; } bufs[] = { { "buffer size", "bufsize" }, { "aggregation size", "aggsize" }, { "speculation size", "specsize" }, { "dynamic variable size", "dynvarsize" }, { NULL } }, rates[] = { { "cleaning rate", "cleanrate" }, { "status rate", "statusrate" }, { NULL } }; for (i = 0; bufs[i].name != NULL; i++) { if (dtrace_getopt(g_dtp, bufs[i].optname, &bufs[i].val) == -1) fatal("couldn't get option %s", bufs[i].optname); } for (i = 0; rates[i].name != NULL; i++) { if (dtrace_getopt(g_dtp, rates[i].optname, &rates[i].val) == -1) fatal("couldn't get option %s", rates[i].optname); } if (dtrace_go(g_dtp) == -1) dfatal("could not enable tracing"); for (i = 0; bufs[i].name != NULL; i++) { dtrace_optval_t j = 0, mul = 10; dtrace_optval_t nsize; if (bufs[i].val == DTRACEOPT_UNSET) continue; (void) dtrace_getopt(g_dtp, bufs[i].optname, &nsize); if (nsize == DTRACEOPT_UNSET || nsize == 0) continue; if (nsize >= bufs[i].val - sizeof (uint64_t)) continue; for (; (INT64_C(1) << mul) <= nsize; j++, mul += 10) continue; if (!(nsize & ((INT64_C(1) << (mul - 10)) - 1))) { error("%s lowered to %lld%c\n", bufs[i].name, (long long)nsize >> (mul - 10), " kmgtpe"[j]); } else { error("%s lowered to %lld bytes\n", bufs[i].name, (long long)nsize); } } for (i = 0; rates[i].name != NULL; i++) { dtrace_optval_t nval; char *dir; if (rates[i].val == DTRACEOPT_UNSET) continue; (void) dtrace_getopt(g_dtp, rates[i].optname, &nval); if (nval == DTRACEOPT_UNSET || nval == 0) continue; if (rates[i].val == nval) continue; dir = nval > rates[i].val ? "reduced" : "increased"; if (nval <= NANOSEC && (NANOSEC % nval) == 0) { error("%s %s to %lld hz\n", rates[i].name, dir, (long long)NANOSEC / (long long)nval); continue; } if ((nval % NANOSEC) == 0) { error("%s %s to once every %lld seconds\n", rates[i].name, dir, (long long)nval / (long long)NANOSEC); continue; } error("%s %s to once every %lld nanoseconds\n", rates[i].name, dir, (long long)nval); } } /*ARGSUSED*/ static void intr(int signo) { if (!g_intr) g_newline = 1; if (g_intr++) g_impatient = 1; } #ifdef __FreeBSD__ static void siginfo(int signo __unused) { g_siginfo++; g_newline = 1; } #endif static void installsighands(void) { struct sigaction act, oact; (void) sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = intr; if (sigaction(SIGINT, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) (void) sigaction(SIGINT, &act, NULL); if (sigaction(SIGTERM, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) (void) sigaction(SIGTERM, &act, NULL); #ifdef __FreeBSD__ if (sigaction(SIGPIPE, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) (void) sigaction(SIGPIPE, &act, NULL); if (sigaction(SIGUSR1, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) (void) sigaction(SIGUSR1, &act, NULL); act.sa_handler = siginfo; if (sigaction(SIGINFO, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN) (void) sigaction(SIGINFO, &act, NULL); #endif } int main(int argc, char *argv[]) { dtrace_bufdesc_t buf; dtrace_status_t status[2]; dtrace_optval_t opt; dtrace_cmd_t *dcp; g_ofp = stdout; int done = 0, mode = 0; int err, i, c, new_argc, libxo_specified; int print_upon_exit = 0; char *p, **v; struct ps_prochandle *P; pid_t pid; #ifdef __FreeBSD__ /* For %'d and the like. */ (void) setlocale(LC_NUMERIC, ""); /* For %T. */ (void) setlocale(LC_TIME, ""); #endif g_pname = basename(argv[0]); if (argc == 1) return (usage(stderr)); if ((g_argv = malloc(sizeof (char *) * argc)) == NULL || (g_cmdv = malloc(sizeof (dtrace_cmd_t) * argc)) == NULL || (g_psv = malloc(sizeof (struct ps_prochandle *) * argc)) == NULL) fatal("failed to allocate memory for arguments"); new_argc = xo_parse_args(argc, argv); if (new_argc < 0) return (usage(stderr)); if (new_argc != argc) libxo_specified = 1; argc = new_argc; g_argv[g_argc++] = argv[0]; /* propagate argv[0] to D as $0/$$0 */ argv[0] = g_pname; /* rewrite argv[0] for getopt errors */ bzero(status, sizeof (status)); bzero(&buf, sizeof (buf)); /* * Make an initial pass through argv[] processing any arguments that * affect our behavior mode (g_mode) and flags used for dtrace_open(). * We also accumulate arguments that are not affiliated with getopt * options into g_argv[], and abort if any invalid options are found. */ for (optind = 1; optind < argc; optind++) { while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) { switch (c) { case '3': if (strcmp(optarg, "2") != 0) { (void) fprintf(stderr, "%s: illegal option -- 3%s\n", argv[0], optarg); return (usage(stderr)); } - g_oflags &= ~DTRACE_O_LP64; + g_oflags &= ~DTRACE_O_MODEL_MASK; g_oflags |= DTRACE_O_ILP32; break; case '6': if (strcmp(optarg, "4") != 0) { (void) fprintf(stderr, "%s: illegal option -- 6%s\n", argv[0], optarg); return (usage(stderr)); } - g_oflags &= ~DTRACE_O_ILP32; + g_oflags &= ~DTRACE_O_MODEL_MASK; g_oflags |= DTRACE_O_LP64; break; case 'a': g_grabanon++; /* also checked in pass 2 below */ break; case 'A': g_mode = DMODE_ANON; g_exec = 0; mode++; break; case 'e': g_exec = 0; done = 1; break; case 'h': g_mode = DMODE_HEADER; g_oflags |= DTRACE_O_NODEV; g_cflags |= DTRACE_C_ZDEFS; /* -h implies -Z */ g_exec = 0; mode++; break; case 'G': g_mode = DMODE_LINK; g_oflags |= DTRACE_O_NODEV; g_cflags |= DTRACE_C_ZDEFS; /* -G implies -Z */ g_exec = 0; mode++; break; case 'l': g_mode = DMODE_LIST; g_cflags |= DTRACE_C_ZDEFS; /* -l implies -Z */ mode++; break; case 'V': g_mode = DMODE_VERS; mode++; break; default: if (strchr(DTRACE_OPTSTR, c) == NULL) return (usage(stderr)); } } if (optind < argc) g_argv[g_argc++] = argv[optind]; } if (mode > 1) { (void) fprintf(stderr, "%s: only one of the [-AGhlV] options " "can be specified at a time\n", g_pname); return (E_USAGE); } if (g_mode == DMODE_VERS) return (printf("%s: %s\n", g_pname, _dtrace_version) <= 0); /* * If we're in linker mode and the data model hasn't been specified, * we try to guess the appropriate setting by examining the object * files. We ignore certain errors since we'll catch them later when * we actually process the object files. */ - if (g_mode == DMODE_LINK && - (g_oflags & (DTRACE_O_ILP32 | DTRACE_O_LP64)) == 0 && + if (g_mode == DMODE_LINK && (g_oflags & DTRACE_O_MODEL_MASK) == 0 && elf_version(EV_CURRENT) != EV_NONE) { int fd; Elf *elf; GElf_Ehdr ehdr; for (i = 1; i < g_argc; i++) { if ((fd = open64(g_argv[i], O_RDONLY)) == -1) break; if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { (void) close(fd); break; } if (elf_kind(elf) != ELF_K_ELF || gelf_getehdr(elf, &ehdr) == NULL) { (void) close(fd); (void) elf_end(elf); break; } (void) close(fd); (void) elf_end(elf); if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) { if (g_oflags & DTRACE_O_ILP32) { fatal("can't mix 32-bit and 64-bit " "object files\n"); } g_oflags |= DTRACE_O_LP64; } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) { if (g_oflags & DTRACE_O_LP64) { fatal("can't mix 32-bit and 64-bit " "object files\n"); } g_oflags |= DTRACE_O_ILP32; } else { break; } } } /* * Open libdtrace. If we are not actually going to be enabling any * instrumentation attempt to reopen libdtrace using DTRACE_O_NODEV. */ while ((g_dtp = dtrace_open(DTRACE_VERSION, g_oflags, &err)) == NULL) { if (!(g_oflags & DTRACE_O_NODEV) && !g_exec && !g_grabanon) { g_oflags |= DTRACE_O_NODEV; continue; } fatal("failed to initialize dtrace: %s\n", dtrace_errmsg(NULL, err)); } #if defined(__i386__) /* XXX The 32-bit seems to need more buffer space by default -sson */ (void) dtrace_setopt(g_dtp, "bufsize", "12m"); (void) dtrace_setopt(g_dtp, "aggsize", "12m"); #else (void) dtrace_setopt(g_dtp, "bufsize", "4m"); (void) dtrace_setopt(g_dtp, "aggsize", "4m"); #endif (void) dtrace_setopt(g_dtp, "temporal", "yes"); /* * If -G is specified, enable -xlink=dynamic and -xunodefs to permit * references to undefined symbols to remain as unresolved relocations. * If -A is specified, enable -xlink=primary to permit static linking * only to kernel symbols that are defined in a primary kernel module. */ if (g_mode == DMODE_LINK) { (void) dtrace_setopt(g_dtp, "linkmode", "dynamic"); (void) dtrace_setopt(g_dtp, "unodefs", NULL); /* * Use the remaining arguments as the list of object files * when in linker mode. */ g_objc = g_argc - 1; g_objv = g_argv + 1; /* * We still use g_argv[0], the name of the executable. */ g_argc = 1; } else if (g_mode == DMODE_ANON) (void) dtrace_setopt(g_dtp, "linkmode", "primary"); if (libxo_specified) dtrace_oformat_configure(g_dtp); /* * Now that we have libdtrace open, make a second pass through argv[] * to perform any dtrace_setopt() calls and change any compiler flags. * We also accumulate any program specifications into our g_cmdv[] at * this time; these will compiled as part of the fourth processing pass. */ for (optind = 1; optind < argc; optind++) { while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) { switch (c) { case 'a': if (dtrace_setopt(g_dtp, "grabanon", 0) != 0) dfatal("failed to set -a"); break; case 'b': if (dtrace_setopt(g_dtp, "bufsize", optarg) != 0) dfatal("failed to set -b %s", optarg); break; case 'B': g_ofp = NULL; break; case 'C': g_cflags |= DTRACE_C_CPP; break; case 'd': g_cflags |= DTRACE_C_SUGAR; break; case 'D': if (dtrace_setopt(g_dtp, "define", optarg) != 0) dfatal("failed to set -D %s", optarg); break; case 'f': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_FUNC; dcp->dc_arg = optarg; break; case 'F': if (dtrace_setopt(g_dtp, "flowindent", 0) != 0) dfatal("failed to set -F"); break; case 'H': if (dtrace_setopt(g_dtp, "cpphdrs", 0) != 0) dfatal("failed to set -H"); break; case 'i': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_NAME; dcp->dc_arg = optarg; break; case 'I': if (dtrace_setopt(g_dtp, "incdir", optarg) != 0) dfatal("failed to set -I %s", optarg); break; case 'L': if (dtrace_setopt(g_dtp, "libdir", optarg) != 0) dfatal("failed to set -L %s", optarg); break; case 'm': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_MOD; dcp->dc_arg = optarg; break; case 'n': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_NAME; dcp->dc_arg = optarg; break; case 'P': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_PROVIDER; dcp->dc_arg = optarg; break; case 'O': print_upon_exit = 1; break; case 'q': if (dtrace_setopt(g_dtp, "quiet", 0) != 0) dfatal("failed to set -q"); break; case 'o': g_ofile = optarg; break; case 's': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_file; dcp->dc_spec = DTRACE_PROBESPEC_NONE; dcp->dc_arg = optarg; break; case 'S': g_cflags |= DTRACE_C_DIFV; break; case 'U': if (dtrace_setopt(g_dtp, "undef", optarg) != 0) dfatal("failed to set -U %s", optarg); break; case 'v': g_verbose++; break; case 'w': if (dtrace_setopt(g_dtp, "destructive", 0) != 0) dfatal("failed to set -w"); break; case 'x': if ((p = strchr(optarg, '=')) != NULL) *p++ = '\0'; if (dtrace_setopt(g_dtp, optarg, p) != 0) dfatal("failed to set -x %s", optarg); break; case 'X': if (dtrace_setopt(g_dtp, "stdc", optarg) != 0) dfatal("failed to set -X %s", optarg); break; case 'Z': g_cflags |= DTRACE_C_ZDEFS; break; default: if (strchr(DTRACE_OPTSTR, c) == NULL) return (usage(stderr)); } } } if (g_ofp == NULL && g_mode != DMODE_EXEC) { (void) fprintf(stderr, "%s: -B not valid in combination" " with [-AGl] options\n", g_pname); return (E_USAGE); } if (g_ofp == NULL && g_ofile != NULL) { (void) fprintf(stderr, "%s: -B not valid in combination" " with -o option\n", g_pname); return (E_USAGE); } /* * In our third pass we handle any command-line options related to * grabbing or creating victim processes. The behavior of these calls * may been affected by any library options set by the second pass. */ for (optind = 1; optind < argc; optind++) { while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) { switch (c) { case 'c': if ((v = make_argv(optarg)) == NULL) fatal("failed to allocate memory"); P = dtrace_proc_create(g_dtp, v[0], v, NULL, NULL); if (P == NULL) dfatal(NULL); /* dtrace_errmsg() only */ g_psv[g_psc++] = P; free(v); break; case 'p': errno = 0; pid = strtol(optarg, &p, 10); if (errno != 0 || p == optarg || p[0] != '\0') fatal("invalid pid: %s\n", optarg); P = dtrace_proc_grab(g_dtp, pid, 0); if (P == NULL) dfatal(NULL); /* dtrace_errmsg() only */ g_psv[g_psc++] = P; break; } } } /* * In our fourth pass we finish g_cmdv[] by calling dc_func to convert * each string or file specification into a compiled program structure. */ for (i = 0; i < g_cmdc; i++) g_cmdv[i].dc_func(&g_cmdv[i]); if (g_mode != DMODE_LIST) { if (dtrace_handle_err(g_dtp, &errhandler, NULL) == -1) dfatal("failed to establish error handler"); if (dtrace_handle_drop(g_dtp, &drophandler, NULL) == -1) dfatal("failed to establish drop handler"); if (dtrace_handle_proc(g_dtp, &prochandler, NULL) == -1) dfatal("failed to establish proc handler"); if (dtrace_handle_setopt(g_dtp, &setopthandler, NULL) == -1) dfatal("failed to establish setopt handler"); if (g_ofp == NULL && dtrace_handle_buffered(g_dtp, &bufhandler, NULL) == -1) dfatal("failed to establish buffered handler"); } (void) dtrace_getopt(g_dtp, "flowindent", &opt); g_flowindent = opt != DTRACEOPT_UNSET; (void) dtrace_getopt(g_dtp, "grabanon", &opt); g_grabanon = opt != DTRACEOPT_UNSET; (void) dtrace_getopt(g_dtp, "quiet", &opt); g_quiet = opt != DTRACEOPT_UNSET; if (dtrace_oformat(g_dtp)) { if (dtrace_setopt(g_dtp, "quiet", 0) != 0) dfatal("failed to set quiet (caused by oformat)"); } /* * Now make a fifth and final pass over the options that have been * turned into programs and saved in g_cmdv[], performing any mode- * specific processing. If g_mode is DMODE_EXEC, we will break out * of the switch() and continue on to the data processing loop. For * other modes, we will exit dtrace once mode-specific work is done. */ switch (g_mode) { case DMODE_EXEC: if (g_ofile != NULL && (g_ofp = fopen(g_ofile, "a")) == NULL) fatal("failed to open output file '%s'", g_ofile); if (dtrace_oformat(g_dtp)) dtrace_set_outfp(g_ofp); for (i = 0; i < g_cmdc; i++) exec_prog(&g_cmdv[i]); if (done && !g_grabanon) { dtrace_close(g_dtp); return (g_status); } break; case DMODE_ANON: if (g_ofile == NULL) #ifdef illumos g_ofile = "/kernel/drv/dtrace.conf"; #else /* * On FreeBSD, anonymous DOF data is written to * the DTrace DOF file. */ g_ofile = "/boot/dtrace.dof"; #endif dof_prune(g_ofile); /* strip out any old DOF directives */ #ifdef illumos etcsystem_prune(); /* string out any forceload directives */ #endif if (g_cmdc == 0) { dtrace_close(g_dtp); return (g_status); } if ((g_ofp = fopen(g_ofile, "a")) == NULL) fatal("failed to open output file '%s'", g_ofile); if (dtrace_oformat(g_dtp)) dtrace_set_outfp(g_ofp); for (i = 0; i < g_cmdc; i++) { anon_prog(&g_cmdv[i], dtrace_dof_create(g_dtp, g_cmdv[i].dc_prog, 0), i); } /* * Dump out the DOF corresponding to the error handler and the * current options as the final DOF property in the .conf file. */ anon_prog(NULL, dtrace_geterr_dof(g_dtp), i++); anon_prog(NULL, dtrace_getopt_dof(g_dtp), i++); if (fclose(g_ofp) == EOF) fatal("failed to close output file '%s'", g_ofile); /* * These messages would use notice() rather than error(), but * we don't want them suppressed when -A is run on a D program * that itself contains a #pragma D option quiet. */ error("saved anonymous enabling in %s\n", g_ofile); #ifdef __FreeBSD__ bootdof_add(); #else etcsystem_add(); error("run update_drv(1M) or reboot to enable changes\n"); #endif dtrace_close(g_dtp); return (g_status); case DMODE_LINK: if (g_cmdc == 0) { (void) fprintf(stderr, "%s: -G requires one or more " "scripts or enabling options\n", g_pname); dtrace_close(g_dtp); return (E_USAGE); } for (i = 0; i < g_cmdc; i++) link_prog(&g_cmdv[i]); if (g_cmdc > 1 && g_ofile != NULL) { char **objv = alloca(g_cmdc * sizeof (char *)); for (i = 0; i < g_cmdc; i++) objv[i] = g_cmdv[i].dc_ofile; if (dtrace_program_link(g_dtp, NULL, DTRACE_D_PROBES, g_ofile, g_cmdc, objv) != 0) dfatal(NULL); /* dtrace_errmsg() only */ } dtrace_close(g_dtp); return (g_status); case DMODE_LIST: if (g_ofile != NULL && (g_ofp = fopen(g_ofile, "a")) == NULL) fatal("failed to open output file '%s'", g_ofile); installsighands(); oprintf("%5s %10s %17s %33s %s\n", "ID", "PROVIDER", "MODULE", "FUNCTION", "NAME"); for (i = 0; i < g_cmdc; i++) list_prog(&g_cmdv[i]); if (g_cmdc == 0) (void) dtrace_probe_iter(g_dtp, NULL, list_probe, NULL); dtrace_close(g_dtp); return (g_status); case DMODE_HEADER: if (g_cmdc == 0) { (void) fprintf(stderr, "%s: -h requires one or more " "scripts or enabling options\n", g_pname); dtrace_close(g_dtp); return (E_USAGE); } if (g_ofile == NULL) { char *p; if (g_cmdc > 1) { (void) fprintf(stderr, "%s: -h requires an " "output file if multiple scripts are " "specified\n", g_pname); dtrace_close(g_dtp); return (E_USAGE); } if ((p = strrchr(g_cmdv[0].dc_arg, '.')) == NULL || strcmp(p, ".d") != 0) { (void) fprintf(stderr, "%s: -h requires an " "output file if no scripts are " "specified\n", g_pname); dtrace_close(g_dtp); return (E_USAGE); } p[0] = '\0'; /* strip .d suffix */ g_ofile = p = g_cmdv[0].dc_ofile; (void) snprintf(p, sizeof (g_cmdv[0].dc_ofile), "%s.h", basename(g_cmdv[0].dc_arg)); } if ((g_ofp = fopen(g_ofile, "w")) == NULL) fatal("failed to open header file '%s'", g_ofile); oprintf("/*\n * Generated by dtrace(1M).\n */\n\n"); if (dtrace_program_header(g_dtp, g_ofp, g_ofile) != 0 || fclose(g_ofp) == EOF) dfatal("failed to create header file %s", g_ofile); dtrace_close(g_dtp); return (g_status); } /* * If -a and -Z were not specified and no probes have been matched, no * probe criteria was specified on the command line and we abort. */ if (g_total == 0 && !g_grabanon && !(g_cflags & DTRACE_C_ZDEFS)) dfatal("no probes %s\n", g_cmdc ? "matched" : "specified"); /* * Start tracing. Once we dtrace_go(), reload any options that affect * our globals in case consuming anonymous state has changed them. */ go(); (void) dtrace_getopt(g_dtp, "flowindent", &opt); g_flowindent = opt != DTRACEOPT_UNSET; (void) dtrace_getopt(g_dtp, "grabanon", &opt); g_grabanon = opt != DTRACEOPT_UNSET; (void) dtrace_getopt(g_dtp, "quiet", &opt); g_quiet = opt != DTRACEOPT_UNSET; (void) dtrace_getopt(g_dtp, "destructive", &opt); if (opt != DTRACEOPT_UNSET) notice("allowing destructive actions\n"); installsighands(); /* * Now that tracing is active and we are ready to consume trace data, * continue any grabbed or created processes, setting them running * using the /proc control mechanism inside of libdtrace. */ for (i = 0; i < g_psc; i++) dtrace_proc_continue(g_dtp, g_psv[i]); g_pslive = g_psc; /* count for prochandler() */ dtrace_oformat_setup(g_dtp); do { if (!g_intr && !done) dtrace_sleep(g_dtp); #ifdef __FreeBSD__ /* * XXX: Supporting SIGINFO with oformat makes little sense, as * it can't really produce sensible DTrace output. * * If needed, we could support it by having an imaginary * "SIGINFO" probe that we can construct in the output but leave * it out for now. */ if (g_siginfo && !dtrace_oformat(g_dtp)) { (void)dtrace_aggregate_print(g_dtp, g_ofp, NULL); g_siginfo = 0; } #endif if (g_newline) { /* * Output a newline just to make the output look * slightly cleaner. Note that we do this even in * "quiet" mode... */ oprintf("\n"); g_newline = 0; } if (done || g_intr || (g_psc != 0 && g_pslive == 0)) { done = 1; if (dtrace_stop(g_dtp) == -1) dfatal("couldn't stop tracing"); } switch (dtrace_work(g_dtp, g_ofp, chew, chewrec, NULL)) { case DTRACE_WORKSTATUS_DONE: done = 1; break; case DTRACE_WORKSTATUS_OKAY: break; default: if (!g_impatient && dtrace_errno(g_dtp) != EINTR) dfatal("processing aborted"); } if (g_ofp != NULL && fflush(g_ofp) == EOF) clearerr(g_ofp); } while (!done); if (!dtrace_oformat(g_dtp)) oprintf("\n"); /* * Since there is no way to format a probe here and machine-readable * output makes little sense without explicitly asking for it, we print * nothing upon Ctrl-C if oformat is specified. If the user wishes to * get output upon exit, they must write an explicit dtrace:::END probe * to do so. */ if ((!g_impatient && !dtrace_oformat(g_dtp)) || (!g_impatient && print_upon_exit)) { if (dtrace_aggregate_print(g_dtp, g_ofp, NULL) == -1 && dtrace_errno(g_dtp) != EINTR) dfatal("failed to print aggregations"); } dtrace_oformat_teardown(g_dtp); dtrace_close(g_dtp); return (g_status); } diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c index 8f8d20298e4c..40200771fd4d 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c @@ -1,1763 +1,1769 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. * Copyright (c) 2012, 2016 by Delphix. All rights reserved. */ #include #ifdef illumos #include #include #else #include #include #include #endif #include #include #include #ifdef illumos #include #endif #include #include #include #include #include #include #include #define _POSIX_PTHREAD_SEMANTICS #include #undef _POSIX_PTHREAD_SEMANTICS #include #include #include #include #include #include #include #ifndef illumos #include #include #endif #if defined(__i386__) #include #endif /* * Stability and versioning definitions. These #defines are used in the tables * of identifiers below to fill in the attribute and version fields associated * with each identifier. The DT_ATTR_* macros are a convenience to permit more * concise declarations of common attributes such as Stable/Stable/Common. The * DT_VERS_* macros declare the encoded integer values of all versions used so * far. DT_VERS_LATEST must correspond to the latest version value among all * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta). * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, * and then add the new version to the _dtrace_versions[] array declared below. * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters * respectively for an explanation of these DTrace features and their values. * * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this. * All versions are assumed to strictly inherit from one another. If * we ever need to provide divergent interfaces, this will need work. */ #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \ DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON } #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \ DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \ } /* * The version number should be increased for every customer visible release * of DTrace. The major number should be incremented when a fundamental * change has been made that would affect all consumers, and would reflect * sweeping changes to DTrace or the D language. The minor number should be * incremented when a change is introduced that could break scripts that had * previously worked; for example, adding a new built-in variable could break * a script which was already using that identifier. The micro number should * be changed when introducing functionality changes or major bug fixes that * do not affect backward compatibility -- this is merely to make capabilities * easily determined from the version number. Minor bugs do not require any * modification to the version number. */ #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0) #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0) #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0) #define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1) #define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2) #define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0) #define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0) #define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1) #define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0) #define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0) #define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1) #define DT_VERS_1_6_2 DT_VERSION_NUMBER(1, 6, 2) #define DT_VERS_1_6_3 DT_VERSION_NUMBER(1, 6, 3) #define DT_VERS_1_7 DT_VERSION_NUMBER(1, 7, 0) #define DT_VERS_1_7_1 DT_VERSION_NUMBER(1, 7, 1) #define DT_VERS_1_8 DT_VERSION_NUMBER(1, 8, 0) #define DT_VERS_1_8_1 DT_VERSION_NUMBER(1, 8, 1) #define DT_VERS_1_9 DT_VERSION_NUMBER(1, 9, 0) #define DT_VERS_1_9_1 DT_VERSION_NUMBER(1, 9, 1) #define DT_VERS_1_10 DT_VERSION_NUMBER(1, 10, 0) #define DT_VERS_1_11 DT_VERSION_NUMBER(1, 11, 0) #define DT_VERS_1_12 DT_VERSION_NUMBER(1, 12, 0) #define DT_VERS_1_12_1 DT_VERSION_NUMBER(1, 12, 1) #define DT_VERS_1_13 DT_VERSION_NUMBER(1, 13, 0) #define DT_VERS_LATEST DT_VERS_1_13 #define DT_VERS_STRING "Sun D 1.13" const dt_version_t _dtrace_versions[] = { DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */ DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */ DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */ DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */ DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */ DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */ DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */ DT_VERS_1_5, /* D API 1.5 Solaris Express 7/07 */ DT_VERS_1_6, /* D API 1.6 */ DT_VERS_1_6_1, /* D API 1.6.1 */ DT_VERS_1_6_2, /* D API 1.6.2 */ DT_VERS_1_6_3, /* D API 1.6.3 */ DT_VERS_1_7, /* D API 1.7 */ DT_VERS_1_7_1, /* D API 1.7.1 */ DT_VERS_1_8, /* D API 1.8 */ DT_VERS_1_8_1, /* D API 1.8.1 */ DT_VERS_1_9, /* D API 1.9 */ DT_VERS_1_9_1, /* D API 1.9.1 */ DT_VERS_1_10, /* D API 1.10 */ DT_VERS_1_11, /* D API 1.11 */ DT_VERS_1_12, /* D API 1.12 */ DT_VERS_1_12_1, /* D API 1.12.1 */ DT_VERS_1_13, /* D API 1.13 */ 0 }; /* * Global variables that are formatted on FreeBSD based on the kernel file name. */ #ifndef illumos static char curthread_str[MAXPATHLEN]; static char intmtx_str[MAXPATHLEN]; static char threadmtx_str[MAXPATHLEN]; static char rwlock_str[MAXPATHLEN]; static char sxlock_str[MAXPATHLEN]; #endif /* * Table of global identifiers. This is used to populate the global identifier * hash when a new dtrace client open occurs. For more info see dt_ident.h. * The global identifiers that represent functions use the dt_idops_func ops * and specify the private data pointer as a prototype string which is parsed * when the identifier is first encountered. These prototypes look like ANSI * C function prototypes except that the special symbol "@" can be used as a * wildcard to represent a single parameter of any type (i.e. any dt_node_t). * The standard "..." notation can also be used to represent varargs. An empty * parameter list is taken to mean void (that is, no arguments are permitted). * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional * argument. */ static const dt_ident_t _dtrace_globals[] = { { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void *(size_t)" }, { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_args, NULL }, { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(void *, void *, size_t)" }, { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uintptr_t" }, { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void *(uintptr_t, size_t)" }, { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(uintptr_t, [size_t])" }, { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" }, { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(void *, uintptr_t, size_t)" }, { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(char *, uintptr_t, size_t)" }, { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD, { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_COMMON }, DT_VERS_1_0, #ifdef illumos &dt_idops_type, "genunix`kthread_t *" }, #else &dt_idops_type, curthread_str }, #endif { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "string(void *, int64_t)" }, { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, { "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int" }, { "execargs", DT_IDENT_SCALAR, 0, DIF_VAR_EXECARGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "void(@, ...)" }, { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint32_t(uint32_t)" }, { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint64_t(uint64_t)" }, { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint16_t(uint16_t)" }, { "getf", DT_IDENT_FUNC, 0, DIF_SUBR_GETF, DT_ATTR_STABCMN, DT_VERS_1_10, &dt_idops_func, "file_t *(int)" }, { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "gid_t" }, { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "int(const char *, const char *, [int])" }, { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN, #ifdef illumos DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" }, #else DT_VERS_1_5, &dt_idops_func, "string(in_addr_t *)" }, #endif { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN, #ifdef illumos DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" }, #else DT_VERS_1_5, &dt_idops_func, "string(struct in6_addr *)" }, #endif { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN, DT_VERS_1_5, &dt_idops_func, "string(int, void *)" }, { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, #ifdef __FreeBSD__ { "jailname", DT_IDENT_SCALAR, 0, DIF_VAR_JAILNAME, DT_ATTR_STABCMN, DT_VERS_1_13, &dt_idops_type, "string" }, { "jid", DT_IDENT_SCALAR, 0, DIF_VAR_JID, DT_ATTR_STABCMN, DT_VERS_1_13, &dt_idops_type, "int" }, #endif { "json", DT_IDENT_FUNC, 0, DIF_SUBR_JSON, DT_ATTR_STABCMN, DT_VERS_1_11, &dt_idops_func, "string(const char *, const char *)" }, { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(int64_t, [int])" }, { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_7, &dt_idops_func, "void(@, int32_t, int32_t, int32_t, int32_t, ...)" }, { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, int32_t, int32_t, ...)" }, { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "memref", DT_IDENT_FUNC, 0, DIF_SUBR_MEMREF, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "uintptr_t *(void *, size_t)" }, #ifndef illumos { "memstr", DT_IDENT_FUNC, 0, DIF_SUBR_MEMSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(void *, char, size_t)" }, #endif { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, #ifdef illumos { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(mblk_t *)" }, { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(mblk_t *)" }, { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" }, { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, #else { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, threadmtx_str }, { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, #endif { "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint32_t(uint32_t)" }, { "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint64_t(uint64_t)" }, { "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint16_t(uint16_t)" }, { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "pid_t" }, { "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "pid_t" }, { "print", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINT, DT_ATTR_STABCMN, DT_VERS_1_9, &dt_idops_func, "void(@)" }, { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "printm", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(size_t, uintptr_t *)" }, { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int(pid_t)" }, { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int()" }, { "regs", DT_IDENT_ARRAY, 0, DIF_VAR_REGS, DT_ATTR_STABCMN, DT_VERS_1_13, &dt_idops_regs, NULL }, { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "int(const char *, const char *, [int])" }, #ifdef illumos { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, #else { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, #endif { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "void" }, { "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" }, { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int()" }, { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint32_t" }, { "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN, DT_VERS_1_6, &dt_idops_func, "void(@)" }, { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, char)" }, { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(const char *)" }, { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *, const char *)" }, { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, char)" }, { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, const char *)" }, { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, const char *)" }, { "strtoll", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOLL, DT_ATTR_STABCMN, DT_VERS_1_11, &dt_idops_func, "int64_t(const char *, [int])" }, { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, int, [int])" }, { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, #ifndef illumos { "sx_isexclusive", DT_IDENT_FUNC, 0, DIF_SUBR_SX_ISEXCLUSIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, { "sx_shared_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_SHARED_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, { "sx_exclusive_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_EXCLUSIVE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, #endif { "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "void" }, { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "id_t" }, { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint64_t" }, { "tolower", DT_IDENT_FUNC, 0, DIF_SUBR_TOLOWER, DT_ATTR_STABCMN, DT_VERS_1_8, &dt_idops_func, "string(const char *)" }, { "toupper", DT_IDENT_FUNC, 0, DIF_SUBR_TOUPPER, DT_ATTR_STABCMN, DT_VERS_1_8, &dt_idops_func, "string(const char *)" }, { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, size_t, ...)" }, { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_type, "uint64_t" }, { "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uid_t" }, { "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_regs, NULL }, { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_type, "uint32_t" }, { "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint64_t" }, { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, #ifndef illumos { "cpu", DT_IDENT_SCALAR, 0, DIF_VAR_CPU, DT_ATTR_STABCMN, DT_VERS_1_6_3, &dt_idops_type, "int" }, #endif { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } }; /* * Tables of ILP32 intrinsic integer and floating-point type templates to use * to populate the dynamic "C" CTF type container. */ static const dt_intrinsic_t _dtrace_intrinsics_32[] = { { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, { NULL, { 0, 0, 0 }, 0 } }; /* * Tables of LP64 intrinsic integer and floating-point type templates to use * to populate the dynamic "C" CTF type container. */ static const dt_intrinsic_t _dtrace_intrinsics_64[] = { { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER }, { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, { NULL, { 0, 0, 0 }, 0 } }; /* * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container. * These aliases ensure that D definitions can use typical names. */ static const dt_typedef_t _dtrace_typedefs_32[] = { { "char", "int8_t" }, { "short", "int16_t" }, { "int", "int32_t" }, { "long long", "int64_t" }, { "int", "intptr_t" }, { "int", "ssize_t" }, { "unsigned char", "uint8_t" }, { "unsigned short", "uint16_t" }, { "unsigned", "uint32_t" }, { "unsigned long long", "uint64_t" }, { "unsigned char", "uchar_t" }, { "unsigned short", "ushort_t" }, { "unsigned", "uint_t" }, { "unsigned long", "ulong_t" }, { "unsigned long long", "u_longlong_t" }, { "int", "ptrdiff_t" }, { "unsigned", "uintptr_t" }, { "unsigned", "size_t" }, { "long", "id_t" }, { "long", "pid_t" }, { NULL, NULL } }; /* * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container. * These aliases ensure that D definitions can use typical names. */ static const dt_typedef_t _dtrace_typedefs_64[] = { { "char", "int8_t" }, { "short", "int16_t" }, { "int", "int32_t" }, { "long", "int64_t" }, { "long", "intptr_t" }, { "long", "ssize_t" }, { "unsigned char", "uint8_t" }, { "unsigned short", "uint16_t" }, { "unsigned", "uint32_t" }, { "unsigned long", "uint64_t" }, { "unsigned char", "uchar_t" }, { "unsigned short", "ushort_t" }, { "unsigned", "uint_t" }, { "unsigned long", "ulong_t" }, { "unsigned long long", "u_longlong_t" }, { "long", "ptrdiff_t" }, { "unsigned long", "uintptr_t" }, { "unsigned long", "size_t" }, { "int", "id_t" }, { "int", "pid_t" }, { NULL, NULL } }; /* * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[] * cache when a new dtrace client open occurs. Values are set by dtrace_open(). */ static const dt_intdesc_t _dtrace_ints_32[] = { { "int", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, { "long", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned long", NULL, CTF_ERR, 0xffffffffULL }, { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } }; /* * Tables of LP64 integer type templates used to populate the dtp->dt_ints[] * cache when a new dtrace client open occurs. Values are set by dtrace_open(). */ static const dt_intdesc_t _dtrace_ints_64[] = { { "int", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL }, { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } }; /* * Table of macro variable templates used to populate the macro identifier hash * when a new dtrace client open occurs. Values are set by dtrace_update(). */ static const dt_ident_t _dtrace_macros[] = { { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { NULL, 0, 0, 0, { 0, 0, 0 }, 0 } }; /* * Hard-wired definition string to be compiled and cached every time a new * DTrace library handle is initialized. This string should only be used to * contain definitions that should be present regardless of DTRACE_O_NOLIBS. */ static const char _dtrace_hardwire[] = "\ inline long NULL = 0; \n\ #pragma D binding \"1.0\" NULL\n\ "; /* * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV. * If DTRACE_O_NODEV is not set, we load the configuration from the kernel. * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are * relying on the fact that when running dtrace(1M), isaexec will invoke the * binary with the same bitness as the kernel, which is what we want by default * when generating our DIF. The user can override the choice using oflags. */ static const dtrace_conf_t _dtrace_conf = { DIF_VERSION, /* dtc_difversion */ DIF_DIR_NREGS, /* dtc_difintregs */ DIF_DTR_NREGS, /* dtc_diftupregs */ CTF_MODEL_NATIVE /* dtc_ctfmodel */ }; const dtrace_attribute_t _dtrace_maxattr = { DTRACE_STABILITY_MAX, DTRACE_STABILITY_MAX, DTRACE_CLASS_MAX }; const dtrace_attribute_t _dtrace_defattr = { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }; const dtrace_attribute_t _dtrace_symattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_attribute_t _dtrace_typattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_attribute_t _dtrace_prvattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_pattr_t _dtrace_prvdesc = { { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, }; #ifdef illumos const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ #else const char *_dtrace_defcpp = "cpp"; /* default cpp(1) to invoke */ const char *_dtrace_defld = "ld"; /* default ld(1) to invoke */ const char *_dtrace_defobjcopy = "objcopy"; /* default objcopy(1) to invoke */ #endif const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ #ifdef illumos const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */ #else const char *_dtrace_libdir32 = "/usr/lib32/dtrace"; const char *_dtrace_provdir = "/dev/dtrace"; /* provider directory */ #endif int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */ int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */ uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */ uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */ uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */ uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */ size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */ int _dtrace_argmax = 32; /* default maximum number of probe arguments */ int _dtrace_debug = 0; /* debug messages enabled (off) */ const char *const _dtrace_version = DT_VERS_STRING; /* API version string */ int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */ typedef struct dt_fdlist { int *df_fds; /* array of provider driver file descriptors */ uint_t df_ents; /* number of valid elements in df_fds[] */ uint_t df_size; /* size of df_fds[] */ } dt_fdlist_t; #ifdef illumos #pragma init(_dtrace_init) #else void _dtrace_init(void) __attribute__ ((constructor)); #endif void _dtrace_init(void) { _dtrace_debug = getenv("DTRACE_DEBUG") != NULL; for (; _dtrace_rdvers > 0; _dtrace_rdvers--) { if (rd_init(_dtrace_rdvers) == RD_OK) break; } #if defined(__i386__) /* make long doubles 64 bits -sson */ (void) fpsetprec(FP_PE); #endif } static dtrace_hdl_t * set_open_errno(dtrace_hdl_t *dtp, int *errp, int err) { if (dtp != NULL) dtrace_close(dtp); if (errp != NULL) *errp = err; return (NULL); } static void dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp) { dt_provmod_t *prov; char path[PATH_MAX]; int fd; #ifdef illumos struct dirent *dp, *ep; DIR *dirp; if ((dirp = opendir(_dtrace_provdir)) == NULL) return; /* failed to open directory; just skip it */ ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { if (dp->d_name[0] == '.') continue; /* skip "." and ".." */ if (dfp->df_ents == dfp->df_size) { uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; int *fds = realloc(dfp->df_fds, size * sizeof (int)); if (fds == NULL) break; /* skip the rest of this directory */ dfp->df_fds = fds; dfp->df_size = size; } (void) snprintf(path, sizeof (path), "%s/%s", _dtrace_provdir, dp->d_name); if ((fd = open(path, O_RDONLY)) == -1) continue; /* failed to open driver; just skip it */ if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { free(prov); (void) close(fd); break; } (void) strcpy(prov->dp_name, dp->d_name); prov->dp_next = *provmod; *provmod = prov; dt_dprintf("opened provider %s\n", dp->d_name); dfp->df_fds[dfp->df_ents++] = fd; } (void) closedir(dirp); #else /* !illumos */ char *p; char *p1; char *p_providers = NULL; int error; size_t len = 0; /* * Loop to allocate/reallocate memory for the string of provider * names and retry: */ while(1) { /* * The first time around, get the string length. The next time, * hopefully we've allocated enough memory. */ error = sysctlbyname("debug.dtrace.providers",p_providers,&len,NULL,0); if (len == 0) /* No providers? That's strange. Where's dtrace? */ break; else if (error == 0 && p_providers == NULL) { /* * Allocate the initial memory which should be enough * unless another provider loads before we have * time to go back and get the string. */ if ((p_providers = malloc(len)) == NULL) /* How do we report errors here? */ return; } else if (error == -1 && errno == ENOMEM) { /* * The current buffer isn't large enough, so * reallocate it. We normally won't need to do this * because providers aren't being loaded all the time. */ if ((p = realloc(p_providers,len)) == NULL) { free(p_providers); /* How do we report errors here? */ return; } p_providers = p; } else break; } /* Check if we got a string of provider names: */ if (error == 0 && len > 0 && p_providers != NULL) { p = p_providers; /* * Parse the string containing the space separated * provider names. */ while ((p1 = strsep(&p," ")) != NULL) { if (dfp->df_ents == dfp->df_size) { uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; int *fds = realloc(dfp->df_fds, size * sizeof (int)); if (fds == NULL) break; dfp->df_fds = fds; dfp->df_size = size; } (void) snprintf(path, sizeof (path), "/dev/dtrace/%s", p1); if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) continue; /* failed to open driver; just skip it */ if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || (prov->dp_name = malloc(strlen(p1) + 1)) == NULL) { free(prov); (void) close(fd); break; } (void) strcpy(prov->dp_name, p1); prov->dp_next = *provmod; *provmod = prov; dt_dprintf("opened provider %s\n", p1); dfp->df_fds[dfp->df_ents++] = fd; } } if (p_providers != NULL) free(p_providers); #endif /* illumos */ } static void dt_provmod_destroy(dt_provmod_t **provmod) { dt_provmod_t *next, *current; for (current = *provmod; current != NULL; current = next) { next = current->dp_next; free(current->dp_name); free(current); } *provmod = NULL; } #ifdef illumos static const char * dt_get_sysinfo(int cmd, char *buf, size_t len) { ssize_t rv = sysinfo(cmd, buf, len); char *p = buf; if (rv < 0 || rv > len) (void) snprintf(buf, len, "%s", "Unknown"); while ((p = strchr(p, '.')) != NULL) *p++ = '_'; return (buf); } #endif static dtrace_hdl_t * dt_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) { dtrace_hdl_t *dtp = NULL; int dtfd = -1, ftfd = -1, fterr = 0; dtrace_prog_t *pgp; dt_module_t *dmp; dt_provmod_t *provmod = NULL; int i, err; struct rlimit rl; const dt_intrinsic_t *dinp; const dt_typedef_t *dtyp; const dt_ident_t *idp; dtrace_typeinfo_t dtt; ctf_funcinfo_t ctc; ctf_arinfo_t ctr; dt_fdlist_t df = { NULL, 0, 0 }; char isadef[32], utsdef[32]; char s1[64], s2[64]; if (version <= 0) return (set_open_errno(dtp, errp, EINVAL)); if (version > DTRACE_VERSION) return (set_open_errno(dtp, errp, EDT_VERSION)); if (version < DTRACE_VERSION) { /* * Currently, increasing the library version number is used to * denote a binary incompatible change. That is, a consumer * of the library cannot run on a version of the library with * a higher DTRACE_VERSION number than the consumer compiled * against. Once the library API has been committed to, * backwards binary compatibility will be required; at that * time, this check should change to return EDT_OVERSION only * if the specified version number is less than the version * number at the time of interface commitment. */ return (set_open_errno(dtp, errp, EDT_OVERSION)); } if (flags & ~DTRACE_O_MASK) return (set_open_errno(dtp, errp, EINVAL)); - if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) + switch (flags & DTRACE_O_MODEL_MASK) { + case 0: /* native model */ + case DTRACE_O_ILP32: + case DTRACE_O_LP64: + break; + default: return (set_open_errno(dtp, errp, EINVAL)); + } if (vector == NULL && arg != NULL) return (set_open_errno(dtp, errp, EINVAL)); if (elf_version(EV_CURRENT) == EV_NONE) return (set_open_errno(dtp, errp, EDT_ELFVERSION)); if (vector != NULL || (flags & DTRACE_O_NODEV)) goto alloc; /* do not attempt to open dtrace device */ /* * Before we get going, crank our limit on file descriptors up to the * hard limit. This is to allow for the fact that libproc keeps file * descriptors to objects open for the lifetime of the proc handle; * without raising our hard limit, we would have an acceptably small * bound on the number of processes that we could concurrently * instrument with the pid provider. */ if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { rl.rlim_cur = rl.rlim_max; (void) setrlimit(RLIMIT_NOFILE, &rl); } /* * Get the device path of each of the providers. We hold them open * in the df.df_fds list until we open the DTrace driver itself, * allowing us to see all of the probes provided on this system. Once * we have the DTrace driver open, we can safely close all the providers * now that they have registered with the framework. */ dt_provmod_open(&provmod, &df); dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC); err = dtfd == -1 ? errno : 0; /* save errno from opening dtfd */ #if defined(__FreeBSD__) /* * Automatically load the 'dtraceall' module if we couldn't open the * char device. */ if (err == ENOENT && modfind("dtraceall") < 0) { kldload("dtraceall"); /* ignore the error */ #if __SIZEOF_LONG__ == 8 if (modfind("linux64elf") >= 0) kldload("systrace_linux"); if (modfind("linuxelf") >= 0) kldload("systrace_linux32"); #else if (modfind("linuxelf") >= 0) kldload("systrace_linux"); #endif dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC); err = errno; } #endif #ifdef illumos ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR); #else ftfd = open("/dev/dtrace/fasttrap", O_RDWR | O_CLOEXEC); #endif fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ while (df.df_ents-- != 0) (void) close(df.df_fds[df.df_ents]); free(df.df_fds); /* * If we failed to open the dtrace device, fail dtrace_open(). * We convert some kernel errnos to custom libdtrace errnos to * improve the resulting message from the usual strerror(). */ if (dtfd == -1) { dt_provmod_destroy(&provmod); switch (err) { case ENOENT: err = EDT_NOENT; break; case EBUSY: err = EDT_BUSY; break; case EACCES: err = EDT_ACCESS; break; } return (set_open_errno(dtp, errp, err)); } alloc: if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) { dt_provmod_destroy(&provmod); return (set_open_errno(dtp, errp, EDT_NOMEM)); } bzero(dtp, sizeof (dtrace_hdl_t)); dtp->dt_oflags = flags; #ifdef illumos dtp->dt_prcmode = DT_PROC_STOP_PREINIT; #else dtp->dt_prcmode = DT_PROC_STOP_POSTINIT; #endif dtp->dt_linkmode = DT_LINK_KERNEL; dtp->dt_linktype = DT_LTYP_ELF; dtp->dt_xlatemode = DT_XL_STATIC; dtp->dt_stdcmode = DT_STDC_XA; dtp->dt_encoding = DT_ENCODING_UNSET; dtp->dt_version = version; dtp->dt_fd = dtfd; dtp->dt_ftfd = ftfd; dtp->dt_kinstfd = -1; dtp->dt_fterr = fterr; dtp->dt_cdefs_fd = -1; dtp->dt_ddefs_fd = -1; #ifdef illumos dtp->dt_stdout_fd = -1; #else dtp->dt_freopen_fp = NULL; #endif dtp->dt_modbuckets = _dtrace_strbuckets; dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); #ifdef __FreeBSD__ dtp->dt_kmods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); #endif dtp->dt_provbuckets = _dtrace_strbuckets; dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); dt_proc_init(dtp); dtp->dt_vmax = DT_VERS_LATEST; dtp->dt_cpp_path = strdup(_dtrace_defcpp); dtp->dt_cpp_argv = malloc(sizeof (char *)); dtp->dt_cpp_argc = 1; dtp->dt_cpp_args = 1; dtp->dt_ld_path = strdup(_dtrace_defld); #ifdef __FreeBSD__ dtp->dt_objcopy_path = strdup(_dtrace_defobjcopy); #endif dtp->dt_provmod = provmod; dtp->dt_vector = vector; dtp->dt_varg = arg; dt_dof_init(dtp); (void) uname(&dtp->dt_uts); if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || dtp->dt_procs == NULL || dtp->dt_proc_env == NULL || dtp->dt_ld_path == NULL || dtp->dt_cpp_path == NULL || #ifdef __FreeBSD__ dtp->dt_kmods == NULL || dtp->dt_objcopy_path == NULL || #endif dtp->dt_cpp_argv == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); for (i = 0; i < DTRACEOPT_MAX; i++) dtp->dt_options[i] = DTRACEOPT_UNSET; dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); #ifdef illumos (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", (uint_t)(sizeof (void *) * NBBY)); (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || dt_cpp_add_arg(dtp, "-D__unix") == NULL || dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || dt_cpp_add_arg(dtp, isadef) == NULL || dt_cpp_add_arg(dtp, utsdef) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); #endif if (flags & DTRACE_O_NODEV) bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) return (set_open_errno(dtp, errp, errno)); if (flags & DTRACE_O_LP64) dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; else if (flags & DTRACE_O_ILP32) dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; #ifdef __sparc /* * On SPARC systems, __sparc is always defined for * and __sparcv9 is defined if we are doing a 64-bit compile. */ if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); #endif #ifdef illumos #ifdef __x86 /* * On x86 systems, __i386 is defined for for 32-bit * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, * they are defined exclusive of one another (see PSARC 2004/619). */ if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } else { if (dt_cpp_add_arg(dtp, "-D__i386") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } #endif #else #if defined(__amd64__) || defined(__i386__) if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { if (dt_cpp_add_arg(dtp, "-m64") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } else { if (dt_cpp_add_arg(dtp, "-m32") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } #endif #endif if (dtp->dt_conf.dtc_difversion < DIF_VERSION) return (set_open_errno(dtp, errp, EDT_DIFVERS)); if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); else bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); /* * On FreeBSD the kernel module name can't be hard-coded. The * 'kern.bootfile' sysctl value tells us exactly which file is being * used as the kernel. */ #ifndef illumos { char bootfile[MAXPATHLEN]; char *p; int i; size_t len = sizeof(bootfile); /* This call shouldn't fail, but use a default just in case. */ if (sysctlbyname("kern.bootfile", bootfile, &len, NULL, 0) != 0) strlcpy(bootfile, "kernel", sizeof(bootfile)); if ((p = strrchr(bootfile, '/')) != NULL) p++; else p = bootfile; /* * Format the global variables based on the kernel module name. */ snprintf(curthread_str, sizeof(curthread_str), "%s`struct thread *",p); snprintf(intmtx_str, sizeof(intmtx_str), "int(%s`struct mtx *)",p); snprintf(threadmtx_str, sizeof(threadmtx_str), "struct thread *(%s`struct mtx *)",p); snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`struct rwlock *)",p); snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sx *)",p); } #endif dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); dtp->dt_aggs = dt_idhash_create("aggregation", NULL, DTRACE_AGGVARIDNONE + 1, UINT_MAX); dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); dtp->dt_tls = dt_idhash_create("thread local", NULL, DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || dtp->dt_globals == NULL || dtp->dt_tls == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); /* * Populate the dt_macros identifier hash table by hand: we can't use * the dt_idhash_populate() mechanism because we're not yet compiling * and dtrace_update() needs to immediately reference these idents. */ for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { if (dt_idhash_insert(dtp->dt_macros, idp->di_name, idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, idp->di_iarg, 0) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } /* * Update the module list using /system/object and load the values for * the macro variable definitions according to the current process. */ dtrace_update(dtp); /* * Select the intrinsics and typedefs we want based on the data model. * The intrinsics are under "C". The typedefs are added under "D". */ if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { dinp = _dtrace_intrinsics_32; dtyp = _dtrace_typedefs_32; } else { dinp = _dtrace_intrinsics_64; dtyp = _dtrace_typedefs_64; } /* * Create a dynamic CTF container under the "C" scope for intrinsic * types and types defined in ANSI-C header files that are included. */ if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) return (set_open_errno(dtp, errp, EDT_CTF)); dt_dprintf("created CTF container for %s (%p)\n", dmp->dm_name, (void *)dmp->dm_ctfp); (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); ctf_setspecific(dmp->dm_ctfp, dmp); dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ dmp->dm_modid = -1; /* no module ID */ /* * Fill the dynamic "C" CTF container with all of the intrinsic * integer and floating-point types appropriate for this data model. */ for (; dinp->din_name != NULL; dinp++) { if (dinp->din_kind == CTF_K_INTEGER) { err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, dinp->din_name, &dinp->din_data); } else { err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, dinp->din_name, &dinp->din_data); } if (err == CTF_ERR) { dt_dprintf("failed to add %s to C container: %s\n", dinp->din_name, ctf_errmsg( ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } } if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed to update C container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Add intrinsic pointer types that are needed to initialize printf * format dictionary types (see table in dt_printf.c). */ (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "void")); (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "char")); (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "int")); if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed to update C container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Create a dynamic CTF container under the "D" scope for types that * are defined by the D program itself or on-the-fly by the D compiler. * The "D" CTF container is a child of the "C" CTF container. */ if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) return (set_open_errno(dtp, errp, EDT_CTF)); dt_dprintf("created CTF container for %s (%p)\n", dmp->dm_name, (void *)dmp->dm_ctfp); (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); ctf_setspecific(dmp->dm_ctfp, dmp); dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ dmp->dm_modid = -1; /* no module ID */ if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { dt_dprintf("failed to import D parent container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Fill the dynamic "D" CTF container with all of the built-in typedefs * that we need to use for our D variable and function definitions. * This ensures that basic inttypes.h names are always available to us. */ for (; dtyp->dty_src != NULL; dtyp++) { if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, dtyp->dty_src)) == CTF_ERR) { dt_dprintf("failed to add typedef %s %s to D " "container: %s\n", dtyp->dty_src, dtyp->dty_dst, ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } } /* * Insert a CTF ID corresponding to a pointer to a type of kind * CTF_K_FUNCTION we can use in the compiler for function pointers. * CTF treats all function pointers as "int (*)()" so we only need one. */ ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); ctc.ctc_argc = 0; ctc.ctc_flags = 0; dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, CTF_ADD_ROOT, &ctc, NULL); dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, dtp->dt_type_func); /* * We also insert CTF definitions for the special D intrinsic types * string and into the D container. The string type is added * as a typedef of char[n]. The type is an alias for void. * We compare types to these special CTF ids throughout the compiler. */ ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); ctr.ctr_nelems = _dtrace_strsize; dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR || dtp->dt_type_usymaddr == CTF_ERR) { dt_dprintf("failed to add intrinsic to D container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed update D container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Initialize the integer description table used to convert integer * constants to the appropriate types. Refer to the comments above * dt_node_int() for a complete description of how this table is used. */ for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, dtp->dt_ints[i].did_name, &dtt) != 0) { dt_dprintf("failed to lookup integer type %s: %s\n", dtp->dt_ints[i].did_name, dtrace_errmsg(dtp, dtrace_errno(dtp))); return (set_open_errno(dtp, errp, dtp->dt_errno)); } dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; dtp->dt_ints[i].did_type = dtt.dtt_type; } /* * Now that we've created the "C" and "D" containers, move them to the * start of the module list so that these types and symbols are found * first (for stability) when iterating through the module list. */ dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); if (dt_pfdict_create(dtp) == -1) return (set_open_errno(dtp, errp, dtp->dt_errno)); /* * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default * because without /dev/dtrace open, we will not be able to load the * names and attributes of any providers or probes from the kernel. */ if (flags & DTRACE_O_NODEV) dtp->dt_cflags |= DTRACE_C_ZDEFS; /* * Load hard-wired inlines into the definition cache by calling the * compiler on the raw definition string defined above. */ if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { dt_dprintf("failed to load hard-wired definitions: %s\n", dtrace_errmsg(dtp, dtrace_errno(dtp))); return (set_open_errno(dtp, errp, EDT_HARDWIRE)); } dt_program_destroy(dtp, pgp); /* * Set up the default DTrace library path. Once set, the next call to * dt_compile() will compile all the libraries. We intentionally defer * library processing to improve overhead for clients that don't ever * compile, and to provide better error reporting (because the full * reporting of compiler errors requires dtrace_open() to succeed). */ #ifdef __FreeBSD__ #ifdef __LP64__ if ((dtp->dt_oflags & DTRACE_O_ILP32) != 0) { if (dtrace_setopt(dtp, "libdir", _dtrace_libdir32) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); } #endif if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); #else if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); #endif return (dtp); } dtrace_hdl_t * dtrace_open(int version, int flags, int *errp) { return (dt_vopen(version, flags, errp, NULL, NULL)); } dtrace_hdl_t * dtrace_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) { return (dt_vopen(version, flags, errp, vector, arg)); } void dtrace_close(dtrace_hdl_t *dtp) { dt_ident_t *idp, *ndp; dt_module_t *dmp; dt_provider_t *pvp; dtrace_prog_t *pgp; dt_xlator_t *dxp; dt_dirpath_t *dirp; #ifdef __FreeBSD__ dt_kmodule_t *dkm; uint_t h; #endif int i; if (dtp->dt_procs != NULL) dt_proc_fini(dtp); while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) dt_program_destroy(dtp, pgp); while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) dt_xlator_destroy(dtp, dxp); dt_free(dtp, dtp->dt_xlatormap); for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { ndp = idp->di_next; dt_ident_destroy(idp); } if (dtp->dt_macros != NULL) dt_idhash_destroy(dtp->dt_macros); if (dtp->dt_aggs != NULL) dt_idhash_destroy(dtp->dt_aggs); if (dtp->dt_globals != NULL) dt_idhash_destroy(dtp->dt_globals); if (dtp->dt_tls != NULL) dt_idhash_destroy(dtp->dt_tls); #ifdef __FreeBSD__ for (h = 0; h < dtp->dt_modbuckets; h++) while ((dkm = dtp->dt_kmods[h]) != NULL) { dtp->dt_kmods[h] = dkm->dkm_next; free(dkm->dkm_name); free(dkm); } #endif while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) dt_module_destroy(dtp, dmp); while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) dt_provider_destroy(dtp, pvp); if (dtp->dt_fd != -1) (void) close(dtp->dt_fd); if (dtp->dt_ftfd != -1) (void) close(dtp->dt_ftfd); if (dtp->dt_kinstfd != -1) (void) close(dtp->dt_kinstfd); if (dtp->dt_cdefs_fd != -1) (void) close(dtp->dt_cdefs_fd); if (dtp->dt_ddefs_fd != -1) (void) close(dtp->dt_ddefs_fd); #ifdef illumos if (dtp->dt_stdout_fd != -1) (void) close(dtp->dt_stdout_fd); #else if (dtp->dt_freopen_fp != NULL) (void) fclose(dtp->dt_freopen_fp); #endif dt_epid_destroy(dtp); dt_aggid_destroy(dtp); dt_format_destroy(dtp); dt_strdata_destroy(dtp); dt_buffered_destroy(dtp); dt_aggregate_destroy(dtp); dt_pfdict_destroy(dtp); dt_provmod_destroy(&dtp->dt_provmod); dt_dof_fini(dtp); for (i = 1; i < dtp->dt_cpp_argc; i++) free(dtp->dt_cpp_argv[i]); while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { dt_list_delete(&dtp->dt_lib_path, dirp); free(dirp->dir_path); free(dirp); } free(dtp->dt_cpp_argv); free(dtp->dt_cpp_path); free(dtp->dt_ld_path); #ifdef __FreeBSD__ free(dtp->dt_objcopy_path); #endif free(dtp->dt_mods); #ifdef __FreeBSD__ free(dtp->dt_kmods); #endif free(dtp->dt_provs); xo_finish(); free(dtp); } int dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) { dt_provmod_t *prov; int i = 0; for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { if (i < nmods) mods[i] = prov->dp_name; } return (i); } int dtrace_ctlfd(dtrace_hdl_t *dtp) { return (dtp->dt_fd); } diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h index b380f5eb3313..1f4c5a2efd6b 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h @@ -1,641 +1,642 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2023 by Domagoj Stolfa. All rights reserved. * Copyright (c) 2014, 2016 by Delphix. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ #ifndef _DTRACE_H #define _DTRACE_H #include #include #include #include #include #ifndef illumos #include #endif #ifdef __cplusplus extern "C" { #endif /* * DTrace Dynamic Tracing Software: Library Interfaces * * Note: The contents of this file are private to the implementation of the * Solaris system and DTrace subsystem and are subject to change at any time * without notice. Applications and drivers using these interfaces will fail * to run on future releases. These interfaces should not be used for any * purpose except those expressly outlined in dtrace(7D) and libdtrace(3LIB). * Please refer to the "Solaris Dynamic Tracing Guide" for more information. */ #define DTRACE_VERSION 3 /* library ABI interface version */ struct ps_prochandle; struct dt_node; typedef struct dtrace_hdl dtrace_hdl_t; typedef struct dtrace_prog dtrace_prog_t; typedef struct dtrace_vector dtrace_vector_t; typedef struct dtrace_aggdata dtrace_aggdata_t; #define DTRACE_O_NODEV 0x01 /* do not open dtrace(7D) device */ #define DTRACE_O_NOSYS 0x02 /* do not load /system/object modules */ #define DTRACE_O_LP64 0x04 /* force D compiler to be LP64 */ #define DTRACE_O_ILP32 0x08 /* force D compiler to be ILP32 */ +#define DTRACE_O_MODEL_MASK (DTRACE_O_LP64 | DTRACE_O_ILP32) #define DTRACE_O_MASK 0x0f /* mask of valid flags to dtrace_open */ extern dtrace_hdl_t *dtrace_open(int, int, int *); extern dtrace_hdl_t *dtrace_vopen(int, int, int *, const dtrace_vector_t *, void *); extern int dtrace_go(dtrace_hdl_t *); extern int dtrace_stop(dtrace_hdl_t *); extern void dtrace_sleep(dtrace_hdl_t *); extern void dtrace_close(dtrace_hdl_t *); extern int dtrace_errno(dtrace_hdl_t *); extern const char *dtrace_errmsg(dtrace_hdl_t *, int); extern const char *dtrace_faultstr(dtrace_hdl_t *, int); extern const char *dtrace_subrstr(dtrace_hdl_t *, int); extern int dtrace_setopt(dtrace_hdl_t *, const char *, const char *); extern int dtrace_getopt(dtrace_hdl_t *, const char *, dtrace_optval_t *); extern void dtrace_update(dtrace_hdl_t *); extern int dtrace_ctlfd(dtrace_hdl_t *); /* * DTrace Program Interface * * DTrace programs can be created by compiling ASCII text files containing * D programs or by compiling in-memory C strings that specify a D program. * Once created, callers can examine the list of program statements and * enable the probes and actions described by these statements. */ typedef struct dtrace_proginfo { dtrace_attribute_t dpi_descattr; /* minimum probedesc attributes */ dtrace_attribute_t dpi_stmtattr; /* minimum statement attributes */ uint_t dpi_aggregates; /* number of aggregates specified in program */ uint_t dpi_recgens; /* number of record generating probes in prog */ uint_t dpi_matches; /* number of probes matched by program */ uint_t dpi_speculations; /* number of speculations specified in prog */ } dtrace_proginfo_t; #define DTRACE_C_DIFV 0x0001 /* DIF verbose mode: show each compiled DIFO */ #define DTRACE_C_EMPTY 0x0002 /* Permit compilation of empty D source files */ #define DTRACE_C_ZDEFS 0x0004 /* Permit probe defs that match zero probes */ #define DTRACE_C_EATTR 0x0008 /* Error if program attributes less than min */ #define DTRACE_C_CPP 0x0010 /* Preprocess input file with cpp(1) utility */ #define DTRACE_C_KNODEF 0x0020 /* Permit unresolved kernel symbols in DIFO */ #define DTRACE_C_UNODEF 0x0040 /* Permit unresolved user symbols in DIFO */ #define DTRACE_C_PSPEC 0x0080 /* Interpret ambiguous specifiers as probes */ #define DTRACE_C_ETAGS 0x0100 /* Prefix error messages with error tags */ #define DTRACE_C_ARGREF 0x0200 /* Do not require all macro args to be used */ #define DTRACE_C_SUGAR 0x0400 /* Dump D script post-dt_sugar */ #define DTRACE_C_DEFARG 0x0800 /* Use 0/"" as value for unspecified args */ #define DTRACE_C_NOLIBS 0x1000 /* Do not process D system libraries */ #define DTRACE_C_CTL 0x2000 /* Only process control directives */ #define DTRACE_C_MASK 0x3fff /* mask of all valid flags to dtrace_*compile */ extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *, const char *, dtrace_probespec_t, uint_t, int, char *const []); extern dtrace_prog_t *dtrace_program_fcompile(dtrace_hdl_t *, FILE *, uint_t, int, char *const []); extern int dtrace_program_exec(dtrace_hdl_t *, dtrace_prog_t *, dtrace_proginfo_t *); extern void dtrace_program_info(dtrace_hdl_t *, dtrace_prog_t *, dtrace_proginfo_t *); #define DTRACE_D_STRIP 0x01 /* strip non-loadable sections from program */ #define DTRACE_D_PROBES 0x02 /* include provider and probe definitions */ #define DTRACE_D_MASK 0x03 /* mask of valid flags to dtrace_dof_create */ extern int dtrace_program_link(dtrace_hdl_t *, dtrace_prog_t *, uint_t, const char *, int, char *const []); extern int dtrace_program_header(dtrace_hdl_t *, FILE *, const char *); extern void *dtrace_dof_create(dtrace_hdl_t *, dtrace_prog_t *, uint_t); extern void dtrace_dof_destroy(dtrace_hdl_t *, void *); extern void *dtrace_getopt_dof(dtrace_hdl_t *); extern void *dtrace_geterr_dof(dtrace_hdl_t *); typedef struct dtrace_stmtdesc { dtrace_ecbdesc_t *dtsd_ecbdesc; /* ECB description */ dtrace_actdesc_t *dtsd_action; /* action list */ dtrace_actdesc_t *dtsd_action_last; /* last action in action list */ void *dtsd_aggdata; /* aggregation data */ void *dtsd_fmtdata; /* type-specific output data */ void *dtsd_strdata; /* type-specific string data */ void (*dtsd_callback)(void); /* callback function for EPID */ void *dtsd_data; /* callback data pointer */ dtrace_attribute_t dtsd_descattr; /* probedesc attributes */ dtrace_attribute_t dtsd_stmtattr; /* statement attributes */ } dtrace_stmtdesc_t; typedef int dtrace_stmt_f(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmtdesc_t *, void *); extern dtrace_stmtdesc_t *dtrace_stmt_create(dtrace_hdl_t *, dtrace_ecbdesc_t *); extern dtrace_actdesc_t *dtrace_stmt_action(dtrace_hdl_t *, dtrace_stmtdesc_t *); extern int dtrace_stmt_add(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmtdesc_t *); extern int dtrace_stmt_iter(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmt_f *, void *); extern void dtrace_stmt_destroy(dtrace_hdl_t *, dtrace_stmtdesc_t *); /* * DTrace Data Consumption Interface */ typedef enum { DTRACEFLOW_ENTRY, DTRACEFLOW_RETURN, DTRACEFLOW_NONE } dtrace_flowkind_t; #define DTRACE_CONSUME_ERROR -1 /* error while processing */ #define DTRACE_CONSUME_THIS 0 /* consume this probe/record */ #define DTRACE_CONSUME_NEXT 1 /* advance to next probe/rec */ #define DTRACE_CONSUME_ABORT 2 /* abort consumption */ typedef struct dtrace_probedata { dtrace_hdl_t *dtpda_handle; /* handle to DTrace library */ dtrace_eprobedesc_t *dtpda_edesc; /* enabled probe description */ dtrace_probedesc_t *dtpda_pdesc; /* probe description */ processorid_t dtpda_cpu; /* CPU for data */ caddr_t dtpda_data; /* pointer to raw data */ dtrace_flowkind_t dtpda_flow; /* flow kind */ const char *dtpda_prefix; /* recommended flow prefix */ int dtpda_indent; /* recommended flow indent */ uint64_t dtpda_timestamp; /* hrtime of snapshot */ } dtrace_probedata_t; typedef int dtrace_consume_probe_f(const dtrace_probedata_t *, void *); typedef int dtrace_consume_rec_f(const dtrace_probedata_t *, const dtrace_recdesc_t *, void *); extern int dtrace_consume(dtrace_hdl_t *, FILE *, dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *); #define DTRACE_STATUS_NONE 0 /* no status; not yet time */ #define DTRACE_STATUS_OKAY 1 /* status okay */ #define DTRACE_STATUS_EXITED 2 /* exit() was called; tracing stopped */ #define DTRACE_STATUS_FILLED 3 /* fill buffer filled; tracing stoped */ #define DTRACE_STATUS_STOPPED 4 /* tracing already stopped */ extern int dtrace_status(dtrace_hdl_t *); /* * DTrace Formatted Output Interfaces * * To format output associated with a given dtrace_stmtdesc, the caller can * invoke one of the following functions, passing the opaque dtsd_fmtdata and a * list of record descriptions. These functions return either -1 to indicate * an error, or a positive integer indicating the number of records consumed. * For anonymous enablings, the consumer can use the dtrd_format member of * the record description to obtain a format description. The dtfd_string * member of the format description may be passed to dtrace_print{fa}_create() * to create the opaque format data. */ extern void *dtrace_printf_create(dtrace_hdl_t *, const char *); extern void *dtrace_printa_create(dtrace_hdl_t *, const char *); extern size_t dtrace_printf_format(dtrace_hdl_t *, void *, char *, size_t); extern int dtrace_sprintf(dtrace_hdl_t *, FILE *, void *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_fprintf(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_fprinta(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_system(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_freopen(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); /* * Type-specific output printing * * The print() action will associate a string data record that is actually the * fully-qualified type name of the data traced by the DIFEXPR action. This is * stored in the same 'format' record from the kernel, but we know by virtue of * the fact that the action is still DIFEXPR that it is actually a reference to * plain string data. */ extern int dtrace_print(dtrace_hdl_t *, FILE *, const char *, caddr_t, size_t); extern int dtrace_format_print(dtrace_hdl_t *, FILE *, const char *, caddr_t, size_t); /* * DTrace Work Interface */ typedef enum { DTRACE_WORKSTATUS_ERROR = -1, DTRACE_WORKSTATUS_OKAY, DTRACE_WORKSTATUS_DONE } dtrace_workstatus_t; extern dtrace_workstatus_t dtrace_work(dtrace_hdl_t *, FILE *, dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *); /* * DTrace Handler Interface */ #define DTRACE_HANDLE_ABORT -1 /* abort current operation */ #define DTRACE_HANDLE_OK 0 /* handled okay; continue */ typedef struct dtrace_errdata { dtrace_hdl_t *dteda_handle; /* handle to DTrace library */ dtrace_eprobedesc_t *dteda_edesc; /* enabled probe inducing err */ dtrace_probedesc_t *dteda_pdesc; /* probe inducing error */ processorid_t dteda_cpu; /* CPU of error */ int dteda_action; /* action inducing error */ int dteda_offset; /* offset in DIFO of error */ int dteda_fault; /* specific fault */ uint64_t dteda_addr; /* address of fault, if any */ const char *dteda_msg; /* preconstructed message */ } dtrace_errdata_t; typedef int dtrace_handle_err_f(const dtrace_errdata_t *, void *); extern int dtrace_handle_err(dtrace_hdl_t *, dtrace_handle_err_f *, void *); typedef enum { DTRACEDROP_PRINCIPAL, /* drop to principal buffer */ DTRACEDROP_AGGREGATION, /* drop to aggregation buffer */ DTRACEDROP_DYNAMIC, /* dynamic drop */ DTRACEDROP_DYNRINSE, /* dyn drop due to rinsing */ DTRACEDROP_DYNDIRTY, /* dyn drop due to dirty */ DTRACEDROP_SPEC, /* speculative drop */ DTRACEDROP_SPECBUSY, /* spec drop due to busy */ DTRACEDROP_SPECUNAVAIL, /* spec drop due to unavail */ DTRACEDROP_STKSTROVERFLOW, /* stack string tab overflow */ DTRACEDROP_DBLERROR /* error in ERROR probe */ } dtrace_dropkind_t; typedef struct dtrace_dropdata { dtrace_hdl_t *dtdda_handle; /* handle to DTrace library */ processorid_t dtdda_cpu; /* CPU, if any */ dtrace_dropkind_t dtdda_kind; /* kind of drop */ uint64_t dtdda_drops; /* number of drops */ uint64_t dtdda_total; /* total drops */ const char *dtdda_msg; /* preconstructed message */ } dtrace_dropdata_t; typedef int dtrace_handle_drop_f(const dtrace_dropdata_t *, void *); extern int dtrace_handle_drop(dtrace_hdl_t *, dtrace_handle_drop_f *, void *); typedef void dtrace_handle_proc_f(struct ps_prochandle *, const char *, void *); extern int dtrace_handle_proc(dtrace_hdl_t *, dtrace_handle_proc_f *, void *); #define DTRACE_BUFDATA_AGGKEY 0x0001 /* aggregation key */ #define DTRACE_BUFDATA_AGGVAL 0x0002 /* aggregation value */ #define DTRACE_BUFDATA_AGGFORMAT 0x0004 /* aggregation format data */ #define DTRACE_BUFDATA_AGGLAST 0x0008 /* last for this key/val */ typedef struct dtrace_bufdata { dtrace_hdl_t *dtbda_handle; /* handle to DTrace library */ const char *dtbda_buffered; /* buffered output */ dtrace_probedata_t *dtbda_probe; /* probe data */ const dtrace_recdesc_t *dtbda_recdesc; /* record description */ const dtrace_aggdata_t *dtbda_aggdata; /* aggregation data, if agg. */ uint32_t dtbda_flags; /* flags; see above */ } dtrace_bufdata_t; typedef int dtrace_handle_buffered_f(const dtrace_bufdata_t *, void *); extern int dtrace_handle_buffered(dtrace_hdl_t *, dtrace_handle_buffered_f *, void *); typedef struct dtrace_setoptdata { dtrace_hdl_t *dtsda_handle; /* handle to DTrace library */ const dtrace_probedata_t *dtsda_probe; /* probe data */ const char *dtsda_option; /* option that was set */ dtrace_optval_t dtsda_oldval; /* old value */ dtrace_optval_t dtsda_newval; /* new value */ } dtrace_setoptdata_t; typedef int dtrace_handle_setopt_f(const dtrace_setoptdata_t *, void *); extern int dtrace_handle_setopt(dtrace_hdl_t *, dtrace_handle_setopt_f *, void *); /* * DTrace Aggregate Interface */ #define DTRACE_A_PERCPU 0x0001 #define DTRACE_A_KEEPDELTA 0x0002 #define DTRACE_A_ANONYMOUS 0x0004 #define DTRACE_A_TOTAL 0x0008 #define DTRACE_A_MINMAXBIN 0x0010 #define DTRACE_A_HASNEGATIVES 0x0020 #define DTRACE_A_HASPOSITIVES 0x0040 #define DTRACE_AGGZOOM_MAX 0.95 /* height of max bar */ #define DTRACE_AGGWALK_ERROR -1 /* error while processing */ #define DTRACE_AGGWALK_NEXT 0 /* proceed to next element */ #define DTRACE_AGGWALK_ABORT 1 /* abort aggregation walk */ #define DTRACE_AGGWALK_CLEAR 2 /* clear this element */ #define DTRACE_AGGWALK_NORMALIZE 3 /* normalize this element */ #define DTRACE_AGGWALK_DENORMALIZE 4 /* denormalize this element */ #define DTRACE_AGGWALK_REMOVE 5 /* remove this element */ struct dtrace_aggdata { dtrace_hdl_t *dtada_handle; /* handle to DTrace library */ dtrace_aggdesc_t *dtada_desc; /* aggregation description */ dtrace_eprobedesc_t *dtada_edesc; /* enabled probe description */ dtrace_probedesc_t *dtada_pdesc; /* probe description */ caddr_t dtada_data; /* pointer to raw data */ uint64_t dtada_normal; /* the normal -- 1 for denorm */ size_t dtada_size; /* total size of the data */ caddr_t dtada_delta; /* delta data, if available */ caddr_t *dtada_percpu; /* per CPU data, if avail */ caddr_t *dtada_percpu_delta; /* per CPU delta, if avail */ int64_t dtada_total; /* per agg total, if avail */ uint16_t dtada_minbin; /* minimum bin, if avail */ uint16_t dtada_maxbin; /* maximum bin, if avail */ uint32_t dtada_flags; /* flags */ }; typedef int dtrace_aggregate_f(const dtrace_aggdata_t *, void *); typedef int dtrace_aggregate_walk_f(dtrace_hdl_t *, dtrace_aggregate_f *, void *); typedef int dtrace_aggregate_walk_joined_f(const dtrace_aggdata_t **, const int, void *); extern void dtrace_aggregate_clear(dtrace_hdl_t *); extern int dtrace_aggregate_snap(dtrace_hdl_t *); extern int dtrace_aggregate_print(dtrace_hdl_t *, FILE *, dtrace_aggregate_walk_f *); extern int dtrace_aggregate_walk(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_joined(dtrace_hdl_t *, dtrace_aggvarid_t *, int, dtrace_aggregate_walk_joined_f *, void *); extern int dtrace_aggregate_walk_sorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keysorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyvarsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valvarsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyvarrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valvarrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); #define DTRACE_AGD_PRINTED 0x1 /* aggregation printed in program */ /* * DTrace Process Control Interface * * Library clients who wish to have libdtrace create or grab processes for * monitoring of their symbol table changes may use these interfaces to * request that libdtrace obtain control of the process using libproc. */ extern struct ps_prochandle *dtrace_proc_create(dtrace_hdl_t *, const char *, char *const *, proc_child_func *, void *); extern struct ps_prochandle *dtrace_proc_grab(dtrace_hdl_t *, pid_t, int); extern void dtrace_proc_release(dtrace_hdl_t *, struct ps_prochandle *); extern void dtrace_proc_continue(dtrace_hdl_t *, struct ps_prochandle *); /* * DTrace Object, Symbol, and Type Interfaces * * Library clients can use libdtrace to perform symbol and C type information * lookups by symbol name, symbol address, or C type name, or to lookup meta- * information cached for each of the program objects in use by DTrace. The * resulting struct contain pointers to arbitrary-length strings, including * object, symbol, and type names, that are persistent until the next call to * dtrace_update(). Once dtrace_update() is called, any cached values must * be flushed and not used subsequently by the client program. */ #define DTRACE_OBJ_EXEC ((const char *)0L) /* primary executable file */ #define DTRACE_OBJ_RTLD ((const char *)1L) /* run-time link-editor */ #define DTRACE_OBJ_CDEFS ((const char *)2L) /* C include definitions */ #define DTRACE_OBJ_DDEFS ((const char *)3L) /* D program definitions */ #define DTRACE_OBJ_EVERY ((const char *)-1L) /* all known objects */ #define DTRACE_OBJ_KMODS ((const char *)-2L) /* all kernel objects */ #define DTRACE_OBJ_UMODS ((const char *)-3L) /* all user objects */ typedef struct dtrace_objinfo { const char *dto_name; /* object file scope name */ const char *dto_file; /* object file path (if any) */ int dto_id; /* object file id (if any) */ uint_t dto_flags; /* object flags (see below) */ GElf_Addr dto_text_va; /* address of text section */ GElf_Xword dto_text_size; /* size of text section */ GElf_Addr dto_data_va; /* address of data section */ GElf_Xword dto_data_size; /* size of data section */ GElf_Addr dto_bss_va; /* address of BSS */ GElf_Xword dto_bss_size; /* size of BSS */ } dtrace_objinfo_t; #define DTRACE_OBJ_F_KERNEL 0x1 /* object is a kernel module */ #define DTRACE_OBJ_F_PRIMARY 0x2 /* object is a primary module */ typedef int dtrace_obj_f(dtrace_hdl_t *, const dtrace_objinfo_t *, void *); extern int dtrace_object_iter(dtrace_hdl_t *, dtrace_obj_f *, void *); extern int dtrace_object_info(dtrace_hdl_t *, const char *, dtrace_objinfo_t *); typedef struct dtrace_syminfo { const char *dts_object; /* object name */ const char *dts_name; /* symbol name */ ulong_t dts_id; /* symbol id */ } dtrace_syminfo_t; extern int dtrace_lookup_by_name(dtrace_hdl_t *, const char *, const char *, GElf_Sym *, dtrace_syminfo_t *); extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr, GElf_Sym *, dtrace_syminfo_t *); typedef struct dtrace_typeinfo { const char *dtt_object; /* object containing type */ ctf_file_t *dtt_ctfp; /* CTF container handle */ ctf_id_t dtt_type; /* CTF type identifier */ uint_t dtt_flags; /* Misc. flags */ } dtrace_typeinfo_t; #define DTT_FL_USER 0x1 /* user type */ extern int dtrace_lookup_by_type(dtrace_hdl_t *, const char *, const char *, dtrace_typeinfo_t *); extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *, const dtrace_syminfo_t *, dtrace_typeinfo_t *); extern int dtrace_type_strcompile(dtrace_hdl_t *, const char *, dtrace_typeinfo_t *); extern int dtrace_type_fcompile(dtrace_hdl_t *, FILE *, dtrace_typeinfo_t *); extern struct dt_node *dt_compile_sugar(dtrace_hdl_t *, struct dt_node *); /* * DTrace Probe Interface * * Library clients can use these functions to iterate over the set of available * probe definitions and inquire as to their attributes. The probe iteration * interfaces report probes that are declared as well as those from dtrace(7D). */ typedef struct dtrace_probeinfo { dtrace_attribute_t dtp_attr; /* name attributes */ dtrace_attribute_t dtp_arga; /* arg attributes */ const dtrace_typeinfo_t *dtp_argv; /* arg types */ int dtp_argc; /* arg count */ } dtrace_probeinfo_t; typedef int dtrace_probe_f(dtrace_hdl_t *, const dtrace_probedesc_t *, void *); extern int dtrace_probe_iter(dtrace_hdl_t *, const dtrace_probedesc_t *pdp, dtrace_probe_f *, void *); extern int dtrace_probe_info(dtrace_hdl_t *, const dtrace_probedesc_t *, dtrace_probeinfo_t *); /* * DTrace Vector Interface * * The DTrace library normally speaks directly to dtrace(7D). However, * this communication may be vectored elsewhere. Consumers who wish to * perform a vectored open must fill in the vector, and use the dtrace_vopen() * entry point to obtain a library handle. */ struct dtrace_vector { #ifdef illumos int (*dtv_ioctl)(void *, int, void *); #else int (*dtv_ioctl)(void *, u_long, void *); #endif int (*dtv_lookup_by_addr)(void *, GElf_Addr, GElf_Sym *, dtrace_syminfo_t *); int (*dtv_status)(void *, processorid_t); long (*dtv_sysconf)(void *, int); }; /* * DTrace Utility Functions * * Library clients can use these functions to convert addresses strings, to * convert between string and integer probe descriptions and the * dtrace_probedesc_t representation, and to perform similar conversions on * stability attributes. */ extern int dtrace_addr2str(dtrace_hdl_t *, uint64_t, char *, int); extern int dtrace_uaddr2str(dtrace_hdl_t *, pid_t, uint64_t, char *, int); extern int dtrace_xstr2desc(dtrace_hdl_t *, dtrace_probespec_t, const char *, int, char *const [], dtrace_probedesc_t *); extern int dtrace_str2desc(dtrace_hdl_t *, dtrace_probespec_t, const char *, dtrace_probedesc_t *); extern int dtrace_id2desc(dtrace_hdl_t *, dtrace_id_t, dtrace_probedesc_t *); #define DTRACE_DESC2STR_MAX 1024 /* min buf size for dtrace_desc2str() */ extern char *dtrace_desc2str(const dtrace_probedesc_t *, char *, size_t); #define DTRACE_ATTR2STR_MAX 64 /* min buf size for dtrace_attr2str() */ extern char *dtrace_attr2str(dtrace_attribute_t, char *, size_t); extern int dtrace_str2attr(const char *, dtrace_attribute_t *); extern const char *dtrace_stability_name(dtrace_stability_t); extern const char *dtrace_class_name(dtrace_class_t); extern int dtrace_provider_modules(dtrace_hdl_t *, const char **, int); extern const char *const _dtrace_version; extern int _dtrace_debug; #ifdef __cplusplus } #endif #ifndef illumos #define _SC_CPUID_MAX _SC_NPROCESSORS_CONF #define _SC_NPROCESSORS_MAX _SC_NPROCESSORS_CONF #endif /* * Values for the dt_oformat property. */ #define DTRACE_OFORMAT_TEXT 0 #define DTRACE_OFORMAT_STRUCTURED 1 extern int dtrace_oformat_configure(dtrace_hdl_t *); extern int dtrace_oformat(dtrace_hdl_t *); extern void dtrace_set_outfp(const FILE *); extern void dtrace_oformat_setup(dtrace_hdl_t *); extern void dtrace_oformat_teardown(dtrace_hdl_t *); extern void dtrace_oformat_probe(dtrace_hdl_t *, const dtrace_probedata_t *, processorid_t, dtrace_probedesc_t *); #endif /* _DTRACE_H */