xref: /titanic_51/usr/src/cmd/tnf/prex/prexgram.y (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 %{
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License, Version 1.0 only
7  * (the "License").  You may not use this file except in compliance
8  * with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or http://www.opensolaris.org/os/licensing.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  *
23  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 %}
28 
29 %token ADD
30 %token ALLOC
31 %token BUFFER
32 %token CLEAR
33 %token COMMA
34 %token CONNECT
35 %token DEALLOC
36 %token DELETE
37 %token FILTER
38 %token CONTINUE
39 %token CREATE
40 %token DISABLE
41 %token ENABLE
42 %token EQ
43 %token FCNNAME
44 %token FCNS
45 %token ON
46 %token OFF
47 %token HELP
48 %token KTRACE
49 %token HISTORY
50 %token IDENT
51 %token INVAL
52 %token KILL
53 %token LIST
54 %token NL
55 %token PFILTER
56 %token PROBES
57 %token QUIT
58 %token REGEXP
59 %token RESUME
60 %token SCALED_INT
61 %token SETNAME
62 %token SETS
63 %token SOURCE
64 %token SUSPEND
65 %token TRACE
66 %token TRACEFILE
67 %token UNTRACE
68 %token VALSTR
69 %token VALUES
70 
71 %{
72 #include <stdio.h>
73 #include <string.h>
74 #include <sys/types.h>
75 
76 #include "set.h"
77 #include "cmd.h"
78 #include "fcn.h"
79 #include "list.h"
80 #include "expr.h"
81 #include "spec.h"
82 #include "source.h"
83 #include "prbk.h"
84 
85 extern int	yylex();
86 
87 extern void help_on_topic(char *topic);
88 extern void help_on_command(int cmd);
89 extern boolean_t g_kernelmode;
90 extern tnfctl_handle_t *g_hndl;
91 
92 void		quit(boolean_t	killtarget, boolean_t  runtarget);
93 extern void	help(void);
94 extern void	process_cmd(tnfctl_handle_t *hndl, cmd_t *cmd);
95 extern void 	cmd_listtracefile();
96 %}
97 
98 %union
99 {
100 	char *	strval;
101 	expr_t *	exprval;
102 	spec_t *	specval;
103 	void *	pidlistval;
104 	int		intval;
105 }
106 
107 %type <strval>	SETNAME FCNNAME IDENT VALSTR REGEXP
108 %type <intval>  CONTINUE DISABLE ENABLE HELP LIST QUIT SOURCE TRACE UNTRACE BUFFER KTRACE PFILTER CLEAR CONNECT command
109 %type <exprval>	expr exprlist
110 %type <specval> spec speclist
111 %type <pidlistval> pidlist
112 %type <intval>	SCALED_INT singlepid
113 
114 %%
115 
116 file			: statement_list
117 			;
118 
119 statement_list		: /* empty */			{ prompt(); }
120 			| statement_list statement
121 				{
122 			  		  if (g_kernelmode)
123 						prbk_warn_pfilter_empty();
124 						prompt();
125 				}
126 			;
127 
128 statement		: empty_statement
129 			| help_statement
130 			| continue_statement
131 			| quit_statement
132 			| enable_statement
133 			| disable_statement
134 			| trace_statement
135 			| untrace_statement
136 			| connect_statement
137 			| clear_statement
138 			| pfilter_statement
139 			| ktrace_statement
140 			| buffer_statement
141 			| create_statement
142 			| source_statement
143 			| listsets_statement
144 			| listhistory_statement
145 			| listtracefile_statement
146 			| listfcns_statement
147 			| listprobes_statement
148 			| listvalues_statement
149 			| error NL		{ yyerrok; }
150 			;
151 
152 empty_statement		: NL
153 			;
154 
155 command			: CONTINUE	{ $$ = $1; } /* user&kernel */
156 			| DISABLE	{ $$ = $1; }
157     			| ENABLE	{ $$ = $1; }
158 			| HELP		{ $$ = $1; }
159 			| LIST		{ $$ = $1; }
160     			| QUIT		{ $$ = $1; }
161 			| SOURCE	{ $$ = $1; }
162 			| TRACE		{ $$ = $1; }
163 			| UNTRACE	{ $$ = $1; }
164 			| BUFFER	{ $$ = $1; } /* kernel only */
165 			| KTRACE	{ $$ = $1; }
166 			| PFILTER	{ $$ = $1; }
167     			| CLEAR		{ $$ = $1; } /* user only */
168 			| CONNECT	{ $$ = $1; }
169     			;
170 
171 help_statement		: HELP NL		{ help(); }
172 			| HELP command NL       { help_on_command($2); }
173 			| HELP IDENT NL         { help_on_topic($2); }
174 			;
175 
176 continue_statement	: CONTINUE NL
177 				{
178 					if (!g_kernelmode) YYACCEPT;
179 				}
180 			;
181 
182 quit_statement		: QUIT NL		{ quit(B_TRUE, B_TRUE); }
183 			| QUIT KILL NL		{ quit(B_TRUE, B_FALSE); }
184 			| QUIT RESUME NL	{ quit(B_FALSE, B_TRUE); }
185 			| QUIT SUSPEND NL	{ quit(B_FALSE, B_FALSE); }
186 			;
187 
188 enable_statement	: ENABLE SETNAME NL
189 				{
190 					cmd_t *cmd_p;
191 					cmd_p = cmd_set($2, CMD_ENABLE, NULL);
192 					if (cmd_p)
193 						process_cmd(g_hndl, cmd_p);
194 				}
195 			| ENABLE exprlist NL
196 				{
197 					cmd_t *cmd_p;
198 					cmd_p = cmd_expr($2, CMD_ENABLE, NULL);
199 					if (cmd_p)
200 						process_cmd(g_hndl, cmd_p);
201 				}
202 			;
203 
204 disable_statement	: DISABLE SETNAME NL
205 				{
206 					cmd_t *cmd_p;
207 					cmd_p = cmd_set($2, CMD_DISABLE, NULL);
208 					if (cmd_p)
209 						process_cmd(g_hndl, cmd_p);
210 				}
211 			| DISABLE exprlist NL
212 				{
213 					cmd_t *cmd_p;
214 					cmd_p = cmd_expr($2, CMD_DISABLE, NULL);
215 					if (cmd_p)
216 						process_cmd(g_hndl, cmd_p);
217 				}
218 			;
219 
220 trace_statement		: TRACE SETNAME NL
221 				{
222 					cmd_t *cmd_p;
223 					cmd_p = cmd_set($2, CMD_TRACE, NULL);
224 					if (cmd_p)
225 						process_cmd(g_hndl, cmd_p);
226 				}
227 			| TRACE exprlist NL
228 				{
229 					cmd_t *cmd_p;
230 					cmd_p = cmd_expr($2, CMD_TRACE, NULL);
231 					if (cmd_p)
232 						process_cmd(g_hndl, cmd_p);
233 				}
234 			;
235 
236 untrace_statement	: UNTRACE SETNAME NL
237 				{
238 					cmd_t *cmd_p;
239 					cmd_p = cmd_set($2, CMD_UNTRACE, NULL);
240 					if (cmd_p)
241 						process_cmd(g_hndl, cmd_p);
242 				}
243 			| UNTRACE exprlist NL
244 				{
245 					cmd_t *cmd_p;
246 					cmd_p = cmd_expr($2, CMD_UNTRACE, NULL);
247 					if (cmd_p)
248 						process_cmd(g_hndl, cmd_p);
249 				}
250 			;
251 
252 connect_statement	: CONNECT FCNNAME SETNAME NL
253 				{
254 					cmd_t *cmd_p;
255 					cmd_p = cmd_set($3, CMD_CONNECT, $2);
256 					if (cmd_p)
257 						process_cmd(g_hndl, cmd_p);
258 				}
259 			| CONNECT FCNNAME exprlist NL
260 				{
261 					cmd_t *cmd_p;
262 					cmd_p = cmd_expr($3, CMD_CONNECT, $2);
263 					if (cmd_p)
264 						process_cmd(g_hndl, cmd_p);
265 				}
266 			;
267 
268 clear_statement		: CLEAR SETNAME NL
269 				{
270 					cmd_t *cmd_p;
271 					cmd_p = cmd_set($2, CMD_CLEAR, NULL);
272 					if (cmd_p)
273 						process_cmd(g_hndl, cmd_p);
274 				}
275 			| CLEAR exprlist NL
276 				{
277 					cmd_t *cmd_p;
278 					cmd_p = cmd_expr($2, CMD_CLEAR, NULL);
279 					if (cmd_p)
280 						process_cmd(g_hndl, cmd_p);
281 				}
282 			;
283 
284 create_statement	: CREATE SETNAME exprlist NL	{ (void) set($2, $3); }
285 			| CREATE FCNNAME IDENT NL	{ fcn($2, $3); }
286 			;
287 
288 source_statement	: SOURCE VALSTR NL	{ source_file($2); }
289 			| SOURCE IDENT NL	{ source_file($2); }
290 			;
291 
292 listsets_statement	: LIST SETS NL		{ set_list(); }
293 			;
294 
295 listhistory_statement	: LIST HISTORY NL	{ cmd_list(); }
296 			;
297 
298 listtracefile_statement	: LIST TRACEFILE NL	{ cmd_listtracefile(); }
299 			;
300 
301 listfcns_statement	: LIST FCNS NL		{ fcn_list(); }
302 			;
303 
304 			;
305 
306 pfilter_statement	: PFILTER ON NL
307 					{ prbk_set_pfilter_mode(B_TRUE); }
308 			| PFILTER OFF NL
309 					{ prbk_set_pfilter_mode(B_FALSE); }
310 			| PFILTER ADD pidlist NL
311 					{ prbk_pfilter_add($3); }
312 			| PFILTER DELETE pidlist NL
313 					{ prbk_pfilter_drop($3); }
314 			| PFILTER NL
315 					{ prbk_show_pfilter_mode(); }
316 			;
317 
318 ktrace_statement	: KTRACE ON NL
319 					{ prbk_set_tracing(B_TRUE); }
320 			| KTRACE OFF NL
321 					{ prbk_set_tracing(B_FALSE); }
322 			| KTRACE NL
323 					{ prbk_show_tracing(); }
324 			;
325 
326 listprobes_statement	: LIST speclist PROBES SETNAME NL
327 						{ list_set($2, $4); }
328 			| LIST speclist PROBES exprlist NL
329 						{ list_expr($2, $4); }
330 			;
331 
332 listvalues_statement	: LIST VALUES speclist NL { list_values($3); }
333 			;
334 
335 exprlist		: /* empty */		{ $$ = NULL; }
336 			| exprlist expr		{ $$ = expr_list($1, $2); }
337 			;
338 
339 speclist		: /* empty */		{ $$ = NULL; }
340 			| speclist spec		{ $$ = spec_list($1, $2); }
341 			;
342 
343 expr			: spec EQ spec		{ $$ = expr($1, $3); }
344 			| spec			{ $$ = expr(spec(strdup("keys"),
345 							SPEC_EXACT), $1); }
346 			;
347 
348 spec			: IDENT			{ $$ = spec($1, SPEC_EXACT); }
349 			| VALSTR		{ $$ = spec($1, SPEC_EXACT); }
350 			| REGEXP		{ $$ = spec($1, SPEC_REGEXP); }
351 			;
352 
353 pidlist			: pidlist COMMA singlepid
354 				{ $$ = prbk_pidlist_add($1, $3); }
355 			| singlepid
356 				{ $$ = prbk_pidlist_add(NULL, $1); }
357 			;
358 
359 singlepid		: SCALED_INT
360 			;
361 
362 buffer_statement	: BUFFER NL
363 				{
364 				    prbk_buffer_list();
365 				}
366 			| BUFFER ALLOC NL
367 				{
368 				    extern int g_outsize;
369 				    prbk_buffer_alloc(g_outsize);
370 				}
371 			| BUFFER ALLOC SCALED_INT NL
372 				{
373 				    prbk_buffer_alloc($3);
374 				}
375 			| BUFFER DEALLOC NL
376 				{
377 				    prbk_buffer_dealloc();
378 				}
379 			;
380 
381 
382 %%
383