Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/cmd/scripts/dstyle.pl =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/cmd/scripts/dstyle.pl (revision 304199) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/cmd/scripts/dstyle.pl (revision 304200) @@ -1,235 +1,240 @@ #!/usr/local/bin/perl # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# +# Copyright (c) 2014, 2016 by Delphix. All rights reserved. +# + require 5.8.4; $PNAME = $0; $PNAME =~ s:.*/::; $USAGE = "Usage: $PNAME [file ...]\n"; $errs = 0; sub err { my($msg) = @_; print "$file: $lineno: $msg\n"; $errs++; } sub dstyle { open(FILE, "$file"); $lineno = 0; $inclause = 0; $skipnext = 0; while () { $lineno++; chop; if ($skipnext) { $skipnext = 0; next; } # # Amazingly, some ident strings are longer than 80 characters! # if (/^#pragma ident/) { next; } # # The algorithm to calculate line length from cstyle. # $line = $_; if ($line =~ tr/\t/\t/ * 7 + length($line) > 80) { # yes, there is a chance. # replace tabs with spaces and check again. $eline = $line; 1 while $eline =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; if (length($eline) > 80) { err "line > 80 characters"; } } if (/\/\*DSTYLED\*\//) { $skipnext = 1; next; } if (/^#pragma/) { next; } if (/^#include/) { next; } # # Before we do any more analysis, we want to prune out any # quoted strings. This is a bit tricky because we need # to be careful of backslashed quotes within quoted strings. # I'm sure there is a very crafty way to do this with a # single regular expression, but that will have to wait for # somone with better regex juju that I; we do this by first # eliminating the backslashed quotes, and then eliminating # whatever quoted strings are left. Note that we eliminate # the string by replacing it with "quotedstr"; this is to # allow lines to end with a quoted string. (If we simply # eliminated the quoted string, dstyle might complain about # the line ending in a space or tab.) # s/\\\"//g; s/\"[^\"]*\"/quotedstr/g; if (/[ \t]$/) { err "space or tab at end of line"; } if (/^[\t]+[ ]+[\t]+/) { err "spaces between tabs"; } if (/^[\t]* \*/) { next; } if (/^ /) { err "indented by spaces not tabs"; } if (/^{}$/) { next; } if (!/^enum/ && !/^\t*struct/ && !/^\t*union/ && !/^typedef/ && - !/^translator/ && !/^provider/) { + !/^translator/ && !/^provider/ && !/\tif / && + !/ else /) { if (/[\w\s]+{/) { err "left brace not on its own line"; } if (/{[\w\s]+/) { err "left brace not on its own line"; } } - if (!/;$/) { + if (!/;$/ && !/\t*}$/ && !/ else /) { if (/[\w\s]+}/) { err "right brace not on its own line"; } if (/}[\w\s]+/) { err "right brace not on its own line"; } } if (/^}/) { $inclause = 0; } if (!$inclause && /^[\w ]+\//) { err "predicate not at beginning of line"; } if (!$inclause && /^\/[ \t]+\w/) { err "space between '/' and expression in predicate"; } if (!$inclause && /\w[ \t]+\/$/) { err "space between expression and '/' in predicate"; } if (!$inclause && /\s,/) { err "space before comma in probe description"; } if (!$inclause && /\w,[\w\s]/ && !/;$/) { if (!/extern/ && !/\(/ && !/inline/) { err "multiple probe descriptions on same line"; } } if ($inclause && /sizeof\(/) { err "missing space after sizeof"; } if ($inclause && /^[\w ]/) { err "line doesn't begin with a tab"; } if ($inclause && /,[\w]/) { err "comma without trailing space"; } if (/\w&&/ || /&&\w/ || /\w\|\|/ || /\|\|\w/) { err "logical operator not set off with spaces"; } # # We want to catch "i<0" variants, but we don't want to # erroneously flag translators. # if (!/\w<\w+>\(/) { if (/\w>/ || / >\w/ || /\w=\w/ || /\w!=/ || /!=\w/) { err "comparison operator not set off with spaces"; } if (/\w=/ || /=\w/) { err "assignment operator not set off with spaces"; } if (/^{/) { $inclause = 1; } } } foreach $arg (@ARGV) { if (-f $arg) { push(@files, $arg); } else { die "$PNAME: $arg is not a valid file\n"; } } die $USAGE if (scalar(@files) == 0); foreach $file (@files) { dstyle($file); } exit($errs != 0); Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.else.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.else.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.else.d (revision 304200) @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * "else" statement is executed + */ + +BEGIN +{ + if (0) { + n = 1; + } else { + n = 0; + } + exit(n) +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if.d (revision 304200) @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * "if" statement executes the correct body. + */ + +BEGIN +{ + if (1) { + n = 0; + } else { + n = 1; + } + exit(n) +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if2.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if2.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if2.d (revision 304200) @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * "if" statement executes the correct body. + * parses single-statement, braceless bodies correctly. + */ + +BEGIN +{ + if (1) + n = 0; + else + n = 1; + exit(n) +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_before_after.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_before_after.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_before_after.d (revision 304200) @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * statements before and after an if statement are executed. + */ + +BEGIN +{ + i = 1; + if (1) { + i++; + } else { + i++; + } + i++; +} + +BEGIN +/i == 3/ +{ + exit(0); +} + +BEGIN +/i != 3/ +{ + exit(1); +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_nested.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_nested.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_nested.d (revision 304200) @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * nested "if" statement executes the correct body. + */ + +BEGIN +{ + if (0) { + exit(1); + } else { + if (0) { + exit(1); + } else { + exit(0); + } + exit(1); + } + exit(1); +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon.d (revision 304200) @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * "if" body without trailing semicolon parses correctly + */ + +BEGIN +{ + if (1) { + exit(0) + } +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon2.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon2.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/sugar/tst.if_trailing_semicolon2.d (revision 304200) @@ -0,0 +1,31 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. + */ + +/* + * ASSERTION: + * "if" body without trailing semicolon parses correctly + */ + +BEGIN +{ + if (1) { + i = 1; + exit(0) + } +} Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c (revision 304200) @@ -1,2632 +1,2655 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016 by Delphix. All rights reserved. * Copyright (c) 2013, Joyent Inc. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. * Copyright 2015 Gary Mills */ /* * DTrace D Language Compiler * * The code in this source file implements the main engine for the D language * compiler. The driver routine for the compiler is dt_compile(), below. The * compiler operates on either stdio FILEs or in-memory strings as its input * and can produce either dtrace_prog_t structures from a D program or a single * dtrace_difo_t structure from a D expression. Multiple entry points are * provided as wrappers around dt_compile() for the various input/output pairs. * The compiler itself is implemented across the following source files: * * dt_lex.l - lex scanner * dt_grammar.y - yacc grammar * dt_parser.c - parse tree creation and semantic checking * dt_decl.c - declaration stack processing * dt_xlator.c - D translator lookup and creation * dt_ident.c - identifier and symbol table routines * dt_pragma.c - #pragma processing and D pragmas * dt_printf.c - D printf() and printa() argument checking and processing * dt_cc.c - compiler driver and dtrace_prog_t construction * dt_cg.c - DIF code generator * dt_as.c - DIF assembler * dt_dof.c - dtrace_prog_t -> DOF conversion * * Several other source files provide collections of utility routines used by * these major files. The compiler itself is implemented in multiple passes: * * (1) The input program is scanned and parsed by dt_lex.l and dt_grammar.y * and parse tree nodes are constructed using the routines in dt_parser.c. * This node construction pass is described further in dt_parser.c. * * (2) The parse tree is "cooked" by assigning each clause a context (see the * routine dt_setcontext(), below) based on its probe description and then * recursively descending the tree performing semantic checking. The cook * routines are also implemented in dt_parser.c and described there. * * (3) For actions that are DIF expression statements, the DIF code generator * and assembler are invoked to create a finished DIFO for the statement. * * (4) The dtrace_prog_t data structures for the program clauses and actions * are built, containing pointers to any DIFOs created in step (3). * * (5) The caller invokes a routine in dt_dof.c to convert the finished program * into DOF format for use in anonymous tracing or enabling in the kernel. * * In the implementation, steps 2-4 are intertwined in that they are performed * in order for each clause as part of a loop that executes over the clauses. * * The D compiler currently implements nearly no optimization. The compiler * implements integer constant folding as part of pass (1), and a set of very * simple peephole optimizations as part of pass (3). As with any C compiler, * a large number of optimizations are possible on both the intermediate data * structures and the generated DIF code. These possibilities should be * investigated in the context of whether they will have any substantive effect * on the overall DTrace probe effect before they are undertaken. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static const dtrace_diftype_t dt_void_rtype = { DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, 0 }; static const dtrace_diftype_t dt_int_rtype = { DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, sizeof (uint64_t) }; static void *dt_compile(dtrace_hdl_t *, int, dtrace_probespec_t, void *, uint_t, int, char *const[], FILE *, const char *); - /*ARGSUSED*/ static int dt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored) { idp->di_flags &= ~(DT_IDFLG_REF | DT_IDFLG_MOD | DT_IDFLG_DIFR | DT_IDFLG_DIFW); return (0); } /*ARGSUSED*/ static int dt_idpragma(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored) { yylineno = idp->di_lineno; xyerror(D_PRAGMA_UNUSED, "unused #pragma %s\n", (char *)idp->di_iarg); return (0); } static dtrace_stmtdesc_t * dt_stmt_create(dtrace_hdl_t *dtp, dtrace_ecbdesc_t *edp, dtrace_attribute_t descattr, dtrace_attribute_t stmtattr) { dtrace_stmtdesc_t *sdp = dtrace_stmt_create(dtp, edp); if (sdp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); assert(yypcb->pcb_stmt == NULL); yypcb->pcb_stmt = sdp; sdp->dtsd_descattr = descattr; sdp->dtsd_stmtattr = stmtattr; return (sdp); } static dtrace_actdesc_t * dt_stmt_action(dtrace_hdl_t *dtp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *new; if ((new = dtrace_stmt_action(dtp, sdp)) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); return (new); } /* * Utility function to determine if a given action description is destructive. * The dtdo_destructive bit is set for us by the DIF assembler (see dt_as.c). */ static int dt_action_destructive(const dtrace_actdesc_t *ap) { return (DTRACEACT_ISDESTRUCTIVE(ap->dtad_kind) || (ap->dtad_kind == DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_destructive)); } static void dt_stmt_append(dtrace_stmtdesc_t *sdp, const dt_node_t *dnp) { dtrace_ecbdesc_t *edp = sdp->dtsd_ecbdesc; dtrace_actdesc_t *ap, *tap; int commit = 0; int speculate = 0; int datarec = 0; /* * Make sure that the new statement jibes with the rest of the ECB. */ for (ap = edp->dted_action; ap != NULL; ap = ap->dtad_next) { if (ap->dtad_kind == DTRACEACT_COMMIT) { if (commit) { dnerror(dnp, D_COMM_COMM, "commit( ) may " "not follow commit( )\n"); } if (datarec) { dnerror(dnp, D_COMM_DREC, "commit( ) may " "not follow data-recording action(s)\n"); } for (tap = ap; tap != NULL; tap = tap->dtad_next) { if (!DTRACEACT_ISAGG(tap->dtad_kind)) continue; dnerror(dnp, D_AGG_COMM, "aggregating actions " "may not follow commit( )\n"); } commit = 1; continue; } if (ap->dtad_kind == DTRACEACT_SPECULATE) { if (speculate) { dnerror(dnp, D_SPEC_SPEC, "speculate( ) may " "not follow speculate( )\n"); } if (commit) { dnerror(dnp, D_SPEC_COMM, "speculate( ) may " "not follow commit( )\n"); } if (datarec) { dnerror(dnp, D_SPEC_DREC, "speculate( ) may " "not follow data-recording action(s)\n"); } speculate = 1; continue; } if (DTRACEACT_ISAGG(ap->dtad_kind)) { if (speculate) { dnerror(dnp, D_AGG_SPEC, "aggregating actions " "may not follow speculate( )\n"); } datarec = 1; continue; } if (speculate) { if (dt_action_destructive(ap)) { dnerror(dnp, D_ACT_SPEC, "destructive actions " "may not follow speculate( )\n"); } if (ap->dtad_kind == DTRACEACT_EXIT) { dnerror(dnp, D_EXIT_SPEC, "exit( ) may not " "follow speculate( )\n"); } } /* * Exclude all non data-recording actions. */ if (dt_action_destructive(ap) || ap->dtad_kind == DTRACEACT_DISCARD) continue; if (ap->dtad_kind == DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_CTF && ap->dtad_difo->dtdo_rtype.dtdt_size == 0) continue; if (commit) { dnerror(dnp, D_DREC_COMM, "data-recording actions " "may not follow commit( )\n"); } if (!speculate) datarec = 1; } if (dtrace_stmt_add(yypcb->pcb_hdl, yypcb->pcb_prog, sdp) != 0) longjmp(yypcb->pcb_jmpbuf, dtrace_errno(yypcb->pcb_hdl)); if (yypcb->pcb_stmt == sdp) yypcb->pcb_stmt = NULL; } /* * For the first element of an aggregation tuple or for printa(), we create a * simple DIF program that simply returns the immediate value that is the ID * of the aggregation itself. This could be optimized in the future by * creating a new in-kernel dtad_kind that just returns an integer. */ static void dt_action_difconst(dtrace_actdesc_t *ap, uint_t id, dtrace_actkind_t kind) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dtrace_difo_t *dp = dt_zalloc(dtp, sizeof (dtrace_difo_t)); if (dp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dp->dtdo_buf = dt_alloc(dtp, sizeof (dif_instr_t) * 2); dp->dtdo_inttab = dt_alloc(dtp, sizeof (uint64_t)); if (dp->dtdo_buf == NULL || dp->dtdo_inttab == NULL) { dt_difo_free(dtp, dp); longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); } dp->dtdo_buf[0] = DIF_INSTR_SETX(0, 1); /* setx DIF_INTEGER[0], %r1 */ dp->dtdo_buf[1] = DIF_INSTR_RET(1); /* ret %r1 */ dp->dtdo_len = 2; dp->dtdo_inttab[0] = id; dp->dtdo_intlen = 1; dp->dtdo_rtype = dt_int_rtype; ap->dtad_difo = dp; ap->dtad_kind = kind; } static void dt_action_clear(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dt_ident_t *aid; dtrace_actdesc_t *ap; dt_node_t *anp; char n[DT_TYPE_NAMELEN]; int argc = 0; for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) argc++; /* count up arguments for error messages below */ if (argc != 1) { dnerror(dnp, D_CLEAR_PROTO, "%s( ) prototype mismatch: %d args passed, 1 expected\n", dnp->dn_ident->di_name, argc); } anp = dnp->dn_args; assert(anp != NULL); if (anp->dn_kind != DT_NODE_AGG) { dnerror(dnp, D_CLEAR_AGGARG, "%s( ) argument #1 is incompatible with prototype:\n" "\tprototype: aggregation\n\t argument: %s\n", dnp->dn_ident->di_name, dt_node_type_name(anp, n, sizeof (n))); } aid = anp->dn_ident; if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { dnerror(dnp, D_CLEAR_AGGBAD, "undefined aggregation: @%s\n", aid->di_name); } ap = dt_stmt_action(dtp, sdp); dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); ap->dtad_arg = DT_ACT_CLEAR; } static void dt_action_normalize(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dt_ident_t *aid; dtrace_actdesc_t *ap; dt_node_t *anp, *normal; int denormal = (strcmp(dnp->dn_ident->di_name, "denormalize") == 0); char n[DT_TYPE_NAMELEN]; int argc = 0; for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) argc++; /* count up arguments for error messages below */ if ((denormal && argc != 1) || (!denormal && argc != 2)) { dnerror(dnp, D_NORMALIZE_PROTO, "%s( ) prototype mismatch: %d args passed, %d expected\n", dnp->dn_ident->di_name, argc, denormal ? 1 : 2); } anp = dnp->dn_args; assert(anp != NULL); if (anp->dn_kind != DT_NODE_AGG) { dnerror(dnp, D_NORMALIZE_AGGARG, "%s( ) argument #1 is incompatible with prototype:\n" "\tprototype: aggregation\n\t argument: %s\n", dnp->dn_ident->di_name, dt_node_type_name(anp, n, sizeof (n))); } if ((normal = anp->dn_list) != NULL && !dt_node_is_scalar(normal)) { dnerror(dnp, D_NORMALIZE_SCALAR, "%s( ) argument #2 must be of scalar type\n", dnp->dn_ident->di_name); } aid = anp->dn_ident; if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { dnerror(dnp, D_NORMALIZE_AGGBAD, "undefined aggregation: @%s\n", aid->di_name); } ap = dt_stmt_action(dtp, sdp); dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); if (denormal) { ap->dtad_arg = DT_ACT_DENORMALIZE; return; } ap->dtad_arg = DT_ACT_NORMALIZE; assert(normal != NULL); ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, normal); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_LIBACT; ap->dtad_arg = DT_ACT_NORMALIZE; } static void dt_action_trunc(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dt_ident_t *aid; dtrace_actdesc_t *ap; dt_node_t *anp, *trunc; char n[DT_TYPE_NAMELEN]; int argc = 0; for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) argc++; /* count up arguments for error messages below */ if (argc > 2 || argc < 1) { dnerror(dnp, D_TRUNC_PROTO, "%s( ) prototype mismatch: %d args passed, %s expected\n", dnp->dn_ident->di_name, argc, argc < 1 ? "at least 1" : "no more than 2"); } anp = dnp->dn_args; assert(anp != NULL); trunc = anp->dn_list; if (anp->dn_kind != DT_NODE_AGG) { dnerror(dnp, D_TRUNC_AGGARG, "%s( ) argument #1 is incompatible with prototype:\n" "\tprototype: aggregation\n\t argument: %s\n", dnp->dn_ident->di_name, dt_node_type_name(anp, n, sizeof (n))); } if (argc == 2) { assert(trunc != NULL); if (!dt_node_is_scalar(trunc)) { dnerror(dnp, D_TRUNC_SCALAR, "%s( ) argument #2 must be of scalar type\n", dnp->dn_ident->di_name); } } aid = anp->dn_ident; if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { dnerror(dnp, D_TRUNC_AGGBAD, "undefined aggregation: @%s\n", aid->di_name); } ap = dt_stmt_action(dtp, sdp); dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT); ap->dtad_arg = DT_ACT_TRUNC; ap = dt_stmt_action(dtp, sdp); if (argc == 1) { dt_action_difconst(ap, 0, DTRACEACT_LIBACT); } else { assert(trunc != NULL); dt_cg(yypcb, trunc); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_LIBACT; } ap->dtad_arg = DT_ACT_TRUNC; } static void dt_action_printa(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dt_ident_t *aid, *fid; dtrace_actdesc_t *ap; const char *format; dt_node_t *anp, *proto = NULL; char n[DT_TYPE_NAMELEN]; int argc = 0, argr = 0; for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list) argc++; /* count up arguments for error messages below */ switch (dnp->dn_args->dn_kind) { case DT_NODE_STRING: format = dnp->dn_args->dn_string; anp = dnp->dn_args->dn_list; argr = 2; break; case DT_NODE_AGG: format = NULL; anp = dnp->dn_args; argr = 1; break; default: format = NULL; anp = dnp->dn_args; argr = 1; } if (argc < argr) { dnerror(dnp, D_PRINTA_PROTO, "%s( ) prototype mismatch: %d args passed, %d expected\n", dnp->dn_ident->di_name, argc, argr); } assert(anp != NULL); while (anp != NULL) { if (anp->dn_kind != DT_NODE_AGG) { dnerror(dnp, D_PRINTA_AGGARG, "%s( ) argument #%d is incompatible with " "prototype:\n\tprototype: aggregation\n" "\t argument: %s\n", dnp->dn_ident->di_name, argr, dt_node_type_name(anp, n, sizeof (n))); } aid = anp->dn_ident; fid = aid->di_iarg; if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) { dnerror(dnp, D_PRINTA_AGGBAD, "undefined aggregation: @%s\n", aid->di_name); } /* * If we have multiple aggregations, we must be sure that * their key signatures match. */ if (proto != NULL) { dt_printa_validate(proto, anp); } else { proto = anp; } if (format != NULL) { yylineno = dnp->dn_line; sdp->dtsd_fmtdata = dt_printf_create(yypcb->pcb_hdl, format); dt_printf_validate(sdp->dtsd_fmtdata, DT_PRINTF_AGGREGATION, dnp->dn_ident, 1, fid->di_id, ((dt_idsig_t *)aid->di_data)->dis_args); format = NULL; } ap = dt_stmt_action(dtp, sdp); dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_PRINTA); anp = anp->dn_list; argr++; } } static void dt_action_printflike(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp, dtrace_actkind_t kind) { dt_node_t *anp, *arg1; dtrace_actdesc_t *ap = NULL; char n[DT_TYPE_NAMELEN], *str; assert(DTRACEACT_ISPRINTFLIKE(kind)); if (dnp->dn_args->dn_kind != DT_NODE_STRING) { dnerror(dnp, D_PRINTF_ARG_FMT, "%s( ) argument #1 is incompatible with prototype:\n" "\tprototype: string constant\n\t argument: %s\n", dnp->dn_ident->di_name, dt_node_type_name(dnp->dn_args, n, sizeof (n))); } arg1 = dnp->dn_args->dn_list; yylineno = dnp->dn_line; str = dnp->dn_args->dn_string; /* * If this is an freopen(), we use an empty string to denote that * stdout should be restored. For other printf()-like actions, an * empty format string is illegal: an empty format string would * result in malformed DOF, and the compiler thus flags an empty * format string as a compile-time error. To avoid propagating the * freopen() special case throughout the system, we simply transpose * an empty string into a sentinel string (DT_FREOPEN_RESTORE) that * denotes that stdout should be restored. */ if (kind == DTRACEACT_FREOPEN) { if (strcmp(str, DT_FREOPEN_RESTORE) == 0) { /* * Our sentinel is always an invalid argument to * freopen(), but if it's been manually specified, we * must fail now instead of when the freopen() is * actually evaluated. */ dnerror(dnp, D_FREOPEN_INVALID, "%s( ) argument #1 cannot be \"%s\"\n", dnp->dn_ident->di_name, DT_FREOPEN_RESTORE); } if (str[0] == '\0') str = DT_FREOPEN_RESTORE; } sdp->dtsd_fmtdata = dt_printf_create(dtp, str); dt_printf_validate(sdp->dtsd_fmtdata, DT_PRINTF_EXACTLEN, dnp->dn_ident, 1, DTRACEACT_AGGREGATION, arg1); if (arg1 == NULL) { dif_instr_t *dbuf; dtrace_difo_t *dp; if ((dbuf = dt_alloc(dtp, sizeof (dif_instr_t))) == NULL || (dp = dt_zalloc(dtp, sizeof (dtrace_difo_t))) == NULL) { dt_free(dtp, dbuf); longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); } dbuf[0] = DIF_INSTR_RET(DIF_REG_R0); /* ret %r0 */ dp->dtdo_buf = dbuf; dp->dtdo_len = 1; dp->dtdo_rtype = dt_int_rtype; ap = dt_stmt_action(dtp, sdp); ap->dtad_difo = dp; ap->dtad_kind = kind; return; } for (anp = arg1; anp != NULL; anp = anp->dn_list) { ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, anp); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = kind; } } static void dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { int ctflib; dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); boolean_t istrace = (dnp->dn_ident->di_id == DT_ACT_TRACE); const char *act = istrace ? "trace" : "print"; if (dt_node_is_void(dnp->dn_args)) { dnerror(dnp->dn_args, istrace ? D_TRACE_VOID : D_PRINT_VOID, "%s( ) may not be applied to a void expression\n", act); } if (dt_node_resolve(dnp->dn_args, DT_IDENT_XLPTR) != NULL) { dnerror(dnp->dn_args, istrace ? D_TRACE_DYN : D_PRINT_DYN, "%s( ) may not be applied to a translated pointer\n", act); } if (dnp->dn_args->dn_kind == DT_NODE_AGG) { dnerror(dnp->dn_args, istrace ? D_TRACE_AGG : D_PRINT_AGG, "%s( ) may not be applied to an aggregation%s\n", act, istrace ? "" : " -- did you mean printa()?"); } dt_cg(yypcb, dnp->dn_args); /* * The print() action behaves identically to trace(), except that it * stores the CTF type of the argument (if present) within the DOF for * the DIFEXPR action. To do this, we set the 'dtsd_strdata' to point * to the fully-qualified CTF type ID for the result of the DIF * action. We use the ID instead of the name to handles complex types * like arrays and function pointers that can't be resolved by * ctf_type_lookup(). This is later processed by dtrace_dof_create() * and turned into a reference into the string table so that we can * get the type information when we process the data after the fact. In * the case where we are referring to userland CTF data, we also need to * to identify which ctf container in question we care about and encode * that within the name. */ if (dnp->dn_ident->di_id == DT_ACT_PRINT) { dt_node_t *dret; size_t n; dt_module_t *dmp; dret = yypcb->pcb_dret; dmp = dt_module_lookup_by_ctf(dtp, dret->dn_ctfp); n = snprintf(NULL, 0, "%s`%ld", dmp->dm_name, dret->dn_type) + 1; if (dmp->dm_pid != 0) { ctflib = dt_module_getlibid(dtp, dmp, dret->dn_ctfp); assert(ctflib >= 0); n = snprintf(NULL, 0, "%s`%d`%ld", dmp->dm_name, ctflib, dret->dn_type) + 1; } else { n = snprintf(NULL, 0, "%s`%ld", dmp->dm_name, dret->dn_type) + 1; } sdp->dtsd_strdata = dt_alloc(dtp, n); if (sdp->dtsd_strdata == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); (void) snprintf(sdp->dtsd_strdata, n, "%s`%ld", dmp->dm_name, dret->dn_type); if (dmp->dm_pid != 0) { (void) snprintf(sdp->dtsd_strdata, n, "%s`%d`%ld", dmp->dm_name, ctflib, dret->dn_type); } else { (void) snprintf(sdp->dtsd_strdata, n, "%s`%ld", dmp->dm_name, dret->dn_type); } } ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_DIFEXPR; } static void dt_action_tracemem(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_node_t *addr = dnp->dn_args; dt_node_t *max = dnp->dn_args->dn_list; dt_node_t *size; char n[DT_TYPE_NAMELEN]; if (dt_node_is_integer(addr) == 0 && dt_node_is_pointer(addr) == 0) { dnerror(addr, D_TRACEMEM_ADDR, "tracemem( ) argument #1 is incompatible with " "prototype:\n\tprototype: pointer or integer\n" "\t argument: %s\n", dt_node_type_name(addr, n, sizeof (n))); } if (dt_node_is_posconst(max) == 0) { dnerror(max, D_TRACEMEM_SIZE, "tracemem( ) argument #2 must " "be a non-zero positive integral constant expression\n"); } if ((size = max->dn_list) != NULL) { if (size->dn_list != NULL) { dnerror(size, D_TRACEMEM_ARGS, "tracemem ( ) prototype " "mismatch: expected at most 3 args\n"); } if (!dt_node_is_scalar(size)) { dnerror(size, D_TRACEMEM_DYNSIZE, "tracemem ( ) " "dynamic size (argument #3) must be of " "scalar type\n"); } dt_cg(yypcb, size); ap->dtad_difo = dt_as(yypcb); ap->dtad_difo->dtdo_rtype = dt_int_rtype; ap->dtad_kind = DTRACEACT_TRACEMEM_DYNSIZE; ap = dt_stmt_action(dtp, sdp); } dt_cg(yypcb, addr); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_TRACEMEM; ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF; ap->dtad_difo->dtdo_rtype.dtdt_size = max->dn_value; } static void dt_action_stack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *arg0) { ap->dtad_kind = DTRACEACT_STACK; if (dtp->dt_options[DTRACEOPT_STACKFRAMES] != DTRACEOPT_UNSET) { ap->dtad_arg = dtp->dt_options[DTRACEOPT_STACKFRAMES]; } else { ap->dtad_arg = 0; } if (arg0 != NULL) { if (arg0->dn_list != NULL) { dnerror(arg0, D_STACK_PROTO, "stack( ) prototype " "mismatch: too many arguments\n"); } if (dt_node_is_posconst(arg0) == 0) { dnerror(arg0, D_STACK_SIZE, "stack( ) size must be a " "non-zero positive integral constant expression\n"); } ap->dtad_arg = arg0->dn_value; } } static void dt_action_stack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_action_stack_args(dtp, ap, dnp->dn_args); } static void dt_action_ustack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *dnp) { uint32_t nframes = 0; uint32_t strsize = 0; /* default string table size */ dt_node_t *arg0 = dnp->dn_args; dt_node_t *arg1 = arg0 != NULL ? arg0->dn_list : NULL; assert(dnp->dn_ident->di_id == DT_ACT_JSTACK || dnp->dn_ident->di_id == DT_ACT_USTACK); if (dnp->dn_ident->di_id == DT_ACT_JSTACK) { if (dtp->dt_options[DTRACEOPT_JSTACKFRAMES] != DTRACEOPT_UNSET) nframes = dtp->dt_options[DTRACEOPT_JSTACKFRAMES]; if (dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE] != DTRACEOPT_UNSET) strsize = dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE]; ap->dtad_kind = DTRACEACT_JSTACK; } else { assert(dnp->dn_ident->di_id == DT_ACT_USTACK); if (dtp->dt_options[DTRACEOPT_USTACKFRAMES] != DTRACEOPT_UNSET) nframes = dtp->dt_options[DTRACEOPT_USTACKFRAMES]; ap->dtad_kind = DTRACEACT_USTACK; } if (arg0 != NULL) { if (!dt_node_is_posconst(arg0)) { dnerror(arg0, D_USTACK_FRAMES, "ustack( ) argument #1 " "must be a non-zero positive integer constant\n"); } nframes = (uint32_t)arg0->dn_value; } if (arg1 != NULL) { if (arg1->dn_kind != DT_NODE_INT || ((arg1->dn_flags & DT_NF_SIGNED) && (int64_t)arg1->dn_value < 0)) { dnerror(arg1, D_USTACK_STRSIZE, "ustack( ) argument #2 " "must be a positive integer constant\n"); } if (arg1->dn_list != NULL) { dnerror(arg1, D_USTACK_PROTO, "ustack( ) prototype " "mismatch: too many arguments\n"); } strsize = (uint32_t)arg1->dn_value; } ap->dtad_arg = DTRACE_USTACK_ARG(nframes, strsize); } static void dt_action_ustack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_action_ustack_args(dtp, ap, dnp); } static void dt_action_setopt(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap; dt_node_t *arg0, *arg1; /* * The prototype guarantees that we are called with either one or * two arguments, and that any arguments that are present are strings. */ arg0 = dnp->dn_args; arg1 = arg0->dn_list; ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, arg0); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_LIBACT; ap->dtad_arg = DT_ACT_SETOPT; ap = dt_stmt_action(dtp, sdp); if (arg1 == NULL) { dt_action_difconst(ap, 0, DTRACEACT_LIBACT); } else { dt_cg(yypcb, arg1); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_LIBACT; } ap->dtad_arg = DT_ACT_SETOPT; } /*ARGSUSED*/ static void dt_action_symmod_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *dnp, dtrace_actkind_t kind) { assert(kind == DTRACEACT_SYM || kind == DTRACEACT_MOD || kind == DTRACEACT_USYM || kind == DTRACEACT_UMOD || kind == DTRACEACT_UADDR); dt_cg(yypcb, dnp); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = kind; ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (uint64_t); } static void dt_action_symmod(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp, dtrace_actkind_t kind) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_action_symmod_args(dtp, ap, dnp->dn_args, kind); } /*ARGSUSED*/ static void dt_action_ftruncate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); /* * Library actions need a DIFO that serves as an argument. As * ftruncate() doesn't take an argument, we generate the constant 0 * in a DIFO; this constant will be ignored when the ftruncate() is * processed. */ dt_action_difconst(ap, 0, DTRACEACT_LIBACT); ap->dtad_arg = DT_ACT_FTRUNCATE; } /*ARGSUSED*/ static void dt_action_stop(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); ap->dtad_kind = DTRACEACT_STOP; ap->dtad_arg = 0; } /*ARGSUSED*/ static void dt_action_breakpoint(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); ap->dtad_kind = DTRACEACT_BREAKPOINT; ap->dtad_arg = 0; } /*ARGSUSED*/ static void dt_action_panic(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); ap->dtad_kind = DTRACEACT_PANIC; ap->dtad_arg = 0; } static void dt_action_chill(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_CHILL; } static void dt_action_raise(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_RAISE; } static void dt_action_exit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_EXIT; ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (int); } static void dt_action_speculate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_SPECULATE; } static void dt_action_printm(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_node_t *size = dnp->dn_args; dt_node_t *addr = dnp->dn_args->dn_list; char n[DT_TYPE_NAMELEN]; if (dt_node_is_posconst(size) == 0) { dnerror(size, D_PRINTM_SIZE, "printm( ) argument #1 must " "be a non-zero positive integral constant expression\n"); } if (dt_node_is_pointer(addr) == 0) { dnerror(addr, D_PRINTM_ADDR, "printm( ) argument #2 is incompatible with " "prototype:\n\tprototype: pointer\n" "\t argument: %s\n", dt_node_type_name(addr, n, sizeof (n))); } dt_cg(yypcb, addr); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_PRINTM; ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF; ap->dtad_difo->dtdo_rtype.dtdt_size = size->dn_value + sizeof(uintptr_t); } static void dt_action_printt(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_node_t *size = dnp->dn_args; dt_node_t *addr = dnp->dn_args->dn_list; char n[DT_TYPE_NAMELEN]; if (dt_node_is_posconst(size) == 0) { dnerror(size, D_PRINTT_SIZE, "printt( ) argument #1 must " "be a non-zero positive integral constant expression\n"); } if (addr == NULL || addr->dn_kind != DT_NODE_FUNC || addr->dn_ident != dt_idhash_lookup(dtp->dt_globals, "typeref")) { dnerror(addr, D_PRINTT_ADDR, "printt( ) argument #2 is incompatible with " "prototype:\n\tprototype: typeref()\n" "\t argument: %s\n", dt_node_type_name(addr, n, sizeof (n))); } dt_cg(yypcb, addr); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_PRINTT; ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF; /* * Allow additional buffer space for the data size, type size, * type string length and a stab in the dark (32 bytes) for the * type string. The type string is part of the typeref() that * this action references. */ ap->dtad_difo->dtdo_rtype.dtdt_size = size->dn_value + 3 * sizeof(uintptr_t) + 32; } static void dt_action_commit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_COMMIT; } static void dt_action_discard(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_args); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_DISCARD; } static void dt_compile_fun(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { switch (dnp->dn_expr->dn_ident->di_id) { case DT_ACT_BREAKPOINT: dt_action_breakpoint(dtp, dnp->dn_expr, sdp); break; case DT_ACT_CHILL: dt_action_chill(dtp, dnp->dn_expr, sdp); break; case DT_ACT_CLEAR: dt_action_clear(dtp, dnp->dn_expr, sdp); break; case DT_ACT_COMMIT: dt_action_commit(dtp, dnp->dn_expr, sdp); break; case DT_ACT_DENORMALIZE: dt_action_normalize(dtp, dnp->dn_expr, sdp); break; case DT_ACT_DISCARD: dt_action_discard(dtp, dnp->dn_expr, sdp); break; case DT_ACT_EXIT: dt_action_exit(dtp, dnp->dn_expr, sdp); break; case DT_ACT_FREOPEN: dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_FREOPEN); break; case DT_ACT_FTRUNCATE: dt_action_ftruncate(dtp, dnp->dn_expr, sdp); break; case DT_ACT_MOD: dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_MOD); break; case DT_ACT_NORMALIZE: dt_action_normalize(dtp, dnp->dn_expr, sdp); break; case DT_ACT_PANIC: dt_action_panic(dtp, dnp->dn_expr, sdp); break; case DT_ACT_PRINT: dt_action_trace(dtp, dnp->dn_expr, sdp); break; case DT_ACT_PRINTA: dt_action_printa(dtp, dnp->dn_expr, sdp); break; case DT_ACT_PRINTF: dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF); break; case DT_ACT_PRINTM: dt_action_printm(dtp, dnp->dn_expr, sdp); break; case DT_ACT_PRINTT: dt_action_printt(dtp, dnp->dn_expr, sdp); break; case DT_ACT_RAISE: dt_action_raise(dtp, dnp->dn_expr, sdp); break; case DT_ACT_SETOPT: dt_action_setopt(dtp, dnp->dn_expr, sdp); break; case DT_ACT_SPECULATE: dt_action_speculate(dtp, dnp->dn_expr, sdp); break; case DT_ACT_STACK: dt_action_stack(dtp, dnp->dn_expr, sdp); break; case DT_ACT_STOP: dt_action_stop(dtp, dnp->dn_expr, sdp); break; case DT_ACT_SYM: dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_SYM); break; case DT_ACT_SYSTEM: dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM); break; case DT_ACT_TRACE: dt_action_trace(dtp, dnp->dn_expr, sdp); break; case DT_ACT_TRACEMEM: dt_action_tracemem(dtp, dnp->dn_expr, sdp); break; case DT_ACT_TRUNC: dt_action_trunc(dtp, dnp->dn_expr, sdp); break; case DT_ACT_UADDR: dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UADDR); break; case DT_ACT_UMOD: dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UMOD); break; case DT_ACT_USYM: dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_USYM); break; case DT_ACT_USTACK: case DT_ACT_JSTACK: dt_action_ustack(dtp, dnp->dn_expr, sdp); break; default: dnerror(dnp->dn_expr, D_UNKNOWN, "tracing function %s( ) is " "not yet supported\n", dnp->dn_expr->dn_ident->di_name); } } static void dt_compile_exp(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); dt_cg(yypcb, dnp->dn_expr); ap->dtad_difo = dt_as(yypcb); ap->dtad_difo->dtdo_rtype = dt_void_rtype; ap->dtad_kind = DTRACEACT_DIFEXPR; } static void dt_compile_agg(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { dt_ident_t *aid, *fid; dt_node_t *anp, *incr = NULL; dtrace_actdesc_t *ap; uint_t n = 1, argmax; uint64_t arg = 0; /* * If the aggregation has no aggregating function applied to it, then * this statement has no effect. Flag this as a programming error. */ if (dnp->dn_aggfun == NULL) { dnerror(dnp, D_AGG_NULL, "expression has null effect: @%s\n", dnp->dn_ident->di_name); } aid = dnp->dn_ident; fid = dnp->dn_aggfun->dn_ident; if (dnp->dn_aggfun->dn_args != NULL && dt_node_is_scalar(dnp->dn_aggfun->dn_args) == 0) { dnerror(dnp->dn_aggfun, D_AGG_SCALAR, "%s( ) argument #1 must " "be of scalar type\n", fid->di_name); } /* * The ID of the aggregation itself is implicitly recorded as the first * member of each aggregation tuple so we can distinguish them later. */ ap = dt_stmt_action(dtp, sdp); dt_action_difconst(ap, aid->di_id, DTRACEACT_DIFEXPR); for (anp = dnp->dn_aggtup; anp != NULL; anp = anp->dn_list) { ap = dt_stmt_action(dtp, sdp); n++; if (anp->dn_kind == DT_NODE_FUNC) { if (anp->dn_ident->di_id == DT_ACT_STACK) { dt_action_stack_args(dtp, ap, anp->dn_args); continue; } if (anp->dn_ident->di_id == DT_ACT_USTACK || anp->dn_ident->di_id == DT_ACT_JSTACK) { dt_action_ustack_args(dtp, ap, anp); continue; } switch (anp->dn_ident->di_id) { case DT_ACT_UADDR: dt_action_symmod_args(dtp, ap, anp->dn_args, DTRACEACT_UADDR); continue; case DT_ACT_USYM: dt_action_symmod_args(dtp, ap, anp->dn_args, DTRACEACT_USYM); continue; case DT_ACT_UMOD: dt_action_symmod_args(dtp, ap, anp->dn_args, DTRACEACT_UMOD); continue; case DT_ACT_SYM: dt_action_symmod_args(dtp, ap, anp->dn_args, DTRACEACT_SYM); continue; case DT_ACT_MOD: dt_action_symmod_args(dtp, ap, anp->dn_args, DTRACEACT_MOD); continue; default: break; } } dt_cg(yypcb, anp); ap->dtad_difo = dt_as(yypcb); ap->dtad_kind = DTRACEACT_DIFEXPR; } if (fid->di_id == DTRACEAGG_LQUANTIZE) { /* * For linear quantization, we have between two and four * arguments in addition to the expression: * * arg1 => Base value * arg2 => Limit value * arg3 => Quantization level step size (defaults to 1) * arg4 => Quantization increment value (defaults to 1) */ dt_node_t *arg1 = dnp->dn_aggfun->dn_args->dn_list; dt_node_t *arg2 = arg1->dn_list; dt_node_t *arg3 = arg2->dn_list; dt_idsig_t *isp; uint64_t nlevels, step = 1, oarg; int64_t baseval, limitval; if (arg1->dn_kind != DT_NODE_INT) { dnerror(arg1, D_LQUANT_BASETYPE, "lquantize( ) " "argument #1 must be an integer constant\n"); } baseval = (int64_t)arg1->dn_value; if (baseval < INT32_MIN || baseval > INT32_MAX) { dnerror(arg1, D_LQUANT_BASEVAL, "lquantize( ) " "argument #1 must be a 32-bit quantity\n"); } if (arg2->dn_kind != DT_NODE_INT) { dnerror(arg2, D_LQUANT_LIMTYPE, "lquantize( ) " "argument #2 must be an integer constant\n"); } limitval = (int64_t)arg2->dn_value; if (limitval < INT32_MIN || limitval > INT32_MAX) { dnerror(arg2, D_LQUANT_LIMVAL, "lquantize( ) " "argument #2 must be a 32-bit quantity\n"); } if (limitval < baseval) { dnerror(dnp, D_LQUANT_MISMATCH, "lquantize( ) base (argument #1) must be less " "than limit (argument #2)\n"); } if (arg3 != NULL) { if (!dt_node_is_posconst(arg3)) { dnerror(arg3, D_LQUANT_STEPTYPE, "lquantize( ) " "argument #3 must be a non-zero positive " "integer constant\n"); } if ((step = arg3->dn_value) > UINT16_MAX) { dnerror(arg3, D_LQUANT_STEPVAL, "lquantize( ) " "argument #3 must be a 16-bit quantity\n"); } } nlevels = (limitval - baseval) / step; if (nlevels == 0) { dnerror(dnp, D_LQUANT_STEPLARGE, "lquantize( ) step (argument #3) too large: must " "have at least one quantization level\n"); } if (nlevels > UINT16_MAX) { dnerror(dnp, D_LQUANT_STEPSMALL, "lquantize( ) step " "(argument #3) too small: number of quantization " "levels must be a 16-bit quantity\n"); } arg = (step << DTRACE_LQUANTIZE_STEPSHIFT) | (nlevels << DTRACE_LQUANTIZE_LEVELSHIFT) | ((baseval << DTRACE_LQUANTIZE_BASESHIFT) & DTRACE_LQUANTIZE_BASEMASK); assert(arg != 0); isp = (dt_idsig_t *)aid->di_data; if (isp->dis_auxinfo == 0) { /* * This is the first time we've seen an lquantize() * for this aggregation; we'll store our argument * as the auxiliary signature information. */ isp->dis_auxinfo = arg; } else if ((oarg = isp->dis_auxinfo) != arg) { /* * If we have seen this lquantize() before and the * argument doesn't match the original argument, pick * the original argument apart to concisely report the * mismatch. */ int obaseval = DTRACE_LQUANTIZE_BASE(oarg); int onlevels = DTRACE_LQUANTIZE_LEVELS(oarg); int ostep = DTRACE_LQUANTIZE_STEP(oarg); if (obaseval != baseval) { dnerror(dnp, D_LQUANT_MATCHBASE, "lquantize( ) " "base (argument #1) doesn't match previous " "declaration: expected %d, found %d\n", obaseval, (int)baseval); } if (onlevels * ostep != nlevels * step) { dnerror(dnp, D_LQUANT_MATCHLIM, "lquantize( ) " "limit (argument #2) doesn't match previous" " declaration: expected %d, found %d\n", obaseval + onlevels * ostep, (int)baseval + (int)nlevels * (int)step); } if (ostep != step) { dnerror(dnp, D_LQUANT_MATCHSTEP, "lquantize( ) " "step (argument #3) doesn't match previous " "declaration: expected %d, found %d\n", ostep, (int)step); } /* * We shouldn't be able to get here -- one of the * parameters must be mismatched if the arguments * didn't match. */ assert(0); } incr = arg3 != NULL ? arg3->dn_list : NULL; argmax = 5; } if (fid->di_id == DTRACEAGG_LLQUANTIZE) { /* * For log/linear quantizations, we have between one and five * arguments in addition to the expression: * * arg1 => Factor * arg2 => Low magnitude * arg3 => High magnitude * arg4 => Number of steps per magnitude * arg5 => Quantization increment value (defaults to 1) */ dt_node_t *llarg = dnp->dn_aggfun->dn_args->dn_list; uint64_t oarg, order, v; dt_idsig_t *isp; int i; struct { char *str; /* string identifier */ int badtype; /* error on bad type */ int badval; /* error on bad value */ int mismatch; /* error on bad match */ int shift; /* shift value */ uint16_t value; /* value itself */ } args[] = { { "factor", D_LLQUANT_FACTORTYPE, D_LLQUANT_FACTORVAL, D_LLQUANT_FACTORMATCH, DTRACE_LLQUANTIZE_FACTORSHIFT }, { "low magnitude", D_LLQUANT_LOWTYPE, D_LLQUANT_LOWVAL, D_LLQUANT_LOWMATCH, DTRACE_LLQUANTIZE_LOWSHIFT }, { "high magnitude", D_LLQUANT_HIGHTYPE, D_LLQUANT_HIGHVAL, D_LLQUANT_HIGHMATCH, DTRACE_LLQUANTIZE_HIGHSHIFT }, { "linear steps per magnitude", D_LLQUANT_NSTEPTYPE, D_LLQUANT_NSTEPVAL, D_LLQUANT_NSTEPMATCH, DTRACE_LLQUANTIZE_NSTEPSHIFT }, { NULL } }; assert(arg == 0); for (i = 0; args[i].str != NULL; i++) { if (llarg->dn_kind != DT_NODE_INT) { dnerror(llarg, args[i].badtype, "llquantize( ) " "argument #%d (%s) must be an " "integer constant\n", i + 1, args[i].str); } if ((uint64_t)llarg->dn_value > UINT16_MAX) { dnerror(llarg, args[i].badval, "llquantize( ) " "argument #%d (%s) must be an unsigned " "16-bit quantity\n", i + 1, args[i].str); } args[i].value = (uint16_t)llarg->dn_value; assert(!(arg & ((uint64_t)UINT16_MAX << args[i].shift))); arg |= ((uint64_t)args[i].value << args[i].shift); llarg = llarg->dn_list; } assert(arg != 0); if (args[0].value < 2) { dnerror(dnp, D_LLQUANT_FACTORSMALL, "llquantize( ) " "factor (argument #1) must be two or more\n"); } if (args[1].value >= args[2].value) { dnerror(dnp, D_LLQUANT_MAGRANGE, "llquantize( ) " "high magnitude (argument #3) must be greater " "than low magnitude (argument #2)\n"); } if (args[3].value < args[0].value) { dnerror(dnp, D_LLQUANT_FACTORNSTEPS, "llquantize( ) " "factor (argument #1) must be less than or " "equal to the number of linear steps per " "magnitude (argument #4)\n"); } for (v = args[0].value; v < args[3].value; v *= args[0].value) continue; if ((args[3].value % args[0].value) || (v % args[3].value)) { dnerror(dnp, D_LLQUANT_FACTOREVEN, "llquantize( ) " "factor (argument #1) must evenly divide the " "number of steps per magnitude (argument #4), " "and the number of steps per magnitude must evenly " "divide a power of the factor\n"); } for (i = 0, order = 1; i < args[2].value; i++) { if (order * args[0].value > order) { order *= args[0].value; continue; } dnerror(dnp, D_LLQUANT_MAGTOOBIG, "llquantize( ) " "factor (%d) raised to power of high magnitude " "(%d) overflows 64-bits\n", args[0].value, args[2].value); } isp = (dt_idsig_t *)aid->di_data; if (isp->dis_auxinfo == 0) { /* * This is the first time we've seen an llquantize() * for this aggregation; we'll store our argument * as the auxiliary signature information. */ isp->dis_auxinfo = arg; } else if ((oarg = isp->dis_auxinfo) != arg) { /* * If we have seen this llquantize() before and the * argument doesn't match the original argument, pick * the original argument apart to concisely report the * mismatch. */ int expected = 0, found = 0; for (i = 0; expected == found; i++) { assert(args[i].str != NULL); expected = (oarg >> args[i].shift) & UINT16_MAX; found = (arg >> args[i].shift) & UINT16_MAX; } dnerror(dnp, args[i - 1].mismatch, "llquantize( ) " "%s (argument #%d) doesn't match previous " "declaration: expected %d, found %d\n", args[i - 1].str, i, expected, found); } incr = llarg; argmax = 6; } if (fid->di_id == DTRACEAGG_QUANTIZE) { incr = dnp->dn_aggfun->dn_args->dn_list; argmax = 2; } if (incr != NULL) { if (!dt_node_is_scalar(incr)) { dnerror(dnp, D_PROTO_ARG, "%s( ) increment value " "(argument #%d) must be of scalar type\n", fid->di_name, argmax); } if ((anp = incr->dn_list) != NULL) { int argc = argmax; for (; anp != NULL; anp = anp->dn_list) argc++; dnerror(incr, D_PROTO_LEN, "%s( ) prototype " "mismatch: %d args passed, at most %d expected", fid->di_name, argc, argmax); } ap = dt_stmt_action(dtp, sdp); n++; dt_cg(yypcb, incr); ap->dtad_difo = dt_as(yypcb); ap->dtad_difo->dtdo_rtype = dt_void_rtype; ap->dtad_kind = DTRACEACT_DIFEXPR; } assert(sdp->dtsd_aggdata == NULL); sdp->dtsd_aggdata = aid; ap = dt_stmt_action(dtp, sdp); assert(fid->di_kind == DT_IDENT_AGGFUNC); assert(DTRACEACT_ISAGG(fid->di_id)); ap->dtad_kind = fid->di_id; ap->dtad_ntuple = n; ap->dtad_arg = arg; if (dnp->dn_aggfun->dn_args != NULL) { dt_cg(yypcb, dnp->dn_aggfun->dn_args); ap->dtad_difo = dt_as(yypcb); } } static void dt_compile_one_clause(dtrace_hdl_t *dtp, dt_node_t *cnp, dt_node_t *pnp) { dtrace_ecbdesc_t *edp; dtrace_stmtdesc_t *sdp; dt_node_t *dnp; yylineno = pnp->dn_line; dt_setcontext(dtp, pnp->dn_desc); (void) dt_node_cook(cnp, DT_IDFLG_REF); if (DT_TREEDUMP_PASS(dtp, 2)) dt_node_printr(cnp, stderr, 0); if ((edp = dt_ecbdesc_create(dtp, pnp->dn_desc)) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); assert(yypcb->pcb_ecbdesc == NULL); yypcb->pcb_ecbdesc = edp; if (cnp->dn_pred != NULL) { dt_cg(yypcb, cnp->dn_pred); edp->dted_pred.dtpdd_difo = dt_as(yypcb); } if (cnp->dn_acts == NULL) { dt_stmt_append(dt_stmt_create(dtp, edp, cnp->dn_ctxattr, _dtrace_defattr), cnp); } for (dnp = cnp->dn_acts; dnp != NULL; dnp = dnp->dn_list) { assert(yypcb->pcb_stmt == NULL); sdp = dt_stmt_create(dtp, edp, cnp->dn_ctxattr, cnp->dn_attr); switch (dnp->dn_kind) { case DT_NODE_DEXPR: if (dnp->dn_expr->dn_kind == DT_NODE_AGG) dt_compile_agg(dtp, dnp->dn_expr, sdp); else dt_compile_exp(dtp, dnp, sdp); break; case DT_NODE_DFUNC: dt_compile_fun(dtp, dnp, sdp); break; case DT_NODE_AGG: dt_compile_agg(dtp, dnp, sdp); break; default: dnerror(dnp, D_UNKNOWN, "internal error -- node kind " "%u is not a valid statement\n", dnp->dn_kind); } assert(yypcb->pcb_stmt == sdp); dt_stmt_append(sdp, dnp); } assert(yypcb->pcb_ecbdesc == edp); dt_ecbdesc_release(dtp, edp); dt_endcontext(dtp); yypcb->pcb_ecbdesc = NULL; } static void dt_compile_clause(dtrace_hdl_t *dtp, dt_node_t *cnp) { dt_node_t *pnp; for (pnp = cnp->dn_pdescs; pnp != NULL; pnp = pnp->dn_list) dt_compile_one_clause(dtp, cnp, pnp); } static void dt_compile_xlator(dt_node_t *dnp) { dt_xlator_t *dxp = dnp->dn_xlator; dt_node_t *mnp; for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) { assert(dxp->dx_membdif[mnp->dn_membid] == NULL); dt_cg(yypcb, mnp); dxp->dx_membdif[mnp->dn_membid] = dt_as(yypcb); } } void dt_setcontext(dtrace_hdl_t *dtp, dtrace_probedesc_t *pdp) { const dtrace_pattr_t *pap; dt_probe_t *prp; dt_provider_t *pvp; dt_ident_t *idp; char attrstr[8]; int err; /* * Both kernel and pid based providers are allowed to have names * ending with what could be interpreted as a number. We assume it's * a pid and that we may need to dynamically create probes for * that process if: * * (1) The provider doesn't exist, or, * (2) The provider exists and has DTRACE_PRIV_PROC privilege. * * On an error, dt_pid_create_probes() will set the error message * and tag -- we just have to longjmp() out of here. */ if (isdigit(pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) && ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) == NULL || pvp->pv_desc.dtvd_priv.dtpp_flags & DTRACE_PRIV_PROC) && dt_pid_create_probes(pdp, dtp, yypcb) != 0) { longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } /* * Call dt_probe_info() to get the probe arguments and attributes. If * a representative probe is found, set 'pap' to the probe provider's * attributes. Otherwise set 'pap' to default Unstable attributes. */ if ((prp = dt_probe_info(dtp, pdp, &yypcb->pcb_pinfo)) == NULL) { pap = &_dtrace_prvdesc; err = dtrace_errno(dtp); bzero(&yypcb->pcb_pinfo, sizeof (dtrace_probeinfo_t)); yypcb->pcb_pinfo.dtp_attr = pap->dtpa_provider; yypcb->pcb_pinfo.dtp_arga = pap->dtpa_args; } else { pap = &prp->pr_pvp->pv_desc.dtvd_attr; err = 0; } if (err == EDT_NOPROBE && !(yypcb->pcb_cflags & DTRACE_C_ZDEFS)) { xyerror(D_PDESC_ZERO, "probe description %s:%s:%s:%s does not " "match any probes\n", pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name); } if (err != EDT_NOPROBE && err != EDT_UNSTABLE && err != 0) xyerror(D_PDESC_INVAL, "%s\n", dtrace_errmsg(dtp, err)); dt_dprintf("set context to %s:%s:%s:%s [%u] prp=%p attr=%s argc=%d\n", pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name, pdp->dtpd_id, (void *)prp, dt_attr_str(yypcb->pcb_pinfo.dtp_attr, attrstr, sizeof (attrstr)), yypcb->pcb_pinfo.dtp_argc); /* * Reset the stability attributes of D global variables that vary * based on the attributes of the provider and context itself. */ if ((idp = dt_idhash_lookup(dtp->dt_globals, "probeprov")) != NULL) idp->di_attr = pap->dtpa_provider; if ((idp = dt_idhash_lookup(dtp->dt_globals, "probemod")) != NULL) idp->di_attr = pap->dtpa_mod; if ((idp = dt_idhash_lookup(dtp->dt_globals, "probefunc")) != NULL) idp->di_attr = pap->dtpa_func; if ((idp = dt_idhash_lookup(dtp->dt_globals, "probename")) != NULL) idp->di_attr = pap->dtpa_name; if ((idp = dt_idhash_lookup(dtp->dt_globals, "args")) != NULL) idp->di_attr = pap->dtpa_args; yypcb->pcb_pdesc = pdp; yypcb->pcb_probe = prp; } /* * Reset context-dependent variables and state at the end of cooking a D probe * definition clause. This ensures that external declarations between clauses * do not reference any stale context-dependent data from the previous clause. */ void dt_endcontext(dtrace_hdl_t *dtp) { static const char *const cvars[] = { "probeprov", "probemod", "probefunc", "probename", "args", NULL }; dt_ident_t *idp; int i; for (i = 0; cvars[i] != NULL; i++) { if ((idp = dt_idhash_lookup(dtp->dt_globals, cvars[i])) != NULL) idp->di_attr = _dtrace_defattr; } yypcb->pcb_pdesc = NULL; yypcb->pcb_probe = NULL; } static int dt_reduceid(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp) { if (idp->di_vers != 0 && idp->di_vers > dtp->dt_vmax) dt_idhash_delete(dhp, idp); return (0); } /* * When dtrace_setopt() is called for "version", it calls dt_reduce() to remove * any identifiers or translators that have been previously defined as bound to * a version greater than the specified version. Therefore, in our current * version implementation, establishing a binding is a one-way transformation. * In addition, no versioning is currently provided for types as our .d library * files do not define any types and we reserve prefixes DTRACE_ and dtrace_ * for our exclusive use. If required, type versioning will require more work. */ int dt_reduce(dtrace_hdl_t *dtp, dt_version_t v) { char s[DT_VERSION_STRMAX]; dt_xlator_t *dxp, *nxp; if (v > dtp->dt_vmax) return (dt_set_errno(dtp, EDT_VERSREDUCED)); else if (v == dtp->dt_vmax) return (0); /* no reduction necessary */ dt_dprintf("reducing api version to %s\n", dt_version_num2str(v, s, sizeof (s))); dtp->dt_vmax = v; for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = nxp) { nxp = dt_list_next(dxp); if ((dxp->dx_souid.di_vers != 0 && dxp->dx_souid.di_vers > v) || (dxp->dx_ptrid.di_vers != 0 && dxp->dx_ptrid.di_vers > v)) dt_list_delete(&dtp->dt_xlators, dxp); } (void) dt_idhash_iter(dtp->dt_macros, (dt_idhash_f *)dt_reduceid, dtp); (void) dt_idhash_iter(dtp->dt_aggs, (dt_idhash_f *)dt_reduceid, dtp); (void) dt_idhash_iter(dtp->dt_globals, (dt_idhash_f *)dt_reduceid, dtp); (void) dt_idhash_iter(dtp->dt_tls, (dt_idhash_f *)dt_reduceid, dtp); return (0); } /* * Fork and exec the cpp(1) preprocessor to run over the specified input file, * and return a FILE handle for the cpp output. We use the /dev/fd filesystem * here to simplify the code by leveraging file descriptor inheritance. */ static FILE * dt_preproc(dtrace_hdl_t *dtp, FILE *ifp) { int argc = dtp->dt_cpp_argc; char **argv = malloc(sizeof (char *) * (argc + 5)); FILE *ofp = tmpfile(); #ifdef illumos char ipath[20], opath[20]; /* big enough for /dev/fd/ + INT_MAX + \0 */ #endif char verdef[32]; /* big enough for -D__SUNW_D_VERSION=0x%08x + \0 */ struct sigaction act, oact; sigset_t mask, omask; int wstat, estat; pid_t pid; #ifdef illumos off64_t off; #else off_t off = 0; #endif int c; if (argv == NULL || ofp == NULL) { (void) dt_set_errno(dtp, errno); goto err; } /* * If the input is a seekable file, see if it is an interpreter file. * If we see #!, seek past the first line because cpp will choke on it. * We start cpp just prior to the \n at the end of this line so that * it still sees the newline, ensuring that #line values are correct. */ if (isatty(fileno(ifp)) == 0 && (off = ftello64(ifp)) != -1) { if ((c = fgetc(ifp)) == '#' && (c = fgetc(ifp)) == '!') { for (off += 2; c != '\n'; off++) { if ((c = fgetc(ifp)) == EOF) break; } if (c == '\n') off--; /* start cpp just prior to \n */ } (void) fflush(ifp); (void) fseeko64(ifp, off, SEEK_SET); } #ifdef illumos (void) snprintf(ipath, sizeof (ipath), "/dev/fd/%d", fileno(ifp)); (void) snprintf(opath, sizeof (opath), "/dev/fd/%d", fileno(ofp)); #endif bcopy(dtp->dt_cpp_argv, argv, sizeof (char *) * argc); (void) snprintf(verdef, sizeof (verdef), "-D__SUNW_D_VERSION=0x%08x", dtp->dt_vmax); argv[argc++] = verdef; #ifdef illumos switch (dtp->dt_stdcmode) { case DT_STDC_XA: case DT_STDC_XT: argv[argc++] = "-D__STDC__=0"; break; case DT_STDC_XC: argv[argc++] = "-D__STDC__=1"; break; } argv[argc++] = ipath; argv[argc++] = opath; #else argv[argc++] = "-P"; #endif argv[argc] = NULL; /* * libdtrace must be able to be embedded in other programs that may * include application-specific signal handlers. Therefore, if we * need to fork to run cpp(1), we must avoid generating a SIGCHLD * that could confuse the containing application. To do this, * we block SIGCHLD and reset its disposition to SIG_DFL. * We restore our signal state once we are done. */ (void) sigemptyset(&mask); (void) sigaddset(&mask, SIGCHLD); (void) sigprocmask(SIG_BLOCK, &mask, &omask); bzero(&act, sizeof (act)); act.sa_handler = SIG_DFL; (void) sigaction(SIGCHLD, &act, &oact); if ((pid = fork1()) == -1) { (void) sigaction(SIGCHLD, &oact, NULL); (void) sigprocmask(SIG_SETMASK, &omask, NULL); (void) dt_set_errno(dtp, EDT_CPPFORK); goto err; } if (pid == 0) { #ifndef illumos if (isatty(fileno(ifp)) == 0) lseek(fileno(ifp), off, SEEK_SET); dup2(fileno(ifp), 0); dup2(fileno(ofp), 1); #endif (void) execvp(dtp->dt_cpp_path, argv); _exit(errno == ENOENT ? 127 : 126); } do { dt_dprintf("waiting for %s (PID %d)\n", dtp->dt_cpp_path, (int)pid); } while (waitpid(pid, &wstat, 0) == -1 && errno == EINTR); (void) sigaction(SIGCHLD, &oact, NULL); (void) sigprocmask(SIG_SETMASK, &omask, NULL); dt_dprintf("%s returned exit status 0x%x\n", dtp->dt_cpp_path, wstat); estat = WIFEXITED(wstat) ? WEXITSTATUS(wstat) : -1; if (estat != 0) { switch (estat) { case 126: (void) dt_set_errno(dtp, EDT_CPPEXEC); break; case 127: (void) dt_set_errno(dtp, EDT_CPPENT); break; default: (void) dt_set_errno(dtp, EDT_CPPERR); } goto err; } free(argv); (void) fflush(ofp); (void) fseek(ofp, 0, SEEK_SET); return (ofp); err: free(argv); (void) fclose(ofp); return (NULL); } static void dt_lib_depend_error(dtrace_hdl_t *dtp, const char *format, ...) { va_list ap; va_start(ap, format); dt_set_errmsg(dtp, NULL, NULL, NULL, 0, format, ap); va_end(ap); } int dt_lib_depend_add(dtrace_hdl_t *dtp, dt_list_t *dlp, const char *arg) { dt_lib_depend_t *dld; const char *end; assert(arg != NULL); if ((end = strrchr(arg, '/')) == NULL) return (dt_set_errno(dtp, EINVAL)); if ((dld = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL) return (-1); if ((dld->dtld_libpath = dt_alloc(dtp, MAXPATHLEN)) == NULL) { dt_free(dtp, dld); return (-1); } (void) strlcpy(dld->dtld_libpath, arg, end - arg + 2); if ((dld->dtld_library = strdup(arg)) == NULL) { dt_free(dtp, dld->dtld_libpath); dt_free(dtp, dld); return (dt_set_errno(dtp, EDT_NOMEM)); } dt_list_append(dlp, dld); return (0); } dt_lib_depend_t * dt_lib_depend_lookup(dt_list_t *dld, const char *arg) { dt_lib_depend_t *dldn; for (dldn = dt_list_next(dld); dldn != NULL; dldn = dt_list_next(dldn)) { if (strcmp(dldn->dtld_library, arg) == 0) return (dldn); } return (NULL); } /* * Go through all the library files, and, if any library dependencies exist for * that file, add it to that node's list of dependents. The result of this * will be a graph which can then be topologically sorted to produce a * compilation order. */ static int dt_lib_build_graph(dtrace_hdl_t *dtp) { dt_lib_depend_t *dld, *dpld; for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; dld = dt_list_next(dld)) { char *library = dld->dtld_library; for (dpld = dt_list_next(&dld->dtld_dependencies); dpld != NULL; dpld = dt_list_next(dpld)) { dt_lib_depend_t *dlda; if ((dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep, dpld->dtld_library)) == NULL) { dt_lib_depend_error(dtp, "Invalid library dependency in %s: %s\n", dld->dtld_library, dpld->dtld_library); return (dt_set_errno(dtp, EDT_COMPILER)); } if ((dt_lib_depend_add(dtp, &dlda->dtld_dependents, library)) != 0) { return (-1); /* preserve dt_errno */ } } } return (0); } static int dt_topo_sort(dtrace_hdl_t *dtp, dt_lib_depend_t *dld, int *count) { dt_lib_depend_t *dpld, *dlda, *new; dld->dtld_start = ++(*count); for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL; dpld = dt_list_next(dpld)) { dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep, dpld->dtld_library); assert(dlda != NULL); if (dlda->dtld_start == 0 && dt_topo_sort(dtp, dlda, count) == -1) return (-1); } if ((new = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL) return (-1); if ((new->dtld_library = strdup(dld->dtld_library)) == NULL) { dt_free(dtp, new); return (dt_set_errno(dtp, EDT_NOMEM)); } new->dtld_start = dld->dtld_start; new->dtld_finish = dld->dtld_finish = ++(*count); dt_list_prepend(&dtp->dt_lib_dep_sorted, new); dt_dprintf("library %s sorted (%d/%d)\n", new->dtld_library, new->dtld_start, new->dtld_finish); return (0); } static int dt_lib_depend_sort(dtrace_hdl_t *dtp) { dt_lib_depend_t *dld, *dpld, *dlda; int count = 0; if (dt_lib_build_graph(dtp) == -1) return (-1); /* preserve dt_errno */ /* * Perform a topological sort of the graph that hangs off * dtp->dt_lib_dep. The result of this process will be a * dependency ordered list located at dtp->dt_lib_dep_sorted. */ for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; dld = dt_list_next(dld)) { if (dld->dtld_start == 0 && dt_topo_sort(dtp, dld, &count) == -1) return (-1); /* preserve dt_errno */; } /* * Check the graph for cycles. If an ancestor's finishing time is * less than any of its dependent's finishing times then a back edge * exists in the graph and this is a cycle. */ for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; dld = dt_list_next(dld)) { for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL; dpld = dt_list_next(dpld)) { dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep_sorted, dpld->dtld_library); assert(dlda != NULL); if (dlda->dtld_finish > dld->dtld_finish) { dt_lib_depend_error(dtp, "Cyclic dependency detected: %s => %s\n", dld->dtld_library, dpld->dtld_library); return (dt_set_errno(dtp, EDT_COMPILER)); } } } return (0); } static void dt_lib_depend_free(dtrace_hdl_t *dtp) { dt_lib_depend_t *dld, *dlda; while ((dld = dt_list_next(&dtp->dt_lib_dep)) != NULL) { while ((dlda = dt_list_next(&dld->dtld_dependencies)) != NULL) { dt_list_delete(&dld->dtld_dependencies, dlda); dt_free(dtp, dlda->dtld_library); dt_free(dtp, dlda->dtld_libpath); dt_free(dtp, dlda); } while ((dlda = dt_list_next(&dld->dtld_dependents)) != NULL) { dt_list_delete(&dld->dtld_dependents, dlda); dt_free(dtp, dlda->dtld_library); dt_free(dtp, dlda->dtld_libpath); dt_free(dtp, dlda); } dt_list_delete(&dtp->dt_lib_dep, dld); dt_free(dtp, dld->dtld_library); dt_free(dtp, dld->dtld_libpath); dt_free(dtp, dld); } while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) { dt_list_delete(&dtp->dt_lib_dep_sorted, dld); dt_free(dtp, dld->dtld_library); dt_free(dtp, dld); } } /* * Open all the .d library files found in the specified directory and * compile each one of them. We silently ignore any missing directories and * other files found therein. We only fail (and thereby fail dt_load_libs()) if * we fail to compile a library and the error is something other than #pragma D * depends_on. Dependency errors are silently ignored to permit a library * directory to contain libraries which may not be accessible depending on our * privileges. */ static int dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) { struct dirent *dp; const char *p, *end; DIR *dirp; char fname[PATH_MAX]; FILE *fp; void *rv; dt_lib_depend_t *dld; if ((dirp = opendir(path)) == NULL) { dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno)); return (0); } /* First, parse each file for library dependencies. */ while ((dp = readdir(dirp)) != NULL) { if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d")) continue; /* skip any filename not ending in .d */ (void) snprintf(fname, sizeof (fname), "%s/%s", path, dp->d_name); if ((fp = fopen(fname, "r")) == NULL) { dt_dprintf("skipping library %s: %s\n", fname, strerror(errno)); continue; } /* * Skip files whose name match an already processed library */ for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; dld = dt_list_next(dld)) { end = strrchr(dld->dtld_library, '/'); /* dt_lib_depend_add ensures this */ assert(end != NULL); if (strcmp(end + 1, dp->d_name) == 0) break; } if (dld != NULL) { dt_dprintf("skipping library %s, already processed " "library with the same name: %s", dp->d_name, dld->dtld_library); (void) fclose(fp); continue; } dtp->dt_filetag = fname; if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0) { (void) fclose(fp); return (-1); /* preserve dt_errno */ } rv = dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL, DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp, NULL); if (rv != NULL && dtp->dt_errno && (dtp->dt_errno != EDT_COMPILER || dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) { (void) fclose(fp); return (-1); /* preserve dt_errno */ } if (dtp->dt_errno) dt_dprintf("error parsing library %s: %s\n", fname, dtrace_errmsg(dtp, dtrace_errno(dtp))); (void) fclose(fp); dtp->dt_filetag = NULL; } (void) closedir(dirp); return (0); } /* * Perform a topological sorting of all the libraries found across the entire * dt_lib_path. Once sorted, compile each one in topological order to cache its * inlines and translators, etc. We silently ignore any missing directories and * other files found therein. We only fail (and thereby fail dt_load_libs()) if * we fail to compile a library and the error is something other than #pragma D * depends_on. Dependency errors are silently ignored to permit a library * directory to contain libraries which may not be accessible depending on our * privileges. */ static int dt_load_libs_sort(dtrace_hdl_t *dtp) { dtrace_prog_t *pgp; FILE *fp; dt_lib_depend_t *dld; /* * Finish building the graph containing the library dependencies * and perform a topological sort to generate an ordered list * for compilation. */ if (dt_lib_depend_sort(dtp) == -1) goto err; for (dld = dt_list_next(&dtp->dt_lib_dep_sorted); dld != NULL; dld = dt_list_next(dld)) { if ((fp = fopen(dld->dtld_library, "r")) == NULL) { dt_dprintf("skipping library %s: %s\n", dld->dtld_library, strerror(errno)); continue; } dtp->dt_filetag = dld->dtld_library; pgp = dtrace_program_fcompile(dtp, fp, DTRACE_C_EMPTY, 0, NULL); (void) fclose(fp); dtp->dt_filetag = NULL; if (pgp == NULL && (dtp->dt_errno != EDT_COMPILER || dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) goto err; if (pgp == NULL) { dt_dprintf("skipping library %s: %s\n", dld->dtld_library, dtrace_errmsg(dtp, dtrace_errno(dtp))); } else { dld->dtld_loaded = B_TRUE; dt_program_destroy(dtp, pgp); } } dt_lib_depend_free(dtp); return (0); err: dt_lib_depend_free(dtp); return (-1); /* preserve dt_errno */ } /* * Load the contents of any appropriate DTrace .d library files. These files * contain inlines and translators that will be cached by the compiler. We * defer this activity until the first compile to permit libdtrace clients to * add their own library directories and so that we can properly report errors. */ static int dt_load_libs(dtrace_hdl_t *dtp) { dt_dirpath_t *dirp; if (dtp->dt_cflags & DTRACE_C_NOLIBS) return (0); /* libraries already processed */ dtp->dt_cflags |= DTRACE_C_NOLIBS; /* * /usr/lib/dtrace is always at the head of the list. The rest of the * list is specified in the precedence order the user requested. Process * everything other than the head first. DTRACE_C_NOLIBS has already * been spcified so dt_vopen will ensure that there is always one entry * in dt_lib_path. */ for (dirp = dt_list_next(dt_list_next(&dtp->dt_lib_path)); dirp != NULL; dirp = dt_list_next(dirp)) { if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { dtp->dt_cflags &= ~DTRACE_C_NOLIBS; return (-1); /* errno is set for us */ } } /* Handle /usr/lib/dtrace */ dirp = dt_list_next(&dtp->dt_lib_path); if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { dtp->dt_cflags &= ~DTRACE_C_NOLIBS; return (-1); /* errno is set for us */ } if (dt_load_libs_sort(dtp) < 0) return (-1); /* errno is set for us */ return (0); } static void * dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s) { dt_node_t *dnp; dt_decl_t *ddp; dt_pcb_t pcb; void *volatile rv; int err; if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) { (void) dt_set_errno(dtp, EINVAL); return (NULL); } if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0) return (NULL); /* errno is set for us */ if (dtp->dt_globals->dh_nelems != 0) (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL); if (dtp->dt_tls->dh_nelems != 0) (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL); if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL) return (NULL); /* errno is set for us */ dt_pcb_push(dtp, &pcb); pcb.pcb_fileptr = fp; pcb.pcb_string = s; pcb.pcb_strptr = s; pcb.pcb_strlen = s ? strlen(s) : 0; pcb.pcb_sargc = argc; pcb.pcb_sargv = argv; pcb.pcb_sflagv = argc ? calloc(argc, sizeof (ushort_t)) : NULL; pcb.pcb_pspec = pspec; pcb.pcb_cflags = dtp->dt_cflags | cflags; pcb.pcb_amin = dtp->dt_amin; pcb.pcb_yystate = -1; pcb.pcb_context = context; pcb.pcb_token = context; if (context != DT_CTX_DPROG) yybegin(YYS_EXPR); else if (cflags & DTRACE_C_CTL) yybegin(YYS_CONTROL); else yybegin(YYS_CLAUSE); if ((err = setjmp(yypcb->pcb_jmpbuf)) != 0) goto out; if (yypcb->pcb_sargc != 0 && yypcb->pcb_sflagv == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); yypcb->pcb_idents = dt_idhash_create("ambiguous", NULL, 0, 0); yypcb->pcb_locals = dt_idhash_create("clause local", NULL, DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); if (yypcb->pcb_idents == NULL || yypcb->pcb_locals == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); /* * Invoke the parser to evaluate the D source code. If any errors * occur during parsing, an error function will be called and we * will longjmp back to pcb_jmpbuf to abort. If parsing succeeds, * we optionally display the parse tree if debugging is enabled. */ if (yyparse() != 0 || yypcb->pcb_root == NULL) xyerror(D_EMPTY, "empty D program translation unit\n"); yybegin(YYS_DONE); if (cflags & DTRACE_C_CTL) goto out; if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 1)) dt_node_printr(yypcb->pcb_root, stderr, 0); if (yypcb->pcb_pragmas != NULL) (void) dt_idhash_iter(yypcb->pcb_pragmas, dt_idpragma, NULL); if (argc > 1 && !(yypcb->pcb_cflags & DTRACE_C_ARGREF) && !(yypcb->pcb_sflagv[argc - 1] & DT_IDFLG_REF)) { xyerror(D_MACRO_UNUSED, "extraneous argument '%s' ($%d is " "not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1); } /* + * Perform sugar transformations (for "if" / "else") and replace the + * existing clause chain with the new one. + */ + if (context == DT_CTX_DPROG) { + dt_node_t *dnp, *next_dnp; + dt_node_t *new_list = NULL; + + for (dnp = yypcb->pcb_root->dn_list; + dnp != NULL; dnp = next_dnp) { + /* remove this node from the list */ + next_dnp = dnp->dn_list; + dnp->dn_list = NULL; + + if (dnp->dn_kind == DT_NODE_CLAUSE) + dnp = dt_compile_sugar(dtp, dnp); + /* append node to the new list */ + new_list = dt_node_link(new_list, dnp); + } + yypcb->pcb_root->dn_list = new_list; + } + + /* * If we have successfully created a parse tree for a D program, loop * over the clauses and actions and instantiate the corresponding * libdtrace program. If we are parsing a D expression, then we * simply run the code generator and assembler on the resulting tree. */ switch (context) { case DT_CTX_DPROG: assert(yypcb->pcb_root->dn_kind == DT_NODE_PROG); if ((dnp = yypcb->pcb_root->dn_list) == NULL && !(yypcb->pcb_cflags & DTRACE_C_EMPTY)) xyerror(D_EMPTY, "empty D program translation unit\n"); if ((yypcb->pcb_prog = dt_program_create(dtp)) == NULL) longjmp(yypcb->pcb_jmpbuf, dtrace_errno(dtp)); for (; dnp != NULL; dnp = dnp->dn_list) { switch (dnp->dn_kind) { case DT_NODE_CLAUSE: + if (DT_TREEDUMP_PASS(dtp, 4)) + dt_printd(dnp, stderr, 0); dt_compile_clause(dtp, dnp); break; case DT_NODE_XLATOR: if (dtp->dt_xlatemode == DT_XL_DYNAMIC) dt_compile_xlator(dnp); break; case DT_NODE_PROVIDER: (void) dt_node_cook(dnp, DT_IDFLG_REF); break; } } yypcb->pcb_prog->dp_xrefs = yypcb->pcb_asxrefs; yypcb->pcb_prog->dp_xrefslen = yypcb->pcb_asxreflen; yypcb->pcb_asxrefs = NULL; yypcb->pcb_asxreflen = 0; rv = yypcb->pcb_prog; break; case DT_CTX_DEXPR: (void) dt_node_cook(yypcb->pcb_root, DT_IDFLG_REF); dt_cg(yypcb, yypcb->pcb_root); rv = dt_as(yypcb); break; case DT_CTX_DTYPE: ddp = (dt_decl_t *)yypcb->pcb_root; /* root is really a decl */ err = dt_decl_type(ddp, arg); dt_decl_free(ddp); if (err != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); rv = NULL; break; } out: if (context != DT_CTX_DTYPE && yypcb->pcb_root != NULL && DT_TREEDUMP_PASS(dtp, 3)) dt_node_printr(yypcb->pcb_root, stderr, 0); if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 || lseek64(dtp->dt_cdefs_fd, 0, SEEK_SET) == -1 || ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR)) dt_dprintf("failed to update CTF cache: %s\n", strerror(errno)); if (dtp->dt_ddefs_fd != -1 && (ftruncate64(dtp->dt_ddefs_fd, 0) == -1 || lseek64(dtp->dt_ddefs_fd, 0, SEEK_SET) == -1 || ctf_write(dtp->dt_ddefs->dm_ctfp, dtp->dt_ddefs_fd) == CTF_ERR)) dt_dprintf("failed to update CTF cache: %s\n", strerror(errno)); if (yypcb->pcb_fileptr && (cflags & DTRACE_C_CPP)) (void) fclose(yypcb->pcb_fileptr); /* close dt_preproc() file */ dt_pcb_pop(dtp, err); (void) dt_set_errno(dtp, err); return (err ? NULL : rv); } dtrace_prog_t * dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[]) { return (dt_compile(dtp, DT_CTX_DPROG, spec, NULL, cflags, argc, argv, NULL, s)); } dtrace_prog_t * dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp, uint_t cflags, int argc, char *const argv[]) { return (dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL, cflags, argc, argv, fp, NULL)); } int dtrace_type_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_typeinfo_t *dtt) { (void) dt_compile(dtp, DT_CTX_DTYPE, DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, NULL, s); return (dtp->dt_errno ? -1 : 0); } int dtrace_type_fcompile(dtrace_hdl_t *dtp, FILE *fp, dtrace_typeinfo_t *dtt) { (void) dt_compile(dtp, DT_CTX_DTYPE, DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, fp, NULL); return (dtp->dt_errno ? -1 : 0); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y (revision 304200) @@ -1,861 +1,885 @@ %{ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* - * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ #include #define OP1(op, c) dt_node_op1(op, c) #define OP2(op, l, r) dt_node_op2(op, l, r) #define OP3(x, y, z) dt_node_op3(x, y, z) #define LINK(l, r) dt_node_link(l, r) #define DUP(s) strdup(s) %} %union { dt_node_t *l_node; dt_decl_t *l_decl; char *l_str; uintmax_t l_int; int l_tok; } %token DT_TOK_COMMA DT_TOK_ELLIPSIS %token DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ %token DT_TOK_DIV_EQ DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ %token DT_TOK_LSH_EQ DT_TOK_RSH_EQ DT_TOK_QUESTION DT_TOK_COLON %token DT_TOK_LOR DT_TOK_LXOR DT_TOK_LAND %token DT_TOK_BOR DT_TOK_XOR DT_TOK_BAND DT_TOK_EQU DT_TOK_NEQ %token DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE DT_TOK_LSH DT_TOK_RSH %token DT_TOK_ADD DT_TOK_SUB DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD %token DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB %token DT_TOK_PREINC DT_TOK_POSTINC DT_TOK_PREDEC DT_TOK_POSTDEC %token DT_TOK_IPOS DT_TOK_INEG DT_TOK_DEREF DT_TOK_ADDROF %token DT_TOK_OFFSETOF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE %token DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT %token DT_TOK_STRING %token DT_TOK_IDENT %token DT_TOK_PSPEC %token DT_TOK_AGG %token DT_TOK_TNAME %token DT_TOK_INT %token DT_KEY_AUTO %token DT_KEY_BREAK %token DT_KEY_CASE %token DT_KEY_CHAR %token DT_KEY_CONST %token DT_KEY_CONTINUE %token DT_KEY_COUNTER %token DT_KEY_DEFAULT %token DT_KEY_DO %token DT_KEY_DOUBLE %token DT_KEY_ELSE %token DT_KEY_ENUM %token DT_KEY_EXTERN %token DT_KEY_FLOAT %token DT_KEY_FOR %token DT_KEY_GOTO %token DT_KEY_IF %token DT_KEY_IMPORT %token DT_KEY_INLINE %token DT_KEY_INT %token DT_KEY_LONG %token DT_KEY_PROBE %token DT_KEY_PROVIDER %token DT_KEY_REGISTER %token DT_KEY_RESTRICT %token DT_KEY_RETURN %token DT_KEY_SELF %token DT_KEY_SHORT %token DT_KEY_SIGNED %token DT_KEY_STATIC %token DT_KEY_STRING %token DT_KEY_STRUCT %token DT_KEY_SWITCH %token DT_KEY_THIS %token DT_KEY_TYPEDEF %token DT_KEY_UNION %token DT_KEY_UNSIGNED %token DT_KEY_USERLAND %token DT_KEY_VOID %token DT_KEY_VOLATILE %token DT_KEY_WHILE %token DT_KEY_XLATOR %token DT_TOK_EPRED %token DT_CTX_DEXPR %token DT_CTX_DPROG %token DT_CTX_DTYPE %token DT_TOK_EOF 0 %left DT_TOK_COMMA %right DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ DT_TOK_DIV_EQ DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ DT_TOK_LSH_EQ DT_TOK_RSH_EQ %left DT_TOK_QUESTION DT_TOK_COLON %left DT_TOK_LOR %left DT_TOK_LXOR %left DT_TOK_LAND %left DT_TOK_BOR %left DT_TOK_XOR %left DT_TOK_BAND %left DT_TOK_EQU DT_TOK_NEQ %left DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE %left DT_TOK_LSH DT_TOK_RSH %left DT_TOK_ADD DT_TOK_SUB %left DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD %right DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB DT_TOK_IPOS DT_TOK_INEG %right DT_TOK_DEREF DT_TOK_ADDROF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE %left DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT %type d_expression %type d_program %type d_type %type translation_unit %type external_declaration %type inline_definition %type translator_definition %type translator_member_list %type translator_member %type provider_definition %type provider_probe_list %type provider_probe %type probe_definition %type probe_specifiers %type probe_specifier_list %type probe_specifier %type statement_list +%type statement_list_impl +%type statement_or_block %type statement %type declaration %type init_declarator_list %type init_declarator %type type_specifier %type type_qualifier %type struct_or_union_specifier %type specifier_qualifier_list %type enum_specifier %type declarator %type direct_declarator %type pointer %type type_qualifier_list %type type_name %type abstract_declarator %type direct_abstract_declarator %type parameter_type_list %type parameter_list %type parameter_declaration %type array %type array_parameters %type function %type function_parameters %type expression %type assignment_expression %type conditional_expression %type constant_expression %type logical_or_expression %type logical_xor_expression %type logical_and_expression %type inclusive_or_expression %type exclusive_or_expression %type and_expression %type equality_expression %type relational_expression %type shift_expression %type additive_expression %type multiplicative_expression %type cast_expression %type unary_expression %type postfix_expression %type primary_expression %type argument_expression_list %type assignment_operator %type unary_operator %type struct_or_union %type dtrace_keyword_ident %% dtrace_program: d_expression DT_TOK_EOF { return (dt_node_root($1)); } | d_program DT_TOK_EOF { return (dt_node_root($1)); } | d_type DT_TOK_EOF { return (dt_node_root($1)); } ; d_expression: DT_CTX_DEXPR { $$ = NULL; } | DT_CTX_DEXPR expression { $$ = $2; } ; d_program: DT_CTX_DPROG { $$ = dt_node_program(NULL); } | DT_CTX_DPROG translation_unit { $$ = dt_node_program($2); } ; d_type: DT_CTX_DTYPE { $$ = NULL; } | DT_CTX_DTYPE type_name { $$ = (dt_node_t *)$2; } ; translation_unit: external_declaration | translation_unit external_declaration { $$ = LINK($1, $2); } ; external_declaration: inline_definition | translator_definition | provider_definition | probe_definition | declaration ; inline_definition: DT_KEY_INLINE declaration_specifiers declarator { dt_scope_push(NULL, CTF_ERR); } DT_TOK_ASGN assignment_expression ';' { /* * We push a new declaration scope before shifting the * assignment_expression in order to preserve ds_class * and ds_ident for use in dt_node_inline(). Once the * entire inline_definition rule is matched, pop the * scope and construct the inline using the saved decl. */ dt_scope_pop(); $$ = dt_node_inline($6); } ; translator_definition: DT_KEY_XLATOR type_name DT_TOK_LT type_name DT_TOK_IDENT DT_TOK_GT '{' translator_member_list '}' ';' { $$ = dt_node_xlator($2, $4, $5, $8); } | DT_KEY_XLATOR type_name DT_TOK_LT type_name DT_TOK_IDENT DT_TOK_GT '{' '}' ';' { $$ = dt_node_xlator($2, $4, $5, NULL); } ; translator_member_list: translator_member | translator_member_list translator_member { $$ = LINK($1,$2); } ; translator_member: DT_TOK_IDENT DT_TOK_ASGN assignment_expression ';' { $$ = dt_node_member(NULL, $1, $3); } ; provider_definition: DT_KEY_PROVIDER DT_TOK_IDENT '{' provider_probe_list '}' ';' { $$ = dt_node_provider($2, $4); } | DT_KEY_PROVIDER DT_TOK_IDENT '{' '}' ';' { $$ = dt_node_provider($2, NULL); } ; provider_probe_list: provider_probe | provider_probe_list provider_probe { $$ = LINK($1, $2); } ; provider_probe: DT_KEY_PROBE DT_TOK_IDENT function DT_TOK_COLON function ';' { $$ = dt_node_probe($2, 2, $3, $5); } | DT_KEY_PROBE DT_TOK_IDENT function ';' { $$ = dt_node_probe($2, 1, $3, NULL); } ; probe_definition: probe_specifiers { /* * If the input stream is a file, do not permit a probe * specification without / / or { } after * it. This can only occur if the next token is EOF or * an ambiguous predicate was slurped up as a comment. * We cannot perform this check if input() is a string * because dtrace(1M) [-fmnP] also use the compiler and * things like dtrace -n BEGIN have to be accepted. */ if (yypcb->pcb_fileptr != NULL) { dnerror($1, D_SYNTAX, "expected predicate and/" "or actions following probe description\n"); } $$ = dt_node_clause($1, NULL, NULL); + yybegin(YYS_CLAUSE); } | probe_specifiers '{' statement_list '}' { $$ = dt_node_clause($1, NULL, $3); + yybegin(YYS_CLAUSE); } | probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED { dnerror($3, D_SYNTAX, "expected actions { } following " "probe description and predicate\n"); } | probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED '{' statement_list '}' { $$ = dt_node_clause($1, $3, $6); + yybegin(YYS_CLAUSE); } ; probe_specifiers: probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; } ; probe_specifier_list: probe_specifier | probe_specifier_list DT_TOK_COMMA probe_specifier { $$ = LINK($1, $3); } ; probe_specifier: DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); } | DT_TOK_INT { $$ = dt_node_pdesc_by_id($1); } ; -statement_list: statement { $$ = $1; } - | statement_list ';' statement { $$ = LINK($1, $3); } +statement_list_impl: /* empty */ { $$ = NULL; } + | statement_list_impl statement { $$ = LINK($1, $2); } ; -statement: /* empty */ { $$ = NULL; } - | expression { $$ = dt_node_statement($1); } +statement_list: + statement_list_impl { $$ = $1; } + | statement_list_impl expression { + $$ = LINK($1, dt_node_statement($2)); + } + ; + +statement_or_block: + statement + | '{' statement_list '}' { $$ = $2; } + +statement: ';' { $$ = NULL; } + | expression ';' { $$ = dt_node_statement($1); } + | DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR statement_or_block { + $$ = dt_node_if($3, $5, NULL); + } + | DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR + statement_or_block DT_KEY_ELSE statement_or_block { + $$ = dt_node_if($3, $5, $7); + } ; argument_expression_list: assignment_expression | argument_expression_list DT_TOK_COMMA assignment_expression { $$ = LINK($1, $3); } ; primary_expression: DT_TOK_IDENT { $$ = dt_node_ident($1); } | DT_TOK_AGG { $$ = dt_node_ident($1); } | DT_TOK_INT { $$ = dt_node_int($1); } | DT_TOK_STRING { $$ = dt_node_string($1); } | DT_KEY_SELF { $$ = dt_node_ident(DUP("self")); } | DT_KEY_THIS { $$ = dt_node_ident(DUP("this")); } | DT_TOK_LPAR expression DT_TOK_RPAR { $$ = $2; } ; postfix_expression: primary_expression | postfix_expression DT_TOK_LBRAC argument_expression_list DT_TOK_RBRAC { $$ = OP2(DT_TOK_LBRAC, $1, $3); } | postfix_expression DT_TOK_LPAR DT_TOK_RPAR { $$ = dt_node_func($1, NULL); } | postfix_expression DT_TOK_LPAR argument_expression_list DT_TOK_RPAR { $$ = dt_node_func($1, $3); } | postfix_expression DT_TOK_DOT DT_TOK_IDENT { $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_DOT DT_TOK_TNAME { $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_DOT dtrace_keyword_ident { $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_PTR DT_TOK_IDENT { $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_PTR DT_TOK_TNAME { $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_PTR dtrace_keyword_ident { $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3)); } | postfix_expression DT_TOK_ADDADD { $$ = OP1(DT_TOK_POSTINC, $1); } | postfix_expression DT_TOK_SUBSUB { $$ = OP1(DT_TOK_POSTDEC, $1); } | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA DT_TOK_IDENT DT_TOK_RPAR { $$ = dt_node_offsetof($3, $5); } | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA DT_TOK_TNAME DT_TOK_RPAR { $$ = dt_node_offsetof($3, $5); } | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA dtrace_keyword_ident DT_TOK_RPAR { $$ = dt_node_offsetof($3, $5); } | DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT DT_TOK_LPAR expression DT_TOK_RPAR { $$ = OP2(DT_TOK_XLATE, dt_node_type($3), $6); } ; unary_expression: postfix_expression | DT_TOK_ADDADD unary_expression { $$ = OP1(DT_TOK_PREINC, $2); } | DT_TOK_SUBSUB unary_expression { $$ = OP1(DT_TOK_PREDEC, $2); } | unary_operator cast_expression { $$ = OP1($1, $2); } | DT_TOK_SIZEOF unary_expression { $$ = OP1(DT_TOK_SIZEOF, $2); } | DT_TOK_SIZEOF DT_TOK_LPAR type_name DT_TOK_RPAR { $$ = OP1(DT_TOK_SIZEOF, dt_node_type($3)); } | DT_TOK_STRINGOF unary_expression { $$ = OP1(DT_TOK_STRINGOF, $2); } ; unary_operator: DT_TOK_BAND { $$ = DT_TOK_ADDROF; } | DT_TOK_MUL { $$ = DT_TOK_DEREF; } | DT_TOK_ADD { $$ = DT_TOK_IPOS; } | DT_TOK_SUB { $$ = DT_TOK_INEG; } | DT_TOK_BNEG { $$ = DT_TOK_BNEG; } | DT_TOK_LNEG { $$ = DT_TOK_LNEG; } ; cast_expression: unary_expression | DT_TOK_LPAR type_name DT_TOK_RPAR cast_expression { $$ = OP2(DT_TOK_LPAR, dt_node_type($2), $4); } ; multiplicative_expression: cast_expression | multiplicative_expression DT_TOK_MUL cast_expression { $$ = OP2(DT_TOK_MUL, $1, $3); } | multiplicative_expression DT_TOK_DIV cast_expression { $$ = OP2(DT_TOK_DIV, $1, $3); } | multiplicative_expression DT_TOK_MOD cast_expression { $$ = OP2(DT_TOK_MOD, $1, $3); } ; additive_expression: multiplicative_expression | additive_expression DT_TOK_ADD multiplicative_expression { $$ = OP2(DT_TOK_ADD, $1, $3); } | additive_expression DT_TOK_SUB multiplicative_expression { $$ = OP2(DT_TOK_SUB, $1, $3); } ; shift_expression: additive_expression | shift_expression DT_TOK_LSH additive_expression { $$ = OP2(DT_TOK_LSH, $1, $3); } | shift_expression DT_TOK_RSH additive_expression { $$ = OP2(DT_TOK_RSH, $1, $3); } ; relational_expression: shift_expression | relational_expression DT_TOK_LT shift_expression { $$ = OP2(DT_TOK_LT, $1, $3); } | relational_expression DT_TOK_GT shift_expression { $$ = OP2(DT_TOK_GT, $1, $3); } | relational_expression DT_TOK_LE shift_expression { $$ = OP2(DT_TOK_LE, $1, $3); } | relational_expression DT_TOK_GE shift_expression { $$ = OP2(DT_TOK_GE, $1, $3); } ; equality_expression: relational_expression | equality_expression DT_TOK_EQU relational_expression { $$ = OP2(DT_TOK_EQU, $1, $3); } | equality_expression DT_TOK_NEQ relational_expression { $$ = OP2(DT_TOK_NEQ, $1, $3); } ; and_expression: equality_expression | and_expression DT_TOK_BAND equality_expression { $$ = OP2(DT_TOK_BAND, $1, $3); } ; exclusive_or_expression: and_expression | exclusive_or_expression DT_TOK_XOR and_expression { $$ = OP2(DT_TOK_XOR, $1, $3); } ; inclusive_or_expression: exclusive_or_expression | inclusive_or_expression DT_TOK_BOR exclusive_or_expression { $$ = OP2(DT_TOK_BOR, $1, $3); } ; logical_and_expression: inclusive_or_expression | logical_and_expression DT_TOK_LAND inclusive_or_expression { $$ = OP2(DT_TOK_LAND, $1, $3); } ; logical_xor_expression: logical_and_expression | logical_xor_expression DT_TOK_LXOR logical_and_expression { $$ = OP2(DT_TOK_LXOR, $1, $3); } ; logical_or_expression: logical_xor_expression | logical_or_expression DT_TOK_LOR logical_xor_expression { $$ = OP2(DT_TOK_LOR, $1, $3); } ; constant_expression: conditional_expression ; conditional_expression: logical_or_expression | logical_or_expression DT_TOK_QUESTION expression DT_TOK_COLON conditional_expression { $$ = OP3($1, $3, $5); } ; assignment_expression: conditional_expression | unary_expression assignment_operator assignment_expression { $$ = OP2($2, $1, $3); } ; assignment_operator: DT_TOK_ASGN { $$ = DT_TOK_ASGN; } | DT_TOK_MUL_EQ { $$ = DT_TOK_MUL_EQ; } | DT_TOK_DIV_EQ { $$ = DT_TOK_DIV_EQ; } | DT_TOK_MOD_EQ { $$ = DT_TOK_MOD_EQ; } | DT_TOK_ADD_EQ { $$ = DT_TOK_ADD_EQ; } | DT_TOK_SUB_EQ { $$ = DT_TOK_SUB_EQ; } | DT_TOK_LSH_EQ { $$ = DT_TOK_LSH_EQ; } | DT_TOK_RSH_EQ { $$ = DT_TOK_RSH_EQ; } | DT_TOK_AND_EQ { $$ = DT_TOK_AND_EQ; } | DT_TOK_XOR_EQ { $$ = DT_TOK_XOR_EQ; } | DT_TOK_OR_EQ { $$ = DT_TOK_OR_EQ; } ; expression: assignment_expression | expression DT_TOK_COMMA assignment_expression { $$ = OP2(DT_TOK_COMMA, $1, $3); } ; declaration: declaration_specifiers ';' { $$ = dt_node_decl(); dt_decl_free(dt_decl_pop()); yybegin(YYS_CLAUSE); } | declaration_specifiers init_declarator_list ';' { $$ = $2; dt_decl_free(dt_decl_pop()); yybegin(YYS_CLAUSE); } ; declaration_specifiers: d_storage_class_specifier | d_storage_class_specifier declaration_specifiers | type_specifier | type_specifier declaration_specifiers | type_qualifier | type_qualifier declaration_specifiers ; parameter_declaration_specifiers: storage_class_specifier | storage_class_specifier declaration_specifiers | type_specifier | type_specifier declaration_specifiers | type_qualifier | type_qualifier declaration_specifiers ; storage_class_specifier: DT_KEY_AUTO { dt_decl_class(DT_DC_AUTO); } | DT_KEY_REGISTER { dt_decl_class(DT_DC_REGISTER); } | DT_KEY_STATIC { dt_decl_class(DT_DC_STATIC); } | DT_KEY_EXTERN { dt_decl_class(DT_DC_EXTERN); } | DT_KEY_TYPEDEF { dt_decl_class(DT_DC_TYPEDEF); } ; d_storage_class_specifier: storage_class_specifier | DT_KEY_SELF { dt_decl_class(DT_DC_SELF); } | DT_KEY_THIS { dt_decl_class(DT_DC_THIS); } ; type_specifier: DT_KEY_VOID { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("void")); } | DT_KEY_CHAR { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("char")); } | DT_KEY_SHORT { $$ = dt_decl_attr(DT_DA_SHORT); } | DT_KEY_INT { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("int")); } | DT_KEY_LONG { $$ = dt_decl_attr(DT_DA_LONG); } | DT_KEY_FLOAT { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("float")); } | DT_KEY_DOUBLE { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("double")); } | DT_KEY_SIGNED { $$ = dt_decl_attr(DT_DA_SIGNED); } | DT_KEY_UNSIGNED { $$ = dt_decl_attr(DT_DA_UNSIGNED); } | DT_KEY_USERLAND { $$ = dt_decl_attr(DT_DA_USER); } | DT_KEY_STRING { $$ = dt_decl_spec(CTF_K_TYPEDEF, DUP("string")); } | DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_TYPEDEF, $1); } | struct_or_union_specifier | enum_specifier ; type_qualifier: DT_KEY_CONST { $$ = dt_decl_attr(DT_DA_CONST); } | DT_KEY_RESTRICT { $$ = dt_decl_attr(DT_DA_RESTRICT); } | DT_KEY_VOLATILE { $$ = dt_decl_attr(DT_DA_VOLATILE); } ; struct_or_union_specifier: struct_or_union_definition struct_declaration_list '}' { $$ = dt_scope_pop(); } | struct_or_union DT_TOK_IDENT { $$ = dt_decl_spec($1, $2); } | struct_or_union DT_TOK_TNAME { $$ = dt_decl_spec($1, $2); } ; struct_or_union_definition: struct_or_union '{' { dt_decl_sou($1, NULL); } | struct_or_union DT_TOK_IDENT '{' { dt_decl_sou($1, $2); } | struct_or_union DT_TOK_TNAME '{' { dt_decl_sou($1, $2); } ; struct_or_union: DT_KEY_STRUCT { $$ = CTF_K_STRUCT; } | DT_KEY_UNION { $$ = CTF_K_UNION; } ; struct_declaration_list: struct_declaration | struct_declaration_list struct_declaration ; init_declarator_list: init_declarator | init_declarator_list DT_TOK_COMMA init_declarator { $$ = LINK($1, $3); } ; init_declarator: declarator { $$ = dt_node_decl(); dt_decl_reset(); } ; struct_declaration: specifier_qualifier_list struct_declarator_list ';' { dt_decl_free(dt_decl_pop()); } ; specifier_qualifier_list: type_specifier | type_specifier specifier_qualifier_list { $$ = $2; } | type_qualifier | type_qualifier specifier_qualifier_list { $$ = $2; } ; struct_declarator_list: struct_declarator | struct_declarator_list DT_TOK_COMMA struct_declarator ; struct_declarator: declarator { dt_decl_member(NULL); } | DT_TOK_COLON constant_expression { dt_decl_member($2); } | declarator DT_TOK_COLON constant_expression { dt_decl_member($3); } ; enum_specifier: enum_definition enumerator_list '}' { $$ = dt_scope_pop(); } | DT_KEY_ENUM DT_TOK_IDENT { $$ = dt_decl_spec(CTF_K_ENUM, $2); } | DT_KEY_ENUM DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_ENUM, $2); } ; enum_definition: DT_KEY_ENUM '{' { dt_decl_enum(NULL); } | DT_KEY_ENUM DT_TOK_IDENT '{' { dt_decl_enum($2); } | DT_KEY_ENUM DT_TOK_TNAME '{' { dt_decl_enum($2); } ; enumerator_list: enumerator | enumerator_list DT_TOK_COMMA enumerator ; enumerator: DT_TOK_IDENT { dt_decl_enumerator($1, NULL); } | DT_TOK_IDENT DT_TOK_ASGN expression { dt_decl_enumerator($1, $3); } ; declarator: direct_declarator | pointer direct_declarator ; direct_declarator: DT_TOK_IDENT { $$ = dt_decl_ident($1); } | lparen declarator DT_TOK_RPAR { $$ = $2; } | direct_declarator array { dt_decl_array($2); } | direct_declarator function { dt_decl_func($1, $2); } ; lparen: DT_TOK_LPAR { dt_decl_top()->dd_attr |= DT_DA_PAREN; } ; pointer: DT_TOK_MUL { $$ = dt_decl_ptr(); } | DT_TOK_MUL type_qualifier_list { $$ = dt_decl_ptr(); } | DT_TOK_MUL pointer { $$ = dt_decl_ptr(); } | DT_TOK_MUL type_qualifier_list pointer { $$ = dt_decl_ptr(); } ; type_qualifier_list: type_qualifier | type_qualifier_list type_qualifier { $$ = $2; } ; parameter_type_list: parameter_list | DT_TOK_ELLIPSIS { $$ = dt_node_vatype(); } | parameter_list DT_TOK_COMMA DT_TOK_ELLIPSIS { $$ = LINK($1, dt_node_vatype()); } ; parameter_list: parameter_declaration | parameter_list DT_TOK_COMMA parameter_declaration { $$ = LINK($1, $3); } ; parameter_declaration: parameter_declaration_specifiers { $$ = dt_node_type(NULL); } | parameter_declaration_specifiers declarator { $$ = dt_node_type(NULL); } | parameter_declaration_specifiers abstract_declarator { $$ = dt_node_type(NULL); } ; type_name: specifier_qualifier_list { $$ = dt_decl_pop(); } | specifier_qualifier_list abstract_declarator { $$ = dt_decl_pop(); } ; abstract_declarator: pointer | direct_abstract_declarator | pointer direct_abstract_declarator ; direct_abstract_declarator: lparen abstract_declarator DT_TOK_RPAR { $$ = $2; } | direct_abstract_declarator array { dt_decl_array($2); } | array { dt_decl_array($1); $$ = NULL; } | direct_abstract_declarator function { dt_decl_func($1, $2); } | function { dt_decl_func(NULL, $1); } ; array: DT_TOK_LBRAC { dt_scope_push(NULL, CTF_ERR); } array_parameters DT_TOK_RBRAC { dt_scope_pop(); $$ = $3; } ; array_parameters: /* empty */ { $$ = NULL; } | constant_expression { $$ = $1; } | parameter_type_list { $$ = $1; } ; function: DT_TOK_LPAR { dt_scope_push(NULL, CTF_ERR); } function_parameters DT_TOK_RPAR { dt_scope_pop(); $$ = $3; } ; function_parameters: /* empty */ { $$ = NULL; } | parameter_type_list { $$ = $1; } ; dtrace_keyword_ident: DT_KEY_PROBE { $$ = DUP("probe"); } | DT_KEY_PROVIDER { $$ = DUP("provider"); } | DT_KEY_SELF { $$ = DUP("self"); } | DT_KEY_STRING { $$ = DUP("string"); } | DT_TOK_STRINGOF { $$ = DUP("stringof"); } | DT_KEY_USERLAND { $$ = DUP("userland"); } | DT_TOK_XLATE { $$ = DUP("xlate"); } | DT_KEY_XLATOR { $$ = DUP("translator"); } ; %% Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h (revision 304200) @@ -1,756 +1,757 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2013, Joyent, Inc. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2011, 2016 by Delphix. All rights reserved. */ #ifndef _DT_IMPL_H #define _DT_IMPL_H #include #include #ifndef illumos #include #include #include #include #include #endif #include #include #include #include #ifdef illumos #include #endif #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include #include #include #include #include #include #include #include struct dt_module; /* see below */ struct dt_pfdict; /* see */ struct dt_arg; /* see below */ struct dt_provider; /* see */ struct dt_xlator; /* see */ typedef struct dt_intrinsic { const char *din_name; /* string name of the intrinsic type */ ctf_encoding_t din_data; /* integer or floating-point CTF encoding */ uint_t din_kind; /* CTF type kind to instantiate */ } dt_intrinsic_t; typedef struct dt_typedef { const char *dty_src; /* string name of typedef source type */ const char *dty_dst; /* string name of typedef destination type */ } dt_typedef_t; typedef struct dt_intdesc { const char *did_name; /* string name of the integer type */ ctf_file_t *did_ctfp; /* CTF container for this type reference */ ctf_id_t did_type; /* CTF type reference for this type */ uintmax_t did_limit; /* maximum positive value held by type */ } dt_intdesc_t; typedef struct dt_modops { uint_t (*do_syminit)(struct dt_module *); void (*do_symsort)(struct dt_module *); GElf_Sym *(*do_symname)(struct dt_module *, const char *, GElf_Sym *, uint_t *); GElf_Sym *(*do_symaddr)(struct dt_module *, GElf_Addr, GElf_Sym *, uint_t *); } dt_modops_t; typedef struct dt_arg { int da_ndx; /* index of this argument */ int da_mapping; /* mapping of argument indices to arguments */ ctf_id_t da_type; /* type of argument */ ctf_file_t *da_ctfp; /* CTF container for type */ dt_ident_t *da_xlator; /* translator, if any */ struct dt_arg *da_next; /* next argument */ } dt_arg_t; typedef struct dt_sym { uint_t ds_symid; /* id of corresponding symbol */ uint_t ds_next; /* index of next element in hash chain */ } dt_sym_t; typedef struct dt_module { dt_list_t dm_list; /* list forward/back pointers */ char dm_name[DTRACE_MODNAMELEN]; /* string name of module */ char dm_file[MAXPATHLEN]; /* file path of module (if any) */ struct dt_module *dm_next; /* pointer to next module in hash chain */ const dt_modops_t *dm_ops; /* pointer to data model's ops vector */ Elf *dm_elf; /* libelf handle for module object */ objfs_info_t dm_info; /* object filesystem private info */ ctf_sect_t dm_symtab; /* symbol table for module */ ctf_sect_t dm_strtab; /* string table for module */ ctf_sect_t dm_ctdata; /* CTF data for module */ ctf_file_t *dm_ctfp; /* CTF container handle */ uint_t *dm_symbuckets; /* symbol table hash buckets (chain indices) */ dt_sym_t *dm_symchains; /* symbol table hash chains buffer */ void *dm_asmap; /* symbol pointers sorted by value */ uint_t dm_symfree; /* index of next free hash element */ uint_t dm_nsymbuckets; /* number of elements in bucket array */ uint_t dm_nsymelems; /* number of elements in hash table */ uint_t dm_asrsv; /* actual reserved size of dm_asmap */ uint_t dm_aslen; /* number of entries in dm_asmap */ uint_t dm_flags; /* module flags (see below) */ int dm_modid; /* modinfo(1M) module identifier */ GElf_Addr dm_text_va; /* virtual address of text section */ GElf_Xword dm_text_size; /* size in bytes of text section */ GElf_Addr dm_data_va; /* virtual address of data section */ GElf_Xword dm_data_size; /* size in bytes of data section */ GElf_Addr dm_bss_va; /* virtual address of BSS */ GElf_Xword dm_bss_size; /* size in bytes of BSS */ dt_idhash_t *dm_extern; /* external symbol definitions */ #ifndef illumos caddr_t dm_reloc_offset; /* Symbol relocation offset. */ uintptr_t *dm_sec_offsets; #endif pid_t dm_pid; /* pid for this module */ uint_t dm_nctflibs; /* number of ctf children libraries */ ctf_file_t **dm_libctfp; /* process library ctf pointers */ char **dm_libctfn; /* names of process ctf containers */ } dt_module_t; #define DT_DM_LOADED 0x1 /* module symbol and type data is loaded */ #define DT_DM_KERNEL 0x2 /* module is associated with a kernel object */ #define DT_DM_PRIMARY 0x4 /* module is a krtld primary kernel object */ #ifdef __FreeBSD__ /* * A representation of a FreeBSD kernel module, used when checking module * dependencies. This differs from dt_module_t, which refers to a KLD in the * case of kernel probes. Since modules can be identified regardless of whether * they've been compiled into the kernel, we use them to identify DTrace * modules. */ typedef struct dt_kmodule { struct dt_kmodule *dkm_next; /* hash table entry */ char *dkm_name; /* string name of module */ dt_module_t *dkm_module; /* corresponding KLD module */ } dt_kmodule_t; #endif typedef struct dt_provmod { char *dp_name; /* name of provider module */ struct dt_provmod *dp_next; /* next module */ } dt_provmod_t; typedef struct dt_ahashent { struct dt_ahashent *dtahe_prev; /* prev on hash chain */ struct dt_ahashent *dtahe_next; /* next on hash chain */ struct dt_ahashent *dtahe_prevall; /* prev on list of all */ struct dt_ahashent *dtahe_nextall; /* next on list of all */ uint64_t dtahe_hashval; /* hash value */ size_t dtahe_size; /* size of data */ dtrace_aggdata_t dtahe_data; /* data */ void (*dtahe_aggregate)(int64_t *, int64_t *, size_t); /* function */ } dt_ahashent_t; typedef struct dt_ahash { dt_ahashent_t **dtah_hash; /* hash table */ dt_ahashent_t *dtah_all; /* list of all elements */ size_t dtah_size; /* size of hash table */ } dt_ahash_t; typedef struct dt_aggregate { dtrace_bufdesc_t dtat_buf; /* buf aggregation snapshot */ int dtat_flags; /* aggregate flags */ processorid_t dtat_ncpus; /* number of CPUs in aggregate */ processorid_t *dtat_cpus; /* CPUs in aggregate */ processorid_t dtat_ncpu; /* size of dtat_cpus array */ processorid_t dtat_maxcpu; /* maximum number of CPUs */ dt_ahash_t dtat_hash; /* aggregate hash table */ } dt_aggregate_t; typedef struct dt_print_aggdata { dtrace_hdl_t *dtpa_dtp; /* pointer to libdtrace handle */ dtrace_aggvarid_t dtpa_id; /* aggregation variable of interest */ FILE *dtpa_fp; /* file pointer */ int dtpa_allunprint; /* print only unprinted aggregations */ int dtpa_agghist; /* print aggregation as histogram */ int dtpa_agghisthdr; /* aggregation histogram hdr printed */ int dtpa_aggpack; /* pack quantized aggregations */ } dt_print_aggdata_t; typedef struct dt_dirpath { dt_list_t dir_list; /* linked-list forward/back pointers */ char *dir_path; /* directory pathname */ } dt_dirpath_t; typedef struct dt_lib_depend { dt_list_t dtld_deplist; /* linked-list forward/back pointers */ char *dtld_library; /* library name */ char *dtld_libpath; /* library pathname */ uint_t dtld_finish; /* completion time in tsort for lib */ uint_t dtld_start; /* starting time in tsort for lib */ uint_t dtld_loaded; /* boolean: is this library loaded */ dt_list_t dtld_dependencies; /* linked-list of lib dependencies */ dt_list_t dtld_dependents; /* linked-list of lib dependents */ } dt_lib_depend_t; typedef uint32_t dt_version_t; /* encoded version (see below) */ struct dtrace_hdl { const dtrace_vector_t *dt_vector; /* library vector, if vectored open */ void *dt_varg; /* vector argument, if vectored open */ dtrace_conf_t dt_conf; /* DTrace driver configuration profile */ char dt_errmsg[BUFSIZ]; /* buffer for formatted syntax error msgs */ const char *dt_errtag; /* tag used with last call to dt_set_errmsg() */ dt_pcb_t *dt_pcb; /* pointer to current parsing control block */ ulong_t dt_gen; /* compiler generation number */ dt_list_t dt_programs; /* linked list of dtrace_prog_t's */ dt_list_t dt_xlators; /* linked list of dt_xlator_t's */ struct dt_xlator **dt_xlatormap; /* dt_xlator_t's indexed by dx_id */ id_t dt_xlatorid; /* next dt_xlator_t id to assign */ dt_ident_t *dt_externs; /* linked list of external symbol identifiers */ dt_idhash_t *dt_macros; /* hash table of macro variable identifiers */ dt_idhash_t *dt_aggs; /* hash table of aggregation identifiers */ dt_idhash_t *dt_globals; /* hash table of global identifiers */ dt_idhash_t *dt_tls; /* hash table of thread-local identifiers */ dt_list_t dt_modlist; /* linked list of dt_module_t's */ dt_module_t **dt_mods; /* hash table of dt_module_t's */ #ifdef __FreeBSD__ dt_kmodule_t **dt_kmods; /* hash table of dt_kmodule_t's */ #endif uint_t dt_modbuckets; /* number of module hash buckets */ uint_t dt_nmods; /* number of modules in hash and list */ dt_provmod_t *dt_provmod; /* linked list of provider modules */ dt_module_t *dt_exec; /* pointer to executable module */ dt_module_t *dt_rtld; /* pointer to run-time linker module */ dt_module_t *dt_cdefs; /* pointer to C dynamic type module */ dt_module_t *dt_ddefs; /* pointer to D dynamic type module */ dt_list_t dt_provlist; /* linked list of dt_provider_t's */ struct dt_provider **dt_provs; /* hash table of dt_provider_t's */ uint_t dt_provbuckets; /* number of provider hash buckets */ uint_t dt_nprovs; /* number of providers in hash and list */ dt_proc_hash_t *dt_procs; /* hash table of grabbed process handles */ char **dt_proc_env; /* additional environment variables */ dt_intdesc_t dt_ints[6]; /* cached integer type descriptions */ ctf_id_t dt_type_func; /* cached CTF identifier for function type */ ctf_id_t dt_type_fptr; /* cached CTF identifier for function pointer */ ctf_id_t dt_type_str; /* cached CTF identifier for string type */ ctf_id_t dt_type_dyn; /* cached CTF identifier for type */ ctf_id_t dt_type_stack; /* cached CTF identifier for stack type */ ctf_id_t dt_type_symaddr; /* cached CTF identifier for _symaddr type */ ctf_id_t dt_type_usymaddr; /* cached CTF ident. for _usymaddr type */ size_t dt_maxprobe; /* max enabled probe ID */ dtrace_eprobedesc_t **dt_edesc; /* enabled probe descriptions */ dtrace_probedesc_t **dt_pdesc; /* probe descriptions for enabled prbs */ size_t dt_maxagg; /* max aggregation ID */ dtrace_aggdesc_t **dt_aggdesc; /* aggregation descriptions */ int dt_maxformat; /* max format ID */ void **dt_formats; /* pointer to format array */ int dt_maxstrdata; /* max strdata ID */ char **dt_strdata; /* pointer to strdata array */ dt_aggregate_t dt_aggregate; /* aggregate */ dt_pq_t *dt_bufq; /* CPU-specific data queue */ struct dt_pfdict *dt_pfdict; /* dictionary of printf conversions */ dt_version_t dt_vmax; /* optional ceiling on program API binding */ dtrace_attribute_t dt_amin; /* optional floor on program attributes */ char *dt_cpp_path; /* pathname of cpp(1) to invoke if needed */ char **dt_cpp_argv; /* argument vector for exec'ing cpp(1) */ int dt_cpp_argc; /* count of initialized cpp(1) arguments */ int dt_cpp_args; /* size of dt_cpp_argv[] array */ char *dt_ld_path; /* pathname of ld(1) to invoke if needed */ #ifdef __FreeBSD__ char *dt_objcopy_path; /* pathname of objcopy(1) to invoke if needed */ #endif dt_list_t dt_lib_path; /* linked-list forming library search path */ uint_t dt_lazyload; /* boolean: set via -xlazyload */ uint_t dt_droptags; /* boolean: set via -xdroptags */ uint_t dt_active; /* boolean: set once tracing is active */ uint_t dt_stopped; /* boolean: set once tracing is stopped */ processorid_t dt_beganon; /* CPU that executed BEGIN probe (if any) */ processorid_t dt_endedon; /* CPU that executed END probe (if any) */ uint_t dt_oflags; /* dtrace open-time options (see dtrace.h) */ uint_t dt_cflags; /* dtrace compile-time options (see dtrace.h) */ uint_t dt_dflags; /* dtrace link-time options (see dtrace.h) */ uint_t dt_prcmode; /* dtrace process create mode (see dt_proc.h) */ uint_t dt_linkmode; /* dtrace symbol linking mode (see below) */ uint_t dt_linktype; /* dtrace link output file type (see below) */ uint_t dt_xlatemode; /* dtrace translator linking mode (see below) */ uint_t dt_stdcmode; /* dtrace stdc compatibility mode (see below) */ uint_t dt_encoding; /* dtrace output encoding (see below) */ uint_t dt_treedump; /* dtrace tree debug bitmap (see below) */ uint64_t dt_options[DTRACEOPT_MAX]; /* dtrace run-time options */ int dt_version; /* library version requested by client */ int dt_ctferr; /* error resulting from last CTF failure */ int dt_errno; /* error resulting from last failed operation */ #ifndef illumos const char *dt_errfile; int dt_errline; #endif int dt_fd; /* file descriptor for dtrace pseudo-device */ int dt_ftfd; /* file descriptor for fasttrap pseudo-device */ int dt_fterr; /* saved errno from failed open of dt_ftfd */ int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */ int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */ #ifdef illumos int dt_stdout_fd; /* file descriptor for saved stdout */ #else FILE *dt_freopen_fp; /* file pointer for freopened stdout */ #endif dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */ void *dt_errarg; /* error handler argument */ dtrace_prog_t *dt_errprog; /* error handler program, if any */ dtrace_handle_drop_f *dt_drophdlr; /* drop handler, if any */ void *dt_droparg; /* drop handler argument */ dtrace_handle_proc_f *dt_prochdlr; /* proc handler, if any */ void *dt_procarg; /* proc handler argument */ dtrace_handle_setopt_f *dt_setopthdlr; /* setopt handler, if any */ void *dt_setoptarg; /* setopt handler argument */ dtrace_status_t dt_status[2]; /* status cache */ int dt_statusgen; /* current status generation */ hrtime_t dt_laststatus; /* last status */ hrtime_t dt_lastswitch; /* last switch of buffer data */ hrtime_t dt_lastagg; /* last snapshot of aggregation data */ char *dt_sprintf_buf; /* buffer for dtrace_sprintf() */ int dt_sprintf_buflen; /* length of dtrace_sprintf() buffer */ const char *dt_filetag; /* default filetag for dt_set_errmsg() */ char *dt_buffered_buf; /* buffer for buffered output */ size_t dt_buffered_offs; /* current offset into buffered buffer */ size_t dt_buffered_size; /* size of buffered buffer */ dtrace_handle_buffered_f *dt_bufhdlr; /* buffered handler, if any */ void *dt_bufarg; /* buffered handler argument */ dt_dof_t dt_dof; /* DOF generation buffers (see dt_dof.c) */ struct utsname dt_uts; /* uname(2) information for system */ dt_list_t dt_lib_dep; /* scratch linked-list of lib dependencies */ dt_list_t dt_lib_dep_sorted; /* dependency sorted library list */ dtrace_flowkind_t dt_flow; /* flow kind */ const char *dt_prefix; /* recommended flow prefix */ int dt_indent; /* recommended flow indent */ dtrace_epid_t dt_last_epid; /* most recently consumed EPID */ uint64_t dt_last_timestamp; /* most recently consumed timestamp */ + boolean_t dt_has_sugar; /* syntactic sugar used? */ }; /* * Values for the user arg of the ECB. */ #define DT_ECB_DEFAULT 0 #define DT_ECB_ERROR 1 /* * Values for the dt_linkmode property, which is used by the assembler when * processing external symbol references. User can set using -xlink=. */ #define DT_LINK_KERNEL 0 /* kernel syms static, user syms dynamic */ #define DT_LINK_PRIMARY 1 /* primary kernel syms static, others dynamic */ #define DT_LINK_DYNAMIC 2 /* all symbols dynamic */ #define DT_LINK_STATIC 3 /* all symbols static */ /* * Values for the dt_linktype property, which is used by dtrace_program_link() * to determine the type of output file that is desired by the client. */ #define DT_LTYP_ELF 0 /* produce ELF containing DOF */ #define DT_LTYP_DOF 1 /* produce stand-alone DOF */ /* * Values for the dt_xlatemode property, which is used to determine whether * references to dynamic translators are permitted. Set using -xlate=. */ #define DT_XL_STATIC 0 /* require xlators to be statically defined */ #define DT_XL_DYNAMIC 1 /* produce references to dynamic translators */ /* * Values for the dt_stdcmode property, which is used by the compiler when * running cpp to determine the presence and setting of the __STDC__ macro. */ #define DT_STDC_XA 0 /* ISO C + K&R C compat w/o ISO: __STDC__=0 */ #define DT_STDC_XC 1 /* Strict ISO C: __STDC__=1 */ #define DT_STDC_XS 2 /* K&R C: __STDC__ not defined */ #define DT_STDC_XT 3 /* ISO C + K&R C compat with ISO: __STDC__=0 */ /* * Values for the dt_encoding property, which is used to force a particular * character encoding (overriding default behavior and/or automatic detection). */ #define DT_ENCODING_UNSET 0 #define DT_ENCODING_ASCII 1 #define DT_ENCODING_UTF8 2 /* * Macro to test whether a given pass bit is set in the dt_treedump bit-vector. * If the bit for pass 'p' is set, the D compiler displays the parse tree for * the program by printing it to stderr at the end of compiler pass 'p'. */ #define DT_TREEDUMP_PASS(dtp, p) ((dtp)->dt_treedump & (1 << ((p) - 1))) /* * Macros for accessing the cached CTF container and type ID for the common * types "int", "string", and , which we need to use frequently in the D * compiler. The DT_INT_* macro relies upon "int" being at index 0 in the * _dtrace_ints_* tables in dt_open.c; the others are also set up there. */ #define DT_INT_CTFP(dtp) ((dtp)->dt_ints[0].did_ctfp) #define DT_INT_TYPE(dtp) ((dtp)->dt_ints[0].did_type) #define DT_FUNC_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_FUNC_TYPE(dtp) ((dtp)->dt_type_func) #define DT_FPTR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_FPTR_TYPE(dtp) ((dtp)->dt_type_fptr) #define DT_STR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_STR_TYPE(dtp) ((dtp)->dt_type_str) #define DT_DYN_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_DYN_TYPE(dtp) ((dtp)->dt_type_dyn) #define DT_STACK_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_STACK_TYPE(dtp) ((dtp)->dt_type_stack) #define DT_SYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_SYMADDR_TYPE(dtp) ((dtp)->dt_type_symaddr) #define DT_USYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) #define DT_USYMADDR_TYPE(dtp) ((dtp)->dt_type_usymaddr) /* * Actions and subroutines are both DT_NODE_FUNC nodes; to avoid confusing * an action for a subroutine (or vice versa), we assure that the DT_ACT_* * constants and the DIF_SUBR_* constants occupy non-overlapping ranges by * starting the DT_ACT_* constants at DIF_SUBR_MAX + 1. */ #define DT_ACT_BASE DIF_SUBR_MAX + 1 #define DT_ACT(n) (DT_ACT_BASE + (n)) #define DT_ACT_PRINTF DT_ACT(0) /* printf() action */ #define DT_ACT_TRACE DT_ACT(1) /* trace() action */ #define DT_ACT_TRACEMEM DT_ACT(2) /* tracemem() action */ #define DT_ACT_STACK DT_ACT(3) /* stack() action */ #define DT_ACT_STOP DT_ACT(4) /* stop() action */ #define DT_ACT_BREAKPOINT DT_ACT(5) /* breakpoint() action */ #define DT_ACT_PANIC DT_ACT(6) /* panic() action */ #define DT_ACT_SPECULATE DT_ACT(7) /* speculate() action */ #define DT_ACT_COMMIT DT_ACT(8) /* commit() action */ #define DT_ACT_DISCARD DT_ACT(9) /* discard() action */ #define DT_ACT_CHILL DT_ACT(10) /* chill() action */ #define DT_ACT_EXIT DT_ACT(11) /* exit() action */ #define DT_ACT_USTACK DT_ACT(12) /* ustack() action */ #define DT_ACT_PRINTA DT_ACT(13) /* printa() action */ #define DT_ACT_RAISE DT_ACT(14) /* raise() action */ #define DT_ACT_CLEAR DT_ACT(15) /* clear() action */ #define DT_ACT_NORMALIZE DT_ACT(16) /* normalize() action */ #define DT_ACT_DENORMALIZE DT_ACT(17) /* denormalize() action */ #define DT_ACT_TRUNC DT_ACT(18) /* trunc() action */ #define DT_ACT_SYSTEM DT_ACT(19) /* system() action */ #define DT_ACT_JSTACK DT_ACT(20) /* jstack() action */ #define DT_ACT_FTRUNCATE DT_ACT(21) /* ftruncate() action */ #define DT_ACT_FREOPEN DT_ACT(22) /* freopen() action */ #define DT_ACT_SYM DT_ACT(23) /* sym()/func() actions */ #define DT_ACT_MOD DT_ACT(24) /* mod() action */ #define DT_ACT_USYM DT_ACT(25) /* usym()/ufunc() actions */ #define DT_ACT_UMOD DT_ACT(26) /* umod() action */ #define DT_ACT_UADDR DT_ACT(27) /* uaddr() action */ #define DT_ACT_SETOPT DT_ACT(28) /* setopt() action */ #define DT_ACT_PRINT DT_ACT(29) /* print() action */ #define DT_ACT_PRINTM DT_ACT(30) /* printm() action */ #define DT_ACT_PRINTT DT_ACT(31) /* printt() action */ /* * Sentinel to tell freopen() to restore the saved stdout. This must not * be ever valid for opening for write access via freopen(3C), which of * course, "." never is. */ #define DT_FREOPEN_RESTORE "." #define EDT_BASE 1000 /* base value for libdtrace errnos */ enum { EDT_VERSION = EDT_BASE, /* client is requesting unsupported version */ EDT_VERSINVAL, /* version string is invalid or overflows */ EDT_VERSUNDEF, /* requested API version is not defined */ EDT_VERSREDUCED, /* requested API version has been reduced */ EDT_CTF, /* libctf called failed (dt_ctferr has more) */ EDT_COMPILER, /* error in D program compilation */ EDT_NOTUPREG, /* tuple register allocation failure */ EDT_NOMEM, /* memory allocation failure */ EDT_INT2BIG, /* integer limit exceeded */ EDT_STR2BIG, /* string limit exceeded */ EDT_NOMOD, /* unknown module name */ EDT_NOPROV, /* unknown provider name */ EDT_NOPROBE, /* unknown probe name */ EDT_NOSYM, /* unknown symbol name */ EDT_NOSYMADDR, /* no symbol corresponds to address */ EDT_NOTYPE, /* unknown type name */ EDT_NOVAR, /* unknown variable name */ EDT_NOAGG, /* unknown aggregation name */ EDT_BADSCOPE, /* improper use of type name scoping operator */ EDT_BADSPEC, /* overspecified probe description */ EDT_BADSPCV, /* bad macro variable in probe description */ EDT_BADID, /* invalid probe identifier */ EDT_NOTLOADED, /* module is not currently loaded */ EDT_NOCTF, /* module does not contain any CTF data */ EDT_DATAMODEL, /* module and program data models don't match */ EDT_DIFVERS, /* library has newer DIF version than driver */ EDT_BADAGG, /* unrecognized aggregating action */ EDT_FIO, /* file i/o error */ EDT_DIFINVAL, /* invalid DIF program */ EDT_DIFSIZE, /* invalid DIF size */ EDT_DIFFAULT, /* failed to copyin DIF program */ EDT_BADPROBE, /* bad probe description */ EDT_BADPGLOB, /* bad probe description globbing pattern */ EDT_NOSCOPE, /* declaration scope stack underflow */ EDT_NODECL, /* declaration stack underflow */ EDT_DMISMATCH, /* record list does not match statement */ EDT_DOFFSET, /* record data offset error */ EDT_DALIGN, /* record data alignment error */ EDT_BADOPTNAME, /* invalid dtrace_setopt option name */ EDT_BADOPTVAL, /* invalid dtrace_setopt option value */ EDT_BADOPTCTX, /* invalid dtrace_setopt option context */ EDT_CPPFORK, /* failed to fork preprocessor */ EDT_CPPEXEC, /* failed to exec preprocessor */ EDT_CPPENT, /* preprocessor not found */ EDT_CPPERR, /* unknown preprocessor error */ EDT_SYMOFLOW, /* external symbol table overflow */ EDT_ACTIVE, /* operation illegal when tracing is active */ EDT_DESTRUCTIVE, /* destructive actions not allowed */ EDT_NOANON, /* no anonymous tracing state */ EDT_ISANON, /* can't claim anon state and enable probes */ EDT_ENDTOOBIG, /* END enablings exceed size of prncpl buffer */ EDT_NOCONV, /* failed to load type for printf conversion */ EDT_BADCONV, /* incomplete printf conversion */ EDT_BADERROR, /* invalid library ERROR action */ EDT_ERRABORT, /* abort due to error */ EDT_DROPABORT, /* abort due to drop */ EDT_DIRABORT, /* abort explicitly directed */ EDT_BADRVAL, /* invalid return value from callback */ EDT_BADNORMAL, /* invalid normalization */ EDT_BUFTOOSMALL, /* enabling exceeds size of buffer */ EDT_BADTRUNC, /* invalid truncation */ EDT_BUSY, /* device busy (active kernel debugger) */ EDT_ACCESS, /* insufficient privileges to use DTrace */ EDT_NOENT, /* dtrace device not available */ EDT_BRICKED, /* abort due to systemic unresponsiveness */ EDT_HARDWIRE, /* failed to load hard-wired definitions */ EDT_ELFVERSION, /* libelf is out-of-date w.r.t libdtrace */ EDT_NOBUFFERED, /* attempt to buffer output without handler */ EDT_UNSTABLE, /* description matched unstable set of probes */ EDT_BADSETOPT, /* invalid setopt library action */ EDT_BADSTACKPC, /* invalid stack program counter size */ EDT_BADAGGVAR, /* invalid aggregation variable identifier */ EDT_OVERSION, /* client is requesting deprecated version */ EDT_ENABLING_ERR, /* failed to enable probe */ EDT_NOPROBES, /* no probes sites for declared provider */ EDT_CANTLOAD /* failed to load a module */ }; /* * Interfaces for parsing and comparing DTrace attribute tuples, which describe * stability and architectural binding information. The dtrace_attribute_t * structure and associated constant definitions are found in . */ extern dtrace_attribute_t dt_attr_min(dtrace_attribute_t, dtrace_attribute_t); extern dtrace_attribute_t dt_attr_max(dtrace_attribute_t, dtrace_attribute_t); extern char *dt_attr_str(dtrace_attribute_t, char *, size_t); extern int dt_attr_cmp(dtrace_attribute_t, dtrace_attribute_t); /* * Interfaces for parsing and handling DTrace version strings. Version binding * is a feature of the D compiler that is handled completely independently of * the DTrace kernel infrastructure, so the definitions are here in libdtrace. * Version strings are compiled into an encoded uint32_t which can be compared * using C comparison operators. Version definitions are found in dt_open.c. */ #define DT_VERSION_STRMAX 16 /* enough for "255.4095.4095\0" */ #define DT_VERSION_MAJMAX 0xFF /* maximum major version number */ #define DT_VERSION_MINMAX 0xFFF /* maximum minor version number */ #define DT_VERSION_MICMAX 0xFFF /* maximum micro version number */ #define DT_VERSION_NUMBER(M, m, u) \ ((((M) & 0xFF) << 24) | (((m) & 0xFFF) << 12) | ((u) & 0xFFF)) #define DT_VERSION_MAJOR(v) (((v) & 0xFF000000) >> 24) #define DT_VERSION_MINOR(v) (((v) & 0x00FFF000) >> 12) #define DT_VERSION_MICRO(v) ((v) & 0x00000FFF) extern char *dt_version_num2str(dt_version_t, char *, size_t); extern int dt_version_str2num(const char *, dt_version_t *); extern int dt_version_defined(dt_version_t); /* * Miscellaneous internal libdtrace interfaces. The definitions below are for * libdtrace routines that do not yet merit their own separate header file. */ extern char *dt_cpp_add_arg(dtrace_hdl_t *, const char *); extern char *dt_cpp_pop_arg(dtrace_hdl_t *); #ifdef illumos extern int dt_set_errno(dtrace_hdl_t *, int); #else int _dt_set_errno(dtrace_hdl_t *, int, const char *, int); void dt_get_errloc(dtrace_hdl_t *, const char **, int *); #define dt_set_errno(_a,_b) _dt_set_errno(_a,_b,__FILE__,__LINE__) #endif extern void dt_set_errmsg(dtrace_hdl_t *, const char *, const char *, const char *, int, const char *, va_list); #ifdef illumos extern int dt_ioctl(dtrace_hdl_t *, int, void *); #else extern int dt_ioctl(dtrace_hdl_t *, u_long, void *); #endif extern int dt_status(dtrace_hdl_t *, processorid_t); extern long dt_sysconf(dtrace_hdl_t *, int); extern ssize_t dt_write(dtrace_hdl_t *, int, const void *, size_t); extern int dt_printf(dtrace_hdl_t *, FILE *, const char *, ...); extern void *dt_zalloc(dtrace_hdl_t *, size_t); extern void *dt_alloc(dtrace_hdl_t *, size_t); extern void dt_free(dtrace_hdl_t *, void *); extern void dt_difo_free(dtrace_hdl_t *, dtrace_difo_t *); extern int dt_gmatch(const char *, const char *); extern char *dt_basename(char *); extern ulong_t dt_popc(ulong_t); extern ulong_t dt_popcb(const ulong_t *, ulong_t); extern int dt_buffered_enable(dtrace_hdl_t *); extern int dt_buffered_flush(dtrace_hdl_t *, dtrace_probedata_t *, const dtrace_recdesc_t *, const dtrace_aggdata_t *, uint32_t flags); extern void dt_buffered_disable(dtrace_hdl_t *); extern void dt_buffered_destroy(dtrace_hdl_t *); extern uint64_t dt_stddev(uint64_t *, uint64_t); extern int dt_rw_read_held(pthread_rwlock_t *); extern int dt_rw_write_held(pthread_rwlock_t *); extern int dt_mutex_held(pthread_mutex_t *); extern int dt_options_load(dtrace_hdl_t *); #define DT_RW_READ_HELD(x) dt_rw_read_held(x) #define DT_RW_WRITE_HELD(x) dt_rw_write_held(x) #define DT_RW_LOCK_HELD(x) (DT_RW_READ_HELD(x) || DT_RW_WRITE_HELD(x)) #define DT_MUTEX_HELD(x) dt_mutex_held(x) extern void dt_dprintf(const char *, ...); extern void dt_setcontext(dtrace_hdl_t *, dtrace_probedesc_t *); extern void dt_endcontext(dtrace_hdl_t *); extern void dt_pragma(dt_node_t *); extern int dt_reduce(dtrace_hdl_t *, dt_version_t); extern void dt_cg(dt_pcb_t *, dt_node_t *); extern dtrace_difo_t *dt_as(dt_pcb_t *); extern void dt_dis(const dtrace_difo_t *, FILE *); extern int dt_aggregate_go(dtrace_hdl_t *); extern int dt_aggregate_init(dtrace_hdl_t *); extern void dt_aggregate_destroy(dtrace_hdl_t *); extern int dt_epid_lookup(dtrace_hdl_t *, dtrace_epid_t, dtrace_eprobedesc_t **, dtrace_probedesc_t **); extern void dt_epid_destroy(dtrace_hdl_t *); extern int dt_aggid_lookup(dtrace_hdl_t *, dtrace_aggid_t, dtrace_aggdesc_t **); extern void dt_aggid_destroy(dtrace_hdl_t *); extern void *dt_format_lookup(dtrace_hdl_t *, int); extern void dt_format_destroy(dtrace_hdl_t *); extern const char *dt_strdata_lookup(dtrace_hdl_t *, int); extern void dt_strdata_destroy(dtrace_hdl_t *); extern int dt_print_quantize(dtrace_hdl_t *, FILE *, const void *, size_t, uint64_t); extern int dt_print_lquantize(dtrace_hdl_t *, FILE *, const void *, size_t, uint64_t); extern int dt_print_llquantize(dtrace_hdl_t *, FILE *, const void *, size_t, uint64_t); extern int dt_print_agg(const dtrace_aggdata_t *, void *); extern int dt_handle(dtrace_hdl_t *, dtrace_probedata_t *); extern int dt_handle_liberr(dtrace_hdl_t *, const dtrace_probedata_t *, const char *); extern int dt_handle_cpudrop(dtrace_hdl_t *, processorid_t, dtrace_dropkind_t, uint64_t); extern int dt_handle_status(dtrace_hdl_t *, dtrace_status_t *, dtrace_status_t *); extern int dt_handle_setopt(dtrace_hdl_t *, dtrace_setoptdata_t *); extern int dt_lib_depend_add(dtrace_hdl_t *, dt_list_t *, const char *); extern dt_lib_depend_t *dt_lib_depend_lookup(dt_list_t *, const char *); extern dt_pcb_t *yypcb; /* pointer to current parser control block */ extern char yyintprefix; /* int token prefix for macros (+/-) */ extern char yyintsuffix[4]; /* int token suffix ([uUlL]*) */ extern int yyintdecimal; /* int token is decimal (1) or octal/hex (0) */ extern char yytext[]; /* lex input buffer */ extern int yylineno; /* lex line number */ extern int yydebug; /* lex debugging */ extern dt_node_t *yypragma; /* lex token list for control lines */ extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */ extern const dtrace_attribute_t _dtrace_defattr; /* default attributes */ extern const dtrace_attribute_t _dtrace_symattr; /* symbol ref attributes */ extern const dtrace_attribute_t _dtrace_typattr; /* type ref attributes */ extern const dtrace_attribute_t _dtrace_prvattr; /* provider attributes */ extern const dtrace_pattr_t _dtrace_prvdesc; /* provider attribute bundle */ extern const dt_version_t _dtrace_versions[]; /* array of valid versions */ extern const char *const _dtrace_version; /* current version string */ extern int _dtrace_strbuckets; /* number of hash buckets for strings */ extern int _dtrace_intbuckets; /* number of hash buckets for ints */ extern uint_t _dtrace_stkindent; /* default indent for stack/ustack */ extern uint_t _dtrace_pidbuckets; /* number of hash buckets for pids */ extern uint_t _dtrace_pidlrulim; /* number of proc handles to cache */ extern int _dtrace_debug; /* debugging messages enabled */ extern size_t _dtrace_bufsize; /* default dt_buf_create() size */ extern int _dtrace_argmax; /* default maximum probe arguments */ extern const char *_dtrace_libdir; /* default library directory */ extern const char *_dtrace_moddir; /* default kernel module directory */ #ifdef __FreeBSD__ extern int gmatch(const char *, const char *); extern int yylex(void); #endif #ifdef __cplusplus } #endif #endif /* _DT_IMPL_H */ Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c (revision 304200) @@ -1,1742 +1,1744 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2012, 2016 by Delphix. All rights reserved. */ #include #ifdef illumos #include #include #else #include #include #include #endif #include #include #include #ifdef illumos #include #endif #include #include #include #include #include #include #include #define _POSIX_PTHREAD_SEMANTICS #include #undef _POSIX_PTHREAD_SEMANTICS #include #include #include #include #include #include #ifndef illumos #include #include #endif #if defined(__i386__) #include #endif /* * Stability and versioning definitions. These #defines are used in the tables * of identifiers below to fill in the attribute and version fields associated * with each identifier. The DT_ATTR_* macros are a convenience to permit more * concise declarations of common attributes such as Stable/Stable/Common. The * DT_VERS_* macros declare the encoded integer values of all versions used so * far. DT_VERS_LATEST must correspond to the latest version value among all * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta). * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, * and then add the new version to the _dtrace_versions[] array declared below. * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters * respectively for an explanation of these DTrace features and their values. * * NOTE: Although the DTrace versioning scheme supports the labeling and * introduction of incompatible changes (e.g. dropping an interface in a * major release), the libdtrace code does not currently support this. * All versions are assumed to strictly inherit from one another. If * we ever need to provide divergent interfaces, this will need work. */ #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \ DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON } #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \ DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \ } /* * The version number should be increased for every customer visible release * of DTrace. The major number should be incremented when a fundamental * change has been made that would affect all consumers, and would reflect * sweeping changes to DTrace or the D language. The minor number should be * incremented when a change is introduced that could break scripts that had * previously worked; for example, adding a new built-in variable could break * a script which was already using that identifier. The micro number should * be changed when introducing functionality changes or major bug fixes that * do not affect backward compatibility -- this is merely to make capabilities * easily determined from the version number. Minor bugs do not require any * modification to the version number. */ #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0) #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0) #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0) #define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1) #define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2) #define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0) #define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0) #define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1) #define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0) #define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0) #define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1) #define DT_VERS_1_6_2 DT_VERSION_NUMBER(1, 6, 2) #define DT_VERS_1_6_3 DT_VERSION_NUMBER(1, 6, 3) #define DT_VERS_1_7 DT_VERSION_NUMBER(1, 7, 0) #define DT_VERS_1_7_1 DT_VERSION_NUMBER(1, 7, 1) #define DT_VERS_1_8 DT_VERSION_NUMBER(1, 8, 0) #define DT_VERS_1_8_1 DT_VERSION_NUMBER(1, 8, 1) #define DT_VERS_1_9 DT_VERSION_NUMBER(1, 9, 0) #define DT_VERS_1_9_1 DT_VERSION_NUMBER(1, 9, 1) #define DT_VERS_1_10 DT_VERSION_NUMBER(1, 10, 0) #define DT_VERS_1_11 DT_VERSION_NUMBER(1, 11, 0) #define DT_VERS_1_12 DT_VERSION_NUMBER(1, 12, 0) #define DT_VERS_1_12_1 DT_VERSION_NUMBER(1, 12, 1) -#define DT_VERS_LATEST DT_VERS_1_12_1 -#define DT_VERS_STRING "Sun D 1.12.1" +#define DT_VERS_1_13 DT_VERSION_NUMBER(1, 13, 0) +#define DT_VERS_LATEST DT_VERS_1_13 +#define DT_VERS_STRING "Sun D 1.13" const dt_version_t _dtrace_versions[] = { DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */ DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */ DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */ DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */ DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */ DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */ DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */ DT_VERS_1_5, /* D API 1.5 Solaris Express 7/07 */ DT_VERS_1_6, /* D API 1.6 */ DT_VERS_1_6_1, /* D API 1.6.1 */ DT_VERS_1_6_2, /* D API 1.6.2 */ DT_VERS_1_6_3, /* D API 1.6.3 */ DT_VERS_1_7, /* D API 1.7 */ DT_VERS_1_7_1, /* D API 1.7.1 */ DT_VERS_1_8, /* D API 1.8 */ DT_VERS_1_8_1, /* D API 1.8.1 */ DT_VERS_1_9, /* D API 1.9 */ DT_VERS_1_9_1, /* D API 1.9.1 */ DT_VERS_1_10, /* D API 1.10 */ DT_VERS_1_11, /* D API 1.11 */ DT_VERS_1_12, /* D API 1.12 */ DT_VERS_1_12_1, /* D API 1.12.1 */ + DT_VERS_1_13, /* D API 1.13 */ 0 }; /* * Global variables that are formatted on FreeBSD based on the kernel file name. */ #ifndef illumos static char curthread_str[MAXPATHLEN]; static char intmtx_str[MAXPATHLEN]; static char threadmtx_str[MAXPATHLEN]; static char rwlock_str[MAXPATHLEN]; static char sxlock_str[MAXPATHLEN]; #endif /* * Table of global identifiers. This is used to populate the global identifier * hash when a new dtrace client open occurs. For more info see dt_ident.h. * The global identifiers that represent functions use the dt_idops_func ops * and specify the private data pointer as a prototype string which is parsed * when the identifier is first encountered. These prototypes look like ANSI * C function prototypes except that the special symbol "@" can be used as a * wildcard to represent a single parameter of any type (i.e. any dt_node_t). * The standard "..." notation can also be used to represent varargs. An empty * parameter list is taken to mean void (that is, no arguments are permitted). * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional * argument. */ static const dt_ident_t _dtrace_globals[] = { { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void *(size_t)" }, { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_args, NULL }, { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(void *, void *, size_t)" }, { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uintptr_t" }, { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void *(uintptr_t, size_t)" }, { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(uintptr_t, [size_t])" }, { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" }, { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(void *, uintptr_t, size_t)" }, { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(char *, uintptr_t, size_t)" }, { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD, { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_COMMON }, DT_VERS_1_0, #ifdef illumos &dt_idops_type, "genunix`kthread_t *" }, #else &dt_idops_type, curthread_str }, #endif { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "string(void *, int64_t)" }, { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, { "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int" }, { "execargs", DT_IDENT_SCALAR, 0, DIF_VAR_EXECARGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "void(@, ...)" }, { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint32_t(uint32_t)" }, { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint64_t(uint64_t)" }, { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint16_t(uint16_t)" }, { "getf", DT_IDENT_FUNC, 0, DIF_SUBR_GETF, DT_ATTR_STABCMN, DT_VERS_1_10, &dt_idops_func, "file_t *(int)" }, { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "gid_t" }, { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "int(const char *, const char *, [int])" }, { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN, #ifdef illumos DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" }, #else DT_VERS_1_5, &dt_idops_func, "string(in_addr_t *)" }, #endif { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN, #ifdef illumos DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" }, #else DT_VERS_1_5, &dt_idops_func, "string(struct in6_addr *)" }, #endif { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN, DT_VERS_1_5, &dt_idops_func, "string(int, void *)" }, { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint_t" }, { "json", DT_IDENT_FUNC, 0, DIF_SUBR_JSON, DT_ATTR_STABCMN, DT_VERS_1_11, &dt_idops_func, "string(const char *, const char *)" }, { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(int64_t, [int])" }, { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_7, &dt_idops_func, "void(@, int32_t, int32_t, int32_t, int32_t, ...)" }, { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, int32_t, int32_t, ...)" }, { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "memref", DT_IDENT_FUNC, 0, DIF_SUBR_MEMREF, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "uintptr_t *(void *, size_t)" }, #ifndef illumos { "memstr", DT_IDENT_FUNC, 0, DIF_SUBR_MEMSTR, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(void *, char, size_t)" }, #endif { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(mblk_t *)" }, { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(mblk_t *)" }, #ifdef illumos { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" }, { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`kmutex_t *)" }, #else { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, threadmtx_str }, { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, intmtx_str }, #endif { "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint32_t(uint32_t)" }, { "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint64_t(uint64_t)" }, { "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint16_t(uint16_t)" }, { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "pid_t" }, { "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "pid_t" }, { "print", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINT, DT_ATTR_STABCMN, DT_VERS_1_9, &dt_idops_func, "void(@)" }, { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "printm", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(size_t, uintptr_t *)" }, { "printt", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTT, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(size_t, uintptr_t *)" }, { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int(pid_t)" }, { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int()" }, { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "int(const char *, const char *, [int])" }, #ifdef illumos { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, "int(genunix`krwlock_t *)" }, #else { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, rwlock_str }, #endif { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "void" }, { "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" }, { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(int)" }, { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int()" }, { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint32_t" }, { "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN, DT_VERS_1_6, &dt_idops_func, "void(@)" }, { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void()" }, { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, char)" }, { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "size_t(const char *)" }, { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "string(const char *, const char *)" }, { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, char)" }, { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, const char *)" }, { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, const char *)" }, { "strtoll", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOLL, DT_ATTR_STABCMN, DT_VERS_1_11, &dt_idops_func, "int64_t(const char *, [int])" }, { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "string(const char *, int, [int])" }, { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, #ifndef illumos { "sx_isexclusive", DT_IDENT_FUNC, 0, DIF_SUBR_SX_ISEXCLUSIVE, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, { "sx_shared_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_SHARED_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, { "sx_exclusive_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_EXCLUSIVE_HELD, DT_ATTR_EVOLCMN, DT_VERS_1_0, &dt_idops_func, sxlock_str }, #endif { "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, ...)" }, { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "void" }, { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "id_t" }, { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint64_t" }, { "tolower", DT_IDENT_FUNC, 0, DIF_SUBR_TOLOWER, DT_ATTR_STABCMN, DT_VERS_1_8, &dt_idops_func, "string(const char *)" }, { "toupper", DT_IDENT_FUNC, 0, DIF_SUBR_TOUPPER, DT_ATTR_STABCMN, DT_VERS_1_8, &dt_idops_func, "string(const char *)" }, { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@)" }, { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(@, size_t, ...)" }, { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "void(...)" }, { "typeref", DT_IDENT_FUNC, 0, DIF_SUBR_TYPEREF, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "uintptr_t *(void *, size_t, string, size_t)" }, { "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_type, "uint64_t" }, { "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uid_t" }, { "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_regs, NULL }, { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "stack(...)" }, { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_type, "uint32_t" }, { "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "uint64_t" }, { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "int64_t" }, #ifdef illumos { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, #endif #ifndef illumos { "cpu", DT_IDENT_SCALAR, 0, DIF_VAR_CPU, DT_ATTR_STABCMN, DT_VERS_1_6_3, &dt_idops_type, "int" }, #endif { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } }; /* * Tables of ILP32 intrinsic integer and floating-point type templates to use * to populate the dynamic "C" CTF type container. */ static const dt_intrinsic_t _dtrace_intrinsics_32[] = { { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, { NULL, { 0, 0, 0 }, 0 } }; /* * Tables of LP64 intrinsic integer and floating-point type templates to use * to populate the dynamic "C" CTF type container. */ static const dt_intrinsic_t _dtrace_intrinsics_64[] = { { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER }, { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, { NULL, { 0, 0, 0 }, 0 } }; /* * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container. * These aliases ensure that D definitions can use typical names. */ static const dt_typedef_t _dtrace_typedefs_32[] = { { "char", "int8_t" }, { "short", "int16_t" }, { "int", "int32_t" }, { "long long", "int64_t" }, { "int", "intptr_t" }, { "int", "ssize_t" }, { "unsigned char", "uint8_t" }, { "unsigned short", "uint16_t" }, { "unsigned", "uint32_t" }, { "unsigned long long", "uint64_t" }, { "unsigned char", "uchar_t" }, { "unsigned short", "ushort_t" }, { "unsigned", "uint_t" }, { "unsigned long", "ulong_t" }, { "unsigned long long", "u_longlong_t" }, { "int", "ptrdiff_t" }, { "unsigned", "uintptr_t" }, { "unsigned", "size_t" }, { "long", "id_t" }, { "long", "pid_t" }, { NULL, NULL } }; /* * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container. * These aliases ensure that D definitions can use typical names. */ static const dt_typedef_t _dtrace_typedefs_64[] = { { "char", "int8_t" }, { "short", "int16_t" }, { "int", "int32_t" }, { "long", "int64_t" }, { "long", "intptr_t" }, { "long", "ssize_t" }, { "unsigned char", "uint8_t" }, { "unsigned short", "uint16_t" }, { "unsigned", "uint32_t" }, { "unsigned long", "uint64_t" }, { "unsigned char", "uchar_t" }, { "unsigned short", "ushort_t" }, { "unsigned", "uint_t" }, { "unsigned long", "ulong_t" }, { "unsigned long long", "u_longlong_t" }, { "long", "ptrdiff_t" }, { "unsigned long", "uintptr_t" }, { "unsigned long", "size_t" }, { "int", "id_t" }, { "int", "pid_t" }, { NULL, NULL } }; /* * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[] * cache when a new dtrace client open occurs. Values are set by dtrace_open(). */ static const dt_intdesc_t _dtrace_ints_32[] = { { "int", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, { "long", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned long", NULL, CTF_ERR, 0xffffffffULL }, { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } }; /* * Tables of LP64 integer type templates used to populate the dtp->dt_ints[] * cache when a new dtrace client open occurs. Values are set by dtrace_open(). */ static const dt_intdesc_t _dtrace_ints_64[] = { { "int", NULL, CTF_ERR, 0x7fffffffULL }, { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL }, { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } }; /* * Table of macro variable templates used to populate the macro identifier hash * when a new dtrace client open occurs. Values are set by dtrace_update(). */ static const dt_ident_t _dtrace_macros[] = { { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, { NULL, 0, 0, 0, { 0, 0, 0 }, 0 } }; /* * Hard-wired definition string to be compiled and cached every time a new * DTrace library handle is initialized. This string should only be used to * contain definitions that should be present regardless of DTRACE_O_NOLIBS. */ static const char _dtrace_hardwire[] = "\ inline long NULL = 0; \n\ #pragma D binding \"1.0\" NULL\n\ "; /* * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV. * If DTRACE_O_NODEV is not set, we load the configuration from the kernel. * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are * relying on the fact that when running dtrace(1M), isaexec will invoke the * binary with the same bitness as the kernel, which is what we want by default * when generating our DIF. The user can override the choice using oflags. */ static const dtrace_conf_t _dtrace_conf = { DIF_VERSION, /* dtc_difversion */ DIF_DIR_NREGS, /* dtc_difintregs */ DIF_DTR_NREGS, /* dtc_diftupregs */ CTF_MODEL_NATIVE /* dtc_ctfmodel */ }; const dtrace_attribute_t _dtrace_maxattr = { DTRACE_STABILITY_MAX, DTRACE_STABILITY_MAX, DTRACE_CLASS_MAX }; const dtrace_attribute_t _dtrace_defattr = { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }; const dtrace_attribute_t _dtrace_symattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_attribute_t _dtrace_typattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_attribute_t _dtrace_prvattr = { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }; const dtrace_pattr_t _dtrace_prvdesc = { { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, }; #ifdef illumos const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ #else const char *_dtrace_defcpp = "cpp"; /* default cpp(1) to invoke */ const char *_dtrace_defld = "ld"; /* default ld(1) to invoke */ const char *_dtrace_defobjcopy = "objcopy"; /* default objcopy(1) to invoke */ #endif const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ #ifdef illumos const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */ #else const char *_dtrace_libdir32 = "/usr/lib32/dtrace"; const char *_dtrace_provdir = "/dev/dtrace"; /* provider directory */ #endif int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */ int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */ uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */ uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */ uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */ uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */ size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */ int _dtrace_argmax = 32; /* default maximum number of probe arguments */ int _dtrace_debug = 0; /* debug messages enabled (off) */ const char *const _dtrace_version = DT_VERS_STRING; /* API version string */ int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */ typedef struct dt_fdlist { int *df_fds; /* array of provider driver file descriptors */ uint_t df_ents; /* number of valid elements in df_fds[] */ uint_t df_size; /* size of df_fds[] */ } dt_fdlist_t; #ifdef illumos #pragma init(_dtrace_init) #else void _dtrace_init(void) __attribute__ ((constructor)); #endif void _dtrace_init(void) { _dtrace_debug = getenv("DTRACE_DEBUG") != NULL; for (; _dtrace_rdvers > 0; _dtrace_rdvers--) { if (rd_init(_dtrace_rdvers) == RD_OK) break; } #if defined(__i386__) /* make long doubles 64 bits -sson */ (void) fpsetprec(FP_PE); #endif } static dtrace_hdl_t * set_open_errno(dtrace_hdl_t *dtp, int *errp, int err) { if (dtp != NULL) dtrace_close(dtp); if (errp != NULL) *errp = err; return (NULL); } static void dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp) { dt_provmod_t *prov; char path[PATH_MAX]; int fd; #ifdef illumos struct dirent *dp, *ep; DIR *dirp; if ((dirp = opendir(_dtrace_provdir)) == NULL) return; /* failed to open directory; just skip it */ ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { if (dp->d_name[0] == '.') continue; /* skip "." and ".." */ if (dfp->df_ents == dfp->df_size) { uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; int *fds = realloc(dfp->df_fds, size * sizeof (int)); if (fds == NULL) break; /* skip the rest of this directory */ dfp->df_fds = fds; dfp->df_size = size; } (void) snprintf(path, sizeof (path), "%s/%s", _dtrace_provdir, dp->d_name); if ((fd = open(path, O_RDONLY)) == -1) continue; /* failed to open driver; just skip it */ if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { free(prov); (void) close(fd); break; } (void) strcpy(prov->dp_name, dp->d_name); prov->dp_next = *provmod; *provmod = prov; dt_dprintf("opened provider %s\n", dp->d_name); dfp->df_fds[dfp->df_ents++] = fd; } (void) closedir(dirp); #else /* !illumos */ char *p; char *p1; char *p_providers = NULL; int error; size_t len = 0; /* * Loop to allocate/reallocate memory for the string of provider * names and retry: */ while(1) { /* * The first time around, get the string length. The next time, * hopefully we've allocated enough memory. */ error = sysctlbyname("debug.dtrace.providers",p_providers,&len,NULL,0); if (len == 0) /* No providers? That's strange. Where's dtrace? */ break; else if (error == 0 && p_providers == NULL) { /* * Allocate the initial memory which should be enough * unless another provider loads before we have * time to go back and get the string. */ if ((p_providers = malloc(len)) == NULL) /* How do we report errors here? */ return; } else if (error == -1 && errno == ENOMEM) { /* * The current buffer isn't large enough, so * reallocate it. We normally won't need to do this * because providers aren't being loaded all the time. */ if ((p = realloc(p_providers,len)) == NULL) /* How do we report errors here? */ return; p_providers = p; } else break; } /* Check if we got a string of provider names: */ if (error == 0 && len > 0 && p_providers != NULL) { p = p_providers; /* * Parse the string containing the space separated * provider names. */ while ((p1 = strsep(&p," ")) != NULL) { if (dfp->df_ents == dfp->df_size) { uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; int *fds = realloc(dfp->df_fds, size * sizeof (int)); if (fds == NULL) break; dfp->df_fds = fds; dfp->df_size = size; } (void) snprintf(path, sizeof (path), "/dev/dtrace/%s", p1); if ((fd = open(path, O_RDONLY)) == -1) continue; /* failed to open driver; just skip it */ if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || (prov->dp_name = malloc(strlen(p1) + 1)) == NULL) { free(prov); (void) close(fd); break; } (void) strcpy(prov->dp_name, p1); prov->dp_next = *provmod; *provmod = prov; dt_dprintf("opened provider %s\n", p1); dfp->df_fds[dfp->df_ents++] = fd; } } if (p_providers != NULL) free(p_providers); #endif /* illumos */ } static void dt_provmod_destroy(dt_provmod_t **provmod) { dt_provmod_t *next, *current; for (current = *provmod; current != NULL; current = next) { next = current->dp_next; free(current->dp_name); free(current); } *provmod = NULL; } #ifdef illumos static const char * dt_get_sysinfo(int cmd, char *buf, size_t len) { ssize_t rv = sysinfo(cmd, buf, len); char *p = buf; if (rv < 0 || rv > len) (void) snprintf(buf, len, "%s", "Unknown"); while ((p = strchr(p, '.')) != NULL) *p++ = '_'; return (buf); } #endif static dtrace_hdl_t * dt_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) { dtrace_hdl_t *dtp = NULL; int dtfd = -1, ftfd = -1, fterr = 0; dtrace_prog_t *pgp; dt_module_t *dmp; dt_provmod_t *provmod = NULL; int i, err; struct rlimit rl; const dt_intrinsic_t *dinp; const dt_typedef_t *dtyp; const dt_ident_t *idp; dtrace_typeinfo_t dtt; ctf_funcinfo_t ctc; ctf_arinfo_t ctr; dt_fdlist_t df = { NULL, 0, 0 }; char isadef[32], utsdef[32]; char s1[64], s2[64]; if (version <= 0) return (set_open_errno(dtp, errp, EINVAL)); if (version > DTRACE_VERSION) return (set_open_errno(dtp, errp, EDT_VERSION)); if (version < DTRACE_VERSION) { /* * Currently, increasing the library version number is used to * denote a binary incompatible change. That is, a consumer * of the library cannot run on a version of the library with * a higher DTRACE_VERSION number than the consumer compiled * against. Once the library API has been committed to, * backwards binary compatibility will be required; at that * time, this check should change to return EDT_OVERSION only * if the specified version number is less than the version * number at the time of interface commitment. */ return (set_open_errno(dtp, errp, EDT_OVERSION)); } if (flags & ~DTRACE_O_MASK) return (set_open_errno(dtp, errp, EINVAL)); if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) return (set_open_errno(dtp, errp, EINVAL)); if (vector == NULL && arg != NULL) return (set_open_errno(dtp, errp, EINVAL)); if (elf_version(EV_CURRENT) == EV_NONE) return (set_open_errno(dtp, errp, EDT_ELFVERSION)); if (vector != NULL || (flags & DTRACE_O_NODEV)) goto alloc; /* do not attempt to open dtrace device */ /* * Before we get going, crank our limit on file descriptors up to the * hard limit. This is to allow for the fact that libproc keeps file * descriptors to objects open for the lifetime of the proc handle; * without raising our hard limit, we would have an acceptably small * bound on the number of processes that we could concurrently * instrument with the pid provider. */ if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { rl.rlim_cur = rl.rlim_max; (void) setrlimit(RLIMIT_NOFILE, &rl); } /* * Get the device path of each of the providers. We hold them open * in the df.df_fds list until we open the DTrace driver itself, * allowing us to see all of the probes provided on this system. Once * we have the DTrace driver open, we can safely close all the providers * now that they have registered with the framework. */ dt_provmod_open(&provmod, &df); dtfd = open("/dev/dtrace/dtrace", O_RDWR); err = errno; /* save errno from opening dtfd */ #if defined(__FreeBSD__) /* * Automatically load the 'dtraceall' module if we couldn't open the * char device. */ if (err == ENOENT && modfind("dtraceall") < 0) { kldload("dtraceall"); /* ignore the error */ dtfd = open("/dev/dtrace/dtrace", O_RDWR); err = errno; } #endif #ifdef illumos ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR); #else ftfd = open("/dev/dtrace/fasttrap", O_RDWR); #endif fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ while (df.df_ents-- != 0) (void) close(df.df_fds[df.df_ents]); free(df.df_fds); /* * If we failed to open the dtrace device, fail dtrace_open(). * We convert some kernel errnos to custom libdtrace errnos to * improve the resulting message from the usual strerror(). */ if (dtfd == -1) { dt_provmod_destroy(&provmod); switch (err) { case ENOENT: err = EDT_NOENT; break; case EBUSY: err = EDT_BUSY; break; case EACCES: err = EDT_ACCESS; break; } return (set_open_errno(dtp, errp, err)); } (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); alloc: if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); bzero(dtp, sizeof (dtrace_hdl_t)); dtp->dt_oflags = flags; #ifdef illumos dtp->dt_prcmode = DT_PROC_STOP_PREINIT; #else dtp->dt_prcmode = DT_PROC_STOP_POSTINIT; #endif dtp->dt_linkmode = DT_LINK_KERNEL; dtp->dt_linktype = DT_LTYP_ELF; dtp->dt_xlatemode = DT_XL_STATIC; dtp->dt_stdcmode = DT_STDC_XA; dtp->dt_encoding = DT_ENCODING_UNSET; dtp->dt_version = version; dtp->dt_fd = dtfd; dtp->dt_ftfd = ftfd; dtp->dt_fterr = fterr; dtp->dt_cdefs_fd = -1; dtp->dt_ddefs_fd = -1; #ifdef illumos dtp->dt_stdout_fd = -1; #else dtp->dt_freopen_fp = NULL; #endif dtp->dt_modbuckets = _dtrace_strbuckets; dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); #ifdef __FreeBSD__ dtp->dt_kmods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); #endif dtp->dt_provbuckets = _dtrace_strbuckets; dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); dt_proc_hash_create(dtp); dtp->dt_vmax = DT_VERS_LATEST; dtp->dt_cpp_path = strdup(_dtrace_defcpp); dtp->dt_cpp_argv = malloc(sizeof (char *)); dtp->dt_cpp_argc = 1; dtp->dt_cpp_args = 1; dtp->dt_ld_path = strdup(_dtrace_defld); #ifdef __FreeBSD__ dtp->dt_objcopy_path = strdup(_dtrace_defobjcopy); #endif dtp->dt_provmod = provmod; dtp->dt_vector = vector; dtp->dt_varg = arg; dt_dof_init(dtp); (void) uname(&dtp->dt_uts); if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || #ifdef __FreeBSD__ dtp->dt_kmods == NULL || dtp->dt_objcopy_path == NULL || #endif dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); for (i = 0; i < DTRACEOPT_MAX; i++) dtp->dt_options[i] = DTRACEOPT_UNSET; dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); #ifdef illumos (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", (uint_t)(sizeof (void *) * NBBY)); (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || dt_cpp_add_arg(dtp, "-D__unix") == NULL || dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || dt_cpp_add_arg(dtp, isadef) == NULL || dt_cpp_add_arg(dtp, utsdef) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); #endif if (flags & DTRACE_O_NODEV) bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) return (set_open_errno(dtp, errp, errno)); if (flags & DTRACE_O_LP64) dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; else if (flags & DTRACE_O_ILP32) dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; #ifdef __sparc /* * On SPARC systems, __sparc is always defined for * and __sparcv9 is defined if we are doing a 64-bit compile. */ if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); #endif #ifdef illumos #ifdef __x86 /* * On x86 systems, __i386 is defined for for 32-bit * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, * they are defined exclusive of one another (see PSARC 2004/619). */ if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } else { if (dt_cpp_add_arg(dtp, "-D__i386") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } #endif #else #if defined(__amd64__) || defined(__i386__) if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { if (dt_cpp_add_arg(dtp, "-m64") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } else { if (dt_cpp_add_arg(dtp, "-m32") == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } #endif #endif if (dtp->dt_conf.dtc_difversion < DIF_VERSION) return (set_open_errno(dtp, errp, EDT_DIFVERS)); if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); else bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); /* * On FreeBSD the kernel module name can't be hard-coded. The * 'kern.bootfile' sysctl value tells us exactly which file is being * used as the kernel. */ #ifndef illumos { char bootfile[MAXPATHLEN]; char *p; int i; size_t len = sizeof(bootfile); /* This call shouldn't fail, but use a default just in case. */ if (sysctlbyname("kern.bootfile", bootfile, &len, NULL, 0) != 0) strlcpy(bootfile, "kernel", sizeof(bootfile)); if ((p = strrchr(bootfile, '/')) != NULL) p++; else p = bootfile; /* * Format the global variables based on the kernel module name. */ snprintf(curthread_str, sizeof(curthread_str), "%s`struct thread *",p); snprintf(intmtx_str, sizeof(intmtx_str), "int(%s`struct mtx *)",p); snprintf(threadmtx_str, sizeof(threadmtx_str), "struct thread *(%s`struct mtx *)",p); snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`struct rwlock *)",p); snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)",p); } #endif dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); dtp->dt_aggs = dt_idhash_create("aggregation", NULL, DTRACE_AGGVARIDNONE + 1, UINT_MAX); dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); dtp->dt_tls = dt_idhash_create("thread local", NULL, DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || dtp->dt_globals == NULL || dtp->dt_tls == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); /* * Populate the dt_macros identifier hash table by hand: we can't use * the dt_idhash_populate() mechanism because we're not yet compiling * and dtrace_update() needs to immediately reference these idents. */ for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { if (dt_idhash_insert(dtp->dt_macros, idp->di_name, idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, idp->di_iarg, 0) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); } /* * Update the module list using /system/object and load the values for * the macro variable definitions according to the current process. */ dtrace_update(dtp); /* * Select the intrinsics and typedefs we want based on the data model. * The intrinsics are under "C". The typedefs are added under "D". */ if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { dinp = _dtrace_intrinsics_32; dtyp = _dtrace_typedefs_32; } else { dinp = _dtrace_intrinsics_64; dtyp = _dtrace_typedefs_64; } /* * Create a dynamic CTF container under the "C" scope for intrinsic * types and types defined in ANSI-C header files that are included. */ if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) return (set_open_errno(dtp, errp, EDT_CTF)); dt_dprintf("created CTF container for %s (%p)\n", dmp->dm_name, (void *)dmp->dm_ctfp); (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); ctf_setspecific(dmp->dm_ctfp, dmp); dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ dmp->dm_modid = -1; /* no module ID */ /* * Fill the dynamic "C" CTF container with all of the intrinsic * integer and floating-point types appropriate for this data model. */ for (; dinp->din_name != NULL; dinp++) { if (dinp->din_kind == CTF_K_INTEGER) { err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, dinp->din_name, &dinp->din_data); } else { err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, dinp->din_name, &dinp->din_data); } if (err == CTF_ERR) { dt_dprintf("failed to add %s to C container: %s\n", dinp->din_name, ctf_errmsg( ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } } if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed to update C container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Add intrinsic pointer types that are needed to initialize printf * format dictionary types (see table in dt_printf.c). */ (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "void")); (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "char")); (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, ctf_lookup_by_name(dmp->dm_ctfp, "int")); if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed to update C container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Create a dynamic CTF container under the "D" scope for types that * are defined by the D program itself or on-the-fly by the D compiler. * The "D" CTF container is a child of the "C" CTF container. */ if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) return (set_open_errno(dtp, errp, EDT_NOMEM)); if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) return (set_open_errno(dtp, errp, EDT_CTF)); dt_dprintf("created CTF container for %s (%p)\n", dmp->dm_name, (void *)dmp->dm_ctfp); (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); ctf_setspecific(dmp->dm_ctfp, dmp); dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ dmp->dm_modid = -1; /* no module ID */ if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { dt_dprintf("failed to import D parent container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Fill the dynamic "D" CTF container with all of the built-in typedefs * that we need to use for our D variable and function definitions. * This ensures that basic inttypes.h names are always available to us. */ for (; dtyp->dty_src != NULL; dtyp++) { if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, dtyp->dty_src)) == CTF_ERR) { dt_dprintf("failed to add typedef %s %s to D " "container: %s", dtyp->dty_src, dtyp->dty_dst, ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } } /* * Insert a CTF ID corresponding to a pointer to a type of kind * CTF_K_FUNCTION we can use in the compiler for function pointers. * CTF treats all function pointers as "int (*)()" so we only need one. */ ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); ctc.ctc_argc = 0; ctc.ctc_flags = 0; dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, CTF_ADD_ROOT, &ctc, NULL); dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, dtp->dt_type_func); /* * We also insert CTF definitions for the special D intrinsic types * string and into the D container. The string type is added * as a typedef of char[n]. The type is an alias for void. * We compare types to these special CTF ids throughout the compiler. */ ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); ctr.ctr_nelems = _dtrace_strsize; dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR || dtp->dt_type_usymaddr == CTF_ERR) { dt_dprintf("failed to add intrinsic to D container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } if (ctf_update(dmp->dm_ctfp) != 0) { dt_dprintf("failed update D container: %s\n", ctf_errmsg(ctf_errno(dmp->dm_ctfp))); return (set_open_errno(dtp, errp, EDT_CTF)); } /* * Initialize the integer description table used to convert integer * constants to the appropriate types. Refer to the comments above * dt_node_int() for a complete description of how this table is used. */ for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, dtp->dt_ints[i].did_name, &dtt) != 0) { dt_dprintf("failed to lookup integer type %s: %s\n", dtp->dt_ints[i].did_name, dtrace_errmsg(dtp, dtrace_errno(dtp))); return (set_open_errno(dtp, errp, dtp->dt_errno)); } dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; dtp->dt_ints[i].did_type = dtt.dtt_type; } /* * Now that we've created the "C" and "D" containers, move them to the * start of the module list so that these types and symbols are found * first (for stability) when iterating through the module list. */ dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); if (dt_pfdict_create(dtp) == -1) return (set_open_errno(dtp, errp, dtp->dt_errno)); /* * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default * because without /dev/dtrace open, we will not be able to load the * names and attributes of any providers or probes from the kernel. */ if (flags & DTRACE_O_NODEV) dtp->dt_cflags |= DTRACE_C_ZDEFS; /* * Load hard-wired inlines into the definition cache by calling the * compiler on the raw definition string defined above. */ if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { dt_dprintf("failed to load hard-wired definitions: %s\n", dtrace_errmsg(dtp, dtrace_errno(dtp))); return (set_open_errno(dtp, errp, EDT_HARDWIRE)); } dt_program_destroy(dtp, pgp); /* * Set up the default DTrace library path. Once set, the next call to * dt_compile() will compile all the libraries. We intentionally defer * library processing to improve overhead for clients that don't ever * compile, and to provide better error reporting (because the full * reporting of compiler errors requires dtrace_open() to succeed). */ #ifdef __FreeBSD__ #ifdef __LP64__ if ((dtp->dt_oflags & DTRACE_O_ILP32) != 0) { if (dtrace_setopt(dtp, "libdir", _dtrace_libdir32) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); } #endif if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); #else if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); #endif return (dtp); } dtrace_hdl_t * dtrace_open(int version, int flags, int *errp) { return (dt_vopen(version, flags, errp, NULL, NULL)); } dtrace_hdl_t * dtrace_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) { return (dt_vopen(version, flags, errp, vector, arg)); } void dtrace_close(dtrace_hdl_t *dtp) { dt_ident_t *idp, *ndp; dt_module_t *dmp; dt_provider_t *pvp; dtrace_prog_t *pgp; dt_xlator_t *dxp; dt_dirpath_t *dirp; #ifdef __FreeBSD__ dt_kmodule_t *dkm; uint_t h; #endif int i; if (dtp->dt_procs != NULL) dt_proc_hash_destroy(dtp); while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) dt_program_destroy(dtp, pgp); while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) dt_xlator_destroy(dtp, dxp); dt_free(dtp, dtp->dt_xlatormap); for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { ndp = idp->di_next; dt_ident_destroy(idp); } if (dtp->dt_macros != NULL) dt_idhash_destroy(dtp->dt_macros); if (dtp->dt_aggs != NULL) dt_idhash_destroy(dtp->dt_aggs); if (dtp->dt_globals != NULL) dt_idhash_destroy(dtp->dt_globals); if (dtp->dt_tls != NULL) dt_idhash_destroy(dtp->dt_tls); #ifdef __FreeBSD__ for (h = 0; h < dtp->dt_modbuckets; h++) while ((dkm = dtp->dt_kmods[h]) != NULL) { dtp->dt_kmods[h] = dkm->dkm_next; free(dkm->dkm_name); free(dkm); } #endif while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) dt_module_destroy(dtp, dmp); while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) dt_provider_destroy(dtp, pvp); if (dtp->dt_fd != -1) (void) close(dtp->dt_fd); if (dtp->dt_ftfd != -1) (void) close(dtp->dt_ftfd); if (dtp->dt_cdefs_fd != -1) (void) close(dtp->dt_cdefs_fd); if (dtp->dt_ddefs_fd != -1) (void) close(dtp->dt_ddefs_fd); #ifdef illumos if (dtp->dt_stdout_fd != -1) (void) close(dtp->dt_stdout_fd); #else if (dtp->dt_freopen_fp != NULL) (void) fclose(dtp->dt_freopen_fp); #endif dt_epid_destroy(dtp); dt_aggid_destroy(dtp); dt_format_destroy(dtp); dt_strdata_destroy(dtp); dt_buffered_destroy(dtp); dt_aggregate_destroy(dtp); dt_pfdict_destroy(dtp); dt_provmod_destroy(&dtp->dt_provmod); dt_dof_fini(dtp); for (i = 1; i < dtp->dt_cpp_argc; i++) free(dtp->dt_cpp_argv[i]); while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { dt_list_delete(&dtp->dt_lib_path, dirp); free(dirp->dir_path); free(dirp); } free(dtp->dt_cpp_argv); free(dtp->dt_cpp_path); free(dtp->dt_ld_path); #ifdef __FreeBSD__ free(dtp->dt_objcopy_path); #endif free(dtp->dt_mods); #ifdef __FreeBSD__ free(dtp->dt_kmods); #endif free(dtp->dt_provs); free(dtp); } int dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) { dt_provmod_t *prov; int i = 0; for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { if (i < nmods) mods[i] = prov->dp_name; } return (i); } int dtrace_ctlfd(dtrace_hdl_t *dtp) { return (dtp->dt_fd); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.c (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.c (revision 304200) @@ -1,4985 +1,5191 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2013, Joyent Inc. All rights reserved. - * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2012, 2016 by Delphix. All rights reserved. */ #pragma ident "%Z%%M% %I% %E% SMI" /* * DTrace D Language Parser * * The D Parser is a lex/yacc parser consisting of the lexer dt_lex.l, the * parsing grammar dt_grammar.y, and this file, dt_parser.c, which handles * the construction of the parse tree nodes and their syntactic validation. * The parse tree is constructed of dt_node_t structures (see ) * that are built in two passes: (1) the "create" pass, where the parse tree * nodes are allocated by calls from the grammar to dt_node_*() subroutines, * and (2) the "cook" pass, where nodes are coalesced, assigned D types, and * validated according to the syntactic rules of the language. * * All node allocations are performed using dt_node_alloc(). All node frees * during the parsing phase are performed by dt_node_free(), which frees node- * internal state but does not actually free the nodes. All final node frees * are done as part of the end of dt_compile() or as part of destroying * persistent identifiers or translators which have embedded nodes. * * The dt_node_* routines that implement pass (1) may allocate new nodes. The * dt_cook_* routines that implement pass (2) may *not* allocate new nodes. * They may free existing nodes using dt_node_free(), but they may not actually * deallocate any dt_node_t's. Currently dt_cook_op2() is an exception to this * rule: see the comments therein for how this issue is resolved. * * The dt_cook_* routines are responsible for (at minimum) setting the final * node type (dn_ctfp/dn_type) and attributes (dn_attr). If dn_ctfp/dn_type * are set manually (i.e. not by one of the type assignment functions), then * the DT_NF_COOKED flag must be set manually on the node. * * The cooking pass can be applied to the same parse tree more than once (used * in the case of a comma-separated list of probe descriptions). As such, the * cook routines must not perform any parse tree transformations which would * be invalid if the tree were subsequently cooked using a different context. * * The dn_ctfp and dn_type fields form the type of the node. This tuple can * take on the following set of values, which form our type invariants: * * 1. dn_ctfp = NULL, dn_type = CTF_ERR * * In this state, the node has unknown type and is not yet cooked. The * DT_NF_COOKED flag is not yet set on the node. * * 2. dn_ctfp = DT_DYN_CTFP(dtp), dn_type = DT_DYN_TYPE(dtp) * * In this state, the node is a dynamic D type. This means that generic * operations are not valid on this node and only code that knows how to * examine the inner details of the node can operate on it. A node * must have dn_ident set to point to an identifier describing the object * and its type. The DT_NF_REF flag is set for all nodes of type . * At present, the D compiler uses the type for: * * - associative arrays that do not yet have a value type defined * - translated data (i.e. the result of the xlate operator) * - aggregations * * 3. dn_ctfp = DT_STR_CTFP(dtp), dn_type = DT_STR_TYPE(dtp) * * In this state, the node is of type D string. The string type is really * a char[0] typedef, but requires special handling throughout the compiler. * * 4. dn_ctfp != NULL, dn_type = any other type ID * * In this state, the node is of some known D/CTF type. The normal libctf * APIs can be used to learn more about the type name or structure. When * the type is assigned, the DT_NF_SIGNED, DT_NF_REF, and DT_NF_BITFIELD * flags cache the corresponding attributes of the underlying CTF type. */ #include #include #include #include #include #include #ifdef illumos #include #endif #include #include #include #include #include #include #include #include #include #include #include dt_pcb_t *yypcb; /* current control block for parser */ dt_node_t *yypragma; /* lex token list for control lines */ char yyintprefix; /* int token macro prefix (+/-) */ char yyintsuffix[4]; /* int token suffix string [uU][lL] */ int yyintdecimal; /* int token format flag (1=decimal, 0=octal/hex) */ static const char * opstr(int op) { switch (op) { case DT_TOK_COMMA: return (","); case DT_TOK_ELLIPSIS: return ("..."); case DT_TOK_ASGN: return ("="); case DT_TOK_ADD_EQ: return ("+="); case DT_TOK_SUB_EQ: return ("-="); case DT_TOK_MUL_EQ: return ("*="); case DT_TOK_DIV_EQ: return ("/="); case DT_TOK_MOD_EQ: return ("%="); case DT_TOK_AND_EQ: return ("&="); case DT_TOK_XOR_EQ: return ("^="); case DT_TOK_OR_EQ: return ("|="); case DT_TOK_LSH_EQ: return ("<<="); case DT_TOK_RSH_EQ: return (">>="); case DT_TOK_QUESTION: return ("?"); case DT_TOK_COLON: return (":"); case DT_TOK_LOR: return ("||"); case DT_TOK_LXOR: return ("^^"); case DT_TOK_LAND: return ("&&"); case DT_TOK_BOR: return ("|"); case DT_TOK_XOR: return ("^"); case DT_TOK_BAND: return ("&"); case DT_TOK_EQU: return ("=="); case DT_TOK_NEQ: return ("!="); case DT_TOK_LT: return ("<"); case DT_TOK_LE: return ("<="); case DT_TOK_GT: return (">"); case DT_TOK_GE: return (">="); case DT_TOK_LSH: return ("<<"); case DT_TOK_RSH: return (">>"); case DT_TOK_ADD: return ("+"); case DT_TOK_SUB: return ("-"); case DT_TOK_MUL: return ("*"); case DT_TOK_DIV: return ("/"); case DT_TOK_MOD: return ("%"); case DT_TOK_LNEG: return ("!"); case DT_TOK_BNEG: return ("~"); case DT_TOK_ADDADD: return ("++"); case DT_TOK_PREINC: return ("++"); case DT_TOK_POSTINC: return ("++"); case DT_TOK_SUBSUB: return ("--"); case DT_TOK_PREDEC: return ("--"); case DT_TOK_POSTDEC: return ("--"); case DT_TOK_IPOS: return ("+"); case DT_TOK_INEG: return ("-"); case DT_TOK_DEREF: return ("*"); case DT_TOK_ADDROF: return ("&"); case DT_TOK_OFFSETOF: return ("offsetof"); case DT_TOK_SIZEOF: return ("sizeof"); case DT_TOK_STRINGOF: return ("stringof"); case DT_TOK_XLATE: return ("xlate"); case DT_TOK_LPAR: return ("("); case DT_TOK_RPAR: return (")"); case DT_TOK_LBRAC: return ("["); case DT_TOK_RBRAC: return ("]"); case DT_TOK_PTR: return ("->"); case DT_TOK_DOT: return ("."); case DT_TOK_STRING: return (""); case DT_TOK_IDENT: return (""); case DT_TOK_TNAME: return (""); case DT_TOK_INT: return (""); default: return (""); } } int dt_type_lookup(const char *s, dtrace_typeinfo_t *tip) { static const char delimiters[] = " \t\n\r\v\f*`"; dtrace_hdl_t *dtp = yypcb->pcb_hdl; const char *p, *q, *r, *end, *obj; for (p = s, end = s + strlen(s); *p != '\0'; p = q) { while (isspace(*p)) p++; /* skip leading whitespace prior to token */ if (p == end || (q = strpbrk(p + 1, delimiters)) == NULL) break; /* empty string or single token remaining */ if (*q == '`') { char *object = alloca((size_t)(q - p) + 1); char *type = alloca((size_t)(end - s) + 1); /* * Copy from the start of the token (p) to the location * backquote (q) to extract the nul-terminated object. */ bcopy(p, object, (size_t)(q - p)); object[(size_t)(q - p)] = '\0'; /* * Copy the original string up to the start of this * token (p) into type, and then concatenate everything * after q. This is the type name without the object. */ bcopy(s, type, (size_t)(p - s)); bcopy(q + 1, type + (size_t)(p - s), strlen(q + 1) + 1); /* * There may be at most three delimeters. The second * delimeter is usually used to distinguish the type * within a given module, however, there could be a link * map id on the scene in which case that delimeter * would be the third. We determine presence of the lmid * if it rouglhly meets the from LM[0-9] */ if ((r = strchr(q + 1, '`')) != NULL && ((r = strchr(r + 1, '`')) != NULL)) { if (strchr(r + 1, '`') != NULL) return (dt_set_errno(dtp, EDT_BADSCOPE)); if (q[1] != 'L' || q[2] != 'M') return (dt_set_errno(dtp, EDT_BADSCOPE)); } return (dtrace_lookup_by_type(dtp, object, type, tip)); } } if (yypcb->pcb_idepth != 0) obj = DTRACE_OBJ_CDEFS; else obj = DTRACE_OBJ_EVERY; return (dtrace_lookup_by_type(dtp, obj, s, tip)); } /* * When we parse type expressions or parse an expression with unary "&", we * need to find a type that is a pointer to a previously known type. * Unfortunately CTF is limited to a per-container view, so ctf_type_pointer() * alone does not suffice for our needs. We provide a more intelligent wrapper * for the compiler that attempts to compute a pointer to either the given type * or its base (that is, we try both "foo_t *" and "struct foo *"), and also * to potentially construct the required type on-the-fly. */ int dt_type_pointer(dtrace_typeinfo_t *tip) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; ctf_file_t *ctfp = tip->dtt_ctfp; ctf_id_t type = tip->dtt_type; ctf_id_t base = ctf_type_resolve(ctfp, type); uint_t bflags = tip->dtt_flags; dt_module_t *dmp; ctf_id_t ptr; if ((ptr = ctf_type_pointer(ctfp, type)) != CTF_ERR || (ptr = ctf_type_pointer(ctfp, base)) != CTF_ERR) { tip->dtt_type = ptr; return (0); } if (yypcb->pcb_idepth != 0) dmp = dtp->dt_cdefs; else dmp = dtp->dt_ddefs; if (ctfp != dmp->dm_ctfp && ctfp != ctf_parent_file(dmp->dm_ctfp) && (type = ctf_add_type(dmp->dm_ctfp, ctfp, type)) == CTF_ERR) { dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp); return (dt_set_errno(dtp, EDT_CTF)); } ptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, type); if (ptr == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) { dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp); return (dt_set_errno(dtp, EDT_CTF)); } tip->dtt_object = dmp->dm_name; tip->dtt_ctfp = dmp->dm_ctfp; tip->dtt_type = ptr; tip->dtt_flags = bflags; return (0); } const char * dt_type_name(ctf_file_t *ctfp, ctf_id_t type, char *buf, size_t len) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; if (ctfp == DT_FPTR_CTFP(dtp) && type == DT_FPTR_TYPE(dtp)) (void) snprintf(buf, len, "function pointer"); else if (ctfp == DT_FUNC_CTFP(dtp) && type == DT_FUNC_TYPE(dtp)) (void) snprintf(buf, len, "function"); else if (ctfp == DT_DYN_CTFP(dtp) && type == DT_DYN_TYPE(dtp)) (void) snprintf(buf, len, "dynamic variable"); else if (ctfp == NULL) (void) snprintf(buf, len, ""); else if (ctf_type_name(ctfp, type, buf, len) == NULL) (void) snprintf(buf, len, "unknown"); return (buf); } /* * Perform the "usual arithmetic conversions" to determine which of the two * input operand types should be promoted and used as a result type. The * rules for this are described in ISOC[6.3.1.8] and K&R[A6.5]. */ static void dt_type_promote(dt_node_t *lp, dt_node_t *rp, ctf_file_t **ofp, ctf_id_t *otype) { ctf_file_t *lfp = lp->dn_ctfp; ctf_id_t ltype = lp->dn_type; ctf_file_t *rfp = rp->dn_ctfp; ctf_id_t rtype = rp->dn_type; ctf_id_t lbase = ctf_type_resolve(lfp, ltype); uint_t lkind = ctf_type_kind(lfp, lbase); ctf_id_t rbase = ctf_type_resolve(rfp, rtype); uint_t rkind = ctf_type_kind(rfp, rbase); dtrace_hdl_t *dtp = yypcb->pcb_hdl; ctf_encoding_t le, re; uint_t lrank, rrank; assert(lkind == CTF_K_INTEGER || lkind == CTF_K_ENUM); assert(rkind == CTF_K_INTEGER || rkind == CTF_K_ENUM); if (lkind == CTF_K_ENUM) { lfp = DT_INT_CTFP(dtp); ltype = lbase = DT_INT_TYPE(dtp); } if (rkind == CTF_K_ENUM) { rfp = DT_INT_CTFP(dtp); rtype = rbase = DT_INT_TYPE(dtp); } if (ctf_type_encoding(lfp, lbase, &le) == CTF_ERR) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(lfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } if (ctf_type_encoding(rfp, rbase, &re) == CTF_ERR) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(rfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } /* * Compute an integer rank based on the size and unsigned status. * If rank is identical, pick the "larger" of the equivalent types * which we define as having a larger base ctf_id_t. If rank is * different, pick the type with the greater rank. */ lrank = le.cte_bits + ((le.cte_format & CTF_INT_SIGNED) == 0); rrank = re.cte_bits + ((re.cte_format & CTF_INT_SIGNED) == 0); if (lrank == rrank) { if (lbase - rbase < 0) goto return_rtype; else goto return_ltype; } else if (lrank > rrank) { goto return_ltype; } else goto return_rtype; return_ltype: *ofp = lfp; *otype = ltype; return; return_rtype: *ofp = rfp; *otype = rtype; } void dt_node_promote(dt_node_t *lp, dt_node_t *rp, dt_node_t *dnp) { dt_type_promote(lp, rp, &dnp->dn_ctfp, &dnp->dn_type); dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type, B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); } const char * dt_node_name(const dt_node_t *dnp, char *buf, size_t len) { char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; const char *prefix = "", *suffix = ""; const dtrace_syminfo_t *dts; char *s; switch (dnp->dn_kind) { case DT_NODE_INT: (void) snprintf(buf, len, "integer constant 0x%llx", (u_longlong_t)dnp->dn_value); break; case DT_NODE_STRING: s = strchr2esc(dnp->dn_string, strlen(dnp->dn_string)); (void) snprintf(buf, len, "string constant \"%s\"", s != NULL ? s : dnp->dn_string); free(s); break; case DT_NODE_IDENT: (void) snprintf(buf, len, "identifier %s", dnp->dn_string); break; case DT_NODE_VAR: case DT_NODE_FUNC: case DT_NODE_AGG: case DT_NODE_INLINE: switch (dnp->dn_ident->di_kind) { case DT_IDENT_FUNC: case DT_IDENT_AGGFUNC: case DT_IDENT_ACTFUNC: suffix = "( )"; break; case DT_IDENT_AGG: prefix = "@"; break; } (void) snprintf(buf, len, "%s %s%s%s", dt_idkind_name(dnp->dn_ident->di_kind), prefix, dnp->dn_ident->di_name, suffix); break; case DT_NODE_SYM: dts = dnp->dn_ident->di_data; (void) snprintf(buf, len, "symbol %s`%s", dts->dts_object, dts->dts_name); break; case DT_NODE_TYPE: (void) snprintf(buf, len, "type %s", dt_node_type_name(dnp, n1, sizeof (n1))); break; case DT_NODE_OP1: case DT_NODE_OP2: case DT_NODE_OP3: (void) snprintf(buf, len, "operator %s", opstr(dnp->dn_op)); break; case DT_NODE_DEXPR: case DT_NODE_DFUNC: if (dnp->dn_expr) return (dt_node_name(dnp->dn_expr, buf, len)); (void) snprintf(buf, len, "%s", "statement"); break; case DT_NODE_PDESC: if (dnp->dn_desc->dtpd_id == 0) { (void) snprintf(buf, len, "probe description %s:%s:%s:%s", dnp->dn_desc->dtpd_provider, dnp->dn_desc->dtpd_mod, dnp->dn_desc->dtpd_func, dnp->dn_desc->dtpd_name); } else { (void) snprintf(buf, len, "probe description %u", dnp->dn_desc->dtpd_id); } break; case DT_NODE_CLAUSE: (void) snprintf(buf, len, "%s", "clause"); break; case DT_NODE_MEMBER: (void) snprintf(buf, len, "member %s", dnp->dn_membname); break; case DT_NODE_XLATOR: (void) snprintf(buf, len, "translator <%s> (%s)", dt_type_name(dnp->dn_xlator->dx_dst_ctfp, dnp->dn_xlator->dx_dst_type, n1, sizeof (n1)), dt_type_name(dnp->dn_xlator->dx_src_ctfp, dnp->dn_xlator->dx_src_type, n2, sizeof (n2))); break; case DT_NODE_PROG: (void) snprintf(buf, len, "%s", "program"); break; default: (void) snprintf(buf, len, "node <%u>", dnp->dn_kind); break; } return (buf); } /* * dt_node_xalloc() can be used to create new parse nodes from any libdtrace * caller. The caller is responsible for assigning dn_link appropriately. */ dt_node_t * dt_node_xalloc(dtrace_hdl_t *dtp, int kind) { dt_node_t *dnp = dt_alloc(dtp, sizeof (dt_node_t)); if (dnp == NULL) return (NULL); dnp->dn_ctfp = NULL; dnp->dn_type = CTF_ERR; dnp->dn_kind = (uchar_t)kind; dnp->dn_flags = 0; dnp->dn_op = 0; dnp->dn_line = -1; dnp->dn_reg = -1; dnp->dn_attr = _dtrace_defattr; dnp->dn_list = NULL; dnp->dn_link = NULL; bzero(&dnp->dn_u, sizeof (dnp->dn_u)); return (dnp); } /* * dt_node_alloc() is used to create new parse nodes from the parser. It * assigns the node location based on the current lexer line number and places * the new node on the default allocation list. If allocation fails, we * automatically longjmp the caller back to the enclosing compilation call. */ static dt_node_t * dt_node_alloc(int kind) { dt_node_t *dnp = dt_node_xalloc(yypcb->pcb_hdl, kind); if (dnp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dnp->dn_line = yylineno; dnp->dn_link = yypcb->pcb_list; yypcb->pcb_list = dnp; return (dnp); } void dt_node_free(dt_node_t *dnp) { uchar_t kind = dnp->dn_kind; dnp->dn_kind = DT_NODE_FREE; switch (kind) { case DT_NODE_STRING: case DT_NODE_IDENT: case DT_NODE_TYPE: free(dnp->dn_string); dnp->dn_string = NULL; break; case DT_NODE_VAR: case DT_NODE_FUNC: case DT_NODE_PROBE: if (dnp->dn_ident != NULL) { if (dnp->dn_ident->di_flags & DT_IDFLG_ORPHAN) dt_ident_destroy(dnp->dn_ident); dnp->dn_ident = NULL; } dt_node_list_free(&dnp->dn_args); break; case DT_NODE_OP1: if (dnp->dn_child != NULL) { dt_node_free(dnp->dn_child); dnp->dn_child = NULL; } break; case DT_NODE_OP3: if (dnp->dn_expr != NULL) { dt_node_free(dnp->dn_expr); dnp->dn_expr = NULL; } /*FALLTHRU*/ case DT_NODE_OP2: if (dnp->dn_left != NULL) { dt_node_free(dnp->dn_left); dnp->dn_left = NULL; } if (dnp->dn_right != NULL) { dt_node_free(dnp->dn_right); dnp->dn_right = NULL; } break; case DT_NODE_DEXPR: case DT_NODE_DFUNC: if (dnp->dn_expr != NULL) { dt_node_free(dnp->dn_expr); dnp->dn_expr = NULL; } break; case DT_NODE_AGG: if (dnp->dn_aggfun != NULL) { dt_node_free(dnp->dn_aggfun); dnp->dn_aggfun = NULL; } dt_node_list_free(&dnp->dn_aggtup); break; case DT_NODE_PDESC: free(dnp->dn_spec); dnp->dn_spec = NULL; free(dnp->dn_desc); dnp->dn_desc = NULL; break; case DT_NODE_CLAUSE: if (dnp->dn_pred != NULL) dt_node_free(dnp->dn_pred); if (dnp->dn_locals != NULL) dt_idhash_destroy(dnp->dn_locals); dt_node_list_free(&dnp->dn_pdescs); dt_node_list_free(&dnp->dn_acts); break; case DT_NODE_MEMBER: free(dnp->dn_membname); dnp->dn_membname = NULL; if (dnp->dn_membexpr != NULL) { dt_node_free(dnp->dn_membexpr); dnp->dn_membexpr = NULL; } break; case DT_NODE_PROVIDER: dt_node_list_free(&dnp->dn_probes); free(dnp->dn_provname); dnp->dn_provname = NULL; break; case DT_NODE_PROG: dt_node_list_free(&dnp->dn_list); break; } } void dt_node_attr_assign(dt_node_t *dnp, dtrace_attribute_t attr) { if ((yypcb->pcb_cflags & DTRACE_C_EATTR) && (dt_attr_cmp(attr, yypcb->pcb_amin) < 0)) { char a[DTRACE_ATTR2STR_MAX]; char s[BUFSIZ]; dnerror(dnp, D_ATTR_MIN, "attributes for %s (%s) are less than " "predefined minimum\n", dt_node_name(dnp, s, sizeof (s)), dtrace_attr2str(attr, a, sizeof (a))); } dnp->dn_attr = attr; } void dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type, boolean_t user) { ctf_id_t base = ctf_type_resolve(fp, type); uint_t kind = ctf_type_kind(fp, base); ctf_encoding_t e; dnp->dn_flags &= ~(DT_NF_SIGNED | DT_NF_REF | DT_NF_BITFIELD | DT_NF_USERLAND); if (kind == CTF_K_INTEGER && ctf_type_encoding(fp, base, &e) == 0) { size_t size = e.cte_bits / NBBY; if (size > 8 || (e.cte_bits % NBBY) != 0 || (size & (size - 1))) dnp->dn_flags |= DT_NF_BITFIELD; if (e.cte_format & CTF_INT_SIGNED) dnp->dn_flags |= DT_NF_SIGNED; } if (kind == CTF_K_FLOAT && ctf_type_encoding(fp, base, &e) == 0) { if (e.cte_bits / NBBY > sizeof (uint64_t)) dnp->dn_flags |= DT_NF_REF; } if (kind == CTF_K_STRUCT || kind == CTF_K_UNION || kind == CTF_K_FORWARD || kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION) dnp->dn_flags |= DT_NF_REF; else if (yypcb != NULL && fp == DT_DYN_CTFP(yypcb->pcb_hdl) && type == DT_DYN_TYPE(yypcb->pcb_hdl)) dnp->dn_flags |= DT_NF_REF; if (user) dnp->dn_flags |= DT_NF_USERLAND; dnp->dn_flags |= DT_NF_COOKED; dnp->dn_ctfp = fp; dnp->dn_type = type; } void dt_node_type_propagate(const dt_node_t *src, dt_node_t *dst) { assert(src->dn_flags & DT_NF_COOKED); dst->dn_flags = src->dn_flags & ~DT_NF_LVALUE; dst->dn_ctfp = src->dn_ctfp; dst->dn_type = src->dn_type; } const char * dt_node_type_name(const dt_node_t *dnp, char *buf, size_t len) { if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL) { (void) snprintf(buf, len, "%s", dt_idkind_name(dt_ident_resolve(dnp->dn_ident)->di_kind)); return (buf); } if (dnp->dn_flags & DT_NF_USERLAND) { size_t n = snprintf(buf, len, "userland "); len = len > n ? len - n : 0; (void) dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf + n, len); return (buf); } return (dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf, len)); } size_t dt_node_type_size(const dt_node_t *dnp) { ctf_id_t base; dtrace_hdl_t *dtp = yypcb->pcb_hdl; if (dnp->dn_kind == DT_NODE_STRING) return (strlen(dnp->dn_string) + 1); if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL) return (dt_ident_size(dnp->dn_ident)); base = ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type); if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_FORWARD) return (0); /* * Here we have a 32-bit user pointer that is being used with a 64-bit * kernel. When we're using it and its tagged as a userland reference -- * then we need to keep it as a 32-bit pointer. However, if we are * referring to it as a kernel address, eg. being used after a copyin() * then we need to make sure that we actually return the kernel's size * of a pointer, 8 bytes. */ if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_POINTER && ctf_getmodel(dnp->dn_ctfp) == CTF_MODEL_ILP32 && !(dnp->dn_flags & DT_NF_USERLAND) && dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) return (8); return (ctf_type_size(dnp->dn_ctfp, dnp->dn_type)); } /* * Determine if the specified parse tree node references an identifier of the * specified kind, and if so return a pointer to it; otherwise return NULL. * This function resolves the identifier itself, following through any inlines. */ dt_ident_t * dt_node_resolve(const dt_node_t *dnp, uint_t idkind) { dt_ident_t *idp; switch (dnp->dn_kind) { case DT_NODE_VAR: case DT_NODE_SYM: case DT_NODE_FUNC: case DT_NODE_AGG: case DT_NODE_INLINE: case DT_NODE_PROBE: idp = dt_ident_resolve(dnp->dn_ident); return (idp->di_kind == idkind ? idp : NULL); } if (dt_node_is_dynamic(dnp)) { idp = dt_ident_resolve(dnp->dn_ident); return (idp->di_kind == idkind ? idp : NULL); } return (NULL); } size_t dt_node_sizeof(const dt_node_t *dnp) { dtrace_syminfo_t *sip; GElf_Sym sym; dtrace_hdl_t *dtp = yypcb->pcb_hdl; /* * The size of the node as used for the sizeof() operator depends on * the kind of the node. If the node is a SYM, the size is obtained * from the symbol table; if it is not a SYM, the size is determined * from the node's type. This is slightly different from C's sizeof() * operator in that (for example) when applied to a function, sizeof() * will evaluate to the length of the function rather than the size of * the function type. */ if (dnp->dn_kind != DT_NODE_SYM) return (dt_node_type_size(dnp)); sip = dnp->dn_ident->di_data; if (dtrace_lookup_by_name(dtp, sip->dts_object, sip->dts_name, &sym, NULL) == -1) return (0); return (sym.st_size); } int dt_node_is_integer(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); type = ctf_type_resolve(fp, dnp->dn_type); kind = ctf_type_kind(fp, type); if (kind == CTF_K_INTEGER && ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e)) return (0); /* void integer */ return (kind == CTF_K_INTEGER || kind == CTF_K_ENUM); } int dt_node_is_float(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); type = ctf_type_resolve(fp, dnp->dn_type); kind = ctf_type_kind(fp, type); return (kind == CTF_K_FLOAT && ctf_type_encoding(dnp->dn_ctfp, type, &e) == 0 && ( e.cte_format == CTF_FP_SINGLE || e.cte_format == CTF_FP_DOUBLE || e.cte_format == CTF_FP_LDOUBLE)); } int dt_node_is_scalar(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); type = ctf_type_resolve(fp, dnp->dn_type); kind = ctf_type_kind(fp, type); if (kind == CTF_K_INTEGER && ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e)) return (0); /* void cannot be used as a scalar */ return (kind == CTF_K_INTEGER || kind == CTF_K_ENUM || kind == CTF_K_POINTER); } int dt_node_is_arith(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); type = ctf_type_resolve(fp, dnp->dn_type); kind = ctf_type_kind(fp, type); if (kind == CTF_K_INTEGER) return (ctf_type_encoding(fp, type, &e) == 0 && !IS_VOID(e)); else return (kind == CTF_K_ENUM); } int dt_node_is_vfptr(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); type = ctf_type_resolve(fp, dnp->dn_type); if (ctf_type_kind(fp, type) != CTF_K_POINTER) return (0); /* type is not a pointer */ type = ctf_type_resolve(fp, ctf_type_reference(fp, type)); kind = ctf_type_kind(fp, type); return (kind == CTF_K_FUNCTION || (kind == CTF_K_INTEGER && ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e))); } int dt_node_is_dynamic(const dt_node_t *dnp) { if (dnp->dn_kind == DT_NODE_VAR && (dnp->dn_ident->di_flags & DT_IDFLG_INLINE)) { const dt_idnode_t *inp = dnp->dn_ident->di_iarg; return (inp->din_root ? dt_node_is_dynamic(inp->din_root) : 0); } return (dnp->dn_ctfp == DT_DYN_CTFP(yypcb->pcb_hdl) && dnp->dn_type == DT_DYN_TYPE(yypcb->pcb_hdl)); } int dt_node_is_string(const dt_node_t *dnp) { return (dnp->dn_ctfp == DT_STR_CTFP(yypcb->pcb_hdl) && dnp->dn_type == DT_STR_TYPE(yypcb->pcb_hdl)); } int dt_node_is_stack(const dt_node_t *dnp) { return (dnp->dn_ctfp == DT_STACK_CTFP(yypcb->pcb_hdl) && dnp->dn_type == DT_STACK_TYPE(yypcb->pcb_hdl)); } int dt_node_is_symaddr(const dt_node_t *dnp) { return (dnp->dn_ctfp == DT_SYMADDR_CTFP(yypcb->pcb_hdl) && dnp->dn_type == DT_SYMADDR_TYPE(yypcb->pcb_hdl)); } int dt_node_is_usymaddr(const dt_node_t *dnp) { return (dnp->dn_ctfp == DT_USYMADDR_CTFP(yypcb->pcb_hdl) && dnp->dn_type == DT_USYMADDR_TYPE(yypcb->pcb_hdl)); } int dt_node_is_strcompat(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_arinfo_t r; ctf_id_t base; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); base = ctf_type_resolve(fp, dnp->dn_type); kind = ctf_type_kind(fp, base); if (kind == CTF_K_POINTER && (base = ctf_type_reference(fp, base)) != CTF_ERR && (base = ctf_type_resolve(fp, base)) != CTF_ERR && ctf_type_encoding(fp, base, &e) == 0 && IS_CHAR(e)) return (1); /* promote char pointer to string */ if (kind == CTF_K_ARRAY && ctf_array_info(fp, base, &r) == 0 && (base = ctf_type_resolve(fp, r.ctr_contents)) != CTF_ERR && ctf_type_encoding(fp, base, &e) == 0 && IS_CHAR(e)) return (1); /* promote char array to string */ return (0); } int dt_node_is_pointer(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; uint_t kind; assert(dnp->dn_flags & DT_NF_COOKED); if (dt_node_is_string(dnp)) return (0); /* string are pass-by-ref but act like structs */ kind = ctf_type_kind(fp, ctf_type_resolve(fp, dnp->dn_type)); return (kind == CTF_K_POINTER || kind == CTF_K_ARRAY); } int dt_node_is_void(const dt_node_t *dnp) { ctf_file_t *fp = dnp->dn_ctfp; ctf_encoding_t e; ctf_id_t type; if (dt_node_is_dynamic(dnp)) return (0); /* is an alias for void but not the same */ if (dt_node_is_stack(dnp)) return (0); if (dt_node_is_symaddr(dnp) || dt_node_is_usymaddr(dnp)) return (0); type = ctf_type_resolve(fp, dnp->dn_type); return (ctf_type_kind(fp, type) == CTF_K_INTEGER && ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e)); } int dt_node_is_ptrcompat(const dt_node_t *lp, const dt_node_t *rp, ctf_file_t **fpp, ctf_id_t *tp) { ctf_file_t *lfp = lp->dn_ctfp; ctf_file_t *rfp = rp->dn_ctfp; ctf_id_t lbase = CTF_ERR, rbase = CTF_ERR; ctf_id_t lref = CTF_ERR, rref = CTF_ERR; int lp_is_void, rp_is_void, lp_is_int, rp_is_int, compat; uint_t lkind, rkind; ctf_encoding_t e; ctf_arinfo_t r; assert(lp->dn_flags & DT_NF_COOKED); assert(rp->dn_flags & DT_NF_COOKED); if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp)) return (0); /* fail if either node is a dynamic variable */ lp_is_int = dt_node_is_integer(lp); rp_is_int = dt_node_is_integer(rp); if (lp_is_int && rp_is_int) return (0); /* fail if both nodes are integers */ if (lp_is_int && (lp->dn_kind != DT_NODE_INT || lp->dn_value != 0)) return (0); /* fail if lp is an integer that isn't 0 constant */ if (rp_is_int && (rp->dn_kind != DT_NODE_INT || rp->dn_value != 0)) return (0); /* fail if rp is an integer that isn't 0 constant */ if ((lp_is_int == 0 && rp_is_int == 0) && ( (lp->dn_flags & DT_NF_USERLAND) ^ (rp->dn_flags & DT_NF_USERLAND))) return (0); /* fail if only one pointer is a userland address */ /* * Resolve the left-hand and right-hand types to their base type, and * then resolve the referenced type as well (assuming the base type * is CTF_K_POINTER or CTF_K_ARRAY). Otherwise [lr]ref = CTF_ERR. */ if (!lp_is_int) { lbase = ctf_type_resolve(lfp, lp->dn_type); lkind = ctf_type_kind(lfp, lbase); if (lkind == CTF_K_POINTER) { lref = ctf_type_resolve(lfp, ctf_type_reference(lfp, lbase)); } else if (lkind == CTF_K_ARRAY && ctf_array_info(lfp, lbase, &r) == 0) { lref = ctf_type_resolve(lfp, r.ctr_contents); } } if (!rp_is_int) { rbase = ctf_type_resolve(rfp, rp->dn_type); rkind = ctf_type_kind(rfp, rbase); if (rkind == CTF_K_POINTER) { rref = ctf_type_resolve(rfp, ctf_type_reference(rfp, rbase)); } else if (rkind == CTF_K_ARRAY && ctf_array_info(rfp, rbase, &r) == 0) { rref = ctf_type_resolve(rfp, r.ctr_contents); } } /* * We know that one or the other type may still be a zero-valued * integer constant. To simplify the code below, set the integer * type variables equal to the non-integer types and proceed. */ if (lp_is_int) { lbase = rbase; lkind = rkind; lref = rref; lfp = rfp; } else if (rp_is_int) { rbase = lbase; rkind = lkind; rref = lref; rfp = lfp; } lp_is_void = ctf_type_encoding(lfp, lref, &e) == 0 && IS_VOID(e); rp_is_void = ctf_type_encoding(rfp, rref, &e) == 0 && IS_VOID(e); /* * The types are compatible if both are pointers to the same type, or * if either pointer is a void pointer. If they are compatible, set * tp to point to the more specific pointer type and return it. */ compat = (lkind == CTF_K_POINTER || lkind == CTF_K_ARRAY) && (rkind == CTF_K_POINTER || rkind == CTF_K_ARRAY) && (lp_is_void || rp_is_void || ctf_type_compat(lfp, lref, rfp, rref)); if (compat) { if (fpp != NULL) *fpp = rp_is_void ? lfp : rfp; if (tp != NULL) *tp = rp_is_void ? lbase : rbase; } return (compat); } /* * The rules for checking argument types against parameter types are described * in the ANSI-C spec (see K&R[A7.3.2] and K&R[A7.17]). We use the same rule * set to determine whether associative array arguments match the prototype. */ int dt_node_is_argcompat(const dt_node_t *lp, const dt_node_t *rp) { ctf_file_t *lfp = lp->dn_ctfp; ctf_file_t *rfp = rp->dn_ctfp; assert(lp->dn_flags & DT_NF_COOKED); assert(rp->dn_flags & DT_NF_COOKED); if (dt_node_is_integer(lp) && dt_node_is_integer(rp)) return (1); /* integer types are compatible */ if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp)) return (1); /* string types are compatible */ if (dt_node_is_stack(lp) && dt_node_is_stack(rp)) return (1); /* stack types are compatible */ if (dt_node_is_symaddr(lp) && dt_node_is_symaddr(rp)) return (1); /* symaddr types are compatible */ if (dt_node_is_usymaddr(lp) && dt_node_is_usymaddr(rp)) return (1); /* usymaddr types are compatible */ switch (ctf_type_kind(lfp, ctf_type_resolve(lfp, lp->dn_type))) { case CTF_K_FUNCTION: case CTF_K_STRUCT: case CTF_K_UNION: return (ctf_type_compat(lfp, lp->dn_type, rfp, rp->dn_type)); default: return (dt_node_is_ptrcompat(lp, rp, NULL, NULL)); } } /* * We provide dt_node_is_posconst() as a convenience routine for callers who * wish to verify that an argument is a positive non-zero integer constant. */ int dt_node_is_posconst(const dt_node_t *dnp) { return (dnp->dn_kind == DT_NODE_INT && dnp->dn_value != 0 && ( (dnp->dn_flags & DT_NF_SIGNED) == 0 || (int64_t)dnp->dn_value > 0)); } int dt_node_is_actfunc(const dt_node_t *dnp) { return (dnp->dn_kind == DT_NODE_FUNC && dnp->dn_ident->di_kind == DT_IDENT_ACTFUNC); } /* * The original rules for integer constant typing are described in K&R[A2.5.1]. * However, since we support long long, we instead use the rules from ISO C99 * clause 6.4.4.1 since that is where long longs are formally described. The * rules require us to know whether the constant was specified in decimal or * in octal or hex, which we do by looking at our lexer's 'yyintdecimal' flag. * The type of an integer constant is the first of the corresponding list in * which its value can be represented: * * unsuffixed decimal: int, long, long long * unsuffixed oct/hex: int, unsigned int, long, unsigned long, * long long, unsigned long long * suffix [uU]: unsigned int, unsigned long, unsigned long long * suffix [lL] decimal: long, long long * suffix [lL] oct/hex: long, unsigned long, long long, unsigned long long * suffix [uU][Ll]: unsigned long, unsigned long long * suffix ll/LL decimal: long long * suffix ll/LL oct/hex: long long, unsigned long long * suffix [uU][ll/LL]: unsigned long long * * Given that our lexer has already validated the suffixes by regexp matching, * there is an obvious way to concisely encode these rules: construct an array * of the types in the order int, unsigned int, long, unsigned long, long long, * unsigned long long. Compute an integer array starting index based on the * suffix (e.g. none = 0, u = 1, ull = 5), and compute an increment based on * the specifier (dec/oct/hex) and suffix (u). Then iterate from the starting * index to the end, advancing using the increment, and searching until we * find a limit that matches or we run out of choices (overflow). To make it * even faster, we precompute the table of type information in dtrace_open(). */ dt_node_t * dt_node_int(uintmax_t value) { dt_node_t *dnp = dt_node_alloc(DT_NODE_INT); dtrace_hdl_t *dtp = yypcb->pcb_hdl; int n = (yyintdecimal | (yyintsuffix[0] == 'u')) + 1; int i = 0; const char *p; char c; dnp->dn_op = DT_TOK_INT; dnp->dn_value = value; for (p = yyintsuffix; (c = *p) != '\0'; p++) { if (c == 'U' || c == 'u') i += 1; else if (c == 'L' || c == 'l') i += 2; } for (; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i += n) { if (value <= dtp->dt_ints[i].did_limit) { dt_node_type_assign(dnp, dtp->dt_ints[i].did_ctfp, dtp->dt_ints[i].did_type, B_FALSE); /* * If a prefix character is present in macro text, add * in the corresponding operator node (see dt_lex.l). */ switch (yyintprefix) { case '+': return (dt_node_op1(DT_TOK_IPOS, dnp)); case '-': return (dt_node_op1(DT_TOK_INEG, dnp)); default: return (dnp); } } } xyerror(D_INT_OFLOW, "integer constant 0x%llx cannot be represented " "in any built-in integral type\n", (u_longlong_t)value); /*NOTREACHED*/ return (NULL); /* keep gcc happy */ } dt_node_t * dt_node_string(char *string) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *dnp; if (string == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dnp = dt_node_alloc(DT_NODE_STRING); dnp->dn_op = DT_TOK_STRING; dnp->dn_string = string; dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), B_FALSE); return (dnp); } dt_node_t * dt_node_ident(char *name) { dt_ident_t *idp; dt_node_t *dnp; if (name == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); /* * If the identifier is an inlined integer constant, then create an INT * node that is a clone of the inline parse tree node and return that * immediately, allowing this inline to be used in parsing contexts * that require constant expressions (e.g. scalar array sizes). */ if ((idp = dt_idstack_lookup(&yypcb->pcb_globals, name)) != NULL && (idp->di_flags & DT_IDFLG_INLINE)) { dt_idnode_t *inp = idp->di_iarg; if (inp->din_root != NULL && inp->din_root->dn_kind == DT_NODE_INT) { free(name); dnp = dt_node_alloc(DT_NODE_INT); dnp->dn_op = DT_TOK_INT; dnp->dn_value = inp->din_root->dn_value; dt_node_type_propagate(inp->din_root, dnp); return (dnp); } } dnp = dt_node_alloc(DT_NODE_IDENT); dnp->dn_op = name[0] == '@' ? DT_TOK_AGG : DT_TOK_IDENT; dnp->dn_string = name; return (dnp); } /* * Create an empty node of type corresponding to the given declaration. * Explicit references to user types (C or D) are assigned the default * stability; references to other types are _dtrace_typattr (Private). */ dt_node_t * dt_node_type(dt_decl_t *ddp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dtrace_typeinfo_t dtt; dt_node_t *dnp; char *name = NULL; int err; /* * If 'ddp' is NULL, we get a decl by popping the decl stack. This * form of dt_node_type() is used by parameter rules in dt_grammar.y. */ if (ddp == NULL) ddp = dt_decl_pop_param(&name); err = dt_decl_type(ddp, &dtt); dt_decl_free(ddp); if (err != 0) { free(name); longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } dnp = dt_node_alloc(DT_NODE_TYPE); dnp->dn_op = DT_TOK_IDENT; dnp->dn_string = name; dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags); if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp || dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp) dt_node_attr_assign(dnp, _dtrace_defattr); else dt_node_attr_assign(dnp, _dtrace_typattr); return (dnp); } /* * Create a type node corresponding to a varargs (...) parameter by just * assigning it type CTF_ERR. The decl processing code will handle this. */ dt_node_t * dt_node_vatype(void) { dt_node_t *dnp = dt_node_alloc(DT_NODE_TYPE); dnp->dn_op = DT_TOK_IDENT; dnp->dn_ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp; dnp->dn_type = CTF_ERR; dnp->dn_attr = _dtrace_defattr; return (dnp); } /* * Instantiate a decl using the contents of the current declaration stack. As * we do not currently permit decls to be initialized, this function currently * returns NULL and no parse node is created. When this function is called, * the topmost scope's ds_ident pointer will be set to NULL (indicating no * init_declarator rule was matched) or will point to the identifier to use. */ dt_node_t * dt_node_decl(void) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_scope_t *dsp = &yypcb->pcb_dstack; dt_dclass_t class = dsp->ds_class; dt_decl_t *ddp = dt_decl_top(); dt_module_t *dmp; dtrace_typeinfo_t dtt; ctf_id_t type; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; if (dt_decl_type(ddp, &dtt) != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); /* * If we have no declaration identifier, then this is either a spurious * declaration of an intrinsic type (e.g. "extern int;") or declaration * or redeclaration of a struct, union, or enum type or tag. */ if (dsp->ds_ident == NULL) { if (ddp->dd_kind != CTF_K_STRUCT && ddp->dd_kind != CTF_K_UNION && ddp->dd_kind != CTF_K_ENUM) xyerror(D_DECL_USELESS, "useless declaration\n"); dt_dprintf("type %s added as id %ld\n", dt_type_name( ddp->dd_ctfp, ddp->dd_type, n1, sizeof (n1)), ddp->dd_type); return (NULL); } if (strchr(dsp->ds_ident, '`') != NULL) { xyerror(D_DECL_SCOPE, "D scoping operator may not be used in " "a declaration name (%s)\n", dsp->ds_ident); } /* * If we are nested inside of a C include file, add the declaration to * the C definition module; otherwise use the D definition module. */ if (yypcb->pcb_idepth != 0) dmp = dtp->dt_cdefs; else dmp = dtp->dt_ddefs; /* * If we see a global or static declaration of a function prototype, * treat this as equivalent to a D extern declaration. */ if (ctf_type_kind(dtt.dtt_ctfp, dtt.dtt_type) == CTF_K_FUNCTION && (class == DT_DC_DEFAULT || class == DT_DC_STATIC)) class = DT_DC_EXTERN; switch (class) { case DT_DC_AUTO: case DT_DC_REGISTER: case DT_DC_STATIC: xyerror(D_DECL_BADCLASS, "specified storage class not " "appropriate in D\n"); /*NOTREACHED*/ case DT_DC_EXTERN: { dtrace_typeinfo_t ott; dtrace_syminfo_t dts; GElf_Sym sym; int exists = dtrace_lookup_by_name(dtp, dmp->dm_name, dsp->ds_ident, &sym, &dts) == 0; if (exists && (dtrace_symbol_type(dtp, &sym, &dts, &ott) != 0 || ctf_type_cmp(dtt.dtt_ctfp, dtt.dtt_type, ott.dtt_ctfp, ott.dtt_type) != 0)) { xyerror(D_DECL_IDRED, "identifier redeclared: %s`%s\n" "\t current: %s\n\tprevious: %s\n", dmp->dm_name, dsp->ds_ident, dt_type_name(dtt.dtt_ctfp, dtt.dtt_type, n1, sizeof (n1)), dt_type_name(ott.dtt_ctfp, ott.dtt_type, n2, sizeof (n2))); } else if (!exists && dt_module_extern(dtp, dmp, dsp->ds_ident, &dtt) == NULL) { xyerror(D_UNKNOWN, "failed to extern %s: %s\n", dsp->ds_ident, dtrace_errmsg(dtp, dtrace_errno(dtp))); } else { dt_dprintf("extern %s`%s type=<%s>\n", dmp->dm_name, dsp->ds_ident, dt_type_name(dtt.dtt_ctfp, dtt.dtt_type, n1, sizeof (n1))); } break; } case DT_DC_TYPEDEF: if (dt_idstack_lookup(&yypcb->pcb_globals, dsp->ds_ident)) { xyerror(D_DECL_IDRED, "global variable identifier " "redeclared: %s\n", dsp->ds_ident); } if (ctf_lookup_by_name(dmp->dm_ctfp, dsp->ds_ident) != CTF_ERR) { xyerror(D_DECL_IDRED, "typedef redeclared: %s\n", dsp->ds_ident); } /* * If the source type for the typedef is not defined in the * target container or its parent, copy the type to the target * container and reset dtt_ctfp and dtt_type to the copy. */ if (dtt.dtt_ctfp != dmp->dm_ctfp && dtt.dtt_ctfp != ctf_parent_file(dmp->dm_ctfp)) { dtt.dtt_type = ctf_add_type(dmp->dm_ctfp, dtt.dtt_ctfp, dtt.dtt_type); dtt.dtt_ctfp = dmp->dm_ctfp; if (dtt.dtt_type == CTF_ERR || ctf_update(dtt.dtt_ctfp) == CTF_ERR) { xyerror(D_UNKNOWN, "failed to copy typedef %s " "source type: %s\n", dsp->ds_ident, ctf_errmsg(ctf_errno(dtt.dtt_ctfp))); } } type = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, dsp->ds_ident, dtt.dtt_type); if (type == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) { xyerror(D_UNKNOWN, "failed to typedef %s: %s\n", dsp->ds_ident, ctf_errmsg(ctf_errno(dmp->dm_ctfp))); } dt_dprintf("typedef %s added as id %ld\n", dsp->ds_ident, type); break; default: { ctf_encoding_t cte; dt_idhash_t *dhp; dt_ident_t *idp; dt_node_t idn; int assc, idkind; uint_t id, kind; ushort_t idflags; switch (class) { case DT_DC_THIS: dhp = yypcb->pcb_locals; idflags = DT_IDFLG_LOCAL; idp = dt_idhash_lookup(dhp, dsp->ds_ident); break; case DT_DC_SELF: dhp = dtp->dt_tls; idflags = DT_IDFLG_TLS; idp = dt_idhash_lookup(dhp, dsp->ds_ident); break; default: dhp = dtp->dt_globals; idflags = 0; idp = dt_idstack_lookup( &yypcb->pcb_globals, dsp->ds_ident); break; } if (ddp->dd_kind == CTF_K_ARRAY && ddp->dd_node == NULL) { xyerror(D_DECL_ARRNULL, "array declaration requires array dimension or " "tuple signature: %s\n", dsp->ds_ident); } if (idp != NULL && idp->di_gen == 0) { xyerror(D_DECL_IDRED, "built-in identifier " "redeclared: %s\n", idp->di_name); } if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_CDEFS, dsp->ds_ident, NULL) == 0 || dtrace_lookup_by_type(dtp, DTRACE_OBJ_DDEFS, dsp->ds_ident, NULL) == 0) { xyerror(D_DECL_IDRED, "typedef identifier " "redeclared: %s\n", dsp->ds_ident); } /* * Cache some attributes of the decl to make the rest of this * code simpler: if the decl is an array which is subscripted * by a type rather than an integer, then it's an associative * array (assc). We then expect to match either DT_IDENT_ARRAY * for associative arrays or DT_IDENT_SCALAR for anything else. */ assc = ddp->dd_kind == CTF_K_ARRAY && ddp->dd_node->dn_kind == DT_NODE_TYPE; idkind = assc ? DT_IDENT_ARRAY : DT_IDENT_SCALAR; /* * Create a fake dt_node_t on the stack so we can determine the * type of any matching identifier by assigning to this node. * If the pre-existing ident has its di_type set, propagate * the type by hand so as not to trigger a prototype check for * arrays (yet); otherwise we use dt_ident_cook() on the ident * to ensure it is fully initialized before looking at it. */ bzero(&idn, sizeof (dt_node_t)); if (idp != NULL && idp->di_type != CTF_ERR) dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type, B_FALSE); else if (idp != NULL) (void) dt_ident_cook(&idn, idp, NULL); if (assc) { if (class == DT_DC_THIS) { xyerror(D_DECL_LOCASSC, "associative arrays " "may not be declared as local variables:" " %s\n", dsp->ds_ident); } if (dt_decl_type(ddp->dd_next, &dtt) != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } if (idp != NULL && (idp->di_kind != idkind || ctf_type_cmp(dtt.dtt_ctfp, dtt.dtt_type, idn.dn_ctfp, idn.dn_type) != 0)) { xyerror(D_DECL_IDRED, "identifier redeclared: %s\n" "\t current: %s %s\n\tprevious: %s %s\n", dsp->ds_ident, dt_idkind_name(idkind), dt_type_name(dtt.dtt_ctfp, dtt.dtt_type, n1, sizeof (n1)), dt_idkind_name(idp->di_kind), dt_node_type_name(&idn, n2, sizeof (n2))); } else if (idp != NULL && assc) { const dt_idsig_t *isp = idp->di_data; dt_node_t *dnp = ddp->dd_node; int argc = 0; for (; dnp != NULL; dnp = dnp->dn_list, argc++) { const dt_node_t *pnp = &isp->dis_args[argc]; if (argc >= isp->dis_argc) continue; /* tuple length mismatch */ if (ctf_type_cmp(dnp->dn_ctfp, dnp->dn_type, pnp->dn_ctfp, pnp->dn_type) == 0) continue; xyerror(D_DECL_IDRED, "identifier redeclared: %s\n" "\t current: %s, key #%d of type %s\n" "\tprevious: %s, key #%d of type %s\n", dsp->ds_ident, dt_idkind_name(idkind), argc + 1, dt_node_type_name(dnp, n1, sizeof (n1)), dt_idkind_name(idp->di_kind), argc + 1, dt_node_type_name(pnp, n2, sizeof (n2))); } if (isp->dis_argc != argc) { xyerror(D_DECL_IDRED, "identifier redeclared: %s\n" "\t current: %s of %s, tuple length %d\n" "\tprevious: %s of %s, tuple length %d\n", dsp->ds_ident, dt_idkind_name(idkind), dt_type_name(dtt.dtt_ctfp, dtt.dtt_type, n1, sizeof (n1)), argc, dt_idkind_name(idp->di_kind), dt_node_type_name(&idn, n2, sizeof (n2)), isp->dis_argc); } } else if (idp == NULL) { type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type); kind = ctf_type_kind(dtt.dtt_ctfp, type); switch (kind) { case CTF_K_INTEGER: if (ctf_type_encoding(dtt.dtt_ctfp, type, &cte) == 0 && IS_VOID(cte)) { xyerror(D_DECL_VOIDOBJ, "cannot have " "void object: %s\n", dsp->ds_ident); } break; case CTF_K_STRUCT: case CTF_K_UNION: if (ctf_type_size(dtt.dtt_ctfp, type) != 0) break; /* proceed to declaring */ /*FALLTHRU*/ case CTF_K_FORWARD: xyerror(D_DECL_INCOMPLETE, "incomplete struct/union/enum %s: %s\n", dt_type_name(dtt.dtt_ctfp, dtt.dtt_type, n1, sizeof (n1)), dsp->ds_ident); /*NOTREACHED*/ } if (dt_idhash_nextid(dhp, &id) == -1) { xyerror(D_ID_OFLOW, "cannot create %s: limit " "on number of %s variables exceeded\n", dsp->ds_ident, dt_idhash_name(dhp)); } dt_dprintf("declare %s %s variable %s, id=%u\n", dt_idhash_name(dhp), dt_idkind_name(idkind), dsp->ds_ident, id); idp = dt_idhash_insert(dhp, dsp->ds_ident, idkind, idflags | DT_IDFLG_WRITE | DT_IDFLG_DECL, id, _dtrace_defattr, 0, assc ? &dt_idops_assc : &dt_idops_thaw, NULL, dtp->dt_gen); if (idp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dt_ident_type_assign(idp, dtt.dtt_ctfp, dtt.dtt_type); /* * If we are declaring an associative array, use our * fake parse node to cook the new assoc identifier. * This will force the ident code to instantiate the * array type signature corresponding to the list of * types pointed to by ddp->dd_node. We also reset * the identifier's attributes based upon the result. */ if (assc) { idp->di_attr = dt_ident_cook(&idn, idp, &ddp->dd_node); } } } } /* end of switch */ free(dsp->ds_ident); dsp->ds_ident = NULL; return (NULL); } dt_node_t * dt_node_func(dt_node_t *dnp, dt_node_t *args) { dt_ident_t *idp; if (dnp->dn_kind != DT_NODE_IDENT) { xyerror(D_FUNC_IDENT, "function designator is not of function type\n"); } idp = dt_idstack_lookup(&yypcb->pcb_globals, dnp->dn_string); if (idp == NULL) { xyerror(D_FUNC_UNDEF, "undefined function name: %s\n", dnp->dn_string); } if (idp->di_kind != DT_IDENT_FUNC && idp->di_kind != DT_IDENT_AGGFUNC && idp->di_kind != DT_IDENT_ACTFUNC) { xyerror(D_FUNC_IDKIND, "%s '%s' may not be referenced as a " "function\n", dt_idkind_name(idp->di_kind), idp->di_name); } free(dnp->dn_string); dnp->dn_string = NULL; dnp->dn_kind = DT_NODE_FUNC; dnp->dn_flags &= ~DT_NF_COOKED; dnp->dn_ident = idp; dnp->dn_args = args; dnp->dn_list = NULL; return (dnp); } /* * The offsetof() function is special because it takes a type name as an * argument. It does not actually construct its own node; after looking up the * structure or union offset, we just return an integer node with the offset. */ dt_node_t * dt_node_offsetof(dt_decl_t *ddp, char *s) { dtrace_typeinfo_t dtt; dt_node_t dn; char *name; int err; ctf_membinfo_t ctm; ctf_id_t type; uint_t kind; name = alloca(strlen(s) + 1); (void) strcpy(name, s); free(s); err = dt_decl_type(ddp, &dtt); dt_decl_free(ddp); if (err != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type); kind = ctf_type_kind(dtt.dtt_ctfp, type); if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) { xyerror(D_OFFSETOF_TYPE, "offsetof operand must be a struct or union type\n"); } if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) { xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n", name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp))); } bzero(&dn, sizeof (dn)); dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE); if (dn.dn_flags & DT_NF_BITFIELD) { xyerror(D_OFFSETOF_BITFIELD, "cannot take offset of a bit-field: %s\n", name); } return (dt_node_int(ctm.ctm_offset / NBBY)); } dt_node_t * dt_node_op1(int op, dt_node_t *cp) { dt_node_t *dnp; if (cp->dn_kind == DT_NODE_INT) { switch (op) { case DT_TOK_INEG: /* * If we're negating an unsigned integer, zero out any * extra top bits to truncate the value to the size of * the effective type determined by dt_node_int(). */ cp->dn_value = -cp->dn_value; if (!(cp->dn_flags & DT_NF_SIGNED)) { cp->dn_value &= ~0ULL >> (64 - dt_node_type_size(cp) * NBBY); } /*FALLTHRU*/ case DT_TOK_IPOS: return (cp); case DT_TOK_BNEG: cp->dn_value = ~cp->dn_value; return (cp); case DT_TOK_LNEG: cp->dn_value = !cp->dn_value; return (cp); } } /* * If sizeof is applied to a type_name or string constant, we can * transform 'cp' into an integer constant in the node construction * pass so that it can then be used for arithmetic in this pass. */ if (op == DT_TOK_SIZEOF && (cp->dn_kind == DT_NODE_STRING || cp->dn_kind == DT_NODE_TYPE)) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; size_t size = dt_node_type_size(cp); if (size == 0) { xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an " "operand of unknown size\n"); } dt_node_type_assign(cp, dtp->dt_ddefs->dm_ctfp, ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"), B_FALSE); cp->dn_kind = DT_NODE_INT; cp->dn_op = DT_TOK_INT; cp->dn_value = size; return (cp); } dnp = dt_node_alloc(DT_NODE_OP1); assert(op <= USHRT_MAX); dnp->dn_op = (ushort_t)op; dnp->dn_child = cp; return (dnp); } /* * If an integer constant is being cast to another integer type, we can * perform the cast as part of integer constant folding in this pass. We must * take action when the integer is being cast to a smaller type or if it is * changing signed-ness. If so, we first shift rp's bits bits high (losing * excess bits if narrowing) and then shift them down with either a logical * shift (unsigned) or arithmetic shift (signed). */ static void dt_cast(dt_node_t *lp, dt_node_t *rp) { size_t srcsize = dt_node_type_size(rp); size_t dstsize = dt_node_type_size(lp); if (dstsize < srcsize) { int n = (sizeof (uint64_t) - dstsize) * NBBY; rp->dn_value <<= n; rp->dn_value >>= n; } else if (dstsize > srcsize) { int n = (sizeof (uint64_t) - srcsize) * NBBY; int s = (dstsize - srcsize) * NBBY; rp->dn_value <<= n; if (rp->dn_flags & DT_NF_SIGNED) { rp->dn_value = (intmax_t)rp->dn_value >> s; rp->dn_value >>= n - s; } else { rp->dn_value >>= n; } } } dt_node_t * dt_node_op2(int op, dt_node_t *lp, dt_node_t *rp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *dnp; /* * First we check for operations that are illegal -- namely those that * might result in integer division by zero, and abort if one is found. */ if (rp->dn_kind == DT_NODE_INT && rp->dn_value == 0 && (op == DT_TOK_MOD || op == DT_TOK_DIV || op == DT_TOK_MOD_EQ || op == DT_TOK_DIV_EQ)) xyerror(D_DIV_ZERO, "expression contains division by zero\n"); /* * If both children are immediate values, we can just perform inline * calculation and return a new immediate node with the result. */ if (lp->dn_kind == DT_NODE_INT && rp->dn_kind == DT_NODE_INT) { uintmax_t l = lp->dn_value; uintmax_t r = rp->dn_value; dnp = dt_node_int(0); /* allocate new integer node for result */ switch (op) { case DT_TOK_LOR: dnp->dn_value = l || r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_LXOR: dnp->dn_value = (l != 0) ^ (r != 0); dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_LAND: dnp->dn_value = l && r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_BOR: dnp->dn_value = l | r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_XOR: dnp->dn_value = l ^ r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_BAND: dnp->dn_value = l & r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_EQU: dnp->dn_value = l == r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_NEQ: dnp->dn_value = l != r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_LT: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l < (intmax_t)r; else dnp->dn_value = l < r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_LE: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l <= (intmax_t)r; else dnp->dn_value = l <= r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_GT: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l > (intmax_t)r; else dnp->dn_value = l > r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_GE: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l >= (intmax_t)r; else dnp->dn_value = l >= r; dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_LSH: dnp->dn_value = l << r; dt_node_type_propagate(lp, dnp); dt_node_attr_assign(rp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; case DT_TOK_RSH: dnp->dn_value = l >> r; dt_node_type_propagate(lp, dnp); dt_node_attr_assign(rp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; case DT_TOK_ADD: dnp->dn_value = l + r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_SUB: dnp->dn_value = l - r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_MUL: dnp->dn_value = l * r; dt_node_promote(lp, rp, dnp); break; case DT_TOK_DIV: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l / (intmax_t)r; else dnp->dn_value = l / r; break; case DT_TOK_MOD: dt_node_promote(lp, rp, dnp); if (dnp->dn_flags & DT_NF_SIGNED) dnp->dn_value = (intmax_t)l % (intmax_t)r; else dnp->dn_value = l % r; break; default: dt_node_free(dnp); dnp = NULL; } if (dnp != NULL) { dt_node_free(lp); dt_node_free(rp); return (dnp); } } if (op == DT_TOK_LPAR && rp->dn_kind == DT_NODE_INT && dt_node_is_integer(lp)) { dt_cast(lp, rp); dt_node_type_propagate(lp, rp); dt_node_attr_assign(rp, dt_attr_min(lp->dn_attr, rp->dn_attr)); dt_node_free(lp); return (rp); } /* * If no immediate optimizations are available, create an new OP2 node * and glue the left and right children into place and return. */ dnp = dt_node_alloc(DT_NODE_OP2); assert(op <= USHRT_MAX); dnp->dn_op = (ushort_t)op; dnp->dn_left = lp; dnp->dn_right = rp; return (dnp); } dt_node_t * dt_node_op3(dt_node_t *expr, dt_node_t *lp, dt_node_t *rp) { dt_node_t *dnp; if (expr->dn_kind == DT_NODE_INT) return (expr->dn_value != 0 ? lp : rp); dnp = dt_node_alloc(DT_NODE_OP3); dnp->dn_op = DT_TOK_QUESTION; dnp->dn_expr = expr; dnp->dn_left = lp; dnp->dn_right = rp; return (dnp); } dt_node_t * dt_node_statement(dt_node_t *expr) { dt_node_t *dnp; if (expr->dn_kind == DT_NODE_AGG) return (expr); if (expr->dn_kind == DT_NODE_FUNC && expr->dn_ident->di_kind == DT_IDENT_ACTFUNC) dnp = dt_node_alloc(DT_NODE_DFUNC); else dnp = dt_node_alloc(DT_NODE_DEXPR); dnp->dn_expr = expr; return (dnp); } dt_node_t * +dt_node_if(dt_node_t *pred, dt_node_t *acts, dt_node_t *else_acts) +{ + dt_node_t *dnp = dt_node_alloc(DT_NODE_IF); + dnp->dn_conditional = pred; + dnp->dn_body = acts; + dnp->dn_alternate_body = else_acts; + + return (dnp); +} + +dt_node_t * dt_node_pdesc_by_name(char *spec) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *dnp; if (spec == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dnp = dt_node_alloc(DT_NODE_PDESC); dnp->dn_spec = spec; dnp->dn_desc = malloc(sizeof (dtrace_probedesc_t)); if (dnp->dn_desc == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (dtrace_xstr2desc(dtp, yypcb->pcb_pspec, dnp->dn_spec, yypcb->pcb_sargc, yypcb->pcb_sargv, dnp->dn_desc) != 0) { xyerror(D_PDESC_INVAL, "invalid probe description \"%s\": %s\n", dnp->dn_spec, dtrace_errmsg(dtp, dtrace_errno(dtp))); } free(dnp->dn_spec); dnp->dn_spec = NULL; return (dnp); } dt_node_t * dt_node_pdesc_by_id(uintmax_t id) { static const char *const names[] = { "providers", "modules", "functions" }; dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *dnp = dt_node_alloc(DT_NODE_PDESC); if ((dnp->dn_desc = malloc(sizeof (dtrace_probedesc_t))) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (id > UINT_MAX) { xyerror(D_PDESC_INVAL, "identifier %llu exceeds maximum " "probe id\n", (u_longlong_t)id); } if (yypcb->pcb_pspec != DTRACE_PROBESPEC_NAME) { xyerror(D_PDESC_INVAL, "probe identifier %llu not permitted " "when specifying %s\n", (u_longlong_t)id, names[yypcb->pcb_pspec]); } if (dtrace_id2desc(dtp, (dtrace_id_t)id, dnp->dn_desc) != 0) { xyerror(D_PDESC_INVAL, "invalid probe identifier %llu: %s\n", (u_longlong_t)id, dtrace_errmsg(dtp, dtrace_errno(dtp))); } return (dnp); } dt_node_t * dt_node_clause(dt_node_t *pdescs, dt_node_t *pred, dt_node_t *acts) { dt_node_t *dnp = dt_node_alloc(DT_NODE_CLAUSE); dnp->dn_pdescs = pdescs; dnp->dn_pred = pred; dnp->dn_acts = acts; - yybegin(YYS_CLAUSE); return (dnp); } dt_node_t * dt_node_inline(dt_node_t *expr) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_scope_t *dsp = &yypcb->pcb_dstack; dt_decl_t *ddp = dt_decl_top(); char n[DT_TYPE_NAMELEN]; dtrace_typeinfo_t dtt; dt_ident_t *idp, *rdp; dt_idnode_t *inp; dt_node_t *dnp; if (dt_decl_type(ddp, &dtt) != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); if (dsp->ds_class != DT_DC_DEFAULT) { xyerror(D_DECL_BADCLASS, "specified storage class not " "appropriate for inline declaration\n"); } if (dsp->ds_ident == NULL) xyerror(D_DECL_USELESS, "inline declaration requires a name\n"); if ((idp = dt_idstack_lookup( &yypcb->pcb_globals, dsp->ds_ident)) != NULL) { xyerror(D_DECL_IDRED, "identifier redefined: %s\n\t current: " "inline definition\n\tprevious: %s %s\n", idp->di_name, dt_idkind_name(idp->di_kind), (idp->di_flags & DT_IDFLG_INLINE) ? "inline" : ""); } /* * If we are declaring an inlined array, verify that we have a tuple * signature, and then recompute 'dtt' as the array's value type. */ if (ddp->dd_kind == CTF_K_ARRAY) { if (ddp->dd_node == NULL) { xyerror(D_DECL_ARRNULL, "inline declaration requires " "array tuple signature: %s\n", dsp->ds_ident); } if (ddp->dd_node->dn_kind != DT_NODE_TYPE) { xyerror(D_DECL_ARRNULL, "inline declaration cannot be " "of scalar array type: %s\n", dsp->ds_ident); } if (dt_decl_type(ddp->dd_next, &dtt) != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } /* * If the inline identifier is not defined, then create it with the * orphan flag set. We do not insert the identifier into dt_globals * until we have successfully cooked the right-hand expression, below. */ dnp = dt_node_alloc(DT_NODE_INLINE); dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, B_FALSE); dt_node_attr_assign(dnp, _dtrace_defattr); if (dt_node_is_void(dnp)) { xyerror(D_DECL_VOIDOBJ, "cannot declare void inline: %s\n", dsp->ds_ident); } if (ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve( dnp->dn_ctfp, dnp->dn_type)) == CTF_K_FORWARD) { xyerror(D_DECL_INCOMPLETE, "incomplete struct/union/enum %s: %s\n", dt_node_type_name(dnp, n, sizeof (n)), dsp->ds_ident); } if ((inp = malloc(sizeof (dt_idnode_t))) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); bzero(inp, sizeof (dt_idnode_t)); idp = dnp->dn_ident = dt_ident_create(dsp->ds_ident, ddp->dd_kind == CTF_K_ARRAY ? DT_IDENT_ARRAY : DT_IDENT_SCALAR, DT_IDFLG_INLINE | DT_IDFLG_REF | DT_IDFLG_DECL | DT_IDFLG_ORPHAN, 0, _dtrace_defattr, 0, &dt_idops_inline, inp, dtp->dt_gen); if (idp == NULL) { free(inp); longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); } /* * If we're inlining an associative array, create a private identifier * hash containing the named parameters and store it in inp->din_hash. * We then push this hash on to the top of the pcb_globals stack. */ if (ddp->dd_kind == CTF_K_ARRAY) { dt_idnode_t *pinp; dt_ident_t *pidp; dt_node_t *pnp; uint_t i = 0; for (pnp = ddp->dd_node; pnp != NULL; pnp = pnp->dn_list) i++; /* count up parameters for din_argv[] */ inp->din_hash = dt_idhash_create("inline args", NULL, 0, 0); inp->din_argv = calloc(i, sizeof (dt_ident_t *)); if (inp->din_hash == NULL || inp->din_argv == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); /* * Create an identifier for each parameter as a scalar inline, * and store it in din_hash and in position in din_argv[]. The * parameter identifiers also use dt_idops_inline, but we leave * the dt_idnode_t argument 'pinp' zeroed. This will be filled * in by the code generation pass with references to the args. */ for (i = 0, pnp = ddp->dd_node; pnp != NULL; pnp = pnp->dn_list, i++) { if (pnp->dn_string == NULL) continue; /* ignore anonymous parameters */ if ((pinp = malloc(sizeof (dt_idnode_t))) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); pidp = dt_idhash_insert(inp->din_hash, pnp->dn_string, DT_IDENT_SCALAR, DT_IDFLG_DECL | DT_IDFLG_INLINE, 0, _dtrace_defattr, 0, &dt_idops_inline, pinp, dtp->dt_gen); if (pidp == NULL) { free(pinp); longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); } inp->din_argv[i] = pidp; bzero(pinp, sizeof (dt_idnode_t)); dt_ident_type_assign(pidp, pnp->dn_ctfp, pnp->dn_type); } dt_idstack_push(&yypcb->pcb_globals, inp->din_hash); } /* * Unlike most constructors, we need to explicitly cook the right-hand * side of the inline definition immediately to prevent recursion. If * the right-hand side uses the inline itself, the cook will fail. */ expr = dt_node_cook(expr, DT_IDFLG_REF); if (ddp->dd_kind == CTF_K_ARRAY) dt_idstack_pop(&yypcb->pcb_globals, inp->din_hash); /* * Set the type, attributes, and flags for the inline. If the right- * hand expression has an identifier, propagate its flags. Then cook * the identifier to fully initialize it: if we're declaring an inline * associative array this will construct a type signature from 'ddp'. */ if (dt_node_is_dynamic(expr)) rdp = dt_ident_resolve(expr->dn_ident); else if (expr->dn_kind == DT_NODE_VAR || expr->dn_kind == DT_NODE_SYM) rdp = expr->dn_ident; else rdp = NULL; if (rdp != NULL) { idp->di_flags |= (rdp->di_flags & (DT_IDFLG_WRITE | DT_IDFLG_USER | DT_IDFLG_PRIM)); } idp->di_attr = dt_attr_min(_dtrace_defattr, expr->dn_attr); dt_ident_type_assign(idp, dtt.dtt_ctfp, dtt.dtt_type); (void) dt_ident_cook(dnp, idp, &ddp->dd_node); /* * Store the parse tree nodes for 'expr' inside of idp->di_data ('inp') * so that they will be preserved with this identifier. Then pop the * inline declaration from the declaration stack and restore the lexer. */ inp->din_list = yypcb->pcb_list; inp->din_root = expr; dt_decl_free(dt_decl_pop()); yybegin(YYS_CLAUSE); /* * Finally, insert the inline identifier into dt_globals to make it * visible, and then cook 'dnp' to check its type against 'expr'. */ dt_idhash_xinsert(dtp->dt_globals, idp); return (dt_node_cook(dnp, DT_IDFLG_REF)); } dt_node_t * dt_node_member(dt_decl_t *ddp, char *name, dt_node_t *expr) { dtrace_typeinfo_t dtt; dt_node_t *dnp; int err; if (ddp != NULL) { err = dt_decl_type(ddp, &dtt); dt_decl_free(ddp); if (err != 0) longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } dnp = dt_node_alloc(DT_NODE_MEMBER); dnp->dn_membname = name; dnp->dn_membexpr = expr; if (ddp != NULL) dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags); return (dnp); } dt_node_t * dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dtrace_typeinfo_t src, dst; dt_node_t sn, dn; dt_xlator_t *dxp; dt_node_t *dnp; int edst, esrc; uint_t kind; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; edst = dt_decl_type(ddp, &dst); dt_decl_free(ddp); esrc = dt_decl_type(sdp, &src); dt_decl_free(sdp); if (edst != 0 || esrc != 0) { free(name); longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } bzero(&sn, sizeof (sn)); dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type, B_FALSE); bzero(&dn, sizeof (dn)); dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type, B_FALSE); if (dt_xlator_lookup(dtp, &sn, &dn, DT_XLATE_EXACT) != NULL) { xyerror(D_XLATE_REDECL, "translator from %s to %s has already been declared\n", dt_node_type_name(&sn, n1, sizeof (n1)), dt_node_type_name(&dn, n2, sizeof (n2))); } kind = ctf_type_kind(dst.dtt_ctfp, ctf_type_resolve(dst.dtt_ctfp, dst.dtt_type)); if (kind == CTF_K_FORWARD) { xyerror(D_XLATE_SOU, "incomplete struct/union/enum %s\n", dt_type_name(dst.dtt_ctfp, dst.dtt_type, n1, sizeof (n1))); } if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) { xyerror(D_XLATE_SOU, "translator output type must be a struct or union\n"); } dxp = dt_xlator_create(dtp, &src, &dst, name, members, yypcb->pcb_list); yybegin(YYS_CLAUSE); free(name); if (dxp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dnp = dt_node_alloc(DT_NODE_XLATOR); dnp->dn_xlator = dxp; dnp->dn_members = members; return (dt_node_cook(dnp, DT_IDFLG_REF)); } dt_node_t * dt_node_probe(char *s, int protoc, dt_node_t *nargs, dt_node_t *xargs) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; int nargc, xargc; dt_node_t *dnp; size_t len = strlen(s) + 3; /* +3 for :: and \0 */ char *name = alloca(len); (void) snprintf(name, len, "::%s", s); (void) strhyphenate(name); free(s); if (strchr(name, '`') != NULL) { xyerror(D_PROV_BADNAME, "probe name may not " "contain scoping operator: %s\n", name); } if (strlen(name) - 2 >= DTRACE_NAMELEN) { xyerror(D_PROV_BADNAME, "probe name may not exceed %d " "characters: %s\n", DTRACE_NAMELEN - 1, name); } dnp = dt_node_alloc(DT_NODE_PROBE); dnp->dn_ident = dt_ident_create(name, DT_IDENT_PROBE, DT_IDFLG_ORPHAN, DTRACE_IDNONE, _dtrace_defattr, 0, &dt_idops_probe, NULL, dtp->dt_gen); nargc = dt_decl_prototype(nargs, nargs, "probe input", DT_DP_VOID | DT_DP_ANON); xargc = dt_decl_prototype(xargs, nargs, "probe output", DT_DP_VOID); if (nargc > UINT8_MAX) { xyerror(D_PROV_PRARGLEN, "probe %s input prototype exceeds %u " "parameters: %d params used\n", name, UINT8_MAX, nargc); } if (xargc > UINT8_MAX) { xyerror(D_PROV_PRARGLEN, "probe %s output prototype exceeds %u " "parameters: %d params used\n", name, UINT8_MAX, xargc); } if (dnp->dn_ident == NULL || dt_probe_create(dtp, dnp->dn_ident, protoc, nargs, nargc, xargs, xargc) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); return (dnp); } dt_node_t * dt_node_provider(char *name, dt_node_t *probes) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *dnp = dt_node_alloc(DT_NODE_PROVIDER); dt_node_t *lnp; size_t len; dnp->dn_provname = name; dnp->dn_probes = probes; if (strchr(name, '`') != NULL) { dnerror(dnp, D_PROV_BADNAME, "provider name may not " "contain scoping operator: %s\n", name); } if ((len = strlen(name)) >= DTRACE_PROVNAMELEN) { dnerror(dnp, D_PROV_BADNAME, "provider name may not exceed %d " "characters: %s\n", DTRACE_PROVNAMELEN - 1, name); } if (isdigit(name[len - 1])) { dnerror(dnp, D_PROV_BADNAME, "provider name may not " "end with a digit: %s\n", name); } /* * Check to see if the provider is already defined or visible through * dtrace(7D). If so, set dn_provred to treat it as a re-declaration. * If not, create a new provider and set its interface-only flag. This * flag may be cleared later by calls made to dt_probe_declare(). */ if ((dnp->dn_provider = dt_provider_lookup(dtp, name)) != NULL) dnp->dn_provred = B_TRUE; else if ((dnp->dn_provider = dt_provider_create(dtp, name)) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); else dnp->dn_provider->pv_flags |= DT_PROVIDER_INTF; /* * Store all parse nodes created since we consumed the DT_KEY_PROVIDER * token with the provider and then restore our lexing state to CLAUSE. * Note that if dnp->dn_provred is true, we may end up storing dups of * a provider's interface and implementation: we eat this space because * the implementation will likely need to redeclare probe members, and * therefore may result in those member nodes becoming persistent. */ for (lnp = yypcb->pcb_list; lnp->dn_link != NULL; lnp = lnp->dn_link) continue; /* skip to end of allocation list */ lnp->dn_link = dnp->dn_provider->pv_nodes; dnp->dn_provider->pv_nodes = yypcb->pcb_list; yybegin(YYS_CLAUSE); return (dnp); } dt_node_t * dt_node_program(dt_node_t *lnp) { dt_node_t *dnp = dt_node_alloc(DT_NODE_PROG); dnp->dn_list = lnp; return (dnp); } /* * This function provides the underlying implementation of cooking an * identifier given its node, a hash of dynamic identifiers, an identifier * kind, and a boolean flag indicating whether we are allowed to instantiate * a new identifier if the string is not found. This function is either * called from dt_cook_ident(), below, or directly by the various cooking * routines that are allowed to instantiate identifiers (e.g. op2 TOK_ASGN). */ static void dt_xcook_ident(dt_node_t *dnp, dt_idhash_t *dhp, uint_t idkind, int create) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; const char *sname = dt_idhash_name(dhp); int uref = 0; dtrace_attribute_t attr = _dtrace_defattr; dt_ident_t *idp; dtrace_syminfo_t dts; GElf_Sym sym; const char *scope, *mark; uchar_t dnkind; char *name; /* * Look for scoping marks in the identifier. If one is found, set our * scope to either DTRACE_OBJ_KMODS or UMODS or to the first part of * the string that specifies the scope using an explicit module name. * If two marks in a row are found, set 'uref' (user symbol reference). * Otherwise we set scope to DTRACE_OBJ_EXEC, indicating that normal * scope is desired and we should search the specified idhash. */ if ((name = strrchr(dnp->dn_string, '`')) != NULL) { if (name > dnp->dn_string && name[-1] == '`') { uref++; name[-1] = '\0'; } if (name == dnp->dn_string + uref) scope = uref ? DTRACE_OBJ_UMODS : DTRACE_OBJ_KMODS; else scope = dnp->dn_string; *name++ = '\0'; /* leave name pointing after scoping mark */ dnkind = DT_NODE_VAR; } else if (idkind == DT_IDENT_AGG) { scope = DTRACE_OBJ_EXEC; name = dnp->dn_string + 1; dnkind = DT_NODE_AGG; } else { scope = DTRACE_OBJ_EXEC; name = dnp->dn_string; dnkind = DT_NODE_VAR; } /* * If create is set to false, and we fail our idhash lookup, preset * the errno code to EDT_NOVAR for our final error message below. * If we end up calling dtrace_lookup_by_name(), it will reset the * errno appropriately and that error will be reported instead. */ (void) dt_set_errno(dtp, EDT_NOVAR); mark = uref ? "``" : "`"; if (scope == DTRACE_OBJ_EXEC && ( (dhp != dtp->dt_globals && (idp = dt_idhash_lookup(dhp, name)) != NULL) || (dhp == dtp->dt_globals && (idp = dt_idstack_lookup(&yypcb->pcb_globals, name)) != NULL))) { /* * Check that we are referencing the ident in the manner that * matches its type if this is a global lookup. In the TLS or * local case, we don't know how the ident will be used until * the time operator -> is seen; more parsing is needed. */ if (idp->di_kind != idkind && dhp == dtp->dt_globals) { xyerror(D_IDENT_BADREF, "%s '%s' may not be referenced " "as %s\n", dt_idkind_name(idp->di_kind), idp->di_name, dt_idkind_name(idkind)); } /* * Arrays and aggregations are not cooked individually. They * have dynamic types and must be referenced using operator []. * This is handled explicitly by the code for DT_TOK_LBRAC. */ if (idp->di_kind != DT_IDENT_ARRAY && idp->di_kind != DT_IDENT_AGG) attr = dt_ident_cook(dnp, idp, NULL); else { dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); attr = idp->di_attr; } free(dnp->dn_string); dnp->dn_string = NULL; dnp->dn_kind = dnkind; dnp->dn_ident = idp; dnp->dn_flags |= DT_NF_LVALUE; if (idp->di_flags & DT_IDFLG_WRITE) dnp->dn_flags |= DT_NF_WRITABLE; dt_node_attr_assign(dnp, attr); } else if (dhp == dtp->dt_globals && scope != DTRACE_OBJ_EXEC && dtrace_lookup_by_name(dtp, scope, name, &sym, &dts) == 0) { dt_module_t *mp = dt_module_lookup_by_name(dtp, dts.dts_object); int umod = (mp->dm_flags & DT_DM_KERNEL) == 0; static const char *const kunames[] = { "kernel", "user" }; dtrace_typeinfo_t dtt; dtrace_syminfo_t *sip; if (uref ^ umod) { xyerror(D_SYM_BADREF, "%s module '%s' symbol '%s' may " "not be referenced as a %s symbol\n", kunames[umod], dts.dts_object, dts.dts_name, kunames[uref]); } if (dtrace_symbol_type(dtp, &sym, &dts, &dtt) != 0) { /* * For now, we special-case EDT_DATAMODEL to clarify * that mixed data models are not currently supported. */ if (dtp->dt_errno == EDT_DATAMODEL) { xyerror(D_SYM_MODEL, "cannot use %s symbol " "%s%s%s in a %s D program\n", dt_module_modelname(mp), dts.dts_object, mark, dts.dts_name, dt_module_modelname(dtp->dt_ddefs)); } xyerror(D_SYM_NOTYPES, "no symbolic type information is available for " "%s%s%s: %s\n", dts.dts_object, mark, dts.dts_name, dtrace_errmsg(dtp, dtrace_errno(dtp))); } idp = dt_ident_create(name, DT_IDENT_SYMBOL, 0, 0, _dtrace_symattr, 0, &dt_idops_thaw, NULL, dtp->dt_gen); if (idp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (mp->dm_flags & DT_DM_PRIMARY) idp->di_flags |= DT_IDFLG_PRIM; idp->di_next = dtp->dt_externs; dtp->dt_externs = idp; if ((sip = malloc(sizeof (dtrace_syminfo_t))) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); bcopy(&dts, sip, sizeof (dtrace_syminfo_t)); idp->di_data = sip; idp->di_ctfp = dtt.dtt_ctfp; idp->di_type = dtt.dtt_type; free(dnp->dn_string); dnp->dn_string = NULL; dnp->dn_kind = DT_NODE_SYM; dnp->dn_ident = idp; dnp->dn_flags |= DT_NF_LVALUE; dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags); dt_node_attr_assign(dnp, _dtrace_symattr); if (uref) { idp->di_flags |= DT_IDFLG_USER; dnp->dn_flags |= DT_NF_USERLAND; } } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) { uint_t flags = DT_IDFLG_WRITE; uint_t id; if (dt_idhash_nextid(dhp, &id) == -1) { xyerror(D_ID_OFLOW, "cannot create %s: limit on number " "of %s variables exceeded\n", name, sname); } if (dhp == yypcb->pcb_locals) flags |= DT_IDFLG_LOCAL; else if (dhp == dtp->dt_tls) flags |= DT_IDFLG_TLS; dt_dprintf("create %s %s variable %s, id=%u\n", sname, dt_idkind_name(idkind), name, id); if (idkind == DT_IDENT_ARRAY || idkind == DT_IDENT_AGG) { idp = dt_idhash_insert(dhp, name, idkind, flags, id, _dtrace_defattr, 0, &dt_idops_assc, NULL, dtp->dt_gen); } else { idp = dt_idhash_insert(dhp, name, idkind, flags, id, _dtrace_defattr, 0, &dt_idops_thaw, NULL, dtp->dt_gen); } if (idp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); /* * Arrays and aggregations are not cooked individually. They * have dynamic types and must be referenced using operator []. * This is handled explicitly by the code for DT_TOK_LBRAC. */ if (idp->di_kind != DT_IDENT_ARRAY && idp->di_kind != DT_IDENT_AGG) attr = dt_ident_cook(dnp, idp, NULL); else { dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); attr = idp->di_attr; } free(dnp->dn_string); dnp->dn_string = NULL; dnp->dn_kind = dnkind; dnp->dn_ident = idp; dnp->dn_flags |= DT_NF_LVALUE | DT_NF_WRITABLE; dt_node_attr_assign(dnp, attr); } else if (scope != DTRACE_OBJ_EXEC) { xyerror(D_IDENT_UNDEF, "failed to resolve %s%s%s: %s\n", dnp->dn_string, mark, name, dtrace_errmsg(dtp, dtrace_errno(dtp))); } else { xyerror(D_IDENT_UNDEF, "failed to resolve %s: %s\n", dnp->dn_string, dtrace_errmsg(dtp, dtrace_errno(dtp))); } } static dt_node_t * dt_cook_ident(dt_node_t *dnp, uint_t idflags) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; if (dnp->dn_op == DT_TOK_AGG) dt_xcook_ident(dnp, dtp->dt_aggs, DT_IDENT_AGG, B_FALSE); else dt_xcook_ident(dnp, dtp->dt_globals, DT_IDENT_SCALAR, B_FALSE); return (dt_node_cook(dnp, idflags)); } /* * Since operators [ and -> can instantiate new variables before we know * whether the reference is for a read or a write, we need to check read * references to determine if the identifier is currently dt_ident_unref(). * If so, we report that this first access was to an undefined variable. */ static dt_node_t * dt_cook_var(dt_node_t *dnp, uint_t idflags) { dt_ident_t *idp = dnp->dn_ident; if ((idflags & DT_IDFLG_REF) && dt_ident_unref(idp)) { dnerror(dnp, D_VAR_UNDEF, "%s%s has not yet been declared or assigned\n", (idp->di_flags & DT_IDFLG_LOCAL) ? "this->" : (idp->di_flags & DT_IDFLG_TLS) ? "self->" : "", idp->di_name); } dt_node_attr_assign(dnp, dt_ident_cook(dnp, idp, &dnp->dn_args)); return (dnp); } /*ARGSUSED*/ static dt_node_t * dt_cook_func(dt_node_t *dnp, uint_t idflags) { dt_node_attr_assign(dnp, dt_ident_cook(dnp, dnp->dn_ident, &dnp->dn_args)); return (dnp); } static dt_node_t * dt_cook_op1(dt_node_t *dnp, uint_t idflags) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *cp = dnp->dn_child; char n[DT_TYPE_NAMELEN]; dtrace_typeinfo_t dtt; dt_ident_t *idp; ctf_encoding_t e; ctf_arinfo_t r; ctf_id_t type, base; uint_t kind; if (dnp->dn_op == DT_TOK_PREINC || dnp->dn_op == DT_TOK_POSTINC || dnp->dn_op == DT_TOK_PREDEC || dnp->dn_op == DT_TOK_POSTDEC) idflags = DT_IDFLG_REF | DT_IDFLG_MOD; else idflags = DT_IDFLG_REF; /* * We allow the unary ++ and -- operators to instantiate new scalar * variables if applied to an identifier; otherwise just cook as usual. */ if (cp->dn_kind == DT_NODE_IDENT && (idflags & DT_IDFLG_MOD)) dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE); cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */ if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) { if (dt_type_lookup("int64_t", &dtt) != 0) xyerror(D_TYPE_ERR, "failed to lookup int64_t\n"); dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type); dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags); } if (cp->dn_kind == DT_NODE_VAR) cp->dn_ident->di_flags |= idflags; switch (dnp->dn_op) { case DT_TOK_DEREF: /* * If the deref operator is applied to a translated pointer, * we set our output type to the output of the translation. */ if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) { dt_xlator_t *dxp = idp->di_data; dnp->dn_ident = &dxp->dx_souid; dt_node_type_assign(dnp, dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type, cp->dn_flags & DT_NF_USERLAND); break; } type = ctf_type_resolve(cp->dn_ctfp, cp->dn_type); kind = ctf_type_kind(cp->dn_ctfp, type); if (kind == CTF_K_ARRAY) { if (ctf_array_info(cp->dn_ctfp, type, &r) != 0) { dtp->dt_ctferr = ctf_errno(cp->dn_ctfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } else type = r.ctr_contents; } else if (kind == CTF_K_POINTER) { type = ctf_type_reference(cp->dn_ctfp, type); } else { xyerror(D_DEREF_NONPTR, "cannot dereference non-pointer type\n"); } dt_node_type_assign(dnp, cp->dn_ctfp, type, cp->dn_flags & DT_NF_USERLAND); base = ctf_type_resolve(cp->dn_ctfp, type); kind = ctf_type_kind(cp->dn_ctfp, base); if (kind == CTF_K_INTEGER && ctf_type_encoding(cp->dn_ctfp, base, &e) == 0 && IS_VOID(e)) { xyerror(D_DEREF_VOID, "cannot dereference pointer to void\n"); } if (kind == CTF_K_FUNCTION) { xyerror(D_DEREF_FUNC, "cannot dereference pointer to function\n"); } if (kind != CTF_K_ARRAY || dt_node_is_string(dnp)) dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.4.3] */ /* * If we propagated the l-value bit and the child operand was * a writable D variable or a binary operation of the form * a + b where a is writable, then propagate the writable bit. * This is necessary to permit assignments to scalar arrays, * which are converted to expressions of the form *(a + i). */ if ((cp->dn_flags & DT_NF_WRITABLE) || (cp->dn_kind == DT_NODE_OP2 && cp->dn_op == DT_TOK_ADD && (cp->dn_left->dn_flags & DT_NF_WRITABLE))) dnp->dn_flags |= DT_NF_WRITABLE; if ((cp->dn_flags & DT_NF_USERLAND) && (kind == CTF_K_POINTER || (dnp->dn_flags & DT_NF_REF))) dnp->dn_flags |= DT_NF_USERLAND; break; case DT_TOK_IPOS: case DT_TOK_INEG: if (!dt_node_is_arith(cp)) { xyerror(D_OP_ARITH, "operator %s requires an operand " "of arithmetic type\n", opstr(dnp->dn_op)); } dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */ break; case DT_TOK_BNEG: if (!dt_node_is_integer(cp)) { xyerror(D_OP_INT, "operator %s requires an operand of " "integral type\n", opstr(dnp->dn_op)); } dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */ break; case DT_TOK_LNEG: if (!dt_node_is_scalar(cp)) { xyerror(D_OP_SCALAR, "operator %s requires an operand " "of scalar type\n", opstr(dnp->dn_op)); } dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); break; case DT_TOK_ADDROF: if (cp->dn_kind == DT_NODE_VAR || cp->dn_kind == DT_NODE_AGG) { xyerror(D_ADDROF_VAR, "cannot take address of dynamic variable\n"); } if (dt_node_is_dynamic(cp)) { xyerror(D_ADDROF_VAR, "cannot take address of dynamic object\n"); } if (!(cp->dn_flags & DT_NF_LVALUE)) { xyerror(D_ADDROF_LVAL, /* see K&R[A7.4.2] */ "unacceptable operand for unary & operator\n"); } if (cp->dn_flags & DT_NF_BITFIELD) { xyerror(D_ADDROF_BITFIELD, "cannot take address of bit-field\n"); } dtt.dtt_object = NULL; dtt.dtt_ctfp = cp->dn_ctfp; dtt.dtt_type = cp->dn_type; if (dt_type_pointer(&dtt) == -1) { xyerror(D_TYPE_ERR, "cannot find type for \"&\": %s*\n", dt_node_type_name(cp, n, sizeof (n))); } dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, cp->dn_flags & DT_NF_USERLAND); break; case DT_TOK_SIZEOF: if (cp->dn_flags & DT_NF_BITFIELD) { xyerror(D_SIZEOF_BITFIELD, "cannot apply sizeof to a bit-field\n"); } if (dt_node_sizeof(cp) == 0) { xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an " "operand of unknown size\n"); } dt_node_type_assign(dnp, dtp->dt_ddefs->dm_ctfp, ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"), B_FALSE); break; case DT_TOK_STRINGOF: if (!dt_node_is_scalar(cp) && !dt_node_is_pointer(cp) && !dt_node_is_strcompat(cp)) { xyerror(D_STRINGOF_TYPE, "cannot apply stringof to a value of type %s\n", dt_node_type_name(cp, n, sizeof (n))); } dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), cp->dn_flags & DT_NF_USERLAND); break; case DT_TOK_PREINC: case DT_TOK_POSTINC: case DT_TOK_PREDEC: case DT_TOK_POSTDEC: if (dt_node_is_scalar(cp) == 0) { xyerror(D_OP_SCALAR, "operator %s requires operand of " "scalar type\n", opstr(dnp->dn_op)); } if (dt_node_is_vfptr(cp)) { xyerror(D_OP_VFPTR, "operator %s requires an operand " "of known size\n", opstr(dnp->dn_op)); } if (!(cp->dn_flags & DT_NF_LVALUE)) { xyerror(D_OP_LVAL, "operator %s requires modifiable " "lvalue as an operand\n", opstr(dnp->dn_op)); } if (!(cp->dn_flags & DT_NF_WRITABLE)) { xyerror(D_OP_WRITE, "operator %s can only be applied " "to a writable variable\n", opstr(dnp->dn_op)); } dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.1] */ break; default: xyerror(D_UNKNOWN, "invalid unary op %s\n", opstr(dnp->dn_op)); } dt_node_attr_assign(dnp, cp->dn_attr); return (dnp); } static void dt_assign_common(dt_node_t *dnp) { dt_node_t *lp = dnp->dn_left; dt_node_t *rp = dnp->dn_right; int op = dnp->dn_op; if (rp->dn_kind == DT_NODE_INT) dt_cast(lp, rp); if (!(lp->dn_flags & DT_NF_LVALUE)) { xyerror(D_OP_LVAL, "operator %s requires modifiable " "lvalue as an operand\n", opstr(op)); /* see K&R[A7.17] */ } if (!(lp->dn_flags & DT_NF_WRITABLE)) { xyerror(D_OP_WRITE, "operator %s can only be applied " "to a writable variable\n", opstr(op)); } dt_node_type_propagate(lp, dnp); /* see K&R[A7.17] */ dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); } static dt_node_t * dt_cook_op2(dt_node_t *dnp, uint_t idflags) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *lp = dnp->dn_left; dt_node_t *rp = dnp->dn_right; int op = dnp->dn_op; ctf_membinfo_t m; ctf_file_t *ctfp; ctf_id_t type; int kind, val, uref; dt_ident_t *idp; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; /* * The expression E1[E2] is identical by definition to *((E1)+(E2)) so * we convert "[" to "+" and glue on "*" at the end (see K&R[A7.3.1]) * unless the left-hand side is an untyped D scalar, associative array, * or aggregation. In these cases, we proceed to case DT_TOK_LBRAC and * handle associative array and aggregation references there. */ if (op == DT_TOK_LBRAC) { if (lp->dn_kind == DT_NODE_IDENT) { dt_idhash_t *dhp; uint_t idkind; if (lp->dn_op == DT_TOK_AGG) { dhp = dtp->dt_aggs; idp = dt_idhash_lookup(dhp, lp->dn_string + 1); idkind = DT_IDENT_AGG; } else { dhp = dtp->dt_globals; idp = dt_idstack_lookup( &yypcb->pcb_globals, lp->dn_string); idkind = DT_IDENT_ARRAY; } if (idp == NULL || dt_ident_unref(idp)) dt_xcook_ident(lp, dhp, idkind, B_TRUE); else dt_xcook_ident(lp, dhp, idp->di_kind, B_FALSE); - } else + } else { lp = dnp->dn_left = dt_node_cook(lp, 0); + } /* * Switch op to '+' for *(E1 + E2) array mode in these cases: * (a) lp is a DT_IDENT_ARRAY variable that has already been * referenced using [] notation (dn_args != NULL). * (b) lp is a non-ARRAY variable that has already been given * a type by assignment or declaration (!dt_ident_unref()) * (c) lp is neither a variable nor an aggregation */ if (lp->dn_kind == DT_NODE_VAR) { if (lp->dn_ident->di_kind == DT_IDENT_ARRAY) { if (lp->dn_args != NULL) op = DT_TOK_ADD; - } else if (!dt_ident_unref(lp->dn_ident)) + } else if (!dt_ident_unref(lp->dn_ident)) { op = DT_TOK_ADD; - } else if (lp->dn_kind != DT_NODE_AGG) + } + } else if (lp->dn_kind != DT_NODE_AGG) { op = DT_TOK_ADD; + } } switch (op) { case DT_TOK_BAND: case DT_TOK_XOR: case DT_TOK_BOR: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) { xyerror(D_OP_INT, "operator %s requires operands of " "integral type\n", opstr(op)); } dt_node_promote(lp, rp, dnp); /* see K&R[A7.11-13] */ break; case DT_TOK_LSH: case DT_TOK_RSH: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) { xyerror(D_OP_INT, "operator %s requires operands of " "integral type\n", opstr(op)); } dt_node_type_propagate(lp, dnp); /* see K&R[A7.8] */ dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; case DT_TOK_MOD: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) { xyerror(D_OP_INT, "operator %s requires operands of " "integral type\n", opstr(op)); } dt_node_promote(lp, rp, dnp); /* see K&R[A7.6] */ break; case DT_TOK_MUL: case DT_TOK_DIV: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (!dt_node_is_arith(lp) || !dt_node_is_arith(rp)) { xyerror(D_OP_ARITH, "operator %s requires operands of " "arithmetic type\n", opstr(op)); } dt_node_promote(lp, rp, dnp); /* see K&R[A7.6] */ break; case DT_TOK_LAND: case DT_TOK_LXOR: case DT_TOK_LOR: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (!dt_node_is_scalar(lp) || !dt_node_is_scalar(rp)) { xyerror(D_OP_SCALAR, "operator %s requires operands " "of scalar type\n", opstr(op)); } dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; case DT_TOK_LT: case DT_TOK_LE: case DT_TOK_GT: case DT_TOK_GE: case DT_TOK_EQU: case DT_TOK_NEQ: /* * The D comparison operators provide the ability to transform * a right-hand identifier into a corresponding enum tag value * if the left-hand side is an enum type. To do this, we cook * the left-hand side, and then see if the right-hand side is * an unscoped identifier defined in the enum. If so, we * convert into an integer constant node with the tag's value. */ lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); kind = ctf_type_kind(lp->dn_ctfp, ctf_type_resolve(lp->dn_ctfp, lp->dn_type)); if (kind == CTF_K_ENUM && rp->dn_kind == DT_NODE_IDENT && strchr(rp->dn_string, '`') == NULL && ctf_enum_value( lp->dn_ctfp, lp->dn_type, rp->dn_string, &val) == 0) { if ((idp = dt_idstack_lookup(&yypcb->pcb_globals, rp->dn_string)) != NULL) { xyerror(D_IDENT_AMBIG, "ambiguous use of operator %s: %s is " "both a %s enum tag and a global %s\n", opstr(op), rp->dn_string, dt_node_type_name(lp, n1, sizeof (n1)), dt_idkind_name(idp->di_kind)); } free(rp->dn_string); rp->dn_string = NULL; rp->dn_kind = DT_NODE_INT; rp->dn_flags |= DT_NF_COOKED; rp->dn_op = DT_TOK_INT; rp->dn_value = (intmax_t)val; dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type, B_FALSE); dt_node_attr_assign(rp, _dtrace_symattr); } rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); /* * The rules for type checking for the relational operators are * described in the ANSI-C spec (see K&R[A7.9-10]). We perform * the various tests in order from least to most expensive. We * also allow derived strings to be compared as a first-class * type (resulting in a strcmp(3C)-style comparison), and we * slightly relax the A7.9 rules to permit void pointer * comparisons as in A7.10. Our users won't be confused by * this since they understand pointers are just numbers, and * relaxing this constraint simplifies the implementation. */ if (ctf_type_compat(lp->dn_ctfp, lp->dn_type, rp->dn_ctfp, rp->dn_type)) /*EMPTY*/; else if (dt_node_is_integer(lp) && dt_node_is_integer(rp)) /*EMPTY*/; else if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp) && (dt_node_is_string(lp) || dt_node_is_string(rp))) /*EMPTY*/; else if (dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) { xyerror(D_OP_INCOMPAT, "operands have " "incompatible types: \"%s\" %s \"%s\"\n", dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), dt_node_type_name(rp, n2, sizeof (n2))); } dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; case DT_TOK_ADD: case DT_TOK_SUB: { /* * The rules for type checking for the additive operators are * described in the ANSI-C spec (see K&R[A7.7]). Pointers and * integers may be manipulated according to specific rules. In * these cases D permits strings to be treated as pointers. */ int lp_is_ptr, lp_is_int, rp_is_ptr, rp_is_int; lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); lp_is_ptr = dt_node_is_string(lp) || (dt_node_is_pointer(lp) && !dt_node_is_vfptr(lp)); lp_is_int = dt_node_is_integer(lp); rp_is_ptr = dt_node_is_string(rp) || (dt_node_is_pointer(rp) && !dt_node_is_vfptr(rp)); rp_is_int = dt_node_is_integer(rp); if (lp_is_int && rp_is_int) { dt_type_promote(lp, rp, &ctfp, &type); uref = 0; } else if (lp_is_ptr && rp_is_int) { ctfp = lp->dn_ctfp; type = lp->dn_type; uref = lp->dn_flags & DT_NF_USERLAND; } else if (lp_is_int && rp_is_ptr && op == DT_TOK_ADD) { ctfp = rp->dn_ctfp; type = rp->dn_type; uref = rp->dn_flags & DT_NF_USERLAND; } else if (lp_is_ptr && rp_is_ptr && op == DT_TOK_SUB && dt_node_is_ptrcompat(lp, rp, NULL, NULL)) { ctfp = dtp->dt_ddefs->dm_ctfp; type = ctf_lookup_by_name(ctfp, "ptrdiff_t"); uref = 0; } else { xyerror(D_OP_INCOMPAT, "operands have incompatible " "types: \"%s\" %s \"%s\"\n", dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), dt_node_type_name(rp, n2, sizeof (n2))); } dt_node_type_assign(dnp, ctfp, type, B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); if (uref) dnp->dn_flags |= DT_NF_USERLAND; break; } case DT_TOK_OR_EQ: case DT_TOK_XOR_EQ: case DT_TOK_AND_EQ: case DT_TOK_LSH_EQ: case DT_TOK_RSH_EQ: case DT_TOK_MOD_EQ: if (lp->dn_kind == DT_NODE_IDENT) { dt_xcook_ident(lp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE); } lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD); if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) { xyerror(D_OP_INT, "operator %s requires operands of " "integral type\n", opstr(op)); } goto asgn_common; case DT_TOK_MUL_EQ: case DT_TOK_DIV_EQ: if (lp->dn_kind == DT_NODE_IDENT) { dt_xcook_ident(lp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE); } lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD); if (!dt_node_is_arith(lp) || !dt_node_is_arith(rp)) { xyerror(D_OP_ARITH, "operator %s requires operands of " "arithmetic type\n", opstr(op)); } goto asgn_common; case DT_TOK_ASGN: /* * If the left-hand side is an identifier, attempt to resolve * it as either an aggregation or scalar variable. We pass * B_TRUE to dt_xcook_ident to indicate that a new variable can * be created if no matching variable exists in the namespace. */ if (lp->dn_kind == DT_NODE_IDENT) { if (lp->dn_op == DT_TOK_AGG) { dt_xcook_ident(lp, dtp->dt_aggs, DT_IDENT_AGG, B_TRUE); } else { dt_xcook_ident(lp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE); } } lp = dnp->dn_left = dt_node_cook(lp, 0); /* don't set mod yet */ rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); /* * If the left-hand side is an aggregation, verify that we are * assigning it the result of an aggregating function. Once * we've done so, hide the func node in the aggregation and * return the aggregation itself up to the parse tree parent. * This transformation is legal since the assigned function * cannot change identity across disjoint cooking passes and * the argument list subtree is retained for later cooking. */ if (lp->dn_kind == DT_NODE_AGG) { const char *aname = lp->dn_ident->di_name; dt_ident_t *oid = lp->dn_ident->di_iarg; if (rp->dn_kind != DT_NODE_FUNC || rp->dn_ident->di_kind != DT_IDENT_AGGFUNC) { xyerror(D_AGG_FUNC, "@%s must be assigned the result of " "an aggregating function\n", aname); } if (oid != NULL && oid != rp->dn_ident) { xyerror(D_AGG_REDEF, "aggregation redefined: @%s\n\t " "current: @%s = %s( )\n\tprevious: @%s = " "%s( ) : line %d\n", aname, aname, rp->dn_ident->di_name, aname, oid->di_name, lp->dn_ident->di_lineno); } else if (oid == NULL) lp->dn_ident->di_iarg = rp->dn_ident; /* * Do not allow multiple aggregation assignments in a * single statement, e.g. (@a = count()) = count(); * We produce a message as if the result of aggregating * function does not propagate DT_NF_LVALUE. */ if (lp->dn_aggfun != NULL) { xyerror(D_OP_LVAL, "operator = requires " "modifiable lvalue as an operand\n"); } lp->dn_aggfun = rp; lp = dt_node_cook(lp, DT_IDFLG_MOD); dnp->dn_left = dnp->dn_right = NULL; dt_node_free(dnp); return (lp); } /* * If the right-hand side is a dynamic variable that is the * output of a translator, our result is the translated type. */ if ((idp = dt_node_resolve(rp, DT_IDENT_XLSOU)) != NULL) { ctfp = idp->di_ctfp; type = idp->di_type; uref = idp->di_flags & DT_IDFLG_USER; } else { ctfp = rp->dn_ctfp; type = rp->dn_type; uref = rp->dn_flags & DT_NF_USERLAND; } /* * If the left-hand side of an assignment statement is a virgin * variable created by this compilation pass, reset the type of * this variable to the type of the right-hand side. */ if (lp->dn_kind == DT_NODE_VAR && dt_ident_unref(lp->dn_ident)) { dt_node_type_assign(lp, ctfp, type, B_FALSE); dt_ident_type_assign(lp->dn_ident, ctfp, type); if (uref) { lp->dn_flags |= DT_NF_USERLAND; lp->dn_ident->di_flags |= DT_IDFLG_USER; } } if (lp->dn_kind == DT_NODE_VAR) lp->dn_ident->di_flags |= DT_IDFLG_MOD; /* * The rules for type checking for the assignment operators are * described in the ANSI-C spec (see K&R[A7.17]). We share * most of this code with the argument list checking code. */ if (!dt_node_is_string(lp)) { kind = ctf_type_kind(lp->dn_ctfp, ctf_type_resolve(lp->dn_ctfp, lp->dn_type)); if (kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION) { xyerror(D_OP_ARRFUN, "operator %s may not be " "applied to operand of type \"%s\"\n", opstr(op), dt_node_type_name(lp, n1, sizeof (n1))); } } if (idp != NULL && idp->di_kind == DT_IDENT_XLSOU && ctf_type_compat(lp->dn_ctfp, lp->dn_type, ctfp, type)) goto asgn_common; if (dt_node_is_argcompat(lp, rp)) goto asgn_common; xyerror(D_OP_INCOMPAT, "operands have incompatible types: \"%s\" %s \"%s\"\n", dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), dt_node_type_name(rp, n2, sizeof (n2))); /*NOTREACHED*/ case DT_TOK_ADD_EQ: case DT_TOK_SUB_EQ: if (lp->dn_kind == DT_NODE_IDENT) { dt_xcook_ident(lp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE); } lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD); if (dt_node_is_string(lp) || dt_node_is_string(rp)) { xyerror(D_OP_INCOMPAT, "operands have " "incompatible types: \"%s\" %s \"%s\"\n", dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), dt_node_type_name(rp, n2, sizeof (n2))); } /* * The rules for type checking for the assignment operators are * described in the ANSI-C spec (see K&R[A7.17]). To these * rules we add that only writable D nodes can be modified. */ if (dt_node_is_integer(lp) == 0 || dt_node_is_integer(rp) == 0) { if (!dt_node_is_pointer(lp) || dt_node_is_vfptr(lp)) { xyerror(D_OP_VFPTR, "operator %s requires left-hand scalar " "operand of known size\n", opstr(op)); } else if (dt_node_is_integer(rp) == 0 && dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) { xyerror(D_OP_INCOMPAT, "operands have " "incompatible types: \"%s\" %s \"%s\"\n", dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), dt_node_type_name(rp, n2, sizeof (n2))); } } asgn_common: dt_assign_common(dnp); break; case DT_TOK_PTR: /* - * If the left-hand side of operator -> is the name "self", - * then we permit a TLS variable to be created or referenced. + * If the left-hand side of operator -> is one of the scoping + * keywords, permit a local or thread variable to be created or + * referenced. */ - if (lp->dn_kind == DT_NODE_IDENT && - strcmp(lp->dn_string, "self") == 0) { - if (rp->dn_kind != DT_NODE_VAR) { - dt_xcook_ident(rp, dtp->dt_tls, - DT_IDENT_SCALAR, B_TRUE); - } + if (lp->dn_kind == DT_NODE_IDENT) { + dt_idhash_t *dhp = NULL; - if (idflags != 0) - rp = dt_node_cook(rp, idflags); - - dnp->dn_right = dnp->dn_left; /* avoid freeing rp */ - dt_node_free(dnp); - return (rp); - } - - /* - * If the left-hand side of operator -> is the name "this", - * then we permit a local variable to be created or referenced. - */ - if (lp->dn_kind == DT_NODE_IDENT && - strcmp(lp->dn_string, "this") == 0) { - if (rp->dn_kind != DT_NODE_VAR) { - dt_xcook_ident(rp, yypcb->pcb_locals, - DT_IDENT_SCALAR, B_TRUE); + if (strcmp(lp->dn_string, "self") == 0) { + dhp = dtp->dt_tls; + } else if (strcmp(lp->dn_string, "this") == 0) { + dhp = yypcb->pcb_locals; } + if (dhp != NULL) { + if (rp->dn_kind != DT_NODE_VAR) { + dt_xcook_ident(rp, dhp, + DT_IDENT_SCALAR, B_TRUE); + } - if (idflags != 0) - rp = dt_node_cook(rp, idflags); + if (idflags != 0) + rp = dt_node_cook(rp, idflags); - dnp->dn_right = dnp->dn_left; /* avoid freeing rp */ - dt_node_free(dnp); - return (rp); + /* avoid freeing rp */ + dnp->dn_right = dnp->dn_left; + dt_node_free(dnp); + return (rp); + } } - /*FALLTHRU*/ - case DT_TOK_DOT: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); if (rp->dn_kind != DT_NODE_IDENT) { xyerror(D_OP_IDENT, "operator %s must be followed by " "an identifier\n", opstr(op)); } if ((idp = dt_node_resolve(lp, DT_IDENT_XLSOU)) != NULL || (idp = dt_node_resolve(lp, DT_IDENT_XLPTR)) != NULL) { /* * If the left-hand side is a translated struct or ptr, * the type of the left is the translation output type. */ dt_xlator_t *dxp = idp->di_data; if (dt_xlator_member(dxp, rp->dn_string) == NULL) { xyerror(D_XLATE_NOCONV, "translator does not define conversion " "for member: %s\n", rp->dn_string); } ctfp = idp->di_ctfp; type = ctf_type_resolve(ctfp, idp->di_type); uref = idp->di_flags & DT_IDFLG_USER; } else { ctfp = lp->dn_ctfp; type = ctf_type_resolve(ctfp, lp->dn_type); uref = lp->dn_flags & DT_NF_USERLAND; } kind = ctf_type_kind(ctfp, type); if (op == DT_TOK_PTR) { if (kind != CTF_K_POINTER) { xyerror(D_OP_PTR, "operator %s must be " "applied to a pointer\n", opstr(op)); } type = ctf_type_reference(ctfp, type); type = ctf_type_resolve(ctfp, type); kind = ctf_type_kind(ctfp, type); } /* * If we follow a reference to a forward declaration tag, * search the entire type space for the actual definition. */ while (kind == CTF_K_FORWARD) { char *tag = ctf_type_name(ctfp, type, n1, sizeof (n1)); dtrace_typeinfo_t dtt; if (tag != NULL && dt_type_lookup(tag, &dtt) == 0 && (dtt.dtt_ctfp != ctfp || dtt.dtt_type != type)) { ctfp = dtt.dtt_ctfp; type = ctf_type_resolve(ctfp, dtt.dtt_type); kind = ctf_type_kind(ctfp, type); } else { xyerror(D_OP_INCOMPLETE, "operator %s cannot be applied to a " "forward declaration: no %s definition " "is available\n", opstr(op), tag); } } if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) { if (op == DT_TOK_PTR) { xyerror(D_OP_SOU, "operator -> cannot be " "applied to pointer to type \"%s\"; must " "be applied to a struct or union pointer\n", ctf_type_name(ctfp, type, n1, sizeof (n1))); } else { xyerror(D_OP_SOU, "operator %s cannot be " "applied to type \"%s\"; must be applied " "to a struct or union\n", opstr(op), ctf_type_name(ctfp, type, n1, sizeof (n1))); } } if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) { xyerror(D_TYPE_MEMBER, "%s is not a member of %s\n", rp->dn_string, ctf_type_name(ctfp, type, n1, sizeof (n1))); } type = ctf_type_resolve(ctfp, m.ctm_type); kind = ctf_type_kind(ctfp, type); dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE); dt_node_attr_assign(dnp, lp->dn_attr); if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY || dt_node_is_string(dnp))) dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */ if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) && (kind != CTF_K_ARRAY || dt_node_is_string(dnp))) dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */ if (lp->dn_flags & DT_NF_WRITABLE) dnp->dn_flags |= DT_NF_WRITABLE; if (uref && (kind == CTF_K_POINTER || (dnp->dn_flags & DT_NF_REF))) dnp->dn_flags |= DT_NF_USERLAND; break; case DT_TOK_LBRAC: { /* * If op is DT_TOK_LBRAC, we know from the special-case code at * the top that lp is either a D variable or an aggregation. */ dt_node_t *lnp; /* * If the left-hand side is an aggregation, just set dn_aggtup * to the right-hand side and return the cooked aggregation. * This transformation is legal since we are just collapsing * nodes to simplify later processing, and the entire aggtup * parse subtree is retained for subsequent cooking passes. */ if (lp->dn_kind == DT_NODE_AGG) { if (lp->dn_aggtup != NULL) { xyerror(D_AGG_MDIM, "improper attempt to " "reference @%s as a multi-dimensional " "array\n", lp->dn_ident->di_name); } lp->dn_aggtup = rp; lp = dt_node_cook(lp, 0); dnp->dn_left = dnp->dn_right = NULL; dt_node_free(dnp); return (lp); } assert(lp->dn_kind == DT_NODE_VAR); idp = lp->dn_ident; /* * If the left-hand side is a non-global scalar that hasn't yet * been referenced or modified, it was just created by self-> * or this-> and we can convert it from scalar to assoc array. */ if (idp->di_kind == DT_IDENT_SCALAR && dt_ident_unref(idp) && (idp->di_flags & (DT_IDFLG_LOCAL | DT_IDFLG_TLS)) != 0) { if (idp->di_flags & DT_IDFLG_LOCAL) { xyerror(D_ARR_LOCAL, "local variables may not be used as " "associative arrays: %s\n", idp->di_name); } dt_dprintf("morph variable %s (id %u) from scalar to " "array\n", idp->di_name, idp->di_id); dt_ident_morph(idp, DT_IDENT_ARRAY, &dt_idops_assc, NULL); } if (idp->di_kind != DT_IDENT_ARRAY) { xyerror(D_IDENT_BADREF, "%s '%s' may not be referenced " "as %s\n", dt_idkind_name(idp->di_kind), idp->di_name, dt_idkind_name(DT_IDENT_ARRAY)); } /* * Now that we've confirmed our left-hand side is a DT_NODE_VAR * of idkind DT_IDENT_ARRAY, we need to splice the [ node from * the parse tree and leave a cooked DT_NODE_VAR in its place * where dn_args for the VAR node is the right-hand 'rp' tree, * as shown in the parse tree diagram below: * * / / * [ OP2 "[" ]=dnp [ VAR ]=dnp * / \ => | * / \ +- dn_args -> [ ??? ]=rp * [ VAR ]=lp [ ??? ]=rp * * Since the final dt_node_cook(dnp) can fail using longjmp we * must perform the transformations as a group first by over- * writing 'dnp' to become the VAR node, so that the parse tree * is guaranteed to be in a consistent state if the cook fails. */ assert(lp->dn_kind == DT_NODE_VAR); assert(lp->dn_args == NULL); lnp = dnp->dn_link; bcopy(lp, dnp, sizeof (dt_node_t)); dnp->dn_link = lnp; dnp->dn_args = rp; dnp->dn_list = NULL; dt_node_free(lp); return (dt_node_cook(dnp, idflags)); } case DT_TOK_XLATE: { dt_xlator_t *dxp; assert(lp->dn_kind == DT_NODE_TYPE); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); dxp = dt_xlator_lookup(dtp, rp, lp, DT_XLATE_FUZZY); if (dxp == NULL) { xyerror(D_XLATE_NONE, "cannot translate from \"%s\" to \"%s\"\n", dt_node_type_name(rp, n1, sizeof (n1)), dt_node_type_name(lp, n2, sizeof (n2))); } dnp->dn_ident = dt_xlator_ident(dxp, lp->dn_ctfp, lp->dn_type); dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(rp->dn_attr, dnp->dn_ident->di_attr)); break; } case DT_TOK_LPAR: { ctf_id_t ltype, rtype; uint_t lkind, rkind; assert(lp->dn_kind == DT_NODE_TYPE); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); ltype = ctf_type_resolve(lp->dn_ctfp, lp->dn_type); lkind = ctf_type_kind(lp->dn_ctfp, ltype); rtype = ctf_type_resolve(rp->dn_ctfp, rp->dn_type); rkind = ctf_type_kind(rp->dn_ctfp, rtype); /* * The rules for casting are loosely explained in K&R[A7.5] * and K&R[A6]. Basically, we can cast to the same type or * same base type, between any kind of scalar values, from * arrays to pointers, and we can cast anything to void. * To these rules D adds casts from scalars to strings. */ if (ctf_type_compat(lp->dn_ctfp, lp->dn_type, rp->dn_ctfp, rp->dn_type)) /*EMPTY*/; else if (dt_node_is_scalar(lp) && (dt_node_is_scalar(rp) || rkind == CTF_K_FUNCTION)) /*EMPTY*/; else if (dt_node_is_void(lp)) /*EMPTY*/; else if (lkind == CTF_K_POINTER && dt_node_is_pointer(rp)) /*EMPTY*/; else if (dt_node_is_string(lp) && (dt_node_is_scalar(rp) || dt_node_is_pointer(rp) || dt_node_is_strcompat(rp))) /*EMPTY*/; else { xyerror(D_CAST_INVAL, "invalid cast expression: \"%s\" to \"%s\"\n", dt_node_type_name(rp, n1, sizeof (n1)), dt_node_type_name(lp, n2, sizeof (n2))); } dt_node_type_propagate(lp, dnp); /* see K&R[A7.5] */ dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); /* * If it's a pointer then should be able to (attempt to) * assign to it. */ if (lkind == CTF_K_POINTER) dnp->dn_flags |= DT_NF_WRITABLE; break; } case DT_TOK_COMMA: lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp)) { xyerror(D_OP_DYN, "operator %s operands " "cannot be of dynamic type\n", opstr(op)); } if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) { xyerror(D_OP_ACT, "operator %s operands " "cannot be actions\n", opstr(op)); } dt_node_type_propagate(rp, dnp); /* see K&R[A7.18] */ dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); break; default: xyerror(D_UNKNOWN, "invalid binary op %s\n", opstr(op)); } /* * Complete the conversion of E1[E2] to *((E1)+(E2)) that we started * at the top of our switch() above (see K&R[A7.3.1]). Since E2 is * parsed as an argument_expression_list by dt_grammar.y, we can * end up with a comma-separated list inside of a non-associative * array reference. We check for this and report an appropriate error. */ if (dnp->dn_op == DT_TOK_LBRAC && op == DT_TOK_ADD) { dt_node_t *pnp; if (rp->dn_list != NULL) { xyerror(D_ARR_BADREF, "cannot access %s as an associative array\n", dt_node_name(lp, n1, sizeof (n1))); } dnp->dn_op = DT_TOK_ADD; pnp = dt_node_op1(DT_TOK_DEREF, dnp); /* * Cook callbacks are not typically permitted to allocate nodes. * When we do, we must insert them in the middle of an existing * allocation list rather than having them appended to the pcb * list because the sub-expression may be part of a definition. */ assert(yypcb->pcb_list == pnp); yypcb->pcb_list = pnp->dn_link; pnp->dn_link = dnp->dn_link; dnp->dn_link = pnp; return (dt_node_cook(pnp, DT_IDFLG_REF)); } return (dnp); } /*ARGSUSED*/ static dt_node_t * dt_cook_op3(dt_node_t *dnp, uint_t idflags) { dt_node_t *lp, *rp; ctf_file_t *ctfp; ctf_id_t type; dnp->dn_expr = dt_node_cook(dnp->dn_expr, DT_IDFLG_REF); lp = dnp->dn_left = dt_node_cook(dnp->dn_left, DT_IDFLG_REF); rp = dnp->dn_right = dt_node_cook(dnp->dn_right, DT_IDFLG_REF); if (!dt_node_is_scalar(dnp->dn_expr)) { xyerror(D_OP_SCALAR, "operator ?: expression must be of scalar type\n"); } if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp)) { xyerror(D_OP_DYN, "operator ?: operands cannot be of dynamic type\n"); } /* * The rules for type checking for the ternary operator are complex and * are described in the ANSI-C spec (see K&R[A7.16]). We implement * the various tests in order from least to most expensive. */ if (ctf_type_compat(lp->dn_ctfp, lp->dn_type, rp->dn_ctfp, rp->dn_type)) { ctfp = lp->dn_ctfp; type = lp->dn_type; } else if (dt_node_is_integer(lp) && dt_node_is_integer(rp)) { dt_type_promote(lp, rp, &ctfp, &type); } else if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp) && (dt_node_is_string(lp) || dt_node_is_string(rp))) { ctfp = DT_STR_CTFP(yypcb->pcb_hdl); type = DT_STR_TYPE(yypcb->pcb_hdl); } else if (dt_node_is_ptrcompat(lp, rp, &ctfp, &type) == 0) { xyerror(D_OP_INCOMPAT, "operator ?: operands must have compatible types\n"); } if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) { xyerror(D_OP_ACT, "action cannot be " "used in a conditional context\n"); } dt_node_type_assign(dnp, ctfp, type, B_FALSE); dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_expr->dn_attr, dt_attr_min(lp->dn_attr, rp->dn_attr))); return (dnp); } static dt_node_t * dt_cook_statement(dt_node_t *dnp, uint_t idflags) { dnp->dn_expr = dt_node_cook(dnp->dn_expr, idflags); dt_node_attr_assign(dnp, dnp->dn_expr->dn_attr); return (dnp); } /* * If dn_aggfun is set, this node is a collapsed aggregation assignment (see * the special case code for DT_TOK_ASGN in dt_cook_op2() above), in which * case we cook both the tuple and the function call. If dn_aggfun is NULL, * this node is just a reference to the aggregation's type and attributes. */ /*ARGSUSED*/ static dt_node_t * dt_cook_aggregation(dt_node_t *dnp, uint_t idflags) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; if (dnp->dn_aggfun != NULL) { dnp->dn_aggfun = dt_node_cook(dnp->dn_aggfun, DT_IDFLG_REF); dt_node_attr_assign(dnp, dt_ident_cook(dnp, dnp->dn_ident, &dnp->dn_aggtup)); } else { dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); dt_node_attr_assign(dnp, dnp->dn_ident->di_attr); } return (dnp); } /* * Since D permits new variable identifiers to be instantiated in any program * expression, we may need to cook a clause's predicate either before or after * the action list depending on the program code in question. Consider: * * probe-description-list probe-description-list * /x++/ /x == 0/ * { { * trace(x); trace(x++); * } } * * In the left-hand example, the predicate uses operator ++ to instantiate 'x' * as a variable of type int64_t. The predicate must be cooked first because * otherwise the statement trace(x) refers to an unknown identifier. In the * right-hand example, the action list uses ++ to instantiate 'x'; the action * list must be cooked first because otherwise the predicate x == 0 refers to * an unknown identifier. In order to simplify programming, we support both. * * When cooking a clause, we cook the action statements before the predicate by * default, since it seems more common to create or modify identifiers in the * action list. If cooking fails due to an unknown identifier, we attempt to * cook the predicate (i.e. do it first) and then go back and cook the actions. * If this, too, fails (or if we get an error other than D_IDENT_UNDEF) we give * up and report failure back to the user. There are five possible paths: * * cook actions = OK, cook predicate = OK -> OK * cook actions = OK, cook predicate = ERR -> ERR * cook actions = ERR, cook predicate = ERR -> ERR * cook actions = ERR, cook predicate = OK, cook actions = OK -> OK * cook actions = ERR, cook predicate = OK, cook actions = ERR -> ERR * * The programmer can still defeat our scheme by creating circular definition * dependencies between predicates and actions, as in this example clause: * * probe-description-list * /x++ && y == 0/ * { * trace(x + y++); * } * * but it doesn't seem worth the complexity to handle such rare cases. The * user can simply use the D variable declaration syntax to work around them. */ static dt_node_t * dt_cook_clause(dt_node_t *dnp, uint_t idflags) { volatile int err, tries; jmp_buf ojb; /* * Before assigning dn_ctxattr, temporarily assign the probe attribute * to 'dnp' itself to force an attribute check and minimum violation. */ dt_node_attr_assign(dnp, yypcb->pcb_pinfo.dtp_attr); dnp->dn_ctxattr = yypcb->pcb_pinfo.dtp_attr; bcopy(yypcb->pcb_jmpbuf, ojb, sizeof (jmp_buf)); tries = 0; if (dnp->dn_pred != NULL && (err = setjmp(yypcb->pcb_jmpbuf)) != 0) { bcopy(ojb, yypcb->pcb_jmpbuf, sizeof (jmp_buf)); if (tries++ != 0 || err != EDT_COMPILER || ( yypcb->pcb_hdl->dt_errtag != dt_errtag(D_IDENT_UNDEF) && yypcb->pcb_hdl->dt_errtag != dt_errtag(D_VAR_UNDEF))) longjmp(yypcb->pcb_jmpbuf, err); } if (tries == 0) { yylabel("action list"); dt_node_attr_assign(dnp, dt_node_list_cook(&dnp->dn_acts, idflags)); bcopy(ojb, yypcb->pcb_jmpbuf, sizeof (jmp_buf)); yylabel(NULL); } if (dnp->dn_pred != NULL) { yylabel("predicate"); dnp->dn_pred = dt_node_cook(dnp->dn_pred, idflags); dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_attr, dnp->dn_pred->dn_attr)); if (!dt_node_is_scalar(dnp->dn_pred)) { xyerror(D_PRED_SCALAR, "predicate result must be of scalar type\n"); } yylabel(NULL); } if (tries != 0) { yylabel("action list"); dt_node_attr_assign(dnp, dt_node_list_cook(&dnp->dn_acts, idflags)); yylabel(NULL); } return (dnp); } /*ARGSUSED*/ static dt_node_t * dt_cook_inline(dt_node_t *dnp, uint_t idflags) { dt_idnode_t *inp = dnp->dn_ident->di_iarg; dt_ident_t *rdp; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; assert(dnp->dn_ident->di_flags & DT_IDFLG_INLINE); assert(inp->din_root->dn_flags & DT_NF_COOKED); /* * If we are inlining a translation, verify that the inline declaration * type exactly matches the type that is returned by the translation. * Otherwise just use dt_node_is_argcompat() to check the types. */ if ((rdp = dt_node_resolve(inp->din_root, DT_IDENT_XLSOU)) != NULL || (rdp = dt_node_resolve(inp->din_root, DT_IDENT_XLPTR)) != NULL) { ctf_file_t *lctfp = dnp->dn_ctfp; ctf_id_t ltype = ctf_type_resolve(lctfp, dnp->dn_type); dt_xlator_t *dxp = rdp->di_data; ctf_file_t *rctfp = dxp->dx_dst_ctfp; ctf_id_t rtype = dxp->dx_dst_base; if (ctf_type_kind(lctfp, ltype) == CTF_K_POINTER) { ltype = ctf_type_reference(lctfp, ltype); ltype = ctf_type_resolve(lctfp, ltype); } if (ctf_type_compat(lctfp, ltype, rctfp, rtype) == 0) { dnerror(dnp, D_OP_INCOMPAT, "inline %s definition uses incompatible types: " "\"%s\" = \"%s\"\n", dnp->dn_ident->di_name, dt_type_name(lctfp, ltype, n1, sizeof (n1)), dt_type_name(rctfp, rtype, n2, sizeof (n2))); } } else if (dt_node_is_argcompat(dnp, inp->din_root) == 0) { dnerror(dnp, D_OP_INCOMPAT, "inline %s definition uses incompatible types: " "\"%s\" = \"%s\"\n", dnp->dn_ident->di_name, dt_node_type_name(dnp, n1, sizeof (n1)), dt_node_type_name(inp->din_root, n2, sizeof (n2))); } return (dnp); } static dt_node_t * dt_cook_member(dt_node_t *dnp, uint_t idflags) { dnp->dn_membexpr = dt_node_cook(dnp->dn_membexpr, idflags); dt_node_attr_assign(dnp, dnp->dn_membexpr->dn_attr); return (dnp); } /*ARGSUSED*/ static dt_node_t * dt_cook_xlator(dt_node_t *dnp, uint_t idflags) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_xlator_t *dxp = dnp->dn_xlator; dt_node_t *mnp; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; dtrace_attribute_t attr = _dtrace_maxattr; ctf_membinfo_t ctm; /* * Before cooking each translator member, we push a reference to the * hash containing translator-local identifiers on to pcb_globals to * temporarily interpose these identifiers in front of other globals. */ dt_idstack_push(&yypcb->pcb_globals, dxp->dx_locals); for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) { if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type, mnp->dn_membname, &ctm) == CTF_ERR) { xyerror(D_XLATE_MEMB, "translator member %s is not a member of %s\n", mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp, dxp->dx_dst_type, n1, sizeof (n1))); } (void) dt_node_cook(mnp, DT_IDFLG_REF); dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type, B_FALSE); attr = dt_attr_min(attr, mnp->dn_attr); if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) { xyerror(D_XLATE_INCOMPAT, "translator member %s definition uses " "incompatible types: \"%s\" = \"%s\"\n", mnp->dn_membname, dt_node_type_name(mnp, n1, sizeof (n1)), dt_node_type_name(mnp->dn_membexpr, n2, sizeof (n2))); } } dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals); dxp->dx_souid.di_attr = attr; dxp->dx_ptrid.di_attr = attr; dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); dt_node_attr_assign(dnp, _dtrace_defattr); return (dnp); } static void dt_node_provider_cmp_argv(dt_provider_t *pvp, dt_node_t *pnp, const char *kind, uint_t old_argc, dt_node_t *old_argv, uint_t new_argc, dt_node_t *new_argv) { dt_probe_t *prp = pnp->dn_ident->di_data; uint_t i; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; if (old_argc != new_argc) { dnerror(pnp, D_PROV_INCOMPAT, "probe %s:%s %s prototype mismatch:\n" "\t current: %u arg%s\n\tprevious: %u arg%s\n", pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, kind, new_argc, new_argc != 1 ? "s" : "", old_argc, old_argc != 1 ? "s" : ""); } for (i = 0; i < old_argc; i++, old_argv = old_argv->dn_list, new_argv = new_argv->dn_list) { if (ctf_type_cmp(old_argv->dn_ctfp, old_argv->dn_type, new_argv->dn_ctfp, new_argv->dn_type) == 0) continue; dnerror(pnp, D_PROV_INCOMPAT, "probe %s:%s %s prototype argument #%u mismatch:\n" "\t current: %s\n\tprevious: %s\n", pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, kind, i + 1, dt_node_type_name(new_argv, n1, sizeof (n1)), dt_node_type_name(old_argv, n2, sizeof (n2))); } } /* * Compare a new probe declaration with an existing probe definition (either * from a previous declaration or cached from the kernel). If the existing * definition and declaration both have an input and output parameter list, * compare both lists. Otherwise compare only the output parameter lists. */ static void dt_node_provider_cmp(dt_provider_t *pvp, dt_node_t *pnp, dt_probe_t *old, dt_probe_t *new) { dt_node_provider_cmp_argv(pvp, pnp, "output", old->pr_xargc, old->pr_xargs, new->pr_xargc, new->pr_xargs); if (old->pr_nargs != old->pr_xargs && new->pr_nargs != new->pr_xargs) { dt_node_provider_cmp_argv(pvp, pnp, "input", old->pr_nargc, old->pr_nargs, new->pr_nargc, new->pr_nargs); } if (old->pr_nargs == old->pr_xargs && new->pr_nargs != new->pr_xargs) { if (pvp->pv_flags & DT_PROVIDER_IMPL) { dnerror(pnp, D_PROV_INCOMPAT, "provider interface mismatch: %s\n" "\t current: probe %s:%s has an output prototype\n" "\tprevious: probe %s:%s has no output prototype\n", pvp->pv_desc.dtvd_name, pvp->pv_desc.dtvd_name, new->pr_ident->di_name, pvp->pv_desc.dtvd_name, old->pr_ident->di_name); } if (old->pr_ident->di_gen == yypcb->pcb_hdl->dt_gen) old->pr_ident->di_flags |= DT_IDFLG_ORPHAN; dt_idhash_delete(pvp->pv_probes, old->pr_ident); dt_probe_declare(pvp, new); } } static void dt_cook_probe(dt_node_t *dnp, dt_provider_t *pvp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_probe_t *prp = dnp->dn_ident->di_data; dt_xlator_t *dxp; uint_t i; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; if (prp->pr_nargs == prp->pr_xargs) return; for (i = 0; i < prp->pr_xargc; i++) { dt_node_t *xnp = prp->pr_xargv[i]; dt_node_t *nnp = prp->pr_nargv[prp->pr_mapping[i]]; if ((dxp = dt_xlator_lookup(dtp, nnp, xnp, DT_XLATE_FUZZY)) != NULL) { if (dt_provider_xref(dtp, pvp, dxp->dx_id) != 0) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); continue; } if (dt_node_is_argcompat(nnp, xnp)) continue; /* no translator defined and none required */ dnerror(dnp, D_PROV_PRXLATOR, "translator for %s:%s output " "argument #%u from %s to %s is not defined\n", pvp->pv_desc.dtvd_name, dnp->dn_ident->di_name, i + 1, dt_node_type_name(nnp, n1, sizeof (n1)), dt_node_type_name(xnp, n2, sizeof (n2))); } } /*ARGSUSED*/ static dt_node_t * dt_cook_provider(dt_node_t *dnp, uint_t idflags) { dt_provider_t *pvp = dnp->dn_provider; dt_node_t *pnp; /* * If we're declaring a provider for the first time and it is unknown * to dtrace(7D), insert the probe definitions into the provider's hash. * If we're redeclaring a known provider, verify the interface matches. */ for (pnp = dnp->dn_probes; pnp != NULL; pnp = pnp->dn_list) { const char *probename = pnp->dn_ident->di_name; dt_probe_t *prp = dt_probe_lookup(pvp, probename); assert(pnp->dn_kind == DT_NODE_PROBE); if (prp != NULL && dnp->dn_provred) { dt_node_provider_cmp(pvp, pnp, prp, pnp->dn_ident->di_data); } else if (prp == NULL && dnp->dn_provred) { dnerror(pnp, D_PROV_INCOMPAT, "provider interface mismatch: %s\n" "\t current: probe %s:%s defined\n" "\tprevious: probe %s:%s not defined\n", dnp->dn_provname, dnp->dn_provname, probename, dnp->dn_provname, probename); } else if (prp != NULL) { dnerror(pnp, D_PROV_PRDUP, "probe redeclared: %s:%s\n", dnp->dn_provname, probename); } else dt_probe_declare(pvp, pnp->dn_ident->di_data); dt_cook_probe(pnp, pvp); } return (dnp); } /*ARGSUSED*/ static dt_node_t * dt_cook_none(dt_node_t *dnp, uint_t idflags) { return (dnp); } static dt_node_t *(*dt_cook_funcs[])(dt_node_t *, uint_t) = { dt_cook_none, /* DT_NODE_FREE */ dt_cook_none, /* DT_NODE_INT */ dt_cook_none, /* DT_NODE_STRING */ dt_cook_ident, /* DT_NODE_IDENT */ dt_cook_var, /* DT_NODE_VAR */ dt_cook_none, /* DT_NODE_SYM */ dt_cook_none, /* DT_NODE_TYPE */ dt_cook_func, /* DT_NODE_FUNC */ dt_cook_op1, /* DT_NODE_OP1 */ dt_cook_op2, /* DT_NODE_OP2 */ dt_cook_op3, /* DT_NODE_OP3 */ dt_cook_statement, /* DT_NODE_DEXPR */ dt_cook_statement, /* DT_NODE_DFUNC */ dt_cook_aggregation, /* DT_NODE_AGG */ dt_cook_none, /* DT_NODE_PDESC */ dt_cook_clause, /* DT_NODE_CLAUSE */ dt_cook_inline, /* DT_NODE_INLINE */ dt_cook_member, /* DT_NODE_MEMBER */ dt_cook_xlator, /* DT_NODE_XLATOR */ dt_cook_none, /* DT_NODE_PROBE */ dt_cook_provider, /* DT_NODE_PROVIDER */ - dt_cook_none /* DT_NODE_PROG */ + dt_cook_none, /* DT_NODE_PROG */ + dt_cook_none, /* DT_NODE_IF */ }; /* * Recursively cook the parse tree starting at the specified node. The idflags * parameter is used to indicate the type of reference (r/w) and is applied to * the resulting identifier if it is a D variable or D aggregation. */ dt_node_t * dt_node_cook(dt_node_t *dnp, uint_t idflags) { int oldlineno = yylineno; yylineno = dnp->dn_line; + assert(dnp->dn_kind < + sizeof (dt_cook_funcs) / sizeof (dt_cook_funcs[0])); dnp = dt_cook_funcs[dnp->dn_kind](dnp, idflags); dnp->dn_flags |= DT_NF_COOKED; if (dnp->dn_kind == DT_NODE_VAR || dnp->dn_kind == DT_NODE_AGG) dnp->dn_ident->di_flags |= idflags; yylineno = oldlineno; return (dnp); } dtrace_attribute_t dt_node_list_cook(dt_node_t **pnp, uint_t idflags) { dtrace_attribute_t attr = _dtrace_defattr; dt_node_t *dnp, *nnp; for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) { nnp = dnp->dn_list; dnp = *pnp = dt_node_cook(dnp, idflags); attr = dt_attr_min(attr, dnp->dn_attr); dnp->dn_list = nnp; pnp = &dnp->dn_list; } return (attr); } void dt_node_list_free(dt_node_t **pnp) { dt_node_t *dnp, *nnp; for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) { nnp = dnp->dn_list; dt_node_free(dnp); } if (pnp != NULL) *pnp = NULL; } void dt_node_link_free(dt_node_t **pnp) { dt_node_t *dnp, *nnp; for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) { nnp = dnp->dn_link; dt_node_free(dnp); } for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) { nnp = dnp->dn_link; free(dnp); } if (pnp != NULL) *pnp = NULL; } dt_node_t * dt_node_link(dt_node_t *lp, dt_node_t *rp) { dt_node_t *dnp; if (lp == NULL) return (rp); else if (rp == NULL) return (lp); for (dnp = lp; dnp->dn_list != NULL; dnp = dnp->dn_list) continue; dnp->dn_list = rp; return (lp); } /* * Compute the DOF dtrace_diftype_t representation of a node's type. This is * called from a variety of places in the library so it cannot assume yypcb * is valid: any references to handle-specific data must be made through 'dtp'. */ void dt_node_diftype(dtrace_hdl_t *dtp, const dt_node_t *dnp, dtrace_diftype_t *tp) { if (dnp->dn_ctfp == DT_STR_CTFP(dtp) && dnp->dn_type == DT_STR_TYPE(dtp)) { tp->dtdt_kind = DIF_TYPE_STRING; tp->dtdt_ckind = CTF_K_UNKNOWN; } else { tp->dtdt_kind = DIF_TYPE_CTF; tp->dtdt_ckind = ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type)); } tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ? (dnp->dn_flags & DT_NF_USERLAND) ? DIF_TF_BYUREF : DIF_TF_BYREF : 0; tp->dtdt_pad = 0; tp->dtdt_size = ctf_type_size(dnp->dn_ctfp, dnp->dn_type); } +/* + * Output the parse tree as D. The "-xtree=8" argument will call this + * function to print out the program after any syntactic sugar + * transformations have been applied (e.g. to implement "if"). The + * resulting output can be used to understand the transformations + * applied by these features, or to run such a script on a system that + * does not support these features + * + * Note that the output does not express precisely the same program as + * the input. In particular: + * - Only the clauses are output. #pragma options, variable + * declarations, etc. are excluded. + * - Command argument substitution has already been done, so the output + * will not contain e.g. $$1, but rather the substituted string. + */ void +dt_printd(dt_node_t *dnp, FILE *fp, int depth) +{ + dt_node_t *arg; + + switch (dnp->dn_kind) { + case DT_NODE_INT: + (void) fprintf(fp, "0x%llx", (u_longlong_t)dnp->dn_value); + if (!(dnp->dn_flags & DT_NF_SIGNED)) + (void) fprintf(fp, "u"); + break; + + case DT_NODE_STRING: { + char *escd = strchr2esc(dnp->dn_string, strlen(dnp->dn_string)); + (void) fprintf(fp, "\"%s\"", escd); + free(escd); + break; + } + + case DT_NODE_IDENT: + (void) fprintf(fp, "%s", dnp->dn_string); + break; + + case DT_NODE_VAR: + (void) fprintf(fp, "%s%s", + (dnp->dn_ident->di_flags & DT_IDFLG_LOCAL) ? "this->" : + (dnp->dn_ident->di_flags & DT_IDFLG_TLS) ? "self->" : "", + dnp->dn_ident->di_name); + + if (dnp->dn_args != NULL) { + (void) fprintf(fp, "["); + + for (arg = dnp->dn_args; arg != NULL; + arg = arg->dn_list) { + dt_printd(arg, fp, 0); + if (arg->dn_list != NULL) + (void) fprintf(fp, ", "); + } + + (void) fprintf(fp, "]"); + } + break; + + case DT_NODE_SYM: { + const dtrace_syminfo_t *dts = dnp->dn_ident->di_data; + (void) fprintf(fp, "%s`%s", dts->dts_object, dts->dts_name); + break; + } + case DT_NODE_FUNC: + (void) fprintf(fp, "%s(", dnp->dn_ident->di_name); + + for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) { + dt_printd(arg, fp, 0); + if (arg->dn_list != NULL) + (void) fprintf(fp, ", "); + } + (void) fprintf(fp, ")"); + break; + + case DT_NODE_OP1: + (void) fprintf(fp, "%s(", opstr(dnp->dn_op)); + dt_printd(dnp->dn_child, fp, 0); + (void) fprintf(fp, ")"); + break; + + case DT_NODE_OP2: + (void) fprintf(fp, "("); + dt_printd(dnp->dn_left, fp, 0); + if (dnp->dn_op == DT_TOK_LPAR) { + (void) fprintf(fp, ")"); + dt_printd(dnp->dn_right, fp, 0); + break; + } + if (dnp->dn_op == DT_TOK_PTR || dnp->dn_op == DT_TOK_DOT || + dnp->dn_op == DT_TOK_LBRAC) + (void) fprintf(fp, "%s", opstr(dnp->dn_op)); + else + (void) fprintf(fp, " %s ", opstr(dnp->dn_op)); + dt_printd(dnp->dn_right, fp, 0); + if (dnp->dn_op == DT_TOK_LBRAC) { + dt_node_t *ln = dnp->dn_right; + while (ln->dn_list != NULL) { + (void) fprintf(fp, ", "); + dt_printd(ln->dn_list, fp, depth); + ln = ln->dn_list; + } + (void) fprintf(fp, "]"); + } + (void) fprintf(fp, ")"); + break; + + case DT_NODE_OP3: + (void) fprintf(fp, "("); + dt_printd(dnp->dn_expr, fp, 0); + (void) fprintf(fp, " ? "); + dt_printd(dnp->dn_left, fp, 0); + (void) fprintf(fp, " : "); + dt_printd(dnp->dn_right, fp, 0); + (void) fprintf(fp, ")"); + break; + + case DT_NODE_DEXPR: + case DT_NODE_DFUNC: + (void) fprintf(fp, "%*s", depth * 8, ""); + dt_printd(dnp->dn_expr, fp, depth + 1); + (void) fprintf(fp, ";\n"); + break; + + case DT_NODE_PDESC: + (void) fprintf(fp, "%s:%s:%s:%s", + dnp->dn_desc->dtpd_provider, dnp->dn_desc->dtpd_mod, + dnp->dn_desc->dtpd_func, dnp->dn_desc->dtpd_name); + break; + + case DT_NODE_CLAUSE: + for (arg = dnp->dn_pdescs; arg != NULL; arg = arg->dn_list) { + dt_printd(arg, fp, 0); + if (arg->dn_list != NULL) + (void) fprintf(fp, ","); + (void) fprintf(fp, "\n"); + } + + if (dnp->dn_pred != NULL) { + (void) fprintf(fp, "/"); + dt_printd(dnp->dn_pred, fp, 0); + (void) fprintf(fp, "/\n"); + } + (void) fprintf(fp, "{\n"); + + for (arg = dnp->dn_acts; arg != NULL; arg = arg->dn_list) + dt_printd(arg, fp, depth + 1); + (void) fprintf(fp, "}\n"); + (void) fprintf(fp, "\n"); + break; + + case DT_NODE_IF: + (void) fprintf(fp, "%*sif (", depth * 8, ""); + dt_printd(dnp->dn_conditional, fp, 0); + (void) fprintf(fp, ") {\n"); + + for (arg = dnp->dn_body; arg != NULL; arg = arg->dn_list) + dt_printd(arg, fp, depth + 1); + if (dnp->dn_alternate_body == NULL) { + (void) fprintf(fp, "%*s}\n", depth * 8, ""); + } else { + (void) fprintf(fp, "%*s} else {\n", depth * 8, ""); + for (arg = dnp->dn_alternate_body; arg != NULL; + arg = arg->dn_list) + dt_printd(arg, fp, depth + 1); + (void) fprintf(fp, "%*s}\n", depth * 8, ""); + } + + break; + + default: + (void) fprintf(fp, "/* bad node %p, kind %d */\n", + (void *)dnp, dnp->dn_kind); + } +} + +void dt_node_printr(dt_node_t *dnp, FILE *fp, int depth) { char n[DT_TYPE_NAMELEN], buf[BUFSIZ], a[8]; const dtrace_syminfo_t *dts; const dt_idnode_t *inp; dt_node_t *arg; (void) fprintf(fp, "%*s", depth * 2, ""); (void) dt_attr_str(dnp->dn_attr, a, sizeof (a)); if (dnp->dn_ctfp != NULL && dnp->dn_type != CTF_ERR && ctf_type_name(dnp->dn_ctfp, dnp->dn_type, n, sizeof (n)) != NULL) { (void) snprintf(buf, BUFSIZ, "type=<%s> attr=%s flags=", n, a); } else { (void) snprintf(buf, BUFSIZ, "type=<%ld> attr=%s flags=", dnp->dn_type, a); } if (dnp->dn_flags != 0) { n[0] = '\0'; if (dnp->dn_flags & DT_NF_SIGNED) (void) strcat(n, ",SIGN"); if (dnp->dn_flags & DT_NF_COOKED) (void) strcat(n, ",COOK"); if (dnp->dn_flags & DT_NF_REF) (void) strcat(n, ",REF"); if (dnp->dn_flags & DT_NF_LVALUE) (void) strcat(n, ",LVAL"); if (dnp->dn_flags & DT_NF_WRITABLE) (void) strcat(n, ",WRITE"); if (dnp->dn_flags & DT_NF_BITFIELD) (void) strcat(n, ",BITF"); if (dnp->dn_flags & DT_NF_USERLAND) (void) strcat(n, ",USER"); (void) strcat(buf, n + 1); } else (void) strcat(buf, "0"); switch (dnp->dn_kind) { case DT_NODE_FREE: (void) fprintf(fp, "FREE \n", (void *)dnp); break; case DT_NODE_INT: (void) fprintf(fp, "INT 0x%llx (%s)\n", (u_longlong_t)dnp->dn_value, buf); break; case DT_NODE_STRING: (void) fprintf(fp, "STRING \"%s\" (%s)\n", dnp->dn_string, buf); break; case DT_NODE_IDENT: (void) fprintf(fp, "IDENT %s (%s)\n", dnp->dn_string, buf); break; case DT_NODE_VAR: (void) fprintf(fp, "VARIABLE %s%s (%s)\n", (dnp->dn_ident->di_flags & DT_IDFLG_LOCAL) ? "this->" : (dnp->dn_ident->di_flags & DT_IDFLG_TLS) ? "self->" : "", dnp->dn_ident->di_name, buf); if (dnp->dn_args != NULL) (void) fprintf(fp, "%*s[\n", depth * 2, ""); for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) { dt_node_printr(arg, fp, depth + 1); if (arg->dn_list != NULL) (void) fprintf(fp, "%*s,\n", depth * 2, ""); } if (dnp->dn_args != NULL) (void) fprintf(fp, "%*s]\n", depth * 2, ""); break; case DT_NODE_SYM: dts = dnp->dn_ident->di_data; (void) fprintf(fp, "SYMBOL %s`%s (%s)\n", dts->dts_object, dts->dts_name, buf); break; case DT_NODE_TYPE: if (dnp->dn_string != NULL) { (void) fprintf(fp, "TYPE (%s) %s\n", buf, dnp->dn_string); } else (void) fprintf(fp, "TYPE (%s)\n", buf); break; case DT_NODE_FUNC: (void) fprintf(fp, "FUNC %s (%s)\n", dnp->dn_ident->di_name, buf); for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) { dt_node_printr(arg, fp, depth + 1); if (arg->dn_list != NULL) (void) fprintf(fp, "%*s,\n", depth * 2, ""); } break; case DT_NODE_OP1: (void) fprintf(fp, "OP1 %s (%s)\n", opstr(dnp->dn_op), buf); dt_node_printr(dnp->dn_child, fp, depth + 1); break; case DT_NODE_OP2: (void) fprintf(fp, "OP2 %s (%s)\n", opstr(dnp->dn_op), buf); dt_node_printr(dnp->dn_left, fp, depth + 1); dt_node_printr(dnp->dn_right, fp, depth + 1); + if (dnp->dn_op == DT_TOK_LBRAC) { + dt_node_t *ln = dnp->dn_right; + while (ln->dn_list != NULL) { + dt_node_printr(ln->dn_list, fp, depth + 1); + ln = ln->dn_list; + } + } break; case DT_NODE_OP3: (void) fprintf(fp, "OP3 (%s)\n", buf); dt_node_printr(dnp->dn_expr, fp, depth + 1); (void) fprintf(fp, "%*s?\n", depth * 2, ""); dt_node_printr(dnp->dn_left, fp, depth + 1); (void) fprintf(fp, "%*s:\n", depth * 2, ""); dt_node_printr(dnp->dn_right, fp, depth + 1); break; case DT_NODE_DEXPR: case DT_NODE_DFUNC: (void) fprintf(fp, "D EXPRESSION attr=%s\n", a); dt_node_printr(dnp->dn_expr, fp, depth + 1); break; case DT_NODE_AGG: (void) fprintf(fp, "AGGREGATE @%s attr=%s [\n", dnp->dn_ident->di_name, a); for (arg = dnp->dn_aggtup; arg != NULL; arg = arg->dn_list) { dt_node_printr(arg, fp, depth + 1); if (arg->dn_list != NULL) (void) fprintf(fp, "%*s,\n", depth * 2, ""); } if (dnp->dn_aggfun) { (void) fprintf(fp, "%*s] = ", depth * 2, ""); dt_node_printr(dnp->dn_aggfun, fp, depth + 1); } else (void) fprintf(fp, "%*s]\n", depth * 2, ""); if (dnp->dn_aggfun) (void) fprintf(fp, "%*s)\n", depth * 2, ""); break; case DT_NODE_PDESC: (void) fprintf(fp, "PDESC %s:%s:%s:%s [%u]\n", dnp->dn_desc->dtpd_provider, dnp->dn_desc->dtpd_mod, dnp->dn_desc->dtpd_func, dnp->dn_desc->dtpd_name, dnp->dn_desc->dtpd_id); break; case DT_NODE_CLAUSE: (void) fprintf(fp, "CLAUSE attr=%s\n", a); for (arg = dnp->dn_pdescs; arg != NULL; arg = arg->dn_list) dt_node_printr(arg, fp, depth + 1); (void) fprintf(fp, "%*sCTXATTR %s\n", depth * 2, "", dt_attr_str(dnp->dn_ctxattr, a, sizeof (a))); if (dnp->dn_pred != NULL) { (void) fprintf(fp, "%*sPREDICATE /\n", depth * 2, ""); dt_node_printr(dnp->dn_pred, fp, depth + 1); (void) fprintf(fp, "%*s/\n", depth * 2, ""); } for (arg = dnp->dn_acts; arg != NULL; arg = arg->dn_list) dt_node_printr(arg, fp, depth + 1); + (void) fprintf(fp, "\n"); break; case DT_NODE_INLINE: inp = dnp->dn_ident->di_iarg; (void) fprintf(fp, "INLINE %s (%s)\n", dnp->dn_ident->di_name, buf); dt_node_printr(inp->din_root, fp, depth + 1); break; case DT_NODE_MEMBER: (void) fprintf(fp, "MEMBER %s (%s)\n", dnp->dn_membname, buf); if (dnp->dn_membexpr) dt_node_printr(dnp->dn_membexpr, fp, depth + 1); break; case DT_NODE_XLATOR: (void) fprintf(fp, "XLATOR (%s)", buf); if (ctf_type_name(dnp->dn_xlator->dx_src_ctfp, dnp->dn_xlator->dx_src_type, n, sizeof (n)) != NULL) (void) fprintf(fp, " from <%s>", n); if (ctf_type_name(dnp->dn_xlator->dx_dst_ctfp, dnp->dn_xlator->dx_dst_type, n, sizeof (n)) != NULL) (void) fprintf(fp, " to <%s>", n); (void) fprintf(fp, "\n"); for (arg = dnp->dn_members; arg != NULL; arg = arg->dn_list) dt_node_printr(arg, fp, depth + 1); break; case DT_NODE_PROBE: (void) fprintf(fp, "PROBE %s\n", dnp->dn_ident->di_name); break; case DT_NODE_PROVIDER: (void) fprintf(fp, "PROVIDER %s (%s)\n", dnp->dn_provname, dnp->dn_provred ? "redecl" : "decl"); for (arg = dnp->dn_probes; arg != NULL; arg = arg->dn_list) dt_node_printr(arg, fp, depth + 1); break; case DT_NODE_PROG: (void) fprintf(fp, "PROGRAM attr=%s\n", a); for (arg = dnp->dn_list; arg != NULL; arg = arg->dn_list) dt_node_printr(arg, fp, depth + 1); + break; + + case DT_NODE_IF: + (void) fprintf(fp, "IF attr=%s CONDITION:\n", a); + + dt_node_printr(dnp->dn_conditional, fp, depth + 1); + + (void) fprintf(fp, "%*sIF BODY: \n", depth * 2, ""); + for (arg = dnp->dn_body; arg != NULL; arg = arg->dn_list) + dt_node_printr(arg, fp, depth + 1); + + if (dnp->dn_alternate_body != NULL) { + (void) fprintf(fp, "%*sIF ELSE: \n", depth * 2, ""); + for (arg = dnp->dn_alternate_body; arg != NULL; + arg = arg->dn_list) + dt_node_printr(arg, fp, depth + 1); + } + break; default: (void) fprintf(fp, "\n", (void *)dnp, dnp->dn_kind); } } int dt_node_root(dt_node_t *dnp) { yypcb->pcb_root = dnp; return (0); } /*PRINTFLIKE3*/ void dnerror(const dt_node_t *dnp, dt_errtag_t tag, const char *format, ...) { int oldlineno = yylineno; va_list ap; yylineno = dnp->dn_line; va_start(ap, format); xyvwarn(tag, format, ap); va_end(ap); yylineno = oldlineno; longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } /*PRINTFLIKE3*/ void dnwarn(const dt_node_t *dnp, dt_errtag_t tag, const char *format, ...) { int oldlineno = yylineno; va_list ap; yylineno = dnp->dn_line; va_start(ap, format); xyvwarn(tag, format, ap); va_end(ap); yylineno = oldlineno; } /*PRINTFLIKE2*/ void xyerror(dt_errtag_t tag, const char *format, ...) { va_list ap; va_start(ap, format); xyvwarn(tag, format, ap); va_end(ap); longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } /*PRINTFLIKE2*/ void xywarn(dt_errtag_t tag, const char *format, ...) { va_list ap; va_start(ap, format); xyvwarn(tag, format, ap); va_end(ap); } void xyvwarn(dt_errtag_t tag, const char *format, va_list ap) { if (yypcb == NULL) return; /* compiler is not currently active: act as a no-op */ dt_set_errmsg(yypcb->pcb_hdl, dt_errtag(tag), yypcb->pcb_region, yypcb->pcb_filetag, yypcb->pcb_fileptr ? yylineno : 0, format, ap); } /*PRINTFLIKE1*/ void yyerror(const char *format, ...) { va_list ap; va_start(ap, format); yyvwarn(format, ap); va_end(ap); longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); } /*PRINTFLIKE1*/ void yywarn(const char *format, ...) { va_list ap; va_start(ap, format); yyvwarn(format, ap); va_end(ap); } void yyvwarn(const char *format, va_list ap) { if (yypcb == NULL) return; /* compiler is not currently active: act as a no-op */ dt_set_errmsg(yypcb->pcb_hdl, dt_errtag(D_SYNTAX), yypcb->pcb_region, yypcb->pcb_filetag, yypcb->pcb_fileptr ? yylineno : 0, format, ap); if (strchr(format, '\n') == NULL) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; size_t len = strlen(dtp->dt_errmsg); char *p, *s = dtp->dt_errmsg + len; size_t n = sizeof (dtp->dt_errmsg) - len; if (yytext[0] == '\0') (void) snprintf(s, n, " near end of input"); else if (yytext[0] == '\n') (void) snprintf(s, n, " near end of line"); else { if ((p = strchr(yytext, '\n')) != NULL) *p = '\0'; /* crop at newline */ (void) snprintf(s, n, " near \"%s\"", yytext); } } } void yylabel(const char *label) { dt_dprintf("set label to <%s>\n", label ? label : "NULL"); yypcb->pcb_region = label; } int yywrap(void) { return (1); /* indicate that lex should return a zero token for EOF */ } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.h =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.h (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_parser.h (revision 304200) @@ -1,287 +1,301 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* - * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2013, 2016 by Delphix. All rights reserved. * Copyright (c) 2013 Joyent, Inc. All rights reserved. */ #ifndef _DT_PARSER_H #define _DT_PARSER_H #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include typedef struct dt_node { ctf_file_t *dn_ctfp; /* CTF type container for node's type */ ctf_id_t dn_type; /* CTF type reference for node's type */ uchar_t dn_kind; /* node kind (DT_NODE_*, defined below) */ uchar_t dn_flags; /* node flags (DT_NF_*, defined below) */ ushort_t dn_op; /* operator (DT_TOK_*, defined by lex) */ int dn_line; /* line number for error messages */ int dn_reg; /* register allocated by cg */ dtrace_attribute_t dn_attr; /* node stability attributes */ /* * D compiler nodes, as is the usual style, contain a union of the * different sub-elements required by the various kinds of nodes. * These sub-elements are accessed using the macros defined below. */ union { struct { uintmax_t _value; /* integer value */ char *_string; /* string value */ } _const; struct { dt_ident_t *_ident; /* identifier reference */ struct dt_node *_links[3]; /* child node pointers */ } _nodes; struct { struct dt_node *_descs; /* list of descriptions */ struct dt_node *_pred; /* predicate expression */ struct dt_node *_acts; /* action statement list */ dt_idhash_t *_locals; /* local variable hash */ dtrace_attribute_t _attr; /* context attributes */ } _clause; struct { char *_spec; /* specifier string (if any) */ dtrace_probedesc_t *_desc; /* final probe description */ } _pdesc; struct { char *_name; /* string name of member */ struct dt_node *_expr; /* expression node pointer */ dt_xlator_t *_xlator; /* translator reference */ uint_t _id; /* member identifier */ } _member; struct { dt_xlator_t *_xlator; /* translator reference */ struct dt_node *_xmemb; /* individual xlator member */ struct dt_node *_membs; /* list of member nodes */ } _xlator; struct { char *_name; /* string name of provider */ struct dt_provider *_pvp; /* provider references */ struct dt_node *_probes; /* list of probe nodes */ int _redecl; /* provider redeclared */ } _provider; + + struct { + struct dt_node *_conditional; + struct dt_node *_body; + struct dt_node *_alternate_body; + } _conditional; } dn_u; struct dt_node *dn_list; /* parse tree list link */ struct dt_node *dn_link; /* allocation list link */ } dt_node_t; #define dn_value dn_u._const._value /* DT_NODE_INT */ #define dn_string dn_u._const._string /* STRING, IDENT, TYPE */ #define dn_ident dn_u._nodes._ident /* VAR,SYM,FUN,AGG,INL,PROBE */ #define dn_args dn_u._nodes._links[0] /* DT_NODE_VAR, FUNC */ #define dn_child dn_u._nodes._links[0] /* DT_NODE_OP1 */ #define dn_left dn_u._nodes._links[0] /* DT_NODE_OP2, OP3 */ #define dn_right dn_u._nodes._links[1] /* DT_NODE_OP2, OP3 */ #define dn_expr dn_u._nodes._links[2] /* DT_NODE_OP3, DEXPR */ #define dn_aggfun dn_u._nodes._links[0] /* DT_NODE_AGG */ #define dn_aggtup dn_u._nodes._links[1] /* DT_NODE_AGG */ #define dn_pdescs dn_u._clause._descs /* DT_NODE_CLAUSE */ #define dn_pred dn_u._clause._pred /* DT_NODE_CLAUSE */ #define dn_acts dn_u._clause._acts /* DT_NODE_CLAUSE */ #define dn_locals dn_u._clause._locals /* DT_NODE_CLAUSE */ #define dn_ctxattr dn_u._clause._attr /* DT_NODE_CLAUSE */ #define dn_spec dn_u._pdesc._spec /* DT_NODE_PDESC */ #define dn_desc dn_u._pdesc._desc /* DT_NODE_PDESC */ #define dn_membname dn_u._member._name /* DT_NODE_MEMBER */ #define dn_membexpr dn_u._member._expr /* DT_NODE_MEMBER */ #define dn_membxlator dn_u._member._xlator /* DT_NODE_MEMBER */ #define dn_membid dn_u._member._id /* DT_NODE_MEMBER */ #define dn_xlator dn_u._xlator._xlator /* DT_NODE_XLATOR */ #define dn_xmember dn_u._xlator._xmemb /* DT_NODE_XLATOR */ #define dn_members dn_u._xlator._membs /* DT_NODE_XLATOR */ #define dn_provname dn_u._provider._name /* DT_NODE_PROVIDER */ #define dn_provider dn_u._provider._pvp /* DT_NODE_PROVIDER */ #define dn_provred dn_u._provider._redecl /* DT_NODE_PROVIDER */ #define dn_probes dn_u._provider._probes /* DT_NODE_PROVIDER */ +/* DT_NODE_IF: */ +#define dn_conditional dn_u._conditional._conditional +#define dn_body dn_u._conditional._body +#define dn_alternate_body dn_u._conditional._alternate_body + #define DT_NODE_FREE 0 /* unused node (waiting to be freed) */ #define DT_NODE_INT 1 /* integer value */ #define DT_NODE_STRING 2 /* string value */ #define DT_NODE_IDENT 3 /* identifier */ #define DT_NODE_VAR 4 /* variable reference */ #define DT_NODE_SYM 5 /* symbol reference */ #define DT_NODE_TYPE 6 /* type reference or formal parameter */ #define DT_NODE_FUNC 7 /* function call */ #define DT_NODE_OP1 8 /* unary operator */ #define DT_NODE_OP2 9 /* binary operator */ #define DT_NODE_OP3 10 /* ternary operator */ #define DT_NODE_DEXPR 11 /* D expression action */ #define DT_NODE_DFUNC 12 /* D function action */ #define DT_NODE_AGG 13 /* aggregation */ #define DT_NODE_PDESC 14 /* probe description */ #define DT_NODE_CLAUSE 15 /* clause definition */ #define DT_NODE_INLINE 16 /* inline definition */ #define DT_NODE_MEMBER 17 /* member definition */ #define DT_NODE_XLATOR 18 /* translator definition */ #define DT_NODE_PROBE 19 /* probe definition */ #define DT_NODE_PROVIDER 20 /* provider definition */ #define DT_NODE_PROG 21 /* program translation unit */ +#define DT_NODE_IF 22 /* if statement */ #define DT_NF_SIGNED 0x01 /* data is a signed quantity (else unsigned) */ #define DT_NF_COOKED 0x02 /* data is a known type (else still cooking) */ #define DT_NF_REF 0x04 /* pass by reference (array, struct, union) */ #define DT_NF_LVALUE 0x08 /* node is an l-value according to ANSI-C */ #define DT_NF_WRITABLE 0x10 /* node is writable (can be modified) */ #define DT_NF_BITFIELD 0x20 /* node is an integer bitfield */ #define DT_NF_USERLAND 0x40 /* data is a userland address */ #define DT_TYPE_NAMELEN 128 /* reasonable size for ctf_type_name() */ extern int dt_node_is_integer(const dt_node_t *); extern int dt_node_is_float(const dt_node_t *); extern int dt_node_is_scalar(const dt_node_t *); extern int dt_node_is_arith(const dt_node_t *); extern int dt_node_is_vfptr(const dt_node_t *); extern int dt_node_is_dynamic(const dt_node_t *); extern int dt_node_is_stack(const dt_node_t *); extern int dt_node_is_symaddr(const dt_node_t *); extern int dt_node_is_usymaddr(const dt_node_t *); extern int dt_node_is_string(const dt_node_t *); extern int dt_node_is_strcompat(const dt_node_t *); extern int dt_node_is_pointer(const dt_node_t *); extern int dt_node_is_void(const dt_node_t *); extern int dt_node_is_ptrcompat(const dt_node_t *, const dt_node_t *, ctf_file_t **, ctf_id_t *); extern int dt_node_is_argcompat(const dt_node_t *, const dt_node_t *); extern int dt_node_is_posconst(const dt_node_t *); extern int dt_node_is_actfunc(const dt_node_t *); extern dt_node_t *dt_node_int(uintmax_t); extern dt_node_t *dt_node_string(char *); extern dt_node_t *dt_node_ident(char *); extern dt_node_t *dt_node_type(dt_decl_t *); extern dt_node_t *dt_node_vatype(void); extern dt_node_t *dt_node_decl(void); extern dt_node_t *dt_node_func(dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_offsetof(dt_decl_t *, char *); extern dt_node_t *dt_node_op1(int, dt_node_t *); extern dt_node_t *dt_node_op2(int, dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_op3(dt_node_t *, dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_statement(dt_node_t *); extern dt_node_t *dt_node_pdesc_by_name(char *); extern dt_node_t *dt_node_pdesc_by_id(uintmax_t); extern dt_node_t *dt_node_clause(dt_node_t *, dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_inline(dt_node_t *); extern dt_node_t *dt_node_member(dt_decl_t *, char *, dt_node_t *); extern dt_node_t *dt_node_xlator(dt_decl_t *, dt_decl_t *, char *, dt_node_t *); extern dt_node_t *dt_node_probe(char *, int, dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_provider(char *, dt_node_t *); extern dt_node_t *dt_node_program(dt_node_t *); +extern dt_node_t *dt_node_if(dt_node_t *, dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_link(dt_node_t *, dt_node_t *); extern dt_node_t *dt_node_cook(dt_node_t *, uint_t); extern dt_node_t *dt_node_xalloc(dtrace_hdl_t *, int); extern void dt_node_free(dt_node_t *); extern dtrace_attribute_t dt_node_list_cook(dt_node_t **, uint_t); extern void dt_node_list_free(dt_node_t **); extern void dt_node_link_free(dt_node_t **); extern void dt_node_attr_assign(dt_node_t *, dtrace_attribute_t); extern void dt_node_type_assign(dt_node_t *, ctf_file_t *, ctf_id_t, boolean_t); extern void dt_node_type_propagate(const dt_node_t *, dt_node_t *); extern const char *dt_node_type_name(const dt_node_t *, char *, size_t); extern size_t dt_node_type_size(const dt_node_t *); extern dt_ident_t *dt_node_resolve(const dt_node_t *, uint_t); extern size_t dt_node_sizeof(const dt_node_t *); extern void dt_node_promote(dt_node_t *, dt_node_t *, dt_node_t *); extern void dt_node_diftype(dtrace_hdl_t *, const dt_node_t *, dtrace_diftype_t *); extern void dt_node_printr(dt_node_t *, FILE *, int); +extern void dt_printd(dt_node_t *, FILE *, int); extern const char *dt_node_name(const dt_node_t *, char *, size_t); extern int dt_node_root(dt_node_t *); struct dtrace_typeinfo; /* see */ struct dt_pcb; /* see */ #define IS_CHAR(e) \ (((e).cte_format & (CTF_INT_CHAR | CTF_INT_SIGNED)) == \ (CTF_INT_CHAR | CTF_INT_SIGNED) && (e).cte_bits == NBBY) #define IS_VOID(e) \ ((e).cte_offset == 0 && (e).cte_bits == 0) extern int dt_type_lookup(const char *, struct dtrace_typeinfo *); extern int dt_type_pointer(struct dtrace_typeinfo *); extern const char *dt_type_name(ctf_file_t *, ctf_id_t, char *, size_t); typedef enum { YYS_CLAUSE, /* lex/yacc state for finding program clauses */ YYS_DEFINE, /* lex/yacc state for parsing persistent definitions */ YYS_EXPR, /* lex/yacc state for parsing D expressions */ YYS_DONE, /* lex/yacc state for indicating parse tree is done */ YYS_CONTROL /* lex/yacc state for parsing control lines */ } yystate_t; extern void dnerror(const dt_node_t *, dt_errtag_t, const char *, ...); extern void dnwarn(const dt_node_t *, dt_errtag_t, const char *, ...); extern void xyerror(dt_errtag_t, const char *, ...); extern void xywarn(dt_errtag_t, const char *, ...); extern void xyvwarn(dt_errtag_t, const char *, va_list); extern void yyerror(const char *, ...); extern void yywarn(const char *, ...); extern void yyvwarn(const char *, va_list); extern void yylabel(const char *); extern void yybegin(yystate_t); extern void yyinit(struct dt_pcb *); extern int yyparse(void); extern int yyinput(void); #ifdef __cplusplus } #endif #endif /* _DT_PARSER_H */ Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_sugar.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_sugar.c (nonexistent) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_sugar.c (revision 304200) @@ -0,0 +1,516 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2012, 2016 by Delphix. All rights reserved. + */ + +/* + * Syntactic sugar features are implemented by transforming the D parse tree + * such that it only uses the subset of D that is supported by the rest of the + * compiler / the kernel. A clause containing these language features is + * referred to as a "super-clause", and its transformation typically entails + * creating several "sub-clauses" to implement it. For diagnosability, the + * sub-clauses will be printed if the "-xtree=8" flag is specified. + * + * Currently, the only syntactic sugar feature is "if/else" statements. Each + * basic block (e.g. the body of the "if" and "else" statements, and the + * statements before and after) is turned into its own sub-clause, with a + * predicate that causes it to be executed only if the code flows to this point. + * Nested if/else statements are supported. + * + * This infrastructure is designed to accommodate other syntactic sugar features + * in the future. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct dt_sugar_parse { + dtrace_hdl_t *dtsp_dtp; /* dtrace handle */ + dt_node_t *dtsp_pdescs; /* probe descriptions */ + int dtsp_num_conditions; /* number of condition variables */ + int dtsp_num_ifs; /* number of "if" statements */ + dt_node_t *dtsp_clause_list; /* list of clauses */ +} dt_sugar_parse_t; + +static void dt_sugar_visit_stmts(dt_sugar_parse_t *, dt_node_t *, int); + +/* + * Return a node for "self->%error". + * + * Note that the "%" is part of the variable name, and is included so that + * this variable name can not collide with any user-specified variable. + * + * This error variable is used to keep track of if there has been an error + * in any of the sub-clauses, and is used to prevent execution of subsequent + * sub-clauses following an error. + */ +static dt_node_t * +dt_sugar_new_error_var(void) +{ + return (dt_node_op2(DT_TOK_PTR, dt_node_ident(strdup("self")), + dt_node_ident(strdup("%error")))); +} + +/* + * Append this clause to the clause list. + */ +static void +dt_sugar_append_clause(dt_sugar_parse_t *dp, dt_node_t *clause) +{ + dp->dtsp_clause_list = dt_node_link(dp->dtsp_clause_list, clause); +} + +/* + * Prepend this clause to the clause list. + */ +static void +dt_sugar_prepend_clause(dt_sugar_parse_t *dp, dt_node_t *clause) +{ + dp->dtsp_clause_list = dt_node_link(clause, dp->dtsp_clause_list); +} + +/* + * Return a node for "this->%condition_", or NULL if condid==0. + * + * Note that the "%" is part of the variable name, and is included so that + * this variable name can not collide with any user-specified variable. + */ +static dt_node_t * +dt_sugar_new_condition_var(int condid) +{ + char *str; + + if (condid == 0) + return (NULL); + assert(condid > 0); + + (void) asprintf(&str, "%%condition_%d", ABS(condid)); + return (dt_node_op2(DT_TOK_PTR, dt_node_ident(strdup("this")), + dt_node_ident(str))); +} + +/* + * Return new clause to evaluate predicate and set newcond. condid is + * the condition that we are already under, or 0 if none. + * The new clause will be of the form: + * + * dp_pdescs + * /!self->%error/ + * { + * this->%condition_ = + * (this->%condition_ && pred); + * } + * + * Note: if condid==0, we will instead do "... = (1 && pred)", to effectively + * convert the pred to a boolean. + * + * Note: Unless an error has been encountered, we always set the condition + * variable (either to 0 or 1). This lets us avoid resetting the condition + * variables back to 0 when the super-clause completes. + */ +static dt_node_t * +dt_sugar_new_condition_impl(dt_sugar_parse_t *dp, + dt_node_t *pred, int condid, int newcond) +{ + dt_node_t *value, *body, *newpred; + + /* predicate is !self->%error */ + newpred = dt_node_op1(DT_TOK_LNEG, dt_sugar_new_error_var()); + + if (condid == 0) { + /* + * value is (1 && pred) + * + * Note, D doesn't allow a probe-local "this" variable to + * be reused as a different type, even from a different probe. + * Therefore, value can't simply be , because then + * its type could be different when we reuse this condid + * in a different meta-clause. + */ + value = dt_node_op2(DT_TOK_LAND, dt_node_int(1), pred); + } else { + /* value is (this->%condition_ && pred) */ + value = dt_node_op2(DT_TOK_LAND, + dt_sugar_new_condition_var(condid), pred); + } + + /* body is "this->%condition_ = ;" */ + body = dt_node_statement(dt_node_op2(DT_TOK_ASGN, + dt_sugar_new_condition_var(newcond), value)); + + return (dt_node_clause(dp->dtsp_pdescs, newpred, body)); +} + +/* + * Generate a new clause to evaluate predicate and set a new condition variable, + * whose ID will be returned. The new clause will be appended to + * dp_first_new_clause. + */ +static int +dt_sugar_new_condition(dt_sugar_parse_t *dp, dt_node_t *pred, int condid) +{ + dp->dtsp_num_conditions++; + dt_sugar_append_clause(dp, dt_sugar_new_condition_impl(dp, + pred, condid, dp->dtsp_num_conditions)); + return (dp->dtsp_num_conditions); +} + +/* + * Visit the specified node and all of its descendants. Currently this is only + * used to count the number of "if" statements (dtsp_num_ifs). + */ +static void +dt_sugar_visit_all(dt_sugar_parse_t *dp, dt_node_t *dnp) +{ + dt_node_t *arg; + + switch (dnp->dn_kind) { + case DT_NODE_FREE: + case DT_NODE_INT: + case DT_NODE_STRING: + case DT_NODE_SYM: + case DT_NODE_TYPE: + case DT_NODE_PROBE: + case DT_NODE_PDESC: + case DT_NODE_IDENT: + break; + + case DT_NODE_FUNC: + for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + break; + + case DT_NODE_OP1: + dt_sugar_visit_all(dp, dnp->dn_child); + break; + + case DT_NODE_OP2: + dt_sugar_visit_all(dp, dnp->dn_left); + dt_sugar_visit_all(dp, dnp->dn_right); + if (dnp->dn_op == DT_TOK_LBRAC) { + dt_node_t *ln = dnp->dn_right; + while (ln->dn_list != NULL) { + dt_sugar_visit_all(dp, ln->dn_list); + ln = ln->dn_list; + } + } + break; + + case DT_NODE_OP3: + dt_sugar_visit_all(dp, dnp->dn_expr); + dt_sugar_visit_all(dp, dnp->dn_left); + dt_sugar_visit_all(dp, dnp->dn_right); + break; + + case DT_NODE_DEXPR: + case DT_NODE_DFUNC: + dt_sugar_visit_all(dp, dnp->dn_expr); + break; + + case DT_NODE_AGG: + for (arg = dnp->dn_aggtup; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + + if (dnp->dn_aggfun) + dt_sugar_visit_all(dp, dnp->dn_aggfun); + break; + + case DT_NODE_CLAUSE: + for (arg = dnp->dn_pdescs; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + + if (dnp->dn_pred != NULL) + dt_sugar_visit_all(dp, dnp->dn_pred); + + for (arg = dnp->dn_acts; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + break; + + case DT_NODE_INLINE: { + const dt_idnode_t *inp = dnp->dn_ident->di_iarg; + + dt_sugar_visit_all(dp, inp->din_root); + break; + } + case DT_NODE_MEMBER: + if (dnp->dn_membexpr) + dt_sugar_visit_all(dp, dnp->dn_membexpr); + break; + + case DT_NODE_XLATOR: + for (arg = dnp->dn_members; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + break; + + case DT_NODE_PROVIDER: + for (arg = dnp->dn_probes; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + break; + + case DT_NODE_PROG: + for (arg = dnp->dn_list; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + break; + + case DT_NODE_IF: + dp->dtsp_num_ifs++; + dt_sugar_visit_all(dp, dnp->dn_conditional); + + for (arg = dnp->dn_body; arg != NULL; arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + for (arg = dnp->dn_alternate_body; arg != NULL; + arg = arg->dn_list) + dt_sugar_visit_all(dp, arg); + + break; + + default: + (void) dnerror(dnp, D_UNKNOWN, "bad node %p, kind %d\n", + (void *)dnp, dnp->dn_kind); + } +} + +/* + * Return a new clause which resets the error variable to zero: + * + * dp_pdescs{ self->%error = 0; } + * + * This clause will be executed at the beginning of each meta-clause, to + * ensure the error variable is unset (in case the previous meta-clause + * failed). + */ +static dt_node_t * +dt_sugar_new_clearerror_clause(dt_sugar_parse_t *dp) +{ + dt_node_t *stmt = dt_node_statement(dt_node_op2(DT_TOK_ASGN, + dt_sugar_new_error_var(), dt_node_int(0))); + return (dt_node_clause(dp->dtsp_pdescs, NULL, stmt)); +} + +/* + * Evaluate the conditional, and recursively visit the body of the "if" + * statement (and the "else", if present). + */ +static void +dt_sugar_do_if(dt_sugar_parse_t *dp, dt_node_t *if_stmt, int precondition) +{ + int newid; + + assert(if_stmt->dn_kind == DT_NODE_IF); + + /* condition */ + newid = dt_sugar_new_condition(dp, + if_stmt->dn_conditional, precondition); + + /* body of if */ + dt_sugar_visit_stmts(dp, if_stmt->dn_body, newid); + + /* + * Visit the body of the "else" statement, if present. Note that we + * generate a new condition which is the inverse of the previous + * condition. + */ + if (if_stmt->dn_alternate_body != NULL) { + dt_node_t *pred = + dt_node_op1(DT_TOK_LNEG, dt_sugar_new_condition_var(newid)); + dt_sugar_visit_stmts(dp, if_stmt->dn_alternate_body, + dt_sugar_new_condition(dp, pred, precondition)); + } +} + +/* + * Generate a new clause to evaluate the statements based on the condition. + * The new clause will be appended to dp_first_new_clause. + * + * dp_pdescs + * /!self->%error && this->%condition_/ + * { + * stmts + * } + */ +static void +dt_sugar_new_basic_block(dt_sugar_parse_t *dp, int condid, dt_node_t *stmts) +{ + dt_node_t *pred = NULL; + + if (condid == 0) { + /* + * Don't bother with !error on the first clause, because if + * there is only one clause, we don't add the prelude to + * zero out %error. + */ + if (dp->dtsp_num_conditions != 0) { + pred = dt_node_op1(DT_TOK_LNEG, + dt_sugar_new_error_var()); + } + } else { + pred = dt_node_op2(DT_TOK_LAND, + dt_node_op1(DT_TOK_LNEG, dt_sugar_new_error_var()), + dt_sugar_new_condition_var(condid)); + } + dt_sugar_append_clause(dp, + dt_node_clause(dp->dtsp_pdescs, pred, stmts)); +} + +/* + * Visit all the statements in this list, and break them into basic blocks, + * generating new clauses for "if" and "else" statements. + */ +static void +dt_sugar_visit_stmts(dt_sugar_parse_t *dp, dt_node_t *stmts, int precondition) +{ + dt_node_t *stmt; + dt_node_t *prev_stmt = NULL; + dt_node_t *next_stmt; + dt_node_t *first_stmt_in_basic_block = NULL; + + for (stmt = stmts; stmt != NULL; stmt = next_stmt) { + next_stmt = stmt->dn_list; + + if (stmt->dn_kind != DT_NODE_IF) { + if (first_stmt_in_basic_block == NULL) + first_stmt_in_basic_block = stmt; + prev_stmt = stmt; + continue; + } + + /* + * Remove this and following statements from the previous + * clause. + */ + if (prev_stmt != NULL) + prev_stmt->dn_list = NULL; + + /* + * Generate clause for statements preceding the "if" + */ + if (first_stmt_in_basic_block != NULL) { + dt_sugar_new_basic_block(dp, precondition, + first_stmt_in_basic_block); + } + + dt_sugar_do_if(dp, stmt, precondition); + + first_stmt_in_basic_block = NULL; + + prev_stmt = stmt; + } + + /* generate clause for statements after last "if". */ + if (first_stmt_in_basic_block != NULL) { + dt_sugar_new_basic_block(dp, precondition, + first_stmt_in_basic_block); + } +} + +/* + * Generate a new clause which will set the error variable when an error occurs. + * Only one of these clauses is created per program (e.g. script file). + * The clause is: + * + * dtrace:::ERROR{ self->%error = 1; } + */ +static dt_node_t * +dt_sugar_makeerrorclause(void) +{ + dt_node_t *acts, *pdesc; + + pdesc = dt_node_pdesc_by_name(strdup("dtrace:::ERROR")); + + acts = dt_node_statement(dt_node_op2(DT_TOK_ASGN, + dt_sugar_new_error_var(), dt_node_int(1))); + + return (dt_node_clause(pdesc, NULL, acts)); +} + +/* + * Transform the super-clause into straight-D, returning the new list of + * sub-clauses. + */ +dt_node_t * +dt_compile_sugar(dtrace_hdl_t *dtp, dt_node_t *clause) +{ + dt_sugar_parse_t dp = { 0 }; + int condid = 0; + + dp.dtsp_dtp = dtp; + dp.dtsp_pdescs = clause->dn_pdescs; + + /* make dt_node_int() generate an "int"-typed integer */ + yyintdecimal = B_TRUE; + yyintsuffix[0] = '\0'; + yyintprefix = 0; + + dt_sugar_visit_all(&dp, clause); + + if (dp.dtsp_num_ifs == 0 && dp.dtsp_num_conditions == 0) { + /* + * There is nothing that modifies the number of clauses. Use + * the existing clause as-is, with its predicate intact. This + * ensures that in the absence of D sugar, the body of the + * clause can create a variable that is referenced in the + * predicate. + */ + dt_sugar_append_clause(&dp, dt_node_clause(clause->dn_pdescs, + clause->dn_pred, clause->dn_acts)); + } else { + if (clause->dn_pred != NULL) { + condid = dt_sugar_new_condition(&dp, + clause->dn_pred, condid); + } + + if (clause->dn_acts == NULL) { + /* + * dt_sugar_visit_stmts() does not emit a clause with + * an empty body (e.g. if there's an empty "if" body), + * but we need the empty body here so that we + * continue to get the default tracing action. + */ + dt_sugar_new_basic_block(&dp, condid, NULL); + } else { + dt_sugar_visit_stmts(&dp, clause->dn_acts, condid); + } + } + + if (dp.dtsp_num_conditions != 0) { + dt_sugar_prepend_clause(&dp, + dt_sugar_new_clearerror_clause(&dp)); + } + + if (dp.dtsp_clause_list != NULL && + dp.dtsp_clause_list->dn_list != NULL && !dtp->dt_has_sugar) { + dtp->dt_has_sugar = B_TRUE; + dt_sugar_prepend_clause(&dp, dt_sugar_makeerrorclause()); + } + return (dp.dtsp_clause_list); +} Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h (revision 304199) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h (revision 304200) @@ -1,613 +1,618 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* - * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2014, 2016 by Delphix. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ #ifndef _DTRACE_H #define _DTRACE_H #include #include #include #include #include #ifndef illumos #include #endif #ifdef __cplusplus extern "C" { #endif /* * DTrace Dynamic Tracing Software: Library Interfaces * * Note: The contents of this file are private to the implementation of the * Solaris system and DTrace subsystem and are subject to change at any time * without notice. Applications and drivers using these interfaces will fail * to run on future releases. These interfaces should not be used for any * purpose except those expressly outlined in dtrace(7D) and libdtrace(3LIB). * Please refer to the "Solaris Dynamic Tracing Guide" for more information. */ #define DTRACE_VERSION 3 /* library ABI interface version */ struct ps_prochandle; +struct dt_node; typedef struct dtrace_hdl dtrace_hdl_t; typedef struct dtrace_prog dtrace_prog_t; typedef struct dtrace_vector dtrace_vector_t; typedef struct dtrace_aggdata dtrace_aggdata_t; #define DTRACE_O_NODEV 0x01 /* do not open dtrace(7D) device */ #define DTRACE_O_NOSYS 0x02 /* do not load /system/object modules */ #define DTRACE_O_LP64 0x04 /* force D compiler to be LP64 */ #define DTRACE_O_ILP32 0x08 /* force D compiler to be ILP32 */ #define DTRACE_O_MASK 0x0f /* mask of valid flags to dtrace_open */ extern dtrace_hdl_t *dtrace_open(int, int, int *); extern dtrace_hdl_t *dtrace_vopen(int, int, int *, const dtrace_vector_t *, void *); extern int dtrace_go(dtrace_hdl_t *); extern int dtrace_stop(dtrace_hdl_t *); extern void dtrace_sleep(dtrace_hdl_t *); extern void dtrace_close(dtrace_hdl_t *); extern int dtrace_errno(dtrace_hdl_t *); extern const char *dtrace_errmsg(dtrace_hdl_t *, int); extern const char *dtrace_faultstr(dtrace_hdl_t *, int); extern const char *dtrace_subrstr(dtrace_hdl_t *, int); extern int dtrace_setopt(dtrace_hdl_t *, const char *, const char *); extern int dtrace_getopt(dtrace_hdl_t *, const char *, dtrace_optval_t *); extern void dtrace_update(dtrace_hdl_t *); extern int dtrace_ctlfd(dtrace_hdl_t *); /* * DTrace Program Interface * * DTrace programs can be created by compiling ASCII text files containing * D programs or by compiling in-memory C strings that specify a D program. * Once created, callers can examine the list of program statements and * enable the probes and actions described by these statements. */ typedef struct dtrace_proginfo { dtrace_attribute_t dpi_descattr; /* minimum probedesc attributes */ dtrace_attribute_t dpi_stmtattr; /* minimum statement attributes */ uint_t dpi_aggregates; /* number of aggregates specified in program */ uint_t dpi_recgens; /* number of record generating probes in prog */ uint_t dpi_matches; /* number of probes matched by program */ uint_t dpi_speculations; /* number of speculations specified in prog */ } dtrace_proginfo_t; #define DTRACE_C_DIFV 0x0001 /* DIF verbose mode: show each compiled DIFO */ #define DTRACE_C_EMPTY 0x0002 /* Permit compilation of empty D source files */ #define DTRACE_C_ZDEFS 0x0004 /* Permit probe defs that match zero probes */ #define DTRACE_C_EATTR 0x0008 /* Error if program attributes less than min */ #define DTRACE_C_CPP 0x0010 /* Preprocess input file with cpp(1) utility */ #define DTRACE_C_KNODEF 0x0020 /* Permit unresolved kernel symbols in DIFO */ #define DTRACE_C_UNODEF 0x0040 /* Permit unresolved user symbols in DIFO */ -#define DTRACE_C_PSPEC 0x0080 /* Intepret ambiguous specifiers as probes */ +#define DTRACE_C_PSPEC 0x0080 /* Interpret ambiguous specifiers as probes */ #define DTRACE_C_ETAGS 0x0100 /* Prefix error messages with error tags */ #define DTRACE_C_ARGREF 0x0200 /* Do not require all macro args to be used */ #define DTRACE_C_DEFARG 0x0800 /* Use 0/"" as value for unspecified args */ #define DTRACE_C_NOLIBS 0x1000 /* Do not process D system libraries */ #define DTRACE_C_CTL 0x2000 /* Only process control directives */ #define DTRACE_C_MASK 0x3bff /* mask of all valid flags to dtrace_*compile */ extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *, const char *, dtrace_probespec_t, uint_t, int, char *const []); extern dtrace_prog_t *dtrace_program_fcompile(dtrace_hdl_t *, FILE *, uint_t, int, char *const []); extern int dtrace_program_exec(dtrace_hdl_t *, dtrace_prog_t *, dtrace_proginfo_t *); extern void dtrace_program_info(dtrace_hdl_t *, dtrace_prog_t *, dtrace_proginfo_t *); #define DTRACE_D_STRIP 0x01 /* strip non-loadable sections from program */ #define DTRACE_D_PROBES 0x02 /* include provider and probe definitions */ #define DTRACE_D_MASK 0x03 /* mask of valid flags to dtrace_dof_create */ extern int dtrace_program_link(dtrace_hdl_t *, dtrace_prog_t *, uint_t, const char *, int, char *const []); extern int dtrace_program_header(dtrace_hdl_t *, FILE *, const char *); extern void *dtrace_dof_create(dtrace_hdl_t *, dtrace_prog_t *, uint_t); extern void dtrace_dof_destroy(dtrace_hdl_t *, void *); extern void *dtrace_getopt_dof(dtrace_hdl_t *); extern void *dtrace_geterr_dof(dtrace_hdl_t *); typedef struct dtrace_stmtdesc { dtrace_ecbdesc_t *dtsd_ecbdesc; /* ECB description */ dtrace_actdesc_t *dtsd_action; /* action list */ dtrace_actdesc_t *dtsd_action_last; /* last action in action list */ void *dtsd_aggdata; /* aggregation data */ void *dtsd_fmtdata; /* type-specific output data */ void *dtsd_strdata; /* type-specific string data */ void (*dtsd_callback)(void); /* callback function for EPID */ void *dtsd_data; /* callback data pointer */ dtrace_attribute_t dtsd_descattr; /* probedesc attributes */ dtrace_attribute_t dtsd_stmtattr; /* statement attributes */ } dtrace_stmtdesc_t; typedef int dtrace_stmt_f(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmtdesc_t *, void *); extern dtrace_stmtdesc_t *dtrace_stmt_create(dtrace_hdl_t *, dtrace_ecbdesc_t *); extern dtrace_actdesc_t *dtrace_stmt_action(dtrace_hdl_t *, dtrace_stmtdesc_t *); extern int dtrace_stmt_add(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmtdesc_t *); extern int dtrace_stmt_iter(dtrace_hdl_t *, dtrace_prog_t *, dtrace_stmt_f *, void *); extern void dtrace_stmt_destroy(dtrace_hdl_t *, dtrace_stmtdesc_t *); /* * DTrace Data Consumption Interface */ typedef enum { DTRACEFLOW_ENTRY, DTRACEFLOW_RETURN, DTRACEFLOW_NONE } dtrace_flowkind_t; #define DTRACE_CONSUME_ERROR -1 /* error while processing */ #define DTRACE_CONSUME_THIS 0 /* consume this probe/record */ #define DTRACE_CONSUME_NEXT 1 /* advance to next probe/rec */ #define DTRACE_CONSUME_ABORT 2 /* abort consumption */ typedef struct dtrace_probedata { dtrace_hdl_t *dtpda_handle; /* handle to DTrace library */ dtrace_eprobedesc_t *dtpda_edesc; /* enabled probe description */ dtrace_probedesc_t *dtpda_pdesc; /* probe description */ processorid_t dtpda_cpu; /* CPU for data */ caddr_t dtpda_data; /* pointer to raw data */ dtrace_flowkind_t dtpda_flow; /* flow kind */ const char *dtpda_prefix; /* recommended flow prefix */ int dtpda_indent; /* recommended flow indent */ } dtrace_probedata_t; typedef int dtrace_consume_probe_f(const dtrace_probedata_t *, void *); typedef int dtrace_consume_rec_f(const dtrace_probedata_t *, const dtrace_recdesc_t *, void *); extern int dtrace_consume(dtrace_hdl_t *, FILE *, dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *); #define DTRACE_STATUS_NONE 0 /* no status; not yet time */ #define DTRACE_STATUS_OKAY 1 /* status okay */ #define DTRACE_STATUS_EXITED 2 /* exit() was called; tracing stopped */ #define DTRACE_STATUS_FILLED 3 /* fill buffer filled; tracing stoped */ #define DTRACE_STATUS_STOPPED 4 /* tracing already stopped */ extern int dtrace_status(dtrace_hdl_t *); /* * DTrace Formatted Output Interfaces * * To format output associated with a given dtrace_stmtdesc, the caller can * invoke one of the following functions, passing the opaque dtsd_fmtdata and a * list of record descriptions. These functions return either -1 to indicate * an error, or a positive integer indicating the number of records consumed. * For anonymous enablings, the consumer can use the dtrd_format member of * the record description to obtain a format description. The dtfd_string * member of the format description may be passed to dtrace_print{fa}_create() * to create the opaque format data. */ extern void *dtrace_printf_create(dtrace_hdl_t *, const char *); extern void *dtrace_printa_create(dtrace_hdl_t *, const char *); extern size_t dtrace_printf_format(dtrace_hdl_t *, void *, char *, size_t); extern int dtrace_fprintf(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_fprinta(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_system(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); extern int dtrace_freopen(dtrace_hdl_t *, FILE *, void *, const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t, const void *, size_t); /* * Type-specific output printing * * The print() action will associate a string data record that is actually the * fully-qualified type name of the data traced by the DIFEXPR action. This is * stored in the same 'format' record from the kernel, but we know by virtue of * the fact that the action is still DIFEXPR that it is actually a reference to * plain string data. */ extern int dtrace_print(dtrace_hdl_t *, FILE *, const char *, caddr_t, size_t); /* * DTrace Work Interface */ typedef enum { DTRACE_WORKSTATUS_ERROR = -1, DTRACE_WORKSTATUS_OKAY, DTRACE_WORKSTATUS_DONE } dtrace_workstatus_t; extern dtrace_workstatus_t dtrace_work(dtrace_hdl_t *, FILE *, dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *); /* * DTrace Handler Interface */ #define DTRACE_HANDLE_ABORT -1 /* abort current operation */ #define DTRACE_HANDLE_OK 0 /* handled okay; continue */ typedef struct dtrace_errdata { dtrace_hdl_t *dteda_handle; /* handle to DTrace library */ dtrace_eprobedesc_t *dteda_edesc; /* enabled probe inducing err */ dtrace_probedesc_t *dteda_pdesc; /* probe inducing error */ processorid_t dteda_cpu; /* CPU of error */ int dteda_action; /* action inducing error */ int dteda_offset; /* offset in DIFO of error */ int dteda_fault; /* specific fault */ uint64_t dteda_addr; /* address of fault, if any */ const char *dteda_msg; /* preconstructed message */ } dtrace_errdata_t; typedef int dtrace_handle_err_f(const dtrace_errdata_t *, void *); extern int dtrace_handle_err(dtrace_hdl_t *, dtrace_handle_err_f *, void *); typedef enum { DTRACEDROP_PRINCIPAL, /* drop to principal buffer */ DTRACEDROP_AGGREGATION, /* drop to aggregation buffer */ DTRACEDROP_DYNAMIC, /* dynamic drop */ DTRACEDROP_DYNRINSE, /* dyn drop due to rinsing */ DTRACEDROP_DYNDIRTY, /* dyn drop due to dirty */ DTRACEDROP_SPEC, /* speculative drop */ DTRACEDROP_SPECBUSY, /* spec drop due to busy */ DTRACEDROP_SPECUNAVAIL, /* spec drop due to unavail */ DTRACEDROP_STKSTROVERFLOW, /* stack string tab overflow */ DTRACEDROP_DBLERROR /* error in ERROR probe */ } dtrace_dropkind_t; typedef struct dtrace_dropdata { dtrace_hdl_t *dtdda_handle; /* handle to DTrace library */ processorid_t dtdda_cpu; /* CPU, if any */ dtrace_dropkind_t dtdda_kind; /* kind of drop */ uint64_t dtdda_drops; /* number of drops */ uint64_t dtdda_total; /* total drops */ const char *dtdda_msg; /* preconstructed message */ } dtrace_dropdata_t; typedef int dtrace_handle_drop_f(const dtrace_dropdata_t *, void *); extern int dtrace_handle_drop(dtrace_hdl_t *, dtrace_handle_drop_f *, void *); typedef void dtrace_handle_proc_f(struct ps_prochandle *, const char *, void *); extern int dtrace_handle_proc(dtrace_hdl_t *, dtrace_handle_proc_f *, void *); #define DTRACE_BUFDATA_AGGKEY 0x0001 /* aggregation key */ #define DTRACE_BUFDATA_AGGVAL 0x0002 /* aggregation value */ #define DTRACE_BUFDATA_AGGFORMAT 0x0004 /* aggregation format data */ #define DTRACE_BUFDATA_AGGLAST 0x0008 /* last for this key/val */ typedef struct dtrace_bufdata { dtrace_hdl_t *dtbda_handle; /* handle to DTrace library */ const char *dtbda_buffered; /* buffered output */ dtrace_probedata_t *dtbda_probe; /* probe data */ const dtrace_recdesc_t *dtbda_recdesc; /* record description */ const dtrace_aggdata_t *dtbda_aggdata; /* aggregation data, if agg. */ uint32_t dtbda_flags; /* flags; see above */ } dtrace_bufdata_t; typedef int dtrace_handle_buffered_f(const dtrace_bufdata_t *, void *); extern int dtrace_handle_buffered(dtrace_hdl_t *, dtrace_handle_buffered_f *, void *); typedef struct dtrace_setoptdata { dtrace_hdl_t *dtsda_handle; /* handle to DTrace library */ const dtrace_probedata_t *dtsda_probe; /* probe data */ const char *dtsda_option; /* option that was set */ dtrace_optval_t dtsda_oldval; /* old value */ dtrace_optval_t dtsda_newval; /* new value */ } dtrace_setoptdata_t; typedef int dtrace_handle_setopt_f(const dtrace_setoptdata_t *, void *); extern int dtrace_handle_setopt(dtrace_hdl_t *, dtrace_handle_setopt_f *, void *); /* * DTrace Aggregate Interface */ #define DTRACE_A_PERCPU 0x0001 #define DTRACE_A_KEEPDELTA 0x0002 #define DTRACE_A_ANONYMOUS 0x0004 #define DTRACE_A_TOTAL 0x0008 #define DTRACE_A_MINMAXBIN 0x0010 #define DTRACE_A_HASNEGATIVES 0x0020 #define DTRACE_A_HASPOSITIVES 0x0040 #define DTRACE_AGGZOOM_MAX 0.95 /* height of max bar */ #define DTRACE_AGGWALK_ERROR -1 /* error while processing */ #define DTRACE_AGGWALK_NEXT 0 /* proceed to next element */ #define DTRACE_AGGWALK_ABORT 1 /* abort aggregation walk */ #define DTRACE_AGGWALK_CLEAR 2 /* clear this element */ #define DTRACE_AGGWALK_NORMALIZE 3 /* normalize this element */ #define DTRACE_AGGWALK_DENORMALIZE 4 /* denormalize this element */ #define DTRACE_AGGWALK_REMOVE 5 /* remove this element */ struct dtrace_aggdata { dtrace_hdl_t *dtada_handle; /* handle to DTrace library */ dtrace_aggdesc_t *dtada_desc; /* aggregation description */ dtrace_eprobedesc_t *dtada_edesc; /* enabled probe description */ dtrace_probedesc_t *dtada_pdesc; /* probe description */ caddr_t dtada_data; /* pointer to raw data */ uint64_t dtada_normal; /* the normal -- 1 for denorm */ size_t dtada_size; /* total size of the data */ caddr_t dtada_delta; /* delta data, if available */ caddr_t *dtada_percpu; /* per CPU data, if avail */ caddr_t *dtada_percpu_delta; /* per CPU delta, if avail */ int64_t dtada_total; /* per agg total, if avail */ uint16_t dtada_minbin; /* minimum bin, if avail */ uint16_t dtada_maxbin; /* maximum bin, if avail */ uint32_t dtada_flags; /* flags */ }; typedef int dtrace_aggregate_f(const dtrace_aggdata_t *, void *); typedef int dtrace_aggregate_walk_f(dtrace_hdl_t *, dtrace_aggregate_f *, void *); typedef int dtrace_aggregate_walk_joined_f(const dtrace_aggdata_t **, const int, void *); extern void dtrace_aggregate_clear(dtrace_hdl_t *); extern int dtrace_aggregate_snap(dtrace_hdl_t *); extern int dtrace_aggregate_print(dtrace_hdl_t *, FILE *, dtrace_aggregate_walk_f *); extern int dtrace_aggregate_walk(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_joined(dtrace_hdl_t *, dtrace_aggvarid_t *, int, dtrace_aggregate_walk_joined_f *, void *); extern int dtrace_aggregate_walk_sorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keysorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyvarsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valvarsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_keyvarrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); extern int dtrace_aggregate_walk_valvarrevsorted(dtrace_hdl_t *, dtrace_aggregate_f *, void *); #define DTRACE_AGD_PRINTED 0x1 /* aggregation printed in program */ /* * DTrace Process Control Interface * * Library clients who wish to have libdtrace create or grab processes for * monitoring of their symbol table changes may use these interfaces to * request that libdtrace obtain control of the process using libproc. */ extern struct ps_prochandle *dtrace_proc_create(dtrace_hdl_t *, const char *, char *const *, proc_child_func *, void *); extern struct ps_prochandle *dtrace_proc_grab(dtrace_hdl_t *, pid_t, int); extern void dtrace_proc_release(dtrace_hdl_t *, struct ps_prochandle *); extern void dtrace_proc_continue(dtrace_hdl_t *, struct ps_prochandle *); /* * DTrace Object, Symbol, and Type Interfaces * * Library clients can use libdtrace to perform symbol and C type information * lookups by symbol name, symbol address, or C type name, or to lookup meta- * information cached for each of the program objects in use by DTrace. The * resulting struct contain pointers to arbitrary-length strings, including * object, symbol, and type names, that are persistent until the next call to * dtrace_update(). Once dtrace_update() is called, any cached values must * be flushed and not used subsequently by the client program. */ #define DTRACE_OBJ_EXEC ((const char *)0L) /* primary executable file */ #define DTRACE_OBJ_RTLD ((const char *)1L) /* run-time link-editor */ #define DTRACE_OBJ_CDEFS ((const char *)2L) /* C include definitions */ #define DTRACE_OBJ_DDEFS ((const char *)3L) /* D program definitions */ #define DTRACE_OBJ_EVERY ((const char *)-1L) /* all known objects */ #define DTRACE_OBJ_KMODS ((const char *)-2L) /* all kernel objects */ #define DTRACE_OBJ_UMODS ((const char *)-3L) /* all user objects */ typedef struct dtrace_objinfo { const char *dto_name; /* object file scope name */ const char *dto_file; /* object file path (if any) */ int dto_id; /* object file id (if any) */ uint_t dto_flags; /* object flags (see below) */ GElf_Addr dto_text_va; /* address of text section */ GElf_Xword dto_text_size; /* size of text section */ GElf_Addr dto_data_va; /* address of data section */ GElf_Xword dto_data_size; /* size of data section */ GElf_Addr dto_bss_va; /* address of BSS */ GElf_Xword dto_bss_size; /* size of BSS */ } dtrace_objinfo_t; #define DTRACE_OBJ_F_KERNEL 0x1 /* object is a kernel module */ #define DTRACE_OBJ_F_PRIMARY 0x2 /* object is a primary module */ typedef int dtrace_obj_f(dtrace_hdl_t *, const dtrace_objinfo_t *, void *); extern int dtrace_object_iter(dtrace_hdl_t *, dtrace_obj_f *, void *); extern int dtrace_object_info(dtrace_hdl_t *, const char *, dtrace_objinfo_t *); typedef struct dtrace_syminfo { const char *dts_object; /* object name */ const char *dts_name; /* symbol name */ ulong_t dts_id; /* symbol id */ } dtrace_syminfo_t; extern int dtrace_lookup_by_name(dtrace_hdl_t *, const char *, const char *, GElf_Sym *, dtrace_syminfo_t *); extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr, GElf_Sym *, dtrace_syminfo_t *); typedef struct dtrace_typeinfo { const char *dtt_object; /* object containing type */ ctf_file_t *dtt_ctfp; /* CTF container handle */ ctf_id_t dtt_type; /* CTF type identifier */ uint_t dtt_flags; /* Misc. flags */ } dtrace_typeinfo_t; #define DTT_FL_USER 0x1 /* user type */ extern int dtrace_lookup_by_type(dtrace_hdl_t *, const char *, const char *, dtrace_typeinfo_t *); extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *, const dtrace_syminfo_t *, dtrace_typeinfo_t *); extern int dtrace_type_strcompile(dtrace_hdl_t *, const char *, dtrace_typeinfo_t *); extern int dtrace_type_fcompile(dtrace_hdl_t *, FILE *, dtrace_typeinfo_t *); + +extern struct dt_node *dt_compile_sugar(dtrace_hdl_t *, + struct dt_node *); + /* * DTrace Probe Interface * * Library clients can use these functions to iterate over the set of available * probe definitions and inquire as to their attributes. The probe iteration * interfaces report probes that are declared as well as those from dtrace(7D). */ typedef struct dtrace_probeinfo { dtrace_attribute_t dtp_attr; /* name attributes */ dtrace_attribute_t dtp_arga; /* arg attributes */ const dtrace_typeinfo_t *dtp_argv; /* arg types */ int dtp_argc; /* arg count */ } dtrace_probeinfo_t; typedef int dtrace_probe_f(dtrace_hdl_t *, const dtrace_probedesc_t *, void *); extern int dtrace_probe_iter(dtrace_hdl_t *, const dtrace_probedesc_t *pdp, dtrace_probe_f *, void *); extern int dtrace_probe_info(dtrace_hdl_t *, const dtrace_probedesc_t *, dtrace_probeinfo_t *); /* * DTrace Vector Interface * * The DTrace library normally speaks directly to dtrace(7D). However, * this communication may be vectored elsewhere. Consumers who wish to * perform a vectored open must fill in the vector, and use the dtrace_vopen() * entry point to obtain a library handle. */ struct dtrace_vector { #ifdef illumos int (*dtv_ioctl)(void *, int, void *); #else int (*dtv_ioctl)(void *, u_long, void *); #endif int (*dtv_lookup_by_addr)(void *, GElf_Addr, GElf_Sym *, dtrace_syminfo_t *); int (*dtv_status)(void *, processorid_t); long (*dtv_sysconf)(void *, int); }; /* * DTrace Utility Functions * * Library clients can use these functions to convert addresses strings, to * convert between string and integer probe descriptions and the * dtrace_probedesc_t representation, and to perform similar conversions on * stability attributes. */ extern int dtrace_addr2str(dtrace_hdl_t *, uint64_t, char *, int); extern int dtrace_uaddr2str(dtrace_hdl_t *, pid_t, uint64_t, char *, int); extern int dtrace_xstr2desc(dtrace_hdl_t *, dtrace_probespec_t, const char *, int, char *const [], dtrace_probedesc_t *); extern int dtrace_str2desc(dtrace_hdl_t *, dtrace_probespec_t, const char *, dtrace_probedesc_t *); extern int dtrace_id2desc(dtrace_hdl_t *, dtrace_id_t, dtrace_probedesc_t *); #define DTRACE_DESC2STR_MAX 1024 /* min buf size for dtrace_desc2str() */ extern char *dtrace_desc2str(const dtrace_probedesc_t *, char *, size_t); #define DTRACE_ATTR2STR_MAX 64 /* min buf size for dtrace_attr2str() */ extern char *dtrace_attr2str(dtrace_attribute_t, char *, size_t); extern int dtrace_str2attr(const char *, dtrace_attribute_t *); extern const char *dtrace_stability_name(dtrace_stability_t); extern const char *dtrace_class_name(dtrace_class_t); extern int dtrace_provider_modules(dtrace_hdl_t *, const char **, int); extern const char *const _dtrace_version; extern int _dtrace_debug; #ifdef __cplusplus } #endif #ifndef illumos #define _SC_CPUID_MAX _SC_NPROCESSORS_CONF #define _SC_NPROCESSORS_MAX _SC_NPROCESSORS_CONF #endif #endif /* _DTRACE_H */ Index: head/cddl/contrib/opensolaris =================================================================== --- head/cddl/contrib/opensolaris (revision 304199) +++ head/cddl/contrib/opensolaris (revision 304200) Property changes on: head/cddl/contrib/opensolaris ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /vendor/illumos/dist:r304057 Index: head/cddl/lib/libdtrace/Makefile =================================================================== --- head/cddl/lib/libdtrace/Makefile (revision 304199) +++ head/cddl/lib/libdtrace/Makefile (revision 304200) @@ -1,131 +1,132 @@ # $FreeBSD$ .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/common .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libgen/common LIB= dtrace SRCS= dt_aggregate.c \ dt_as.c \ dt_buf.c \ dt_cc.c \ dt_cg.c \ dt_consume.c \ dt_decl.c \ dt_dis.c \ dt_dof.c \ dt_error.c \ dt_errtags.c \ dt_grammar.y \ dt_handle.c \ dt_ident.c \ dt_isadep.c \ dt_inttab.c \ dt_lex.l \ dt_link.c \ dt_list.c \ dt_map.c \ dt_module.c \ dt_names.c \ dt_open.c \ dt_options.c \ dt_parser.c \ dt_pcb.c \ dt_pid.c \ dt_pq.c \ dt_pragma.c \ dt_print.c \ dt_printf.c \ dt_proc.c \ dt_program.c \ dt_provider.c \ dt_regset.c \ dt_string.c \ dt_strtab.c \ dt_subr.c \ + dt_sugar.c \ dt_work.c \ dt_xlator.c \ gmatch.c DSRCS= errno.d \ io.d \ ip.d \ psinfo.d \ siftr.d \ signal.d \ tcp.d \ udp.d \ unistd.d FILES= ${DSRCS} FILESDIR= /usr/lib/dtrace FILESMODE= ${NOBINMODE} WARNS?= 1 CFLAGS+= -I${.OBJDIR} -I${.CURDIR} \ -I${.CURDIR}/../../../sys/cddl/dev/dtrace/${MACHINE_ARCH} \ -I${.CURDIR}/../../../sys/cddl/compat/opensolaris \ -I${.CURDIR}/../../../cddl/compat/opensolaris/include \ -I${OPENSOLARIS_USR_DISTDIR}/head \ -I${OPENSOLARIS_USR_DISTDIR}/lib/libctf/common \ -I${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common \ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common #CFLAGS+= -DYYDEBUG .if ${MACHINE_CPUARCH} == "aarch64" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/aarch64 .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/aarch64 .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/aarch64 .elif ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" CFLAGS+= -I${.CURDIR}/../../../sys/cddl/dev/dtrace/x86 CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel -DDIS_MEM .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/i386 .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/${MACHINE_ARCH} .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/x86 .elif ${MACHINE_CPUARCH} == "arm" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/arm .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/arm .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/arm .elif ${MACHINE_CPUARCH} == "mips" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/mips .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/mips .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/mips .elif ${MACHINE_CPUARCH} == "powerpc" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/powerpc .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/powerpc .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/powerpc .elif ${MACHINE_CPUARCH} == "riscv" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/riscv .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/riscv .PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/riscv .elif ${MACHINE_CPUARCH} == "sparc64" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/sparc .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/sparc .else # temporary hack CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel .endif .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" SRCS+= dis_tables.c DSRCS+= regs_x86.d .endif LFLAGS+=-l YFLAGS+=-d LIBADD= ctf elf proc pthread rtld_db CLEANFILES= dt_errtags.c dt_names.c dt_errtags.c: sh ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/mkerrtags.sh < ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/dt_errtags.h > dt_errtags.c dt_names.c: sh ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/mknames.sh < ${OPENSOLARIS_SYS_DISTDIR}/uts/common/sys/dtrace.h > dt_names.c beforedepend: dt_errtags.c dt_names.c .include