VirtualBox

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

最後變更 在這個檔案從63207是 63207,由 vboxsync 提交於 9 年 前

dtrace: warnings (gcc)

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

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