Rui Paulo e0ea83ebb1 Update DTrace userland code to the latest available.
Summary of changes:

- libdtrace

changeset:   12902:3bb859a7330c
user:        Bryan Cantrill <Bryan.Cantrill@Sun.COM>
date:        Fri Jul 23 17:34:02 2010 -0700
summary:     6679140 asymmetric alloc/dealloc activity can induce dynamic variable drops

changeset:   12692:4341b447c069
user:        Ali Bahrami <Ali.Bahrami@Oracle.COM>
date:        Thu Jun 24 18:16:42 2010 -0600
summary:     6916796 OSnet mapfiles should use version 2 link-editor syntax

changeset:   12507:501806a754d2
user:        Alan Maguire <Alan.Maguire@Sun.COM>
date:        Thu May 27 17:29:51 2010 -0400
summary:     PSARC 2010/106 DTrace TCP and UDP providers

changeset:   11798:1e7f1f154004
user:        Roger A. Faulkner <Roger.Faulkner@Sun.COM>
date:        Sun Feb 28 18:42:20 2010 -0800
summary:     PSARC 2009/657 delete obsolete system call traps

changeset:   11466:d60272412fb0
user:        Roger A. Faulkner <Roger.Faulkner@Sun.COM>
date:        Mon Jan 11 17:42:13 2010 -0800
summary:     6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads

changeset:   11237:0d23e47ed228
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Thu Dec 03 13:39:19 2009 +0000
summary:     6795386 macro arguments and globbing in DTrace probe descriptions don't mix

changeset:   10791:944abfb5b345
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Wed Oct 14 11:25:23 2009 +0100
summary:     6886953 large symbols lead to stack exhaustion

changeset:   10326:8e3fbeec2d76
user:        Siddheshwar Mahesh <Siddheshwar.Mahesh@Sun.COM>
date:        Mon Aug 17 13:26:49 2009 -0500
summary:     6868411 NFS provider generates error on ci_remote on RDMA operations

changeset:   10207:87c40ea3fc4b
user:        jmcp <James.McPherson@Sun.COM>
date:        Wed Jul 29 16:56:03 2009 -0700
summary:     6864230 hiho, hiho, it'ch chtime for CH to go

changeset:   10044:2643c1cd9e2a
user:        Priya Krishnan <Priya.Krishnan@Sun.COM>
date:        Mon Jul 06 21:19:41 2009 -0400
summary:     6855027 iscsit.d breaks dtrace in osol based on snv_117

changeset:   9900:1b86d65a4f9e
user:        Ali Bahrami <Ali.Bahrami@Sun.COM>
date:        Thu Jun 18 13:16:39 2009 -0600
summary:     6851224 elf_getshnum() and elf_getshstrndx() incompatible with 2002 ELF gABI agreement

changeset:   9885:a3d5e9d9e779
user:        Robert Mastors <Robert.Mastors@Sun.COM>
date:        Tue Jun 16 15:25:25 2009 -0500
summary:     6711844 assert: vp->v_shrlocks == 0L, file: ../../common/fs/vnode.c, line: 2333

changeset:   9881:741c9e4e094c
user:        Charles Ting <Charles.Ting@Sun.COM>
date:        Tue Jun 16 14:51:40 2009 -0400
summary:     6849606 SRP DTrace Probe for xfer-done misses completion of READ transfers

changeset:   9829:e8059fcaee97
user:        Charles Ting <Charles.Ting@Sun.COM>
date:        Tue Jun 09 10:11:35 2009 -0400
summary:     6804431 Add Dtrace probes to SRPT

changeset:   9812:a2990074321f
user:        Priya Krishnan <Priya.Krishnan@Sun.COM>
date:        Mon Jun 08 09:49:48 2009 -0400
summary:     6847237 The iscsit.d DTrace translator should include iscsi.d for the definition of iscsiinfo_t

changeset:   9721:4f7e194c7c37
user:        Priya Krishnan <Priya.Krishnan@Sun.COM>
date:        Tue May 26 10:40:43 2009 -0400
summary:     6809997 COMSTAR iscsi target DTrace Provider needed

changeset:   9625:8aa5731291b4
user:        Sam Cramer <Sam.Cramer@Sun.COM>
date:        Wed May 13 17:10:06 2009 -0700
summary:     6840354 "/usr/lib/dtrace/fc.d", line 59: syntax error near "fct_local_port_t"

changeset:   9609:8874cc8d5e3f
user:        Sam Cramer <Sam.Cramer@Sun.COM>
date:        Mon May 11 21:02:27 2009 -0700
summary:     6809580 fct DTrace providers needed for qlt

changeset:   9578:c4b38ec17f4e
user:        Sam Cramer <Sam.Cramer@Sun.COM>
date:        Fri May 08 12:12:40 2009 -0700
summary:     6809580 fct DTrace providers needed for qlt

changeset:   9531:dc8924ef7839
user:        Rafael Vanoni <rafael.vanoni@sun.com>
date:        Mon May 04 11:48:15 2009 -0700
summary:     6730130 dtrace missing printf handler for stdev

changeset:   9389:750ed3471e90
user:        Vamsi Nagineni <Vamsi.Krishna@Sun.COM>
date:        Fri Apr 17 06:26:47 2009 -0700
summary:     6812050 dtrace should translate curpsinfo->pr_contract

changeset:   9085:ff7eb0bace56
user:        Ali Bahrami <Ali.Bahrami@Sun.COM>
date:        Wed Mar 18 13:28:28 2009 -0600
summary:     6813909 generalize eh_frame support to non-amd64 platforms

changeset:   8803:8c01b39012c9
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Fri Feb 13 07:13:13 2009 +0000
summary:     PSARC 2008/480 DTrace CPC Provider

changeset:   8744:03d5725cda56
user:        Ali Bahrami <Ali.Bahrami@Sun.COM>
date:        Tue Feb 10 09:38:02 2009 -0700
summary:     6798660 Cadmium .NOT file processing problem with CWD relative file paths

changeset:   8337:079ecc003ca6
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Thu Dec 11 11:26:47 2008 +0000
summary:     6750659 drti.o crashes app due to corrupt environment

changeset:   7991:d3b751ef3d85
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Mon Nov 03 10:26:23 2008 +0000
summary:     6738982 Representative thread after DTrace stop() action is incorrect

changeset:   7208:568549b138d8
user:        vv149972
date:        Mon Jul 28 23:14:31 2008 -0700
summary:     6696397 NFS v3 provider reports all UDP clients as 0.0.0.0

changeset:   6878:360e73ea6b0c
user:        brendan
date:        Fri Jun 13 19:06:55 2008 -0700
summary:     PSARC 2008/302 DTrace IP Provider

changeset:   6554:b5817e112852
user:        ahl
date:        Mon May 05 14:38:24 2008 -0700
summary:     6677812 race between dtrace activities in non-local zones

----

- ctf tools:

changeset:   12177:800b7f847f1e
user:        Surya Prakki <Surya.Prakki@Sun.COM>
date:        Sun Apr 18 23:59:57 2010 -0700
summary:     6941452 ctfconvert fails on VLAs with code generated by SS12u1

changeset:   11432:c1c450bf62f2
user:        John Levon <john.levon@sun.com>
date:        Tue Jan 05 06:57:53 2010 -0800
summary:     6905711 anonymous and empty SOUs crash ctfconvert

changeset:   11227:cd2ac59c39f2
user:        Ali Bahrami <Ali.Bahrami@Sun.COM>
date:        Wed Dec 02 15:37:55 2009 -0700
summary:     6900241 ld should track SHT_GROUP sections by symbol name, not section name

changeset:   10380:5394a7172e1f
user:        Ali Bahrami <Ali.Bahrami@Sun.COM>
date:        Tue Aug 25 13:51:43 2009 -0600
summary:     6866605 SUNWonbld ELF analysis tools need overhaul (fix ctfmerge/libc dependency)

changeset:   10207:87c40ea3fc4b
user:        jmcp <James.McPherson@Sun.COM>
date:        Wed Jul 29 16:56:03 2009 -0700
summary:     6864230 hiho, hiho, it'ch chtime for CH to go

changeset:   10206:51f52702df72
user:        John Levon <john.levon@sun.com>
date:        Wed Jul 29 14:36:30 2009 -0700
summary:     6854065 CTF tools should error out given 1024+-member structures

changeset:   7230:429b4f7acf1a
user:        sn199410
date:        Wed Jul 30 16:10:30 2008 -0700
summary:     6575435 ctf tools cannot handle C99 VLAs ("variable length arrays")

changeset:   6936:72189fcd99e4
user:        sommerfe
date:        Sun Jun 22 09:13:44 2008 -0700
summary:     6716983 left-for-dead ctfmerge worker threads awake to take out maker

----

- dtrace command utility:

changeset:   12507:501806a754d2
user:        Alan Maguire <Alan.Maguire@Sun.COM>
date:        Thu May 27 17:29:51 2010 -0400
summary:     PSARC 2010/106 DTrace TCP and UDP providers

changeset:   11838:32bb5d254240
user:        Liane Praza <Liane.Praza@Sun.COM>
date:        Tue Mar 02 19:29:26 2010 -0700
summary:     PSARC 2010/067 Interim modernization updates

changeset:   11270:47a962fe7b45
user:        Frank Van Der Linden <Frank.Vanderlinden@Sun.COM>
date:        Mon Dec 07 13:47:36 2009 -0800
summary:     6907170 fix for 6875656 left out updates to DTrace test suite

changeset:   11237:0d23e47ed228
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Thu Dec 03 13:39:19 2009 +0000
summary:     6795386 macro arguments and globbing in DTrace probe descriptions don't mix

changeset:   11153:dec430d20576
user:        Frank Van Der Linden <Frank.Vanderlinden@Sun.COM>
date:        Sun Nov 22 19:22:26 2009 -0800
summary:     6875656 xdt needs to support more XenTrace probes

changeset:   11102:b91faef0c984
user:        Gavin Maltby <Gavin.Maltby@Sun.COM>
date:        Thu Nov 19 15:28:11 2009 +1100
summary:     PSARC/2009/554 door_xcreate - extended door creation interface for private doors

changeset:   11066:cebb50cbe4f9
user:        Rafael Vanoni <rafael.vanoni@sun.com>
date:        Fri Nov 13 01:32:32 2009 -0800
summary:     PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling

changeset:   10791:944abfb5b345
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Wed Oct 14 11:25:23 2009 +0100
summary:     6886953 large symbols lead to stack exhaustion

changeset:   10207:87c40ea3fc4b
user:        jmcp <James.McPherson@Sun.COM>
date:        Wed Jul 29 16:56:03 2009 -0700
summary:     6864230 hiho, hiho, it'ch chtime for CH to go

changeset:   9531:dc8924ef7839
user:        Rafael Vanoni <rafael.vanoni@sun.com>
date:        Mon May 04 11:48:15 2009 -0700
summary:     6730130 dtrace missing printf handler for stdev

changeset:   9397:e667d620a75c
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Mon Apr 20 07:58:44 2009 +0100
summary:     6806023 cpc provider event name validation needs to be a bit tighter

changeset:   8803:8c01b39012c9
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Fri Feb 13 07:13:13 2009 +0000
summary:     PSARC 2008/480 DTrace CPC Provider

changeset:   8605:0189cb9c5358
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Thu Jan 22 12:09:13 2009 +0000
summary:     6749441 intrstat(1M) shows zeroed values after suspend/resume

changeset:   8337:079ecc003ca6
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Thu Dec 11 11:26:47 2008 +0000
summary:     6750659 drti.o crashes app due to corrupt environment

changeset:   8287:771477e4b843
user:        John Sonnenschein <John.Sonnenschein@Sun.COM>
date:        Fri Dec 05 19:08:38 2008 -0800
summary:     PSARC 2005/462 Removal of Perl 5.6.1 from Solaris 11

changeset:   7991:d3b751ef3d85
user:        Jonathan Haslam <Jonathan.Haslam@Sun.COM>
date:        Mon Nov 03 10:26:23 2008 +0000
summary:     6738982 Representative thread after DTrace stop() action is incorrect

changeset:   7502:da077e5d991e
user:        Aruna Ramakrishna <aruna@cs.umn.edu>
date:        Sat Sep 06 05:36:02 2008 -0400
summary:     6706947 tcp_trace should be replaced with dtrace probes.

changeset:   7484:a48e950bad22
user:        Tom Erickson <tomee@eng.sun.com>
date:        Wed Sep 03 15:14:25 2008 -0700
summary:     6737926 getAggregate() method fails to specify anonymous aggregation explicitly

changeset:   7299:d9a056040774
user:        John Beck <John.Beck@Sun.COM>
date:        Thu Aug 07 12:44:26 2008 -0700
summary:     6734627 protocmp complains about opt/SUNWdtrt/README after TW -> Hg switch

changeset:   6998:58787ea78303
user:        brendan
date:        Tue Jul 01 18:28:22 2008 -0700
summary:     6721426 tst.sdtargs.d passes despite dtrace "invalid address" error

changeset:   6878:360e73ea6b0c
user:        brendan
date:        Fri Jun 13 19:06:55 2008 -0700
summary:     PSARC 2008/302 DTrace IP Provider

changeset:   6670:1961a43f2335
user:        tariq
date:        Tue May 20 15:08:16 2008 -0700
summary:     6685348 Hypervisor event provider for DTrace

changeset:   6554:b5817e112852
user:        ahl
date:        Mon May 05 14:38:24 2008 -0700
summary:     6677812 race between dtrace activities in non-local zones

changeset:   6543:465433824d87
user:        rie
date:        Fri May 02 15:01:06 2008 -0700
summary:     6683064 check_rtime could do with some spring cleaning
2010-08-02 12:13:33 +00:00

836 lines
22 KiB
Plaintext

%{
/*
* 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.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <dt_impl.h>
#include <dt_grammar.h>
#include <dt_parser.h>
#include <dt_string.h>
/*
* We need to undefine lex's input and unput macros so that references to these
* call the functions provided at the end of this source file.
*/
#undef input
#undef unput
static int id_or_type(const char *);
static int input(void);
static void unput(int);
/*
* We first define a set of labeled states for use in the D lexer and then a
* set of regular expressions to simplify things below. The lexer states are:
*
* S0 - D program clause and expression lexing
* S1 - D comments (i.e. skip everything until end of comment)
* S2 - D program outer scope (probe specifiers and declarations)
* S3 - D control line parsing (i.e. after ^# is seen but before \n)
* S4 - D control line scan (locate control directives only and invoke S3)
*/
%}
%e 1500 /* maximum nodes */
%p 3700 /* maximum positions */
%n 600 /* maximum states */
%s S0 S1 S2 S3 S4
RGX_AGG "@"[a-zA-Z_][0-9a-zA-Z_]*
RGX_PSPEC [-$:a-zA-Z_.?*\\\[\]!][-$:0-9a-zA-Z_.`?*\\\[\]!]*
RGX_IDENT [a-zA-Z_`][0-9a-zA-Z_`]*
RGX_INT ([0-9]+|0[xX][0-9A-Fa-f]+)[uU]?[lL]?[lL]?
RGX_FP ([0-9]+("."?)[0-9]*|"."[0-9]+)((e|E)("+"|-)?[0-9]+)?[fFlL]?
RGX_WS [\f\n\r\t\v ]
RGX_STR ([^"\\\n]|\\[^"\n]|\\\")*
RGX_CHR ([^'\\\n]|\\[^'\n]|\\')*
RGX_INTERP ^[\f\t\v ]*#!.*
RGX_CTL ^[\f\t\v ]*#
%%
%{
/*
* We insert a special prologue into yylex() itself: if the pcb contains a
* context token, we return that prior to running the normal lexer. This
* allows libdtrace to force yacc into one of our three parsing contexts: D
* expression (DT_CTX_DEXPR), D program (DT_CTX_DPROG) or D type (DT_CTX_DTYPE).
* Once the token is returned, we clear it so this only happens once.
*/
if (yypcb->pcb_token != 0) {
int tok = yypcb->pcb_token;
yypcb->pcb_token = 0;
return (tok);
}
%}
<S0>auto return (DT_KEY_AUTO);
<S0>break return (DT_KEY_BREAK);
<S0>case return (DT_KEY_CASE);
<S0>char return (DT_KEY_CHAR);
<S0>const return (DT_KEY_CONST);
<S0>continue return (DT_KEY_CONTINUE);
<S0>counter return (DT_KEY_COUNTER);
<S0>default return (DT_KEY_DEFAULT);
<S0>do return (DT_KEY_DO);
<S0>double return (DT_KEY_DOUBLE);
<S0>else return (DT_KEY_ELSE);
<S0>enum return (DT_KEY_ENUM);
<S0>extern return (DT_KEY_EXTERN);
<S0>float return (DT_KEY_FLOAT);
<S0>for return (DT_KEY_FOR);
<S0>goto return (DT_KEY_GOTO);
<S0>if return (DT_KEY_IF);
<S0>import return (DT_KEY_IMPORT);
<S0>inline return (DT_KEY_INLINE);
<S0>int return (DT_KEY_INT);
<S0>long return (DT_KEY_LONG);
<S0>offsetof return (DT_TOK_OFFSETOF);
<S0>probe return (DT_KEY_PROBE);
<S0>provider return (DT_KEY_PROVIDER);
<S0>register return (DT_KEY_REGISTER);
<S0>restrict return (DT_KEY_RESTRICT);
<S0>return return (DT_KEY_RETURN);
<S0>self return (DT_KEY_SELF);
<S0>short return (DT_KEY_SHORT);
<S0>signed return (DT_KEY_SIGNED);
<S0>sizeof return (DT_TOK_SIZEOF);
<S0>static return (DT_KEY_STATIC);
<S0>string return (DT_KEY_STRING);
<S0>stringof return (DT_TOK_STRINGOF);
<S0>struct return (DT_KEY_STRUCT);
<S0>switch return (DT_KEY_SWITCH);
<S0>this return (DT_KEY_THIS);
<S0>translator return (DT_KEY_XLATOR);
<S0>typedef return (DT_KEY_TYPEDEF);
<S0>union return (DT_KEY_UNION);
<S0>unsigned return (DT_KEY_UNSIGNED);
<S0>void return (DT_KEY_VOID);
<S0>volatile return (DT_KEY_VOLATILE);
<S0>while return (DT_KEY_WHILE);
<S0>xlate return (DT_TOK_XLATE);
<S2>auto { yybegin(YYS_EXPR); return (DT_KEY_AUTO); }
<S2>char { yybegin(YYS_EXPR); return (DT_KEY_CHAR); }
<S2>const { yybegin(YYS_EXPR); return (DT_KEY_CONST); }
<S2>counter { yybegin(YYS_DEFINE); return (DT_KEY_COUNTER); }
<S2>double { yybegin(YYS_EXPR); return (DT_KEY_DOUBLE); }
<S2>enum { yybegin(YYS_EXPR); return (DT_KEY_ENUM); }
<S2>extern { yybegin(YYS_EXPR); return (DT_KEY_EXTERN); }
<S2>float { yybegin(YYS_EXPR); return (DT_KEY_FLOAT); }
<S2>import { yybegin(YYS_EXPR); return (DT_KEY_IMPORT); }
<S2>inline { yybegin(YYS_DEFINE); return (DT_KEY_INLINE); }
<S2>int { yybegin(YYS_EXPR); return (DT_KEY_INT); }
<S2>long { yybegin(YYS_EXPR); return (DT_KEY_LONG); }
<S2>provider { yybegin(YYS_DEFINE); return (DT_KEY_PROVIDER); }
<S2>register { yybegin(YYS_EXPR); return (DT_KEY_REGISTER); }
<S2>restrict { yybegin(YYS_EXPR); return (DT_KEY_RESTRICT); }
<S2>self { yybegin(YYS_EXPR); return (DT_KEY_SELF); }
<S2>short { yybegin(YYS_EXPR); return (DT_KEY_SHORT); }
<S2>signed { yybegin(YYS_EXPR); return (DT_KEY_SIGNED); }
<S2>static { yybegin(YYS_EXPR); return (DT_KEY_STATIC); }
<S2>string { yybegin(YYS_EXPR); return (DT_KEY_STRING); }
<S2>struct { yybegin(YYS_EXPR); return (DT_KEY_STRUCT); }
<S2>this { yybegin(YYS_EXPR); return (DT_KEY_THIS); }
<S2>translator { yybegin(YYS_DEFINE); return (DT_KEY_XLATOR); }
<S2>typedef { yybegin(YYS_EXPR); return (DT_KEY_TYPEDEF); }
<S2>union { yybegin(YYS_EXPR); return (DT_KEY_UNION); }
<S2>unsigned { yybegin(YYS_EXPR); return (DT_KEY_UNSIGNED); }
<S2>void { yybegin(YYS_EXPR); return (DT_KEY_VOID); }
<S2>volatile { yybegin(YYS_EXPR); return (DT_KEY_VOLATILE); }
<S0>"$$"[0-9]+ {
int i = atoi(yytext + 2);
char *v = "";
/*
* A macro argument reference substitutes the text of
* an argument in place of the current token. When we
* see $$<d> we fetch the saved string from pcb_sargv
* (or use the default argument if the option has been
* set and the argument hasn't been specified) and
* return a token corresponding to this string.
*/
if (i < 0 || (i >= yypcb->pcb_sargc &&
!(yypcb->pcb_cflags & DTRACE_C_DEFARG))) {
xyerror(D_MACRO_UNDEF, "macro argument %s is "
"not defined\n", yytext);
}
if (i < yypcb->pcb_sargc) {
v = yypcb->pcb_sargv[i]; /* get val from pcb */
yypcb->pcb_sflagv[i] |= DT_IDFLG_REF;
}
if ((yylval.l_str = strdup(v)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
(void) stresc2chr(yylval.l_str);
return (DT_TOK_STRING);
}
<S0>"$"[0-9]+ {
int i = atoi(yytext + 1);
char *p, *v = "0";
/*
* A macro argument reference substitutes the text of
* one identifier or integer pattern for another. When
* we see $<d> we fetch the saved string from pcb_sargv
* (or use the default argument if the option has been
* set and the argument hasn't been specified) and
* return a token corresponding to this string.
*/
if (i < 0 || (i >= yypcb->pcb_sargc &&
!(yypcb->pcb_cflags & DTRACE_C_DEFARG))) {
xyerror(D_MACRO_UNDEF, "macro argument %s is "
"not defined\n", yytext);
}
if (i < yypcb->pcb_sargc) {
v = yypcb->pcb_sargv[i]; /* get val from pcb */
yypcb->pcb_sflagv[i] |= DT_IDFLG_REF;
}
/*
* If the macro text is not a valid integer or ident,
* then we treat it as a string. The string may be
* optionally enclosed in quotes, which we strip.
*/
if (strbadidnum(v)) {
size_t len = strlen(v);
if (len != 1 && *v == '"' && v[len - 1] == '"')
yylval.l_str = strndup(v + 1, len - 2);
else
yylval.l_str = strndup(v, len);
if (yylval.l_str == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
(void) stresc2chr(yylval.l_str);
return (DT_TOK_STRING);
}
/*
* If the macro text is not a string an begins with a
* digit or a +/- sign, process it as an integer token.
*/
if (isdigit(v[0]) || v[0] == '-' || v[0] == '+') {
if (isdigit(v[0]))
yyintprefix = 0;
else
yyintprefix = *v++;
errno = 0;
yylval.l_int = strtoull(v, &p, 0);
(void) strncpy(yyintsuffix, p,
sizeof (yyintsuffix));
yyintdecimal = *v != '0';
if (errno == ERANGE) {
xyerror(D_MACRO_OFLOW, "macro argument"
" %s constant %s results in integer"
" overflow\n", yytext, v);
}
return (DT_TOK_INT);
}
return (id_or_type(v));
}
<S0>"$$"{RGX_IDENT} {
dt_ident_t *idp = dt_idhash_lookup(
yypcb->pcb_hdl->dt_macros, yytext + 2);
char s[16]; /* enough for UINT_MAX + \0 */
if (idp == NULL) {
xyerror(D_MACRO_UNDEF, "macro variable %s "
"is not defined\n", yytext);
}
/*
* For the moment, all current macro variables are of
* type id_t (refer to dtrace_update() for details).
*/
(void) snprintf(s, sizeof (s), "%u", idp->di_id);
if ((yylval.l_str = strdup(s)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
return (DT_TOK_STRING);
}
<S0>"$"{RGX_IDENT} {
dt_ident_t *idp = dt_idhash_lookup(
yypcb->pcb_hdl->dt_macros, yytext + 1);
if (idp == NULL) {
xyerror(D_MACRO_UNDEF, "macro variable %s "
"is not defined\n", yytext);
}
/*
* For the moment, all current macro variables are of
* type id_t (refer to dtrace_update() for details).
*/
yylval.l_int = (intmax_t)(int)idp->di_id;
yyintprefix = 0;
yyintsuffix[0] = '\0';
yyintdecimal = 1;
return (DT_TOK_INT);
}
<S0>{RGX_IDENT} {
return (id_or_type(yytext));
}
<S0>{RGX_AGG} {
if ((yylval.l_str = strdup(yytext)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
return (DT_TOK_AGG);
}
<S0>"@" {
if ((yylval.l_str = strdup("@_")) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
return (DT_TOK_AGG);
}
<S0>{RGX_INT} |
<S2>{RGX_INT} |
<S3>{RGX_INT} {
char *p;
errno = 0;
yylval.l_int = strtoull(yytext, &p, 0);
yyintprefix = 0;
(void) strncpy(yyintsuffix, p, sizeof (yyintsuffix));
yyintdecimal = yytext[0] != '0';
if (errno == ERANGE) {
xyerror(D_INT_OFLOW, "constant %s results in "
"integer overflow\n", yytext);
}
if (*p != '\0' && strchr("uUlL", *p) == NULL) {
xyerror(D_INT_DIGIT, "constant %s contains "
"invalid digit %c\n", yytext, *p);
}
if ((YYSTATE) != S3)
return (DT_TOK_INT);
yypragma = dt_node_link(yypragma,
dt_node_int(yylval.l_int));
}
<S0>{RGX_FP} yyerror("floating-point constants are not permitted\n");
<S0>\"{RGX_STR}$ |
<S3>\"{RGX_STR}$ xyerror(D_STR_NL, "newline encountered in string literal");
<S0>\"{RGX_STR}\" |
<S3>\"{RGX_STR}\" {
/*
* Quoted string -- convert C escape sequences and
* return the string as a token.
*/
yylval.l_str = strndup(yytext + 1, yyleng - 2);
if (yylval.l_str == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
(void) stresc2chr(yylval.l_str);
if ((YYSTATE) != S3)
return (DT_TOK_STRING);
yypragma = dt_node_link(yypragma,
dt_node_string(yylval.l_str));
}
<S0>'{RGX_CHR}$ xyerror(D_CHR_NL, "newline encountered in character constant");
<S0>'{RGX_CHR}' {
char *s, *p, *q;
size_t nbytes;
/*
* Character constant -- convert C escape sequences and
* return the character as an integer immediate value.
*/
if (yyleng == 2)
xyerror(D_CHR_NULL, "empty character constant");
s = yytext + 1;
yytext[yyleng - 1] = '\0';
nbytes = stresc2chr(s);
yylval.l_int = 0;
yyintprefix = 0;
yyintsuffix[0] = '\0';
yyintdecimal = 1;
if (nbytes > sizeof (yylval.l_int)) {
xyerror(D_CHR_OFLOW, "character constant is "
"too long");
}
#ifdef _LITTLE_ENDIAN
p = ((char *)&yylval.l_int) + nbytes - 1;
for (q = s; nbytes != 0; nbytes--)
*p-- = *q++;
#else
bcopy(s, ((char *)&yylval.l_int) +
sizeof (yylval.l_int) - nbytes, nbytes);
#endif
return (DT_TOK_INT);
}
<S0>"/*" |
<S2>"/*" {
yypcb->pcb_cstate = (YYSTATE);
BEGIN(S1);
}
<S0>{RGX_INTERP} |
<S2>{RGX_INTERP} ; /* discard any #! lines */
<S0>{RGX_CTL} |
<S2>{RGX_CTL} |
<S4>{RGX_CTL} {
assert(yypragma == NULL);
yypcb->pcb_cstate = (YYSTATE);
BEGIN(S3);
}
<S4>. ; /* discard */
<S4>"\n" ; /* discard */
<S0>"/" {
int c, tok;
/*
* The use of "/" as the predicate delimiter and as the
* integer division symbol requires special lookahead
* to avoid a shift/reduce conflict in the D grammar.
* We look ahead to the next non-whitespace character.
* If we encounter EOF, ";", "{", or "/", then this "/"
* closes the predicate and we return DT_TOK_EPRED.
* If we encounter anything else, it's DT_TOK_DIV.
*/
while ((c = input()) != 0) {
if (strchr("\f\n\r\t\v ", c) == NULL)
break;
}
if (c == 0 || c == ';' || c == '{' || c == '/') {
if (yypcb->pcb_parens != 0) {
yyerror("closing ) expected in "
"predicate before /\n");
}
if (yypcb->pcb_brackets != 0) {
yyerror("closing ] expected in "
"predicate before /\n");
}
tok = DT_TOK_EPRED;
} else
tok = DT_TOK_DIV;
unput(c);
return (tok);
}
<S0>"(" {
yypcb->pcb_parens++;
return (DT_TOK_LPAR);
}
<S0>")" {
if (--yypcb->pcb_parens < 0)
yyerror("extra ) in input stream\n");
return (DT_TOK_RPAR);
}
<S0>"[" {
yypcb->pcb_brackets++;
return (DT_TOK_LBRAC);
}
<S0>"]" {
if (--yypcb->pcb_brackets < 0)
yyerror("extra ] in input stream\n");
return (DT_TOK_RBRAC);
}
<S0>"{" |
<S2>"{" {
yypcb->pcb_braces++;
return ('{');
}
<S0>"}" {
if (--yypcb->pcb_braces < 0)
yyerror("extra } in input stream\n");
return ('}');
}
<S0>"|" return (DT_TOK_BOR);
<S0>"^" return (DT_TOK_XOR);
<S0>"&" return (DT_TOK_BAND);
<S0>"&&" return (DT_TOK_LAND);
<S0>"^^" return (DT_TOK_LXOR);
<S0>"||" return (DT_TOK_LOR);
<S0>"==" return (DT_TOK_EQU);
<S0>"!=" return (DT_TOK_NEQ);
<S0>"<" return (DT_TOK_LT);
<S0>"<=" return (DT_TOK_LE);
<S0>">" return (DT_TOK_GT);
<S0>">=" return (DT_TOK_GE);
<S0>"<<" return (DT_TOK_LSH);
<S0>">>" return (DT_TOK_RSH);
<S0>"+" return (DT_TOK_ADD);
<S0>"-" return (DT_TOK_SUB);
<S0>"*" return (DT_TOK_MUL);
<S0>"%" return (DT_TOK_MOD);
<S0>"~" return (DT_TOK_BNEG);
<S0>"!" return (DT_TOK_LNEG);
<S0>"?" return (DT_TOK_QUESTION);
<S0>":" return (DT_TOK_COLON);
<S0>"." return (DT_TOK_DOT);
<S0>"->" return (DT_TOK_PTR);
<S0>"=" return (DT_TOK_ASGN);
<S0>"+=" return (DT_TOK_ADD_EQ);
<S0>"-=" return (DT_TOK_SUB_EQ);
<S0>"*=" return (DT_TOK_MUL_EQ);
<S0>"/=" return (DT_TOK_DIV_EQ);
<S0>"%=" return (DT_TOK_MOD_EQ);
<S0>"&=" return (DT_TOK_AND_EQ);
<S0>"^=" return (DT_TOK_XOR_EQ);
<S0>"|=" return (DT_TOK_OR_EQ);
<S0>"<<=" return (DT_TOK_LSH_EQ);
<S0>">>=" return (DT_TOK_RSH_EQ);
<S0>"++" return (DT_TOK_ADDADD);
<S0>"--" return (DT_TOK_SUBSUB);
<S0>"..." return (DT_TOK_ELLIPSIS);
<S0>"," return (DT_TOK_COMMA);
<S0>";" return (';');
<S0>{RGX_WS} ; /* discard */
<S0>"\\"\n ; /* discard */
<S0>. yyerror("syntax error near \"%c\"\n", yytext[0]);
<S1>"/*" yyerror("/* encountered inside a comment\n");
<S1>"*/" BEGIN(yypcb->pcb_cstate);
<S1>.|\n ; /* discard */
<S2>{RGX_PSPEC} {
/*
* S2 has an ambiguity because RGX_PSPEC includes '*'
* as a glob character and '*' also can be DT_TOK_STAR.
* Since lex always matches the longest token, this
* rule can be matched by an input string like "int*",
* which could begin a global variable declaration such
* as "int*x;" or could begin a RGX_PSPEC with globbing
* such as "int* { trace(timestamp); }". If C_PSPEC is
* not set, we must resolve the ambiguity in favor of
* the type and perform lexer pushback if the fragment
* before '*' or entire fragment matches a type name.
* If C_PSPEC is set, we always return a PSPEC token.
* If C_PSPEC is off, the user can avoid ambiguity by
* including a ':' delimiter in the specifier, which
* they should be doing anyway to specify the provider.
*/
if (!(yypcb->pcb_cflags & DTRACE_C_PSPEC) &&
strchr(yytext, ':') == NULL) {
char *p = strchr(yytext, '*');
char *q = yytext + yyleng - 1;
if (p != NULL && p > yytext)
*p = '\0'; /* prune yytext */
if (dt_type_lookup(yytext, NULL) == 0) {
yylval.l_str = strdup(yytext);
if (yylval.l_str == NULL) {
longjmp(yypcb->pcb_jmpbuf,
EDT_NOMEM);
}
if (p != NULL && p > yytext) {
for (*p = '*'; q >= p; q--)
unput(*q);
}
yybegin(YYS_EXPR);
return (DT_TOK_TNAME);
}
if (p != NULL && p > yytext)
*p = '*'; /* restore yytext */
}
if ((yylval.l_str = strdup(yytext)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
return (DT_TOK_PSPEC);
}
<S2>"/" return (DT_TOK_DIV);
<S2>"," return (DT_TOK_COMMA);
<S2>{RGX_WS} ; /* discard */
<S2>. yyerror("syntax error near \"%c\"\n", yytext[0]);
<S3>\n {
dt_pragma(yypragma);
yypragma = NULL;
BEGIN(yypcb->pcb_cstate);
}
<S3>[\f\t\v ]+ ; /* discard */
<S3>[^\f\n\t\v "]+ {
dt_node_t *dnp;
if ((yylval.l_str = strdup(yytext)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
/*
* We want to call dt_node_ident() here, but we can't
* because it will expand inlined identifiers, which we
* don't want to do from #pragma context in order to
* support pragmas that apply to the ident itself. We
* call dt_node_string() and then reset dn_op instead.
*/
dnp = dt_node_string(yylval.l_str);
dnp->dn_kind = DT_NODE_IDENT;
dnp->dn_op = DT_TOK_IDENT;
yypragma = dt_node_link(yypragma, dnp);
}
<S3>. yyerror("syntax error near \"%c\"\n", yytext[0]);
%%
/*
* yybegin provides a wrapper for use from C code around the lex BEGIN() macro.
* We use two main states for lexing because probe descriptions use a syntax
* that is incompatible with the normal D tokens (e.g. names can contain "-").
* yybegin also handles the job of switching between two lists of dt_nodes
* as we allocate persistent definitions, like inlines, and transient nodes
* that will be freed once we are done parsing the current program file.
*/
void
yybegin(yystate_t state)
{
#ifdef YYDEBUG
yydebug = _dtrace_debug;
#endif
if (yypcb->pcb_yystate == state)
return; /* nothing to do if we're in the state already */
if (yypcb->pcb_yystate == YYS_DEFINE) {
yypcb->pcb_list = yypcb->pcb_hold;
yypcb->pcb_hold = NULL;
}
switch (state) {
case YYS_CLAUSE:
BEGIN(S2);
break;
case YYS_DEFINE:
assert(yypcb->pcb_hold == NULL);
yypcb->pcb_hold = yypcb->pcb_list;
yypcb->pcb_list = NULL;
/*FALLTHRU*/
case YYS_EXPR:
BEGIN(S0);
break;
case YYS_DONE:
break;
case YYS_CONTROL:
BEGIN(S4);
break;
default:
xyerror(D_UNKNOWN, "internal error -- bad yystate %d\n", state);
}
yypcb->pcb_yystate = state;
}
void
yyinit(dt_pcb_t *pcb)
{
yypcb = pcb;
yylineno = 1;
yypragma = NULL;
yysptr = yysbuf;
}
/*
* Given a lexeme 's' (typically yytext), set yylval and return an appropriate
* token to the parser indicating either an identifier or a typedef name.
* User-defined global variables always take precedence over types, but we do
* use some heuristics because D programs can look at an ever-changing set of
* kernel types and also can implicitly instantiate variables by assignment,
* unlike in C. The code here is ordered carefully as lookups are not cheap.
*/
static int
id_or_type(const char *s)
{
dtrace_hdl_t *dtp = yypcb->pcb_hdl;
dt_decl_t *ddp = yypcb->pcb_dstack.ds_decl;
int c0, c1, ttok = DT_TOK_TNAME;
dt_ident_t *idp;
if ((s = yylval.l_str = strdup(s)) == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
/*
* If the lexeme is a global variable or likely identifier or *not* a
* type_name, then it is an identifier token.
*/
if (dt_idstack_lookup(&yypcb->pcb_globals, s) != NULL ||
dt_idhash_lookup(yypcb->pcb_idents, s) != NULL ||
dt_type_lookup(s, NULL) != 0)
return (DT_TOK_IDENT);
/*
* If we're in the midst of parsing a declaration and a type_specifier
* has already been shifted, then return DT_TOK_IDENT instead of TNAME.
* This semantic is necessary to permit valid ISO C code such as:
*
* typedef int foo;
* struct s { foo foo; };
*
* without causing shift/reduce conflicts in the direct_declarator part
* of the grammar. The result is that we must check for conflicting
* redeclarations of the same identifier as part of dt_node_decl().
*/
if (ddp != NULL && ddp->dd_name != NULL)
return (DT_TOK_IDENT);
/*
* If the lexeme is a type name and we are not in a program clause,
* then always interpret it as a type and return DT_TOK_TNAME.
*/
if ((YYSTATE) != S0)
return (DT_TOK_TNAME);
/*
* If the lexeme matches a type name but is in a program clause, then
* it could be a type or it could be an undefined variable. Peek at
* the next token to decide. If we see ++, --, [, or =, we know there
* might be an assignment that is trying to create a global variable,
* so we optimistically return DT_TOK_IDENT. There is no harm in being
* wrong: a type_name followed by ++, --, [, or = is a syntax error.
*/
while ((c0 = input()) != 0) {
if (strchr("\f\n\r\t\v ", c0) == NULL)
break;
}
switch (c0) {
case '+':
case '-':
if ((c1 = input()) == c0)
ttok = DT_TOK_IDENT;
unput(c1);
break;
case '=':
if ((c1 = input()) != c0)
ttok = DT_TOK_IDENT;
unput(c1);
break;
case '[':
ttok = DT_TOK_IDENT;
break;
}
if (ttok == DT_TOK_IDENT) {
idp = dt_idhash_insert(yypcb->pcb_idents, s, DT_IDENT_SCALAR, 0,
0, _dtrace_defattr, 0, &dt_idops_thaw, NULL, dtp->dt_gen);
if (idp == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
}
unput(c0);
return (ttok);
}
static int
input(void)
{
int c;
if (yysptr > yysbuf)
c = *--yysptr;
else if (yypcb->pcb_fileptr != NULL)
c = fgetc(yypcb->pcb_fileptr);
else if (yypcb->pcb_strptr < yypcb->pcb_string + yypcb->pcb_strlen)
c = *(unsigned char *)(yypcb->pcb_strptr++);
else
c = EOF;
if (c == '\n')
yylineno++;
if (c != EOF)
return (c);
if ((YYSTATE) == S1)
yyerror("end-of-file encountered before matching */\n");
if ((YYSTATE) == S3)
yyerror("end-of-file encountered before end of control line\n");
if (yypcb->pcb_fileptr != NULL && ferror(yypcb->pcb_fileptr))
longjmp(yypcb->pcb_jmpbuf, EDT_FIO);
return (0); /* EOF */
}
static void
unput(int c)
{
if (c == '\n')
yylineno--;
*yysptr++ = c;
yytchar = c;
}