17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5c9d6cd77Sjhaslam * Common Development and Distribution License (the "License"). 6c9d6cd77Sjhaslam * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21900524f3Sahl 227c478bd9Sstevel@tonic-gate /* 23*c9a6ea2eSBryan Cantrill * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * DTrace D Language Compiler 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * The code in this source file implements the main engine for the D language 307c478bd9Sstevel@tonic-gate * compiler. The driver routine for the compiler is dt_compile(), below. The 317c478bd9Sstevel@tonic-gate * compiler operates on either stdio FILEs or in-memory strings as its input 327c478bd9Sstevel@tonic-gate * and can produce either dtrace_prog_t structures from a D program or a single 337c478bd9Sstevel@tonic-gate * dtrace_difo_t structure from a D expression. Multiple entry points are 347c478bd9Sstevel@tonic-gate * provided as wrappers around dt_compile() for the various input/output pairs. 357c478bd9Sstevel@tonic-gate * The compiler itself is implemented across the following source files: 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * dt_lex.l - lex scanner 387c478bd9Sstevel@tonic-gate * dt_grammar.y - yacc grammar 397c478bd9Sstevel@tonic-gate * dt_parser.c - parse tree creation and semantic checking 407c478bd9Sstevel@tonic-gate * dt_decl.c - declaration stack processing 417c478bd9Sstevel@tonic-gate * dt_xlator.c - D translator lookup and creation 427c478bd9Sstevel@tonic-gate * dt_ident.c - identifier and symbol table routines 437c478bd9Sstevel@tonic-gate * dt_pragma.c - #pragma processing and D pragmas 447c478bd9Sstevel@tonic-gate * dt_printf.c - D printf() and printa() argument checking and processing 457c478bd9Sstevel@tonic-gate * dt_cc.c - compiler driver and dtrace_prog_t construction 467c478bd9Sstevel@tonic-gate * dt_cg.c - DIF code generator 477c478bd9Sstevel@tonic-gate * dt_as.c - DIF assembler 487c478bd9Sstevel@tonic-gate * dt_dof.c - dtrace_prog_t -> DOF conversion 497c478bd9Sstevel@tonic-gate * 507c478bd9Sstevel@tonic-gate * Several other source files provide collections of utility routines used by 517c478bd9Sstevel@tonic-gate * these major files. The compiler itself is implemented in multiple passes: 527c478bd9Sstevel@tonic-gate * 537c478bd9Sstevel@tonic-gate * (1) The input program is scanned and parsed by dt_lex.l and dt_grammar.y 547c478bd9Sstevel@tonic-gate * and parse tree nodes are constructed using the routines in dt_parser.c. 557c478bd9Sstevel@tonic-gate * This node construction pass is described further in dt_parser.c. 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * (2) The parse tree is "cooked" by assigning each clause a context (see the 587c478bd9Sstevel@tonic-gate * routine dt_setcontext(), below) based on its probe description and then 597c478bd9Sstevel@tonic-gate * recursively descending the tree performing semantic checking. The cook 607c478bd9Sstevel@tonic-gate * routines are also implemented in dt_parser.c and described there. 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * (3) For actions that are DIF expression statements, the DIF code generator 637c478bd9Sstevel@tonic-gate * and assembler are invoked to create a finished DIFO for the statement. 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * (4) The dtrace_prog_t data structures for the program clauses and actions 667c478bd9Sstevel@tonic-gate * are built, containing pointers to any DIFOs created in step (3). 677c478bd9Sstevel@tonic-gate * 687c478bd9Sstevel@tonic-gate * (5) The caller invokes a routine in dt_dof.c to convert the finished program 697c478bd9Sstevel@tonic-gate * into DOF format for use in anonymous tracing or enabling in the kernel. 707c478bd9Sstevel@tonic-gate * 717c478bd9Sstevel@tonic-gate * In the implementation, steps 2-4 are intertwined in that they are performed 727c478bd9Sstevel@tonic-gate * in order for each clause as part of a loop that executes over the clauses. 737c478bd9Sstevel@tonic-gate * 747c478bd9Sstevel@tonic-gate * The D compiler currently implements nearly no optimization. The compiler 757c478bd9Sstevel@tonic-gate * implements integer constant folding as part of pass (1), and a set of very 767c478bd9Sstevel@tonic-gate * simple peephole optimizations as part of pass (3). As with any C compiler, 777c478bd9Sstevel@tonic-gate * a large number of optimizations are possible on both the intermediate data 787c478bd9Sstevel@tonic-gate * structures and the generated DIF code. These possibilities should be 797c478bd9Sstevel@tonic-gate * investigated in the context of whether they will have any substantive effect 807c478bd9Sstevel@tonic-gate * on the overall DTrace probe effect before they are undertaken. 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #include <sys/types.h> 847c478bd9Sstevel@tonic-gate #include <sys/wait.h> 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #include <assert.h> 877c478bd9Sstevel@tonic-gate #include <strings.h> 887c478bd9Sstevel@tonic-gate #include <signal.h> 897c478bd9Sstevel@tonic-gate #include <unistd.h> 907c478bd9Sstevel@tonic-gate #include <stdlib.h> 917c478bd9Sstevel@tonic-gate #include <stdio.h> 927c478bd9Sstevel@tonic-gate #include <errno.h> 937c478bd9Sstevel@tonic-gate #include <ucontext.h> 947c478bd9Sstevel@tonic-gate #include <limits.h> 957c478bd9Sstevel@tonic-gate #include <ctype.h> 967c478bd9Sstevel@tonic-gate #include <dirent.h> 977c478bd9Sstevel@tonic-gate #include <dt_module.h> 981a7c1b72Smws #include <dt_program.h> 997c478bd9Sstevel@tonic-gate #include <dt_provider.h> 1007c478bd9Sstevel@tonic-gate #include <dt_printf.h> 1017c478bd9Sstevel@tonic-gate #include <dt_pid.h> 1027c478bd9Sstevel@tonic-gate #include <dt_grammar.h> 1037c478bd9Sstevel@tonic-gate #include <dt_ident.h> 1047c478bd9Sstevel@tonic-gate #include <dt_string.h> 1057c478bd9Sstevel@tonic-gate #include <dt_impl.h> 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate static const dtrace_diftype_t dt_void_rtype = { 1087c478bd9Sstevel@tonic-gate DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, 0 1097c478bd9Sstevel@tonic-gate }; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate static const dtrace_diftype_t dt_int_rtype = { 1127c478bd9Sstevel@tonic-gate DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, sizeof (uint64_t) 1137c478bd9Sstevel@tonic-gate }; 1147c478bd9Sstevel@tonic-gate 115c9d6cd77Sjhaslam static void *dt_compile(dtrace_hdl_t *, int, dtrace_probespec_t, void *, 116c9d6cd77Sjhaslam uint_t, int, char *const[], FILE *, const char *); 117c9d6cd77Sjhaslam 118c9d6cd77Sjhaslam 1197c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1207c478bd9Sstevel@tonic-gate static int 1217c478bd9Sstevel@tonic-gate dt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored) 1227c478bd9Sstevel@tonic-gate { 1237c478bd9Sstevel@tonic-gate idp->di_flags &= ~(DT_IDFLG_REF | DT_IDFLG_MOD | 1247c478bd9Sstevel@tonic-gate DT_IDFLG_DIFR | DT_IDFLG_DIFW); 1257c478bd9Sstevel@tonic-gate return (0); 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1297c478bd9Sstevel@tonic-gate static int 1307c478bd9Sstevel@tonic-gate dt_idpragma(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored) 1317c478bd9Sstevel@tonic-gate { 1327c478bd9Sstevel@tonic-gate yylineno = idp->di_lineno; 1337c478bd9Sstevel@tonic-gate xyerror(D_PRAGMA_UNUSED, "unused #pragma %s\n", (char *)idp->di_iarg); 1347c478bd9Sstevel@tonic-gate return (0); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate static dtrace_stmtdesc_t * 1387c478bd9Sstevel@tonic-gate dt_stmt_create(dtrace_hdl_t *dtp, dtrace_ecbdesc_t *edp, 1397c478bd9Sstevel@tonic-gate dtrace_attribute_t descattr, dtrace_attribute_t stmtattr) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate dtrace_stmtdesc_t *sdp = dtrace_stmt_create(dtp, edp); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate if (sdp == NULL) 1447c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate assert(yypcb->pcb_stmt == NULL); 1477c478bd9Sstevel@tonic-gate yypcb->pcb_stmt = sdp; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate sdp->dtsd_descattr = descattr; 1507c478bd9Sstevel@tonic-gate sdp->dtsd_stmtattr = stmtattr; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate return (sdp); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate static dtrace_actdesc_t * 1567c478bd9Sstevel@tonic-gate dt_stmt_action(dtrace_hdl_t *dtp, dtrace_stmtdesc_t *sdp) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate dtrace_actdesc_t *new; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate if ((new = dtrace_stmt_action(dtp, sdp)) == NULL) 1617c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate return (new); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * Utility function to determine if a given action description is destructive. 1687c478bd9Sstevel@tonic-gate * The dtdo_destructive bit is set for us by the DIF assembler (see dt_as.c). 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate static int 1717c478bd9Sstevel@tonic-gate dt_action_destructive(const dtrace_actdesc_t *ap) 1727c478bd9Sstevel@tonic-gate { 1737c478bd9Sstevel@tonic-gate return (DTRACEACT_ISDESTRUCTIVE(ap->dtad_kind) || (ap->dtad_kind == 1747c478bd9Sstevel@tonic-gate DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_destructive)); 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate static void 1787c478bd9Sstevel@tonic-gate dt_stmt_append(dtrace_stmtdesc_t *sdp, const dt_node_t *dnp) 1797c478bd9Sstevel@tonic-gate { 1807c478bd9Sstevel@tonic-gate dtrace_ecbdesc_t *edp = sdp->dtsd_ecbdesc; 1817c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap, *tap; 1827c478bd9Sstevel@tonic-gate int commit = 0; 1837c478bd9Sstevel@tonic-gate int speculate = 0; 1847c478bd9Sstevel@tonic-gate int datarec = 0; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Make sure that the new statement jibes with the rest of the ECB. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate for (ap = edp->dted_action; ap != NULL; ap = ap->dtad_next) { 1907c478bd9Sstevel@tonic-gate if (ap->dtad_kind == DTRACEACT_COMMIT) { 1917c478bd9Sstevel@tonic-gate if (commit) { 1927c478bd9Sstevel@tonic-gate dnerror(dnp, D_COMM_COMM, "commit( ) may " 1937c478bd9Sstevel@tonic-gate "not follow commit( )\n"); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate if (datarec) { 1977c478bd9Sstevel@tonic-gate dnerror(dnp, D_COMM_DREC, "commit( ) may " 1987c478bd9Sstevel@tonic-gate "not follow data-recording action(s)\n"); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate for (tap = ap; tap != NULL; tap = tap->dtad_next) { 2027c478bd9Sstevel@tonic-gate if (!DTRACEACT_ISAGG(tap->dtad_kind)) 2037c478bd9Sstevel@tonic-gate continue; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate dnerror(dnp, D_AGG_COMM, "aggregating actions " 2067c478bd9Sstevel@tonic-gate "may not follow commit( )\n"); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate commit = 1; 2107c478bd9Sstevel@tonic-gate continue; 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (ap->dtad_kind == DTRACEACT_SPECULATE) { 2147c478bd9Sstevel@tonic-gate if (speculate) { 2157c478bd9Sstevel@tonic-gate dnerror(dnp, D_SPEC_SPEC, "speculate( ) may " 2167c478bd9Sstevel@tonic-gate "not follow speculate( )\n"); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if (commit) { 2207c478bd9Sstevel@tonic-gate dnerror(dnp, D_SPEC_COMM, "speculate( ) may " 2217c478bd9Sstevel@tonic-gate "not follow commit( )\n"); 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate if (datarec) { 2257c478bd9Sstevel@tonic-gate dnerror(dnp, D_SPEC_DREC, "speculate( ) may " 2267c478bd9Sstevel@tonic-gate "not follow data-recording action(s)\n"); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate speculate = 1; 2307c478bd9Sstevel@tonic-gate continue; 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if (DTRACEACT_ISAGG(ap->dtad_kind)) { 2347c478bd9Sstevel@tonic-gate if (speculate) { 2357c478bd9Sstevel@tonic-gate dnerror(dnp, D_AGG_SPEC, "aggregating actions " 2367c478bd9Sstevel@tonic-gate "may not follow speculate( )\n"); 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate datarec = 1; 2407c478bd9Sstevel@tonic-gate continue; 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate if (speculate) { 2447c478bd9Sstevel@tonic-gate if (dt_action_destructive(ap)) { 2457c478bd9Sstevel@tonic-gate dnerror(dnp, D_ACT_SPEC, "destructive actions " 2467c478bd9Sstevel@tonic-gate "may not follow speculate( )\n"); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate if (ap->dtad_kind == DTRACEACT_EXIT) { 2507c478bd9Sstevel@tonic-gate dnerror(dnp, D_EXIT_SPEC, "exit( ) may not " 2517c478bd9Sstevel@tonic-gate "follow speculate( )\n"); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * Exclude all non data-recording actions. 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate if (dt_action_destructive(ap) || 2597c478bd9Sstevel@tonic-gate ap->dtad_kind == DTRACEACT_DISCARD) 2607c478bd9Sstevel@tonic-gate continue; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate if (ap->dtad_kind == DTRACEACT_DIFEXPR && 2637c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_CTF && 2647c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype.dtdt_size == 0) 2657c478bd9Sstevel@tonic-gate continue; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (commit) { 2687c478bd9Sstevel@tonic-gate dnerror(dnp, D_DREC_COMM, "data-recording actions " 2697c478bd9Sstevel@tonic-gate "may not follow commit( )\n"); 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate if (!speculate) 2737c478bd9Sstevel@tonic-gate datarec = 1; 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate if (dtrace_stmt_add(yypcb->pcb_hdl, yypcb->pcb_prog, sdp) != 0) 2777c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, dtrace_errno(yypcb->pcb_hdl)); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate if (yypcb->pcb_stmt == sdp) 2807c478bd9Sstevel@tonic-gate yypcb->pcb_stmt = NULL; 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * For the first element of an aggregation tuple or for printa(), we create a 2857c478bd9Sstevel@tonic-gate * simple DIF program that simply returns the immediate value that is the ID 2867c478bd9Sstevel@tonic-gate * of the aggregation itself. This could be optimized in the future by 2877c478bd9Sstevel@tonic-gate * creating a new in-kernel dtad_kind that just returns an integer. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate static void 2907c478bd9Sstevel@tonic-gate dt_action_difconst(dtrace_actdesc_t *ap, uint_t id, dtrace_actkind_t kind) 2917c478bd9Sstevel@tonic-gate { 2921a7c1b72Smws dtrace_hdl_t *dtp = yypcb->pcb_hdl; 2931a7c1b72Smws dtrace_difo_t *dp = dt_zalloc(dtp, sizeof (dtrace_difo_t)); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (dp == NULL) 2967c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 2977c478bd9Sstevel@tonic-gate 2981a7c1b72Smws dp->dtdo_buf = dt_alloc(dtp, sizeof (dif_instr_t) * 2); 2991a7c1b72Smws dp->dtdo_inttab = dt_alloc(dtp, sizeof (uint64_t)); 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate if (dp->dtdo_buf == NULL || dp->dtdo_inttab == NULL) { 3021a7c1b72Smws dt_difo_free(dtp, dp); 3037c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate dp->dtdo_buf[0] = DIF_INSTR_SETX(0, 1); /* setx DIF_INTEGER[0], %r1 */ 3077c478bd9Sstevel@tonic-gate dp->dtdo_buf[1] = DIF_INSTR_RET(1); /* ret %r1 */ 3087c478bd9Sstevel@tonic-gate dp->dtdo_len = 2; 3097c478bd9Sstevel@tonic-gate dp->dtdo_inttab[0] = id; 3107c478bd9Sstevel@tonic-gate dp->dtdo_intlen = 1; 3117c478bd9Sstevel@tonic-gate dp->dtdo_rtype = dt_int_rtype; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate ap->dtad_difo = dp; 3147c478bd9Sstevel@tonic-gate ap->dtad_kind = kind; 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate static void 3187c478bd9Sstevel@tonic-gate dt_action_clear(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 3197c478bd9Sstevel@tonic-gate { 3207c478bd9Sstevel@tonic-gate dt_ident_t *aid; 3217c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap; 3227c478bd9Sstevel@tonic-gate dt_node_t *anp; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN]; 3257c478bd9Sstevel@tonic-gate int argc = 0; 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) 3287c478bd9Sstevel@tonic-gate argc++; /* count up arguments for error messages below */ 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate if (argc != 1) { 3317c478bd9Sstevel@tonic-gate dnerror(dnp, D_CLEAR_PROTO, 3327c478bd9Sstevel@tonic-gate "%s( ) prototype mismatch: %d args passed, 1 expected\n", 3337c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, argc); 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate anp = dnp->dn_args; 3377c478bd9Sstevel@tonic-gate assert(anp != NULL); 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate if (anp->dn_kind != DT_NODE_AGG) { 3407c478bd9Sstevel@tonic-gate dnerror(dnp, D_CLEAR_AGGARG, 3417c478bd9Sstevel@tonic-gate "%s( ) argument #1 is incompatible with prototype:\n" 3427c478bd9Sstevel@tonic-gate "\tprototype: aggregation\n\t argument: %s\n", 3437c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, 3447c478bd9Sstevel@tonic-gate dt_node_type_name(anp, n, sizeof (n))); 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate aid = anp->dn_ident; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { 3507c478bd9Sstevel@tonic-gate dnerror(dnp, D_CLEAR_AGGBAD, 3517c478bd9Sstevel@tonic-gate "undefined aggregation: @%s\n", aid->di_name); 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 3557c478bd9Sstevel@tonic-gate dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); 3567c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_CLEAR; 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate static void 3607c478bd9Sstevel@tonic-gate dt_action_normalize(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 3617c478bd9Sstevel@tonic-gate { 3627c478bd9Sstevel@tonic-gate dt_ident_t *aid; 3637c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap; 3647c478bd9Sstevel@tonic-gate dt_node_t *anp, *normal; 3657c478bd9Sstevel@tonic-gate int denormal = (strcmp(dnp->dn_ident->di_name, "denormalize") == 0); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN]; 3687c478bd9Sstevel@tonic-gate int argc = 0; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) 3717c478bd9Sstevel@tonic-gate argc++; /* count up arguments for error messages below */ 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if ((denormal && argc != 1) || (!denormal && argc != 2)) { 3747c478bd9Sstevel@tonic-gate dnerror(dnp, D_NORMALIZE_PROTO, 3757c478bd9Sstevel@tonic-gate "%s( ) prototype mismatch: %d args passed, %d expected\n", 3767c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, argc, denormal ? 1 : 2); 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate anp = dnp->dn_args; 3807c478bd9Sstevel@tonic-gate assert(anp != NULL); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (anp->dn_kind != DT_NODE_AGG) { 3837c478bd9Sstevel@tonic-gate dnerror(dnp, D_NORMALIZE_AGGARG, 3847c478bd9Sstevel@tonic-gate "%s( ) argument #1 is incompatible with prototype:\n" 3857c478bd9Sstevel@tonic-gate "\tprototype: aggregation\n\t argument: %s\n", 3867c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, 3877c478bd9Sstevel@tonic-gate dt_node_type_name(anp, n, sizeof (n))); 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate if ((normal = anp->dn_list) != NULL && !dt_node_is_scalar(normal)) { 3917c478bd9Sstevel@tonic-gate dnerror(dnp, D_NORMALIZE_SCALAR, 3927c478bd9Sstevel@tonic-gate "%s( ) argument #2 must be of scalar type\n", 3937c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name); 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate aid = anp->dn_ident; 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { 3997c478bd9Sstevel@tonic-gate dnerror(dnp, D_NORMALIZE_AGGBAD, 4007c478bd9Sstevel@tonic-gate "undefined aggregation: @%s\n", aid->di_name); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 4047c478bd9Sstevel@tonic-gate dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate if (denormal) { 4077c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_DENORMALIZE; 4087c478bd9Sstevel@tonic-gate return; 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_NORMALIZE; 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate assert(normal != NULL); 4147c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 4157c478bd9Sstevel@tonic-gate dt_cg(yypcb, normal); 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 4187c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_LIBACT; 4197c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_NORMALIZE; 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate static void 4237c478bd9Sstevel@tonic-gate dt_action_trunc(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate dt_ident_t *aid; 4267c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap; 4277c478bd9Sstevel@tonic-gate dt_node_t *anp, *trunc; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN]; 4307c478bd9Sstevel@tonic-gate int argc = 0; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) 4337c478bd9Sstevel@tonic-gate argc++; /* count up arguments for error messages below */ 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate if (argc > 2 || argc < 1) { 4367c478bd9Sstevel@tonic-gate dnerror(dnp, D_TRUNC_PROTO, 4377c478bd9Sstevel@tonic-gate "%s( ) prototype mismatch: %d args passed, %s expected\n", 4387c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, argc, 4397c478bd9Sstevel@tonic-gate argc < 1 ? "at least 1" : "no more than 2"); 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate anp = dnp->dn_args; 4437c478bd9Sstevel@tonic-gate assert(anp != NULL); 4447c478bd9Sstevel@tonic-gate trunc = anp->dn_list; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if (anp->dn_kind != DT_NODE_AGG) { 4477c478bd9Sstevel@tonic-gate dnerror(dnp, D_TRUNC_AGGARG, 4487c478bd9Sstevel@tonic-gate "%s( ) argument #1 is incompatible with prototype:\n" 4497c478bd9Sstevel@tonic-gate "\tprototype: aggregation\n\t argument: %s\n", 4507c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, 4517c478bd9Sstevel@tonic-gate dt_node_type_name(anp, n, sizeof (n))); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate if (argc == 2) { 4557c478bd9Sstevel@tonic-gate assert(trunc != NULL); 4567c478bd9Sstevel@tonic-gate if (!dt_node_is_scalar(trunc)) { 4577c478bd9Sstevel@tonic-gate dnerror(dnp, D_TRUNC_SCALAR, 4587c478bd9Sstevel@tonic-gate "%s( ) argument #2 must be of scalar type\n", 4597c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name); 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate } 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate aid = anp->dn_ident; 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { 4667c478bd9Sstevel@tonic-gate dnerror(dnp, D_TRUNC_AGGBAD, 4677c478bd9Sstevel@tonic-gate "undefined aggregation: @%s\n", aid->di_name); 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 4717c478bd9Sstevel@tonic-gate dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); 4727c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_TRUNC; 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate if (argc == 1) { 4777c478bd9Sstevel@tonic-gate dt_action_difconst(ap, 0, DTRACEACT_LIBACT); 4787c478bd9Sstevel@tonic-gate } else { 4797c478bd9Sstevel@tonic-gate assert(trunc != NULL); 4807c478bd9Sstevel@tonic-gate dt_cg(yypcb, trunc); 4817c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 4827c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_LIBACT; 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_TRUNC; 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate static void 4897c478bd9Sstevel@tonic-gate dt_action_printa(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 4907c478bd9Sstevel@tonic-gate { 4917c478bd9Sstevel@tonic-gate dt_ident_t *aid, *fid; 4927c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap; 4937c478bd9Sstevel@tonic-gate const char *format; 49430ef842dSbmc dt_node_t *anp, *proto = NULL; 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN]; 4977c478bd9Sstevel@tonic-gate int argc = 0, argr = 0; 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) 5007c478bd9Sstevel@tonic-gate argc++; /* count up arguments for error messages below */ 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate switch (dnp->dn_args->dn_kind) { 5037c478bd9Sstevel@tonic-gate case DT_NODE_STRING: 5047c478bd9Sstevel@tonic-gate format = dnp->dn_args->dn_string; 5057c478bd9Sstevel@tonic-gate anp = dnp->dn_args->dn_list; 5067c478bd9Sstevel@tonic-gate argr = 2; 5077c478bd9Sstevel@tonic-gate break; 5087c478bd9Sstevel@tonic-gate case DT_NODE_AGG: 5097c478bd9Sstevel@tonic-gate format = NULL; 5107c478bd9Sstevel@tonic-gate anp = dnp->dn_args; 5117c478bd9Sstevel@tonic-gate argr = 1; 5127c478bd9Sstevel@tonic-gate break; 5137c478bd9Sstevel@tonic-gate default: 5147c478bd9Sstevel@tonic-gate format = NULL; 5157c478bd9Sstevel@tonic-gate anp = dnp->dn_args; 5167c478bd9Sstevel@tonic-gate argr = 1; 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 51930ef842dSbmc if (argc < argr) { 5207c478bd9Sstevel@tonic-gate dnerror(dnp, D_PRINTA_PROTO, 5217c478bd9Sstevel@tonic-gate "%s( ) prototype mismatch: %d args passed, %d expected\n", 5227c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, argc, argr); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate 52530ef842dSbmc assert(anp != NULL); 5267c478bd9Sstevel@tonic-gate 52730ef842dSbmc while (anp != NULL) { 52830ef842dSbmc if (anp->dn_kind != DT_NODE_AGG) { 52930ef842dSbmc dnerror(dnp, D_PRINTA_AGGARG, 53030ef842dSbmc "%s( ) argument #%d is incompatible with " 53130ef842dSbmc "prototype:\n\tprototype: aggregation\n" 53230ef842dSbmc "\t argument: %s\n", dnp->dn_ident->di_name, argr, 53330ef842dSbmc dt_node_type_name(anp, n, sizeof (n))); 53430ef842dSbmc } 5357c478bd9Sstevel@tonic-gate 53630ef842dSbmc aid = anp->dn_ident; 53730ef842dSbmc fid = aid->di_iarg; 5387c478bd9Sstevel@tonic-gate 53930ef842dSbmc if (aid->di_gen == dtp->dt_gen && 54030ef842dSbmc !(aid->di_flags & DT_IDFLG_MOD)) { 54130ef842dSbmc dnerror(dnp, D_PRINTA_AGGBAD, 54230ef842dSbmc "undefined aggregation: @%s\n", aid->di_name); 54330ef842dSbmc } 5447c478bd9Sstevel@tonic-gate 54530ef842dSbmc /* 54630ef842dSbmc * If we have multiple aggregations, we must be sure that 54730ef842dSbmc * their key signatures match. 54830ef842dSbmc */ 54930ef842dSbmc if (proto != NULL) { 55030ef842dSbmc dt_printa_validate(proto, anp); 55130ef842dSbmc } else { 55230ef842dSbmc proto = anp; 55330ef842dSbmc } 5547c478bd9Sstevel@tonic-gate 55530ef842dSbmc if (format != NULL) { 55630ef842dSbmc yylineno = dnp->dn_line; 55730ef842dSbmc 55830ef842dSbmc sdp->dtsd_fmtdata = 55930ef842dSbmc dt_printf_create(yypcb->pcb_hdl, format); 56030ef842dSbmc dt_printf_validate(sdp->dtsd_fmtdata, 56130ef842dSbmc DT_PRINTF_AGGREGATION, dnp->dn_ident, 1, 56230ef842dSbmc fid->di_id, ((dt_idsig_t *)aid->di_data)->dis_args); 56330ef842dSbmc format = NULL; 56430ef842dSbmc } 56530ef842dSbmc 56630ef842dSbmc ap = dt_stmt_action(dtp, sdp); 56730ef842dSbmc dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_PRINTA); 56830ef842dSbmc 56930ef842dSbmc anp = anp->dn_list; 57030ef842dSbmc argr++; 57130ef842dSbmc } 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate static void 5757c478bd9Sstevel@tonic-gate dt_action_printflike(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp, 5767c478bd9Sstevel@tonic-gate dtrace_actkind_t kind) 5777c478bd9Sstevel@tonic-gate { 5787c478bd9Sstevel@tonic-gate dt_node_t *anp, *arg1; 5797c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = NULL; 5807c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN], *str; 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate assert(DTRACEACT_ISPRINTFLIKE(kind)); 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate if (dnp->dn_args->dn_kind != DT_NODE_STRING) { 5857c478bd9Sstevel@tonic-gate dnerror(dnp, D_PRINTF_ARG_FMT, 5867c478bd9Sstevel@tonic-gate "%s( ) argument #1 is incompatible with prototype:\n" 5877c478bd9Sstevel@tonic-gate "\tprototype: string constant\n\t argument: %s\n", 5887c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, 5897c478bd9Sstevel@tonic-gate dt_node_type_name(dnp->dn_args, n, sizeof (n))); 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate arg1 = dnp->dn_args->dn_list; 5937c478bd9Sstevel@tonic-gate yylineno = dnp->dn_line; 5947c478bd9Sstevel@tonic-gate str = dnp->dn_args->dn_string; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate /* 5987c478bd9Sstevel@tonic-gate * If this is an freopen(), we use an empty string to denote that 5997c478bd9Sstevel@tonic-gate * stdout should be restored. For other printf()-like actions, an 6007c478bd9Sstevel@tonic-gate * empty format string is illegal: an empty format string would 6017c478bd9Sstevel@tonic-gate * result in malformed DOF, and the compiler thus flags an empty 6027c478bd9Sstevel@tonic-gate * format string as a compile-time error. To avoid propagating the 6037c478bd9Sstevel@tonic-gate * freopen() special case throughout the system, we simply transpose 6047c478bd9Sstevel@tonic-gate * an empty string into a sentinel string (DT_FREOPEN_RESTORE) that 6057c478bd9Sstevel@tonic-gate * denotes that stdout should be restored. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate if (kind == DTRACEACT_FREOPEN) { 6087c478bd9Sstevel@tonic-gate if (strcmp(str, DT_FREOPEN_RESTORE) == 0) { 6097c478bd9Sstevel@tonic-gate /* 6107c478bd9Sstevel@tonic-gate * Our sentinel is always an invalid argument to 6117c478bd9Sstevel@tonic-gate * freopen(), but if it's been manually specified, we 6127c478bd9Sstevel@tonic-gate * must fail now instead of when the freopen() is 6137c478bd9Sstevel@tonic-gate * actually evaluated. 6147c478bd9Sstevel@tonic-gate */ 6157c478bd9Sstevel@tonic-gate dnerror(dnp, D_FREOPEN_INVALID, 6167c478bd9Sstevel@tonic-gate "%s( ) argument #1 cannot be \"%s\"\n", 6177c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name, DT_FREOPEN_RESTORE); 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate if (str[0] == '\0') 6217c478bd9Sstevel@tonic-gate str = DT_FREOPEN_RESTORE; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate 6241a7c1b72Smws sdp->dtsd_fmtdata = dt_printf_create(dtp, str); 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate dt_printf_validate(sdp->dtsd_fmtdata, DT_PRINTF_EXACTLEN, 6277c478bd9Sstevel@tonic-gate dnp->dn_ident, 1, DTRACEACT_AGGREGATION, arg1); 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate if (arg1 == NULL) { 6307c478bd9Sstevel@tonic-gate dif_instr_t *dbuf; 6317c478bd9Sstevel@tonic-gate dtrace_difo_t *dp; 6327c478bd9Sstevel@tonic-gate 6331a7c1b72Smws if ((dbuf = dt_alloc(dtp, sizeof (dif_instr_t))) == NULL || 6341a7c1b72Smws (dp = dt_zalloc(dtp, sizeof (dtrace_difo_t))) == NULL) { 6351a7c1b72Smws dt_free(dtp, dbuf); 6367c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate dbuf[0] = DIF_INSTR_RET(DIF_REG_R0); /* ret %r0 */ 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate dp->dtdo_buf = dbuf; 6427c478bd9Sstevel@tonic-gate dp->dtdo_len = 1; 6437c478bd9Sstevel@tonic-gate dp->dtdo_rtype = dt_int_rtype; 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 6467c478bd9Sstevel@tonic-gate ap->dtad_difo = dp; 6477c478bd9Sstevel@tonic-gate ap->dtad_kind = kind; 6487c478bd9Sstevel@tonic-gate return; 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate for (anp = arg1; anp != NULL; anp = anp->dn_list) { 6527c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 6537c478bd9Sstevel@tonic-gate dt_cg(yypcb, anp); 6547c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 6557c478bd9Sstevel@tonic-gate ap->dtad_kind = kind; 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate static void 6607c478bd9Sstevel@tonic-gate dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 6617c478bd9Sstevel@tonic-gate { 6627c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate if (dt_node_is_void(dnp->dn_args)) { 6657c478bd9Sstevel@tonic-gate dnerror(dnp->dn_args, D_TRACE_VOID, 6667c478bd9Sstevel@tonic-gate "trace( ) may not be applied to a void expression\n"); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate if (dt_node_is_dynamic(dnp->dn_args)) { 6707c478bd9Sstevel@tonic-gate dnerror(dnp->dn_args, D_TRACE_DYN, 6717c478bd9Sstevel@tonic-gate "trace( ) may not be applied to a dynamic expression\n"); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 6757c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 6767c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_DIFEXPR; 6777c478bd9Sstevel@tonic-gate } 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate static void 6807c478bd9Sstevel@tonic-gate dt_action_tracemem(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 6817c478bd9Sstevel@tonic-gate { 6827c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate dt_node_t *addr = dnp->dn_args; 6857c478bd9Sstevel@tonic-gate dt_node_t *size = dnp->dn_args->dn_list; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate char n[DT_TYPE_NAMELEN]; 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate if (dt_node_is_integer(addr) == 0 && dt_node_is_pointer(addr) == 0) { 6907c478bd9Sstevel@tonic-gate dnerror(addr, D_TRACEMEM_ADDR, 6917c478bd9Sstevel@tonic-gate "tracemem( ) argument #1 is incompatible with " 6927c478bd9Sstevel@tonic-gate "prototype:\n\tprototype: pointer or integer\n" 6937c478bd9Sstevel@tonic-gate "\t argument: %s\n", 6947c478bd9Sstevel@tonic-gate dt_node_type_name(addr, n, sizeof (n))); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate if (dt_node_is_posconst(size) == 0) { 6987c478bd9Sstevel@tonic-gate dnerror(size, D_TRACEMEM_SIZE, "tracemem( ) argument #2 must " 6997c478bd9Sstevel@tonic-gate "be a non-zero positive integral constant expression\n"); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate dt_cg(yypcb, addr); 7037c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 7047c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_DIFEXPR; 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF; 7077c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype.dtdt_size = size->dn_value; 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate static void 7117c478bd9Sstevel@tonic-gate dt_action_stack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *arg0) 7127c478bd9Sstevel@tonic-gate { 7137c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_STACK; 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate if (dtp->dt_options[DTRACEOPT_STACKFRAMES] != DTRACEOPT_UNSET) { 7167c478bd9Sstevel@tonic-gate ap->dtad_arg = dtp->dt_options[DTRACEOPT_STACKFRAMES]; 7177c478bd9Sstevel@tonic-gate } else { 7187c478bd9Sstevel@tonic-gate ap->dtad_arg = 0; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate if (arg0 != NULL) { 7227c478bd9Sstevel@tonic-gate if (arg0->dn_list != NULL) { 7237c478bd9Sstevel@tonic-gate dnerror(arg0, D_STACK_PROTO, "stack( ) prototype " 7247c478bd9Sstevel@tonic-gate "mismatch: too many arguments\n"); 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate if (dt_node_is_posconst(arg0) == 0) { 7287c478bd9Sstevel@tonic-gate dnerror(arg0, D_STACK_SIZE, "stack( ) size must be a " 7297c478bd9Sstevel@tonic-gate "non-zero positive integral constant expression\n"); 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate ap->dtad_arg = arg0->dn_value; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate static void 7377c478bd9Sstevel@tonic-gate dt_action_stack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 7387c478bd9Sstevel@tonic-gate { 7397c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 7407c478bd9Sstevel@tonic-gate dt_action_stack_args(dtp, ap, dnp->dn_args); 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate static void 7447c478bd9Sstevel@tonic-gate dt_action_ustack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *dnp) 7457c478bd9Sstevel@tonic-gate { 7467c478bd9Sstevel@tonic-gate uint32_t nframes = 0; 7477c478bd9Sstevel@tonic-gate uint32_t strsize = 0; /* default string table size */ 7487c478bd9Sstevel@tonic-gate dt_node_t *arg0 = dnp->dn_args; 7497c478bd9Sstevel@tonic-gate dt_node_t *arg1 = arg0 != NULL ? arg0->dn_list : NULL; 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate assert(dnp->dn_ident->di_id == DT_ACT_JSTACK || 7527c478bd9Sstevel@tonic-gate dnp->dn_ident->di_id == DT_ACT_USTACK); 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate if (dnp->dn_ident->di_id == DT_ACT_JSTACK) { 7557c478bd9Sstevel@tonic-gate if (dtp->dt_options[DTRACEOPT_JSTACKFRAMES] != DTRACEOPT_UNSET) 7567c478bd9Sstevel@tonic-gate nframes = dtp->dt_options[DTRACEOPT_JSTACKFRAMES]; 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate if (dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE] != DTRACEOPT_UNSET) 7597c478bd9Sstevel@tonic-gate strsize = dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE]; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_JSTACK; 7627c478bd9Sstevel@tonic-gate } else { 7637c478bd9Sstevel@tonic-gate assert(dnp->dn_ident->di_id == DT_ACT_USTACK); 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate if (dtp->dt_options[DTRACEOPT_USTACKFRAMES] != DTRACEOPT_UNSET) 7667c478bd9Sstevel@tonic-gate nframes = dtp->dt_options[DTRACEOPT_USTACKFRAMES]; 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_USTACK; 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate if (arg0 != NULL) { 7727c478bd9Sstevel@tonic-gate if (!dt_node_is_posconst(arg0)) { 7737c478bd9Sstevel@tonic-gate dnerror(arg0, D_USTACK_FRAMES, "ustack( ) argument #1 " 7747c478bd9Sstevel@tonic-gate "must be a non-zero positive integer constant\n"); 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate nframes = (uint32_t)arg0->dn_value; 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate if (arg1 != NULL) { 7807c478bd9Sstevel@tonic-gate if (arg1->dn_kind != DT_NODE_INT || 7817c478bd9Sstevel@tonic-gate ((arg1->dn_flags & DT_NF_SIGNED) && 7827c478bd9Sstevel@tonic-gate (int64_t)arg1->dn_value < 0)) { 7837c478bd9Sstevel@tonic-gate dnerror(arg1, D_USTACK_STRSIZE, "ustack( ) argument #2 " 7847c478bd9Sstevel@tonic-gate "must be a positive integer constant\n"); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate if (arg1->dn_list != NULL) { 7887c478bd9Sstevel@tonic-gate dnerror(arg1, D_USTACK_PROTO, "ustack( ) prototype " 7897c478bd9Sstevel@tonic-gate "mismatch: too many arguments\n"); 7907c478bd9Sstevel@tonic-gate } 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate strsize = (uint32_t)arg1->dn_value; 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate ap->dtad_arg = DTRACE_USTACK_ARG(nframes, strsize); 7967c478bd9Sstevel@tonic-gate } 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate static void 7997c478bd9Sstevel@tonic-gate dt_action_ustack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 8007c478bd9Sstevel@tonic-gate { 8017c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 8027c478bd9Sstevel@tonic-gate dt_action_ustack_args(dtp, ap, dnp); 8037c478bd9Sstevel@tonic-gate } 8047c478bd9Sstevel@tonic-gate 805a1b5e537Sbmc static void 806a1b5e537Sbmc dt_action_setopt(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 807a1b5e537Sbmc { 808a1b5e537Sbmc dtrace_actdesc_t *ap; 809a1b5e537Sbmc dt_node_t *arg0, *arg1; 810a1b5e537Sbmc 811a1b5e537Sbmc /* 812a1b5e537Sbmc * The prototype guarantees that we are called with either one or 813a1b5e537Sbmc * two arguments, and that any arguments that are present are strings. 814a1b5e537Sbmc */ 815a1b5e537Sbmc arg0 = dnp->dn_args; 816a1b5e537Sbmc arg1 = arg0->dn_list; 817a1b5e537Sbmc 818a1b5e537Sbmc ap = dt_stmt_action(dtp, sdp); 819a1b5e537Sbmc dt_cg(yypcb, arg0); 820a1b5e537Sbmc ap->dtad_difo = dt_as(yypcb); 821a1b5e537Sbmc ap->dtad_kind = DTRACEACT_LIBACT; 822a1b5e537Sbmc ap->dtad_arg = DT_ACT_SETOPT; 823a1b5e537Sbmc 824a1b5e537Sbmc ap = dt_stmt_action(dtp, sdp); 825a1b5e537Sbmc 826a1b5e537Sbmc if (arg1 == NULL) { 827a1b5e537Sbmc dt_action_difconst(ap, 0, DTRACEACT_LIBACT); 828a1b5e537Sbmc } else { 829a1b5e537Sbmc dt_cg(yypcb, arg1); 830a1b5e537Sbmc ap->dtad_difo = dt_as(yypcb); 831a1b5e537Sbmc ap->dtad_kind = DTRACEACT_LIBACT; 832a1b5e537Sbmc } 833a1b5e537Sbmc 834a1b5e537Sbmc ap->dtad_arg = DT_ACT_SETOPT; 835a1b5e537Sbmc } 836a1b5e537Sbmc 837a1b5e537Sbmc /*ARGSUSED*/ 838a1b5e537Sbmc static void 839a1b5e537Sbmc dt_action_symmod_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, 840a1b5e537Sbmc dt_node_t *dnp, dtrace_actkind_t kind) 841a1b5e537Sbmc { 842a1b5e537Sbmc assert(kind == DTRACEACT_SYM || kind == DTRACEACT_MOD || 843a1b5e537Sbmc kind == DTRACEACT_USYM || kind == DTRACEACT_UMOD || 844a1b5e537Sbmc kind == DTRACEACT_UADDR); 845a1b5e537Sbmc 846a1b5e537Sbmc dt_cg(yypcb, dnp); 847a1b5e537Sbmc ap->dtad_difo = dt_as(yypcb); 848a1b5e537Sbmc ap->dtad_kind = kind; 849a1b5e537Sbmc ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (uint64_t); 850a1b5e537Sbmc } 851a1b5e537Sbmc 852a1b5e537Sbmc static void 853a1b5e537Sbmc dt_action_symmod(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp, 854a1b5e537Sbmc dtrace_actkind_t kind) 855a1b5e537Sbmc { 856a1b5e537Sbmc dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 857a1b5e537Sbmc dt_action_symmod_args(dtp, ap, dnp->dn_args, kind); 858a1b5e537Sbmc } 859a1b5e537Sbmc 8607c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8617c478bd9Sstevel@tonic-gate static void 8627c478bd9Sstevel@tonic-gate dt_action_ftruncate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 8637c478bd9Sstevel@tonic-gate { 8647c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate /* 8677c478bd9Sstevel@tonic-gate * Library actions need a DIFO that serves as an argument. As 8687c478bd9Sstevel@tonic-gate * ftruncate() doesn't take an argument, we generate the constant 0 8697c478bd9Sstevel@tonic-gate * in a DIFO; this constant will be ignored when the ftruncate() is 8707c478bd9Sstevel@tonic-gate * processed. 8717c478bd9Sstevel@tonic-gate */ 8727c478bd9Sstevel@tonic-gate dt_action_difconst(ap, 0, DTRACEACT_LIBACT); 8737c478bd9Sstevel@tonic-gate ap->dtad_arg = DT_ACT_FTRUNCATE; 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8777c478bd9Sstevel@tonic-gate static void 8787c478bd9Sstevel@tonic-gate dt_action_stop(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 8797c478bd9Sstevel@tonic-gate { 8807c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_STOP; 8837c478bd9Sstevel@tonic-gate ap->dtad_arg = 0; 8847c478bd9Sstevel@tonic-gate } 8857c478bd9Sstevel@tonic-gate 8867c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8877c478bd9Sstevel@tonic-gate static void 8887c478bd9Sstevel@tonic-gate dt_action_breakpoint(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 8897c478bd9Sstevel@tonic-gate { 8907c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_BREAKPOINT; 8937c478bd9Sstevel@tonic-gate ap->dtad_arg = 0; 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8977c478bd9Sstevel@tonic-gate static void 8987c478bd9Sstevel@tonic-gate dt_action_panic(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 8997c478bd9Sstevel@tonic-gate { 9007c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_PANIC; 9037c478bd9Sstevel@tonic-gate ap->dtad_arg = 0; 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate static void 9077c478bd9Sstevel@tonic-gate dt_action_chill(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9087c478bd9Sstevel@tonic-gate { 9097c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9127c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9137c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_CHILL; 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate static void 9177c478bd9Sstevel@tonic-gate dt_action_raise(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9187c478bd9Sstevel@tonic-gate { 9197c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9227c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9237c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_RAISE; 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate static void 9277c478bd9Sstevel@tonic-gate dt_action_exit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9287c478bd9Sstevel@tonic-gate { 9297c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9327c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9337c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_EXIT; 9347c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (int); 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate static void 9387c478bd9Sstevel@tonic-gate dt_action_speculate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9397c478bd9Sstevel@tonic-gate { 9407c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9437c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9447c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_SPECULATE; 9457c478bd9Sstevel@tonic-gate } 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate static void 9487c478bd9Sstevel@tonic-gate dt_action_commit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9497c478bd9Sstevel@tonic-gate { 9507c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9537c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9547c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_COMMIT; 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate static void 9587c478bd9Sstevel@tonic-gate dt_action_discard(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9597c478bd9Sstevel@tonic-gate { 9607c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_args); 9637c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 9647c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_DISCARD; 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate static void 9687c478bd9Sstevel@tonic-gate dt_compile_fun(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 9697c478bd9Sstevel@tonic-gate { 9707c478bd9Sstevel@tonic-gate switch (dnp->dn_expr->dn_ident->di_id) { 9717c478bd9Sstevel@tonic-gate case DT_ACT_BREAKPOINT: 9727c478bd9Sstevel@tonic-gate dt_action_breakpoint(dtp, dnp->dn_expr, sdp); 9737c478bd9Sstevel@tonic-gate break; 9747c478bd9Sstevel@tonic-gate case DT_ACT_CHILL: 9757c478bd9Sstevel@tonic-gate dt_action_chill(dtp, dnp->dn_expr, sdp); 9767c478bd9Sstevel@tonic-gate break; 9777c478bd9Sstevel@tonic-gate case DT_ACT_CLEAR: 9787c478bd9Sstevel@tonic-gate dt_action_clear(dtp, dnp->dn_expr, sdp); 9797c478bd9Sstevel@tonic-gate break; 9807c478bd9Sstevel@tonic-gate case DT_ACT_COMMIT: 9817c478bd9Sstevel@tonic-gate dt_action_commit(dtp, dnp->dn_expr, sdp); 9827c478bd9Sstevel@tonic-gate break; 9837c478bd9Sstevel@tonic-gate case DT_ACT_DENORMALIZE: 9847c478bd9Sstevel@tonic-gate dt_action_normalize(dtp, dnp->dn_expr, sdp); 9857c478bd9Sstevel@tonic-gate break; 9867c478bd9Sstevel@tonic-gate case DT_ACT_DISCARD: 9877c478bd9Sstevel@tonic-gate dt_action_discard(dtp, dnp->dn_expr, sdp); 9887c478bd9Sstevel@tonic-gate break; 9897c478bd9Sstevel@tonic-gate case DT_ACT_EXIT: 9907c478bd9Sstevel@tonic-gate dt_action_exit(dtp, dnp->dn_expr, sdp); 9917c478bd9Sstevel@tonic-gate break; 9927c478bd9Sstevel@tonic-gate case DT_ACT_FREOPEN: 9937c478bd9Sstevel@tonic-gate dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_FREOPEN); 9947c478bd9Sstevel@tonic-gate break; 9957c478bd9Sstevel@tonic-gate case DT_ACT_FTRUNCATE: 9967c478bd9Sstevel@tonic-gate dt_action_ftruncate(dtp, dnp->dn_expr, sdp); 9977c478bd9Sstevel@tonic-gate break; 998a1b5e537Sbmc case DT_ACT_MOD: 999a1b5e537Sbmc dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_MOD); 1000a1b5e537Sbmc break; 10017c478bd9Sstevel@tonic-gate case DT_ACT_NORMALIZE: 10027c478bd9Sstevel@tonic-gate dt_action_normalize(dtp, dnp->dn_expr, sdp); 10037c478bd9Sstevel@tonic-gate break; 10047c478bd9Sstevel@tonic-gate case DT_ACT_PANIC: 10057c478bd9Sstevel@tonic-gate dt_action_panic(dtp, dnp->dn_expr, sdp); 10067c478bd9Sstevel@tonic-gate break; 10077c478bd9Sstevel@tonic-gate case DT_ACT_PRINTA: 10087c478bd9Sstevel@tonic-gate dt_action_printa(dtp, dnp->dn_expr, sdp); 10097c478bd9Sstevel@tonic-gate break; 10107c478bd9Sstevel@tonic-gate case DT_ACT_PRINTF: 10117c478bd9Sstevel@tonic-gate dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF); 10127c478bd9Sstevel@tonic-gate break; 10137c478bd9Sstevel@tonic-gate case DT_ACT_RAISE: 10147c478bd9Sstevel@tonic-gate dt_action_raise(dtp, dnp->dn_expr, sdp); 10157c478bd9Sstevel@tonic-gate break; 1016a1b5e537Sbmc case DT_ACT_SETOPT: 1017a1b5e537Sbmc dt_action_setopt(dtp, dnp->dn_expr, sdp); 1018a1b5e537Sbmc break; 10197c478bd9Sstevel@tonic-gate case DT_ACT_SPECULATE: 10207c478bd9Sstevel@tonic-gate dt_action_speculate(dtp, dnp->dn_expr, sdp); 10217c478bd9Sstevel@tonic-gate break; 10227c478bd9Sstevel@tonic-gate case DT_ACT_STACK: 10237c478bd9Sstevel@tonic-gate dt_action_stack(dtp, dnp->dn_expr, sdp); 10247c478bd9Sstevel@tonic-gate break; 10257c478bd9Sstevel@tonic-gate case DT_ACT_STOP: 10267c478bd9Sstevel@tonic-gate dt_action_stop(dtp, dnp->dn_expr, sdp); 10277c478bd9Sstevel@tonic-gate break; 1028a1b5e537Sbmc case DT_ACT_SYM: 1029a1b5e537Sbmc dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_SYM); 1030a1b5e537Sbmc break; 10317c478bd9Sstevel@tonic-gate case DT_ACT_SYSTEM: 10327c478bd9Sstevel@tonic-gate dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM); 10337c478bd9Sstevel@tonic-gate break; 10347c478bd9Sstevel@tonic-gate case DT_ACT_TRACE: 10357c478bd9Sstevel@tonic-gate dt_action_trace(dtp, dnp->dn_expr, sdp); 10367c478bd9Sstevel@tonic-gate break; 10377c478bd9Sstevel@tonic-gate case DT_ACT_TRACEMEM: 10387c478bd9Sstevel@tonic-gate dt_action_tracemem(dtp, dnp->dn_expr, sdp); 10397c478bd9Sstevel@tonic-gate break; 10407c478bd9Sstevel@tonic-gate case DT_ACT_TRUNC: 10417c478bd9Sstevel@tonic-gate dt_action_trunc(dtp, dnp->dn_expr, sdp); 10427c478bd9Sstevel@tonic-gate break; 1043a1b5e537Sbmc case DT_ACT_UADDR: 1044a1b5e537Sbmc dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UADDR); 1045a1b5e537Sbmc break; 1046a1b5e537Sbmc case DT_ACT_UMOD: 1047a1b5e537Sbmc dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UMOD); 1048a1b5e537Sbmc break; 1049a1b5e537Sbmc case DT_ACT_USYM: 1050a1b5e537Sbmc dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_USYM); 1051a1b5e537Sbmc break; 10527c478bd9Sstevel@tonic-gate case DT_ACT_USTACK: 10537c478bd9Sstevel@tonic-gate case DT_ACT_JSTACK: 10547c478bd9Sstevel@tonic-gate dt_action_ustack(dtp, dnp->dn_expr, sdp); 10557c478bd9Sstevel@tonic-gate break; 10567c478bd9Sstevel@tonic-gate default: 10577c478bd9Sstevel@tonic-gate dnerror(dnp->dn_expr, D_UNKNOWN, "tracing function %s( ) is " 10587c478bd9Sstevel@tonic-gate "not yet supported\n", dnp->dn_expr->dn_ident->di_name); 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate } 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate static void 10637c478bd9Sstevel@tonic-gate dt_compile_exp(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 10647c478bd9Sstevel@tonic-gate { 10657c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate dt_cg(yypcb, dnp->dn_expr); 10687c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 10697c478bd9Sstevel@tonic-gate ap->dtad_difo->dtdo_rtype = dt_void_rtype; 10707c478bd9Sstevel@tonic-gate ap->dtad_kind = DTRACEACT_DIFEXPR; 10717c478bd9Sstevel@tonic-gate } 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate static void 10747c478bd9Sstevel@tonic-gate dt_compile_agg(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) 10757c478bd9Sstevel@tonic-gate { 10767c478bd9Sstevel@tonic-gate dt_ident_t *aid, *fid; 1077a1b5e537Sbmc dt_node_t *anp, *incr = NULL; 10787c478bd9Sstevel@tonic-gate dtrace_actdesc_t *ap; 1079a1b5e537Sbmc uint_t n = 1, argmax; 1080a1b5e537Sbmc uint64_t arg = 0; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* 10837c478bd9Sstevel@tonic-gate * If the aggregation has no aggregating function applied to it, then 10847c478bd9Sstevel@tonic-gate * this statement has no effect. Flag this as a programming error. 10857c478bd9Sstevel@tonic-gate */ 10867c478bd9Sstevel@tonic-gate if (dnp->dn_aggfun == NULL) { 10877c478bd9Sstevel@tonic-gate dnerror(dnp, D_AGG_NULL, "expression has null effect: @%s\n", 10887c478bd9Sstevel@tonic-gate dnp->dn_ident->di_name); 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate aid = dnp->dn_ident; 10927c478bd9Sstevel@tonic-gate fid = dnp->dn_aggfun->dn_ident; 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate if (dnp->dn_aggfun->dn_args != NULL && 10957c478bd9Sstevel@tonic-gate dt_node_is_scalar(dnp->dn_aggfun->dn_args) == 0) { 10967c478bd9Sstevel@tonic-gate dnerror(dnp->dn_aggfun, D_AGG_SCALAR, "%s( ) argument #1 must " 10977c478bd9Sstevel@tonic-gate "be of scalar type\n", fid->di_name); 10987c478bd9Sstevel@tonic-gate } 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate /* 11017c478bd9Sstevel@tonic-gate * The ID of the aggregation itself is implicitly recorded as the first 11027c478bd9Sstevel@tonic-gate * member of each aggregation tuple so we can distinguish them later. 11037c478bd9Sstevel@tonic-gate */ 11047c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 11057c478bd9Sstevel@tonic-gate dt_action_difconst(ap, aid->di_id, DTRACEACT_DIFEXPR); 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate for (anp = dnp->dn_aggtup; anp != NULL; anp = anp->dn_list) { 11087c478bd9Sstevel@tonic-gate ap = dt_stmt_action(dtp, sdp); 11097c478bd9Sstevel@tonic-gate n++; 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate if (anp->dn_kind == DT_NODE_FUNC) { 11127c478bd9Sstevel@tonic-gate if (anp->dn_ident->di_id == DT_ACT_STACK) { 11137c478bd9Sstevel@tonic-gate dt_action_stack_args(dtp, ap, anp->dn_args); 11147c478bd9Sstevel@tonic-gate continue; 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate if (anp->dn_ident->di_id == DT_ACT_USTACK || 11187c478bd9Sstevel@tonic-gate anp->dn_ident->di_id == DT_ACT_JSTACK) { 11197c478bd9Sstevel@tonic-gate dt_action_ustack_args(dtp, ap, anp); 11207c478bd9Sstevel@tonic-gate continue; 11217c478bd9Sstevel@tonic-gate } 11227c478bd9Sstevel@tonic-gate 1123a1b5e537Sbmc switch (anp->dn_ident->di_id) { 1124a1b5e537Sbmc case DT_ACT_UADDR: 1125a1b5e537Sbmc dt_action_symmod_args(dtp, ap, 1126a1b5e537Sbmc anp->dn_args, DTRACEACT_UADDR); 1127a1b5e537Sbmc continue; 11287c478bd9Sstevel@tonic-gate 1129a1b5e537Sbmc case DT_ACT_USYM: 1130a1b5e537Sbmc dt_action_symmod_args(dtp, ap, 1131a1b5e537Sbmc anp->dn_args, DTRACEACT_USYM); 1132a1b5e537Sbmc continue; 11337c478bd9Sstevel@tonic-gate 1134a1b5e537Sbmc case DT_ACT_UMOD: 1135a1b5e537Sbmc dt_action_symmod_args(dtp, ap, 1136a1b5e537Sbmc anp->dn_args, DTRACEACT_UMOD); 1137a1b5e537Sbmc continue; 11387c478bd9Sstevel@tonic-gate 1139a1b5e537Sbmc case DT_ACT_SYM: 1140a1b5e537Sbmc dt_action_symmod_args(dtp, ap, 1141a1b5e537Sbmc anp->dn_args, DTRACEACT_SYM); 1142a1b5e537Sbmc continue; 1143a1b5e537Sbmc 1144a1b5e537Sbmc case DT_ACT_MOD: 1145a1b5e537Sbmc dt_action_symmod_args(dtp, ap, 1146a1b5e537Sbmc anp->dn_args, DTRACEACT_MOD); 1147a1b5e537Sbmc continue; 1148a1b5e537Sbmc 1149a1b5e537Sbmc default: 1150a1b5e537Sbmc break; 1151a1b5e537Sbmc } 1152a1b5e537Sbmc } 1153a1b5e537Sbmc 1154a1b5e537Sbmc dt_cg(yypcb, anp); 11557c478bd9Sstevel@tonic-gate ap->dtad_difo = dt_as(yypcb); 1156a1b5e537Sbmc ap->dtad_kind = DTRACEACT_DIFEXPR; 11577c478bd9Sstevel@tonic-gate } 11587c478bd9Sstevel@tonic-gate 11597c478bd9Sstevel@tonic-gate if (fid->di_id == DTRACEAGG_LQUANTIZE) { 11607c478bd9Sstevel@tonic-gate /* 1161a1b5e537Sbmc * For linear quantization, we have between two and four 1162a1b5e537Sbmc * arguments in addition to the expression: 11637c478bd9Sstevel@tonic-gate * 11647c478bd9Sstevel@tonic-gate * arg1 => Base value 11657c478bd9Sstevel@tonic-gate * arg2 => Limit value 11667c478bd9Sstevel@tonic-gate * arg3 => Quantization level step size (defaults to 1) 1167a1b5e537Sbmc * arg4 => Quantization increment value (defaults to 1) 11687c478bd9Sstevel@tonic-gate */ 11697c478bd9Sstevel@tonic-gate dt_node_t *arg1 = dnp->dn_aggfun->dn_args->dn_list; 11707c478bd9Sstevel@tonic-gate dt_node_t *arg2 = arg1->dn_list; 11717c478bd9Sstevel@tonic-gate dt_node_t *arg3 = arg2->dn_list; 117230ef842dSbmc dt_idsig_t *isp; 117330ef842dSbmc uint64_t nlevels, step = 1, oarg; 11747c478bd9Sstevel@tonic-gate int64_t baseval, limitval; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate if (arg1->dn_kind != DT_NODE_INT) { 11777c478bd9Sstevel@tonic-gate dnerror(arg1, D_LQUANT_BASETYPE, "lquantize( ) " 11787c478bd9Sstevel@tonic-gate "argument #1 must be an integer constant\n"); 11797c478bd9Sstevel@tonic-gate } 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate baseval = (int64_t)arg1->dn_value; 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate if (baseval < INT32_MIN || baseval > INT32_MAX) { 11847c478bd9Sstevel@tonic-gate dnerror(arg1, D_LQUANT_BASEVAL, "lquantize( ) " 11857c478bd9Sstevel@tonic-gate "argument #1 must be a 32-bit quantity\n"); 11867c478bd9Sstevel@tonic-gate } 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate if (arg2->dn_kind != DT_NODE_INT) { 11897c478bd9Sstevel@tonic-gate dnerror(arg2, D_LQUANT_LIMTYPE, "lquantize( ) " 11907c478bd9Sstevel@tonic-gate "argument #2 must be an integer constant\n"); 11917c478bd9Sstevel@tonic-gate } 11927c478bd9Sstevel@tonic-gate 11937c478bd9Sstevel@tonic-gate limitval = (int64_t)arg2->dn_value; 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate if (limitval < INT32_MIN || limitval > INT32_MAX) { 11967c478bd9Sstevel@tonic-gate dnerror(arg2, D_LQUANT_LIMVAL, "lquantize( ) " 11977c478bd9Sstevel@tonic-gate "argument #2 must be a 32-bit quantity\n"); 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate if (limitval < baseval) { 12017c478bd9Sstevel@tonic-gate dnerror(dnp, D_LQUANT_MISMATCH, 12027c478bd9Sstevel@tonic-gate "lquantize( ) base (argument #1) must be less " 12037c478bd9Sstevel@tonic-gate "than limit (argument #2)\n"); 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate if (arg3 != NULL) { 12077c478bd9Sstevel@tonic-gate if (!dt_node_is_posconst(arg3)) { 12087c478bd9Sstevel@tonic-gate dnerror(arg3, D_LQUANT_STEPTYPE, "lquantize( ) " 12097c478bd9Sstevel@tonic-gate "argument #3 must be a non-zero positive " 12107c478bd9Sstevel@tonic-gate "integer constant\n"); 12117c478bd9Sstevel@tonic-gate } 12127c478bd9Sstevel@tonic-gate 12137c478bd9Sstevel@tonic-gate if ((step = arg3->dn_value) > UINT16_MAX) { 12147c478bd9Sstevel@tonic-gate dnerror(arg3, D_LQUANT_STEPVAL, "lquantize( ) " 12157c478bd9Sstevel@tonic-gate "argument #3 must be a 16-bit quantity\n"); 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate } 12187c478bd9Sstevel@tonic-gate 12197c478bd9Sstevel@tonic-gate nlevels = (limitval - baseval) / step; 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate if (nlevels == 0) { 12227c478bd9Sstevel@tonic-gate dnerror(dnp, D_LQUANT_STEPLARGE, 12237c478bd9Sstevel@tonic-gate "lquantize( ) step (argument #3) too large: must " 12247c478bd9Sstevel@tonic-gate "have at least one quantization level\n"); 12257c478bd9Sstevel@tonic-gate } 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate if (nlevels > UINT16_MAX) { 12287c478bd9Sstevel@tonic-gate dnerror(dnp, D_LQUANT_STEPSMALL, "lquantize( ) step " 12297c478bd9Sstevel@tonic-gate "(argument #3) too small: number of quantization " 12307c478bd9Sstevel@tonic-gate "levels must be a 16-bit quantity\n"); 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate 1233a1b5e537Sbmc arg = (step << DTRACE_LQUANTIZE_STEPSHIFT) | 12347c478bd9Sstevel@tonic-gate (nlevels << DTRACE_LQUANTIZE_LEVELSHIFT) | 12357c478bd9Sstevel@tonic-gate ((baseval << DTRACE_LQUANTIZE_BASESHIFT) & 12367c478bd9Sstevel@tonic-gate DTRACE_LQUANTIZE_BASEMASK); 1237a1b5e537Sbmc 123830ef842dSbmc assert(arg != 0); 123930ef842dSbmc 124030ef842dSbmc isp = (dt_idsig_t *)aid->di_data; 124130ef842dSbmc 124230ef842dSbmc if (isp->dis_auxinfo == 0) { 124330ef842dSbmc /* 124430ef842dSbmc * This is the first time we've seen an lquantize() 124530ef842dSbmc * for this aggregation; we'll store our argument 124630ef842dSbmc * as the auxiliary signature information. 124730ef842dSbmc */ 124830ef842dSbmc isp->dis_auxinfo = arg; 124930ef842dSbmc } else if ((oarg = isp->dis_auxinfo) != arg) { 125030ef842dSbmc /* 125130ef842dSbmc * If we have seen this lquantize() before and the 125230ef842dSbmc * argument doesn't match the original argument, pick 125330ef842dSbmc * the original argument apart to concisely report the 125430ef842dSbmc * mismatch. 125530ef842dSbmc */ 125630ef842dSbmc int obaseval = DTRACE_LQUANTIZE_BASE(oarg); 125730ef842dSbmc int onlevels = DTRACE_LQUANTIZE_LEVELS(oarg); 125830ef842dSbmc int ostep = DTRACE_LQUANTIZE_STEP(oarg); 125930ef842dSbmc 126030ef842dSbmc if (obaseval != baseval) { 126130ef842dSbmc dnerror(dnp, D_LQUANT_MATCHBASE, "lquantize( ) " 126230ef842dSbmc "base (argument #1) doesn't match previous " 126330ef842dSbmc "declaration: expected %d, found %d\n", 126430ef842dSbmc obaseval, (int)baseval); 126530ef842dSbmc } 126630ef842dSbmc 126730ef842dSbmc if (onlevels * ostep != nlevels * step) { 126830ef842dSbmc dnerror(dnp, D_LQUANT_MATCHLIM, "lquantize( ) " 126930ef842dSbmc "limit (argument #2) doesn't match previous" 127030ef842dSbmc " declaration: expected %d, found %d\n", 127130ef842dSbmc obaseval + onlevels * ostep, 127230ef842dSbmc (int)baseval + (int)nlevels * (int)step); 127330ef842dSbmc } 127430ef842dSbmc 127530ef842dSbmc if (ostep != step) { 127630ef842dSbmc dnerror(dnp, D_LQUANT_MATCHSTEP, "lquantize( ) " 127730ef842dSbmc "step (argument #3) doesn't match previous " 127830ef842dSbmc "declaration: expected %d, found %d\n", 127930ef842dSbmc ostep, (int)step); 128030ef842dSbmc } 128130ef842dSbmc 128230ef842dSbmc /* 128330ef842dSbmc * We shouldn't be able to get here -- one of the 128430ef842dSbmc * parameters must be mismatched if the arguments 128530ef842dSbmc * didn't match. 128630ef842dSbmc */ 128730ef842dSbmc assert(0); 128830ef842dSbmc } 128930ef842dSbmc 1290a1b5e537Sbmc incr = arg3 != NULL ? arg3->dn_list : NULL; 1291a1b5e537Sbmc argmax = 5; 1292a1b5e537Sbmc } 1293a1b5e537Sbmc 1294a1b5e537Sbmc if (fid->di_id == DTRACEAGG_QUANTIZE) { 1295a1b5e537Sbmc incr = dnp->dn_aggfun->dn_args->dn_list; 1296a1b5e537Sbmc argmax = 2; 1297a1b5e537Sbmc } 1298a1b5e537Sbmc 1299a1b5e537Sbmc if (incr != NULL) { 1300a1b5e537Sbmc if (!dt_node_is_scalar(incr)) { 1301a1b5e537Sbmc dnerror(dnp, D_PROTO_ARG, "%s( ) increment value " 1302a1b5e537Sbmc "(argument #%d) must be of scalar type\n", 1303a1b5e537Sbmc fid->di_name, argmax); 1304a1b5e537Sbmc } 1305a1b5e537Sbmc 1306a1b5e537Sbmc if ((anp = incr->dn_list) != NULL) { 1307a1b5e537Sbmc int argc = argmax; 1308a1b5e537Sbmc 1309a1b5e537Sbmc for (; anp != NULL; anp = anp->dn_list) 1310a1b5e537Sbmc argc++; 1311a1b5e537Sbmc 1312a1b5e537Sbmc dnerror(incr, D_PROTO_LEN, "%s( ) prototype " 1313a1b5e537Sbmc "mismatch: %d args passed, at most %d expected", 1314a1b5e537Sbmc fid->di_name, argc, argmax); 1315a1b5e537Sbmc } 1316a1b5e537Sbmc 1317a1b5e537Sbmc ap = dt_stmt_action(dtp, sdp); 1318a1b5e537Sbmc n++; 1319a1b5e537Sbmc 1320a1b5e537Sbmc dt_cg(yypcb, incr); 1321a1b5e537Sbmc ap->dtad_difo = dt_as(yypcb); 1322a1b5e537Sbmc ap->dtad_difo->dtdo_rtype = dt_void_rtype; 1323a1b5e537Sbmc ap->dtad_kind = DTRACEACT_DIFEXPR; 1324a1b5e537Sbmc } 1325a1b5e537Sbmc 1326a1b5e537Sbmc assert(sdp->dtsd_aggdata == NULL); 1327a1b5e537Sbmc sdp->dtsd_aggdata = aid; 1328a1b5e537Sbmc 1329a1b5e537Sbmc ap = dt_stmt_action(dtp, sdp); 1330a1b5e537Sbmc assert(fid->di_kind == DT_IDENT_AGGFUNC); 1331a1b5e537Sbmc assert(DTRACEACT_ISAGG(fid->di_id)); 1332a1b5e537Sbmc ap->dtad_kind = fid->di_id; 1333a1b5e537Sbmc ap->dtad_ntuple = n; 1334a1b5e537Sbmc ap->dtad_arg = arg; 1335a1b5e537Sbmc 1336a1b5e537Sbmc if (dnp->dn_aggfun->dn_args != NULL) { 1337a1b5e537Sbmc dt_cg(yypcb, dnp->dn_aggfun->dn_args); 1338a1b5e537Sbmc ap->dtad_difo = dt_as(yypcb); 13397c478bd9Sstevel@tonic-gate } 13407c478bd9Sstevel@tonic-gate } 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate static void 13437c478bd9Sstevel@tonic-gate dt_compile_one_clause(dtrace_hdl_t *dtp, dt_node_t *cnp, dt_node_t *pnp) 13447c478bd9Sstevel@tonic-gate { 13457c478bd9Sstevel@tonic-gate dtrace_ecbdesc_t *edp; 13467c478bd9Sstevel@tonic-gate dtrace_stmtdesc_t *sdp; 13477c478bd9Sstevel@tonic-gate dt_node_t *dnp; 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate yylineno = pnp->dn_line; 13507c478bd9Sstevel@tonic-gate dt_setcontext(dtp, pnp->dn_desc); 13517c478bd9Sstevel@tonic-gate (void) dt_node_cook(cnp, DT_IDFLG_REF); 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate if (DT_TREEDUMP_PASS(dtp, 2)) 13547c478bd9Sstevel@tonic-gate dt_node_printr(cnp, stderr, 0); 13557c478bd9Sstevel@tonic-gate 13561a7c1b72Smws if ((edp = dt_ecbdesc_create(dtp, pnp->dn_desc)) == NULL) 13577c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate assert(yypcb->pcb_ecbdesc == NULL); 13607c478bd9Sstevel@tonic-gate yypcb->pcb_ecbdesc = edp; 13617c478bd9Sstevel@tonic-gate 13627c478bd9Sstevel@tonic-gate if (cnp->dn_pred != NULL) { 13637c478bd9Sstevel@tonic-gate dt_cg(yypcb, cnp->dn_pred); 13647c478bd9Sstevel@tonic-gate edp->dted_pred.dtpdd_difo = dt_as(yypcb); 13657c478bd9Sstevel@tonic-gate } 13667c478bd9Sstevel@tonic-gate 13677c478bd9Sstevel@tonic-gate if (cnp->dn_acts == NULL) { 13687c478bd9Sstevel@tonic-gate dt_stmt_append(dt_stmt_create(dtp, edp, 13697c478bd9Sstevel@tonic-gate cnp->dn_ctxattr, _dtrace_defattr), cnp); 13707c478bd9Sstevel@tonic-gate } 13717c478bd9Sstevel@tonic-gate 13727c478bd9Sstevel@tonic-gate for (dnp = cnp->dn_acts; dnp != NULL; dnp = dnp->dn_list) { 13737c478bd9Sstevel@tonic-gate assert(yypcb->pcb_stmt == NULL); 13747c478bd9Sstevel@tonic-gate sdp = dt_stmt_create(dtp, edp, cnp->dn_ctxattr, cnp->dn_attr); 13757c478bd9Sstevel@tonic-gate 13767c478bd9Sstevel@tonic-gate switch (dnp->dn_kind) { 13777c478bd9Sstevel@tonic-gate case DT_NODE_DEXPR: 13787c478bd9Sstevel@tonic-gate if (dnp->dn_expr->dn_kind == DT_NODE_AGG) 13797c478bd9Sstevel@tonic-gate dt_compile_agg(dtp, dnp->dn_expr, sdp); 13807c478bd9Sstevel@tonic-gate else 13817c478bd9Sstevel@tonic-gate dt_compile_exp(dtp, dnp, sdp); 13827c478bd9Sstevel@tonic-gate break; 13837c478bd9Sstevel@tonic-gate case DT_NODE_DFUNC: 13847c478bd9Sstevel@tonic-gate dt_compile_fun(dtp, dnp, sdp); 13857c478bd9Sstevel@tonic-gate break; 13867c478bd9Sstevel@tonic-gate case DT_NODE_AGG: 13877c478bd9Sstevel@tonic-gate dt_compile_agg(dtp, dnp, sdp); 13887c478bd9Sstevel@tonic-gate break; 13897c478bd9Sstevel@tonic-gate default: 13907c478bd9Sstevel@tonic-gate dnerror(dnp, D_UNKNOWN, "internal error -- node kind " 13917c478bd9Sstevel@tonic-gate "%u is not a valid statement\n", dnp->dn_kind); 13927c478bd9Sstevel@tonic-gate } 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate assert(yypcb->pcb_stmt == sdp); 13957c478bd9Sstevel@tonic-gate dt_stmt_append(sdp, dnp); 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate assert(yypcb->pcb_ecbdesc == edp); 13991a7c1b72Smws dt_ecbdesc_release(dtp, edp); 14007c478bd9Sstevel@tonic-gate dt_endcontext(dtp); 14017c478bd9Sstevel@tonic-gate yypcb->pcb_ecbdesc = NULL; 14027c478bd9Sstevel@tonic-gate } 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate static void 14057c478bd9Sstevel@tonic-gate dt_compile_clause(dtrace_hdl_t *dtp, dt_node_t *cnp) 14067c478bd9Sstevel@tonic-gate { 14077c478bd9Sstevel@tonic-gate dt_node_t *pnp; 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate for (pnp = cnp->dn_pdescs; pnp != NULL; pnp = pnp->dn_list) 14107c478bd9Sstevel@tonic-gate dt_compile_one_clause(dtp, cnp, pnp); 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate 14131a7c1b72Smws static void 14141a7c1b72Smws dt_compile_xlator(dt_node_t *dnp) 14151a7c1b72Smws { 14161a7c1b72Smws dt_xlator_t *dxp = dnp->dn_xlator; 14171a7c1b72Smws dt_node_t *mnp; 14181a7c1b72Smws 14191a7c1b72Smws for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) { 14201a7c1b72Smws assert(dxp->dx_membdif[mnp->dn_membid] == NULL); 14211a7c1b72Smws dt_cg(yypcb, mnp); 14221a7c1b72Smws dxp->dx_membdif[mnp->dn_membid] = dt_as(yypcb); 14231a7c1b72Smws } 14241a7c1b72Smws } 14251a7c1b72Smws 14267c478bd9Sstevel@tonic-gate void 14277c478bd9Sstevel@tonic-gate dt_setcontext(dtrace_hdl_t *dtp, dtrace_probedesc_t *pdp) 14287c478bd9Sstevel@tonic-gate { 14297c478bd9Sstevel@tonic-gate const dtrace_pattr_t *pap; 14307c478bd9Sstevel@tonic-gate dt_probe_t *prp; 1431c9d6cd77Sjhaslam dt_provider_t *pvp; 14327c478bd9Sstevel@tonic-gate dt_ident_t *idp; 14337c478bd9Sstevel@tonic-gate char attrstr[8]; 14347c478bd9Sstevel@tonic-gate int err; 14357c478bd9Sstevel@tonic-gate 14367c478bd9Sstevel@tonic-gate /* 1437c9d6cd77Sjhaslam * Both kernel and pid based providers are allowed to have names 1438c9d6cd77Sjhaslam * ending with what could be interpreted as a number. We assume it's 1439c9d6cd77Sjhaslam * a pid and that we may need to dynamically create probes for 1440c9d6cd77Sjhaslam * that process if: 1441c9d6cd77Sjhaslam * 1442c9d6cd77Sjhaslam * (1) The provider doesn't exist, or, 1443c9d6cd77Sjhaslam * (2) The provider exists and has DTRACE_PRIV_PROC privilege. 1444c9d6cd77Sjhaslam * 1445c9d6cd77Sjhaslam * On an error, dt_pid_create_probes() will set the error message 1446c9d6cd77Sjhaslam * and tag -- we just have to longjmp() out of here. 14477c478bd9Sstevel@tonic-gate */ 1448900524f3Sahl if (isdigit(pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) && 1449c9d6cd77Sjhaslam ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) == NULL || 1450c9d6cd77Sjhaslam pvp->pv_desc.dtvd_priv.dtpp_flags & DTRACE_PRIV_PROC) && 1451900524f3Sahl dt_pid_create_probes(pdp, dtp, yypcb) != 0) { 1452900524f3Sahl longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); 1453900524f3Sahl } 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate /* 14567c478bd9Sstevel@tonic-gate * Call dt_probe_info() to get the probe arguments and attributes. If 14577c478bd9Sstevel@tonic-gate * a representative probe is found, set 'pap' to the probe provider's 14587c478bd9Sstevel@tonic-gate * attributes. Otherwise set 'pap' to default Unstable attributes. 14597c478bd9Sstevel@tonic-gate */ 14607c478bd9Sstevel@tonic-gate if ((prp = dt_probe_info(dtp, pdp, &yypcb->pcb_pinfo)) == NULL) { 14617c478bd9Sstevel@tonic-gate pap = &_dtrace_prvdesc; 14627c478bd9Sstevel@tonic-gate err = dtrace_errno(dtp); 14637c478bd9Sstevel@tonic-gate bzero(&yypcb->pcb_pinfo, sizeof (dtrace_probeinfo_t)); 14647c478bd9Sstevel@tonic-gate yypcb->pcb_pinfo.dtp_attr = pap->dtpa_provider; 14657c478bd9Sstevel@tonic-gate yypcb->pcb_pinfo.dtp_arga = pap->dtpa_args; 14667c478bd9Sstevel@tonic-gate } else { 14677c478bd9Sstevel@tonic-gate pap = &prp->pr_pvp->pv_desc.dtvd_attr; 14687c478bd9Sstevel@tonic-gate err = 0; 14697c478bd9Sstevel@tonic-gate } 14707c478bd9Sstevel@tonic-gate 14717c478bd9Sstevel@tonic-gate if (err == EDT_NOPROBE && !(yypcb->pcb_cflags & DTRACE_C_ZDEFS)) { 14727c478bd9Sstevel@tonic-gate xyerror(D_PDESC_ZERO, "probe description %s:%s:%s:%s does not " 14737c478bd9Sstevel@tonic-gate "match any probes\n", pdp->dtpd_provider, pdp->dtpd_mod, 14747c478bd9Sstevel@tonic-gate pdp->dtpd_func, pdp->dtpd_name); 14757c478bd9Sstevel@tonic-gate } 14767c478bd9Sstevel@tonic-gate 14777c478bd9Sstevel@tonic-gate if (err != EDT_NOPROBE && err != EDT_UNSTABLE && err != 0) 14787c478bd9Sstevel@tonic-gate xyerror(D_PDESC_INVAL, "%s\n", dtrace_errmsg(dtp, err)); 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate dt_dprintf("set context to %s:%s:%s:%s [%u] prp=%p attr=%s argc=%d\n", 14817c478bd9Sstevel@tonic-gate pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name, 14827c478bd9Sstevel@tonic-gate pdp->dtpd_id, (void *)prp, dt_attr_str(yypcb->pcb_pinfo.dtp_attr, 14837c478bd9Sstevel@tonic-gate attrstr, sizeof (attrstr)), yypcb->pcb_pinfo.dtp_argc); 14847c478bd9Sstevel@tonic-gate 14857c478bd9Sstevel@tonic-gate /* 14867c478bd9Sstevel@tonic-gate * Reset the stability attributes of D global variables that vary 14877c478bd9Sstevel@tonic-gate * based on the attributes of the provider and context itself. 14887c478bd9Sstevel@tonic-gate */ 14897c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, "probeprov")) != NULL) 14907c478bd9Sstevel@tonic-gate idp->di_attr = pap->dtpa_provider; 14917c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, "probemod")) != NULL) 14927c478bd9Sstevel@tonic-gate idp->di_attr = pap->dtpa_mod; 14937c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, "probefunc")) != NULL) 14947c478bd9Sstevel@tonic-gate idp->di_attr = pap->dtpa_func; 14957c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, "probename")) != NULL) 14967c478bd9Sstevel@tonic-gate idp->di_attr = pap->dtpa_name; 14977c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, "args")) != NULL) 14987c478bd9Sstevel@tonic-gate idp->di_attr = pap->dtpa_args; 14997c478bd9Sstevel@tonic-gate 15007c478bd9Sstevel@tonic-gate yypcb->pcb_pdesc = pdp; 15017c478bd9Sstevel@tonic-gate yypcb->pcb_probe = prp; 15027c478bd9Sstevel@tonic-gate } 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate /* 15057c478bd9Sstevel@tonic-gate * Reset context-dependent variables and state at the end of cooking a D probe 15067c478bd9Sstevel@tonic-gate * definition clause. This ensures that external declarations between clauses 15077c478bd9Sstevel@tonic-gate * do not reference any stale context-dependent data from the previous clause. 15087c478bd9Sstevel@tonic-gate */ 15097c478bd9Sstevel@tonic-gate void 15107c478bd9Sstevel@tonic-gate dt_endcontext(dtrace_hdl_t *dtp) 15117c478bd9Sstevel@tonic-gate { 15127c478bd9Sstevel@tonic-gate static const char *const cvars[] = { 15137c478bd9Sstevel@tonic-gate "probeprov", "probemod", "probefunc", "probename", "args", NULL 15147c478bd9Sstevel@tonic-gate }; 15157c478bd9Sstevel@tonic-gate 15167c478bd9Sstevel@tonic-gate dt_ident_t *idp; 15177c478bd9Sstevel@tonic-gate int i; 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate for (i = 0; cvars[i] != NULL; i++) { 15207c478bd9Sstevel@tonic-gate if ((idp = dt_idhash_lookup(dtp->dt_globals, cvars[i])) != NULL) 15217c478bd9Sstevel@tonic-gate idp->di_attr = _dtrace_defattr; 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate 15247c478bd9Sstevel@tonic-gate yypcb->pcb_pdesc = NULL; 15257c478bd9Sstevel@tonic-gate yypcb->pcb_probe = NULL; 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate 15287c478bd9Sstevel@tonic-gate static int 15297c478bd9Sstevel@tonic-gate dt_reduceid(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp) 15307c478bd9Sstevel@tonic-gate { 15317c478bd9Sstevel@tonic-gate if (idp->di_vers != 0 && idp->di_vers > dtp->dt_vmax) 15327c478bd9Sstevel@tonic-gate dt_idhash_delete(dhp, idp); 15337c478bd9Sstevel@tonic-gate 15347c478bd9Sstevel@tonic-gate return (0); 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate /* 15387c478bd9Sstevel@tonic-gate * When dtrace_setopt() is called for "version", it calls dt_reduce() to remove 15397c478bd9Sstevel@tonic-gate * any identifiers or translators that have been previously defined as bound to 15407c478bd9Sstevel@tonic-gate * a version greater than the specified version. Therefore, in our current 15417c478bd9Sstevel@tonic-gate * version implementation, establishing a binding is a one-way transformation. 15427c478bd9Sstevel@tonic-gate * In addition, no versioning is currently provided for types as our .d library 15437c478bd9Sstevel@tonic-gate * files do not define any types and we reserve prefixes DTRACE_ and dtrace_ 15447c478bd9Sstevel@tonic-gate * for our exclusive use. If required, type versioning will require more work. 15457c478bd9Sstevel@tonic-gate */ 15467c478bd9Sstevel@tonic-gate int 15477c478bd9Sstevel@tonic-gate dt_reduce(dtrace_hdl_t *dtp, dt_version_t v) 15487c478bd9Sstevel@tonic-gate { 15497c478bd9Sstevel@tonic-gate char s[DT_VERSION_STRMAX]; 15507c478bd9Sstevel@tonic-gate dt_xlator_t *dxp, *nxp; 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate if (v > dtp->dt_vmax) 15537c478bd9Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_VERSREDUCED)); 15547c478bd9Sstevel@tonic-gate else if (v == dtp->dt_vmax) 15557c478bd9Sstevel@tonic-gate return (0); /* no reduction necessary */ 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate dt_dprintf("reducing api version to %s\n", 15587c478bd9Sstevel@tonic-gate dt_version_num2str(v, s, sizeof (s))); 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate dtp->dt_vmax = v; 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = nxp) { 15637c478bd9Sstevel@tonic-gate nxp = dt_list_next(dxp); 15647c478bd9Sstevel@tonic-gate if ((dxp->dx_souid.di_vers != 0 && dxp->dx_souid.di_vers > v) || 15657c478bd9Sstevel@tonic-gate (dxp->dx_ptrid.di_vers != 0 && dxp->dx_ptrid.di_vers > v)) 15667c478bd9Sstevel@tonic-gate dt_list_delete(&dtp->dt_xlators, dxp); 15677c478bd9Sstevel@tonic-gate } 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate (void) dt_idhash_iter(dtp->dt_macros, (dt_idhash_f *)dt_reduceid, dtp); 15707c478bd9Sstevel@tonic-gate (void) dt_idhash_iter(dtp->dt_aggs, (dt_idhash_f *)dt_reduceid, dtp); 15717c478bd9Sstevel@tonic-gate (void) dt_idhash_iter(dtp->dt_globals, (dt_idhash_f *)dt_reduceid, dtp); 15727c478bd9Sstevel@tonic-gate (void) dt_idhash_iter(dtp->dt_tls, (dt_idhash_f *)dt_reduceid, dtp); 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate return (0); 15757c478bd9Sstevel@tonic-gate } 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * Fork and exec the cpp(1) preprocessor to run over the specified input file, 15797c478bd9Sstevel@tonic-gate * and return a FILE handle for the cpp output. We use the /dev/fd filesystem 15807c478bd9Sstevel@tonic-gate * here to simplify the code by leveraging file descriptor inheritance. 15817c478bd9Sstevel@tonic-gate */ 15827c478bd9Sstevel@tonic-gate static FILE * 15837c478bd9Sstevel@tonic-gate dt_preproc(dtrace_hdl_t *dtp, FILE *ifp) 15847c478bd9Sstevel@tonic-gate { 15857c478bd9Sstevel@tonic-gate int argc = dtp->dt_cpp_argc; 15867c478bd9Sstevel@tonic-gate char **argv = malloc(sizeof (char *) * (argc + 5)); 15877c478bd9Sstevel@tonic-gate FILE *ofp = tmpfile(); 15887c478bd9Sstevel@tonic-gate 15897c478bd9Sstevel@tonic-gate char ipath[20], opath[20]; /* big enough for /dev/fd/ + INT_MAX + \0 */ 15907c478bd9Sstevel@tonic-gate char verdef[32]; /* big enough for -D__SUNW_D_VERSION=0x%08x + \0 */ 15917c478bd9Sstevel@tonic-gate 15927c478bd9Sstevel@tonic-gate struct sigaction act, oact; 15937c478bd9Sstevel@tonic-gate sigset_t mask, omask; 15947c478bd9Sstevel@tonic-gate 15957c478bd9Sstevel@tonic-gate int wstat, estat; 15967c478bd9Sstevel@tonic-gate pid_t pid; 15977c478bd9Sstevel@tonic-gate off64_t off; 15987c478bd9Sstevel@tonic-gate int c; 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate if (argv == NULL || ofp == NULL) { 16017c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, errno); 16027c478bd9Sstevel@tonic-gate goto err; 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate /* 16067c478bd9Sstevel@tonic-gate * If the input is a seekable file, see if it is an interpreter file. 16077c478bd9Sstevel@tonic-gate * If we see #!, seek past the first line because cpp will choke on it. 16087c478bd9Sstevel@tonic-gate * We start cpp just prior to the \n at the end of this line so that 16097c478bd9Sstevel@tonic-gate * it still sees the newline, ensuring that #line values are correct. 16107c478bd9Sstevel@tonic-gate */ 16117c478bd9Sstevel@tonic-gate if (isatty(fileno(ifp)) == 0 && (off = ftello64(ifp)) != -1) { 16127c478bd9Sstevel@tonic-gate if ((c = fgetc(ifp)) == '#' && (c = fgetc(ifp)) == '!') { 16137c478bd9Sstevel@tonic-gate for (off += 2; c != '\n'; off++) { 16147c478bd9Sstevel@tonic-gate if ((c = fgetc(ifp)) == EOF) 16157c478bd9Sstevel@tonic-gate break; 16167c478bd9Sstevel@tonic-gate } 16177c478bd9Sstevel@tonic-gate if (c == '\n') 16187c478bd9Sstevel@tonic-gate off--; /* start cpp just prior to \n */ 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate (void) fflush(ifp); 16217c478bd9Sstevel@tonic-gate (void) fseeko64(ifp, off, SEEK_SET); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate 16247c478bd9Sstevel@tonic-gate (void) snprintf(ipath, sizeof (ipath), "/dev/fd/%d", fileno(ifp)); 16257c478bd9Sstevel@tonic-gate (void) snprintf(opath, sizeof (opath), "/dev/fd/%d", fileno(ofp)); 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate bcopy(dtp->dt_cpp_argv, argv, sizeof (char *) * argc); 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate (void) snprintf(verdef, sizeof (verdef), 16307c478bd9Sstevel@tonic-gate "-D__SUNW_D_VERSION=0x%08x", dtp->dt_vmax); 16317c478bd9Sstevel@tonic-gate argv[argc++] = verdef; 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate switch (dtp->dt_stdcmode) { 16347c478bd9Sstevel@tonic-gate case DT_STDC_XA: 16357c478bd9Sstevel@tonic-gate case DT_STDC_XT: 16367c478bd9Sstevel@tonic-gate argv[argc++] = "-D__STDC__=0"; 16377c478bd9Sstevel@tonic-gate break; 16387c478bd9Sstevel@tonic-gate case DT_STDC_XC: 16397c478bd9Sstevel@tonic-gate argv[argc++] = "-D__STDC__=1"; 16407c478bd9Sstevel@tonic-gate break; 16417c478bd9Sstevel@tonic-gate } 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate argv[argc++] = ipath; 16447c478bd9Sstevel@tonic-gate argv[argc++] = opath; 16457c478bd9Sstevel@tonic-gate argv[argc] = NULL; 16467c478bd9Sstevel@tonic-gate 16477c478bd9Sstevel@tonic-gate /* 16487c478bd9Sstevel@tonic-gate * libdtrace must be able to be embedded in other programs that may 16497c478bd9Sstevel@tonic-gate * include application-specific signal handlers. Therefore, if we 16507c478bd9Sstevel@tonic-gate * need to fork to run cpp(1), we must avoid generating a SIGCHLD 16517c478bd9Sstevel@tonic-gate * that could confuse the containing application. To do this, 16527c478bd9Sstevel@tonic-gate * we block SIGCHLD and reset its disposition to SIG_DFL. 16537c478bd9Sstevel@tonic-gate * We restore our signal state once we are done. 16547c478bd9Sstevel@tonic-gate */ 16557c478bd9Sstevel@tonic-gate (void) sigemptyset(&mask); 16567c478bd9Sstevel@tonic-gate (void) sigaddset(&mask, SIGCHLD); 16577c478bd9Sstevel@tonic-gate (void) sigprocmask(SIG_BLOCK, &mask, &omask); 16587c478bd9Sstevel@tonic-gate 16597c478bd9Sstevel@tonic-gate bzero(&act, sizeof (act)); 16607c478bd9Sstevel@tonic-gate act.sa_handler = SIG_DFL; 16617c478bd9Sstevel@tonic-gate (void) sigaction(SIGCHLD, &act, &oact); 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate if ((pid = fork1()) == -1) { 16647c478bd9Sstevel@tonic-gate (void) sigaction(SIGCHLD, &oact, NULL); 16657c478bd9Sstevel@tonic-gate (void) sigprocmask(SIG_SETMASK, &omask, NULL); 16667c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_CPPFORK); 16677c478bd9Sstevel@tonic-gate goto err; 16687c478bd9Sstevel@tonic-gate } 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate if (pid == 0) { 16717c478bd9Sstevel@tonic-gate (void) execvp(dtp->dt_cpp_path, argv); 16727c478bd9Sstevel@tonic-gate _exit(errno == ENOENT ? 127 : 126); 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate do { 16767c478bd9Sstevel@tonic-gate dt_dprintf("waiting for %s (PID %d)\n", dtp->dt_cpp_path, 16777c478bd9Sstevel@tonic-gate (int)pid); 16787c478bd9Sstevel@tonic-gate } while (waitpid(pid, &wstat, 0) == -1 && errno == EINTR); 16797c478bd9Sstevel@tonic-gate 16807c478bd9Sstevel@tonic-gate (void) sigaction(SIGCHLD, &oact, NULL); 16817c478bd9Sstevel@tonic-gate (void) sigprocmask(SIG_SETMASK, &omask, NULL); 16827c478bd9Sstevel@tonic-gate 16837c478bd9Sstevel@tonic-gate dt_dprintf("%s returned exit status 0x%x\n", dtp->dt_cpp_path, wstat); 16847c478bd9Sstevel@tonic-gate estat = WIFEXITED(wstat) ? WEXITSTATUS(wstat) : -1; 16857c478bd9Sstevel@tonic-gate 16867c478bd9Sstevel@tonic-gate if (estat != 0) { 16877c478bd9Sstevel@tonic-gate switch (estat) { 16887c478bd9Sstevel@tonic-gate case 126: 16897c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_CPPEXEC); 16907c478bd9Sstevel@tonic-gate break; 16917c478bd9Sstevel@tonic-gate case 127: 16927c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_CPPENT); 16937c478bd9Sstevel@tonic-gate break; 16947c478bd9Sstevel@tonic-gate default: 16957c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EDT_CPPERR); 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate goto err; 16987c478bd9Sstevel@tonic-gate } 16997c478bd9Sstevel@tonic-gate 17007c478bd9Sstevel@tonic-gate free(argv); 17017c478bd9Sstevel@tonic-gate (void) fflush(ofp); 17027c478bd9Sstevel@tonic-gate (void) fseek(ofp, 0, SEEK_SET); 17037c478bd9Sstevel@tonic-gate return (ofp); 17047c478bd9Sstevel@tonic-gate 17057c478bd9Sstevel@tonic-gate err: 17067c478bd9Sstevel@tonic-gate free(argv); 17077c478bd9Sstevel@tonic-gate (void) fclose(ofp); 17087c478bd9Sstevel@tonic-gate return (NULL); 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate 1711c9d6cd77Sjhaslam static void 1712c9d6cd77Sjhaslam dt_lib_depend_error(dtrace_hdl_t *dtp, const char *format, ...) 1713c9d6cd77Sjhaslam { 1714c9d6cd77Sjhaslam va_list ap; 1715c9d6cd77Sjhaslam 1716c9d6cd77Sjhaslam va_start(ap, format); 1717c9d6cd77Sjhaslam dt_set_errmsg(dtp, NULL, NULL, NULL, 0, format, ap); 1718c9d6cd77Sjhaslam va_end(ap); 1719c9d6cd77Sjhaslam } 1720c9d6cd77Sjhaslam 1721c9d6cd77Sjhaslam int 1722c9d6cd77Sjhaslam dt_lib_depend_add(dtrace_hdl_t *dtp, dt_list_t *dlp, const char *arg) 1723c9d6cd77Sjhaslam { 1724c9d6cd77Sjhaslam dt_lib_depend_t *dld; 1725c9d6cd77Sjhaslam const char *end; 1726c9d6cd77Sjhaslam 1727c9d6cd77Sjhaslam assert(arg != NULL); 1728c9d6cd77Sjhaslam 1729c9d6cd77Sjhaslam if ((end = strrchr(arg, '/')) == NULL) 1730c9d6cd77Sjhaslam return (dt_set_errno(dtp, EINVAL)); 1731c9d6cd77Sjhaslam 1732c9d6cd77Sjhaslam if ((dld = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL) 1733c9d6cd77Sjhaslam return (-1); 1734c9d6cd77Sjhaslam 1735c9d6cd77Sjhaslam if ((dld->dtld_libpath = dt_alloc(dtp, MAXPATHLEN)) == NULL) { 1736c9d6cd77Sjhaslam dt_free(dtp, dld); 1737c9d6cd77Sjhaslam return (-1); 1738c9d6cd77Sjhaslam } 1739c9d6cd77Sjhaslam 1740c9d6cd77Sjhaslam (void) strlcpy(dld->dtld_libpath, arg, end - arg + 2); 1741c9d6cd77Sjhaslam if ((dld->dtld_library = strdup(arg)) == NULL) { 1742c9d6cd77Sjhaslam dt_free(dtp, dld->dtld_libpath); 1743c9d6cd77Sjhaslam dt_free(dtp, dld); 1744c9d6cd77Sjhaslam return (dt_set_errno(dtp, EDT_NOMEM)); 1745c9d6cd77Sjhaslam } 1746c9d6cd77Sjhaslam 1747c9d6cd77Sjhaslam dt_list_append(dlp, dld); 1748c9d6cd77Sjhaslam return (0); 1749c9d6cd77Sjhaslam } 1750c9d6cd77Sjhaslam 1751c9d6cd77Sjhaslam dt_lib_depend_t * 1752c9d6cd77Sjhaslam dt_lib_depend_lookup(dt_list_t *dld, const char *arg) 1753c9d6cd77Sjhaslam { 1754c9d6cd77Sjhaslam dt_lib_depend_t *dldn; 1755c9d6cd77Sjhaslam 1756c9d6cd77Sjhaslam for (dldn = dt_list_next(dld); dldn != NULL; 1757c9d6cd77Sjhaslam dldn = dt_list_next(dldn)) { 1758c9d6cd77Sjhaslam if (strcmp(dldn->dtld_library, arg) == 0) 1759c9d6cd77Sjhaslam return (dldn); 1760c9d6cd77Sjhaslam } 1761c9d6cd77Sjhaslam 1762c9d6cd77Sjhaslam return (NULL); 1763c9d6cd77Sjhaslam } 1764c9d6cd77Sjhaslam 1765c9d6cd77Sjhaslam /* 1766c9d6cd77Sjhaslam * Go through all the library files, and, if any library dependencies exist for 1767c9d6cd77Sjhaslam * that file, add it to that node's list of dependents. The result of this 1768c9d6cd77Sjhaslam * will be a graph which can then be topologically sorted to produce a 1769c9d6cd77Sjhaslam * compilation order. 1770c9d6cd77Sjhaslam */ 1771c9d6cd77Sjhaslam static int 1772c9d6cd77Sjhaslam dt_lib_build_graph(dtrace_hdl_t *dtp) 1773c9d6cd77Sjhaslam { 1774c9d6cd77Sjhaslam dt_lib_depend_t *dld, *dpld; 1775c9d6cd77Sjhaslam 1776c9d6cd77Sjhaslam for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; 1777c9d6cd77Sjhaslam dld = dt_list_next(dld)) { 1778c9d6cd77Sjhaslam char *library = dld->dtld_library; 1779c9d6cd77Sjhaslam 1780c9d6cd77Sjhaslam for (dpld = dt_list_next(&dld->dtld_dependencies); dpld != NULL; 1781c9d6cd77Sjhaslam dpld = dt_list_next(dpld)) { 1782c9d6cd77Sjhaslam dt_lib_depend_t *dlda; 1783c9d6cd77Sjhaslam 1784c9d6cd77Sjhaslam if ((dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep, 1785c9d6cd77Sjhaslam dpld->dtld_library)) == NULL) { 1786c9d6cd77Sjhaslam dt_lib_depend_error(dtp, 1787c9d6cd77Sjhaslam "Invalid library dependency in %s: %s\n", 1788c9d6cd77Sjhaslam dld->dtld_library, dpld->dtld_library); 1789c9d6cd77Sjhaslam 1790c9d6cd77Sjhaslam return (dt_set_errno(dtp, EDT_COMPILER)); 1791c9d6cd77Sjhaslam } 1792c9d6cd77Sjhaslam 1793c9d6cd77Sjhaslam if ((dt_lib_depend_add(dtp, &dlda->dtld_dependents, 1794c9d6cd77Sjhaslam library)) != 0) { 1795c9d6cd77Sjhaslam return (-1); /* preserve dt_errno */ 1796c9d6cd77Sjhaslam } 1797c9d6cd77Sjhaslam } 1798c9d6cd77Sjhaslam } 1799c9d6cd77Sjhaslam return (0); 1800c9d6cd77Sjhaslam } 1801c9d6cd77Sjhaslam 1802c9d6cd77Sjhaslam static int 1803c9d6cd77Sjhaslam dt_topo_sort(dtrace_hdl_t *dtp, dt_lib_depend_t *dld, int *count) 1804c9d6cd77Sjhaslam { 1805c9d6cd77Sjhaslam dt_lib_depend_t *dpld, *dlda, *new; 1806c9d6cd77Sjhaslam 1807c9d6cd77Sjhaslam dld->dtld_start = ++(*count); 1808c9d6cd77Sjhaslam 1809c9d6cd77Sjhaslam for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL; 1810c9d6cd77Sjhaslam dpld = dt_list_next(dpld)) { 1811c9d6cd77Sjhaslam dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep, 1812c9d6cd77Sjhaslam dpld->dtld_library); 1813c9d6cd77Sjhaslam assert(dlda != NULL); 1814c9d6cd77Sjhaslam 1815c9d6cd77Sjhaslam if (dlda->dtld_start == 0 && 1816c9d6cd77Sjhaslam dt_topo_sort(dtp, dlda, count) == -1) 1817c9d6cd77Sjhaslam return (-1); 1818c9d6cd77Sjhaslam } 1819c9d6cd77Sjhaslam 1820c9d6cd77Sjhaslam if ((new = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL) 1821c9d6cd77Sjhaslam return (-1); 1822c9d6cd77Sjhaslam 1823c9d6cd77Sjhaslam if ((new->dtld_library = strdup(dld->dtld_library)) == NULL) { 1824c9d6cd77Sjhaslam dt_free(dtp, new); 1825c9d6cd77Sjhaslam return (dt_set_errno(dtp, EDT_NOMEM)); 1826c9d6cd77Sjhaslam } 1827c9d6cd77Sjhaslam 1828c9d6cd77Sjhaslam new->dtld_start = dld->dtld_start; 1829c9d6cd77Sjhaslam new->dtld_finish = dld->dtld_finish = ++(*count); 1830c9d6cd77Sjhaslam dt_list_prepend(&dtp->dt_lib_dep_sorted, new); 1831c9d6cd77Sjhaslam 1832c9d6cd77Sjhaslam dt_dprintf("library %s sorted (%d/%d)\n", new->dtld_library, 1833c9d6cd77Sjhaslam new->dtld_start, new->dtld_finish); 1834c9d6cd77Sjhaslam 1835c9d6cd77Sjhaslam return (0); 1836c9d6cd77Sjhaslam } 1837c9d6cd77Sjhaslam 1838c9d6cd77Sjhaslam static int 1839c9d6cd77Sjhaslam dt_lib_depend_sort(dtrace_hdl_t *dtp) 1840c9d6cd77Sjhaslam { 1841c9d6cd77Sjhaslam dt_lib_depend_t *dld, *dpld, *dlda; 1842c9d6cd77Sjhaslam int count = 0; 1843c9d6cd77Sjhaslam 1844c9d6cd77Sjhaslam if (dt_lib_build_graph(dtp) == -1) 1845c9d6cd77Sjhaslam return (-1); /* preserve dt_errno */ 1846c9d6cd77Sjhaslam 1847c9d6cd77Sjhaslam /* 1848c9d6cd77Sjhaslam * Perform a topological sort of the graph that hangs off 1849c9d6cd77Sjhaslam * dtp->dt_lib_dep. The result of this process will be a 1850c9d6cd77Sjhaslam * dependency ordered list located at dtp->dt_lib_dep_sorted. 1851c9d6cd77Sjhaslam */ 1852c9d6cd77Sjhaslam for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; 1853c9d6cd77Sjhaslam dld = dt_list_next(dld)) { 1854c9d6cd77Sjhaslam if (dld->dtld_start == 0 && 1855c9d6cd77Sjhaslam dt_topo_sort(dtp, dld, &count) == -1) 1856c9d6cd77Sjhaslam return (-1); /* preserve dt_errno */; 1857c9d6cd77Sjhaslam } 1858c9d6cd77Sjhaslam 1859c9d6cd77Sjhaslam /* 1860c9d6cd77Sjhaslam * Check the graph for cycles. If an ancestor's finishing time is 1861c9d6cd77Sjhaslam * less than any of its dependent's finishing times then a back edge 1862c9d6cd77Sjhaslam * exists in the graph and this is a cycle. 1863c9d6cd77Sjhaslam */ 1864c9d6cd77Sjhaslam for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; 1865c9d6cd77Sjhaslam dld = dt_list_next(dld)) { 1866c9d6cd77Sjhaslam for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL; 1867c9d6cd77Sjhaslam dpld = dt_list_next(dpld)) { 1868c9d6cd77Sjhaslam dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep_sorted, 1869c9d6cd77Sjhaslam dpld->dtld_library); 1870c9d6cd77Sjhaslam assert(dlda != NULL); 1871c9d6cd77Sjhaslam 1872c9d6cd77Sjhaslam if (dlda->dtld_finish > dld->dtld_finish) { 1873c9d6cd77Sjhaslam dt_lib_depend_error(dtp, 1874c9d6cd77Sjhaslam "Cyclic dependency detected: %s => %s\n", 1875c9d6cd77Sjhaslam dld->dtld_library, dpld->dtld_library); 1876c9d6cd77Sjhaslam 1877c9d6cd77Sjhaslam return (dt_set_errno(dtp, EDT_COMPILER)); 1878c9d6cd77Sjhaslam } 1879c9d6cd77Sjhaslam } 1880c9d6cd77Sjhaslam } 1881c9d6cd77Sjhaslam 1882c9d6cd77Sjhaslam return (0); 1883c9d6cd77Sjhaslam } 1884c9d6cd77Sjhaslam 1885c9d6cd77Sjhaslam static void 1886c9d6cd77Sjhaslam dt_lib_depend_free(dtrace_hdl_t *dtp) 1887c9d6cd77Sjhaslam { 1888c9d6cd77Sjhaslam dt_lib_depend_t *dld, *dlda; 1889c9d6cd77Sjhaslam 1890c9d6cd77Sjhaslam while ((dld = dt_list_next(&dtp->dt_lib_dep)) != NULL) { 1891c9d6cd77Sjhaslam while ((dlda = dt_list_next(&dld->dtld_dependencies)) != NULL) { 1892c9d6cd77Sjhaslam dt_list_delete(&dld->dtld_dependencies, dlda); 1893c9d6cd77Sjhaslam dt_free(dtp, dlda->dtld_library); 1894c9d6cd77Sjhaslam dt_free(dtp, dlda->dtld_libpath); 1895c9d6cd77Sjhaslam dt_free(dtp, dlda); 1896c9d6cd77Sjhaslam } 1897c9d6cd77Sjhaslam while ((dlda = dt_list_next(&dld->dtld_dependents)) != NULL) { 1898c9d6cd77Sjhaslam dt_list_delete(&dld->dtld_dependents, dlda); 1899c9d6cd77Sjhaslam dt_free(dtp, dlda->dtld_library); 1900c9d6cd77Sjhaslam dt_free(dtp, dlda->dtld_libpath); 1901c9d6cd77Sjhaslam dt_free(dtp, dlda); 1902c9d6cd77Sjhaslam } 1903c9d6cd77Sjhaslam dt_list_delete(&dtp->dt_lib_dep, dld); 1904c9d6cd77Sjhaslam dt_free(dtp, dld->dtld_library); 1905c9d6cd77Sjhaslam dt_free(dtp, dld->dtld_libpath); 1906c9d6cd77Sjhaslam dt_free(dtp, dld); 1907c9d6cd77Sjhaslam } 1908c9d6cd77Sjhaslam 1909c9d6cd77Sjhaslam while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) { 1910c9d6cd77Sjhaslam dt_list_delete(&dtp->dt_lib_dep_sorted, dld); 1911c9d6cd77Sjhaslam dt_free(dtp, dld->dtld_library); 1912c9d6cd77Sjhaslam dt_free(dtp, dld); 1913c9d6cd77Sjhaslam } 1914c9d6cd77Sjhaslam } 1915c9d6cd77Sjhaslam 1916c9d6cd77Sjhaslam 19177c478bd9Sstevel@tonic-gate /* 1918c9d6cd77Sjhaslam * Open all of the .d library files found in the specified directory and 1919c9d6cd77Sjhaslam * compile each one in topological order to cache its inlines and translators, 1920c9d6cd77Sjhaslam * etc. We silently ignore any missing directories and other files found 1921c9d6cd77Sjhaslam * therein. We only fail (and thereby fail dt_load_libs()) if we fail to 1922c9d6cd77Sjhaslam * compile a library and the error is something other than #pragma D depends_on. 19237c478bd9Sstevel@tonic-gate * Dependency errors are silently ignored to permit a library directory to 19247c478bd9Sstevel@tonic-gate * contain libraries which may not be accessible depending on our privileges. 19257c478bd9Sstevel@tonic-gate */ 19267c478bd9Sstevel@tonic-gate static int 19277c478bd9Sstevel@tonic-gate dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) 19287c478bd9Sstevel@tonic-gate { 19294bc0a2efScasper struct dirent *dp; 19307c478bd9Sstevel@tonic-gate const char *p; 19317c478bd9Sstevel@tonic-gate DIR *dirp; 19327c478bd9Sstevel@tonic-gate 19337c478bd9Sstevel@tonic-gate char fname[PATH_MAX]; 19347c478bd9Sstevel@tonic-gate dtrace_prog_t *pgp; 19357c478bd9Sstevel@tonic-gate FILE *fp; 1936c9d6cd77Sjhaslam void *rv; 1937c9d6cd77Sjhaslam dt_lib_depend_t *dld; 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate if ((dirp = opendir(path)) == NULL) { 19407c478bd9Sstevel@tonic-gate dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno)); 19417c478bd9Sstevel@tonic-gate return (0); 19427c478bd9Sstevel@tonic-gate } 19437c478bd9Sstevel@tonic-gate 1944c9d6cd77Sjhaslam /* First, parse each file for library dependencies. */ 19454bc0a2efScasper while ((dp = readdir(dirp)) != NULL) { 19467c478bd9Sstevel@tonic-gate if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d")) 19477c478bd9Sstevel@tonic-gate continue; /* skip any filename not ending in .d */ 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate (void) snprintf(fname, sizeof (fname), 19507c478bd9Sstevel@tonic-gate "%s/%s", path, dp->d_name); 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate if ((fp = fopen(fname, "r")) == NULL) { 19537c478bd9Sstevel@tonic-gate dt_dprintf("skipping library %s: %s\n", 19547c478bd9Sstevel@tonic-gate fname, strerror(errno)); 19557c478bd9Sstevel@tonic-gate continue; 19567c478bd9Sstevel@tonic-gate } 19577c478bd9Sstevel@tonic-gate 19587c478bd9Sstevel@tonic-gate dtp->dt_filetag = fname; 1959c9d6cd77Sjhaslam if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0) 1960c9d6cd77Sjhaslam goto err; 1961c9d6cd77Sjhaslam 1962c9d6cd77Sjhaslam rv = dt_compile(dtp, DT_CTX_DPROG, 1963c9d6cd77Sjhaslam DTRACE_PROBESPEC_NAME, NULL, 1964c9d6cd77Sjhaslam DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp, NULL); 1965c9d6cd77Sjhaslam 1966c9d6cd77Sjhaslam if (rv != NULL && dtp->dt_errno && 1967c9d6cd77Sjhaslam (dtp->dt_errno != EDT_COMPILER || 1968c9d6cd77Sjhaslam dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) 1969c9d6cd77Sjhaslam goto err; 1970c9d6cd77Sjhaslam 1971c9d6cd77Sjhaslam if (dtp->dt_errno) 1972c9d6cd77Sjhaslam dt_dprintf("error parsing library %s: %s\n", 1973c9d6cd77Sjhaslam fname, dtrace_errmsg(dtp, dtrace_errno(dtp))); 1974c9d6cd77Sjhaslam 1975c9d6cd77Sjhaslam (void) fclose(fp); 1976c9d6cd77Sjhaslam dtp->dt_filetag = NULL; 1977c9d6cd77Sjhaslam } 1978c9d6cd77Sjhaslam 1979c9d6cd77Sjhaslam (void) closedir(dirp); 1980c9d6cd77Sjhaslam /* 1981c9d6cd77Sjhaslam * Finish building the graph containing the library dependencies 1982c9d6cd77Sjhaslam * and perform a topological sort to generate an ordered list 1983c9d6cd77Sjhaslam * for compilation. 1984c9d6cd77Sjhaslam */ 1985c9d6cd77Sjhaslam if (dt_lib_depend_sort(dtp) == -1) 1986c9d6cd77Sjhaslam goto err; 1987c9d6cd77Sjhaslam 1988c9d6cd77Sjhaslam for (dld = dt_list_next(&dtp->dt_lib_dep_sorted); dld != NULL; 1989c9d6cd77Sjhaslam dld = dt_list_next(dld)) { 1990c9d6cd77Sjhaslam 1991c9d6cd77Sjhaslam if ((fp = fopen(dld->dtld_library, "r")) == NULL) { 1992c9d6cd77Sjhaslam dt_dprintf("skipping library %s: %s\n", 1993c9d6cd77Sjhaslam dld->dtld_library, strerror(errno)); 1994c9d6cd77Sjhaslam continue; 1995c9d6cd77Sjhaslam } 1996c9d6cd77Sjhaslam 1997c9d6cd77Sjhaslam dtp->dt_filetag = dld->dtld_library; 19987c478bd9Sstevel@tonic-gate pgp = dtrace_program_fcompile(dtp, fp, DTRACE_C_EMPTY, 0, NULL); 19997c478bd9Sstevel@tonic-gate (void) fclose(fp); 20007c478bd9Sstevel@tonic-gate dtp->dt_filetag = NULL; 20017c478bd9Sstevel@tonic-gate 20027c478bd9Sstevel@tonic-gate if (pgp == NULL && (dtp->dt_errno != EDT_COMPILER || 2003c9d6cd77Sjhaslam dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) 2004c9d6cd77Sjhaslam goto err; 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate if (pgp == NULL) { 2007c9d6cd77Sjhaslam dt_dprintf("skipping library %s: %s\n", 2008c9d6cd77Sjhaslam dld->dtld_library, 20097c478bd9Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 20106009dbc6Sahl } else { 20116009dbc6Sahl dld->dtld_loaded = B_TRUE; 20121a7c1b72Smws dt_program_destroy(dtp, pgp); 20136009dbc6Sahl } 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate 2016c9d6cd77Sjhaslam dt_lib_depend_free(dtp); 20177c478bd9Sstevel@tonic-gate return (0); 2018c9d6cd77Sjhaslam 2019c9d6cd77Sjhaslam err: 2020c9d6cd77Sjhaslam dt_lib_depend_free(dtp); 2021c9d6cd77Sjhaslam return (-1); /* preserve dt_errno */ 20227c478bd9Sstevel@tonic-gate } 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate /* 20257c478bd9Sstevel@tonic-gate * Load the contents of any appropriate DTrace .d library files. These files 20267c478bd9Sstevel@tonic-gate * contain inlines and translators that will be cached by the compiler. We 20277c478bd9Sstevel@tonic-gate * defer this activity until the first compile to permit libdtrace clients to 20287c478bd9Sstevel@tonic-gate * add their own library directories and so that we can properly report errors. 20297c478bd9Sstevel@tonic-gate */ 20307c478bd9Sstevel@tonic-gate static int 20317c478bd9Sstevel@tonic-gate dt_load_libs(dtrace_hdl_t *dtp) 20327c478bd9Sstevel@tonic-gate { 20337c478bd9Sstevel@tonic-gate dt_dirpath_t *dirp; 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate if (dtp->dt_cflags & DTRACE_C_NOLIBS) 20367c478bd9Sstevel@tonic-gate return (0); /* libraries already processed */ 20377c478bd9Sstevel@tonic-gate 20387c478bd9Sstevel@tonic-gate dtp->dt_cflags |= DTRACE_C_NOLIBS; 20397c478bd9Sstevel@tonic-gate 20407c478bd9Sstevel@tonic-gate for (dirp = dt_list_next(&dtp->dt_lib_path); 20417c478bd9Sstevel@tonic-gate dirp != NULL; dirp = dt_list_next(dirp)) { 20427c478bd9Sstevel@tonic-gate if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { 20437c478bd9Sstevel@tonic-gate dtp->dt_cflags &= ~DTRACE_C_NOLIBS; 20447c478bd9Sstevel@tonic-gate return (-1); /* errno is set for us */ 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate } 20477c478bd9Sstevel@tonic-gate 20487c478bd9Sstevel@tonic-gate return (0); 20497c478bd9Sstevel@tonic-gate } 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate static void * 20527c478bd9Sstevel@tonic-gate dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, 20537c478bd9Sstevel@tonic-gate uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s) 20547c478bd9Sstevel@tonic-gate { 20557c478bd9Sstevel@tonic-gate dt_node_t *dnp; 20567c478bd9Sstevel@tonic-gate dt_decl_t *ddp; 20577c478bd9Sstevel@tonic-gate dt_pcb_t pcb; 20587c478bd9Sstevel@tonic-gate void *rv; 20597c478bd9Sstevel@tonic-gate int err; 20607c478bd9Sstevel@tonic-gate 20617c478bd9Sstevel@tonic-gate if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) { 20627c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, EINVAL); 20637c478bd9Sstevel@tonic-gate return (NULL); 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0) 20677c478bd9Sstevel@tonic-gate return (NULL); /* errno is set for us */ 20687c478bd9Sstevel@tonic-gate 2069*c9a6ea2eSBryan Cantrill if (dtp->dt_globals->dh_nelems != 0) 2070*c9a6ea2eSBryan Cantrill (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL); 20717c478bd9Sstevel@tonic-gate 2072*c9a6ea2eSBryan Cantrill if (dtp->dt_tls->dh_nelems != 0) 2073*c9a6ea2eSBryan Cantrill (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL); 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL) 20767c478bd9Sstevel@tonic-gate return (NULL); /* errno is set for us */ 20777c478bd9Sstevel@tonic-gate 20787c478bd9Sstevel@tonic-gate dt_pcb_push(dtp, &pcb); 20797c478bd9Sstevel@tonic-gate 20807c478bd9Sstevel@tonic-gate pcb.pcb_fileptr = fp; 20817c478bd9Sstevel@tonic-gate pcb.pcb_string = s; 20827c478bd9Sstevel@tonic-gate pcb.pcb_strptr = s; 20837c478bd9Sstevel@tonic-gate pcb.pcb_strlen = s ? strlen(s) : 0; 20847c478bd9Sstevel@tonic-gate pcb.pcb_sargc = argc; 20857c478bd9Sstevel@tonic-gate pcb.pcb_sargv = argv; 20867c478bd9Sstevel@tonic-gate pcb.pcb_sflagv = argc ? calloc(argc, sizeof (ushort_t)) : NULL; 20877c478bd9Sstevel@tonic-gate pcb.pcb_pspec = pspec; 20887c478bd9Sstevel@tonic-gate pcb.pcb_cflags = dtp->dt_cflags | cflags; 20897c478bd9Sstevel@tonic-gate pcb.pcb_amin = dtp->dt_amin; 20907c478bd9Sstevel@tonic-gate pcb.pcb_yystate = -1; 20917c478bd9Sstevel@tonic-gate pcb.pcb_context = context; 20927c478bd9Sstevel@tonic-gate pcb.pcb_token = context; 20937c478bd9Sstevel@tonic-gate 2094c9d6cd77Sjhaslam if (context != DT_CTX_DPROG) 20957c478bd9Sstevel@tonic-gate yybegin(YYS_EXPR); 2096c9d6cd77Sjhaslam else if (cflags & DTRACE_C_CTL) 2097c9d6cd77Sjhaslam yybegin(YYS_CONTROL); 2098c9d6cd77Sjhaslam else 2099c9d6cd77Sjhaslam yybegin(YYS_CLAUSE); 21007c478bd9Sstevel@tonic-gate 21017c478bd9Sstevel@tonic-gate if ((err = setjmp(yypcb->pcb_jmpbuf)) != 0) 21027c478bd9Sstevel@tonic-gate goto out; 21037c478bd9Sstevel@tonic-gate 21047c478bd9Sstevel@tonic-gate if (yypcb->pcb_sargc != 0 && yypcb->pcb_sflagv == NULL) 21057c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 21067c478bd9Sstevel@tonic-gate 21077c478bd9Sstevel@tonic-gate yypcb->pcb_idents = dt_idhash_create("ambiguous", NULL, 0, 0); 21087c478bd9Sstevel@tonic-gate yypcb->pcb_locals = dt_idhash_create("clause local", NULL, 21097c478bd9Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate if (yypcb->pcb_idents == NULL || yypcb->pcb_locals == NULL) 21127c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate /* 21157c478bd9Sstevel@tonic-gate * Invoke the parser to evaluate the D source code. If any errors 21167c478bd9Sstevel@tonic-gate * occur during parsing, an error function will be called and we 21177c478bd9Sstevel@tonic-gate * will longjmp back to pcb_jmpbuf to abort. If parsing succeeds, 21187c478bd9Sstevel@tonic-gate * we optionally display the parse tree if debugging is enabled. 21197c478bd9Sstevel@tonic-gate */ 21207c478bd9Sstevel@tonic-gate if (yyparse() != 0 || yypcb->pcb_root == NULL) 21217c478bd9Sstevel@tonic-gate xyerror(D_EMPTY, "empty D program translation unit\n"); 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate yybegin(YYS_DONE); 21247c478bd9Sstevel@tonic-gate 2125c9d6cd77Sjhaslam if (cflags & DTRACE_C_CTL) 2126c9d6cd77Sjhaslam goto out; 2127c9d6cd77Sjhaslam 21287c478bd9Sstevel@tonic-gate if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 1)) 21297c478bd9Sstevel@tonic-gate dt_node_printr(yypcb->pcb_root, stderr, 0); 21307c478bd9Sstevel@tonic-gate 21317c478bd9Sstevel@tonic-gate if (yypcb->pcb_pragmas != NULL) 21327c478bd9Sstevel@tonic-gate (void) dt_idhash_iter(yypcb->pcb_pragmas, dt_idpragma, NULL); 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate if (argc > 1 && !(yypcb->pcb_cflags & DTRACE_C_ARGREF) && 21357c478bd9Sstevel@tonic-gate !(yypcb->pcb_sflagv[argc - 1] & DT_IDFLG_REF)) { 21367c478bd9Sstevel@tonic-gate xyerror(D_MACRO_UNUSED, "extraneous argument '%s' ($%d is " 21377c478bd9Sstevel@tonic-gate "not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1); 21387c478bd9Sstevel@tonic-gate } 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate /* 21417c478bd9Sstevel@tonic-gate * If we have successfully created a parse tree for a D program, loop 21427c478bd9Sstevel@tonic-gate * over the clauses and actions and instantiate the corresponding 21437c478bd9Sstevel@tonic-gate * libdtrace program. If we are parsing a D expression, then we 21447c478bd9Sstevel@tonic-gate * simply run the code generator and assembler on the resulting tree. 21457c478bd9Sstevel@tonic-gate */ 21467c478bd9Sstevel@tonic-gate switch (context) { 21477c478bd9Sstevel@tonic-gate case DT_CTX_DPROG: 21487c478bd9Sstevel@tonic-gate assert(yypcb->pcb_root->dn_kind == DT_NODE_PROG); 21497c478bd9Sstevel@tonic-gate 21507c478bd9Sstevel@tonic-gate if ((dnp = yypcb->pcb_root->dn_list) == NULL && 21517c478bd9Sstevel@tonic-gate !(yypcb->pcb_cflags & DTRACE_C_EMPTY)) 21527c478bd9Sstevel@tonic-gate xyerror(D_EMPTY, "empty D program translation unit\n"); 21537c478bd9Sstevel@tonic-gate 21541a7c1b72Smws if ((yypcb->pcb_prog = dt_program_create(dtp)) == NULL) 21557c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, dtrace_errno(dtp)); 21567c478bd9Sstevel@tonic-gate 21577c478bd9Sstevel@tonic-gate for (; dnp != NULL; dnp = dnp->dn_list) { 21587c478bd9Sstevel@tonic-gate switch (dnp->dn_kind) { 21597c478bd9Sstevel@tonic-gate case DT_NODE_CLAUSE: 21607c478bd9Sstevel@tonic-gate dt_compile_clause(dtp, dnp); 21617c478bd9Sstevel@tonic-gate break; 21621a7c1b72Smws case DT_NODE_XLATOR: 21631a7c1b72Smws if (dtp->dt_xlatemode == DT_XL_DYNAMIC) 21641a7c1b72Smws dt_compile_xlator(dnp); 21651a7c1b72Smws break; 21667c478bd9Sstevel@tonic-gate case DT_NODE_PROVIDER: 21677c478bd9Sstevel@tonic-gate (void) dt_node_cook(dnp, DT_IDFLG_REF); 21687c478bd9Sstevel@tonic-gate break; 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate } 21717c478bd9Sstevel@tonic-gate 21721a7c1b72Smws yypcb->pcb_prog->dp_xrefs = yypcb->pcb_asxrefs; 21731a7c1b72Smws yypcb->pcb_prog->dp_xrefslen = yypcb->pcb_asxreflen; 21741a7c1b72Smws yypcb->pcb_asxrefs = NULL; 21751a7c1b72Smws yypcb->pcb_asxreflen = 0; 21761a7c1b72Smws 21771a7c1b72Smws rv = yypcb->pcb_prog; 21787c478bd9Sstevel@tonic-gate break; 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate case DT_CTX_DEXPR: 21817c478bd9Sstevel@tonic-gate (void) dt_node_cook(yypcb->pcb_root, DT_IDFLG_REF); 21827c478bd9Sstevel@tonic-gate dt_cg(yypcb, yypcb->pcb_root); 21837c478bd9Sstevel@tonic-gate rv = dt_as(yypcb); 21847c478bd9Sstevel@tonic-gate break; 21857c478bd9Sstevel@tonic-gate 21867c478bd9Sstevel@tonic-gate case DT_CTX_DTYPE: 21877c478bd9Sstevel@tonic-gate ddp = (dt_decl_t *)yypcb->pcb_root; /* root is really a decl */ 21887c478bd9Sstevel@tonic-gate err = dt_decl_type(ddp, arg); 21897c478bd9Sstevel@tonic-gate dt_decl_free(ddp); 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate if (err != 0) 21927c478bd9Sstevel@tonic-gate longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate rv = NULL; 21957c478bd9Sstevel@tonic-gate break; 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate 21987c478bd9Sstevel@tonic-gate out: 21997c478bd9Sstevel@tonic-gate if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 3)) 22007c478bd9Sstevel@tonic-gate dt_node_printr(yypcb->pcb_root, stderr, 0); 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 || 22037c478bd9Sstevel@tonic-gate lseek64(dtp->dt_cdefs_fd, 0, SEEK_SET) == -1 || 22047c478bd9Sstevel@tonic-gate ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR)) 22057c478bd9Sstevel@tonic-gate dt_dprintf("failed to update CTF cache: %s\n", strerror(errno)); 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate if (dtp->dt_ddefs_fd != -1 && (ftruncate64(dtp->dt_ddefs_fd, 0) == -1 || 22087c478bd9Sstevel@tonic-gate lseek64(dtp->dt_ddefs_fd, 0, SEEK_SET) == -1 || 22097c478bd9Sstevel@tonic-gate ctf_write(dtp->dt_ddefs->dm_ctfp, dtp->dt_ddefs_fd) == CTF_ERR)) 22107c478bd9Sstevel@tonic-gate dt_dprintf("failed to update CTF cache: %s\n", strerror(errno)); 22117c478bd9Sstevel@tonic-gate 22127c478bd9Sstevel@tonic-gate if (yypcb->pcb_fileptr && (cflags & DTRACE_C_CPP)) 22137c478bd9Sstevel@tonic-gate (void) fclose(yypcb->pcb_fileptr); /* close dt_preproc() file */ 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate dt_pcb_pop(dtp, err); 22167c478bd9Sstevel@tonic-gate (void) dt_set_errno(dtp, err); 22177c478bd9Sstevel@tonic-gate return (err ? NULL : rv); 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate dtrace_prog_t * 22217c478bd9Sstevel@tonic-gate dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s, 22227c478bd9Sstevel@tonic-gate dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[]) 22237c478bd9Sstevel@tonic-gate { 22247c478bd9Sstevel@tonic-gate return (dt_compile(dtp, DT_CTX_DPROG, 22257c478bd9Sstevel@tonic-gate spec, NULL, cflags, argc, argv, NULL, s)); 22267c478bd9Sstevel@tonic-gate } 22277c478bd9Sstevel@tonic-gate 22287c478bd9Sstevel@tonic-gate dtrace_prog_t * 22297c478bd9Sstevel@tonic-gate dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp, 22307c478bd9Sstevel@tonic-gate uint_t cflags, int argc, char *const argv[]) 22317c478bd9Sstevel@tonic-gate { 22327c478bd9Sstevel@tonic-gate return (dt_compile(dtp, DT_CTX_DPROG, 22337c478bd9Sstevel@tonic-gate DTRACE_PROBESPEC_NAME, NULL, cflags, argc, argv, fp, NULL)); 22347c478bd9Sstevel@tonic-gate } 22357c478bd9Sstevel@tonic-gate 22367c478bd9Sstevel@tonic-gate int 22377c478bd9Sstevel@tonic-gate dtrace_type_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_typeinfo_t *dtt) 22387c478bd9Sstevel@tonic-gate { 22397c478bd9Sstevel@tonic-gate (void) dt_compile(dtp, DT_CTX_DTYPE, 22407c478bd9Sstevel@tonic-gate DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, NULL, s); 22417c478bd9Sstevel@tonic-gate return (dtp->dt_errno ? -1 : 0); 22427c478bd9Sstevel@tonic-gate } 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate int 22457c478bd9Sstevel@tonic-gate dtrace_type_fcompile(dtrace_hdl_t *dtp, FILE *fp, dtrace_typeinfo_t *dtt) 22467c478bd9Sstevel@tonic-gate { 22477c478bd9Sstevel@tonic-gate (void) dt_compile(dtp, DT_CTX_DTYPE, 22487c478bd9Sstevel@tonic-gate DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, fp, NULL); 22497c478bd9Sstevel@tonic-gate return (dtp->dt_errno ? -1 : 0); 22507c478bd9Sstevel@tonic-gate } 2251