VirtualBox

source: vbox/trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/dtrace.c@ 63129

Last change on this file since 63129 was 63129, checked in by vboxsync, 8 years ago

dtrace: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.8 KB
Line 
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef VBOX
28#pragma ident "%Z%%M% %I% %E% SMI"
29#endif
30
31#include <sys/types.h>
32#include <sys/stat.h>
33#ifndef _MSC_VER
34# include <sys/wait.h>
35#endif
36
37#include <dtrace.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <stdio.h>
41#ifndef VBOX
42# include <strings.h>
43#endif
44#ifndef _MSC_VER
45# include <unistd.h>
46#else
47# include <direct.h>
48# include <io.h>
49#endif
50#include <limits.h>
51#include <fcntl.h>
52#include <errno.h>
53#include <signal.h>
54#ifndef VBOX
55#include <alloca.h>
56#include <libgen.h>
57#include <libproc.h>
58#endif
59
60#ifdef VBOX
61# include <stdio.h>
62
63# include <iprt/alloca.h>
64# include <iprt/getopt.h>
65# include <iprt/initterm.h>
66# include <iprt/path.h>
67# include <iprt/message.h>
68# include <iprt/process.h>
69# include <iprt/string.h>
70
71# include "VBoxDTraceLibCWrappers.h"
72
73# ifdef _MSC_VER
74# pragma warning(disable:4267) /* size_t conversion warnings */
75# pragma warning(disable:4018) /* signed/unsigned mismatch */
76# endif
77#endif
78
79typedef struct dtrace_cmd {
80 void (*dc_func)(struct dtrace_cmd *); /* function to compile arg */
81 dtrace_probespec_t dc_spec; /* probe specifier context */
82 char *dc_arg; /* argument from main argv */
83 const char *dc_name; /* name for error messages */
84 const char *dc_desc; /* desc for error messages */
85 dtrace_prog_t *dc_prog; /* program compiled from arg */
86 char dc_ofile[PATH_MAX]; /* derived output file name */
87} dtrace_cmd_t;
88
89#define DMODE_VERS 0 /* display version information and exit (-V) */
90#define DMODE_EXEC 1 /* compile program for enabling (-a/e/E) */
91#define DMODE_ANON 2 /* compile program for anonymous tracing (-A) */
92#define DMODE_LINK 3 /* compile program for linking with ELF (-G) */
93#define DMODE_LIST 4 /* compile program and list probes (-l) */
94#define DMODE_HEADER 5 /* compile program for headergen (-h) */
95
96#define E_SUCCESS 0
97#define E_ERROR 1
98#define E_USAGE 2
99
100#ifndef VBOX
101static const char DTRACE_OPTSTR[] =
102 "3:6:aAb:Bc:CD:ef:FGhHi:I:lL:m:n:o:p:P:qs:SU:vVwx:X:Z";
103#else
104static const RTGETOPTDEF g_aOptions[] =
105{
106 { "-32", 10064, RTGETOPT_REQ_NOTHING },
107 { "-64", 10032, RTGETOPT_REQ_NOTHING },
108 { NULL, 'a', RTGETOPT_REQ_NOTHING },
109 { NULL, 'A', RTGETOPT_REQ_NOTHING },
110 { NULL, 'b', RTGETOPT_REQ_STRING },
111 { NULL, 'B', RTGETOPT_REQ_NOTHING },
112 { NULL, 'c', RTGETOPT_REQ_STRING },
113 { NULL, 'C', RTGETOPT_REQ_NOTHING },
114 { NULL, 'D', RTGETOPT_REQ_STRING },
115 { NULL, 'e', RTGETOPT_REQ_NOTHING },
116 { NULL, 'f', RTGETOPT_REQ_STRING },
117 { NULL, 'F', RTGETOPT_REQ_NOTHING },
118 { NULL, 'G', RTGETOPT_REQ_NOTHING },
119 { NULL, 'h', RTGETOPT_REQ_NOTHING },
120 { NULL, 'H', RTGETOPT_REQ_NOTHING },
121 { NULL, 'i', RTGETOPT_REQ_STRING },
122 { NULL, 'I', RTGETOPT_REQ_STRING },
123 { NULL, 'l', RTGETOPT_REQ_NOTHING },
124 { NULL, 'L', RTGETOPT_REQ_STRING },
125 { NULL, 'M', RTGETOPT_REQ_STRING },
126 { NULL, 'n', RTGETOPT_REQ_STRING },
127 { NULL, 'o', RTGETOPT_REQ_STRING },
128 { NULL, 'p', RTGETOPT_REQ_STRING },
129 { NULL, 'P', RTGETOPT_REQ_STRING },
130 { NULL, 'q', RTGETOPT_REQ_NOTHING },
131 { NULL, 's', RTGETOPT_REQ_STRING },
132 { NULL, 'S', RTGETOPT_REQ_NOTHING },
133 { NULL, 'U', RTGETOPT_REQ_STRING },
134 { NULL, 'v', RTGETOPT_REQ_NOTHING },
135 { NULL, 'V', RTGETOPT_REQ_NOTHING },
136 { NULL, 'w', RTGETOPT_REQ_NOTHING },
137 { NULL, 'x', RTGETOPT_REQ_STRING },
138 { NULL, 'X', RTGETOPT_REQ_STRING },
139 { NULL, 'Z', RTGETOPT_REQ_NOTHING },
140};
141#endif /* VBOX */
142
143
144static char **g_argv;
145static int g_argc;
146#ifndef VBOX /* No linking. */
147static char **g_objv;
148static int g_objc;
149#endif
150static dtrace_cmd_t *g_cmdv;
151static int g_cmdc;
152static struct ps_prochandle **g_psv;
153static int g_psc;
154static int g_pslive;
155static char *g_pname;
156static int g_quiet;
157static int g_flowindent;
158#ifdef VBOX /* Added volatile to signal handler variables. */
159static int volatile g_intr;
160static int volatile g_impatient;
161static int volatile g_newline;
162#else
163static int g_intr;
164static int g_impatient;
165static int g_newline;
166#endif
167static int g_total;
168static int g_cflags;
169static int g_oflags;
170static int g_verbose;
171static int g_exec = 1;
172static int g_mode = DMODE_EXEC;
173static int g_status = E_SUCCESS;
174static int g_grabanon = 0;
175static const char *g_ofile = NULL;
176#ifndef VBOX /* stdout isn't a necessarily constant usable like this in C code. */
177static FILE *g_ofp = stdout;
178#else
179static FILE *g_ofp = NULL;
180#endif
181static dtrace_hdl_t *g_dtp;
182static char *g_etcfile = "/etc/system";
183static const char *g_etcbegin = "* vvvv Added by DTrace";
184static const char *g_etcend = "* ^^^^ Added by DTrace";
185
186static const char *g_etc[] = {
187"*",
188"* The following forceload directives were added by dtrace(1M) to allow for",
189"* tracing during boot. If these directives are removed, the system will",
190"* continue to function, but tracing will not occur during boot as desired.",
191"* To remove these directives (and this block comment) automatically, run",
192"* \"dtrace -A\" without additional arguments. See the \"Anonymous Tracing\"",
193"* chapter of the Solaris Dynamic Tracing Guide for details.",
194"*",
195NULL };
196
197static int
198usage(FILE *fp)
199{
200 static const char predact[] = "[[ predicate ] action ]";
201
202 (void) fprintf(fp, "Usage: %s [-32|-64] [-aACeFGhHlqSvVwZ] "
203 "[-b bufsz] [-c cmd] [-D name[=def]]\n\t[-I path] [-L path] "
204 "[-o output] [-p pid] [-s script] [-U name]\n\t"
205 "[-x opt[=val]] [-X a|c|s|t]\n\n"
206 "\t[-P provider %s]\n"
207 "\t[-m [ provider: ] module %s]\n"
208 "\t[-f [[ provider: ] module: ] func %s]\n"
209 "\t[-n [[[ provider: ] module: ] func: ] name %s]\n"
210 "\t[-i probe-id %s] [ args ... ]\n\n", g_pname,
211 predact, predact, predact, predact, predact);
212
213 (void) fprintf(fp, "\tpredicate -> '/' D-expression '/'\n");
214 (void) fprintf(fp, "\t action -> '{' D-statements '}'\n");
215
216 (void) fprintf(fp, "\n"
217 "\t-32 generate 32-bit D programs and ELF files\n"
218 "\t-64 generate 64-bit D programs and ELF files\n\n"
219 "\t-a claim anonymous tracing state\n"
220 "\t-A generate driver.conf(4) directives for anonymous tracing\n"
221 "\t-b set trace buffer size\n"
222 "\t-c run specified command and exit upon its completion\n"
223 "\t-C run cpp(1) preprocessor on script files\n"
224 "\t-D define symbol when invoking preprocessor\n"
225 "\t-e exit after compiling request but prior to enabling probes\n"
226 "\t-f enable or list probes matching the specified function name\n"
227 "\t-F coalesce trace output by function\n"
228 "\t-G generate an ELF file containing embedded dtrace program\n"
229 "\t-h generate a header file with definitions for static probes\n"
230 "\t-H print included files when invoking preprocessor\n"
231 "\t-i enable or list probes matching the specified probe id\n"
232 "\t-I add include directory to preprocessor search path\n"
233 "\t-l list probes matching specified criteria\n"
234 "\t-L add library directory to library search path\n"
235 "\t-m enable or list probes matching the specified module name\n"
236 "\t-n enable or list probes matching the specified probe name\n"
237 "\t-o set output file\n"
238 "\t-p grab specified process-ID and cache its symbol tables\n"
239 "\t-P enable or list probes matching the specified provider name\n"
240 "\t-q set quiet mode (only output explicitly traced data)\n"
241 "\t-s enable or list probes according to the specified D script\n"
242 "\t-S print D compiler intermediate code\n"
243 "\t-U undefine symbol when invoking preprocessor\n"
244 "\t-v set verbose mode (report stability attributes, arguments)\n"
245 "\t-V report DTrace API version\n"
246 "\t-w permit destructive actions\n"
247 "\t-x enable or modify compiler and tracing options\n"
248 "\t-X specify ISO C conformance settings for preprocessor\n"
249 "\t-Z permit probe descriptions that match zero probes\n");
250
251 return (E_USAGE);
252}
253
254static void
255verror(const char *fmt, va_list ap)
256{
257 int error = errno;
258
259 (void) fprintf(stderr, "%s: ", g_pname);
260 (void) vfprintf(stderr, fmt, ap);
261
262 if (fmt[strlen(fmt) - 1] != '\n')
263 (void) fprintf(stderr, ": %s\n", strerror(error));
264}
265
266/*PRINTFLIKE1*/
267static void
268fatal(const char *fmt, ...)
269{
270 va_list ap;
271
272 va_start(ap, fmt);
273 verror(fmt, ap);
274 va_end(ap);
275
276 exit(E_ERROR);
277}
278
279/*PRINTFLIKE1*/
280static void
281dfatal(const char *fmt, ...)
282{
283 va_list ap;
284
285 va_start(ap, fmt);
286
287 (void) fprintf(stderr, "%s: ", g_pname);
288 if (fmt != NULL)
289 (void) vfprintf(stderr, fmt, ap);
290
291 va_end(ap);
292
293 if (fmt != NULL && fmt[strlen(fmt) - 1] != '\n') {
294 (void) fprintf(stderr, ": %s\n",
295 dtrace_errmsg(g_dtp, dtrace_errno(g_dtp)));
296 } else if (fmt == NULL) {
297 (void) fprintf(stderr, "%s\n",
298 dtrace_errmsg(g_dtp, dtrace_errno(g_dtp)));
299 }
300
301 /*
302 * Close the DTrace handle to ensure that any controlled processes are
303 * correctly restored and continued.
304 */
305 dtrace_close(g_dtp);
306
307 exit(E_ERROR);
308}
309
310/*PRINTFLIKE1*/
311static void
312error(const char *fmt, ...)
313{
314 va_list ap;
315
316 va_start(ap, fmt);
317 verror(fmt, ap);
318 va_end(ap);
319}
320
321/*PRINTFLIKE1*/
322static void
323notice(const char *fmt, ...)
324{
325 va_list ap;
326
327 if (g_quiet)
328 return; /* -q or quiet pragma suppresses notice()s */
329
330 va_start(ap, fmt);
331 verror(fmt, ap);
332 va_end(ap);
333}
334
335/*PRINTFLIKE1*/
336static void
337oprintf(const char *fmt, ...)
338{
339 va_list ap;
340 int n;
341
342 if (g_ofp == NULL)
343 return;
344
345 va_start(ap, fmt);
346 n = vfprintf(g_ofp, fmt, ap);
347 va_end(ap);
348
349 if (n < 0) {
350 if (errno != EINTR) {
351 fatal("failed to write to %s",
352 g_ofile ? g_ofile : "<stdout>");
353 }
354 clearerr(g_ofp);
355 }
356}
357
358static char **
359make_argv(char *s)
360{
361 const char *ws = "\f\n\r\t\v ";
362 char **argv = malloc(sizeof (char *) * (strlen(s) / 2 + 1));
363 int argc = 0;
364 char *p = s;
365
366 if (argv == NULL)
367 return (NULL);
368
369 for (p = strtok(s, ws); p != NULL; p = strtok(NULL, ws))
370 argv[argc++] = p;
371
372 if (argc == 0)
373 argv[argc++] = s;
374
375 argv[argc] = NULL;
376 return (argv);
377}
378
379static void
380dof_prune(const char *fname)
381{
382 struct stat sbuf;
383 size_t sz, i, j, mark, len;
384 char *buf;
385 int msg = 0, fd;
386
387 if ((fd = open(fname, O_RDONLY)) == -1) {
388 /*
389 * This is okay only if the file doesn't exist at all.
390 */
391 if (errno != ENOENT)
392 fatal("failed to open %s", fname);
393 return;
394 }
395
396 if (fstat(fd, &sbuf) == -1)
397 fatal("failed to fstat %s", fname);
398
399 if ((buf = malloc((sz = sbuf.st_size) + 1)) == NULL)
400 fatal("failed to allocate memory for %s", fname);
401
402 if ((size_t/*vbox*/)read(fd, buf, sz) != sz)
403 fatal("failed to read %s", fname);
404
405 buf[sz] = '\0';
406 (void) close(fd);
407
408 if ((fd = open(fname, O_WRONLY | O_TRUNC)) == -1)
409 fatal("failed to open %s for writing", fname);
410
411 len = strlen("dof-data-");
412
413 for (mark = 0, i = 0; i < sz; i++) {
414 if (strncmp(&buf[i], "dof-data-", len) != 0)
415 continue;
416
417 /*
418 * This is only a match if it's in the 0th column.
419 */
420 if (i != 0 && buf[i - 1] != '\n')
421 continue;
422
423 if (msg++ == 0) {
424 error("cleaned up old anonymous "
425 "enabling in %s\n", fname);
426 }
427
428 /*
429 * We have a match. First write out our data up until now.
430 */
431 if (i != mark) {
432 if ((size_t/*vbox*/)write(fd, &buf[mark], i - mark) != i - mark)
433 fatal("failed to write to %s", fname);
434 }
435
436 /*
437 * Now scan forward until we scan past a newline.
438 */
439 for (j = i; j < sz && buf[j] != '\n'; j++)
440 continue;
441
442 /*
443 * Reset our mark.
444 */
445 if ((mark = j + 1) >= sz)
446 break;
447
448 i = j;
449 }
450
451 if (mark < sz) {
452 if ((size_t/*vbox*/)write(fd, &buf[mark], sz - mark) != sz - mark)
453 fatal("failed to write to %s", fname);
454 }
455
456 (void) close(fd);
457 free(buf);
458}
459
460static void
461etcsystem_prune(void)
462{
463 struct stat sbuf;
464 size_t sz;
465 char *buf, *start, *end;
466 int fd;
467 char *fname = g_etcfile, *tmpname;
468
469 if ((fd = open(fname, O_RDONLY)) == -1)
470 fatal("failed to open %s", fname);
471
472 if (fstat(fd, &sbuf) == -1)
473 fatal("failed to fstat %s", fname);
474
475 if ((buf = malloc((sz = sbuf.st_size) + 1)) == NULL)
476 fatal("failed to allocate memory for %s", fname);
477
478 if ((size_t/*vbox*/)read(fd, buf, sz) != sz)
479 fatal("failed to read %s", fname);
480
481 buf[sz] = '\0';
482 (void) close(fd);
483
484 if ((start = strstr(buf, g_etcbegin)) == NULL)
485 goto out;
486
487 if (strlen(buf) != sz) {
488 fatal("embedded nul byte in %s; manual repair of %s "
489 "required\n", fname, fname);
490 }
491
492 if (strstr(start + 1, g_etcbegin) != NULL) {
493 fatal("multiple start sentinels in %s; manual repair of %s "
494 "required\n", fname, fname);
495 }
496
497 if ((end = strstr(buf, g_etcend)) == NULL) {
498 fatal("missing end sentinel in %s; manual repair of %s "
499 "required\n", fname, fname);
500 }
501
502 if (start > end) {
503 fatal("end sentinel preceeds start sentinel in %s; manual "
504 "repair of %s required\n", fname, fname);
505 }
506
507 end += strlen(g_etcend) + 1;
508 bcopy(end, start, strlen(end) + 1);
509
510 tmpname = alloca(sz = strlen(fname) + 80);
511 (void) snprintf(tmpname, sz, "%s.dtrace.%d", fname, getpid());
512
513 if ((fd = open(tmpname,
514 O_WRONLY | O_CREAT | O_EXCL, sbuf.st_mode)) == -1)
515 fatal("failed to create %s", tmpname);
516
517 if (write(fd, buf, strlen(buf)) < strlen(buf)) {
518 (void) unlink(tmpname);
519 fatal("failed to write to %s", tmpname);
520 }
521
522 (void) close(fd);
523
524#ifndef _MSC_VER
525 if (chown(tmpname, sbuf.st_uid, sbuf.st_gid) != 0) {
526 (void) unlink(tmpname);
527 fatal("failed to chown(2) %s to uid %d, gid %d", tmpname,
528 (int)sbuf.st_uid, (int)sbuf.st_gid);
529 }
530#endif
531
532 if (rename(tmpname, fname) == -1)
533 fatal("rename of %s to %s failed", tmpname, fname);
534
535 error("cleaned up forceload directives in %s\n", fname);
536out:
537 free(buf);
538}
539
540static void
541etcsystem_add(void)
542{
543 const char *mods[20];
544 int nmods, line;
545
546 if ((g_ofp = fopen(g_ofile = g_etcfile, "a")) == NULL)
547 fatal("failed to open output file '%s'", g_ofile);
548
549 oprintf("%s\n", g_etcbegin);
550
551 for (line = 0; g_etc[line] != NULL; line++)
552 oprintf("%s\n", g_etc[line]);
553
554 nmods = dtrace_provider_modules(g_dtp, mods,
555 sizeof (mods) / sizeof (char *) - 1);
556
557 if (nmods >= sizeof (mods) / sizeof (char *))
558 fatal("unexpectedly large number of modules!");
559
560 mods[nmods++] = "dtrace";
561
562 for (line = 0; line < nmods; line++)
563 oprintf("forceload: drv/%s\n", mods[line]);
564
565 oprintf("%s\n", g_etcend);
566
567 if (fclose(g_ofp) == EOF)
568 fatal("failed to close output file '%s'", g_ofile);
569
570 error("added forceload directives to %s\n", g_ofile);
571}
572
573static void
574print_probe_info(const dtrace_probeinfo_t *p)
575{
576 char buf[BUFSIZ];
577 int i;
578
579 oprintf("\n\tProbe Description Attributes\n");
580
581 oprintf("\t\tIdentifier Names: %s\n",
582 dtrace_stability_name(p->dtp_attr.dtat_name));
583 oprintf("\t\tData Semantics: %s\n",
584 dtrace_stability_name(p->dtp_attr.dtat_data));
585 oprintf("\t\tDependency Class: %s\n",
586 dtrace_class_name(p->dtp_attr.dtat_class));
587
588 oprintf("\n\tArgument Attributes\n");
589
590 oprintf("\t\tIdentifier Names: %s\n",
591 dtrace_stability_name(p->dtp_arga.dtat_name));
592 oprintf("\t\tData Semantics: %s\n",
593 dtrace_stability_name(p->dtp_arga.dtat_data));
594 oprintf("\t\tDependency Class: %s\n",
595 dtrace_class_name(p->dtp_arga.dtat_class));
596
597 oprintf("\n\tArgument Types\n");
598
599 for (i = 0; i < p->dtp_argc; i++) {
600 if (ctf_type_name(p->dtp_argv[i].dtt_ctfp,
601 p->dtp_argv[i].dtt_type, buf, sizeof (buf)) == NULL)
602 (void) strlcpy(buf, "(unknown)", sizeof (buf));
603 oprintf("\t\targs[%d]: %s\n", i, buf);
604 }
605
606 if (p->dtp_argc == 0)
607 oprintf("\t\tNone\n");
608
609 oprintf("\n");
610}
611
612/*ARGSUSED*/
613static int
614info_stmt(dtrace_hdl_t *dtp, dtrace_prog_t *pgp,
615 dtrace_stmtdesc_t *stp, dtrace_ecbdesc_t **last)
616{
617 dtrace_ecbdesc_t *edp = stp->dtsd_ecbdesc;
618 dtrace_probedesc_t *pdp = &edp->dted_probe;
619 dtrace_probeinfo_t p;
620 RT_NOREF1(pgp);
621
622 if (edp == *last)
623 return (0);
624
625 oprintf("\n%s:%s:%s:%s\n",
626 pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name);
627
628 if (dtrace_probe_info(dtp, pdp, &p) == 0)
629 print_probe_info(&p);
630
631 *last = edp;
632 return (0);
633}
634
635/*
636 * Execute the specified program by enabling the corresponding instrumentation.
637 * If -e has been specified, we get the program info but do not enable it. If
638 * -v has been specified, we print a stability report for the program.
639 */
640static void
641exec_prog(const dtrace_cmd_t *dcp)
642{
643 dtrace_ecbdesc_t *last = NULL;
644 dtrace_proginfo_t dpi;
645
646 if (!g_exec) {
647 dtrace_program_info(g_dtp, dcp->dc_prog, &dpi);
648 } else if (dtrace_program_exec(g_dtp, dcp->dc_prog, &dpi) == -1) {
649 dfatal("failed to enable '%s'", dcp->dc_name);
650 } else {
651 notice("%s '%s' matched %u probe%s\n",
652 dcp->dc_desc, dcp->dc_name,
653 dpi.dpi_matches, dpi.dpi_matches == 1 ? "" : "s");
654 }
655
656 if (g_verbose) {
657 oprintf("\nStability attributes for %s %s:\n",
658 dcp->dc_desc, dcp->dc_name);
659
660 oprintf("\n\tMinimum Probe Description Attributes\n");
661 oprintf("\t\tIdentifier Names: %s\n",
662 dtrace_stability_name(dpi.dpi_descattr.dtat_name));
663 oprintf("\t\tData Semantics: %s\n",
664 dtrace_stability_name(dpi.dpi_descattr.dtat_data));
665 oprintf("\t\tDependency Class: %s\n",
666 dtrace_class_name(dpi.dpi_descattr.dtat_class));
667
668 oprintf("\n\tMinimum Statement Attributes\n");
669
670 oprintf("\t\tIdentifier Names: %s\n",
671 dtrace_stability_name(dpi.dpi_stmtattr.dtat_name));
672 oprintf("\t\tData Semantics: %s\n",
673 dtrace_stability_name(dpi.dpi_stmtattr.dtat_data));
674 oprintf("\t\tDependency Class: %s\n",
675 dtrace_class_name(dpi.dpi_stmtattr.dtat_class));
676
677 if (!g_exec) {
678 (void) dtrace_stmt_iter(g_dtp, dcp->dc_prog,
679 (dtrace_stmt_f *)info_stmt, &last);
680 } else
681 oprintf("\n");
682 }
683
684 g_total += dpi.dpi_matches;
685}
686
687/*
688 * Print out the specified DOF buffer as a set of ASCII bytes appropriate for
689 * storing in a driver.conf(4) file associated with the dtrace driver.
690 */
691static void
692anon_prog(const dtrace_cmd_t *dcp, dof_hdr_t *dof, int n)
693{
694 const uchar_t *p, *q;
695
696 if (dof == NULL)
697 dfatal("failed to create DOF image for '%s'", dcp->dc_name);
698
699 p = (uchar_t *)dof;
700 q = p + dof->dofh_loadsz;
701
702 oprintf("dof-data-%d=0x%x", n, *p++);
703
704 while (p < q)
705 oprintf(",0x%x", *p++);
706
707 oprintf(";\n");
708 dtrace_dof_destroy(g_dtp, dof);
709}
710
711#ifndef VBOX
712/*
713 * Link the specified D program in DOF form into an ELF file for use in either
714 * helpers, userland provider definitions, or both. If -o was specified, that
715 * path is used as the output file name. If -o wasn't specified and the input
716 * program is from a script whose name is %.d, use basename(%.o) as the output
717 * file name. Otherwise we use "d.out" as the default output file name.
718 */
719static void
720link_prog(dtrace_cmd_t *dcp)
721{
722 char *p;
723
724 if (g_cmdc == 1 && g_ofile != NULL) {
725 (void) strlcpy(dcp->dc_ofile, g_ofile, sizeof (dcp->dc_ofile));
726 } else if ((p = strrchr(dcp->dc_arg, '.')) != NULL &&
727 strcmp(p, ".d") == 0) {
728 p[0] = '\0'; /* strip .d suffix */
729 (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile),
730 "%s.o", basename(dcp->dc_arg));
731 } else {
732 (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile),
733 g_cmdc > 1 ? "%s.%d" : "%s", "d.out", (int)(dcp - g_cmdv));
734 }
735
736 if (dtrace_program_link(g_dtp, dcp->dc_prog, DTRACE_D_PROBES,
737 dcp->dc_ofile, g_objc, g_objv) != 0)
738 dfatal("failed to link %s %s", dcp->dc_desc, dcp->dc_name);
739}
740#endif /* !VBOX */
741
742/*ARGSUSED*/
743static int
744list_probe(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *arg)
745{
746 dtrace_probeinfo_t p;
747 RT_NOREF1(arg);
748
749 oprintf("%5d %10s %17s %33s %s\n", pdp->dtpd_id,
750 pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name);
751
752 if (g_verbose && dtrace_probe_info(dtp, pdp, &p) == 0)
753 print_probe_info(&p);
754
755 return (0);
756}
757
758/*ARGSUSED*/
759static int
760list_stmt(dtrace_hdl_t *dtp, dtrace_prog_t *pgp,
761 dtrace_stmtdesc_t *stp, dtrace_ecbdesc_t **last)
762{
763 dtrace_ecbdesc_t *edp = stp->dtsd_ecbdesc;
764 RT_NOREF1(pgp);
765
766 if (edp == *last)
767 return (0);
768
769 if (dtrace_probe_iter(g_dtp, &edp->dted_probe, list_probe, NULL) != 0) {
770 error("failed to match %s:%s:%s:%s: %s\n",
771 edp->dted_probe.dtpd_provider, edp->dted_probe.dtpd_mod,
772 edp->dted_probe.dtpd_func, edp->dted_probe.dtpd_name,
773 dtrace_errmsg(dtp, dtrace_errno(dtp)));
774 }
775
776 *last = edp;
777 return (0);
778}
779
780/*
781 * List the probes corresponding to the specified program by iterating over
782 * each statement and then matching probes to the statement probe descriptions.
783 */
784static void
785list_prog(const dtrace_cmd_t *dcp)
786{
787 dtrace_ecbdesc_t *last = NULL;
788
789 (void) dtrace_stmt_iter(g_dtp, dcp->dc_prog,
790 (dtrace_stmt_f *)list_stmt, &last);
791}
792
793static void
794compile_file(dtrace_cmd_t *dcp)
795{
796 char *arg0;
797 FILE *fp;
798
799 if ((fp = fopen(dcp->dc_arg, "r")) == NULL)
800 fatal("failed to open %s", dcp->dc_arg);
801
802 arg0 = g_argv[0];
803 g_argv[0] = dcp->dc_arg;
804
805 if ((dcp->dc_prog = dtrace_program_fcompile(g_dtp, fp,
806 g_cflags, g_argc, g_argv)) == NULL)
807 dfatal("failed to compile script %s", dcp->dc_arg);
808
809 g_argv[0] = arg0;
810 (void) fclose(fp);
811
812 dcp->dc_desc = "script";
813 dcp->dc_name = dcp->dc_arg;
814}
815
816static void
817compile_str(dtrace_cmd_t *dcp)
818{
819 char *p;
820
821 if ((dcp->dc_prog = dtrace_program_strcompile(g_dtp, dcp->dc_arg,
822 dcp->dc_spec, g_cflags | DTRACE_C_PSPEC, g_argc, g_argv)) == NULL)
823 dfatal("invalid probe specifier %s", dcp->dc_arg);
824
825 if ((p = strpbrk(dcp->dc_arg, "{/;")) != NULL)
826 *p = '\0'; /* crop name for reporting */
827
828 dcp->dc_desc = "description";
829 dcp->dc_name = dcp->dc_arg;
830}
831
832/*ARGSUSED*/
833static void
834prochandler(struct ps_prochandle *P, const char *msg, void *arg)
835{
836#ifndef VBOX
837 const psinfo_t *prp = Ppsinfo(P);
838 int pid = Pstatus(P)->pr_pid;
839 char name[SIG2STR_MAX];
840
841 if (msg != NULL) {
842 notice("pid %d: %s\n", pid, msg);
843 return;
844 }
845
846 switch (Pstate(P)) {
847 case PS_UNDEAD:
848 /*
849 * Ideally we would like to always report pr_wstat here, but it
850 * isn't possible given current /proc semantics. If we grabbed
851 * the process, Ppsinfo() will either fail or return a zeroed
852 * psinfo_t depending on how far the parent is in reaping it.
853 * When /proc provides a stable pr_wstat in the status file,
854 * this code can be improved by examining this new pr_wstat.
855 */
856 if (prp != NULL && WIFSIGNALED(prp->pr_wstat)) {
857 notice("pid %d terminated by %s\n", pid,
858 proc_signame(WTERMSIG(prp->pr_wstat),
859 name, sizeof (name)));
860 } else if (prp != NULL && WEXITSTATUS(prp->pr_wstat) != 0) {
861 notice("pid %d exited with status %d\n",
862 pid, WEXITSTATUS(prp->pr_wstat));
863 } else {
864 notice("pid %d has exited\n", pid);
865 }
866 g_pslive--;
867 break;
868
869 case PS_LOST:
870 notice("pid %d exec'd a set-id or unobservable program\n", pid);
871 g_pslive--;
872 break;
873 }
874#else
875 RT_NOREF3(P, msg, arg);
876#endif /* VBOX */
877}
878
879/*ARGSUSED*/
880static int
881errhandler(const dtrace_errdata_t *data, void *arg)
882{
883 RT_NOREF1(arg);
884 error(data->dteda_msg);
885 return (DTRACE_HANDLE_OK);
886}
887
888/*ARGSUSED*/
889static int
890drophandler(const dtrace_dropdata_t *data, void *arg)
891{
892 RT_NOREF1(arg);
893 error(data->dtdda_msg);
894 return (DTRACE_HANDLE_OK);
895}
896
897/*ARGSUSED*/
898static int
899setopthandler(const dtrace_setoptdata_t *data, void *arg)
900{
901 RT_NOREF1(arg);
902 if (strcmp(data->dtsda_option, "quiet") == 0)
903 g_quiet = data->dtsda_newval != DTRACEOPT_UNSET;
904
905 if (strcmp(data->dtsda_option, "flowindent") == 0)
906 g_flowindent = data->dtsda_newval != DTRACEOPT_UNSET;
907
908 return (DTRACE_HANDLE_OK);
909}
910
911#define BUFDUMPHDR(hdr) \
912 (void) printf("%s: %s%s\n", g_pname, hdr, strlen(hdr) > 0 ? ":" : "");
913
914#define BUFDUMPSTR(ptr, field) \
915 (void) printf("%s: %20s => ", g_pname, #field); \
916 if ((ptr)->field != NULL) { \
917 const char *c = (ptr)->field; \
918 (void) printf("\""); \
919 do { \
920 if (*c == '\n') { \
921 (void) printf("\\n"); \
922 continue; \
923 } \
924 \
925 (void) printf("%c", *c); \
926 } while (*c++ != '\0'); \
927 (void) printf("\"\n"); \
928 } else { \
929 (void) printf("<NULL>\n"); \
930 }
931
932#define BUFDUMPASSTR(ptr, field, str) \
933 (void) printf("%s: %20s => %s\n", g_pname, #field, str);
934
935#define BUFDUMP(ptr, field) \
936 (void) printf("%s: %20s => %lld\n", g_pname, #field, \
937 (long long)(ptr)->field);
938
939#define BUFDUMPPTR(ptr, field) \
940 (void) printf("%s: %20s => %s\n", g_pname, #field, \
941 (ptr)->field != NULL ? "<non-NULL>" : "<NULL>");
942
943/*ARGSUSED*/
944static int
945bufhandler(const dtrace_bufdata_t *bufdata, void *arg)
946{
947 const dtrace_aggdata_t *agg = bufdata->dtbda_aggdata;
948 const dtrace_recdesc_t *rec = bufdata->dtbda_recdesc;
949 const dtrace_probedesc_t *pd;
950 uint32_t flags = bufdata->dtbda_flags;
951 char buf[512], *c = buf, *end = c + sizeof (buf);
952 int i, printed;
953
954 struct {
955 const char *name;
956 uint32_t value;
957 } flagnames[] = {
958 { "AGGVAL", DTRACE_BUFDATA_AGGVAL },
959 { "AGGKEY", DTRACE_BUFDATA_AGGKEY },
960 { "AGGFORMAT", DTRACE_BUFDATA_AGGFORMAT },
961 { "AGGLAST", DTRACE_BUFDATA_AGGLAST },
962 { "???", UINT32_MAX },
963 { NULL }
964 };
965 RT_NOREF1(arg);
966
967 if (bufdata->dtbda_probe != NULL) {
968 pd = bufdata->dtbda_probe->dtpda_pdesc;
969 } else if (agg != NULL) {
970 pd = agg->dtada_pdesc;
971 } else {
972 pd = NULL;
973 }
974
975 BUFDUMPHDR(">>> Called buffer handler");
976 BUFDUMPHDR("");
977
978 BUFDUMPHDR(" dtrace_bufdata");
979 BUFDUMPSTR(bufdata, dtbda_buffered);
980 BUFDUMPPTR(bufdata, dtbda_probe);
981 BUFDUMPPTR(bufdata, dtbda_aggdata);
982 BUFDUMPPTR(bufdata, dtbda_recdesc);
983
984 (void) snprintf(c, end - c, "0x%x ", bufdata->dtbda_flags);
985 c += strlen(c);
986
987 for (i = 0, printed = 0; flagnames[i].name != NULL; i++) {
988 if (!(flags & flagnames[i].value))
989 continue;
990
991 (void) snprintf(c, end - c,
992 "%s%s", printed++ ? " | " : "(", flagnames[i].name);
993 c += strlen(c);
994 flags &= ~flagnames[i].value;
995 }
996
997 if (printed)
998 (void) snprintf(c, end - c, ")");
999
1000 BUFDUMPASSTR(bufdata, dtbda_flags, buf);
1001 BUFDUMPHDR("");
1002
1003 if (pd != NULL) {
1004 BUFDUMPHDR(" dtrace_probedesc");
1005 BUFDUMPSTR(pd, dtpd_provider);
1006 BUFDUMPSTR(pd, dtpd_mod);
1007 BUFDUMPSTR(pd, dtpd_func);
1008 BUFDUMPSTR(pd, dtpd_name);
1009 BUFDUMPHDR("");
1010 }
1011
1012 if (rec != NULL) {
1013 BUFDUMPHDR(" dtrace_recdesc");
1014 BUFDUMP(rec, dtrd_action);
1015 BUFDUMP(rec, dtrd_size);
1016
1017 if (agg != NULL) {
1018 uint8_t *data;
1019 int lim = rec->dtrd_size;
1020
1021 (void) sprintf(buf, "%d (data: ", rec->dtrd_offset);
1022 c = buf + strlen(buf);
1023
1024 if (lim > sizeof (uint64_t))
1025 lim = sizeof (uint64_t);
1026
1027 data = (uint8_t *)agg->dtada_data + rec->dtrd_offset;
1028
1029 for (i = 0; i < lim; i++) {
1030 (void) snprintf(c, end - c, "%s%02x",
1031 i == 0 ? "" : " ", *data++);
1032 c += strlen(c);
1033 }
1034
1035 (void) snprintf(c, end - c,
1036 "%s)", lim < rec->dtrd_size ? " ..." : "");
1037 BUFDUMPASSTR(rec, dtrd_offset, buf);
1038 } else {
1039 BUFDUMP(rec, dtrd_offset);
1040 }
1041
1042 BUFDUMPHDR("");
1043 }
1044
1045 if (agg != NULL) {
1046 dtrace_aggdesc_t *desc = agg->dtada_desc;
1047
1048 BUFDUMPHDR(" dtrace_aggdesc");
1049 BUFDUMPSTR(desc, dtagd_name);
1050 BUFDUMP(desc, dtagd_varid);
1051 BUFDUMP(desc, dtagd_id);
1052 BUFDUMP(desc, dtagd_nrecs);
1053 BUFDUMPHDR("");
1054 }
1055
1056 return (DTRACE_HANDLE_OK);
1057}
1058
1059/*ARGSUSED*/
1060static int
1061chewrec(const dtrace_probedata_t *data, const dtrace_recdesc_t *rec, void *arg)
1062{
1063 dtrace_actkind_t act;
1064 uintptr_t addr;
1065 RT_NOREF1(arg);
1066
1067 if (rec == NULL) {
1068 /*
1069 * We have processed the final record; output the newline if
1070 * we're not in quiet mode.
1071 */
1072 if (!g_quiet)
1073 oprintf("\n");
1074
1075 return (DTRACE_CONSUME_NEXT);
1076 }
1077
1078 act = rec->dtrd_action;
1079 addr = (uintptr_t)data->dtpda_data;
1080
1081 if (act == DTRACEACT_EXIT) {
1082 g_status = *((uint32_t *)addr);
1083 return (DTRACE_CONSUME_NEXT);
1084 }
1085
1086 return (DTRACE_CONSUME_THIS);
1087}
1088
1089/*ARGSUSED*/
1090static int
1091chew(const dtrace_probedata_t *data, void *arg)
1092{
1093 dtrace_probedesc_t *pd = data->dtpda_pdesc;
1094 processorid_t cpu = data->dtpda_cpu;
1095 static int heading;
1096 RT_NOREF1(arg);
1097
1098 if (g_impatient) {
1099 g_newline = 0;
1100 return (DTRACE_CONSUME_ABORT);
1101 }
1102
1103 if (heading == 0) {
1104 if (!g_flowindent) {
1105 if (!g_quiet) {
1106 oprintf("%3s %6s %32s\n",
1107 "CPU", "ID", "FUNCTION:NAME");
1108 }
1109 } else {
1110 oprintf("%3s %-41s\n", "CPU", "FUNCTION");
1111 }
1112 heading = 1;
1113 }
1114
1115 if (!g_flowindent) {
1116 if (!g_quiet) {
1117 char name[DTRACE_FUNCNAMELEN + DTRACE_NAMELEN + 2];
1118
1119 (void) snprintf(name, sizeof (name), "%s:%s",
1120 pd->dtpd_func, pd->dtpd_name);
1121
1122 oprintf("%3d %6d %32s ", cpu, pd->dtpd_id, name);
1123 }
1124 } else {
1125 int indent = data->dtpda_indent;
1126 char *name;
1127 size_t len;
1128
1129 if (data->dtpda_flow == DTRACEFLOW_NONE) {
1130 len = indent + DTRACE_FUNCNAMELEN + DTRACE_NAMELEN + 5;
1131 name = alloca(len);
1132 (void) snprintf(name, len, "%*s%s%s:%s", indent, "",
1133 data->dtpda_prefix, pd->dtpd_func,
1134 pd->dtpd_name);
1135 } else {
1136 len = indent + DTRACE_FUNCNAMELEN + 5;
1137 name = alloca(len);
1138 (void) snprintf(name, len, "%*s%s%s", indent, "",
1139 data->dtpda_prefix, pd->dtpd_func);
1140 }
1141
1142 oprintf("%3d %-41s ", cpu, name);
1143 }
1144
1145 return (DTRACE_CONSUME_THIS);
1146}
1147
1148static void
1149go(void)
1150{
1151 int i;
1152
1153 struct {
1154 char *name;
1155 char *optname;
1156 dtrace_optval_t val;
1157 } bufs[] = {
1158 { "buffer size", "bufsize" },
1159 { "aggregation size", "aggsize" },
1160 { "speculation size", "specsize" },
1161 { "dynamic variable size", "dynvarsize" },
1162 { NULL }
1163 }, rates[] = {
1164 { "cleaning rate", "cleanrate" },
1165 { "status rate", "statusrate" },
1166 { NULL }
1167 };
1168
1169 for (i = 0; bufs[i].name != NULL; i++) {
1170 if (dtrace_getopt(g_dtp, bufs[i].optname, &bufs[i].val) == -1)
1171 fatal("couldn't get option %s", bufs[i].optname);
1172 }
1173
1174 for (i = 0; rates[i].name != NULL; i++) {
1175 if (dtrace_getopt(g_dtp, rates[i].optname, &rates[i].val) == -1)
1176 fatal("couldn't get option %s", rates[i].optname);
1177 }
1178
1179 if (dtrace_go(g_dtp) == -1)
1180 dfatal("could not enable tracing");
1181
1182 for (i = 0; bufs[i].name != NULL; i++) {
1183 dtrace_optval_t j = 0, mul = 10;
1184 dtrace_optval_t nsize;
1185
1186 if (bufs[i].val == DTRACEOPT_UNSET)
1187 continue;
1188
1189 (void) dtrace_getopt(g_dtp, bufs[i].optname, &nsize);
1190
1191 if (nsize == DTRACEOPT_UNSET || nsize == 0)
1192 continue;
1193
1194 if (nsize >= bufs[i].val - sizeof (uint64_t))
1195 continue;
1196
1197 for (; (INT64_C(1) << mul) <= nsize; j++, mul += 10)
1198 continue;
1199
1200 if (!(nsize & ((INT64_C(1) << (mul - 10)) - 1))) {
1201 error("%s lowered to %lld%c\n", bufs[i].name,
1202 (long long)nsize >> (mul - 10), " kmgtpe"[j]);
1203 } else {
1204 error("%s lowered to %lld bytes\n", bufs[i].name,
1205 (long long)nsize);
1206 }
1207 }
1208
1209 for (i = 0; rates[i].name != NULL; i++) {
1210 dtrace_optval_t nval;
1211 char *dir;
1212
1213 if (rates[i].val == DTRACEOPT_UNSET)
1214 continue;
1215
1216 (void) dtrace_getopt(g_dtp, rates[i].optname, &nval);
1217
1218 if (nval == DTRACEOPT_UNSET || nval == 0)
1219 continue;
1220
1221 if (rates[i].val == nval)
1222 continue;
1223
1224 dir = nval > rates[i].val ? "reduced" : "increased";
1225
1226 if (nval <= NANOSEC && (NANOSEC % nval) == 0) {
1227 error("%s %s to %lld hz\n", rates[i].name, dir,
1228 (long long)NANOSEC / (long long)nval);
1229 continue;
1230 }
1231
1232 if ((nval % NANOSEC) == 0) {
1233 error("%s %s to once every %lld seconds\n",
1234 rates[i].name, dir,
1235 (long long)nval / (long long)NANOSEC);
1236 continue;
1237 }
1238
1239 error("%s %s to once every %lld nanoseconds\n",
1240 rates[i].name, dir, (long long)nval);
1241 }
1242}
1243
1244/*ARGSUSED*/
1245static void
1246intr(int signo)
1247{
1248 if (!g_intr)
1249 g_newline = 1;
1250
1251 if (g_intr++)
1252 g_impatient = 1;
1253#ifdef _MSC_VER
1254 /* Reinstall signal handler. Seems MSVCRT is System V style. */
1255 signal(signo, intr);
1256#endif
1257}
1258
1259#ifdef VBOX
1260DECLEXPORT(int) RTCALL VBoxDTraceMain(int argc, char **argv)
1261#else
1262int
1263main(int argc, char *argv[])
1264#endif
1265{
1266 dtrace_bufdesc_t buf;
1267#ifndef _MSC_VER
1268 struct sigaction act, oact;
1269#endif
1270 dtrace_status_t status[2];
1271 dtrace_optval_t opt;
1272 dtrace_cmd_t *dcp;
1273
1274 int done = 0, mode = 0;
1275 int err, i;
1276#ifndef VBOX
1277 char c, *p, **v;
1278 struct ps_prochandle *P;
1279 pid_t pid;
1280
1281 g_pname = basename(argv[0]);
1282#else
1283 int c;
1284 char *p;
1285 RTGETOPTUNION ValueUnion;
1286 RTGETOPTSTATE GetState;
1287
1288 err = RTR3InitDll(0);
1289 if (RT_FAILURE(err))
1290 return RTMsgInitFailure(err);
1291 dtrace_init();
1292
1293 g_ofp = stdout;
1294 g_pname = (char *)RTProcShortName();
1295#endif
1296
1297 if (argc == 1)
1298 return (usage(stderr));
1299
1300 if ((g_argv = malloc(sizeof (char *) * argc)) == NULL ||
1301 (g_cmdv = malloc(sizeof (dtrace_cmd_t) * argc)) == NULL ||
1302 (g_psv = malloc(sizeof (struct ps_prochandle *) * argc)) == NULL)
1303 fatal("failed to allocate memory for arguments");
1304
1305 g_argv[g_argc++] = argv[0]; /* propagate argv[0] to D as $0/$$0 */
1306 argv[0] = g_pname; /* rewrite argv[0] for getopt errors */
1307
1308 bzero(status, sizeof (status));
1309 bzero(&buf, sizeof (buf));
1310
1311 /*
1312 * Make an initial pass through argv[] processing any arguments that
1313 * affect our behavior mode (g_mode) and flags used for dtrace_open().
1314 * We also accumulate arguments that are not affiliated with getopt
1315 * options into g_argv[], and abort if any invalid options are found.
1316 */
1317#ifndef VBOX
1318 for (optind = 1; optind < argc; optind++) {
1319 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
1320#else
1321 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
1322 while ((c = RTGetOpt(&GetState, &ValueUnion))) {
1323 {
1324 /* const char *optarg = ValueUnion.psz; - unused */
1325#endif
1326 switch (c) {
1327#ifndef VBOX
1328 case '3':
1329 if (strcmp(optarg, "2") != 0) {
1330 (void) fprintf(stderr,
1331 "%s: illegal option -- 3%s\n",
1332 argv[0], optarg);
1333 return (usage(stderr));
1334 }
1335#else
1336 case 10032:
1337#endif
1338 g_oflags &= ~DTRACE_O_LP64;
1339 g_oflags |= DTRACE_O_ILP32;
1340 break;
1341
1342#ifndef VBOX
1343 case '6':
1344 if (strcmp(optarg, "4") != 0) {
1345 (void) fprintf(stderr,
1346 "%s: illegal option -- 6%s\n",
1347 argv[0], optarg);
1348 return (usage(stderr));
1349 }
1350#else
1351 case 10064:
1352#endif
1353 g_oflags &= ~DTRACE_O_ILP32;
1354 g_oflags |= DTRACE_O_LP64;
1355 break;
1356
1357 case 'a':
1358 g_grabanon++; /* also checked in pass 2 below */
1359 break;
1360
1361 case 'A':
1362 g_mode = DMODE_ANON;
1363 g_exec = 0;
1364 mode++;
1365 break;
1366
1367 case 'e':
1368 g_exec = 0;
1369 done = 1;
1370 break;
1371
1372 case 'h':
1373 g_mode = DMODE_HEADER;
1374 g_oflags |= DTRACE_O_NODEV;
1375 g_cflags |= DTRACE_C_ZDEFS; /* -h implies -Z */
1376 g_exec = 0;
1377 mode++;
1378 break;
1379
1380#ifndef VBOX
1381 case 'G':
1382 g_mode = DMODE_LINK;
1383 g_oflags |= DTRACE_O_NODEV;
1384 g_cflags |= DTRACE_C_ZDEFS; /* -G implies -Z */
1385 g_exec = 0;
1386 mode++;
1387 break;
1388#endif
1389
1390 case 'l':
1391 g_mode = DMODE_LIST;
1392 g_cflags |= DTRACE_C_ZDEFS; /* -l implies -Z */
1393 mode++;
1394 break;
1395
1396 case 'V':
1397 g_mode = DMODE_VERS;
1398 mode++;
1399 break;
1400
1401#ifndef VBOX
1402 default:
1403 if (strchr(DTRACE_OPTSTR, c) == NULL)
1404 return (usage(stderr));
1405#else
1406 case 'c':
1407 case 'p':
1408 case 'G':
1409 fprintf(stderr, "%s: -%c is not supported\n", g_pname, c);
1410 return (E_USAGE);
1411
1412 case VINF_GETOPT_NOT_OPTION:
1413 g_argv[g_argc++] = (char *)ValueUnion.psz;
1414 break;
1415
1416 default:
1417 if (c < 0) { /* Note: Not all options are handled. */
1418 RTGetOptPrintError(c, &ValueUnion);
1419 return (usage(stderr));
1420 }
1421#endif
1422 }
1423 }
1424
1425#ifndef VBOX
1426 if (optind < argc)
1427 g_argv[g_argc++] = argv[optind];
1428#endif
1429 }
1430
1431 if (mode > 1) {
1432 (void) fprintf(stderr, "%s: only one of the [-AGhlV] options "
1433 "can be specified at a time\n", g_pname);
1434 return (E_USAGE);
1435 }
1436
1437 if (g_mode == DMODE_VERS)
1438 return (printf("%s: %s\n", g_pname, _dtrace_version) <= 0);
1439
1440#ifndef VBOX
1441 /*
1442 * If we're in linker mode and the data model hasn't been specified,
1443 * we try to guess the appropriate setting by examining the object
1444 * files. We ignore certain errors since we'll catch them later when
1445 * we actually process the object files.
1446 */
1447 if (g_mode == DMODE_LINK &&
1448 (g_oflags & (DTRACE_O_ILP32 | DTRACE_O_LP64)) == 0 &&
1449 elf_version(EV_CURRENT) != EV_NONE) {
1450 int fd;
1451 Elf *elf;
1452 GElf_Ehdr ehdr;
1453
1454 for (i = 1; i < g_argc; i++) {
1455 if ((fd = open64(g_argv[i], O_RDONLY)) == -1)
1456 break;
1457
1458 if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
1459 (void) close(fd);
1460 break;
1461 }
1462
1463 if (elf_kind(elf) != ELF_K_ELF ||
1464 gelf_getehdr(elf, &ehdr) == NULL) {
1465 (void) close(fd);
1466 (void) elf_end(elf);
1467 break;
1468 }
1469
1470 (void) close(fd);
1471 (void) elf_end(elf);
1472
1473 if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) {
1474 if (g_oflags & DTRACE_O_ILP32) {
1475 fatal("can't mix 32-bit and 64-bit "
1476 "object files\n");
1477 }
1478 g_oflags |= DTRACE_O_LP64;
1479 } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
1480 if (g_oflags & DTRACE_O_LP64) {
1481 fatal("can't mix 32-bit and 64-bit "
1482 "object files\n");
1483 }
1484 g_oflags |= DTRACE_O_ILP32;
1485 } else {
1486 break;
1487 }
1488 }
1489 }
1490#endif /* !VBOX */
1491
1492 /*
1493 * Open libdtrace. If we are not actually going to be enabling any
1494 * instrumentation attempt to reopen libdtrace using DTRACE_O_NODEV.
1495 */
1496 while ((g_dtp = dtrace_open(DTRACE_VERSION, g_oflags, &err)) == NULL) {
1497 if (!(g_oflags & DTRACE_O_NODEV) && !g_exec && !g_grabanon) {
1498 g_oflags |= DTRACE_O_NODEV;
1499 continue;
1500 }
1501
1502 fatal("failed to initialize dtrace: %s\n",
1503 dtrace_errmsg(NULL, err));
1504 }
1505
1506 (void) dtrace_setopt(g_dtp, "bufsize", "4m");
1507 (void) dtrace_setopt(g_dtp, "aggsize", "4m");
1508
1509 /*
1510 * If -G is specified, enable -xlink=dynamic and -xunodefs to permit
1511 * references to undefined symbols to remain as unresolved relocations.
1512 * If -A is specified, enable -xlink=primary to permit static linking
1513 * only to kernel symbols that are defined in a primary kernel module.
1514 */
1515 if (g_mode == DMODE_LINK) {
1516#ifndef VBOX /* No link mode. */
1517 (void) dtrace_setopt(g_dtp, "linkmode", "dynamic");
1518 (void) dtrace_setopt(g_dtp, "unodefs", NULL);
1519
1520 /*
1521 * Use the remaining arguments as the list of object files
1522 * when in linker mode.
1523 */
1524 g_objc = g_argc - 1;
1525 g_objv = g_argv + 1;
1526
1527 /*
1528 * We still use g_argv[0], the name of the executable.
1529 */
1530 g_argc = 1;
1531#else /* VBOX */
1532 AssertFailed();
1533#endif /* VBOX */
1534 } else if (g_mode == DMODE_ANON)
1535 (void) dtrace_setopt(g_dtp, "linkmode", "primary");
1536
1537 /*
1538 * Now that we have libdtrace open, make a second pass through argv[]
1539 * to perform any dtrace_setopt() calls and change any compiler flags.
1540 * We also accumulate any program specifications into our g_cmdv[] at
1541 * this time; these will compiled as part of the fourth processing pass.
1542 */
1543#ifndef VBOX
1544 for (optind = 1; optind < argc; optind++) {
1545 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
1546#else
1547 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
1548 while ((c = RTGetOpt(&GetState, &ValueUnion))) {
1549 {
1550 char *optarg = (char *)ValueUnion.psz;
1551#endif
1552
1553 switch (c) {
1554 case 'a':
1555 if (dtrace_setopt(g_dtp, "grabanon", 0) != 0)
1556 dfatal("failed to set -a");
1557 break;
1558
1559 case 'b':
1560 if (dtrace_setopt(g_dtp,
1561 "bufsize", optarg) != 0)
1562 dfatal("failed to set -b %s", optarg);
1563 break;
1564
1565 case 'B':
1566 g_ofp = NULL;
1567 break;
1568
1569 case 'C':
1570 g_cflags |= DTRACE_C_CPP;
1571 break;
1572
1573 case 'D':
1574 if (dtrace_setopt(g_dtp, "define", optarg) != 0)
1575 dfatal("failed to set -D %s", optarg);
1576 break;
1577
1578 case 'f':
1579 dcp = &g_cmdv[g_cmdc++];
1580 dcp->dc_func = compile_str;
1581 dcp->dc_spec = DTRACE_PROBESPEC_FUNC;
1582 dcp->dc_arg = optarg;
1583 break;
1584
1585 case 'F':
1586 if (dtrace_setopt(g_dtp, "flowindent", 0) != 0)
1587 dfatal("failed to set -F");
1588 break;
1589
1590 case 'H':
1591 if (dtrace_setopt(g_dtp, "cpphdrs", 0) != 0)
1592 dfatal("failed to set -H");
1593 break;
1594
1595 case 'i':
1596 dcp = &g_cmdv[g_cmdc++];
1597 dcp->dc_func = compile_str;
1598 dcp->dc_spec = DTRACE_PROBESPEC_NAME;
1599 dcp->dc_arg = optarg;
1600 break;
1601
1602 case 'I':
1603 if (dtrace_setopt(g_dtp, "incdir", optarg) != 0)
1604 dfatal("failed to set -I %s", optarg);
1605 break;
1606
1607 case 'L':
1608 if (dtrace_setopt(g_dtp, "libdir", optarg) != 0)
1609 dfatal("failed to set -L %s", optarg);
1610 break;
1611
1612 case 'm':
1613 dcp = &g_cmdv[g_cmdc++];
1614 dcp->dc_func = compile_str;
1615 dcp->dc_spec = DTRACE_PROBESPEC_MOD;
1616 dcp->dc_arg = optarg;
1617 break;
1618
1619 case 'n':
1620 dcp = &g_cmdv[g_cmdc++];
1621 dcp->dc_func = compile_str;
1622 dcp->dc_spec = DTRACE_PROBESPEC_NAME;
1623 dcp->dc_arg = optarg;
1624 break;
1625
1626 case 'P':
1627 dcp = &g_cmdv[g_cmdc++];
1628 dcp->dc_func = compile_str;
1629 dcp->dc_spec = DTRACE_PROBESPEC_PROVIDER;
1630 dcp->dc_arg = optarg;
1631 break;
1632
1633 case 'q':
1634 if (dtrace_setopt(g_dtp, "quiet", 0) != 0)
1635 dfatal("failed to set -q");
1636 break;
1637
1638 case 'o':
1639 g_ofile = optarg;
1640 break;
1641
1642 case 's':
1643 dcp = &g_cmdv[g_cmdc++];
1644 dcp->dc_func = compile_file;
1645 dcp->dc_spec = DTRACE_PROBESPEC_NONE;
1646 dcp->dc_arg = optarg;
1647 break;
1648
1649 case 'S':
1650 g_cflags |= DTRACE_C_DIFV;
1651 break;
1652
1653 case 'U':
1654 if (dtrace_setopt(g_dtp, "undef", optarg) != 0)
1655 dfatal("failed to set -U %s", optarg);
1656 break;
1657
1658 case 'v':
1659 g_verbose++;
1660 break;
1661
1662 case 'w':
1663 if (dtrace_setopt(g_dtp, "destructive", 0) != 0)
1664 dfatal("failed to set -w");
1665 break;
1666
1667 case 'x':
1668 if ((p = strchr(optarg, '=')) != NULL)
1669 *p++ = '\0';
1670
1671 if (dtrace_setopt(g_dtp, optarg, p) != 0)
1672 dfatal("failed to set -x %s", optarg);
1673 break;
1674
1675 case 'X':
1676 if (dtrace_setopt(g_dtp, "stdc", optarg) != 0)
1677 dfatal("failed to set -X %s", optarg);
1678 break;
1679
1680 case 'Z':
1681 g_cflags |= DTRACE_C_ZDEFS;
1682 break;
1683
1684#ifndef VBOX
1685 default:
1686 if (strchr(DTRACE_OPTSTR, c) == NULL)
1687 return (usage(stderr));
1688#else
1689 default:
1690 if (c < 0) { /* Note: Not all options are handled. */
1691 RTGetOptPrintError(c, &ValueUnion);
1692 return (usage(stderr));
1693 }
1694#endif
1695 }
1696 }
1697 }
1698
1699 if (g_ofp == NULL && g_mode != DMODE_EXEC) {
1700 (void) fprintf(stderr, "%s: -B not valid in combination"
1701 " with [-AGl] options\n", g_pname);
1702 return (E_USAGE);
1703 }
1704
1705 if (g_ofp == NULL && g_ofile != NULL) {
1706 (void) fprintf(stderr, "%s: -B not valid in combination"
1707 " with -o option\n", g_pname);
1708 return (E_USAGE);
1709 }
1710
1711#ifndef VBOX
1712 /*
1713 * In our third pass we handle any command-line options related to
1714 * grabbing or creating victim processes. The behavior of these calls
1715 * may been affected by any library options set by the second pass.
1716 */
1717#ifndef VBOX
1718 for (optind = 1; optind < argc; optind++) {
1719 while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
1720#else
1721 RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
1722 while ((c = RTGetOpt(&GetState, &ValueUnion))) {
1723 {
1724 char *optarg = (char *)ValueUnion.psz;
1725#endif
1726 switch (c) {
1727 case 'c':
1728 if ((v = make_argv(optarg)) == NULL)
1729 fatal("failed to allocate memory");
1730
1731 P = dtrace_proc_create(g_dtp, v[0], v);
1732 if (P == NULL)
1733 dfatal(NULL); /* dtrace_errmsg() only */
1734
1735 g_psv[g_psc++] = P;
1736 free(v);
1737 break;
1738
1739 case 'p':
1740 errno = 0;
1741 pid = strtol(optarg, &p, 10);
1742
1743 if (errno != 0 || p == optarg || p[0] != '\0')
1744 fatal("invalid pid: %s\n", optarg);
1745
1746 P = dtrace_proc_grab(g_dtp, pid, 0);
1747 if (P == NULL)
1748 dfatal(NULL); /* dtrace_errmsg() only */
1749
1750 g_psv[g_psc++] = P;
1751 break;
1752 }
1753 }
1754 }
1755#endif /* !VBOX */
1756
1757 /*
1758 * In our fourth pass we finish g_cmdv[] by calling dc_func to convert
1759 * each string or file specification into a compiled program structure.
1760 */
1761 for (i = 0; i < g_cmdc; i++)
1762 g_cmdv[i].dc_func(&g_cmdv[i]);
1763
1764 if (g_mode != DMODE_LIST) {
1765 if (dtrace_handle_err(g_dtp, &errhandler, NULL) == -1)
1766 dfatal("failed to establish error handler");
1767
1768 if (dtrace_handle_drop(g_dtp, &drophandler, NULL) == -1)
1769 dfatal("failed to establish drop handler");
1770
1771 if (dtrace_handle_proc(g_dtp, &prochandler, NULL) == -1)
1772 dfatal("failed to establish proc handler");
1773
1774 if (dtrace_handle_setopt(g_dtp, &setopthandler, NULL) == -1)
1775 dfatal("failed to establish setopt handler");
1776
1777 if (g_ofp == NULL &&
1778 dtrace_handle_buffered(g_dtp, &bufhandler, NULL) == -1)
1779 dfatal("failed to establish buffered handler");
1780 }
1781
1782 (void) dtrace_getopt(g_dtp, "flowindent", &opt);
1783 g_flowindent = opt != DTRACEOPT_UNSET;
1784
1785 (void) dtrace_getopt(g_dtp, "grabanon", &opt);
1786 g_grabanon = opt != DTRACEOPT_UNSET;
1787
1788 (void) dtrace_getopt(g_dtp, "quiet", &opt);
1789 g_quiet = opt != DTRACEOPT_UNSET;
1790
1791 /*
1792 * Now make a fifth and final pass over the options that have been
1793 * turned into programs and saved in g_cmdv[], performing any mode-
1794 * specific processing. If g_mode is DMODE_EXEC, we will break out
1795 * of the switch() and continue on to the data processing loop. For
1796 * other modes, we will exit dtrace once mode-specific work is done.
1797 */
1798 switch (g_mode) {
1799 case DMODE_EXEC:
1800 if (g_ofile != NULL && (g_ofp = fopen(g_ofile, "a")) == NULL)
1801 fatal("failed to open output file '%s'", g_ofile);
1802
1803 for (i = 0; i < g_cmdc; i++)
1804 exec_prog(&g_cmdv[i]);
1805
1806 if (done && !g_grabanon) {
1807 dtrace_close(g_dtp);
1808 return (g_status);
1809 }
1810 break;
1811
1812 case DMODE_ANON:
1813 if (g_ofile == NULL)
1814 g_ofile = "/kernel/drv/dtrace.conf";
1815
1816 dof_prune(g_ofile); /* strip out any old DOF directives */
1817 etcsystem_prune(); /* string out any forceload directives */
1818
1819 if (g_cmdc == 0) {
1820 dtrace_close(g_dtp);
1821 return (g_status);
1822 }
1823
1824 if ((g_ofp = fopen(g_ofile, "a")) == NULL)
1825 fatal("failed to open output file '%s'", g_ofile);
1826
1827 for (i = 0; i < g_cmdc; i++) {
1828 anon_prog(&g_cmdv[i],
1829 dtrace_dof_create(g_dtp, g_cmdv[i].dc_prog, 0), i);
1830 }
1831
1832 /*
1833 * Dump out the DOF corresponding to the error handler and the
1834 * current options as the final DOF property in the .conf file.
1835 */
1836 anon_prog(NULL, dtrace_geterr_dof(g_dtp), i++);
1837 anon_prog(NULL, dtrace_getopt_dof(g_dtp), i++);
1838
1839 if (fclose(g_ofp) == EOF)
1840 fatal("failed to close output file '%s'", g_ofile);
1841
1842 /*
1843 * These messages would use notice() rather than error(), but
1844 * we don't want them suppressed when -A is run on a D program
1845 * that itself contains a #pragma D option quiet.
1846 */
1847 error("saved anonymous enabling in %s\n", g_ofile);
1848 etcsystem_add();
1849 error("run update_drv(1M) or reboot to enable changes\n");
1850
1851 dtrace_close(g_dtp);
1852 return (g_status);
1853
1854 case DMODE_LINK:
1855#ifndef VBOX /* No link mode. */
1856 if (g_cmdc == 0) {
1857 (void) fprintf(stderr, "%s: -G requires one or more "
1858 "scripts or enabling options\n", g_pname);
1859 dtrace_close(g_dtp);
1860 return (E_USAGE);
1861 }
1862
1863 for (i = 0; i < g_cmdc; i++)
1864 link_prog(&g_cmdv[i]);
1865
1866 if (g_cmdc > 1 && g_ofile != NULL) {
1867 char **objv = alloca(g_cmdc * sizeof (char *));
1868
1869 for (i = 0; i < g_cmdc; i++)
1870 objv[i] = g_cmdv[i].dc_ofile;
1871
1872 if (dtrace_program_link(g_dtp, NULL, DTRACE_D_PROBES,
1873 g_ofile, g_cmdc, objv) != 0)
1874 dfatal(NULL); /* dtrace_errmsg() only */
1875 }
1876
1877 dtrace_close(g_dtp);
1878 return (g_status);
1879#else /* VBOX */
1880 AssertFailed();
1881 dtrace_close(g_dtp);
1882 return (E_USAGE);
1883#endif /* VBOX */
1884
1885 case DMODE_LIST:
1886 if (g_ofile != NULL && (g_ofp = fopen(g_ofile, "a")) == NULL)
1887 fatal("failed to open output file '%s'", g_ofile);
1888
1889 oprintf("%5s %10s %17s %33s %s\n",
1890 "ID", "PROVIDER", "MODULE", "FUNCTION", "NAME");
1891
1892 for (i = 0; i < g_cmdc; i++)
1893 list_prog(&g_cmdv[i]);
1894
1895 if (g_cmdc == 0)
1896 (void) dtrace_probe_iter(g_dtp, NULL, list_probe, NULL);
1897
1898 dtrace_close(g_dtp);
1899 return (g_status);
1900
1901 case DMODE_HEADER:
1902 if (g_cmdc == 0) {
1903 (void) fprintf(stderr, "%s: -h requires one or more "
1904 "scripts or enabling options\n", g_pname);
1905 dtrace_close(g_dtp);
1906 return (E_USAGE);
1907 }
1908
1909 if (g_ofile == NULL) {
1910 char *p;
1911
1912 if (g_cmdc > 1) {
1913 (void) fprintf(stderr, "%s: -h requires an "
1914 "output file if multiple scripts are "
1915 "specified\n", g_pname);
1916 dtrace_close(g_dtp);
1917 return (E_USAGE);
1918 }
1919
1920 if ((p = strrchr(g_cmdv[0].dc_arg, '.')) == NULL ||
1921 strcmp(p, ".d") != 0) {
1922 (void) fprintf(stderr, "%s: -h requires an "
1923 "output file if no scripts are "
1924 "specified\n", g_pname);
1925 dtrace_close(g_dtp);
1926 return (E_USAGE);
1927 }
1928
1929 p[0] = '\0'; /* strip .d suffix */
1930 g_ofile = p = g_cmdv[0].dc_ofile;
1931 (void) snprintf(p, sizeof (g_cmdv[0].dc_ofile),
1932 "%s.h", basename(g_cmdv[0].dc_arg));
1933 }
1934
1935 if ((g_ofp = fopen(g_ofile, "w")) == NULL)
1936 fatal("failed to open header file '%s'", g_ofile);
1937
1938 oprintf("/*\n * Generated by dtrace(1M).\n */\n\n");
1939
1940 if (dtrace_program_header(g_dtp, g_ofp, g_ofile) != 0 ||
1941 fclose(g_ofp) == EOF)
1942 dfatal("failed to create header file %s", g_ofile);
1943
1944 dtrace_close(g_dtp);
1945 return (g_status);
1946 }
1947
1948 /*
1949 * If -a and -Z were not specified and no probes have been matched, no
1950 * probe criteria was specified on the command line and we abort.
1951 */
1952 if (g_total == 0 && !g_grabanon && !(g_cflags & DTRACE_C_ZDEFS))
1953 dfatal("no probes %s\n", g_cmdc ? "matched" : "specified");
1954
1955 /*
1956 * Start tracing. Once we dtrace_go(), reload any options that affect
1957 * our globals in case consuming anonymous state has changed them.
1958 */
1959 go();
1960
1961 (void) dtrace_getopt(g_dtp, "flowindent", &opt);
1962 g_flowindent = opt != DTRACEOPT_UNSET;
1963
1964 (void) dtrace_getopt(g_dtp, "grabanon", &opt);
1965 g_grabanon = opt != DTRACEOPT_UNSET;
1966
1967 (void) dtrace_getopt(g_dtp, "quiet", &opt);
1968 g_quiet = opt != DTRACEOPT_UNSET;
1969
1970 (void) dtrace_getopt(g_dtp, "destructive", &opt);
1971 if (opt != DTRACEOPT_UNSET)
1972 notice("allowing destructive actions\n");
1973
1974#ifndef _MSC_VER
1975 (void) sigemptyset(&act.sa_mask);
1976 act.sa_flags = 0;
1977 act.sa_handler = intr;
1978
1979 if (sigaction(SIGINT, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN)
1980 (void) sigaction(SIGINT, &act, NULL);
1981
1982 if (sigaction(SIGTERM, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN)
1983 (void) sigaction(SIGTERM, &act, NULL);
1984#else
1985 signal(SIGINT, intr);
1986 signal(SIGTERM, intr);
1987#endif
1988
1989 /*
1990 * Now that tracing is active and we are ready to consume trace data,
1991 * continue any grabbed or created processes, setting them running
1992 * using the /proc control mechanism inside of libdtrace.
1993 */
1994#ifndef VBOX
1995 for (i = 0; i < g_psc; i++)
1996 dtrace_proc_continue(g_dtp, g_psv[i]);
1997#endif
1998
1999 g_pslive = g_psc; /* count for prochandler() */
2000
2001 do {
2002 if (!g_intr && !done)
2003 dtrace_sleep(g_dtp);
2004
2005 if (g_newline) {
2006 /*
2007 * Output a newline just to make the output look
2008 * slightly cleaner. Note that we do this even in
2009 * "quiet" mode...
2010 */
2011 oprintf("\n");
2012 g_newline = 0;
2013 }
2014
2015 if (done || g_intr || (g_psc != 0 && g_pslive == 0)) {
2016 done = 1;
2017 if (dtrace_stop(g_dtp) == -1)
2018 dfatal("couldn't stop tracing");
2019 }
2020
2021 switch (dtrace_work(g_dtp, g_ofp, chew, chewrec, NULL)) {
2022 case DTRACE_WORKSTATUS_DONE:
2023 done = 1;
2024 break;
2025 case DTRACE_WORKSTATUS_OKAY:
2026 break;
2027 default:
2028 if (!g_impatient && dtrace_errno(g_dtp) != EINTR)
2029 dfatal("processing aborted");
2030 }
2031
2032 if (g_ofp != NULL && fflush(g_ofp) == EOF)
2033 clearerr(g_ofp);
2034 } while (!done);
2035
2036 oprintf("\n");
2037
2038 if (!g_impatient) {
2039 if (dtrace_aggregate_print(g_dtp, g_ofp, NULL) == -1 &&
2040 dtrace_errno(g_dtp) != EINTR)
2041 dfatal("failed to print aggregations");
2042 }
2043
2044 dtrace_close(g_dtp);
2045 return (g_status);
2046}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette