dt_cc.c revision 15131f635944423d12704f2e6e51799511ac51cc
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * DTrace D Language Compiler
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The code in this source file implements the main engine for the D language
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compiler. The driver routine for the compiler is dt_compile(), below. The
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compiler operates on either stdio FILEs or in-memory strings as its input
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and can produce either dtrace_prog_t structures from a D program or a single
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dtrace_difo_t structure from a D expression. Multiple entry points are
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * provided as wrappers around dt_compile() for the various input/output pairs.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The compiler itself is implemented across the following source files:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_lex.l - lex scanner
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_grammar.y - yacc grammar
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_parser.c - parse tree creation and semantic checking
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_decl.c - declaration stack processing
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_xlator.c - D translator lookup and creation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_ident.c - identifier and symbol table routines
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_pragma.c - #pragma processing and D pragmas
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_printf.c - D printf() and printa() argument checking and processing
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_cc.c - compiler driver and dtrace_prog_t construction
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_cg.c - DIF code generator
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_as.c - DIF assembler
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dt_dof.c - dtrace_prog_t -> DOF conversion
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Several other source files provide collections of utility routines used by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * these major files. The compiler itself is implemented in multiple passes:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (1) The input program is scanned and parsed by dt_lex.l and dt_grammar.y
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and parse tree nodes are constructed using the routines in dt_parser.c.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This node construction pass is described further in dt_parser.c.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (2) The parse tree is "cooked" by assigning each clause a context (see the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * routine dt_setcontext(), below) based on its probe description and then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * recursively descending the tree performing semantic checking. The cook
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * routines are also implemented in dt_parser.c and described there.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (3) For actions that are DIF expression statements, the DIF code generator
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and assembler are invoked to create a finished DIFO for the statement.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (4) The dtrace_prog_t data structures for the program clauses and actions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * are built, containing pointers to any DIFOs created in step (3).
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (5) The caller invokes a routine in dt_dof.c to convert the finished program
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * into DOF format for use in anonymous tracing or enabling in the kernel.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * In the implementation, steps 2-4 are intertwined in that they are performed
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * in order for each clause as part of a loop that executes over the clauses.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The D compiler currently implements nearly no optimization. The compiler
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * implements integer constant folding as part of pass (1), and a set of very
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * simple peephole optimizations as part of pass (3). As with any C compiler,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a large number of optimizations are possible on both the intermediate data
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * structures and the generated DIF code. These possibilities should be
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * investigated in the context of whether they will have any substantive effect
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * on the overall DTrace probe effect before they are undertaken.
15131f635944423d12704f2e6e51799511ac51ccvboxsync#else /* VBOX */
15131f635944423d12704f2e6e51799511ac51ccvboxsync#endif /* VBOX */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, sizeof (uint64_t)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void *dt_compile(dtrace_hdl_t *, int, dtrace_probespec_t, void *,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_idpragma(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRAGMA_UNUSED, "unused #pragma %s\n", (char *)idp->di_iarg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_stmt_create(dtrace_hdl_t *dtp, dtrace_ecbdesc_t *edp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_attribute_t descattr, dtrace_attribute_t stmtattr)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_stmtdesc_t *sdp = dtrace_stmt_create(dtp, edp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_stmt_action(dtrace_hdl_t *dtp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Utility function to determine if a given action description is destructive.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The dtdo_destructive bit is set for us by the DIF assembler (see dt_as.c).
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACEACT_ISDESTRUCTIVE(ap->dtad_kind) || (ap->dtad_kind ==
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_destructive));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_stmt_append(dtrace_stmtdesc_t *sdp, const dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Make sure that the new statement jibes with the rest of the ECB.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (ap = edp->dted_action; ap != NULL; ap = ap->dtad_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not follow commit( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not follow data-recording action(s)\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (tap = ap; tap != NULL; tap = tap->dtad_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "may not follow commit( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not follow speculate( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not follow commit( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not follow data-recording action(s)\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "may not follow speculate( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "may not follow speculate( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "follow speculate( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Exclude all non data-recording actions.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_CTF &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp, D_DREC_COMM, "data-recording actions "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "may not follow commit( )\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_stmt_add(yypcb->pcb_hdl, yypcb->pcb_prog, sdp) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync longjmp(yypcb->pcb_jmpbuf, dtrace_errno(yypcb->pcb_hdl));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For the first element of an aggregation tuple or for printa(), we create a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * simple DIF program that simply returns the immediate value that is the ID
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * of the aggregation itself. This could be optimized in the future by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * creating a new in-kernel dtad_kind that just returns an integer.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_difconst(dtrace_actdesc_t *ap, uint_t id, dtrace_actkind_t kind)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_difo_t *dp = dt_zalloc(dtp, sizeof (dtrace_difo_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dp->dtdo_buf = dt_alloc(dtp, sizeof (dif_instr_t) * 2);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dp->dtdo_inttab = dt_alloc(dtp, sizeof (uint64_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dp->dtdo_buf == NULL || dp->dtdo_inttab == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dp->dtdo_buf[0] = DIF_INSTR_SETX(0, 1); /* setx DIF_INTEGER[0], %r1 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_clear(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync argc++; /* count up arguments for error messages below */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: %d args passed, 1 expected\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #1 is incompatible with prototype:\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\tprototype: aggregation\n\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_normalize(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int denormal = (strcmp(dnp->dn_ident->di_name, "denormalize") == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync argc++; /* count up arguments for error messages below */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((denormal && argc != 1) || (!denormal && argc != 2)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: %d args passed, %d expected\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #1 is incompatible with prototype:\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\tprototype: aggregation\n\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((normal = anp->dn_list) != NULL && !dt_node_is_scalar(normal)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #2 must be of scalar type\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_trunc(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync argc++; /* count up arguments for error messages below */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: %d args passed, %s expected\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #1 is incompatible with prototype:\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\tprototype: aggregation\n\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #2 must be of scalar type\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_printa(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *format;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync argc++; /* count up arguments for error messages below */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: %d args passed, %d expected\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #%d is incompatible with "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "prototype:\n\tprototype: aggregation\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we have multiple aggregations, we must be sure that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * their key signatures match.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fid->di_id, ((dt_idsig_t *)aid->di_data)->dis_args);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_PRINTA);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_printflike(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #1 is incompatible with prototype:\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\tprototype: string constant\n\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If this is an freopen(), we use an empty string to denote that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * stdout should be restored. For other printf()-like actions, an
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * empty format string is illegal: an empty format string would
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * result in malformed DOF, and the compiler thus flags an empty
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * format string as a compile-time error. To avoid propagating the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * freopen() special case throughout the system, we simply transpose
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * an empty string into a sentinel string (DT_FREOPEN_RESTORE) that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * denotes that stdout should be restored.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Our sentinel is always an invalid argument to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * freopen(), but if it's been manually specified, we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * must fail now instead of when the freopen() is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * actually evaluated.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #1 cannot be \"%s\"\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_validate(sdp->dtsd_fmtdata, DT_PRINTF_EXACTLEN,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dbuf = dt_alloc(dtp, sizeof (dif_instr_t))) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (dp = dt_zalloc(dtp, sizeof (dtrace_difo_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = arg1; anp != NULL; anp = anp->dn_list) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "trace( ) may not be applied to a void expression\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "trace( ) may not be applied to a dynamic expression\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_tracemem(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_is_integer(addr) == 0 && dt_node_is_pointer(addr) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "tracemem( ) argument #1 is incompatible with "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "prototype:\n\tprototype: pointer or integer\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(size, D_TRACEMEM_SIZE, "tracemem( ) argument #2 must "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "be a non-zero positive integral constant expression\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_difo->dtdo_rtype.dtdt_size = size->dn_value;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_stack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *arg0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_options[DTRACEOPT_STACKFRAMES] != DTRACEOPT_UNSET) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_arg = dtp->dt_options[DTRACEOPT_STACKFRAMES];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "mismatch: too many arguments\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(arg0, D_STACK_SIZE, "stack( ) size must be a "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "non-zero positive integral constant expression\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_stack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_ustack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint32_t strsize = 0; /* default string table size */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_t *arg1 = arg0 != NULL ? arg0->dn_list : NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_options[DTRACEOPT_JSTACKFRAMES] != DTRACEOPT_UNSET)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE] != DTRACEOPT_UNSET)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strsize = dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_options[DTRACEOPT_USTACKFRAMES] != DTRACEOPT_UNSET)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(arg0, D_USTACK_FRAMES, "ustack( ) argument #1 "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "must be a non-zero positive integer constant\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(arg1, D_USTACK_STRSIZE, "ustack( ) argument #2 "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "must be a positive integer constant\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(arg1, D_USTACK_PROTO, "ustack( ) prototype "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "mismatch: too many arguments\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_arg = DTRACE_USTACK_ARG(nframes, strsize);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_ustack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_setopt(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The prototype guarantees that we are called with either one or
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * two arguments, and that any arguments that are present are strings.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_symmod_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(kind == DTRACEACT_SYM || kind == DTRACEACT_MOD ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kind == DTRACEACT_USYM || kind == DTRACEACT_UMOD ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (uint64_t);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_symmod(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod_args(dtp, ap, dnp->dn_args, kind);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_ftruncate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Library actions need a DIFO that serves as an argument. As
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ftruncate() doesn't take an argument, we generate the constant 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * in a DIFO; this constant will be ignored when the ftruncate() is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * processed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_stop(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_breakpoint(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_panic(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_chill(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_raise(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_exit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (int);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_speculate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_commit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_action_discard(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile_fun(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_FREOPEN);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_MOD);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_SYM);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UADDR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UMOD);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_USYM);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp->dn_expr, D_UNKNOWN, "tracing function %s( ) is "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not yet supported\n", dnp->dn_expr->dn_ident->di_name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile_exp(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile_agg(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the aggregation has no aggregating function applied to it, then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this statement has no effect. Flag this as a programming error.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp, D_AGG_NULL, "expression has null effect: @%s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp->dn_aggfun, D_AGG_SCALAR, "%s( ) argument #1 must "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The ID of the aggregation itself is implicitly recorded as the first
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * member of each aggregation tuple so we can distinguish them later.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_action_difconst(ap, aid->di_id, DTRACEACT_DIFEXPR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (anp = dnp->dn_aggtup; anp != NULL; anp = anp->dn_list) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For linear quantization, we have between two and four
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arguments in addition to the expression:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arg1 => Base value
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arg2 => Limit value
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arg3 => Quantization level step size (defaults to 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arg4 => Quantization increment value (defaults to 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_t *arg1 = dnp->dn_aggfun->dn_args->dn_list;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #1 must be an integer constant\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #1 must be a 32-bit quantity\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #2 must be an integer constant\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (limitval < INT32_MIN || limitval > INT32_MAX) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #2 must be a 32-bit quantity\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "lquantize( ) base (argument #1) must be less "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "than limit (argument #2)\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #3 must be a non-zero positive "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "integer constant\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #3 must be a 16-bit quantity\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "lquantize( ) step (argument #3) too large: must "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "have at least one quantization level\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp, D_LQUANT_STEPSMALL, "lquantize( ) step "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "(argument #3) too small: number of quantization "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "levels must be a 16-bit quantity\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This is the first time we've seen an lquantize()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * for this aggregation; we'll store our argument
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * as the auxiliary signature information.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we have seen this lquantize() before and the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * argument doesn't match the original argument, pick
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the original argument apart to concisely report the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * mismatch.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "base (argument #1) doesn't match previous "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "declaration: expected %d, found %d\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "limit (argument #2) doesn't match previous"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync " declaration: expected %d, found %d\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "step (argument #3) doesn't match previous "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "declaration: expected %d, found %d\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We shouldn't be able to get here -- one of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * parameters must be mismatched if the arguments
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * didn't match.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "(argument #%d) must be of scalar type\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "mismatch: %d args passed, at most %d expected",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile_one_clause(dtrace_hdl_t *dtp, dt_node_t *cnp, dt_node_t *pnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((edp = dt_ecbdesc_create(dtp, pnp->dn_desc)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dnp = cnp->dn_acts; dnp != NULL; dnp = dnp->dn_list) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sdp = dt_stmt_create(dtp, edp, cnp->dn_ctxattr, cnp->dn_attr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnerror(dnp, D_UNKNOWN, "internal error -- node kind "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile_clause(dtrace_hdl_t *dtp, dt_node_t *cnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pnp = cnp->dn_pdescs; pnp != NULL; pnp = pnp->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_setcontext(dtrace_hdl_t *dtp, dtrace_probedesc_t *pdp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Both kernel and pid based providers are allowed to have names
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ending with what could be interpreted as a number. We assume it's
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a pid and that we may need to dynamically create probes for
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that process if:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (1) The provider doesn't exist, or,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (2) The provider exists and has DTRACE_PRIV_PROC privilege.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On an error, dt_pid_create_probes() will set the error message
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and tag -- we just have to longjmp() out of here.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (isdigit(pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pvp->pv_desc.dtvd_priv.dtpp_flags & DTRACE_PRIV_PROC) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Call dt_probe_info() to get the probe arguments and attributes. If
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a representative probe is found, set 'pap' to the probe provider's
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * attributes. Otherwise set 'pap' to default Unstable attributes.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((prp = dt_probe_info(dtp, pdp, &yypcb->pcb_pinfo)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(&yypcb->pcb_pinfo, sizeof (dtrace_probeinfo_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (err == EDT_NOPROBE && !(yypcb->pcb_cflags & DTRACE_C_ZDEFS)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PDESC_ZERO, "probe description %s:%s:%s:%s does not "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "match any probes\n", pdp->dtpd_provider, pdp->dtpd_mod,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (err != EDT_NOPROBE && err != EDT_UNSTABLE && err != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PDESC_INVAL, "%s\n", dtrace_errmsg(dtp, err));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("set context to %s:%s:%s:%s [%u] prp=%p attr=%s argc=%d\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pdp->dtpd_id, (void *)prp, dt_attr_str(yypcb->pcb_pinfo.dtp_attr,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync attrstr, sizeof (attrstr)), yypcb->pcb_pinfo.dtp_argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Reset the stability attributes of D global variables that vary
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * based on the attributes of the provider and context itself.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, "probeprov")) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, "probemod")) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, "probefunc")) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, "probename")) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, "args")) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Reset context-dependent variables and state at the end of cooking a D probe
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * definition clause. This ensures that external declarations between clauses
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * do not reference any stale context-dependent data from the previous clause.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync static const char *const cvars[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "probeprov", "probemod", "probefunc", "probename", "args", NULL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((idp = dt_idhash_lookup(dtp->dt_globals, cvars[i])) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_reduceid(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (idp->di_vers != 0 && idp->di_vers > dtp->dt_vmax)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When dtrace_setopt() is called for "version", it calls dt_reduce() to remove
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any identifiers or translators that have been previously defined as bound to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a version greater than the specified version. Therefore, in our current
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * version implementation, establishing a binding is a one-way transformation.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * In addition, no versioning is currently provided for types as our .d library
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * files do not define any types and we reserve prefixes DTRACE_ and dtrace_
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * for our exclusive use. If required, type versioning will require more work.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0); /* no reduction necessary */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_version_num2str(v, s, sizeof (s)));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = nxp) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dxp->dx_souid.di_vers != 0 && dxp->dx_souid.di_vers > v) ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (dxp->dx_ptrid.di_vers != 0 && dxp->dx_ptrid.di_vers > v))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_macros, (dt_idhash_f *)dt_reduceid, dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_aggs, (dt_idhash_f *)dt_reduceid, dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_globals, (dt_idhash_f *)dt_reduceid, dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_tls, (dt_idhash_f *)dt_reduceid, dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Fork and exec the cpp(1) preprocessor to run over the specified input file,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and return a FILE handle for the cpp output. We use the /dev/fd filesystem
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * here to simplify the code by leveraging file descriptor inheritance.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char **argv = malloc(sizeof (char *) * (argc + 5));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char ipath[20], opath[20]; /* big enough for /dev/fd/ + INT_MAX + \0 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char verdef[32]; /* big enough for -D__SUNW_D_VERSION=0x%08x + \0 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the input is a seekable file, see if it is an interpreter file.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we see #!, seek past the first line because cpp will choke on it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We start cpp just prior to the \n at the end of this line so that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * it still sees the newline, ensuring that #line values are correct.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (isatty(fileno(ifp)) == 0 && (off = ftello64(ifp)) != -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((c = fgetc(ifp)) == '#' && (c = fgetc(ifp)) == '!') {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (c == '\n')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(ipath, sizeof (ipath), "/dev/fd/%d", fileno(ifp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(opath, sizeof (opath), "/dev/fd/%d", fileno(ofp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(dtp->dt_cpp_argv, argv, sizeof (char *) * argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * libdtrace must be able to be embedded in other programs that may
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * include application-specific signal handlers. Therefore, if we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * need to fork to run cpp(1), we must avoid generating a SIGCHLD
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that could confuse the containing application. To do this,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we block SIGCHLD and reset its disposition to SIG_DFL.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We restore our signal state once we are done.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pid == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("waiting for %s (PID %d)\n", dtp->dt_cpp_path,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while (waitpid(pid, &wstat, 0) == -1 && errno == EINTR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("%s returned exit status 0x%x\n", dtp->dt_cpp_path, wstat);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync estat = WIFEXITED(wstat) ? WEXITSTATUS(wstat) : -1;
15131f635944423d12704f2e6e51799511ac51ccvboxsync#else /* VBOX */
15131f635944423d12704f2e6e51799511ac51ccvboxsync#endif /* VBOX */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_lib_depend_error(dtrace_hdl_t *dtp, const char *format, ...)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_set_errmsg(dtp, NULL, NULL, NULL, 0, format, ap);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_lib_depend_add(dtrace_hdl_t *dtp, dt_list_t *dlp, const char *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *end;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dld = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dld->dtld_libpath = dt_alloc(dtp, MAXPATHLEN)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strlcpy(dld->dtld_libpath, arg, end - arg + 2);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_lib_depend_lookup(dt_list_t *dld, const char *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Go through all the library files, and, if any library dependencies exist for
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that file, add it to that node's list of dependents. The result of this
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * will be a graph which can then be topologically sorted to produce a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compilation order.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dpld = dt_list_next(&dld->dtld_dependencies); dpld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "Invalid library dependency in %s: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dt_lib_depend_add(dtp, &dlda->dtld_dependents,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_topo_sort(dtrace_hdl_t *dtp, dt_lib_depend_t *dld, int *count)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((new = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((new->dtld_library = strdup(dld->dtld_library)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("library %s sorted (%d/%d)\n", new->dtld_library,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Perform a topological sort of the graph that hangs off
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dtp->dt_lib_dep. The result of this process will be a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * dependency ordered list located at dtp->dt_lib_dep_sorted.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Check the graph for cycles. If an ancestor's finishing time is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * less than any of its dependent's finishing times then a back edge
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * exists in the graph and this is a cycle.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep_sorted,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "Cyclic dependency detected: %s => %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while ((dld = dt_list_next(&dtp->dt_lib_dep)) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while ((dlda = dt_list_next(&dld->dtld_dependencies)) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while ((dlda = dt_list_next(&dld->dtld_dependents)) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Open all of the .d library files found in the specified directory and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compile each one in topological order to cache its inlines and translators,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * etc. We silently ignore any missing directories and other files found
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * therein. We only fail (and thereby fail dt_load_libs()) if we fail to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compile a library and the error is something other than #pragma D depends_on.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Dependency errors are silently ignored to permit a library directory to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * contain libraries which may not be accessible depending on our privileges.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *p;
15131f635944423d12704f2e6e51799511ac51ccvboxsync const char *p;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
15131f635944423d12704f2e6e51799511ac51ccvboxsync dt_dprintf("skipping lib dir %s: %s\n", path, RTErrGetShort(rc));
15131f635944423d12704f2e6e51799511ac51ccvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /* First, parse each file for library dependencies. */
15131f635944423d12704f2e6e51799511ac51ccvboxsync while (RT_SUCCESS(RTDirRead(pDir, &DirEntry, 0))) {
15131f635944423d12704f2e6e51799511ac51ccvboxsync const char *d_name;
15131f635944423d12704f2e6e51799511ac51ccvboxsync } FakeDirEntry = { DirEntry.szName }, *dp = &FakeDirEntry;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d"))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue; /* skip any filename not ending in .d */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Finish building the graph containing the library dependencies
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and perform a topological sort to generate an ordered list
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * for compilation.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dld = dt_list_next(&dtp->dt_lib_dep_sorted); dld != NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((fp = fopen(dld->dtld_library, "r")) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pgp = dtrace_program_fcompile(dtp, fp, DTRACE_C_EMPTY, 0, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pgp == NULL && (dtp->dt_errno != EDT_COMPILER ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Load the contents of any appropriate DTrace .d library files. These files
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * contain inlines and translators that will be cached by the compiler. We
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * defer this activity until the first compile to permit libdtrace clients to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * add their own library directories and so that we can properly report errors.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0); /* libraries already processed */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcb.pcb_sflagv = argc ? calloc(argc, sizeof (ushort_t)) : NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (yypcb->pcb_sargc != 0 && yypcb->pcb_sflagv == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yypcb->pcb_idents = dt_idhash_create("ambiguous", NULL, 0, 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yypcb->pcb_locals = dt_idhash_create("clause local", NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (yypcb->pcb_idents == NULL || yypcb->pcb_locals == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Invoke the parser to evaluate the D source code. If any errors
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * occur during parsing, an error function will be called and we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * will longjmp back to pcb_jmpbuf to abort. If parsing succeeds,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we optionally display the parse tree if debugging is enabled.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_EMPTY, "empty D program translation unit\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 1))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(yypcb->pcb_pragmas, dt_idpragma, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (argc > 1 && !(yypcb->pcb_cflags & DTRACE_C_ARGREF) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_MACRO_UNUSED, "extraneous argument '%s' ($%d is "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we have successfully created a parse tree for a D program, loop
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * over the clauses and actions and instantiate the corresponding
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * libdtrace program. If we are parsing a D expression, then we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * simply run the code generator and assembler on the resulting tree.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_EMPTY, "empty D program translation unit\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((yypcb->pcb_prog = dt_program_create(dtp)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yypcb->pcb_prog->dp_xrefslen = yypcb->pcb_asxreflen;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_node_cook(yypcb->pcb_root, DT_IDFLG_REF);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddp = (dt_decl_t *)yypcb->pcb_root; /* root is really a decl */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 3))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("failed to update CTF cache: %s\n", strerror(errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_ddefs_fd != -1 && (ftruncate64(dtp->dt_ddefs_fd, 0) == -1 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_write(dtp->dt_ddefs->dm_ctfp, dtp->dt_ddefs_fd) == CTF_ERR))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("failed to update CTF cache: %s\n", strerror(errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) fclose(yypcb->pcb_fileptr); /* close dt_preproc() file */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[])
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_PROBESPEC_NAME, NULL, cflags, argc, argv, fp, NULL));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_type_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_typeinfo_t *dtt)