Print this page
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation missing checks
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_parser.c
+++ new/usr/src/lib/libdtrace/common/dt_parser.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright (c) 2011, Joyent Inc. All rights reserved.
25 - * Copyright (c) 2012 by Delphix. All rights reserved.
24 + * Copyright (c) 2013, Joyent Inc. All rights reserved.
25 + * Copyright (c) 2013 by Delphix. All rights reserved.
26 26 */
27 27
28 28 /*
29 29 * DTrace D Language Parser
30 30 *
31 31 * The D Parser is a lex/yacc parser consisting of the lexer dt_lex.l, the
32 32 * parsing grammar dt_grammar.y, and this file, dt_parser.c, which handles
33 33 * the construction of the parse tree nodes and their syntactic validation.
34 34 * The parse tree is constructed of dt_node_t structures (see <dt_parser.h>)
35 35 * that are built in two passes: (1) the "create" pass, where the parse tree
36 36 * nodes are allocated by calls from the grammar to dt_node_*() subroutines,
37 37 * and (2) the "cook" pass, where nodes are coalesced, assigned D types, and
38 38 * validated according to the syntactic rules of the language.
39 39 *
40 40 * All node allocations are performed using dt_node_alloc(). All node frees
41 41 * during the parsing phase are performed by dt_node_free(), which frees node-
42 42 * internal state but does not actually free the nodes. All final node frees
43 43 * are done as part of the end of dt_compile() or as part of destroying
44 44 * persistent identifiers or translators which have embedded nodes.
45 45 *
46 46 * The dt_node_* routines that implement pass (1) may allocate new nodes. The
47 47 * dt_cook_* routines that implement pass (2) may *not* allocate new nodes.
48 48 * They may free existing nodes using dt_node_free(), but they may not actually
49 49 * deallocate any dt_node_t's. Currently dt_cook_op2() is an exception to this
50 50 * rule: see the comments therein for how this issue is resolved.
51 51 *
52 52 * The dt_cook_* routines are responsible for (at minimum) setting the final
53 53 * node type (dn_ctfp/dn_type) and attributes (dn_attr). If dn_ctfp/dn_type
54 54 * are set manually (i.e. not by one of the type assignment functions), then
55 55 * the DT_NF_COOKED flag must be set manually on the node.
56 56 *
57 57 * The cooking pass can be applied to the same parse tree more than once (used
58 58 * in the case of a comma-separated list of probe descriptions). As such, the
59 59 * cook routines must not perform any parse tree transformations which would
60 60 * be invalid if the tree were subsequently cooked using a different context.
61 61 *
62 62 * The dn_ctfp and dn_type fields form the type of the node. This tuple can
63 63 * take on the following set of values, which form our type invariants:
64 64 *
65 65 * 1. dn_ctfp = NULL, dn_type = CTF_ERR
66 66 *
67 67 * In this state, the node has unknown type and is not yet cooked. The
68 68 * DT_NF_COOKED flag is not yet set on the node.
69 69 *
70 70 * 2. dn_ctfp = DT_DYN_CTFP(dtp), dn_type = DT_DYN_TYPE(dtp)
71 71 *
72 72 * In this state, the node is a dynamic D type. This means that generic
73 73 * operations are not valid on this node and only code that knows how to
74 74 * examine the inner details of the node can operate on it. A <DYN> node
75 75 * must have dn_ident set to point to an identifier describing the object
76 76 * and its type. The DT_NF_REF flag is set for all nodes of type <DYN>.
77 77 * At present, the D compiler uses the <DYN> type for:
78 78 *
79 79 * - associative arrays that do not yet have a value type defined
80 80 * - translated data (i.e. the result of the xlate operator)
81 81 * - aggregations
82 82 *
83 83 * 3. dn_ctfp = DT_STR_CTFP(dtp), dn_type = DT_STR_TYPE(dtp)
84 84 *
85 85 * In this state, the node is of type D string. The string type is really
86 86 * a char[0] typedef, but requires special handling throughout the compiler.
87 87 *
88 88 * 4. dn_ctfp != NULL, dn_type = any other type ID
89 89 *
90 90 * In this state, the node is of some known D/CTF type. The normal libctf
91 91 * APIs can be used to learn more about the type name or structure. When
92 92 * the type is assigned, the DT_NF_SIGNED, DT_NF_REF, and DT_NF_BITFIELD
93 93 * flags cache the corresponding attributes of the underlying CTF type.
94 94 */
95 95
96 96 #include <sys/param.h>
97 97 #include <sys/sysmacros.h>
98 98 #include <limits.h>
99 99 #include <setjmp.h>
100 100 #include <strings.h>
101 101 #include <assert.h>
102 102 #include <alloca.h>
103 103 #include <stdlib.h>
104 104 #include <stdarg.h>
105 105 #include <stdio.h>
106 106 #include <errno.h>
107 107 #include <ctype.h>
108 108
109 109 #include <dt_impl.h>
110 110 #include <dt_grammar.h>
111 111 #include <dt_module.h>
112 112 #include <dt_provider.h>
113 113 #include <dt_string.h>
114 114 #include <dt_as.h>
115 115
116 116 dt_pcb_t *yypcb; /* current control block for parser */
117 117 dt_node_t *yypragma; /* lex token list for control lines */
118 118 char yyintprefix; /* int token macro prefix (+/-) */
119 119 char yyintsuffix[4]; /* int token suffix string [uU][lL] */
120 120 int yyintdecimal; /* int token format flag (1=decimal, 0=octal/hex) */
121 121
122 122 static const char *
123 123 opstr(int op)
124 124 {
125 125 switch (op) {
126 126 case DT_TOK_COMMA: return (",");
127 127 case DT_TOK_ELLIPSIS: return ("...");
128 128 case DT_TOK_ASGN: return ("=");
129 129 case DT_TOK_ADD_EQ: return ("+=");
130 130 case DT_TOK_SUB_EQ: return ("-=");
131 131 case DT_TOK_MUL_EQ: return ("*=");
132 132 case DT_TOK_DIV_EQ: return ("/=");
133 133 case DT_TOK_MOD_EQ: return ("%=");
134 134 case DT_TOK_AND_EQ: return ("&=");
135 135 case DT_TOK_XOR_EQ: return ("^=");
136 136 case DT_TOK_OR_EQ: return ("|=");
137 137 case DT_TOK_LSH_EQ: return ("<<=");
138 138 case DT_TOK_RSH_EQ: return (">>=");
139 139 case DT_TOK_QUESTION: return ("?");
140 140 case DT_TOK_COLON: return (":");
141 141 case DT_TOK_LOR: return ("||");
142 142 case DT_TOK_LXOR: return ("^^");
143 143 case DT_TOK_LAND: return ("&&");
144 144 case DT_TOK_BOR: return ("|");
145 145 case DT_TOK_XOR: return ("^");
146 146 case DT_TOK_BAND: return ("&");
147 147 case DT_TOK_EQU: return ("==");
148 148 case DT_TOK_NEQ: return ("!=");
149 149 case DT_TOK_LT: return ("<");
150 150 case DT_TOK_LE: return ("<=");
151 151 case DT_TOK_GT: return (">");
152 152 case DT_TOK_GE: return (">=");
153 153 case DT_TOK_LSH: return ("<<");
154 154 case DT_TOK_RSH: return (">>");
155 155 case DT_TOK_ADD: return ("+");
156 156 case DT_TOK_SUB: return ("-");
157 157 case DT_TOK_MUL: return ("*");
158 158 case DT_TOK_DIV: return ("/");
159 159 case DT_TOK_MOD: return ("%");
160 160 case DT_TOK_LNEG: return ("!");
161 161 case DT_TOK_BNEG: return ("~");
162 162 case DT_TOK_ADDADD: return ("++");
163 163 case DT_TOK_PREINC: return ("++");
164 164 case DT_TOK_POSTINC: return ("++");
165 165 case DT_TOK_SUBSUB: return ("--");
166 166 case DT_TOK_PREDEC: return ("--");
167 167 case DT_TOK_POSTDEC: return ("--");
168 168 case DT_TOK_IPOS: return ("+");
169 169 case DT_TOK_INEG: return ("-");
170 170 case DT_TOK_DEREF: return ("*");
171 171 case DT_TOK_ADDROF: return ("&");
172 172 case DT_TOK_OFFSETOF: return ("offsetof");
173 173 case DT_TOK_SIZEOF: return ("sizeof");
174 174 case DT_TOK_STRINGOF: return ("stringof");
175 175 case DT_TOK_XLATE: return ("xlate");
176 176 case DT_TOK_LPAR: return ("(");
177 177 case DT_TOK_RPAR: return (")");
178 178 case DT_TOK_LBRAC: return ("[");
179 179 case DT_TOK_RBRAC: return ("]");
180 180 case DT_TOK_PTR: return ("->");
181 181 case DT_TOK_DOT: return (".");
182 182 case DT_TOK_STRING: return ("<string>");
183 183 case DT_TOK_IDENT: return ("<ident>");
184 184 case DT_TOK_TNAME: return ("<type>");
↓ open down ↓ |
149 lines elided |
↑ open up ↑ |
185 185 case DT_TOK_INT: return ("<int>");
186 186 default: return ("<?>");
187 187 }
188 188 }
189 189
190 190 int
191 191 dt_type_lookup(const char *s, dtrace_typeinfo_t *tip)
192 192 {
193 193 static const char delimiters[] = " \t\n\r\v\f*`";
194 194 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
195 - const char *p, *q, *end, *obj;
195 + const char *p, *q, *r, *end, *obj;
196 196
197 197 for (p = s, end = s + strlen(s); *p != '\0'; p = q) {
198 198 while (isspace(*p))
199 199 p++; /* skip leading whitespace prior to token */
200 200
201 201 if (p == end || (q = strpbrk(p + 1, delimiters)) == NULL)
202 202 break; /* empty string or single token remaining */
203 203
204 204 if (*q == '`') {
205 205 char *object = alloca((size_t)(q - p) + 1);
206 206 char *type = alloca((size_t)(end - s) + 1);
207 207
208 208 /*
209 209 * Copy from the start of the token (p) to the location
210 210 * backquote (q) to extract the nul-terminated object.
211 211 */
212 212 bcopy(p, object, (size_t)(q - p));
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
213 213 object[(size_t)(q - p)] = '\0';
214 214
215 215 /*
216 216 * Copy the original string up to the start of this
217 217 * token (p) into type, and then concatenate everything
218 218 * after q. This is the type name without the object.
219 219 */
220 220 bcopy(s, type, (size_t)(p - s));
221 221 bcopy(q + 1, type + (size_t)(p - s), strlen(q + 1) + 1);
222 222
223 - if (strchr(q + 1, '`') != NULL)
224 - return (dt_set_errno(dtp, EDT_BADSCOPE));
223 + /*
224 + * There may be at most three delimeters. The second
225 + * delimeter is usually used to distinguish the type
226 + * within a given module, however, there could be a link
227 + * map id on the scene in which case that delimeter
228 + * would be the third. We determine presence of the lmid
229 + * if it rouglhly meets the from LM[0-9]
230 + */
231 + if ((r = strchr(q + 1, '`')) != NULL &&
232 + ((r = strchr(r + 1, '`')) != NULL)) {
233 + if (strchr(r + 1, '`') != NULL)
234 + return (dt_set_errno(dtp,
235 + EDT_BADSCOPE));
236 + if (q[1] != 'L' || q[2] != 'M')
237 + return (dt_set_errno(dtp,
238 + EDT_BADSCOPE));
239 + }
225 240
226 241 return (dtrace_lookup_by_type(dtp, object, type, tip));
227 242 }
228 243 }
229 244
230 245 if (yypcb->pcb_idepth != 0)
231 246 obj = DTRACE_OBJ_CDEFS;
232 247 else
233 248 obj = DTRACE_OBJ_EVERY;
234 249
235 250 return (dtrace_lookup_by_type(dtp, obj, s, tip));
236 251 }
237 252
238 253 /*
239 254 * When we parse type expressions or parse an expression with unary "&", we
240 255 * need to find a type that is a pointer to a previously known type.
241 256 * Unfortunately CTF is limited to a per-container view, so ctf_type_pointer()
242 257 * alone does not suffice for our needs. We provide a more intelligent wrapper
243 258 * for the compiler that attempts to compute a pointer to either the given type
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
244 259 * or its base (that is, we try both "foo_t *" and "struct foo *"), and also
245 260 * to potentially construct the required type on-the-fly.
246 261 */
247 262 int
248 263 dt_type_pointer(dtrace_typeinfo_t *tip)
249 264 {
250 265 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
251 266 ctf_file_t *ctfp = tip->dtt_ctfp;
252 267 ctf_id_t type = tip->dtt_type;
253 268 ctf_id_t base = ctf_type_resolve(ctfp, type);
269 + uint_t bflags = tip->dtt_flags;
254 270
255 271 dt_module_t *dmp;
256 272 ctf_id_t ptr;
257 273
258 274 if ((ptr = ctf_type_pointer(ctfp, type)) != CTF_ERR ||
259 275 (ptr = ctf_type_pointer(ctfp, base)) != CTF_ERR) {
260 276 tip->dtt_type = ptr;
261 277 return (0);
262 278 }
263 279
264 280 if (yypcb->pcb_idepth != 0)
265 281 dmp = dtp->dt_cdefs;
266 282 else
267 283 dmp = dtp->dt_ddefs;
268 284
269 285 if (ctfp != dmp->dm_ctfp && ctfp != ctf_parent_file(dmp->dm_ctfp) &&
270 286 (type = ctf_add_type(dmp->dm_ctfp, ctfp, type)) == CTF_ERR) {
271 287 dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp);
272 288 return (dt_set_errno(dtp, EDT_CTF));
273 289 }
274 290
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
275 291 ptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, type);
276 292
277 293 if (ptr == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) {
278 294 dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp);
279 295 return (dt_set_errno(dtp, EDT_CTF));
280 296 }
281 297
282 298 tip->dtt_object = dmp->dm_name;
283 299 tip->dtt_ctfp = dmp->dm_ctfp;
284 300 tip->dtt_type = ptr;
301 + tip->dtt_flags = bflags;
285 302
286 303 return (0);
287 304 }
288 305
289 306 const char *
290 307 dt_type_name(ctf_file_t *ctfp, ctf_id_t type, char *buf, size_t len)
291 308 {
292 309 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
293 310
294 311 if (ctfp == DT_FPTR_CTFP(dtp) && type == DT_FPTR_TYPE(dtp))
295 312 (void) snprintf(buf, len, "function pointer");
296 313 else if (ctfp == DT_FUNC_CTFP(dtp) && type == DT_FUNC_TYPE(dtp))
297 314 (void) snprintf(buf, len, "function");
298 315 else if (ctfp == DT_DYN_CTFP(dtp) && type == DT_DYN_TYPE(dtp))
299 316 (void) snprintf(buf, len, "dynamic variable");
300 317 else if (ctfp == NULL)
301 318 (void) snprintf(buf, len, "<none>");
302 319 else if (ctf_type_name(ctfp, type, buf, len) == NULL)
303 320 (void) snprintf(buf, len, "unknown");
304 321
305 322 return (buf);
306 323 }
307 324
308 325 /*
309 326 * Perform the "usual arithmetic conversions" to determine which of the two
310 327 * input operand types should be promoted and used as a result type. The
311 328 * rules for this are described in ISOC[6.3.1.8] and K&R[A6.5].
312 329 */
313 330 static void
314 331 dt_type_promote(dt_node_t *lp, dt_node_t *rp, ctf_file_t **ofp, ctf_id_t *otype)
315 332 {
316 333 ctf_file_t *lfp = lp->dn_ctfp;
317 334 ctf_id_t ltype = lp->dn_type;
318 335
319 336 ctf_file_t *rfp = rp->dn_ctfp;
320 337 ctf_id_t rtype = rp->dn_type;
321 338
322 339 ctf_id_t lbase = ctf_type_resolve(lfp, ltype);
323 340 uint_t lkind = ctf_type_kind(lfp, lbase);
324 341
325 342 ctf_id_t rbase = ctf_type_resolve(rfp, rtype);
326 343 uint_t rkind = ctf_type_kind(rfp, rbase);
327 344
328 345 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
329 346 ctf_encoding_t le, re;
330 347 uint_t lrank, rrank;
331 348
332 349 assert(lkind == CTF_K_INTEGER || lkind == CTF_K_ENUM);
333 350 assert(rkind == CTF_K_INTEGER || rkind == CTF_K_ENUM);
334 351
335 352 if (lkind == CTF_K_ENUM) {
336 353 lfp = DT_INT_CTFP(dtp);
337 354 ltype = lbase = DT_INT_TYPE(dtp);
338 355 }
339 356
340 357 if (rkind == CTF_K_ENUM) {
341 358 rfp = DT_INT_CTFP(dtp);
342 359 rtype = rbase = DT_INT_TYPE(dtp);
343 360 }
344 361
345 362 if (ctf_type_encoding(lfp, lbase, &le) == CTF_ERR) {
346 363 yypcb->pcb_hdl->dt_ctferr = ctf_errno(lfp);
347 364 longjmp(yypcb->pcb_jmpbuf, EDT_CTF);
348 365 }
349 366
350 367 if (ctf_type_encoding(rfp, rbase, &re) == CTF_ERR) {
351 368 yypcb->pcb_hdl->dt_ctferr = ctf_errno(rfp);
352 369 longjmp(yypcb->pcb_jmpbuf, EDT_CTF);
353 370 }
354 371
355 372 /*
356 373 * Compute an integer rank based on the size and unsigned status.
357 374 * If rank is identical, pick the "larger" of the equivalent types
358 375 * which we define as having a larger base ctf_id_t. If rank is
359 376 * different, pick the type with the greater rank.
360 377 */
361 378 lrank = le.cte_bits + ((le.cte_format & CTF_INT_SIGNED) == 0);
362 379 rrank = re.cte_bits + ((re.cte_format & CTF_INT_SIGNED) == 0);
363 380
364 381 if (lrank == rrank) {
365 382 if (lbase - rbase < 0)
366 383 goto return_rtype;
367 384 else
368 385 goto return_ltype;
369 386 } else if (lrank > rrank) {
370 387 goto return_ltype;
371 388 } else
372 389 goto return_rtype;
373 390
374 391 return_ltype:
375 392 *ofp = lfp;
376 393 *otype = ltype;
377 394 return;
↓ open down ↓ |
83 lines elided |
↑ open up ↑ |
378 395
379 396 return_rtype:
380 397 *ofp = rfp;
381 398 *otype = rtype;
382 399 }
383 400
384 401 void
385 402 dt_node_promote(dt_node_t *lp, dt_node_t *rp, dt_node_t *dnp)
386 403 {
387 404 dt_type_promote(lp, rp, &dnp->dn_ctfp, &dnp->dn_type);
388 - dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type);
405 + dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type, B_FALSE);
389 406 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
390 407 }
391 408
392 409 const char *
393 410 dt_node_name(const dt_node_t *dnp, char *buf, size_t len)
394 411 {
395 412 char n1[DT_TYPE_NAMELEN];
396 413 char n2[DT_TYPE_NAMELEN];
397 414
398 415 const char *prefix = "", *suffix = "";
399 416 const dtrace_syminfo_t *dts;
400 417 char *s;
401 418
402 419 switch (dnp->dn_kind) {
403 420 case DT_NODE_INT:
404 421 (void) snprintf(buf, len, "integer constant 0x%llx",
405 422 (u_longlong_t)dnp->dn_value);
406 423 break;
407 424 case DT_NODE_STRING:
408 425 s = strchr2esc(dnp->dn_string, strlen(dnp->dn_string));
409 426 (void) snprintf(buf, len, "string constant \"%s\"",
410 427 s != NULL ? s : dnp->dn_string);
411 428 free(s);
412 429 break;
413 430 case DT_NODE_IDENT:
414 431 (void) snprintf(buf, len, "identifier %s", dnp->dn_string);
415 432 break;
416 433 case DT_NODE_VAR:
417 434 case DT_NODE_FUNC:
418 435 case DT_NODE_AGG:
419 436 case DT_NODE_INLINE:
420 437 switch (dnp->dn_ident->di_kind) {
421 438 case DT_IDENT_FUNC:
422 439 case DT_IDENT_AGGFUNC:
423 440 case DT_IDENT_ACTFUNC:
424 441 suffix = "( )";
425 442 break;
426 443 case DT_IDENT_AGG:
427 444 prefix = "@";
428 445 break;
429 446 }
430 447 (void) snprintf(buf, len, "%s %s%s%s",
431 448 dt_idkind_name(dnp->dn_ident->di_kind),
432 449 prefix, dnp->dn_ident->di_name, suffix);
433 450 break;
434 451 case DT_NODE_SYM:
435 452 dts = dnp->dn_ident->di_data;
436 453 (void) snprintf(buf, len, "symbol %s`%s",
437 454 dts->dts_object, dts->dts_name);
438 455 break;
439 456 case DT_NODE_TYPE:
440 457 (void) snprintf(buf, len, "type %s",
441 458 dt_node_type_name(dnp, n1, sizeof (n1)));
442 459 break;
443 460 case DT_NODE_OP1:
444 461 case DT_NODE_OP2:
445 462 case DT_NODE_OP3:
446 463 (void) snprintf(buf, len, "operator %s", opstr(dnp->dn_op));
447 464 break;
448 465 case DT_NODE_DEXPR:
449 466 case DT_NODE_DFUNC:
450 467 if (dnp->dn_expr)
451 468 return (dt_node_name(dnp->dn_expr, buf, len));
452 469 (void) snprintf(buf, len, "%s", "statement");
453 470 break;
454 471 case DT_NODE_PDESC:
455 472 if (dnp->dn_desc->dtpd_id == 0) {
456 473 (void) snprintf(buf, len,
457 474 "probe description %s:%s:%s:%s",
458 475 dnp->dn_desc->dtpd_provider, dnp->dn_desc->dtpd_mod,
459 476 dnp->dn_desc->dtpd_func, dnp->dn_desc->dtpd_name);
460 477 } else {
461 478 (void) snprintf(buf, len, "probe description %u",
462 479 dnp->dn_desc->dtpd_id);
463 480 }
464 481 break;
465 482 case DT_NODE_CLAUSE:
466 483 (void) snprintf(buf, len, "%s", "clause");
467 484 break;
468 485 case DT_NODE_MEMBER:
469 486 (void) snprintf(buf, len, "member %s", dnp->dn_membname);
470 487 break;
471 488 case DT_NODE_XLATOR:
472 489 (void) snprintf(buf, len, "translator <%s> (%s)",
473 490 dt_type_name(dnp->dn_xlator->dx_dst_ctfp,
474 491 dnp->dn_xlator->dx_dst_type, n1, sizeof (n1)),
475 492 dt_type_name(dnp->dn_xlator->dx_src_ctfp,
476 493 dnp->dn_xlator->dx_src_type, n2, sizeof (n2)));
477 494 break;
478 495 case DT_NODE_PROG:
479 496 (void) snprintf(buf, len, "%s", "program");
480 497 break;
481 498 default:
482 499 (void) snprintf(buf, len, "node <%u>", dnp->dn_kind);
483 500 break;
484 501 }
485 502
486 503 return (buf);
487 504 }
488 505
489 506 /*
490 507 * dt_node_xalloc() can be used to create new parse nodes from any libdtrace
491 508 * caller. The caller is responsible for assigning dn_link appropriately.
492 509 */
493 510 dt_node_t *
494 511 dt_node_xalloc(dtrace_hdl_t *dtp, int kind)
495 512 {
496 513 dt_node_t *dnp = dt_alloc(dtp, sizeof (dt_node_t));
497 514
498 515 if (dnp == NULL)
499 516 return (NULL);
500 517
501 518 dnp->dn_ctfp = NULL;
502 519 dnp->dn_type = CTF_ERR;
503 520 dnp->dn_kind = (uchar_t)kind;
504 521 dnp->dn_flags = 0;
505 522 dnp->dn_op = 0;
506 523 dnp->dn_line = -1;
507 524 dnp->dn_reg = -1;
508 525 dnp->dn_attr = _dtrace_defattr;
509 526 dnp->dn_list = NULL;
510 527 dnp->dn_link = NULL;
511 528 bzero(&dnp->dn_u, sizeof (dnp->dn_u));
512 529
513 530 return (dnp);
514 531 }
515 532
516 533 /*
517 534 * dt_node_alloc() is used to create new parse nodes from the parser. It
518 535 * assigns the node location based on the current lexer line number and places
519 536 * the new node on the default allocation list. If allocation fails, we
520 537 * automatically longjmp the caller back to the enclosing compilation call.
521 538 */
522 539 static dt_node_t *
523 540 dt_node_alloc(int kind)
524 541 {
525 542 dt_node_t *dnp = dt_node_xalloc(yypcb->pcb_hdl, kind);
526 543
527 544 if (dnp == NULL)
528 545 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
529 546
530 547 dnp->dn_line = yylineno;
531 548 dnp->dn_link = yypcb->pcb_list;
532 549 yypcb->pcb_list = dnp;
533 550
534 551 return (dnp);
535 552 }
536 553
537 554 void
538 555 dt_node_free(dt_node_t *dnp)
539 556 {
540 557 uchar_t kind = dnp->dn_kind;
541 558
542 559 dnp->dn_kind = DT_NODE_FREE;
543 560
544 561 switch (kind) {
545 562 case DT_NODE_STRING:
546 563 case DT_NODE_IDENT:
547 564 case DT_NODE_TYPE:
548 565 free(dnp->dn_string);
549 566 dnp->dn_string = NULL;
550 567 break;
551 568
552 569 case DT_NODE_VAR:
553 570 case DT_NODE_FUNC:
554 571 case DT_NODE_PROBE:
555 572 if (dnp->dn_ident != NULL) {
556 573 if (dnp->dn_ident->di_flags & DT_IDFLG_ORPHAN)
557 574 dt_ident_destroy(dnp->dn_ident);
558 575 dnp->dn_ident = NULL;
559 576 }
560 577 dt_node_list_free(&dnp->dn_args);
561 578 break;
562 579
563 580 case DT_NODE_OP1:
564 581 if (dnp->dn_child != NULL) {
565 582 dt_node_free(dnp->dn_child);
566 583 dnp->dn_child = NULL;
567 584 }
568 585 break;
569 586
570 587 case DT_NODE_OP3:
571 588 if (dnp->dn_expr != NULL) {
572 589 dt_node_free(dnp->dn_expr);
573 590 dnp->dn_expr = NULL;
574 591 }
575 592 /*FALLTHRU*/
576 593 case DT_NODE_OP2:
577 594 if (dnp->dn_left != NULL) {
578 595 dt_node_free(dnp->dn_left);
579 596 dnp->dn_left = NULL;
580 597 }
581 598 if (dnp->dn_right != NULL) {
582 599 dt_node_free(dnp->dn_right);
583 600 dnp->dn_right = NULL;
584 601 }
585 602 break;
586 603
587 604 case DT_NODE_DEXPR:
588 605 case DT_NODE_DFUNC:
589 606 if (dnp->dn_expr != NULL) {
590 607 dt_node_free(dnp->dn_expr);
591 608 dnp->dn_expr = NULL;
592 609 }
593 610 break;
594 611
595 612 case DT_NODE_AGG:
596 613 if (dnp->dn_aggfun != NULL) {
597 614 dt_node_free(dnp->dn_aggfun);
598 615 dnp->dn_aggfun = NULL;
599 616 }
600 617 dt_node_list_free(&dnp->dn_aggtup);
601 618 break;
602 619
603 620 case DT_NODE_PDESC:
604 621 free(dnp->dn_spec);
605 622 dnp->dn_spec = NULL;
606 623 free(dnp->dn_desc);
607 624 dnp->dn_desc = NULL;
608 625 break;
609 626
610 627 case DT_NODE_CLAUSE:
611 628 if (dnp->dn_pred != NULL)
612 629 dt_node_free(dnp->dn_pred);
613 630 if (dnp->dn_locals != NULL)
614 631 dt_idhash_destroy(dnp->dn_locals);
615 632 dt_node_list_free(&dnp->dn_pdescs);
616 633 dt_node_list_free(&dnp->dn_acts);
617 634 break;
618 635
619 636 case DT_NODE_MEMBER:
620 637 free(dnp->dn_membname);
621 638 dnp->dn_membname = NULL;
622 639 if (dnp->dn_membexpr != NULL) {
623 640 dt_node_free(dnp->dn_membexpr);
624 641 dnp->dn_membexpr = NULL;
625 642 }
626 643 break;
627 644
628 645 case DT_NODE_PROVIDER:
629 646 dt_node_list_free(&dnp->dn_probes);
630 647 free(dnp->dn_provname);
631 648 dnp->dn_provname = NULL;
632 649 break;
633 650
634 651 case DT_NODE_PROG:
635 652 dt_node_list_free(&dnp->dn_list);
636 653 break;
637 654 }
638 655 }
639 656
640 657 void
641 658 dt_node_attr_assign(dt_node_t *dnp, dtrace_attribute_t attr)
642 659 {
643 660 if ((yypcb->pcb_cflags & DTRACE_C_EATTR) &&
644 661 (dt_attr_cmp(attr, yypcb->pcb_amin) < 0)) {
645 662 char a[DTRACE_ATTR2STR_MAX];
646 663 char s[BUFSIZ];
↓ open down ↓ |
248 lines elided |
↑ open up ↑ |
647 664
648 665 dnerror(dnp, D_ATTR_MIN, "attributes for %s (%s) are less than "
649 666 "predefined minimum\n", dt_node_name(dnp, s, sizeof (s)),
650 667 dtrace_attr2str(attr, a, sizeof (a)));
651 668 }
652 669
653 670 dnp->dn_attr = attr;
654 671 }
655 672
656 673 void
657 -dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type)
674 +dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type,
675 + boolean_t user)
658 676 {
659 677 ctf_id_t base = ctf_type_resolve(fp, type);
660 678 uint_t kind = ctf_type_kind(fp, base);
661 679 ctf_encoding_t e;
662 680
663 681 dnp->dn_flags &=
664 682 ~(DT_NF_SIGNED | DT_NF_REF | DT_NF_BITFIELD | DT_NF_USERLAND);
665 683
666 684 if (kind == CTF_K_INTEGER && ctf_type_encoding(fp, base, &e) == 0) {
667 685 size_t size = e.cte_bits / NBBY;
668 686
669 687 if (size > 8 || (e.cte_bits % NBBY) != 0 || (size & (size - 1)))
670 688 dnp->dn_flags |= DT_NF_BITFIELD;
671 689
672 690 if (e.cte_format & CTF_INT_SIGNED)
673 691 dnp->dn_flags |= DT_NF_SIGNED;
674 692 }
675 693
676 694 if (kind == CTF_K_FLOAT && ctf_type_encoding(fp, base, &e) == 0) {
677 695 if (e.cte_bits / NBBY > sizeof (uint64_t))
678 696 dnp->dn_flags |= DT_NF_REF;
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
679 697 }
680 698
681 699 if (kind == CTF_K_STRUCT || kind == CTF_K_UNION ||
682 700 kind == CTF_K_FORWARD ||
683 701 kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION)
684 702 dnp->dn_flags |= DT_NF_REF;
685 703 else if (yypcb != NULL && fp == DT_DYN_CTFP(yypcb->pcb_hdl) &&
686 704 type == DT_DYN_TYPE(yypcb->pcb_hdl))
687 705 dnp->dn_flags |= DT_NF_REF;
688 706
707 + if (user)
708 + dnp->dn_flags |= DT_NF_USERLAND;
709 +
689 710 dnp->dn_flags |= DT_NF_COOKED;
690 711 dnp->dn_ctfp = fp;
691 712 dnp->dn_type = type;
692 713 }
693 714
694 715 void
695 716 dt_node_type_propagate(const dt_node_t *src, dt_node_t *dst)
696 717 {
697 718 assert(src->dn_flags & DT_NF_COOKED);
698 719 dst->dn_flags = src->dn_flags & ~DT_NF_LVALUE;
699 720 dst->dn_ctfp = src->dn_ctfp;
700 721 dst->dn_type = src->dn_type;
701 722 }
702 723
703 724 const char *
704 725 dt_node_type_name(const dt_node_t *dnp, char *buf, size_t len)
705 726 {
706 727 if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL) {
707 728 (void) snprintf(buf, len, "%s",
708 729 dt_idkind_name(dt_ident_resolve(dnp->dn_ident)->di_kind));
709 730 return (buf);
710 731 }
711 732
712 733 if (dnp->dn_flags & DT_NF_USERLAND) {
713 734 size_t n = snprintf(buf, len, "userland ");
714 735 len = len > n ? len - n : 0;
715 736 (void) dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf + n, len);
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
716 737 return (buf);
717 738 }
718 739
719 740 return (dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf, len));
720 741 }
721 742
722 743 size_t
723 744 dt_node_type_size(const dt_node_t *dnp)
724 745 {
725 746 ctf_id_t base;
747 + dtrace_hdl_t *dtp = yypcb->pcb_hdl;
726 748
727 749 if (dnp->dn_kind == DT_NODE_STRING)
728 750 return (strlen(dnp->dn_string) + 1);
729 751
730 752 if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL)
731 753 return (dt_ident_size(dnp->dn_ident));
732 754
733 755 base = ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type);
734 756
735 757 if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_FORWARD)
736 758 return (0);
737 759
760 + /*
761 + * Here we have a 32-bit user pointer that is being used with a 64-bit
762 + * kernel. When we're using it and its tagged as a userland reference --
763 + * then we need to keep it as a 32-bit pointer. However, if we are
764 + * referring to it as a kernel address, eg. being used after a copyin()
765 + * then we need to make sure that we actually return the kernel's size
766 + * of a pointer, 8 bytes.
767 + */
768 + if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_POINTER &&
769 + ctf_getmodel(dnp->dn_ctfp) == CTF_MODEL_ILP32 &&
770 + !(dnp->dn_flags & DT_NF_USERLAND) &&
771 + dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64)
772 + return (8);
773 +
738 774 return (ctf_type_size(dnp->dn_ctfp, dnp->dn_type));
739 775 }
740 776
741 777 /*
742 778 * Determine if the specified parse tree node references an identifier of the
743 779 * specified kind, and if so return a pointer to it; otherwise return NULL.
744 780 * This function resolves the identifier itself, following through any inlines.
745 781 */
746 782 dt_ident_t *
747 783 dt_node_resolve(const dt_node_t *dnp, uint_t idkind)
748 784 {
749 785 dt_ident_t *idp;
750 786
751 787 switch (dnp->dn_kind) {
752 788 case DT_NODE_VAR:
753 789 case DT_NODE_SYM:
754 790 case DT_NODE_FUNC:
755 791 case DT_NODE_AGG:
756 792 case DT_NODE_INLINE:
757 793 case DT_NODE_PROBE:
758 794 idp = dt_ident_resolve(dnp->dn_ident);
759 795 return (idp->di_kind == idkind ? idp : NULL);
760 796 }
761 797
762 798 if (dt_node_is_dynamic(dnp)) {
763 799 idp = dt_ident_resolve(dnp->dn_ident);
764 800 return (idp->di_kind == idkind ? idp : NULL);
765 801 }
766 802
767 803 return (NULL);
768 804 }
769 805
770 806 size_t
771 807 dt_node_sizeof(const dt_node_t *dnp)
772 808 {
773 809 dtrace_syminfo_t *sip;
774 810 GElf_Sym sym;
775 811 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
776 812
777 813 /*
778 814 * The size of the node as used for the sizeof() operator depends on
779 815 * the kind of the node. If the node is a SYM, the size is obtained
780 816 * from the symbol table; if it is not a SYM, the size is determined
781 817 * from the node's type. This is slightly different from C's sizeof()
782 818 * operator in that (for example) when applied to a function, sizeof()
783 819 * will evaluate to the length of the function rather than the size of
784 820 * the function type.
785 821 */
786 822 if (dnp->dn_kind != DT_NODE_SYM)
787 823 return (dt_node_type_size(dnp));
788 824
789 825 sip = dnp->dn_ident->di_data;
790 826
791 827 if (dtrace_lookup_by_name(dtp, sip->dts_object,
792 828 sip->dts_name, &sym, NULL) == -1)
793 829 return (0);
794 830
795 831 return (sym.st_size);
796 832 }
797 833
798 834 int
799 835 dt_node_is_integer(const dt_node_t *dnp)
800 836 {
801 837 ctf_file_t *fp = dnp->dn_ctfp;
802 838 ctf_encoding_t e;
803 839 ctf_id_t type;
804 840 uint_t kind;
805 841
806 842 assert(dnp->dn_flags & DT_NF_COOKED);
807 843
808 844 type = ctf_type_resolve(fp, dnp->dn_type);
809 845 kind = ctf_type_kind(fp, type);
810 846
811 847 if (kind == CTF_K_INTEGER &&
812 848 ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e))
813 849 return (0); /* void integer */
814 850
815 851 return (kind == CTF_K_INTEGER || kind == CTF_K_ENUM);
816 852 }
817 853
818 854 int
819 855 dt_node_is_float(const dt_node_t *dnp)
820 856 {
821 857 ctf_file_t *fp = dnp->dn_ctfp;
822 858 ctf_encoding_t e;
823 859 ctf_id_t type;
824 860 uint_t kind;
825 861
826 862 assert(dnp->dn_flags & DT_NF_COOKED);
827 863
828 864 type = ctf_type_resolve(fp, dnp->dn_type);
829 865 kind = ctf_type_kind(fp, type);
830 866
831 867 return (kind == CTF_K_FLOAT &&
832 868 ctf_type_encoding(dnp->dn_ctfp, type, &e) == 0 && (
833 869 e.cte_format == CTF_FP_SINGLE || e.cte_format == CTF_FP_DOUBLE ||
834 870 e.cte_format == CTF_FP_LDOUBLE));
835 871 }
836 872
837 873 int
838 874 dt_node_is_scalar(const dt_node_t *dnp)
839 875 {
840 876 ctf_file_t *fp = dnp->dn_ctfp;
841 877 ctf_encoding_t e;
842 878 ctf_id_t type;
843 879 uint_t kind;
844 880
845 881 assert(dnp->dn_flags & DT_NF_COOKED);
846 882
847 883 type = ctf_type_resolve(fp, dnp->dn_type);
848 884 kind = ctf_type_kind(fp, type);
849 885
850 886 if (kind == CTF_K_INTEGER &&
851 887 ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e))
852 888 return (0); /* void cannot be used as a scalar */
853 889
854 890 return (kind == CTF_K_INTEGER || kind == CTF_K_ENUM ||
855 891 kind == CTF_K_POINTER);
856 892 }
857 893
858 894 int
859 895 dt_node_is_arith(const dt_node_t *dnp)
860 896 {
861 897 ctf_file_t *fp = dnp->dn_ctfp;
862 898 ctf_encoding_t e;
863 899 ctf_id_t type;
864 900 uint_t kind;
865 901
866 902 assert(dnp->dn_flags & DT_NF_COOKED);
867 903
868 904 type = ctf_type_resolve(fp, dnp->dn_type);
869 905 kind = ctf_type_kind(fp, type);
870 906
871 907 if (kind == CTF_K_INTEGER)
872 908 return (ctf_type_encoding(fp, type, &e) == 0 && !IS_VOID(e));
873 909 else
874 910 return (kind == CTF_K_ENUM);
875 911 }
876 912
877 913 int
878 914 dt_node_is_vfptr(const dt_node_t *dnp)
879 915 {
880 916 ctf_file_t *fp = dnp->dn_ctfp;
881 917 ctf_encoding_t e;
882 918 ctf_id_t type;
883 919 uint_t kind;
884 920
885 921 assert(dnp->dn_flags & DT_NF_COOKED);
886 922
887 923 type = ctf_type_resolve(fp, dnp->dn_type);
888 924 if (ctf_type_kind(fp, type) != CTF_K_POINTER)
889 925 return (0); /* type is not a pointer */
890 926
891 927 type = ctf_type_resolve(fp, ctf_type_reference(fp, type));
892 928 kind = ctf_type_kind(fp, type);
893 929
894 930 return (kind == CTF_K_FUNCTION || (kind == CTF_K_INTEGER &&
895 931 ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e)));
896 932 }
897 933
898 934 int
899 935 dt_node_is_dynamic(const dt_node_t *dnp)
900 936 {
901 937 if (dnp->dn_kind == DT_NODE_VAR &&
902 938 (dnp->dn_ident->di_flags & DT_IDFLG_INLINE)) {
903 939 const dt_idnode_t *inp = dnp->dn_ident->di_iarg;
904 940 return (inp->din_root ? dt_node_is_dynamic(inp->din_root) : 0);
905 941 }
906 942
907 943 return (dnp->dn_ctfp == DT_DYN_CTFP(yypcb->pcb_hdl) &&
908 944 dnp->dn_type == DT_DYN_TYPE(yypcb->pcb_hdl));
909 945 }
910 946
911 947 int
912 948 dt_node_is_string(const dt_node_t *dnp)
913 949 {
914 950 return (dnp->dn_ctfp == DT_STR_CTFP(yypcb->pcb_hdl) &&
915 951 dnp->dn_type == DT_STR_TYPE(yypcb->pcb_hdl));
916 952 }
917 953
918 954 int
919 955 dt_node_is_stack(const dt_node_t *dnp)
920 956 {
921 957 return (dnp->dn_ctfp == DT_STACK_CTFP(yypcb->pcb_hdl) &&
922 958 dnp->dn_type == DT_STACK_TYPE(yypcb->pcb_hdl));
923 959 }
924 960
925 961 int
926 962 dt_node_is_symaddr(const dt_node_t *dnp)
927 963 {
928 964 return (dnp->dn_ctfp == DT_SYMADDR_CTFP(yypcb->pcb_hdl) &&
929 965 dnp->dn_type == DT_SYMADDR_TYPE(yypcb->pcb_hdl));
930 966 }
931 967
932 968 int
933 969 dt_node_is_usymaddr(const dt_node_t *dnp)
934 970 {
935 971 return (dnp->dn_ctfp == DT_USYMADDR_CTFP(yypcb->pcb_hdl) &&
936 972 dnp->dn_type == DT_USYMADDR_TYPE(yypcb->pcb_hdl));
937 973 }
938 974
939 975 int
940 976 dt_node_is_strcompat(const dt_node_t *dnp)
941 977 {
942 978 ctf_file_t *fp = dnp->dn_ctfp;
943 979 ctf_encoding_t e;
944 980 ctf_arinfo_t r;
945 981 ctf_id_t base;
946 982 uint_t kind;
947 983
948 984 assert(dnp->dn_flags & DT_NF_COOKED);
949 985
950 986 base = ctf_type_resolve(fp, dnp->dn_type);
951 987 kind = ctf_type_kind(fp, base);
952 988
953 989 if (kind == CTF_K_POINTER &&
954 990 (base = ctf_type_reference(fp, base)) != CTF_ERR &&
955 991 (base = ctf_type_resolve(fp, base)) != CTF_ERR &&
956 992 ctf_type_encoding(fp, base, &e) == 0 && IS_CHAR(e))
957 993 return (1); /* promote char pointer to string */
958 994
959 995 if (kind == CTF_K_ARRAY && ctf_array_info(fp, base, &r) == 0 &&
960 996 (base = ctf_type_resolve(fp, r.ctr_contents)) != CTF_ERR &&
961 997 ctf_type_encoding(fp, base, &e) == 0 && IS_CHAR(e))
962 998 return (1); /* promote char array to string */
963 999
964 1000 return (0);
965 1001 }
966 1002
967 1003 int
968 1004 dt_node_is_pointer(const dt_node_t *dnp)
969 1005 {
970 1006 ctf_file_t *fp = dnp->dn_ctfp;
971 1007 uint_t kind;
972 1008
973 1009 assert(dnp->dn_flags & DT_NF_COOKED);
974 1010
975 1011 if (dt_node_is_string(dnp))
976 1012 return (0); /* string are pass-by-ref but act like structs */
977 1013
978 1014 kind = ctf_type_kind(fp, ctf_type_resolve(fp, dnp->dn_type));
979 1015 return (kind == CTF_K_POINTER || kind == CTF_K_ARRAY);
980 1016 }
981 1017
982 1018 int
983 1019 dt_node_is_void(const dt_node_t *dnp)
984 1020 {
985 1021 ctf_file_t *fp = dnp->dn_ctfp;
986 1022 ctf_encoding_t e;
987 1023 ctf_id_t type;
988 1024
989 1025 if (dt_node_is_dynamic(dnp))
990 1026 return (0); /* <DYN> is an alias for void but not the same */
991 1027
992 1028 if (dt_node_is_stack(dnp))
993 1029 return (0);
994 1030
995 1031 if (dt_node_is_symaddr(dnp) || dt_node_is_usymaddr(dnp))
996 1032 return (0);
997 1033
998 1034 type = ctf_type_resolve(fp, dnp->dn_type);
999 1035
1000 1036 return (ctf_type_kind(fp, type) == CTF_K_INTEGER &&
1001 1037 ctf_type_encoding(fp, type, &e) == 0 && IS_VOID(e));
1002 1038 }
1003 1039
1004 1040 int
1005 1041 dt_node_is_ptrcompat(const dt_node_t *lp, const dt_node_t *rp,
1006 1042 ctf_file_t **fpp, ctf_id_t *tp)
1007 1043 {
1008 1044 ctf_file_t *lfp = lp->dn_ctfp;
1009 1045 ctf_file_t *rfp = rp->dn_ctfp;
1010 1046
1011 1047 ctf_id_t lbase = CTF_ERR, rbase = CTF_ERR;
1012 1048 ctf_id_t lref = CTF_ERR, rref = CTF_ERR;
1013 1049
1014 1050 int lp_is_void, rp_is_void, lp_is_int, rp_is_int, compat;
1015 1051 uint_t lkind, rkind;
1016 1052 ctf_encoding_t e;
1017 1053 ctf_arinfo_t r;
1018 1054
1019 1055 assert(lp->dn_flags & DT_NF_COOKED);
1020 1056 assert(rp->dn_flags & DT_NF_COOKED);
1021 1057
1022 1058 if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp))
1023 1059 return (0); /* fail if either node is a dynamic variable */
1024 1060
1025 1061 lp_is_int = dt_node_is_integer(lp);
1026 1062 rp_is_int = dt_node_is_integer(rp);
1027 1063
1028 1064 if (lp_is_int && rp_is_int)
1029 1065 return (0); /* fail if both nodes are integers */
1030 1066
1031 1067 if (lp_is_int && (lp->dn_kind != DT_NODE_INT || lp->dn_value != 0))
1032 1068 return (0); /* fail if lp is an integer that isn't 0 constant */
1033 1069
1034 1070 if (rp_is_int && (rp->dn_kind != DT_NODE_INT || rp->dn_value != 0))
1035 1071 return (0); /* fail if rp is an integer that isn't 0 constant */
1036 1072
1037 1073 if ((lp_is_int == 0 && rp_is_int == 0) && (
1038 1074 (lp->dn_flags & DT_NF_USERLAND) ^ (rp->dn_flags & DT_NF_USERLAND)))
1039 1075 return (0); /* fail if only one pointer is a userland address */
1040 1076
1041 1077 /*
1042 1078 * Resolve the left-hand and right-hand types to their base type, and
1043 1079 * then resolve the referenced type as well (assuming the base type
1044 1080 * is CTF_K_POINTER or CTF_K_ARRAY). Otherwise [lr]ref = CTF_ERR.
1045 1081 */
1046 1082 if (!lp_is_int) {
1047 1083 lbase = ctf_type_resolve(lfp, lp->dn_type);
1048 1084 lkind = ctf_type_kind(lfp, lbase);
1049 1085
1050 1086 if (lkind == CTF_K_POINTER) {
1051 1087 lref = ctf_type_resolve(lfp,
1052 1088 ctf_type_reference(lfp, lbase));
1053 1089 } else if (lkind == CTF_K_ARRAY &&
1054 1090 ctf_array_info(lfp, lbase, &r) == 0) {
1055 1091 lref = ctf_type_resolve(lfp, r.ctr_contents);
1056 1092 }
1057 1093 }
1058 1094
1059 1095 if (!rp_is_int) {
1060 1096 rbase = ctf_type_resolve(rfp, rp->dn_type);
1061 1097 rkind = ctf_type_kind(rfp, rbase);
1062 1098
1063 1099 if (rkind == CTF_K_POINTER) {
1064 1100 rref = ctf_type_resolve(rfp,
1065 1101 ctf_type_reference(rfp, rbase));
1066 1102 } else if (rkind == CTF_K_ARRAY &&
1067 1103 ctf_array_info(rfp, rbase, &r) == 0) {
1068 1104 rref = ctf_type_resolve(rfp, r.ctr_contents);
1069 1105 }
1070 1106 }
1071 1107
1072 1108 /*
1073 1109 * We know that one or the other type may still be a zero-valued
1074 1110 * integer constant. To simplify the code below, set the integer
1075 1111 * type variables equal to the non-integer types and proceed.
1076 1112 */
1077 1113 if (lp_is_int) {
1078 1114 lbase = rbase;
1079 1115 lkind = rkind;
1080 1116 lref = rref;
1081 1117 lfp = rfp;
1082 1118 } else if (rp_is_int) {
1083 1119 rbase = lbase;
1084 1120 rkind = lkind;
1085 1121 rref = lref;
1086 1122 rfp = lfp;
1087 1123 }
1088 1124
1089 1125 lp_is_void = ctf_type_encoding(lfp, lref, &e) == 0 && IS_VOID(e);
1090 1126 rp_is_void = ctf_type_encoding(rfp, rref, &e) == 0 && IS_VOID(e);
1091 1127
1092 1128 /*
1093 1129 * The types are compatible if both are pointers to the same type, or
1094 1130 * if either pointer is a void pointer. If they are compatible, set
1095 1131 * tp to point to the more specific pointer type and return it.
1096 1132 */
1097 1133 compat = (lkind == CTF_K_POINTER || lkind == CTF_K_ARRAY) &&
1098 1134 (rkind == CTF_K_POINTER || rkind == CTF_K_ARRAY) &&
1099 1135 (lp_is_void || rp_is_void || ctf_type_compat(lfp, lref, rfp, rref));
1100 1136
1101 1137 if (compat) {
1102 1138 if (fpp != NULL)
1103 1139 *fpp = rp_is_void ? lfp : rfp;
1104 1140 if (tp != NULL)
1105 1141 *tp = rp_is_void ? lbase : rbase;
1106 1142 }
1107 1143
1108 1144 return (compat);
1109 1145 }
1110 1146
1111 1147 /*
1112 1148 * The rules for checking argument types against parameter types are described
1113 1149 * in the ANSI-C spec (see K&R[A7.3.2] and K&R[A7.17]). We use the same rule
1114 1150 * set to determine whether associative array arguments match the prototype.
1115 1151 */
1116 1152 int
1117 1153 dt_node_is_argcompat(const dt_node_t *lp, const dt_node_t *rp)
1118 1154 {
1119 1155 ctf_file_t *lfp = lp->dn_ctfp;
1120 1156 ctf_file_t *rfp = rp->dn_ctfp;
1121 1157
1122 1158 assert(lp->dn_flags & DT_NF_COOKED);
1123 1159 assert(rp->dn_flags & DT_NF_COOKED);
1124 1160
1125 1161 if (dt_node_is_integer(lp) && dt_node_is_integer(rp))
1126 1162 return (1); /* integer types are compatible */
1127 1163
1128 1164 if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp))
1129 1165 return (1); /* string types are compatible */
1130 1166
1131 1167 if (dt_node_is_stack(lp) && dt_node_is_stack(rp))
1132 1168 return (1); /* stack types are compatible */
1133 1169
1134 1170 if (dt_node_is_symaddr(lp) && dt_node_is_symaddr(rp))
1135 1171 return (1); /* symaddr types are compatible */
1136 1172
1137 1173 if (dt_node_is_usymaddr(lp) && dt_node_is_usymaddr(rp))
1138 1174 return (1); /* usymaddr types are compatible */
1139 1175
1140 1176 switch (ctf_type_kind(lfp, ctf_type_resolve(lfp, lp->dn_type))) {
1141 1177 case CTF_K_FUNCTION:
1142 1178 case CTF_K_STRUCT:
1143 1179 case CTF_K_UNION:
1144 1180 return (ctf_type_compat(lfp, lp->dn_type, rfp, rp->dn_type));
1145 1181 default:
1146 1182 return (dt_node_is_ptrcompat(lp, rp, NULL, NULL));
1147 1183 }
1148 1184 }
1149 1185
1150 1186 /*
1151 1187 * We provide dt_node_is_posconst() as a convenience routine for callers who
1152 1188 * wish to verify that an argument is a positive non-zero integer constant.
1153 1189 */
1154 1190 int
1155 1191 dt_node_is_posconst(const dt_node_t *dnp)
1156 1192 {
1157 1193 return (dnp->dn_kind == DT_NODE_INT && dnp->dn_value != 0 && (
1158 1194 (dnp->dn_flags & DT_NF_SIGNED) == 0 || (int64_t)dnp->dn_value > 0));
1159 1195 }
1160 1196
1161 1197 int
1162 1198 dt_node_is_actfunc(const dt_node_t *dnp)
1163 1199 {
1164 1200 return (dnp->dn_kind == DT_NODE_FUNC &&
1165 1201 dnp->dn_ident->di_kind == DT_IDENT_ACTFUNC);
1166 1202 }
1167 1203
1168 1204 /*
1169 1205 * The original rules for integer constant typing are described in K&R[A2.5.1].
1170 1206 * However, since we support long long, we instead use the rules from ISO C99
1171 1207 * clause 6.4.4.1 since that is where long longs are formally described. The
1172 1208 * rules require us to know whether the constant was specified in decimal or
1173 1209 * in octal or hex, which we do by looking at our lexer's 'yyintdecimal' flag.
1174 1210 * The type of an integer constant is the first of the corresponding list in
1175 1211 * which its value can be represented:
1176 1212 *
1177 1213 * unsuffixed decimal: int, long, long long
1178 1214 * unsuffixed oct/hex: int, unsigned int, long, unsigned long,
1179 1215 * long long, unsigned long long
1180 1216 * suffix [uU]: unsigned int, unsigned long, unsigned long long
1181 1217 * suffix [lL] decimal: long, long long
1182 1218 * suffix [lL] oct/hex: long, unsigned long, long long, unsigned long long
1183 1219 * suffix [uU][Ll]: unsigned long, unsigned long long
1184 1220 * suffix ll/LL decimal: long long
1185 1221 * suffix ll/LL oct/hex: long long, unsigned long long
1186 1222 * suffix [uU][ll/LL]: unsigned long long
1187 1223 *
1188 1224 * Given that our lexer has already validated the suffixes by regexp matching,
1189 1225 * there is an obvious way to concisely encode these rules: construct an array
1190 1226 * of the types in the order int, unsigned int, long, unsigned long, long long,
1191 1227 * unsigned long long. Compute an integer array starting index based on the
1192 1228 * suffix (e.g. none = 0, u = 1, ull = 5), and compute an increment based on
1193 1229 * the specifier (dec/oct/hex) and suffix (u). Then iterate from the starting
1194 1230 * index to the end, advancing using the increment, and searching until we
1195 1231 * find a limit that matches or we run out of choices (overflow). To make it
1196 1232 * even faster, we precompute the table of type information in dtrace_open().
1197 1233 */
1198 1234 dt_node_t *
1199 1235 dt_node_int(uintmax_t value)
1200 1236 {
1201 1237 dt_node_t *dnp = dt_node_alloc(DT_NODE_INT);
1202 1238 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1203 1239
1204 1240 int n = (yyintdecimal | (yyintsuffix[0] == 'u')) + 1;
1205 1241 int i = 0;
1206 1242
1207 1243 const char *p;
1208 1244 char c;
1209 1245
1210 1246 dnp->dn_op = DT_TOK_INT;
1211 1247 dnp->dn_value = value;
1212 1248
1213 1249 for (p = yyintsuffix; (c = *p) != '\0'; p++) {
↓ open down ↓ |
466 lines elided |
↑ open up ↑ |
1214 1250 if (c == 'U' || c == 'u')
1215 1251 i += 1;
1216 1252 else if (c == 'L' || c == 'l')
1217 1253 i += 2;
1218 1254 }
1219 1255
1220 1256 for (; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i += n) {
1221 1257 if (value <= dtp->dt_ints[i].did_limit) {
1222 1258 dt_node_type_assign(dnp,
1223 1259 dtp->dt_ints[i].did_ctfp,
1224 - dtp->dt_ints[i].did_type);
1260 + dtp->dt_ints[i].did_type, B_FALSE);
1225 1261
1226 1262 /*
1227 1263 * If a prefix character is present in macro text, add
1228 1264 * in the corresponding operator node (see dt_lex.l).
1229 1265 */
1230 1266 switch (yyintprefix) {
1231 1267 case '+':
1232 1268 return (dt_node_op1(DT_TOK_IPOS, dnp));
1233 1269 case '-':
1234 1270 return (dt_node_op1(DT_TOK_INEG, dnp));
1235 1271 default:
1236 1272 return (dnp);
1237 1273 }
1238 1274 }
1239 1275 }
1240 1276
1241 1277 xyerror(D_INT_OFLOW, "integer constant 0x%llx cannot be represented "
1242 1278 "in any built-in integral type\n", (u_longlong_t)value);
1243 1279 /*NOTREACHED*/
1244 1280 return (NULL); /* keep gcc happy */
1245 1281 }
1246 1282
1247 1283 dt_node_t *
1248 1284 dt_node_string(char *string)
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
1249 1285 {
1250 1286 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1251 1287 dt_node_t *dnp;
1252 1288
1253 1289 if (string == NULL)
1254 1290 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1255 1291
1256 1292 dnp = dt_node_alloc(DT_NODE_STRING);
1257 1293 dnp->dn_op = DT_TOK_STRING;
1258 1294 dnp->dn_string = string;
1259 - dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
1295 + dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), B_FALSE);
1260 1296
1261 1297 return (dnp);
1262 1298 }
1263 1299
1264 1300 dt_node_t *
1265 1301 dt_node_ident(char *name)
1266 1302 {
1267 1303 dt_ident_t *idp;
1268 1304 dt_node_t *dnp;
1269 1305
1270 1306 if (name == NULL)
1271 1307 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1272 1308
1273 1309 /*
1274 1310 * If the identifier is an inlined integer constant, then create an INT
1275 1311 * node that is a clone of the inline parse tree node and return that
1276 1312 * immediately, allowing this inline to be used in parsing contexts
1277 1313 * that require constant expressions (e.g. scalar array sizes).
1278 1314 */
1279 1315 if ((idp = dt_idstack_lookup(&yypcb->pcb_globals, name)) != NULL &&
1280 1316 (idp->di_flags & DT_IDFLG_INLINE)) {
1281 1317 dt_idnode_t *inp = idp->di_iarg;
1282 1318
1283 1319 if (inp->din_root != NULL &&
1284 1320 inp->din_root->dn_kind == DT_NODE_INT) {
1285 1321 free(name);
1286 1322
1287 1323 dnp = dt_node_alloc(DT_NODE_INT);
1288 1324 dnp->dn_op = DT_TOK_INT;
1289 1325 dnp->dn_value = inp->din_root->dn_value;
1290 1326 dt_node_type_propagate(inp->din_root, dnp);
1291 1327
1292 1328 return (dnp);
1293 1329 }
1294 1330 }
1295 1331
1296 1332 dnp = dt_node_alloc(DT_NODE_IDENT);
1297 1333 dnp->dn_op = name[0] == '@' ? DT_TOK_AGG : DT_TOK_IDENT;
1298 1334 dnp->dn_string = name;
1299 1335
1300 1336 return (dnp);
1301 1337 }
1302 1338
1303 1339 /*
1304 1340 * Create an empty node of type corresponding to the given declaration.
1305 1341 * Explicit references to user types (C or D) are assigned the default
1306 1342 * stability; references to other types are _dtrace_typattr (Private).
1307 1343 */
1308 1344 dt_node_t *
1309 1345 dt_node_type(dt_decl_t *ddp)
1310 1346 {
1311 1347 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1312 1348 dtrace_typeinfo_t dtt;
1313 1349 dt_node_t *dnp;
1314 1350 char *name = NULL;
1315 1351 int err;
1316 1352
1317 1353 /*
1318 1354 * If 'ddp' is NULL, we get a decl by popping the decl stack. This
1319 1355 * form of dt_node_type() is used by parameter rules in dt_grammar.y.
1320 1356 */
1321 1357 if (ddp == NULL)
1322 1358 ddp = dt_decl_pop_param(&name);
1323 1359
1324 1360 err = dt_decl_type(ddp, &dtt);
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
1325 1361 dt_decl_free(ddp);
1326 1362
1327 1363 if (err != 0) {
1328 1364 free(name);
1329 1365 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1330 1366 }
1331 1367
1332 1368 dnp = dt_node_alloc(DT_NODE_TYPE);
1333 1369 dnp->dn_op = DT_TOK_IDENT;
1334 1370 dnp->dn_string = name;
1335 - dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
1371 +
1372 + dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags);
1336 1373
1337 1374 if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1338 1375 dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1339 1376 dt_node_attr_assign(dnp, _dtrace_defattr);
1340 1377 else
1341 1378 dt_node_attr_assign(dnp, _dtrace_typattr);
1342 1379
1343 1380 return (dnp);
1344 1381 }
1345 1382
1346 1383 /*
1347 1384 * Create a type node corresponding to a varargs (...) parameter by just
1348 1385 * assigning it type CTF_ERR. The decl processing code will handle this.
1349 1386 */
1350 1387 dt_node_t *
1351 1388 dt_node_vatype(void)
1352 1389 {
1353 1390 dt_node_t *dnp = dt_node_alloc(DT_NODE_TYPE);
1354 1391
1355 1392 dnp->dn_op = DT_TOK_IDENT;
1356 1393 dnp->dn_ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp;
1357 1394 dnp->dn_type = CTF_ERR;
1358 1395 dnp->dn_attr = _dtrace_defattr;
1359 1396
1360 1397 return (dnp);
1361 1398 }
1362 1399
1363 1400 /*
1364 1401 * Instantiate a decl using the contents of the current declaration stack. As
1365 1402 * we do not currently permit decls to be initialized, this function currently
1366 1403 * returns NULL and no parse node is created. When this function is called,
1367 1404 * the topmost scope's ds_ident pointer will be set to NULL (indicating no
1368 1405 * init_declarator rule was matched) or will point to the identifier to use.
1369 1406 */
1370 1407 dt_node_t *
1371 1408 dt_node_decl(void)
1372 1409 {
1373 1410 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1374 1411 dt_scope_t *dsp = &yypcb->pcb_dstack;
1375 1412 dt_dclass_t class = dsp->ds_class;
1376 1413 dt_decl_t *ddp = dt_decl_top();
1377 1414
1378 1415 dt_module_t *dmp;
1379 1416 dtrace_typeinfo_t dtt;
1380 1417 ctf_id_t type;
1381 1418
1382 1419 char n1[DT_TYPE_NAMELEN];
1383 1420 char n2[DT_TYPE_NAMELEN];
1384 1421
1385 1422 if (dt_decl_type(ddp, &dtt) != 0)
1386 1423 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1387 1424
1388 1425 /*
1389 1426 * If we have no declaration identifier, then this is either a spurious
1390 1427 * declaration of an intrinsic type (e.g. "extern int;") or declaration
1391 1428 * or redeclaration of a struct, union, or enum type or tag.
1392 1429 */
1393 1430 if (dsp->ds_ident == NULL) {
1394 1431 if (ddp->dd_kind != CTF_K_STRUCT &&
1395 1432 ddp->dd_kind != CTF_K_UNION && ddp->dd_kind != CTF_K_ENUM)
1396 1433 xyerror(D_DECL_USELESS, "useless declaration\n");
1397 1434
1398 1435 dt_dprintf("type %s added as id %ld\n", dt_type_name(
1399 1436 ddp->dd_ctfp, ddp->dd_type, n1, sizeof (n1)), ddp->dd_type);
1400 1437
1401 1438 return (NULL);
1402 1439 }
1403 1440
1404 1441 if (strchr(dsp->ds_ident, '`') != NULL) {
1405 1442 xyerror(D_DECL_SCOPE, "D scoping operator may not be used in "
1406 1443 "a declaration name (%s)\n", dsp->ds_ident);
1407 1444 }
1408 1445
1409 1446 /*
1410 1447 * If we are nested inside of a C include file, add the declaration to
1411 1448 * the C definition module; otherwise use the D definition module.
1412 1449 */
1413 1450 if (yypcb->pcb_idepth != 0)
1414 1451 dmp = dtp->dt_cdefs;
1415 1452 else
1416 1453 dmp = dtp->dt_ddefs;
1417 1454
1418 1455 /*
1419 1456 * If we see a global or static declaration of a function prototype,
1420 1457 * treat this as equivalent to a D extern declaration.
1421 1458 */
1422 1459 if (ctf_type_kind(dtt.dtt_ctfp, dtt.dtt_type) == CTF_K_FUNCTION &&
1423 1460 (class == DT_DC_DEFAULT || class == DT_DC_STATIC))
1424 1461 class = DT_DC_EXTERN;
1425 1462
1426 1463 switch (class) {
1427 1464 case DT_DC_AUTO:
1428 1465 case DT_DC_REGISTER:
1429 1466 case DT_DC_STATIC:
1430 1467 xyerror(D_DECL_BADCLASS, "specified storage class not "
1431 1468 "appropriate in D\n");
1432 1469 /*NOTREACHED*/
1433 1470
1434 1471 case DT_DC_EXTERN: {
1435 1472 dtrace_typeinfo_t ott;
1436 1473 dtrace_syminfo_t dts;
1437 1474 GElf_Sym sym;
1438 1475
1439 1476 int exists = dtrace_lookup_by_name(dtp,
1440 1477 dmp->dm_name, dsp->ds_ident, &sym, &dts) == 0;
1441 1478
1442 1479 if (exists && (dtrace_symbol_type(dtp, &sym, &dts, &ott) != 0 ||
1443 1480 ctf_type_cmp(dtt.dtt_ctfp, dtt.dtt_type,
1444 1481 ott.dtt_ctfp, ott.dtt_type) != 0)) {
1445 1482 xyerror(D_DECL_IDRED, "identifier redeclared: %s`%s\n"
1446 1483 "\t current: %s\n\tprevious: %s\n",
1447 1484 dmp->dm_name, dsp->ds_ident,
1448 1485 dt_type_name(dtt.dtt_ctfp, dtt.dtt_type,
1449 1486 n1, sizeof (n1)),
1450 1487 dt_type_name(ott.dtt_ctfp, ott.dtt_type,
1451 1488 n2, sizeof (n2)));
1452 1489 } else if (!exists && dt_module_extern(dtp, dmp,
1453 1490 dsp->ds_ident, &dtt) == NULL) {
1454 1491 xyerror(D_UNKNOWN,
1455 1492 "failed to extern %s: %s\n", dsp->ds_ident,
1456 1493 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1457 1494 } else {
1458 1495 dt_dprintf("extern %s`%s type=<%s>\n",
1459 1496 dmp->dm_name, dsp->ds_ident,
1460 1497 dt_type_name(dtt.dtt_ctfp, dtt.dtt_type,
1461 1498 n1, sizeof (n1)));
1462 1499 }
1463 1500 break;
1464 1501 }
1465 1502
1466 1503 case DT_DC_TYPEDEF:
1467 1504 if (dt_idstack_lookup(&yypcb->pcb_globals, dsp->ds_ident)) {
1468 1505 xyerror(D_DECL_IDRED, "global variable identifier "
1469 1506 "redeclared: %s\n", dsp->ds_ident);
1470 1507 }
1471 1508
1472 1509 if (ctf_lookup_by_name(dmp->dm_ctfp,
1473 1510 dsp->ds_ident) != CTF_ERR) {
1474 1511 xyerror(D_DECL_IDRED,
1475 1512 "typedef redeclared: %s\n", dsp->ds_ident);
1476 1513 }
1477 1514
1478 1515 /*
1479 1516 * If the source type for the typedef is not defined in the
1480 1517 * target container or its parent, copy the type to the target
1481 1518 * container and reset dtt_ctfp and dtt_type to the copy.
1482 1519 */
1483 1520 if (dtt.dtt_ctfp != dmp->dm_ctfp &&
1484 1521 dtt.dtt_ctfp != ctf_parent_file(dmp->dm_ctfp)) {
1485 1522
1486 1523 dtt.dtt_type = ctf_add_type(dmp->dm_ctfp,
1487 1524 dtt.dtt_ctfp, dtt.dtt_type);
1488 1525 dtt.dtt_ctfp = dmp->dm_ctfp;
1489 1526
1490 1527 if (dtt.dtt_type == CTF_ERR ||
1491 1528 ctf_update(dtt.dtt_ctfp) == CTF_ERR) {
1492 1529 xyerror(D_UNKNOWN, "failed to copy typedef %s "
1493 1530 "source type: %s\n", dsp->ds_ident,
1494 1531 ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1495 1532 }
1496 1533 }
1497 1534
1498 1535 type = ctf_add_typedef(dmp->dm_ctfp,
1499 1536 CTF_ADD_ROOT, dsp->ds_ident, dtt.dtt_type);
1500 1537
1501 1538 if (type == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) {
1502 1539 xyerror(D_UNKNOWN, "failed to typedef %s: %s\n",
1503 1540 dsp->ds_ident, ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1504 1541 }
1505 1542
1506 1543 dt_dprintf("typedef %s added as id %ld\n", dsp->ds_ident, type);
1507 1544 break;
1508 1545
1509 1546 default: {
1510 1547 ctf_encoding_t cte;
1511 1548 dt_idhash_t *dhp;
1512 1549 dt_ident_t *idp;
1513 1550 dt_node_t idn;
1514 1551 int assc, idkind;
1515 1552 uint_t id, kind;
1516 1553 ushort_t idflags;
1517 1554
1518 1555 switch (class) {
1519 1556 case DT_DC_THIS:
1520 1557 dhp = yypcb->pcb_locals;
1521 1558 idflags = DT_IDFLG_LOCAL;
1522 1559 idp = dt_idhash_lookup(dhp, dsp->ds_ident);
1523 1560 break;
1524 1561 case DT_DC_SELF:
1525 1562 dhp = dtp->dt_tls;
1526 1563 idflags = DT_IDFLG_TLS;
1527 1564 idp = dt_idhash_lookup(dhp, dsp->ds_ident);
1528 1565 break;
1529 1566 default:
1530 1567 dhp = dtp->dt_globals;
1531 1568 idflags = 0;
1532 1569 idp = dt_idstack_lookup(
1533 1570 &yypcb->pcb_globals, dsp->ds_ident);
1534 1571 break;
1535 1572 }
1536 1573
1537 1574 if (ddp->dd_kind == CTF_K_ARRAY && ddp->dd_node == NULL) {
1538 1575 xyerror(D_DECL_ARRNULL,
1539 1576 "array declaration requires array dimension or "
1540 1577 "tuple signature: %s\n", dsp->ds_ident);
1541 1578 }
1542 1579
1543 1580 if (idp != NULL && idp->di_gen == 0) {
1544 1581 xyerror(D_DECL_IDRED, "built-in identifier "
1545 1582 "redeclared: %s\n", idp->di_name);
1546 1583 }
1547 1584
1548 1585 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_CDEFS,
1549 1586 dsp->ds_ident, NULL) == 0 ||
1550 1587 dtrace_lookup_by_type(dtp, DTRACE_OBJ_DDEFS,
1551 1588 dsp->ds_ident, NULL) == 0) {
1552 1589 xyerror(D_DECL_IDRED, "typedef identifier "
1553 1590 "redeclared: %s\n", dsp->ds_ident);
1554 1591 }
1555 1592
1556 1593 /*
1557 1594 * Cache some attributes of the decl to make the rest of this
1558 1595 * code simpler: if the decl is an array which is subscripted
1559 1596 * by a type rather than an integer, then it's an associative
1560 1597 * array (assc). We then expect to match either DT_IDENT_ARRAY
1561 1598 * for associative arrays or DT_IDENT_SCALAR for anything else.
1562 1599 */
1563 1600 assc = ddp->dd_kind == CTF_K_ARRAY &&
1564 1601 ddp->dd_node->dn_kind == DT_NODE_TYPE;
1565 1602
1566 1603 idkind = assc ? DT_IDENT_ARRAY : DT_IDENT_SCALAR;
1567 1604
1568 1605 /*
↓ open down ↓ |
223 lines elided |
↑ open up ↑ |
1569 1606 * Create a fake dt_node_t on the stack so we can determine the
1570 1607 * type of any matching identifier by assigning to this node.
1571 1608 * If the pre-existing ident has its di_type set, propagate
1572 1609 * the type by hand so as not to trigger a prototype check for
1573 1610 * arrays (yet); otherwise we use dt_ident_cook() on the ident
1574 1611 * to ensure it is fully initialized before looking at it.
1575 1612 */
1576 1613 bzero(&idn, sizeof (dt_node_t));
1577 1614
1578 1615 if (idp != NULL && idp->di_type != CTF_ERR)
1579 - dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type);
1616 + dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type,
1617 + B_FALSE);
1580 1618 else if (idp != NULL)
1581 1619 (void) dt_ident_cook(&idn, idp, NULL);
1582 1620
1583 1621 if (assc) {
1584 1622 if (class == DT_DC_THIS) {
1585 1623 xyerror(D_DECL_LOCASSC, "associative arrays "
1586 1624 "may not be declared as local variables:"
1587 1625 " %s\n", dsp->ds_ident);
1588 1626 }
1589 1627
1590 1628 if (dt_decl_type(ddp->dd_next, &dtt) != 0)
1591 1629 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1592 1630 }
1593 1631
1594 1632 if (idp != NULL && (idp->di_kind != idkind ||
1595 1633 ctf_type_cmp(dtt.dtt_ctfp, dtt.dtt_type,
1596 1634 idn.dn_ctfp, idn.dn_type) != 0)) {
1597 1635 xyerror(D_DECL_IDRED, "identifier redeclared: %s\n"
1598 1636 "\t current: %s %s\n\tprevious: %s %s\n",
1599 1637 dsp->ds_ident, dt_idkind_name(idkind),
1600 1638 dt_type_name(dtt.dtt_ctfp,
1601 1639 dtt.dtt_type, n1, sizeof (n1)),
1602 1640 dt_idkind_name(idp->di_kind),
1603 1641 dt_node_type_name(&idn, n2, sizeof (n2)));
1604 1642
1605 1643 } else if (idp != NULL && assc) {
1606 1644 const dt_idsig_t *isp = idp->di_data;
1607 1645 dt_node_t *dnp = ddp->dd_node;
1608 1646 int argc = 0;
1609 1647
1610 1648 for (; dnp != NULL; dnp = dnp->dn_list, argc++) {
1611 1649 const dt_node_t *pnp = &isp->dis_args[argc];
1612 1650
1613 1651 if (argc >= isp->dis_argc)
1614 1652 continue; /* tuple length mismatch */
1615 1653
1616 1654 if (ctf_type_cmp(dnp->dn_ctfp, dnp->dn_type,
1617 1655 pnp->dn_ctfp, pnp->dn_type) == 0)
1618 1656 continue;
1619 1657
1620 1658 xyerror(D_DECL_IDRED,
1621 1659 "identifier redeclared: %s\n"
1622 1660 "\t current: %s, key #%d of type %s\n"
1623 1661 "\tprevious: %s, key #%d of type %s\n",
1624 1662 dsp->ds_ident,
1625 1663 dt_idkind_name(idkind), argc + 1,
1626 1664 dt_node_type_name(dnp, n1, sizeof (n1)),
1627 1665 dt_idkind_name(idp->di_kind), argc + 1,
1628 1666 dt_node_type_name(pnp, n2, sizeof (n2)));
1629 1667 }
1630 1668
1631 1669 if (isp->dis_argc != argc) {
1632 1670 xyerror(D_DECL_IDRED,
1633 1671 "identifier redeclared: %s\n"
1634 1672 "\t current: %s of %s, tuple length %d\n"
1635 1673 "\tprevious: %s of %s, tuple length %d\n",
1636 1674 dsp->ds_ident, dt_idkind_name(idkind),
1637 1675 dt_type_name(dtt.dtt_ctfp, dtt.dtt_type,
1638 1676 n1, sizeof (n1)), argc,
1639 1677 dt_idkind_name(idp->di_kind),
1640 1678 dt_node_type_name(&idn, n2, sizeof (n2)),
1641 1679 isp->dis_argc);
1642 1680 }
1643 1681
1644 1682 } else if (idp == NULL) {
1645 1683 type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
1646 1684 kind = ctf_type_kind(dtt.dtt_ctfp, type);
1647 1685
1648 1686 switch (kind) {
1649 1687 case CTF_K_INTEGER:
1650 1688 if (ctf_type_encoding(dtt.dtt_ctfp, type,
1651 1689 &cte) == 0 && IS_VOID(cte)) {
1652 1690 xyerror(D_DECL_VOIDOBJ, "cannot have "
1653 1691 "void object: %s\n", dsp->ds_ident);
1654 1692 }
1655 1693 break;
1656 1694 case CTF_K_STRUCT:
1657 1695 case CTF_K_UNION:
1658 1696 if (ctf_type_size(dtt.dtt_ctfp, type) != 0)
1659 1697 break; /* proceed to declaring */
1660 1698 /*FALLTHRU*/
1661 1699 case CTF_K_FORWARD:
1662 1700 xyerror(D_DECL_INCOMPLETE,
1663 1701 "incomplete struct/union/enum %s: %s\n",
1664 1702 dt_type_name(dtt.dtt_ctfp, dtt.dtt_type,
1665 1703 n1, sizeof (n1)), dsp->ds_ident);
1666 1704 /*NOTREACHED*/
1667 1705 }
1668 1706
1669 1707 if (dt_idhash_nextid(dhp, &id) == -1) {
1670 1708 xyerror(D_ID_OFLOW, "cannot create %s: limit "
1671 1709 "on number of %s variables exceeded\n",
1672 1710 dsp->ds_ident, dt_idhash_name(dhp));
1673 1711 }
1674 1712
1675 1713 dt_dprintf("declare %s %s variable %s, id=%u\n",
1676 1714 dt_idhash_name(dhp), dt_idkind_name(idkind),
1677 1715 dsp->ds_ident, id);
1678 1716
1679 1717 idp = dt_idhash_insert(dhp, dsp->ds_ident, idkind,
1680 1718 idflags | DT_IDFLG_WRITE | DT_IDFLG_DECL, id,
1681 1719 _dtrace_defattr, 0, assc ? &dt_idops_assc :
1682 1720 &dt_idops_thaw, NULL, dtp->dt_gen);
1683 1721
1684 1722 if (idp == NULL)
1685 1723 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1686 1724
1687 1725 dt_ident_type_assign(idp, dtt.dtt_ctfp, dtt.dtt_type);
1688 1726
1689 1727 /*
1690 1728 * If we are declaring an associative array, use our
1691 1729 * fake parse node to cook the new assoc identifier.
1692 1730 * This will force the ident code to instantiate the
1693 1731 * array type signature corresponding to the list of
1694 1732 * types pointed to by ddp->dd_node. We also reset
1695 1733 * the identifier's attributes based upon the result.
1696 1734 */
1697 1735 if (assc) {
1698 1736 idp->di_attr =
1699 1737 dt_ident_cook(&idn, idp, &ddp->dd_node);
1700 1738 }
1701 1739 }
1702 1740 }
1703 1741
1704 1742 } /* end of switch */
1705 1743
1706 1744 free(dsp->ds_ident);
1707 1745 dsp->ds_ident = NULL;
1708 1746
1709 1747 return (NULL);
1710 1748 }
1711 1749
1712 1750 dt_node_t *
1713 1751 dt_node_func(dt_node_t *dnp, dt_node_t *args)
1714 1752 {
1715 1753 dt_ident_t *idp;
1716 1754
1717 1755 if (dnp->dn_kind != DT_NODE_IDENT) {
1718 1756 xyerror(D_FUNC_IDENT,
1719 1757 "function designator is not of function type\n");
1720 1758 }
1721 1759
1722 1760 idp = dt_idstack_lookup(&yypcb->pcb_globals, dnp->dn_string);
1723 1761
1724 1762 if (idp == NULL) {
1725 1763 xyerror(D_FUNC_UNDEF,
1726 1764 "undefined function name: %s\n", dnp->dn_string);
1727 1765 }
1728 1766
1729 1767 if (idp->di_kind != DT_IDENT_FUNC &&
1730 1768 idp->di_kind != DT_IDENT_AGGFUNC &&
1731 1769 idp->di_kind != DT_IDENT_ACTFUNC) {
1732 1770 xyerror(D_FUNC_IDKIND, "%s '%s' may not be referenced as a "
1733 1771 "function\n", dt_idkind_name(idp->di_kind), idp->di_name);
1734 1772 }
1735 1773
1736 1774 free(dnp->dn_string);
1737 1775 dnp->dn_string = NULL;
1738 1776
1739 1777 dnp->dn_kind = DT_NODE_FUNC;
1740 1778 dnp->dn_flags &= ~DT_NF_COOKED;
1741 1779 dnp->dn_ident = idp;
1742 1780 dnp->dn_args = args;
1743 1781 dnp->dn_list = NULL;
1744 1782
1745 1783 return (dnp);
1746 1784 }
1747 1785
1748 1786 /*
1749 1787 * The offsetof() function is special because it takes a type name as an
1750 1788 * argument. It does not actually construct its own node; after looking up the
1751 1789 * structure or union offset, we just return an integer node with the offset.
1752 1790 */
1753 1791 dt_node_t *
1754 1792 dt_node_offsetof(dt_decl_t *ddp, char *s)
1755 1793 {
1756 1794 dtrace_typeinfo_t dtt;
1757 1795 dt_node_t dn;
1758 1796 char *name;
1759 1797 int err;
1760 1798
1761 1799 ctf_membinfo_t ctm;
1762 1800 ctf_id_t type;
1763 1801 uint_t kind;
1764 1802
1765 1803 name = strdupa(s);
1766 1804 free(s);
1767 1805
1768 1806 err = dt_decl_type(ddp, &dtt);
1769 1807 dt_decl_free(ddp);
1770 1808
1771 1809 if (err != 0)
1772 1810 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1773 1811
1774 1812 type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
1775 1813 kind = ctf_type_kind(dtt.dtt_ctfp, type);
1776 1814
1777 1815 if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
↓ open down ↓ |
188 lines elided |
↑ open up ↑ |
1778 1816 xyerror(D_OFFSETOF_TYPE,
1779 1817 "offsetof operand must be a struct or union type\n");
1780 1818 }
1781 1819
1782 1820 if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1783 1821 xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1784 1822 name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1785 1823 }
1786 1824
1787 1825 bzero(&dn, sizeof (dn));
1788 - dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type);
1826 + dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE);
1789 1827
1790 1828 if (dn.dn_flags & DT_NF_BITFIELD) {
1791 1829 xyerror(D_OFFSETOF_BITFIELD,
1792 1830 "cannot take offset of a bit-field: %s\n", name);
1793 1831 }
1794 1832
1795 1833 return (dt_node_int(ctm.ctm_offset / NBBY));
1796 1834 }
1797 1835
1798 1836 dt_node_t *
1799 1837 dt_node_op1(int op, dt_node_t *cp)
1800 1838 {
1801 1839 dt_node_t *dnp;
1802 1840
1803 1841 if (cp->dn_kind == DT_NODE_INT) {
1804 1842 switch (op) {
1805 1843 case DT_TOK_INEG:
1806 1844 /*
1807 1845 * If we're negating an unsigned integer, zero out any
1808 1846 * extra top bits to truncate the value to the size of
1809 1847 * the effective type determined by dt_node_int().
1810 1848 */
1811 1849 cp->dn_value = -cp->dn_value;
1812 1850 if (!(cp->dn_flags & DT_NF_SIGNED)) {
1813 1851 cp->dn_value &= ~0ULL >>
1814 1852 (64 - dt_node_type_size(cp) * NBBY);
1815 1853 }
1816 1854 /*FALLTHRU*/
1817 1855 case DT_TOK_IPOS:
1818 1856 return (cp);
1819 1857 case DT_TOK_BNEG:
1820 1858 cp->dn_value = ~cp->dn_value;
1821 1859 return (cp);
1822 1860 case DT_TOK_LNEG:
1823 1861 cp->dn_value = !cp->dn_value;
1824 1862 return (cp);
1825 1863 }
1826 1864 }
1827 1865
1828 1866 /*
1829 1867 * If sizeof is applied to a type_name or string constant, we can
1830 1868 * transform 'cp' into an integer constant in the node construction
1831 1869 * pass so that it can then be used for arithmetic in this pass.
1832 1870 */
1833 1871 if (op == DT_TOK_SIZEOF &&
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
1834 1872 (cp->dn_kind == DT_NODE_STRING || cp->dn_kind == DT_NODE_TYPE)) {
1835 1873 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1836 1874 size_t size = dt_node_type_size(cp);
1837 1875
1838 1876 if (size == 0) {
1839 1877 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
1840 1878 "operand of unknown size\n");
1841 1879 }
1842 1880
1843 1881 dt_node_type_assign(cp, dtp->dt_ddefs->dm_ctfp,
1844 - ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
1882 + ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"),
1883 + B_FALSE);
1845 1884
1846 1885 cp->dn_kind = DT_NODE_INT;
1847 1886 cp->dn_op = DT_TOK_INT;
1848 1887 cp->dn_value = size;
1849 1888
1850 1889 return (cp);
1851 1890 }
1852 1891
1853 1892 dnp = dt_node_alloc(DT_NODE_OP1);
1854 1893 assert(op <= USHRT_MAX);
1855 1894 dnp->dn_op = (ushort_t)op;
1856 1895 dnp->dn_child = cp;
1857 1896
1858 1897 return (dnp);
1859 1898 }
1860 1899
1861 1900 /*
1862 1901 * If an integer constant is being cast to another integer type, we can
1863 1902 * perform the cast as part of integer constant folding in this pass. We must
1864 1903 * take action when the integer is being cast to a smaller type or if it is
1865 1904 * changing signed-ness. If so, we first shift rp's bits bits high (losing
1866 1905 * excess bits if narrowing) and then shift them down with either a logical
1867 1906 * shift (unsigned) or arithmetic shift (signed).
1868 1907 */
1869 1908 static void
1870 1909 dt_cast(dt_node_t *lp, dt_node_t *rp)
1871 1910 {
1872 1911 size_t srcsize = dt_node_type_size(rp);
1873 1912 size_t dstsize = dt_node_type_size(lp);
1874 1913
1875 1914 if (dstsize < srcsize) {
1876 1915 int n = (sizeof (uint64_t) - dstsize) * NBBY;
1877 1916 rp->dn_value <<= n;
1878 1917 rp->dn_value >>= n;
1879 1918 } else if (dstsize > srcsize) {
1880 1919 int n = (sizeof (uint64_t) - srcsize) * NBBY;
1881 1920 int s = (dstsize - srcsize) * NBBY;
1882 1921
1883 1922 rp->dn_value <<= n;
1884 1923 if (rp->dn_flags & DT_NF_SIGNED) {
1885 1924 rp->dn_value = (intmax_t)rp->dn_value >> s;
1886 1925 rp->dn_value >>= n - s;
1887 1926 } else {
1888 1927 rp->dn_value >>= n;
1889 1928 }
1890 1929 }
1891 1930 }
1892 1931
1893 1932 dt_node_t *
1894 1933 dt_node_op2(int op, dt_node_t *lp, dt_node_t *rp)
1895 1934 {
1896 1935 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1897 1936 dt_node_t *dnp;
1898 1937
1899 1938 /*
1900 1939 * First we check for operations that are illegal -- namely those that
1901 1940 * might result in integer division by zero, and abort if one is found.
1902 1941 */
1903 1942 if (rp->dn_kind == DT_NODE_INT && rp->dn_value == 0 &&
1904 1943 (op == DT_TOK_MOD || op == DT_TOK_DIV ||
1905 1944 op == DT_TOK_MOD_EQ || op == DT_TOK_DIV_EQ))
1906 1945 xyerror(D_DIV_ZERO, "expression contains division by zero\n");
1907 1946
1908 1947 /*
1909 1948 * If both children are immediate values, we can just perform inline
1910 1949 * calculation and return a new immediate node with the result.
1911 1950 */
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
1912 1951 if (lp->dn_kind == DT_NODE_INT && rp->dn_kind == DT_NODE_INT) {
1913 1952 uintmax_t l = lp->dn_value;
1914 1953 uintmax_t r = rp->dn_value;
1915 1954
1916 1955 dnp = dt_node_int(0); /* allocate new integer node for result */
1917 1956
1918 1957 switch (op) {
1919 1958 case DT_TOK_LOR:
1920 1959 dnp->dn_value = l || r;
1921 1960 dt_node_type_assign(dnp,
1922 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1961 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1923 1962 break;
1924 1963 case DT_TOK_LXOR:
1925 1964 dnp->dn_value = (l != 0) ^ (r != 0);
1926 1965 dt_node_type_assign(dnp,
1927 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1966 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1928 1967 break;
1929 1968 case DT_TOK_LAND:
1930 1969 dnp->dn_value = l && r;
1931 1970 dt_node_type_assign(dnp,
1932 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1971 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1933 1972 break;
1934 1973 case DT_TOK_BOR:
1935 1974 dnp->dn_value = l | r;
1936 1975 dt_node_promote(lp, rp, dnp);
1937 1976 break;
1938 1977 case DT_TOK_XOR:
1939 1978 dnp->dn_value = l ^ r;
1940 1979 dt_node_promote(lp, rp, dnp);
1941 1980 break;
1942 1981 case DT_TOK_BAND:
1943 1982 dnp->dn_value = l & r;
1944 1983 dt_node_promote(lp, rp, dnp);
1945 1984 break;
1946 1985 case DT_TOK_EQU:
1947 1986 dnp->dn_value = l == r;
1948 1987 dt_node_type_assign(dnp,
1949 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1988 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1950 1989 break;
1951 1990 case DT_TOK_NEQ:
1952 1991 dnp->dn_value = l != r;
1953 1992 dt_node_type_assign(dnp,
1954 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1993 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1955 1994 break;
1956 1995 case DT_TOK_LT:
1957 1996 dt_node_promote(lp, rp, dnp);
1958 1997 if (dnp->dn_flags & DT_NF_SIGNED)
1959 1998 dnp->dn_value = (intmax_t)l < (intmax_t)r;
1960 1999 else
1961 2000 dnp->dn_value = l < r;
1962 2001 dt_node_type_assign(dnp,
1963 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
2002 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1964 2003 break;
1965 2004 case DT_TOK_LE:
1966 2005 dt_node_promote(lp, rp, dnp);
1967 2006 if (dnp->dn_flags & DT_NF_SIGNED)
1968 2007 dnp->dn_value = (intmax_t)l <= (intmax_t)r;
1969 2008 else
1970 2009 dnp->dn_value = l <= r;
1971 2010 dt_node_type_assign(dnp,
1972 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
2011 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1973 2012 break;
1974 2013 case DT_TOK_GT:
1975 2014 dt_node_promote(lp, rp, dnp);
1976 2015 if (dnp->dn_flags & DT_NF_SIGNED)
1977 2016 dnp->dn_value = (intmax_t)l > (intmax_t)r;
1978 2017 else
1979 2018 dnp->dn_value = l > r;
1980 2019 dt_node_type_assign(dnp,
1981 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
2020 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1982 2021 break;
1983 2022 case DT_TOK_GE:
1984 2023 dt_node_promote(lp, rp, dnp);
1985 2024 if (dnp->dn_flags & DT_NF_SIGNED)
1986 2025 dnp->dn_value = (intmax_t)l >= (intmax_t)r;
1987 2026 else
1988 2027 dnp->dn_value = l >= r;
1989 2028 dt_node_type_assign(dnp,
1990 - DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
2029 + DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1991 2030 break;
1992 2031 case DT_TOK_LSH:
1993 2032 dnp->dn_value = l << r;
1994 2033 dt_node_type_propagate(lp, dnp);
1995 2034 dt_node_attr_assign(rp,
1996 2035 dt_attr_min(lp->dn_attr, rp->dn_attr));
1997 2036 break;
1998 2037 case DT_TOK_RSH:
1999 2038 dnp->dn_value = l >> r;
2000 2039 dt_node_type_propagate(lp, dnp);
2001 2040 dt_node_attr_assign(rp,
2002 2041 dt_attr_min(lp->dn_attr, rp->dn_attr));
2003 2042 break;
2004 2043 case DT_TOK_ADD:
2005 2044 dnp->dn_value = l + r;
2006 2045 dt_node_promote(lp, rp, dnp);
2007 2046 break;
2008 2047 case DT_TOK_SUB:
2009 2048 dnp->dn_value = l - r;
2010 2049 dt_node_promote(lp, rp, dnp);
2011 2050 break;
2012 2051 case DT_TOK_MUL:
2013 2052 dnp->dn_value = l * r;
2014 2053 dt_node_promote(lp, rp, dnp);
2015 2054 break;
2016 2055 case DT_TOK_DIV:
2017 2056 dt_node_promote(lp, rp, dnp);
2018 2057 if (dnp->dn_flags & DT_NF_SIGNED)
2019 2058 dnp->dn_value = (intmax_t)l / (intmax_t)r;
2020 2059 else
2021 2060 dnp->dn_value = l / r;
2022 2061 break;
2023 2062 case DT_TOK_MOD:
2024 2063 dt_node_promote(lp, rp, dnp);
2025 2064 if (dnp->dn_flags & DT_NF_SIGNED)
2026 2065 dnp->dn_value = (intmax_t)l % (intmax_t)r;
2027 2066 else
2028 2067 dnp->dn_value = l % r;
2029 2068 break;
2030 2069 default:
2031 2070 dt_node_free(dnp);
2032 2071 dnp = NULL;
2033 2072 }
2034 2073
2035 2074 if (dnp != NULL) {
2036 2075 dt_node_free(lp);
2037 2076 dt_node_free(rp);
2038 2077 return (dnp);
2039 2078 }
2040 2079 }
2041 2080
2042 2081 if (op == DT_TOK_LPAR && rp->dn_kind == DT_NODE_INT &&
2043 2082 dt_node_is_integer(lp)) {
2044 2083 dt_cast(lp, rp);
2045 2084 dt_node_type_propagate(lp, rp);
2046 2085 dt_node_attr_assign(rp, dt_attr_min(lp->dn_attr, rp->dn_attr));
2047 2086 dt_node_free(lp);
2048 2087
2049 2088 return (rp);
2050 2089 }
2051 2090
2052 2091 /*
2053 2092 * If no immediate optimizations are available, create an new OP2 node
2054 2093 * and glue the left and right children into place and return.
2055 2094 */
2056 2095 dnp = dt_node_alloc(DT_NODE_OP2);
2057 2096 assert(op <= USHRT_MAX);
2058 2097 dnp->dn_op = (ushort_t)op;
2059 2098 dnp->dn_left = lp;
2060 2099 dnp->dn_right = rp;
2061 2100
2062 2101 return (dnp);
2063 2102 }
2064 2103
2065 2104 dt_node_t *
2066 2105 dt_node_op3(dt_node_t *expr, dt_node_t *lp, dt_node_t *rp)
2067 2106 {
2068 2107 dt_node_t *dnp;
2069 2108
2070 2109 if (expr->dn_kind == DT_NODE_INT)
2071 2110 return (expr->dn_value != 0 ? lp : rp);
2072 2111
2073 2112 dnp = dt_node_alloc(DT_NODE_OP3);
2074 2113 dnp->dn_op = DT_TOK_QUESTION;
2075 2114 dnp->dn_expr = expr;
2076 2115 dnp->dn_left = lp;
2077 2116 dnp->dn_right = rp;
2078 2117
2079 2118 return (dnp);
2080 2119 }
2081 2120
2082 2121 dt_node_t *
2083 2122 dt_node_statement(dt_node_t *expr)
2084 2123 {
2085 2124 dt_node_t *dnp;
2086 2125
2087 2126 if (expr->dn_kind == DT_NODE_AGG)
2088 2127 return (expr);
2089 2128
2090 2129 if (expr->dn_kind == DT_NODE_FUNC &&
2091 2130 expr->dn_ident->di_kind == DT_IDENT_ACTFUNC)
2092 2131 dnp = dt_node_alloc(DT_NODE_DFUNC);
2093 2132 else
2094 2133 dnp = dt_node_alloc(DT_NODE_DEXPR);
2095 2134
2096 2135 dnp->dn_expr = expr;
2097 2136 return (dnp);
2098 2137 }
2099 2138
2100 2139 dt_node_t *
2101 2140 dt_node_pdesc_by_name(char *spec)
2102 2141 {
2103 2142 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2104 2143 dt_node_t *dnp;
2105 2144
2106 2145 if (spec == NULL)
2107 2146 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2108 2147
2109 2148 dnp = dt_node_alloc(DT_NODE_PDESC);
2110 2149 dnp->dn_spec = spec;
2111 2150 dnp->dn_desc = malloc(sizeof (dtrace_probedesc_t));
2112 2151
2113 2152 if (dnp->dn_desc == NULL)
2114 2153 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2115 2154
2116 2155 if (dtrace_xstr2desc(dtp, yypcb->pcb_pspec, dnp->dn_spec,
2117 2156 yypcb->pcb_sargc, yypcb->pcb_sargv, dnp->dn_desc) != 0) {
2118 2157 xyerror(D_PDESC_INVAL, "invalid probe description \"%s\": %s\n",
2119 2158 dnp->dn_spec, dtrace_errmsg(dtp, dtrace_errno(dtp)));
2120 2159 }
2121 2160
2122 2161 free(dnp->dn_spec);
2123 2162 dnp->dn_spec = NULL;
2124 2163
2125 2164 return (dnp);
2126 2165 }
2127 2166
2128 2167 dt_node_t *
2129 2168 dt_node_pdesc_by_id(uintmax_t id)
2130 2169 {
2131 2170 static const char *const names[] = {
2132 2171 "providers", "modules", "functions"
2133 2172 };
2134 2173
2135 2174 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2136 2175 dt_node_t *dnp = dt_node_alloc(DT_NODE_PDESC);
2137 2176
2138 2177 if ((dnp->dn_desc = malloc(sizeof (dtrace_probedesc_t))) == NULL)
2139 2178 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2140 2179
2141 2180 if (id > UINT_MAX) {
2142 2181 xyerror(D_PDESC_INVAL, "identifier %llu exceeds maximum "
2143 2182 "probe id\n", (u_longlong_t)id);
2144 2183 }
2145 2184
2146 2185 if (yypcb->pcb_pspec != DTRACE_PROBESPEC_NAME) {
2147 2186 xyerror(D_PDESC_INVAL, "probe identifier %llu not permitted "
2148 2187 "when specifying %s\n", (u_longlong_t)id,
2149 2188 names[yypcb->pcb_pspec]);
2150 2189 }
2151 2190
2152 2191 if (dtrace_id2desc(dtp, (dtrace_id_t)id, dnp->dn_desc) != 0) {
2153 2192 xyerror(D_PDESC_INVAL, "invalid probe identifier %llu: %s\n",
2154 2193 (u_longlong_t)id, dtrace_errmsg(dtp, dtrace_errno(dtp)));
2155 2194 }
2156 2195
2157 2196 return (dnp);
2158 2197 }
2159 2198
2160 2199 dt_node_t *
2161 2200 dt_node_clause(dt_node_t *pdescs, dt_node_t *pred, dt_node_t *acts)
2162 2201 {
2163 2202 dt_node_t *dnp = dt_node_alloc(DT_NODE_CLAUSE);
2164 2203
2165 2204 dnp->dn_pdescs = pdescs;
2166 2205 dnp->dn_pred = pred;
2167 2206 dnp->dn_acts = acts;
2168 2207
2169 2208 yybegin(YYS_CLAUSE);
2170 2209 return (dnp);
2171 2210 }
2172 2211
2173 2212 dt_node_t *
2174 2213 dt_node_inline(dt_node_t *expr)
2175 2214 {
2176 2215 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2177 2216 dt_scope_t *dsp = &yypcb->pcb_dstack;
2178 2217 dt_decl_t *ddp = dt_decl_top();
2179 2218
2180 2219 char n[DT_TYPE_NAMELEN];
2181 2220 dtrace_typeinfo_t dtt;
2182 2221
2183 2222 dt_ident_t *idp, *rdp;
2184 2223 dt_idnode_t *inp;
2185 2224 dt_node_t *dnp;
2186 2225
2187 2226 if (dt_decl_type(ddp, &dtt) != 0)
2188 2227 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2189 2228
2190 2229 if (dsp->ds_class != DT_DC_DEFAULT) {
2191 2230 xyerror(D_DECL_BADCLASS, "specified storage class not "
2192 2231 "appropriate for inline declaration\n");
2193 2232 }
2194 2233
2195 2234 if (dsp->ds_ident == NULL)
2196 2235 xyerror(D_DECL_USELESS, "inline declaration requires a name\n");
2197 2236
2198 2237 if ((idp = dt_idstack_lookup(
2199 2238 &yypcb->pcb_globals, dsp->ds_ident)) != NULL) {
2200 2239 xyerror(D_DECL_IDRED, "identifier redefined: %s\n\t current: "
2201 2240 "inline definition\n\tprevious: %s %s\n",
2202 2241 idp->di_name, dt_idkind_name(idp->di_kind),
2203 2242 (idp->di_flags & DT_IDFLG_INLINE) ? "inline" : "");
2204 2243 }
2205 2244
2206 2245 /*
2207 2246 * If we are declaring an inlined array, verify that we have a tuple
2208 2247 * signature, and then recompute 'dtt' as the array's value type.
2209 2248 */
2210 2249 if (ddp->dd_kind == CTF_K_ARRAY) {
2211 2250 if (ddp->dd_node == NULL) {
2212 2251 xyerror(D_DECL_ARRNULL, "inline declaration requires "
2213 2252 "array tuple signature: %s\n", dsp->ds_ident);
2214 2253 }
2215 2254
2216 2255 if (ddp->dd_node->dn_kind != DT_NODE_TYPE) {
2217 2256 xyerror(D_DECL_ARRNULL, "inline declaration cannot be "
2218 2257 "of scalar array type: %s\n", dsp->ds_ident);
2219 2258 }
2220 2259
↓ open down ↓ |
220 lines elided |
↑ open up ↑ |
2221 2260 if (dt_decl_type(ddp->dd_next, &dtt) != 0)
2222 2261 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2223 2262 }
2224 2263
2225 2264 /*
2226 2265 * If the inline identifier is not defined, then create it with the
2227 2266 * orphan flag set. We do not insert the identifier into dt_globals
2228 2267 * until we have successfully cooked the right-hand expression, below.
2229 2268 */
2230 2269 dnp = dt_node_alloc(DT_NODE_INLINE);
2231 - dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2270 + dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, B_FALSE);
2232 2271 dt_node_attr_assign(dnp, _dtrace_defattr);
2233 2272
2234 2273 if (dt_node_is_void(dnp)) {
2235 2274 xyerror(D_DECL_VOIDOBJ,
2236 2275 "cannot declare void inline: %s\n", dsp->ds_ident);
2237 2276 }
2238 2277
2239 2278 if (ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve(
2240 2279 dnp->dn_ctfp, dnp->dn_type)) == CTF_K_FORWARD) {
2241 2280 xyerror(D_DECL_INCOMPLETE,
2242 2281 "incomplete struct/union/enum %s: %s\n",
2243 2282 dt_node_type_name(dnp, n, sizeof (n)), dsp->ds_ident);
2244 2283 }
2245 2284
2246 2285 if ((inp = malloc(sizeof (dt_idnode_t))) == NULL)
2247 2286 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2248 2287
2249 2288 bzero(inp, sizeof (dt_idnode_t));
2250 2289
2251 2290 idp = dnp->dn_ident = dt_ident_create(dsp->ds_ident,
2252 2291 ddp->dd_kind == CTF_K_ARRAY ? DT_IDENT_ARRAY : DT_IDENT_SCALAR,
2253 2292 DT_IDFLG_INLINE | DT_IDFLG_REF | DT_IDFLG_DECL | DT_IDFLG_ORPHAN, 0,
2254 2293 _dtrace_defattr, 0, &dt_idops_inline, inp, dtp->dt_gen);
2255 2294
2256 2295 if (idp == NULL) {
2257 2296 free(inp);
2258 2297 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2259 2298 }
2260 2299
2261 2300 /*
2262 2301 * If we're inlining an associative array, create a private identifier
2263 2302 * hash containing the named parameters and store it in inp->din_hash.
2264 2303 * We then push this hash on to the top of the pcb_globals stack.
2265 2304 */
2266 2305 if (ddp->dd_kind == CTF_K_ARRAY) {
2267 2306 dt_idnode_t *pinp;
2268 2307 dt_ident_t *pidp;
2269 2308 dt_node_t *pnp;
2270 2309 uint_t i = 0;
2271 2310
2272 2311 for (pnp = ddp->dd_node; pnp != NULL; pnp = pnp->dn_list)
2273 2312 i++; /* count up parameters for din_argv[] */
2274 2313
2275 2314 inp->din_hash = dt_idhash_create("inline args", NULL, 0, 0);
2276 2315 inp->din_argv = calloc(i, sizeof (dt_ident_t *));
2277 2316
2278 2317 if (inp->din_hash == NULL || inp->din_argv == NULL)
2279 2318 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2280 2319
2281 2320 /*
2282 2321 * Create an identifier for each parameter as a scalar inline,
2283 2322 * and store it in din_hash and in position in din_argv[]. The
2284 2323 * parameter identifiers also use dt_idops_inline, but we leave
2285 2324 * the dt_idnode_t argument 'pinp' zeroed. This will be filled
2286 2325 * in by the code generation pass with references to the args.
2287 2326 */
2288 2327 for (i = 0, pnp = ddp->dd_node;
2289 2328 pnp != NULL; pnp = pnp->dn_list, i++) {
2290 2329
2291 2330 if (pnp->dn_string == NULL)
2292 2331 continue; /* ignore anonymous parameters */
2293 2332
2294 2333 if ((pinp = malloc(sizeof (dt_idnode_t))) == NULL)
2295 2334 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2296 2335
2297 2336 pidp = dt_idhash_insert(inp->din_hash, pnp->dn_string,
2298 2337 DT_IDENT_SCALAR, DT_IDFLG_DECL | DT_IDFLG_INLINE, 0,
2299 2338 _dtrace_defattr, 0, &dt_idops_inline,
2300 2339 pinp, dtp->dt_gen);
2301 2340
2302 2341 if (pidp == NULL) {
2303 2342 free(pinp);
2304 2343 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2305 2344 }
2306 2345
2307 2346 inp->din_argv[i] = pidp;
2308 2347 bzero(pinp, sizeof (dt_idnode_t));
2309 2348 dt_ident_type_assign(pidp, pnp->dn_ctfp, pnp->dn_type);
2310 2349 }
2311 2350
2312 2351 dt_idstack_push(&yypcb->pcb_globals, inp->din_hash);
2313 2352 }
2314 2353
2315 2354 /*
2316 2355 * Unlike most constructors, we need to explicitly cook the right-hand
2317 2356 * side of the inline definition immediately to prevent recursion. If
2318 2357 * the right-hand side uses the inline itself, the cook will fail.
2319 2358 */
2320 2359 expr = dt_node_cook(expr, DT_IDFLG_REF);
2321 2360
2322 2361 if (ddp->dd_kind == CTF_K_ARRAY)
2323 2362 dt_idstack_pop(&yypcb->pcb_globals, inp->din_hash);
2324 2363
2325 2364 /*
2326 2365 * Set the type, attributes, and flags for the inline. If the right-
2327 2366 * hand expression has an identifier, propagate its flags. Then cook
2328 2367 * the identifier to fully initialize it: if we're declaring an inline
2329 2368 * associative array this will construct a type signature from 'ddp'.
2330 2369 */
2331 2370 if (dt_node_is_dynamic(expr))
2332 2371 rdp = dt_ident_resolve(expr->dn_ident);
2333 2372 else if (expr->dn_kind == DT_NODE_VAR || expr->dn_kind == DT_NODE_SYM)
2334 2373 rdp = expr->dn_ident;
2335 2374 else
2336 2375 rdp = NULL;
2337 2376
2338 2377 if (rdp != NULL) {
2339 2378 idp->di_flags |= (rdp->di_flags &
2340 2379 (DT_IDFLG_WRITE | DT_IDFLG_USER | DT_IDFLG_PRIM));
2341 2380 }
2342 2381
2343 2382 idp->di_attr = dt_attr_min(_dtrace_defattr, expr->dn_attr);
2344 2383 dt_ident_type_assign(idp, dtt.dtt_ctfp, dtt.dtt_type);
2345 2384 (void) dt_ident_cook(dnp, idp, &ddp->dd_node);
2346 2385
2347 2386 /*
2348 2387 * Store the parse tree nodes for 'expr' inside of idp->di_data ('inp')
2349 2388 * so that they will be preserved with this identifier. Then pop the
2350 2389 * inline declaration from the declaration stack and restore the lexer.
2351 2390 */
2352 2391 inp->din_list = yypcb->pcb_list;
2353 2392 inp->din_root = expr;
2354 2393
2355 2394 dt_decl_free(dt_decl_pop());
2356 2395 yybegin(YYS_CLAUSE);
2357 2396
2358 2397 /*
2359 2398 * Finally, insert the inline identifier into dt_globals to make it
2360 2399 * visible, and then cook 'dnp' to check its type against 'expr'.
2361 2400 */
2362 2401 dt_idhash_xinsert(dtp->dt_globals, idp);
2363 2402 return (dt_node_cook(dnp, DT_IDFLG_REF));
2364 2403 }
2365 2404
2366 2405 dt_node_t *
2367 2406 dt_node_member(dt_decl_t *ddp, char *name, dt_node_t *expr)
2368 2407 {
2369 2408 dtrace_typeinfo_t dtt;
2370 2409 dt_node_t *dnp;
2371 2410 int err;
2372 2411
2373 2412 if (ddp != NULL) {
2374 2413 err = dt_decl_type(ddp, &dtt);
2375 2414 dt_decl_free(ddp);
↓ open down ↓ |
134 lines elided |
↑ open up ↑ |
2376 2415
2377 2416 if (err != 0)
2378 2417 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2379 2418 }
2380 2419
2381 2420 dnp = dt_node_alloc(DT_NODE_MEMBER);
2382 2421 dnp->dn_membname = name;
2383 2422 dnp->dn_membexpr = expr;
2384 2423
2385 2424 if (ddp != NULL)
2386 - dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2425 + dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2426 + dtt.dtt_flags);
2387 2427
2388 2428 return (dnp);
2389 2429 }
2390 2430
2391 2431 dt_node_t *
2392 2432 dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2393 2433 {
2394 2434 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2395 2435 dtrace_typeinfo_t src, dst;
2396 2436 dt_node_t sn, dn;
2397 2437 dt_xlator_t *dxp;
2398 2438 dt_node_t *dnp;
2399 2439 int edst, esrc;
2400 2440 uint_t kind;
2401 2441
2402 2442 char n1[DT_TYPE_NAMELEN];
2403 2443 char n2[DT_TYPE_NAMELEN];
2404 2444
2405 2445 edst = dt_decl_type(ddp, &dst);
2406 2446 dt_decl_free(ddp);
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
2407 2447
2408 2448 esrc = dt_decl_type(sdp, &src);
2409 2449 dt_decl_free(sdp);
2410 2450
2411 2451 if (edst != 0 || esrc != 0) {
2412 2452 free(name);
2413 2453 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2414 2454 }
2415 2455
2416 2456 bzero(&sn, sizeof (sn));
2417 - dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type);
2457 + dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type, B_FALSE);
2418 2458
2419 2459 bzero(&dn, sizeof (dn));
2420 - dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type);
2460 + dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type, B_FALSE);
2421 2461
2422 2462 if (dt_xlator_lookup(dtp, &sn, &dn, DT_XLATE_EXACT) != NULL) {
2423 2463 xyerror(D_XLATE_REDECL,
2424 2464 "translator from %s to %s has already been declared\n",
2425 2465 dt_node_type_name(&sn, n1, sizeof (n1)),
2426 2466 dt_node_type_name(&dn, n2, sizeof (n2)));
2427 2467 }
2428 2468
2429 2469 kind = ctf_type_kind(dst.dtt_ctfp,
2430 2470 ctf_type_resolve(dst.dtt_ctfp, dst.dtt_type));
2431 2471
2432 2472 if (kind == CTF_K_FORWARD) {
2433 2473 xyerror(D_XLATE_SOU, "incomplete struct/union/enum %s\n",
2434 2474 dt_type_name(dst.dtt_ctfp, dst.dtt_type, n1, sizeof (n1)));
2435 2475 }
2436 2476
2437 2477 if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
2438 2478 xyerror(D_XLATE_SOU,
2439 2479 "translator output type must be a struct or union\n");
2440 2480 }
2441 2481
2442 2482 dxp = dt_xlator_create(dtp, &src, &dst, name, members, yypcb->pcb_list);
2443 2483 yybegin(YYS_CLAUSE);
2444 2484 free(name);
2445 2485
2446 2486 if (dxp == NULL)
2447 2487 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2448 2488
2449 2489 dnp = dt_node_alloc(DT_NODE_XLATOR);
2450 2490 dnp->dn_xlator = dxp;
2451 2491 dnp->dn_members = members;
2452 2492
2453 2493 return (dt_node_cook(dnp, DT_IDFLG_REF));
2454 2494 }
2455 2495
2456 2496 dt_node_t *
2457 2497 dt_node_probe(char *s, int protoc, dt_node_t *nargs, dt_node_t *xargs)
2458 2498 {
2459 2499 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2460 2500 int nargc, xargc;
2461 2501 dt_node_t *dnp;
2462 2502
2463 2503 size_t len = strlen(s) + 3; /* +3 for :: and \0 */
2464 2504 char *name = alloca(len);
2465 2505
2466 2506 (void) snprintf(name, len, "::%s", s);
2467 2507 (void) strhyphenate(name);
2468 2508 free(s);
2469 2509
2470 2510 if (strchr(name, '`') != NULL) {
2471 2511 xyerror(D_PROV_BADNAME, "probe name may not "
2472 2512 "contain scoping operator: %s\n", name);
2473 2513 }
2474 2514
2475 2515 if (strlen(name) - 2 >= DTRACE_NAMELEN) {
2476 2516 xyerror(D_PROV_BADNAME, "probe name may not exceed %d "
2477 2517 "characters: %s\n", DTRACE_NAMELEN - 1, name);
2478 2518 }
2479 2519
2480 2520 dnp = dt_node_alloc(DT_NODE_PROBE);
2481 2521
2482 2522 dnp->dn_ident = dt_ident_create(name, DT_IDENT_PROBE,
2483 2523 DT_IDFLG_ORPHAN, DTRACE_IDNONE, _dtrace_defattr, 0,
2484 2524 &dt_idops_probe, NULL, dtp->dt_gen);
2485 2525
2486 2526 nargc = dt_decl_prototype(nargs, nargs,
2487 2527 "probe input", DT_DP_VOID | DT_DP_ANON);
2488 2528
2489 2529 xargc = dt_decl_prototype(xargs, nargs,
2490 2530 "probe output", DT_DP_VOID);
2491 2531
2492 2532 if (nargc > UINT8_MAX) {
2493 2533 xyerror(D_PROV_PRARGLEN, "probe %s input prototype exceeds %u "
2494 2534 "parameters: %d params used\n", name, UINT8_MAX, nargc);
2495 2535 }
2496 2536
2497 2537 if (xargc > UINT8_MAX) {
2498 2538 xyerror(D_PROV_PRARGLEN, "probe %s output prototype exceeds %u "
2499 2539 "parameters: %d params used\n", name, UINT8_MAX, xargc);
2500 2540 }
2501 2541
2502 2542 if (dnp->dn_ident == NULL || dt_probe_create(dtp,
2503 2543 dnp->dn_ident, protoc, nargs, nargc, xargs, xargc) == NULL)
2504 2544 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2505 2545
2506 2546 return (dnp);
2507 2547 }
2508 2548
2509 2549 dt_node_t *
2510 2550 dt_node_provider(char *name, dt_node_t *probes)
2511 2551 {
2512 2552 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2513 2553 dt_node_t *dnp = dt_node_alloc(DT_NODE_PROVIDER);
2514 2554 dt_node_t *lnp;
2515 2555 size_t len;
2516 2556
2517 2557 dnp->dn_provname = name;
2518 2558 dnp->dn_probes = probes;
2519 2559
2520 2560 if (strchr(name, '`') != NULL) {
2521 2561 dnerror(dnp, D_PROV_BADNAME, "provider name may not "
2522 2562 "contain scoping operator: %s\n", name);
2523 2563 }
2524 2564
2525 2565 if ((len = strlen(name)) >= DTRACE_PROVNAMELEN) {
2526 2566 dnerror(dnp, D_PROV_BADNAME, "provider name may not exceed %d "
2527 2567 "characters: %s\n", DTRACE_PROVNAMELEN - 1, name);
2528 2568 }
2529 2569
2530 2570 if (isdigit(name[len - 1])) {
2531 2571 dnerror(dnp, D_PROV_BADNAME, "provider name may not "
2532 2572 "end with a digit: %s\n", name);
2533 2573 }
2534 2574
2535 2575 /*
2536 2576 * Check to see if the provider is already defined or visible through
2537 2577 * dtrace(7D). If so, set dn_provred to treat it as a re-declaration.
2538 2578 * If not, create a new provider and set its interface-only flag. This
2539 2579 * flag may be cleared later by calls made to dt_probe_declare().
2540 2580 */
2541 2581 if ((dnp->dn_provider = dt_provider_lookup(dtp, name)) != NULL)
2542 2582 dnp->dn_provred = B_TRUE;
2543 2583 else if ((dnp->dn_provider = dt_provider_create(dtp, name)) == NULL)
2544 2584 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2545 2585 else
2546 2586 dnp->dn_provider->pv_flags |= DT_PROVIDER_INTF;
2547 2587
2548 2588 /*
2549 2589 * Store all parse nodes created since we consumed the DT_KEY_PROVIDER
2550 2590 * token with the provider and then restore our lexing state to CLAUSE.
2551 2591 * Note that if dnp->dn_provred is true, we may end up storing dups of
2552 2592 * a provider's interface and implementation: we eat this space because
2553 2593 * the implementation will likely need to redeclare probe members, and
2554 2594 * therefore may result in those member nodes becoming persistent.
2555 2595 */
2556 2596 for (lnp = yypcb->pcb_list; lnp->dn_link != NULL; lnp = lnp->dn_link)
2557 2597 continue; /* skip to end of allocation list */
2558 2598
2559 2599 lnp->dn_link = dnp->dn_provider->pv_nodes;
2560 2600 dnp->dn_provider->pv_nodes = yypcb->pcb_list;
2561 2601
2562 2602 yybegin(YYS_CLAUSE);
2563 2603 return (dnp);
2564 2604 }
2565 2605
2566 2606 dt_node_t *
2567 2607 dt_node_program(dt_node_t *lnp)
2568 2608 {
2569 2609 dt_node_t *dnp = dt_node_alloc(DT_NODE_PROG);
2570 2610 dnp->dn_list = lnp;
2571 2611 return (dnp);
2572 2612 }
2573 2613
2574 2614 /*
2575 2615 * This function provides the underlying implementation of cooking an
2576 2616 * identifier given its node, a hash of dynamic identifiers, an identifier
2577 2617 * kind, and a boolean flag indicating whether we are allowed to instantiate
2578 2618 * a new identifier if the string is not found. This function is either
2579 2619 * called from dt_cook_ident(), below, or directly by the various cooking
2580 2620 * routines that are allowed to instantiate identifiers (e.g. op2 TOK_ASGN).
2581 2621 */
2582 2622 static void
2583 2623 dt_xcook_ident(dt_node_t *dnp, dt_idhash_t *dhp, uint_t idkind, int create)
2584 2624 {
2585 2625 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2586 2626 const char *sname = dt_idhash_name(dhp);
2587 2627 int uref = 0;
2588 2628
2589 2629 dtrace_attribute_t attr = _dtrace_defattr;
2590 2630 dt_ident_t *idp;
2591 2631 dtrace_syminfo_t dts;
2592 2632 GElf_Sym sym;
2593 2633
2594 2634 const char *scope, *mark;
2595 2635 uchar_t dnkind;
2596 2636 char *name;
2597 2637
2598 2638 /*
2599 2639 * Look for scoping marks in the identifier. If one is found, set our
2600 2640 * scope to either DTRACE_OBJ_KMODS or UMODS or to the first part of
2601 2641 * the string that specifies the scope using an explicit module name.
2602 2642 * If two marks in a row are found, set 'uref' (user symbol reference).
2603 2643 * Otherwise we set scope to DTRACE_OBJ_EXEC, indicating that normal
2604 2644 * scope is desired and we should search the specified idhash.
2605 2645 */
2606 2646 if ((name = strrchr(dnp->dn_string, '`')) != NULL) {
2607 2647 if (name > dnp->dn_string && name[-1] == '`') {
2608 2648 uref++;
2609 2649 name[-1] = '\0';
2610 2650 }
2611 2651
2612 2652 if (name == dnp->dn_string + uref)
2613 2653 scope = uref ? DTRACE_OBJ_UMODS : DTRACE_OBJ_KMODS;
2614 2654 else
2615 2655 scope = dnp->dn_string;
2616 2656
2617 2657 *name++ = '\0'; /* leave name pointing after scoping mark */
2618 2658 dnkind = DT_NODE_VAR;
2619 2659
2620 2660 } else if (idkind == DT_IDENT_AGG) {
2621 2661 scope = DTRACE_OBJ_EXEC;
2622 2662 name = dnp->dn_string + 1;
2623 2663 dnkind = DT_NODE_AGG;
2624 2664 } else {
2625 2665 scope = DTRACE_OBJ_EXEC;
2626 2666 name = dnp->dn_string;
2627 2667 dnkind = DT_NODE_VAR;
2628 2668 }
2629 2669
2630 2670 /*
2631 2671 * If create is set to false, and we fail our idhash lookup, preset
2632 2672 * the errno code to EDT_NOVAR for our final error message below.
2633 2673 * If we end up calling dtrace_lookup_by_name(), it will reset the
2634 2674 * errno appropriately and that error will be reported instead.
2635 2675 */
2636 2676 (void) dt_set_errno(dtp, EDT_NOVAR);
2637 2677 mark = uref ? "``" : "`";
2638 2678
2639 2679 if (scope == DTRACE_OBJ_EXEC && (
2640 2680 (dhp != dtp->dt_globals &&
2641 2681 (idp = dt_idhash_lookup(dhp, name)) != NULL) ||
2642 2682 (dhp == dtp->dt_globals &&
2643 2683 (idp = dt_idstack_lookup(&yypcb->pcb_globals, name)) != NULL))) {
2644 2684 /*
2645 2685 * Check that we are referencing the ident in the manner that
2646 2686 * matches its type if this is a global lookup. In the TLS or
2647 2687 * local case, we don't know how the ident will be used until
2648 2688 * the time operator -> is seen; more parsing is needed.
2649 2689 */
2650 2690 if (idp->di_kind != idkind && dhp == dtp->dt_globals) {
2651 2691 xyerror(D_IDENT_BADREF, "%s '%s' may not be referenced "
2652 2692 "as %s\n", dt_idkind_name(idp->di_kind),
2653 2693 idp->di_name, dt_idkind_name(idkind));
2654 2694 }
2655 2695
↓ open down ↓ |
225 lines elided |
↑ open up ↑ |
2656 2696 /*
2657 2697 * Arrays and aggregations are not cooked individually. They
2658 2698 * have dynamic types and must be referenced using operator [].
2659 2699 * This is handled explicitly by the code for DT_TOK_LBRAC.
2660 2700 */
2661 2701 if (idp->di_kind != DT_IDENT_ARRAY &&
2662 2702 idp->di_kind != DT_IDENT_AGG)
2663 2703 attr = dt_ident_cook(dnp, idp, NULL);
2664 2704 else {
2665 2705 dt_node_type_assign(dnp,
2666 - DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
2706 + DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
2667 2707 attr = idp->di_attr;
2668 2708 }
2669 2709
2670 2710 free(dnp->dn_string);
2671 2711 dnp->dn_string = NULL;
2672 2712 dnp->dn_kind = dnkind;
2673 2713 dnp->dn_ident = idp;
2674 2714 dnp->dn_flags |= DT_NF_LVALUE;
2675 2715
2676 2716 if (idp->di_flags & DT_IDFLG_WRITE)
2677 2717 dnp->dn_flags |= DT_NF_WRITABLE;
2678 2718
2679 2719 dt_node_attr_assign(dnp, attr);
2680 2720
2681 2721 } else if (dhp == dtp->dt_globals && scope != DTRACE_OBJ_EXEC &&
2682 2722 dtrace_lookup_by_name(dtp, scope, name, &sym, &dts) == 0) {
2683 2723
2684 2724 dt_module_t *mp = dt_module_lookup_by_name(dtp, dts.dts_object);
2685 2725 int umod = (mp->dm_flags & DT_DM_KERNEL) == 0;
2686 2726 static const char *const kunames[] = { "kernel", "user" };
2687 2727
2688 2728 dtrace_typeinfo_t dtt;
2689 2729 dtrace_syminfo_t *sip;
2690 2730
2691 2731 if (uref ^ umod) {
2692 2732 xyerror(D_SYM_BADREF, "%s module '%s' symbol '%s' may "
2693 2733 "not be referenced as a %s symbol\n", kunames[umod],
2694 2734 dts.dts_object, dts.dts_name, kunames[uref]);
2695 2735 }
2696 2736
2697 2737 if (dtrace_symbol_type(dtp, &sym, &dts, &dtt) != 0) {
2698 2738 /*
2699 2739 * For now, we special-case EDT_DATAMODEL to clarify
2700 2740 * that mixed data models are not currently supported.
2701 2741 */
2702 2742 if (dtp->dt_errno == EDT_DATAMODEL) {
2703 2743 xyerror(D_SYM_MODEL, "cannot use %s symbol "
2704 2744 "%s%s%s in a %s D program\n",
2705 2745 dt_module_modelname(mp),
2706 2746 dts.dts_object, mark, dts.dts_name,
2707 2747 dt_module_modelname(dtp->dt_ddefs));
2708 2748 }
2709 2749
2710 2750 xyerror(D_SYM_NOTYPES,
2711 2751 "no symbolic type information is available for "
2712 2752 "%s%s%s: %s\n", dts.dts_object, mark, dts.dts_name,
2713 2753 dtrace_errmsg(dtp, dtrace_errno(dtp)));
2714 2754 }
2715 2755
2716 2756 idp = dt_ident_create(name, DT_IDENT_SYMBOL, 0, 0,
2717 2757 _dtrace_symattr, 0, &dt_idops_thaw, NULL, dtp->dt_gen);
2718 2758
2719 2759 if (idp == NULL)
2720 2760 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2721 2761
2722 2762 if (mp->dm_flags & DT_DM_PRIMARY)
2723 2763 idp->di_flags |= DT_IDFLG_PRIM;
2724 2764
2725 2765 idp->di_next = dtp->dt_externs;
2726 2766 dtp->dt_externs = idp;
2727 2767
2728 2768 if ((sip = malloc(sizeof (dtrace_syminfo_t))) == NULL)
2729 2769 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2730 2770
2731 2771 bcopy(&dts, sip, sizeof (dtrace_syminfo_t));
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
2732 2772 idp->di_data = sip;
2733 2773 idp->di_ctfp = dtt.dtt_ctfp;
2734 2774 idp->di_type = dtt.dtt_type;
2735 2775
2736 2776 free(dnp->dn_string);
2737 2777 dnp->dn_string = NULL;
2738 2778 dnp->dn_kind = DT_NODE_SYM;
2739 2779 dnp->dn_ident = idp;
2740 2780 dnp->dn_flags |= DT_NF_LVALUE;
2741 2781
2742 - dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2782 + dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2783 + dtt.dtt_flags);
2743 2784 dt_node_attr_assign(dnp, _dtrace_symattr);
2744 2785
2745 2786 if (uref) {
2746 2787 idp->di_flags |= DT_IDFLG_USER;
2747 2788 dnp->dn_flags |= DT_NF_USERLAND;
2748 2789 }
2749 2790
2750 2791 } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {
2751 2792 uint_t flags = DT_IDFLG_WRITE;
2752 2793 uint_t id;
2753 2794
2754 2795 if (dt_idhash_nextid(dhp, &id) == -1) {
2755 2796 xyerror(D_ID_OFLOW, "cannot create %s: limit on number "
2756 2797 "of %s variables exceeded\n", name, sname);
2757 2798 }
2758 2799
2759 2800 if (dhp == yypcb->pcb_locals)
2760 2801 flags |= DT_IDFLG_LOCAL;
2761 2802 else if (dhp == dtp->dt_tls)
2762 2803 flags |= DT_IDFLG_TLS;
2763 2804
2764 2805 dt_dprintf("create %s %s variable %s, id=%u\n",
2765 2806 sname, dt_idkind_name(idkind), name, id);
2766 2807
2767 2808 if (idkind == DT_IDENT_ARRAY || idkind == DT_IDENT_AGG) {
2768 2809 idp = dt_idhash_insert(dhp, name,
2769 2810 idkind, flags, id, _dtrace_defattr, 0,
2770 2811 &dt_idops_assc, NULL, dtp->dt_gen);
2771 2812 } else {
2772 2813 idp = dt_idhash_insert(dhp, name,
2773 2814 idkind, flags, id, _dtrace_defattr, 0,
2774 2815 &dt_idops_thaw, NULL, dtp->dt_gen);
2775 2816 }
2776 2817
2777 2818 if (idp == NULL)
2778 2819 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2779 2820
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
2780 2821 /*
2781 2822 * Arrays and aggregations are not cooked individually. They
2782 2823 * have dynamic types and must be referenced using operator [].
2783 2824 * This is handled explicitly by the code for DT_TOK_LBRAC.
2784 2825 */
2785 2826 if (idp->di_kind != DT_IDENT_ARRAY &&
2786 2827 idp->di_kind != DT_IDENT_AGG)
2787 2828 attr = dt_ident_cook(dnp, idp, NULL);
2788 2829 else {
2789 2830 dt_node_type_assign(dnp,
2790 - DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
2831 + DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
2791 2832 attr = idp->di_attr;
2792 2833 }
2793 2834
2794 2835 free(dnp->dn_string);
2795 2836 dnp->dn_string = NULL;
2796 2837 dnp->dn_kind = dnkind;
2797 2838 dnp->dn_ident = idp;
2798 2839 dnp->dn_flags |= DT_NF_LVALUE | DT_NF_WRITABLE;
2799 2840
2800 2841 dt_node_attr_assign(dnp, attr);
2801 2842
2802 2843 } else if (scope != DTRACE_OBJ_EXEC) {
2803 2844 xyerror(D_IDENT_UNDEF, "failed to resolve %s%s%s: %s\n",
2804 2845 dnp->dn_string, mark, name,
2805 2846 dtrace_errmsg(dtp, dtrace_errno(dtp)));
2806 2847 } else {
2807 2848 xyerror(D_IDENT_UNDEF, "failed to resolve %s: %s\n",
2808 2849 dnp->dn_string, dtrace_errmsg(dtp, dtrace_errno(dtp)));
2809 2850 }
2810 2851 }
2811 2852
2812 2853 static dt_node_t *
2813 2854 dt_cook_ident(dt_node_t *dnp, uint_t idflags)
2814 2855 {
2815 2856 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2816 2857
2817 2858 if (dnp->dn_op == DT_TOK_AGG)
2818 2859 dt_xcook_ident(dnp, dtp->dt_aggs, DT_IDENT_AGG, B_FALSE);
2819 2860 else
2820 2861 dt_xcook_ident(dnp, dtp->dt_globals, DT_IDENT_SCALAR, B_FALSE);
2821 2862
2822 2863 return (dt_node_cook(dnp, idflags));
2823 2864 }
2824 2865
2825 2866 /*
2826 2867 * Since operators [ and -> can instantiate new variables before we know
2827 2868 * whether the reference is for a read or a write, we need to check read
2828 2869 * references to determine if the identifier is currently dt_ident_unref().
2829 2870 * If so, we report that this first access was to an undefined variable.
2830 2871 */
2831 2872 static dt_node_t *
2832 2873 dt_cook_var(dt_node_t *dnp, uint_t idflags)
2833 2874 {
2834 2875 dt_ident_t *idp = dnp->dn_ident;
2835 2876
2836 2877 if ((idflags & DT_IDFLG_REF) && dt_ident_unref(idp)) {
2837 2878 dnerror(dnp, D_VAR_UNDEF,
2838 2879 "%s%s has not yet been declared or assigned\n",
2839 2880 (idp->di_flags & DT_IDFLG_LOCAL) ? "this->" :
2840 2881 (idp->di_flags & DT_IDFLG_TLS) ? "self->" : "",
2841 2882 idp->di_name);
2842 2883 }
2843 2884
2844 2885 dt_node_attr_assign(dnp, dt_ident_cook(dnp, idp, &dnp->dn_args));
2845 2886 return (dnp);
2846 2887 }
2847 2888
2848 2889 /*ARGSUSED*/
2849 2890 static dt_node_t *
2850 2891 dt_cook_func(dt_node_t *dnp, uint_t idflags)
2851 2892 {
2852 2893 dt_node_attr_assign(dnp,
2853 2894 dt_ident_cook(dnp, dnp->dn_ident, &dnp->dn_args));
2854 2895
2855 2896 return (dnp);
2856 2897 }
2857 2898
2858 2899 static dt_node_t *
2859 2900 dt_cook_op1(dt_node_t *dnp, uint_t idflags)
2860 2901 {
2861 2902 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2862 2903 dt_node_t *cp = dnp->dn_child;
2863 2904
2864 2905 char n[DT_TYPE_NAMELEN];
2865 2906 dtrace_typeinfo_t dtt;
2866 2907 dt_ident_t *idp;
2867 2908
2868 2909 ctf_encoding_t e;
2869 2910 ctf_arinfo_t r;
2870 2911 ctf_id_t type, base;
2871 2912 uint_t kind;
2872 2913
2873 2914 if (dnp->dn_op == DT_TOK_PREINC || dnp->dn_op == DT_TOK_POSTINC ||
2874 2915 dnp->dn_op == DT_TOK_PREDEC || dnp->dn_op == DT_TOK_POSTDEC)
2875 2916 idflags = DT_IDFLG_REF | DT_IDFLG_MOD;
2876 2917 else
2877 2918 idflags = DT_IDFLG_REF;
2878 2919
2879 2920 /*
2880 2921 * We allow the unary ++ and -- operators to instantiate new scalar
2881 2922 * variables if applied to an identifier; otherwise just cook as usual.
2882 2923 */
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
2883 2924 if (cp->dn_kind == DT_NODE_IDENT && (idflags & DT_IDFLG_MOD))
2884 2925 dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE);
2885 2926
2886 2927 cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2887 2928
2888 2929 if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2889 2930 if (dt_type_lookup("int64_t", &dtt) != 0)
2890 2931 xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2891 2932
2892 2933 dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2893 - dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type);
2934 + dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type,
2935 + dtt.dtt_flags);
2894 2936 }
2895 2937
2896 2938 if (cp->dn_kind == DT_NODE_VAR)
2897 2939 cp->dn_ident->di_flags |= idflags;
2898 2940
2899 2941 switch (dnp->dn_op) {
2900 2942 case DT_TOK_DEREF:
2901 2943 /*
2902 2944 * If the deref operator is applied to a translated pointer,
2903 2945 * we set our output type to the output of the translation.
2904 2946 */
2905 2947 if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) {
2906 2948 dt_xlator_t *dxp = idp->di_data;
2907 2949
2908 2950 dnp->dn_ident = &dxp->dx_souid;
2909 2951 dt_node_type_assign(dnp,
2910 - dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type);
2952 + dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type,
2953 + cp->dn_flags & DT_NF_USERLAND);
2911 2954 break;
2912 2955 }
2913 2956
2914 2957 type = ctf_type_resolve(cp->dn_ctfp, cp->dn_type);
2915 2958 kind = ctf_type_kind(cp->dn_ctfp, type);
2916 2959
2917 2960 if (kind == CTF_K_ARRAY) {
2918 2961 if (ctf_array_info(cp->dn_ctfp, type, &r) != 0) {
2919 2962 dtp->dt_ctferr = ctf_errno(cp->dn_ctfp);
2920 2963 longjmp(yypcb->pcb_jmpbuf, EDT_CTF);
2921 2964 } else
2922 2965 type = r.ctr_contents;
2923 2966 } else if (kind == CTF_K_POINTER) {
2924 2967 type = ctf_type_reference(cp->dn_ctfp, type);
2925 2968 } else {
2926 2969 xyerror(D_DEREF_NONPTR,
2927 2970 "cannot dereference non-pointer type\n");
2928 2971 }
2929 2972
2930 - dt_node_type_assign(dnp, cp->dn_ctfp, type);
2973 + dt_node_type_assign(dnp, cp->dn_ctfp, type,
2974 + cp->dn_flags & DT_NF_USERLAND);
2931 2975 base = ctf_type_resolve(cp->dn_ctfp, type);
2932 2976 kind = ctf_type_kind(cp->dn_ctfp, base);
2933 2977
2934 2978 if (kind == CTF_K_INTEGER && ctf_type_encoding(cp->dn_ctfp,
2935 2979 base, &e) == 0 && IS_VOID(e)) {
2936 2980 xyerror(D_DEREF_VOID,
2937 2981 "cannot dereference pointer to void\n");
2938 2982 }
2939 2983
2940 2984 if (kind == CTF_K_FUNCTION) {
2941 2985 xyerror(D_DEREF_FUNC,
2942 2986 "cannot dereference pointer to function\n");
2943 2987 }
2944 2988
2945 2989 if (kind != CTF_K_ARRAY || dt_node_is_string(dnp))
2946 2990 dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.4.3] */
2947 2991
2948 2992 /*
2949 2993 * If we propagated the l-value bit and the child operand was
2950 2994 * a writable D variable or a binary operation of the form
2951 2995 * a + b where a is writable, then propagate the writable bit.
2952 2996 * This is necessary to permit assignments to scalar arrays,
2953 2997 * which are converted to expressions of the form *(a + i).
2954 2998 */
2955 2999 if ((cp->dn_flags & DT_NF_WRITABLE) ||
2956 3000 (cp->dn_kind == DT_NODE_OP2 && cp->dn_op == DT_TOK_ADD &&
2957 3001 (cp->dn_left->dn_flags & DT_NF_WRITABLE)))
2958 3002 dnp->dn_flags |= DT_NF_WRITABLE;
2959 3003
2960 3004 if ((cp->dn_flags & DT_NF_USERLAND) &&
2961 3005 (kind == CTF_K_POINTER || (dnp->dn_flags & DT_NF_REF)))
2962 3006 dnp->dn_flags |= DT_NF_USERLAND;
2963 3007 break;
2964 3008
2965 3009 case DT_TOK_IPOS:
2966 3010 case DT_TOK_INEG:
2967 3011 if (!dt_node_is_arith(cp)) {
2968 3012 xyerror(D_OP_ARITH, "operator %s requires an operand "
2969 3013 "of arithmetic type\n", opstr(dnp->dn_op));
2970 3014 }
2971 3015 dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */
2972 3016 break;
2973 3017
2974 3018 case DT_TOK_BNEG:
2975 3019 if (!dt_node_is_integer(cp)) {
2976 3020 xyerror(D_OP_INT, "operator %s requires an operand of "
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
2977 3021 "integral type\n", opstr(dnp->dn_op));
2978 3022 }
2979 3023 dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */
2980 3024 break;
2981 3025
2982 3026 case DT_TOK_LNEG:
2983 3027 if (!dt_node_is_scalar(cp)) {
2984 3028 xyerror(D_OP_SCALAR, "operator %s requires an operand "
2985 3029 "of scalar type\n", opstr(dnp->dn_op));
2986 3030 }
2987 - dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
3031 + dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
3032 + B_FALSE);
2988 3033 break;
2989 3034
2990 3035 case DT_TOK_ADDROF:
2991 3036 if (cp->dn_kind == DT_NODE_VAR || cp->dn_kind == DT_NODE_AGG) {
2992 3037 xyerror(D_ADDROF_VAR,
2993 3038 "cannot take address of dynamic variable\n");
2994 3039 }
2995 3040
2996 3041 if (dt_node_is_dynamic(cp)) {
2997 3042 xyerror(D_ADDROF_VAR,
2998 3043 "cannot take address of dynamic object\n");
2999 3044 }
3000 3045
3001 3046 if (!(cp->dn_flags & DT_NF_LVALUE)) {
3002 3047 xyerror(D_ADDROF_LVAL, /* see K&R[A7.4.2] */
3003 3048 "unacceptable operand for unary & operator\n");
3004 3049 }
3005 3050
3006 3051 if (cp->dn_flags & DT_NF_BITFIELD) {
3007 3052 xyerror(D_ADDROF_BITFIELD,
3008 3053 "cannot take address of bit-field\n");
3009 3054 }
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
3010 3055
3011 3056 dtt.dtt_object = NULL;
3012 3057 dtt.dtt_ctfp = cp->dn_ctfp;
3013 3058 dtt.dtt_type = cp->dn_type;
3014 3059
3015 3060 if (dt_type_pointer(&dtt) == -1) {
3016 3061 xyerror(D_TYPE_ERR, "cannot find type for \"&\": %s*\n",
3017 3062 dt_node_type_name(cp, n, sizeof (n)));
3018 3063 }
3019 3064
3020 - dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
3021 -
3022 - if (cp->dn_flags & DT_NF_USERLAND)
3023 - dnp->dn_flags |= DT_NF_USERLAND;
3065 + dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
3066 + cp->dn_flags & DT_NF_USERLAND);
3024 3067 break;
3025 3068
3026 3069 case DT_TOK_SIZEOF:
3027 3070 if (cp->dn_flags & DT_NF_BITFIELD) {
3028 3071 xyerror(D_SIZEOF_BITFIELD,
3029 3072 "cannot apply sizeof to a bit-field\n");
3030 3073 }
3031 3074
3032 3075 if (dt_node_sizeof(cp) == 0) {
3033 3076 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
3034 3077 "operand of unknown size\n");
3035 3078 }
3036 3079
3037 3080 dt_node_type_assign(dnp, dtp->dt_ddefs->dm_ctfp,
3038 - ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
3081 + ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"),
3082 + B_FALSE);
3039 3083 break;
3040 3084
3041 3085 case DT_TOK_STRINGOF:
3042 3086 if (!dt_node_is_scalar(cp) && !dt_node_is_pointer(cp) &&
3043 3087 !dt_node_is_strcompat(cp)) {
3044 3088 xyerror(D_STRINGOF_TYPE,
3045 3089 "cannot apply stringof to a value of type %s\n",
3046 3090 dt_node_type_name(cp, n, sizeof (n)));
3047 3091 }
3048 - dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
3092 + dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp),
3093 + cp->dn_flags & DT_NF_USERLAND);
3049 3094 break;
3050 3095
3051 3096 case DT_TOK_PREINC:
3052 3097 case DT_TOK_POSTINC:
3053 3098 case DT_TOK_PREDEC:
3054 3099 case DT_TOK_POSTDEC:
3055 3100 if (dt_node_is_scalar(cp) == 0) {
3056 3101 xyerror(D_OP_SCALAR, "operator %s requires operand of "
3057 3102 "scalar type\n", opstr(dnp->dn_op));
3058 3103 }
3059 3104
3060 3105 if (dt_node_is_vfptr(cp)) {
3061 3106 xyerror(D_OP_VFPTR, "operator %s requires an operand "
3062 3107 "of known size\n", opstr(dnp->dn_op));
3063 3108 }
3064 3109
3065 3110 if (!(cp->dn_flags & DT_NF_LVALUE)) {
3066 3111 xyerror(D_OP_LVAL, "operator %s requires modifiable "
3067 3112 "lvalue as an operand\n", opstr(dnp->dn_op));
3068 3113 }
3069 3114
3070 3115 if (!(cp->dn_flags & DT_NF_WRITABLE)) {
3071 3116 xyerror(D_OP_WRITE, "operator %s can only be applied "
3072 3117 "to a writable variable\n", opstr(dnp->dn_op));
3073 3118 }
3074 3119
3075 3120 dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.1] */
3076 3121 break;
3077 3122
3078 3123 default:
3079 3124 xyerror(D_UNKNOWN, "invalid unary op %s\n", opstr(dnp->dn_op));
3080 3125 }
3081 3126
3082 3127 dt_node_attr_assign(dnp, cp->dn_attr);
3083 3128 return (dnp);
3084 3129 }
3085 3130
3086 3131 static void
3087 3132 dt_assign_common(dt_node_t *dnp)
3088 3133 {
3089 3134 dt_node_t *lp = dnp->dn_left;
3090 3135 dt_node_t *rp = dnp->dn_right;
3091 3136 int op = dnp->dn_op;
3092 3137
3093 3138 if (rp->dn_kind == DT_NODE_INT)
3094 3139 dt_cast(lp, rp);
3095 3140
3096 3141 if (!(lp->dn_flags & DT_NF_LVALUE)) {
3097 3142 xyerror(D_OP_LVAL, "operator %s requires modifiable "
3098 3143 "lvalue as an operand\n", opstr(op));
3099 3144 /* see K&R[A7.17] */
3100 3145 }
3101 3146
3102 3147 if (!(lp->dn_flags & DT_NF_WRITABLE)) {
3103 3148 xyerror(D_OP_WRITE, "operator %s can only be applied "
3104 3149 "to a writable variable\n", opstr(op));
3105 3150 }
3106 3151
3107 3152 dt_node_type_propagate(lp, dnp); /* see K&R[A7.17] */
3108 3153 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3109 3154 }
3110 3155
3111 3156 static dt_node_t *
3112 3157 dt_cook_op2(dt_node_t *dnp, uint_t idflags)
3113 3158 {
3114 3159 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
3115 3160 dt_node_t *lp = dnp->dn_left;
3116 3161 dt_node_t *rp = dnp->dn_right;
3117 3162 int op = dnp->dn_op;
3118 3163
3119 3164 ctf_membinfo_t m;
3120 3165 ctf_file_t *ctfp;
3121 3166 ctf_id_t type;
3122 3167 int kind, val, uref;
3123 3168 dt_ident_t *idp;
3124 3169
3125 3170 char n1[DT_TYPE_NAMELEN];
3126 3171 char n2[DT_TYPE_NAMELEN];
3127 3172
3128 3173 /*
3129 3174 * The expression E1[E2] is identical by definition to *((E1)+(E2)) so
3130 3175 * we convert "[" to "+" and glue on "*" at the end (see K&R[A7.3.1])
3131 3176 * unless the left-hand side is an untyped D scalar, associative array,
3132 3177 * or aggregation. In these cases, we proceed to case DT_TOK_LBRAC and
3133 3178 * handle associative array and aggregation references there.
3134 3179 */
3135 3180 if (op == DT_TOK_LBRAC) {
3136 3181 if (lp->dn_kind == DT_NODE_IDENT) {
3137 3182 dt_idhash_t *dhp;
3138 3183 uint_t idkind;
3139 3184
3140 3185 if (lp->dn_op == DT_TOK_AGG) {
3141 3186 dhp = dtp->dt_aggs;
3142 3187 idp = dt_idhash_lookup(dhp, lp->dn_string + 1);
3143 3188 idkind = DT_IDENT_AGG;
3144 3189 } else {
3145 3190 dhp = dtp->dt_globals;
3146 3191 idp = dt_idstack_lookup(
3147 3192 &yypcb->pcb_globals, lp->dn_string);
3148 3193 idkind = DT_IDENT_ARRAY;
3149 3194 }
3150 3195
3151 3196 if (idp == NULL || dt_ident_unref(idp))
3152 3197 dt_xcook_ident(lp, dhp, idkind, B_TRUE);
3153 3198 else
3154 3199 dt_xcook_ident(lp, dhp, idp->di_kind, B_FALSE);
3155 3200 } else
3156 3201 lp = dnp->dn_left = dt_node_cook(lp, 0);
3157 3202
3158 3203 /*
3159 3204 * Switch op to '+' for *(E1 + E2) array mode in these cases:
3160 3205 * (a) lp is a DT_IDENT_ARRAY variable that has already been
3161 3206 * referenced using [] notation (dn_args != NULL).
3162 3207 * (b) lp is a non-ARRAY variable that has already been given
3163 3208 * a type by assignment or declaration (!dt_ident_unref())
3164 3209 * (c) lp is neither a variable nor an aggregation
3165 3210 */
3166 3211 if (lp->dn_kind == DT_NODE_VAR) {
3167 3212 if (lp->dn_ident->di_kind == DT_IDENT_ARRAY) {
3168 3213 if (lp->dn_args != NULL)
3169 3214 op = DT_TOK_ADD;
3170 3215 } else if (!dt_ident_unref(lp->dn_ident))
3171 3216 op = DT_TOK_ADD;
3172 3217 } else if (lp->dn_kind != DT_NODE_AGG)
3173 3218 op = DT_TOK_ADD;
3174 3219 }
3175 3220
3176 3221 switch (op) {
3177 3222 case DT_TOK_BAND:
3178 3223 case DT_TOK_XOR:
3179 3224 case DT_TOK_BOR:
3180 3225 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3181 3226 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3182 3227
3183 3228 if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) {
3184 3229 xyerror(D_OP_INT, "operator %s requires operands of "
3185 3230 "integral type\n", opstr(op));
3186 3231 }
3187 3232
3188 3233 dt_node_promote(lp, rp, dnp); /* see K&R[A7.11-13] */
3189 3234 break;
3190 3235
3191 3236 case DT_TOK_LSH:
3192 3237 case DT_TOK_RSH:
3193 3238 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3194 3239 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3195 3240
3196 3241 if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) {
3197 3242 xyerror(D_OP_INT, "operator %s requires operands of "
3198 3243 "integral type\n", opstr(op));
3199 3244 }
3200 3245
3201 3246 dt_node_type_propagate(lp, dnp); /* see K&R[A7.8] */
3202 3247 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3203 3248 break;
3204 3249
3205 3250 case DT_TOK_MOD:
3206 3251 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3207 3252 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3208 3253
3209 3254 if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) {
3210 3255 xyerror(D_OP_INT, "operator %s requires operands of "
3211 3256 "integral type\n", opstr(op));
3212 3257 }
3213 3258
3214 3259 dt_node_promote(lp, rp, dnp); /* see K&R[A7.6] */
3215 3260 break;
3216 3261
3217 3262 case DT_TOK_MUL:
3218 3263 case DT_TOK_DIV:
3219 3264 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3220 3265 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3221 3266
3222 3267 if (!dt_node_is_arith(lp) || !dt_node_is_arith(rp)) {
3223 3268 xyerror(D_OP_ARITH, "operator %s requires operands of "
3224 3269 "arithmetic type\n", opstr(op));
3225 3270 }
3226 3271
3227 3272 dt_node_promote(lp, rp, dnp); /* see K&R[A7.6] */
3228 3273 break;
3229 3274
3230 3275 case DT_TOK_LAND:
↓ open down ↓ |
172 lines elided |
↑ open up ↑ |
3231 3276 case DT_TOK_LXOR:
3232 3277 case DT_TOK_LOR:
3233 3278 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3234 3279 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3235 3280
3236 3281 if (!dt_node_is_scalar(lp) || !dt_node_is_scalar(rp)) {
3237 3282 xyerror(D_OP_SCALAR, "operator %s requires operands "
3238 3283 "of scalar type\n", opstr(op));
3239 3284 }
3240 3285
3241 - dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
3286 + dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
3287 + B_FALSE);
3242 3288 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3243 3289 break;
3244 3290
3245 3291 case DT_TOK_LT:
3246 3292 case DT_TOK_LE:
3247 3293 case DT_TOK_GT:
3248 3294 case DT_TOK_GE:
3249 3295 case DT_TOK_EQU:
3250 3296 case DT_TOK_NEQ:
3251 3297 /*
3252 3298 * The D comparison operators provide the ability to transform
3253 3299 * a right-hand identifier into a corresponding enum tag value
3254 3300 * if the left-hand side is an enum type. To do this, we cook
3255 3301 * the left-hand side, and then see if the right-hand side is
3256 3302 * an unscoped identifier defined in the enum. If so, we
3257 3303 * convert into an integer constant node with the tag's value.
3258 3304 */
3259 3305 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3260 3306
3261 3307 kind = ctf_type_kind(lp->dn_ctfp,
3262 3308 ctf_type_resolve(lp->dn_ctfp, lp->dn_type));
3263 3309
3264 3310 if (kind == CTF_K_ENUM && rp->dn_kind == DT_NODE_IDENT &&
3265 3311 strchr(rp->dn_string, '`') == NULL && ctf_enum_value(
3266 3312 lp->dn_ctfp, lp->dn_type, rp->dn_string, &val) == 0) {
3267 3313
3268 3314 if ((idp = dt_idstack_lookup(&yypcb->pcb_globals,
3269 3315 rp->dn_string)) != NULL) {
3270 3316 xyerror(D_IDENT_AMBIG,
3271 3317 "ambiguous use of operator %s: %s is "
3272 3318 "both a %s enum tag and a global %s\n",
3273 3319 opstr(op), rp->dn_string,
3274 3320 dt_node_type_name(lp, n1, sizeof (n1)),
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
3275 3321 dt_idkind_name(idp->di_kind));
3276 3322 }
3277 3323
3278 3324 free(rp->dn_string);
3279 3325 rp->dn_string = NULL;
3280 3326 rp->dn_kind = DT_NODE_INT;
3281 3327 rp->dn_flags |= DT_NF_COOKED;
3282 3328 rp->dn_op = DT_TOK_INT;
3283 3329 rp->dn_value = (intmax_t)val;
3284 3330
3285 - dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type);
3331 + dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type,
3332 + B_FALSE);
3286 3333 dt_node_attr_assign(rp, _dtrace_symattr);
3287 3334 }
3288 3335
3289 3336 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3290 3337
3291 3338 /*
3292 3339 * The rules for type checking for the relational operators are
3293 3340 * described in the ANSI-C spec (see K&R[A7.9-10]). We perform
3294 3341 * the various tests in order from least to most expensive. We
3295 3342 * also allow derived strings to be compared as a first-class
3296 3343 * type (resulting in a strcmp(3C)-style comparison), and we
3297 3344 * slightly relax the A7.9 rules to permit void pointer
3298 3345 * comparisons as in A7.10. Our users won't be confused by
3299 3346 * this since they understand pointers are just numbers, and
3300 3347 * relaxing this constraint simplifies the implementation.
3301 3348 */
3302 3349 if (ctf_type_compat(lp->dn_ctfp, lp->dn_type,
3303 3350 rp->dn_ctfp, rp->dn_type))
3304 3351 /*EMPTY*/;
3305 3352 else if (dt_node_is_integer(lp) && dt_node_is_integer(rp))
3306 3353 /*EMPTY*/;
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
3307 3354 else if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp) &&
3308 3355 (dt_node_is_string(lp) || dt_node_is_string(rp)))
3309 3356 /*EMPTY*/;
3310 3357 else if (dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) {
3311 3358 xyerror(D_OP_INCOMPAT, "operands have "
3312 3359 "incompatible types: \"%s\" %s \"%s\"\n",
3313 3360 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3314 3361 dt_node_type_name(rp, n2, sizeof (n2)));
3315 3362 }
3316 3363
3317 - dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
3364 + dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
3365 + B_FALSE);
3318 3366 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3319 3367 break;
3320 3368
3321 3369 case DT_TOK_ADD:
3322 3370 case DT_TOK_SUB: {
3323 3371 /*
3324 3372 * The rules for type checking for the additive operators are
3325 3373 * described in the ANSI-C spec (see K&R[A7.7]). Pointers and
3326 3374 * integers may be manipulated according to specific rules. In
3327 3375 * these cases D permits strings to be treated as pointers.
3328 3376 */
3329 3377 int lp_is_ptr, lp_is_int, rp_is_ptr, rp_is_int;
3330 3378
3331 3379 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3332 3380 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3333 3381
3334 3382 lp_is_ptr = dt_node_is_string(lp) ||
3335 3383 (dt_node_is_pointer(lp) && !dt_node_is_vfptr(lp));
3336 3384 lp_is_int = dt_node_is_integer(lp);
3337 3385
3338 3386 rp_is_ptr = dt_node_is_string(rp) ||
3339 3387 (dt_node_is_pointer(rp) && !dt_node_is_vfptr(rp));
3340 3388 rp_is_int = dt_node_is_integer(rp);
3341 3389
3342 3390 if (lp_is_int && rp_is_int) {
3343 3391 dt_type_promote(lp, rp, &ctfp, &type);
3344 3392 uref = 0;
3345 3393 } else if (lp_is_ptr && rp_is_int) {
3346 3394 ctfp = lp->dn_ctfp;
3347 3395 type = lp->dn_type;
3348 3396 uref = lp->dn_flags & DT_NF_USERLAND;
3349 3397 } else if (lp_is_int && rp_is_ptr && op == DT_TOK_ADD) {
3350 3398 ctfp = rp->dn_ctfp;
3351 3399 type = rp->dn_type;
3352 3400 uref = rp->dn_flags & DT_NF_USERLAND;
3353 3401 } else if (lp_is_ptr && rp_is_ptr && op == DT_TOK_SUB &&
3354 3402 dt_node_is_ptrcompat(lp, rp, NULL, NULL)) {
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
3355 3403 ctfp = dtp->dt_ddefs->dm_ctfp;
3356 3404 type = ctf_lookup_by_name(ctfp, "ptrdiff_t");
3357 3405 uref = 0;
3358 3406 } else {
3359 3407 xyerror(D_OP_INCOMPAT, "operands have incompatible "
3360 3408 "types: \"%s\" %s \"%s\"\n",
3361 3409 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3362 3410 dt_node_type_name(rp, n2, sizeof (n2)));
3363 3411 }
3364 3412
3365 - dt_node_type_assign(dnp, ctfp, type);
3413 + dt_node_type_assign(dnp, ctfp, type, B_FALSE);
3366 3414 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3367 3415
3368 3416 if (uref)
3369 3417 dnp->dn_flags |= DT_NF_USERLAND;
3370 3418 break;
3371 3419 }
3372 3420
3373 3421 case DT_TOK_OR_EQ:
3374 3422 case DT_TOK_XOR_EQ:
3375 3423 case DT_TOK_AND_EQ:
3376 3424 case DT_TOK_LSH_EQ:
3377 3425 case DT_TOK_RSH_EQ:
3378 3426 case DT_TOK_MOD_EQ:
3379 3427 if (lp->dn_kind == DT_NODE_IDENT) {
3380 3428 dt_xcook_ident(lp, dtp->dt_globals,
3381 3429 DT_IDENT_SCALAR, B_TRUE);
3382 3430 }
3383 3431
3384 3432 lp = dnp->dn_left =
3385 3433 dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD);
3386 3434
3387 3435 rp = dnp->dn_right =
3388 3436 dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD);
3389 3437
3390 3438 if (!dt_node_is_integer(lp) || !dt_node_is_integer(rp)) {
3391 3439 xyerror(D_OP_INT, "operator %s requires operands of "
3392 3440 "integral type\n", opstr(op));
3393 3441 }
3394 3442 goto asgn_common;
3395 3443
3396 3444 case DT_TOK_MUL_EQ:
3397 3445 case DT_TOK_DIV_EQ:
3398 3446 if (lp->dn_kind == DT_NODE_IDENT) {
3399 3447 dt_xcook_ident(lp, dtp->dt_globals,
3400 3448 DT_IDENT_SCALAR, B_TRUE);
3401 3449 }
3402 3450
3403 3451 lp = dnp->dn_left =
3404 3452 dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD);
3405 3453
3406 3454 rp = dnp->dn_right =
3407 3455 dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD);
3408 3456
3409 3457 if (!dt_node_is_arith(lp) || !dt_node_is_arith(rp)) {
3410 3458 xyerror(D_OP_ARITH, "operator %s requires operands of "
3411 3459 "arithmetic type\n", opstr(op));
3412 3460 }
3413 3461 goto asgn_common;
3414 3462
3415 3463 case DT_TOK_ASGN:
3416 3464 /*
3417 3465 * If the left-hand side is an identifier, attempt to resolve
3418 3466 * it as either an aggregation or scalar variable. We pass
3419 3467 * B_TRUE to dt_xcook_ident to indicate that a new variable can
3420 3468 * be created if no matching variable exists in the namespace.
3421 3469 */
3422 3470 if (lp->dn_kind == DT_NODE_IDENT) {
3423 3471 if (lp->dn_op == DT_TOK_AGG) {
3424 3472 dt_xcook_ident(lp, dtp->dt_aggs,
3425 3473 DT_IDENT_AGG, B_TRUE);
3426 3474 } else {
3427 3475 dt_xcook_ident(lp, dtp->dt_globals,
3428 3476 DT_IDENT_SCALAR, B_TRUE);
3429 3477 }
3430 3478 }
3431 3479
3432 3480 lp = dnp->dn_left = dt_node_cook(lp, 0); /* don't set mod yet */
3433 3481 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3434 3482
3435 3483 /*
3436 3484 * If the left-hand side is an aggregation, verify that we are
3437 3485 * assigning it the result of an aggregating function. Once
3438 3486 * we've done so, hide the func node in the aggregation and
3439 3487 * return the aggregation itself up to the parse tree parent.
3440 3488 * This transformation is legal since the assigned function
3441 3489 * cannot change identity across disjoint cooking passes and
3442 3490 * the argument list subtree is retained for later cooking.
3443 3491 */
3444 3492 if (lp->dn_kind == DT_NODE_AGG) {
3445 3493 const char *aname = lp->dn_ident->di_name;
3446 3494 dt_ident_t *oid = lp->dn_ident->di_iarg;
3447 3495
3448 3496 if (rp->dn_kind != DT_NODE_FUNC ||
3449 3497 rp->dn_ident->di_kind != DT_IDENT_AGGFUNC) {
3450 3498 xyerror(D_AGG_FUNC,
3451 3499 "@%s must be assigned the result of "
3452 3500 "an aggregating function\n", aname);
3453 3501 }
3454 3502
3455 3503 if (oid != NULL && oid != rp->dn_ident) {
3456 3504 xyerror(D_AGG_REDEF,
3457 3505 "aggregation redefined: @%s\n\t "
3458 3506 "current: @%s = %s( )\n\tprevious: @%s = "
3459 3507 "%s( ) : line %d\n", aname, aname,
3460 3508 rp->dn_ident->di_name, aname, oid->di_name,
3461 3509 lp->dn_ident->di_lineno);
3462 3510 } else if (oid == NULL)
3463 3511 lp->dn_ident->di_iarg = rp->dn_ident;
3464 3512
3465 3513 /*
3466 3514 * Do not allow multiple aggregation assignments in a
3467 3515 * single statement, e.g. (@a = count()) = count();
3468 3516 * We produce a message as if the result of aggregating
3469 3517 * function does not propagate DT_NF_LVALUE.
3470 3518 */
3471 3519 if (lp->dn_aggfun != NULL) {
3472 3520 xyerror(D_OP_LVAL, "operator = requires "
3473 3521 "modifiable lvalue as an operand\n");
3474 3522 }
3475 3523
3476 3524 lp->dn_aggfun = rp;
3477 3525 lp = dt_node_cook(lp, DT_IDFLG_MOD);
3478 3526
3479 3527 dnp->dn_left = dnp->dn_right = NULL;
3480 3528 dt_node_free(dnp);
3481 3529
3482 3530 return (lp);
3483 3531 }
3484 3532
3485 3533 /*
3486 3534 * If the right-hand side is a dynamic variable that is the
3487 3535 * output of a translator, our result is the translated type.
3488 3536 */
3489 3537 if ((idp = dt_node_resolve(rp, DT_IDENT_XLSOU)) != NULL) {
3490 3538 ctfp = idp->di_ctfp;
3491 3539 type = idp->di_type;
3492 3540 uref = idp->di_flags & DT_IDFLG_USER;
3493 3541 } else {
3494 3542 ctfp = rp->dn_ctfp;
3495 3543 type = rp->dn_type;
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
3496 3544 uref = rp->dn_flags & DT_NF_USERLAND;
3497 3545 }
3498 3546
3499 3547 /*
3500 3548 * If the left-hand side of an assignment statement is a virgin
3501 3549 * variable created by this compilation pass, reset the type of
3502 3550 * this variable to the type of the right-hand side.
3503 3551 */
3504 3552 if (lp->dn_kind == DT_NODE_VAR &&
3505 3553 dt_ident_unref(lp->dn_ident)) {
3506 - dt_node_type_assign(lp, ctfp, type);
3554 + dt_node_type_assign(lp, ctfp, type, B_FALSE);
3507 3555 dt_ident_type_assign(lp->dn_ident, ctfp, type);
3508 3556
3509 3557 if (uref) {
3510 3558 lp->dn_flags |= DT_NF_USERLAND;
3511 3559 lp->dn_ident->di_flags |= DT_IDFLG_USER;
3512 3560 }
3513 3561 }
3514 3562
3515 3563 if (lp->dn_kind == DT_NODE_VAR)
3516 3564 lp->dn_ident->di_flags |= DT_IDFLG_MOD;
3517 3565
3518 3566 /*
3519 3567 * The rules for type checking for the assignment operators are
3520 3568 * described in the ANSI-C spec (see K&R[A7.17]). We share
3521 3569 * most of this code with the argument list checking code.
3522 3570 */
3523 3571 if (!dt_node_is_string(lp)) {
3524 3572 kind = ctf_type_kind(lp->dn_ctfp,
3525 3573 ctf_type_resolve(lp->dn_ctfp, lp->dn_type));
3526 3574
3527 3575 if (kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION) {
3528 3576 xyerror(D_OP_ARRFUN, "operator %s may not be "
3529 3577 "applied to operand of type \"%s\"\n",
3530 3578 opstr(op),
3531 3579 dt_node_type_name(lp, n1, sizeof (n1)));
3532 3580 }
3533 3581 }
3534 3582
3535 3583 if (idp != NULL && idp->di_kind == DT_IDENT_XLSOU &&
3536 3584 ctf_type_compat(lp->dn_ctfp, lp->dn_type, ctfp, type))
3537 3585 goto asgn_common;
3538 3586
3539 3587 if (dt_node_is_argcompat(lp, rp))
3540 3588 goto asgn_common;
3541 3589
3542 3590 xyerror(D_OP_INCOMPAT,
3543 3591 "operands have incompatible types: \"%s\" %s \"%s\"\n",
3544 3592 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3545 3593 dt_node_type_name(rp, n2, sizeof (n2)));
3546 3594 /*NOTREACHED*/
3547 3595
3548 3596 case DT_TOK_ADD_EQ:
3549 3597 case DT_TOK_SUB_EQ:
3550 3598 if (lp->dn_kind == DT_NODE_IDENT) {
3551 3599 dt_xcook_ident(lp, dtp->dt_globals,
3552 3600 DT_IDENT_SCALAR, B_TRUE);
3553 3601 }
3554 3602
3555 3603 lp = dnp->dn_left =
3556 3604 dt_node_cook(lp, DT_IDFLG_REF | DT_IDFLG_MOD);
3557 3605
3558 3606 rp = dnp->dn_right =
3559 3607 dt_node_cook(rp, DT_IDFLG_REF | DT_IDFLG_MOD);
3560 3608
3561 3609 if (dt_node_is_string(lp) || dt_node_is_string(rp)) {
3562 3610 xyerror(D_OP_INCOMPAT, "operands have "
3563 3611 "incompatible types: \"%s\" %s \"%s\"\n",
3564 3612 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3565 3613 dt_node_type_name(rp, n2, sizeof (n2)));
3566 3614 }
3567 3615
3568 3616 /*
3569 3617 * The rules for type checking for the assignment operators are
3570 3618 * described in the ANSI-C spec (see K&R[A7.17]). To these
3571 3619 * rules we add that only writable D nodes can be modified.
3572 3620 */
3573 3621 if (dt_node_is_integer(lp) == 0 ||
3574 3622 dt_node_is_integer(rp) == 0) {
3575 3623 if (!dt_node_is_pointer(lp) || dt_node_is_vfptr(lp)) {
3576 3624 xyerror(D_OP_VFPTR,
3577 3625 "operator %s requires left-hand scalar "
3578 3626 "operand of known size\n", opstr(op));
3579 3627 } else if (dt_node_is_integer(rp) == 0 &&
3580 3628 dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) {
3581 3629 xyerror(D_OP_INCOMPAT, "operands have "
3582 3630 "incompatible types: \"%s\" %s \"%s\"\n",
3583 3631 dt_node_type_name(lp, n1, sizeof (n1)),
3584 3632 opstr(op),
3585 3633 dt_node_type_name(rp, n2, sizeof (n2)));
3586 3634 }
3587 3635 }
3588 3636 asgn_common:
3589 3637 dt_assign_common(dnp);
3590 3638 break;
3591 3639
3592 3640 case DT_TOK_PTR:
3593 3641 /*
3594 3642 * If the left-hand side of operator -> is the name "self",
3595 3643 * then we permit a TLS variable to be created or referenced.
3596 3644 */
3597 3645 if (lp->dn_kind == DT_NODE_IDENT &&
3598 3646 strcmp(lp->dn_string, "self") == 0) {
3599 3647 if (rp->dn_kind != DT_NODE_VAR) {
3600 3648 dt_xcook_ident(rp, dtp->dt_tls,
3601 3649 DT_IDENT_SCALAR, B_TRUE);
3602 3650 }
3603 3651
3604 3652 if (idflags != 0)
3605 3653 rp = dt_node_cook(rp, idflags);
3606 3654
3607 3655 dnp->dn_right = dnp->dn_left; /* avoid freeing rp */
3608 3656 dt_node_free(dnp);
3609 3657 return (rp);
3610 3658 }
3611 3659
3612 3660 /*
3613 3661 * If the left-hand side of operator -> is the name "this",
3614 3662 * then we permit a local variable to be created or referenced.
3615 3663 */
3616 3664 if (lp->dn_kind == DT_NODE_IDENT &&
3617 3665 strcmp(lp->dn_string, "this") == 0) {
3618 3666 if (rp->dn_kind != DT_NODE_VAR) {
3619 3667 dt_xcook_ident(rp, yypcb->pcb_locals,
3620 3668 DT_IDENT_SCALAR, B_TRUE);
3621 3669 }
3622 3670
3623 3671 if (idflags != 0)
3624 3672 rp = dt_node_cook(rp, idflags);
3625 3673
3626 3674 dnp->dn_right = dnp->dn_left; /* avoid freeing rp */
3627 3675 dt_node_free(dnp);
3628 3676 return (rp);
3629 3677 }
3630 3678
3631 3679 /*FALLTHRU*/
3632 3680
3633 3681 case DT_TOK_DOT:
3634 3682 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3635 3683
3636 3684 if (rp->dn_kind != DT_NODE_IDENT) {
3637 3685 xyerror(D_OP_IDENT, "operator %s must be followed by "
3638 3686 "an identifier\n", opstr(op));
3639 3687 }
3640 3688
3641 3689 if ((idp = dt_node_resolve(lp, DT_IDENT_XLSOU)) != NULL ||
3642 3690 (idp = dt_node_resolve(lp, DT_IDENT_XLPTR)) != NULL) {
3643 3691 /*
3644 3692 * If the left-hand side is a translated struct or ptr,
3645 3693 * the type of the left is the translation output type.
3646 3694 */
3647 3695 dt_xlator_t *dxp = idp->di_data;
3648 3696
3649 3697 if (dt_xlator_member(dxp, rp->dn_string) == NULL) {
3650 3698 xyerror(D_XLATE_NOCONV,
3651 3699 "translator does not define conversion "
3652 3700 "for member: %s\n", rp->dn_string);
3653 3701 }
3654 3702
3655 3703 ctfp = idp->di_ctfp;
3656 3704 type = ctf_type_resolve(ctfp, idp->di_type);
3657 3705 uref = idp->di_flags & DT_IDFLG_USER;
3658 3706 } else {
3659 3707 ctfp = lp->dn_ctfp;
3660 3708 type = ctf_type_resolve(ctfp, lp->dn_type);
3661 3709 uref = lp->dn_flags & DT_NF_USERLAND;
3662 3710 }
3663 3711
3664 3712 kind = ctf_type_kind(ctfp, type);
3665 3713
3666 3714 if (op == DT_TOK_PTR) {
3667 3715 if (kind != CTF_K_POINTER) {
3668 3716 xyerror(D_OP_PTR, "operator %s must be "
3669 3717 "applied to a pointer\n", opstr(op));
3670 3718 }
3671 3719 type = ctf_type_reference(ctfp, type);
3672 3720 type = ctf_type_resolve(ctfp, type);
3673 3721 kind = ctf_type_kind(ctfp, type);
3674 3722 }
3675 3723
3676 3724 /*
3677 3725 * If we follow a reference to a forward declaration tag,
3678 3726 * search the entire type space for the actual definition.
3679 3727 */
3680 3728 while (kind == CTF_K_FORWARD) {
3681 3729 char *tag = ctf_type_name(ctfp, type, n1, sizeof (n1));
3682 3730 dtrace_typeinfo_t dtt;
3683 3731
3684 3732 if (tag != NULL && dt_type_lookup(tag, &dtt) == 0 &&
3685 3733 (dtt.dtt_ctfp != ctfp || dtt.dtt_type != type)) {
3686 3734 ctfp = dtt.dtt_ctfp;
3687 3735 type = ctf_type_resolve(ctfp, dtt.dtt_type);
3688 3736 kind = ctf_type_kind(ctfp, type);
3689 3737 } else {
3690 3738 xyerror(D_OP_INCOMPLETE,
3691 3739 "operator %s cannot be applied to a "
3692 3740 "forward declaration: no %s definition "
3693 3741 "is available\n", opstr(op), tag);
3694 3742 }
3695 3743 }
3696 3744
3697 3745 if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
3698 3746 if (op == DT_TOK_PTR) {
3699 3747 xyerror(D_OP_SOU, "operator -> cannot be "
3700 3748 "applied to pointer to type \"%s\"; must "
3701 3749 "be applied to a struct or union pointer\n",
3702 3750 ctf_type_name(ctfp, type, n1, sizeof (n1)));
3703 3751 } else {
3704 3752 xyerror(D_OP_SOU, "operator %s cannot be "
3705 3753 "applied to type \"%s\"; must be applied "
3706 3754 "to a struct or union\n", opstr(op),
3707 3755 ctf_type_name(ctfp, type, n1, sizeof (n1)));
3708 3756 }
3709 3757 }
↓ open down ↓ |
193 lines elided |
↑ open up ↑ |
3710 3758
3711 3759 if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) {
3712 3760 xyerror(D_TYPE_MEMBER,
3713 3761 "%s is not a member of %s\n", rp->dn_string,
3714 3762 ctf_type_name(ctfp, type, n1, sizeof (n1)));
3715 3763 }
3716 3764
3717 3765 type = ctf_type_resolve(ctfp, m.ctm_type);
3718 3766 kind = ctf_type_kind(ctfp, type);
3719 3767
3720 - dt_node_type_assign(dnp, ctfp, m.ctm_type);
3768 + dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE);
3721 3769 dt_node_attr_assign(dnp, lp->dn_attr);
3722 3770
3723 3771 if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3724 3772 dt_node_is_string(dnp)))
3725 3773 dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3726 3774
3727 3775 if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3728 3776 (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))
3729 3777 dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3730 3778
3731 3779 if (lp->dn_flags & DT_NF_WRITABLE)
3732 3780 dnp->dn_flags |= DT_NF_WRITABLE;
3733 3781
3734 3782 if (uref && (kind == CTF_K_POINTER ||
3735 3783 (dnp->dn_flags & DT_NF_REF)))
3736 3784 dnp->dn_flags |= DT_NF_USERLAND;
3737 3785 break;
3738 3786
3739 3787 case DT_TOK_LBRAC: {
3740 3788 /*
3741 3789 * If op is DT_TOK_LBRAC, we know from the special-case code at
3742 3790 * the top that lp is either a D variable or an aggregation.
3743 3791 */
3744 3792 dt_node_t *lnp;
3745 3793
3746 3794 /*
3747 3795 * If the left-hand side is an aggregation, just set dn_aggtup
3748 3796 * to the right-hand side and return the cooked aggregation.
3749 3797 * This transformation is legal since we are just collapsing
3750 3798 * nodes to simplify later processing, and the entire aggtup
3751 3799 * parse subtree is retained for subsequent cooking passes.
3752 3800 */
3753 3801 if (lp->dn_kind == DT_NODE_AGG) {
3754 3802 if (lp->dn_aggtup != NULL) {
3755 3803 xyerror(D_AGG_MDIM, "improper attempt to "
3756 3804 "reference @%s as a multi-dimensional "
3757 3805 "array\n", lp->dn_ident->di_name);
3758 3806 }
3759 3807
3760 3808 lp->dn_aggtup = rp;
3761 3809 lp = dt_node_cook(lp, 0);
3762 3810
3763 3811 dnp->dn_left = dnp->dn_right = NULL;
3764 3812 dt_node_free(dnp);
3765 3813
3766 3814 return (lp);
3767 3815 }
3768 3816
3769 3817 assert(lp->dn_kind == DT_NODE_VAR);
3770 3818 idp = lp->dn_ident;
3771 3819
3772 3820 /*
3773 3821 * If the left-hand side is a non-global scalar that hasn't yet
3774 3822 * been referenced or modified, it was just created by self->
3775 3823 * or this-> and we can convert it from scalar to assoc array.
3776 3824 */
3777 3825 if (idp->di_kind == DT_IDENT_SCALAR && dt_ident_unref(idp) &&
3778 3826 (idp->di_flags & (DT_IDFLG_LOCAL | DT_IDFLG_TLS)) != 0) {
3779 3827
3780 3828 if (idp->di_flags & DT_IDFLG_LOCAL) {
3781 3829 xyerror(D_ARR_LOCAL,
3782 3830 "local variables may not be used as "
3783 3831 "associative arrays: %s\n", idp->di_name);
3784 3832 }
3785 3833
3786 3834 dt_dprintf("morph variable %s (id %u) from scalar to "
3787 3835 "array\n", idp->di_name, idp->di_id);
3788 3836
3789 3837 dt_ident_morph(idp, DT_IDENT_ARRAY,
3790 3838 &dt_idops_assc, NULL);
3791 3839 }
3792 3840
3793 3841 if (idp->di_kind != DT_IDENT_ARRAY) {
3794 3842 xyerror(D_IDENT_BADREF, "%s '%s' may not be referenced "
3795 3843 "as %s\n", dt_idkind_name(idp->di_kind),
3796 3844 idp->di_name, dt_idkind_name(DT_IDENT_ARRAY));
3797 3845 }
3798 3846
3799 3847 /*
3800 3848 * Now that we've confirmed our left-hand side is a DT_NODE_VAR
3801 3849 * of idkind DT_IDENT_ARRAY, we need to splice the [ node from
3802 3850 * the parse tree and leave a cooked DT_NODE_VAR in its place
3803 3851 * where dn_args for the VAR node is the right-hand 'rp' tree,
3804 3852 * as shown in the parse tree diagram below:
3805 3853 *
3806 3854 * / /
3807 3855 * [ OP2 "[" ]=dnp [ VAR ]=dnp
3808 3856 * / \ => |
3809 3857 * / \ +- dn_args -> [ ??? ]=rp
3810 3858 * [ VAR ]=lp [ ??? ]=rp
3811 3859 *
3812 3860 * Since the final dt_node_cook(dnp) can fail using longjmp we
3813 3861 * must perform the transformations as a group first by over-
3814 3862 * writing 'dnp' to become the VAR node, so that the parse tree
3815 3863 * is guaranteed to be in a consistent state if the cook fails.
3816 3864 */
3817 3865 assert(lp->dn_kind == DT_NODE_VAR);
3818 3866 assert(lp->dn_args == NULL);
3819 3867
3820 3868 lnp = dnp->dn_link;
3821 3869 bcopy(lp, dnp, sizeof (dt_node_t));
3822 3870 dnp->dn_link = lnp;
3823 3871
3824 3872 dnp->dn_args = rp;
3825 3873 dnp->dn_list = NULL;
3826 3874
3827 3875 dt_node_free(lp);
3828 3876 return (dt_node_cook(dnp, idflags));
3829 3877 }
3830 3878
3831 3879 case DT_TOK_XLATE: {
3832 3880 dt_xlator_t *dxp;
3833 3881
3834 3882 assert(lp->dn_kind == DT_NODE_TYPE);
3835 3883 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
↓ open down ↓ |
105 lines elided |
↑ open up ↑ |
3836 3884 dxp = dt_xlator_lookup(dtp, rp, lp, DT_XLATE_FUZZY);
3837 3885
3838 3886 if (dxp == NULL) {
3839 3887 xyerror(D_XLATE_NONE,
3840 3888 "cannot translate from \"%s\" to \"%s\"\n",
3841 3889 dt_node_type_name(rp, n1, sizeof (n1)),
3842 3890 dt_node_type_name(lp, n2, sizeof (n2)));
3843 3891 }
3844 3892
3845 3893 dnp->dn_ident = dt_xlator_ident(dxp, lp->dn_ctfp, lp->dn_type);
3846 - dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
3894 + dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp),
3895 + B_FALSE);
3847 3896 dt_node_attr_assign(dnp,
3848 3897 dt_attr_min(rp->dn_attr, dnp->dn_ident->di_attr));
3849 3898 break;
3850 3899 }
3851 3900
3852 3901 case DT_TOK_LPAR: {
3853 3902 ctf_id_t ltype, rtype;
3854 3903 uint_t lkind, rkind;
3855 3904
3856 3905 assert(lp->dn_kind == DT_NODE_TYPE);
3857 3906 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3858 3907
3859 3908 ltype = ctf_type_resolve(lp->dn_ctfp, lp->dn_type);
3860 3909 lkind = ctf_type_kind(lp->dn_ctfp, ltype);
3861 3910
3862 3911 rtype = ctf_type_resolve(rp->dn_ctfp, rp->dn_type);
3863 3912 rkind = ctf_type_kind(rp->dn_ctfp, rtype);
3864 3913
3865 3914 /*
3866 3915 * The rules for casting are loosely explained in K&R[A7.5]
3867 3916 * and K&R[A6]. Basically, we can cast to the same type or
3868 3917 * same base type, between any kind of scalar values, from
3869 3918 * arrays to pointers, and we can cast anything to void.
3870 3919 * To these rules D adds casts from scalars to strings.
3871 3920 */
3872 3921 if (ctf_type_compat(lp->dn_ctfp, lp->dn_type,
3873 3922 rp->dn_ctfp, rp->dn_type))
3874 3923 /*EMPTY*/;
3875 3924 else if (dt_node_is_scalar(lp) &&
3876 3925 (dt_node_is_scalar(rp) || rkind == CTF_K_FUNCTION))
3877 3926 /*EMPTY*/;
3878 3927 else if (dt_node_is_void(lp))
3879 3928 /*EMPTY*/;
3880 3929 else if (lkind == CTF_K_POINTER && dt_node_is_pointer(rp))
3881 3930 /*EMPTY*/;
3882 3931 else if (dt_node_is_string(lp) && (dt_node_is_scalar(rp) ||
3883 3932 dt_node_is_pointer(rp) || dt_node_is_strcompat(rp)))
3884 3933 /*EMPTY*/;
3885 3934 else {
3886 3935 xyerror(D_CAST_INVAL,
3887 3936 "invalid cast expression: \"%s\" to \"%s\"\n",
3888 3937 dt_node_type_name(rp, n1, sizeof (n1)),
3889 3938 dt_node_type_name(lp, n2, sizeof (n2)));
3890 3939 }
3891 3940
3892 3941 dt_node_type_propagate(lp, dnp); /* see K&R[A7.5] */
3893 3942 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3894 3943
3895 3944 /*
3896 3945 * If it's a pointer then should be able to (attempt to)
3897 3946 * assign to it.
3898 3947 */
3899 3948 if (lkind == CTF_K_POINTER)
3900 3949 dnp->dn_flags |= DT_NF_WRITABLE;
3901 3950
3902 3951 break;
3903 3952 }
3904 3953
3905 3954 case DT_TOK_COMMA:
3906 3955 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3907 3956 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3908 3957
3909 3958 if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp)) {
3910 3959 xyerror(D_OP_DYN, "operator %s operands "
3911 3960 "cannot be of dynamic type\n", opstr(op));
3912 3961 }
3913 3962
3914 3963 if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) {
3915 3964 xyerror(D_OP_ACT, "operator %s operands "
3916 3965 "cannot be actions\n", opstr(op));
3917 3966 }
3918 3967
3919 3968 dt_node_type_propagate(rp, dnp); /* see K&R[A7.18] */
3920 3969 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3921 3970 break;
3922 3971
3923 3972 default:
3924 3973 xyerror(D_UNKNOWN, "invalid binary op %s\n", opstr(op));
3925 3974 }
3926 3975
3927 3976 /*
3928 3977 * Complete the conversion of E1[E2] to *((E1)+(E2)) that we started
3929 3978 * at the top of our switch() above (see K&R[A7.3.1]). Since E2 is
3930 3979 * parsed as an argument_expression_list by dt_grammar.y, we can
3931 3980 * end up with a comma-separated list inside of a non-associative
3932 3981 * array reference. We check for this and report an appropriate error.
3933 3982 */
3934 3983 if (dnp->dn_op == DT_TOK_LBRAC && op == DT_TOK_ADD) {
3935 3984 dt_node_t *pnp;
3936 3985
3937 3986 if (rp->dn_list != NULL) {
3938 3987 xyerror(D_ARR_BADREF,
3939 3988 "cannot access %s as an associative array\n",
3940 3989 dt_node_name(lp, n1, sizeof (n1)));
3941 3990 }
3942 3991
3943 3992 dnp->dn_op = DT_TOK_ADD;
3944 3993 pnp = dt_node_op1(DT_TOK_DEREF, dnp);
3945 3994
3946 3995 /*
3947 3996 * Cook callbacks are not typically permitted to allocate nodes.
3948 3997 * When we do, we must insert them in the middle of an existing
3949 3998 * allocation list rather than having them appended to the pcb
3950 3999 * list because the sub-expression may be part of a definition.
3951 4000 */
3952 4001 assert(yypcb->pcb_list == pnp);
3953 4002 yypcb->pcb_list = pnp->dn_link;
3954 4003
3955 4004 pnp->dn_link = dnp->dn_link;
3956 4005 dnp->dn_link = pnp;
3957 4006
3958 4007 return (dt_node_cook(pnp, DT_IDFLG_REF));
3959 4008 }
3960 4009
3961 4010 return (dnp);
3962 4011 }
3963 4012
3964 4013 /*ARGSUSED*/
3965 4014 static dt_node_t *
3966 4015 dt_cook_op3(dt_node_t *dnp, uint_t idflags)
3967 4016 {
3968 4017 dt_node_t *lp, *rp;
3969 4018 ctf_file_t *ctfp;
3970 4019 ctf_id_t type;
3971 4020
3972 4021 dnp->dn_expr = dt_node_cook(dnp->dn_expr, DT_IDFLG_REF);
3973 4022 lp = dnp->dn_left = dt_node_cook(dnp->dn_left, DT_IDFLG_REF);
3974 4023 rp = dnp->dn_right = dt_node_cook(dnp->dn_right, DT_IDFLG_REF);
3975 4024
3976 4025 if (!dt_node_is_scalar(dnp->dn_expr)) {
3977 4026 xyerror(D_OP_SCALAR,
3978 4027 "operator ?: expression must be of scalar type\n");
3979 4028 }
3980 4029
3981 4030 if (dt_node_is_dynamic(lp) || dt_node_is_dynamic(rp)) {
3982 4031 xyerror(D_OP_DYN,
3983 4032 "operator ?: operands cannot be of dynamic type\n");
3984 4033 }
3985 4034
3986 4035 /*
3987 4036 * The rules for type checking for the ternary operator are complex and
3988 4037 * are described in the ANSI-C spec (see K&R[A7.16]). We implement
3989 4038 * the various tests in order from least to most expensive.
3990 4039 */
3991 4040 if (ctf_type_compat(lp->dn_ctfp, lp->dn_type,
3992 4041 rp->dn_ctfp, rp->dn_type)) {
3993 4042 ctfp = lp->dn_ctfp;
3994 4043 type = lp->dn_type;
3995 4044 } else if (dt_node_is_integer(lp) && dt_node_is_integer(rp)) {
3996 4045 dt_type_promote(lp, rp, &ctfp, &type);
3997 4046 } else if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp) &&
3998 4047 (dt_node_is_string(lp) || dt_node_is_string(rp))) {
3999 4048 ctfp = DT_STR_CTFP(yypcb->pcb_hdl);
4000 4049 type = DT_STR_TYPE(yypcb->pcb_hdl);
↓ open down ↓ |
144 lines elided |
↑ open up ↑ |
4001 4050 } else if (dt_node_is_ptrcompat(lp, rp, &ctfp, &type) == 0) {
4002 4051 xyerror(D_OP_INCOMPAT,
4003 4052 "operator ?: operands must have compatible types\n");
4004 4053 }
4005 4054
4006 4055 if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) {
4007 4056 xyerror(D_OP_ACT, "action cannot be "
4008 4057 "used in a conditional context\n");
4009 4058 }
4010 4059
4011 - dt_node_type_assign(dnp, ctfp, type);
4060 + dt_node_type_assign(dnp, ctfp, type, B_FALSE);
4012 4061 dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_expr->dn_attr,
4013 4062 dt_attr_min(lp->dn_attr, rp->dn_attr)));
4014 4063
4015 4064 return (dnp);
4016 4065 }
4017 4066
4018 4067 static dt_node_t *
4019 4068 dt_cook_statement(dt_node_t *dnp, uint_t idflags)
4020 4069 {
4021 4070 dnp->dn_expr = dt_node_cook(dnp->dn_expr, idflags);
4022 4071 dt_node_attr_assign(dnp, dnp->dn_expr->dn_attr);
4023 4072
4024 4073 return (dnp);
4025 4074 }
4026 4075
4027 4076 /*
4028 4077 * If dn_aggfun is set, this node is a collapsed aggregation assignment (see
4029 4078 * the special case code for DT_TOK_ASGN in dt_cook_op2() above), in which
4030 4079 * case we cook both the tuple and the function call. If dn_aggfun is NULL,
4031 4080 * this node is just a reference to the aggregation's type and attributes.
4032 4081 */
4033 4082 /*ARGSUSED*/
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
4034 4083 static dt_node_t *
4035 4084 dt_cook_aggregation(dt_node_t *dnp, uint_t idflags)
4036 4085 {
4037 4086 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4038 4087
4039 4088 if (dnp->dn_aggfun != NULL) {
4040 4089 dnp->dn_aggfun = dt_node_cook(dnp->dn_aggfun, DT_IDFLG_REF);
4041 4090 dt_node_attr_assign(dnp, dt_ident_cook(dnp,
4042 4091 dnp->dn_ident, &dnp->dn_aggtup));
4043 4092 } else {
4044 - dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
4093 + dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp),
4094 + B_FALSE);
4045 4095 dt_node_attr_assign(dnp, dnp->dn_ident->di_attr);
4046 4096 }
4047 4097
4048 4098 return (dnp);
4049 4099 }
4050 4100
4051 4101 /*
4052 4102 * Since D permits new variable identifiers to be instantiated in any program
4053 4103 * expression, we may need to cook a clause's predicate either before or after
4054 4104 * the action list depending on the program code in question. Consider:
4055 4105 *
4056 4106 * probe-description-list probe-description-list
4057 4107 * /x++/ /x == 0/
4058 4108 * { {
4059 4109 * trace(x); trace(x++);
4060 4110 * } }
4061 4111 *
4062 4112 * In the left-hand example, the predicate uses operator ++ to instantiate 'x'
4063 4113 * as a variable of type int64_t. The predicate must be cooked first because
4064 4114 * otherwise the statement trace(x) refers to an unknown identifier. In the
4065 4115 * right-hand example, the action list uses ++ to instantiate 'x'; the action
4066 4116 * list must be cooked first because otherwise the predicate x == 0 refers to
4067 4117 * an unknown identifier. In order to simplify programming, we support both.
4068 4118 *
4069 4119 * When cooking a clause, we cook the action statements before the predicate by
4070 4120 * default, since it seems more common to create or modify identifiers in the
4071 4121 * action list. If cooking fails due to an unknown identifier, we attempt to
4072 4122 * cook the predicate (i.e. do it first) and then go back and cook the actions.
4073 4123 * If this, too, fails (or if we get an error other than D_IDENT_UNDEF) we give
4074 4124 * up and report failure back to the user. There are five possible paths:
4075 4125 *
4076 4126 * cook actions = OK, cook predicate = OK -> OK
4077 4127 * cook actions = OK, cook predicate = ERR -> ERR
4078 4128 * cook actions = ERR, cook predicate = ERR -> ERR
4079 4129 * cook actions = ERR, cook predicate = OK, cook actions = OK -> OK
4080 4130 * cook actions = ERR, cook predicate = OK, cook actions = ERR -> ERR
4081 4131 *
4082 4132 * The programmer can still defeat our scheme by creating circular definition
4083 4133 * dependencies between predicates and actions, as in this example clause:
4084 4134 *
4085 4135 * probe-description-list
4086 4136 * /x++ && y == 0/
4087 4137 * {
4088 4138 * trace(x + y++);
4089 4139 * }
4090 4140 *
4091 4141 * but it doesn't seem worth the complexity to handle such rare cases. The
4092 4142 * user can simply use the D variable declaration syntax to work around them.
4093 4143 */
4094 4144 static dt_node_t *
4095 4145 dt_cook_clause(dt_node_t *dnp, uint_t idflags)
4096 4146 {
4097 4147 volatile int err, tries;
4098 4148 jmp_buf ojb;
4099 4149
4100 4150 /*
4101 4151 * Before assigning dn_ctxattr, temporarily assign the probe attribute
4102 4152 * to 'dnp' itself to force an attribute check and minimum violation.
4103 4153 */
4104 4154 dt_node_attr_assign(dnp, yypcb->pcb_pinfo.dtp_attr);
4105 4155 dnp->dn_ctxattr = yypcb->pcb_pinfo.dtp_attr;
4106 4156
4107 4157 bcopy(yypcb->pcb_jmpbuf, ojb, sizeof (jmp_buf));
4108 4158 tries = 0;
4109 4159
4110 4160 if (dnp->dn_pred != NULL && (err = setjmp(yypcb->pcb_jmpbuf)) != 0) {
4111 4161 bcopy(ojb, yypcb->pcb_jmpbuf, sizeof (jmp_buf));
4112 4162 if (tries++ != 0 || err != EDT_COMPILER || (
4113 4163 yypcb->pcb_hdl->dt_errtag != dt_errtag(D_IDENT_UNDEF) &&
4114 4164 yypcb->pcb_hdl->dt_errtag != dt_errtag(D_VAR_UNDEF)))
4115 4165 longjmp(yypcb->pcb_jmpbuf, err);
4116 4166 }
4117 4167
4118 4168 if (tries == 0) {
4119 4169 yylabel("action list");
4120 4170
4121 4171 dt_node_attr_assign(dnp,
4122 4172 dt_node_list_cook(&dnp->dn_acts, idflags));
4123 4173
4124 4174 bcopy(ojb, yypcb->pcb_jmpbuf, sizeof (jmp_buf));
4125 4175 yylabel(NULL);
4126 4176 }
4127 4177
4128 4178 if (dnp->dn_pred != NULL) {
4129 4179 yylabel("predicate");
4130 4180
4131 4181 dnp->dn_pred = dt_node_cook(dnp->dn_pred, idflags);
4132 4182 dt_node_attr_assign(dnp,
4133 4183 dt_attr_min(dnp->dn_attr, dnp->dn_pred->dn_attr));
4134 4184
4135 4185 if (!dt_node_is_scalar(dnp->dn_pred)) {
4136 4186 xyerror(D_PRED_SCALAR,
4137 4187 "predicate result must be of scalar type\n");
4138 4188 }
4139 4189
4140 4190 yylabel(NULL);
4141 4191 }
4142 4192
4143 4193 if (tries != 0) {
4144 4194 yylabel("action list");
4145 4195
4146 4196 dt_node_attr_assign(dnp,
4147 4197 dt_node_list_cook(&dnp->dn_acts, idflags));
4148 4198
4149 4199 yylabel(NULL);
4150 4200 }
4151 4201
4152 4202 return (dnp);
4153 4203 }
4154 4204
4155 4205 /*ARGSUSED*/
4156 4206 static dt_node_t *
4157 4207 dt_cook_inline(dt_node_t *dnp, uint_t idflags)
4158 4208 {
4159 4209 dt_idnode_t *inp = dnp->dn_ident->di_iarg;
4160 4210 dt_ident_t *rdp;
4161 4211
4162 4212 char n1[DT_TYPE_NAMELEN];
4163 4213 char n2[DT_TYPE_NAMELEN];
4164 4214
4165 4215 assert(dnp->dn_ident->di_flags & DT_IDFLG_INLINE);
4166 4216 assert(inp->din_root->dn_flags & DT_NF_COOKED);
4167 4217
4168 4218 /*
4169 4219 * If we are inlining a translation, verify that the inline declaration
4170 4220 * type exactly matches the type that is returned by the translation.
4171 4221 * Otherwise just use dt_node_is_argcompat() to check the types.
4172 4222 */
4173 4223 if ((rdp = dt_node_resolve(inp->din_root, DT_IDENT_XLSOU)) != NULL ||
4174 4224 (rdp = dt_node_resolve(inp->din_root, DT_IDENT_XLPTR)) != NULL) {
4175 4225
4176 4226 ctf_file_t *lctfp = dnp->dn_ctfp;
4177 4227 ctf_id_t ltype = ctf_type_resolve(lctfp, dnp->dn_type);
4178 4228
4179 4229 dt_xlator_t *dxp = rdp->di_data;
4180 4230 ctf_file_t *rctfp = dxp->dx_dst_ctfp;
4181 4231 ctf_id_t rtype = dxp->dx_dst_base;
4182 4232
4183 4233 if (ctf_type_kind(lctfp, ltype) == CTF_K_POINTER) {
4184 4234 ltype = ctf_type_reference(lctfp, ltype);
4185 4235 ltype = ctf_type_resolve(lctfp, ltype);
4186 4236 }
4187 4237
4188 4238 if (ctf_type_compat(lctfp, ltype, rctfp, rtype) == 0) {
4189 4239 dnerror(dnp, D_OP_INCOMPAT,
4190 4240 "inline %s definition uses incompatible types: "
4191 4241 "\"%s\" = \"%s\"\n", dnp->dn_ident->di_name,
4192 4242 dt_type_name(lctfp, ltype, n1, sizeof (n1)),
4193 4243 dt_type_name(rctfp, rtype, n2, sizeof (n2)));
4194 4244 }
4195 4245
4196 4246 } else if (dt_node_is_argcompat(dnp, inp->din_root) == 0) {
4197 4247 dnerror(dnp, D_OP_INCOMPAT,
4198 4248 "inline %s definition uses incompatible types: "
4199 4249 "\"%s\" = \"%s\"\n", dnp->dn_ident->di_name,
4200 4250 dt_node_type_name(dnp, n1, sizeof (n1)),
4201 4251 dt_node_type_name(inp->din_root, n2, sizeof (n2)));
4202 4252 }
4203 4253
4204 4254 return (dnp);
4205 4255 }
4206 4256
4207 4257 static dt_node_t *
4208 4258 dt_cook_member(dt_node_t *dnp, uint_t idflags)
4209 4259 {
4210 4260 dnp->dn_membexpr = dt_node_cook(dnp->dn_membexpr, idflags);
4211 4261 dt_node_attr_assign(dnp, dnp->dn_membexpr->dn_attr);
4212 4262 return (dnp);
4213 4263 }
4214 4264
4215 4265 /*ARGSUSED*/
4216 4266 static dt_node_t *
4217 4267 dt_cook_xlator(dt_node_t *dnp, uint_t idflags)
4218 4268 {
4219 4269 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4220 4270 dt_xlator_t *dxp = dnp->dn_xlator;
4221 4271 dt_node_t *mnp;
4222 4272
4223 4273 char n1[DT_TYPE_NAMELEN];
4224 4274 char n2[DT_TYPE_NAMELEN];
4225 4275
4226 4276 dtrace_attribute_t attr = _dtrace_maxattr;
4227 4277 ctf_membinfo_t ctm;
4228 4278
4229 4279 /*
4230 4280 * Before cooking each translator member, we push a reference to the
4231 4281 * hash containing translator-local identifiers on to pcb_globals to
4232 4282 * temporarily interpose these identifiers in front of other globals.
4233 4283 */
4234 4284 dt_idstack_push(&yypcb->pcb_globals, dxp->dx_locals);
4235 4285
↓ open down ↓ |
181 lines elided |
↑ open up ↑ |
4236 4286 for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
4237 4287 if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type,
4238 4288 mnp->dn_membname, &ctm) == CTF_ERR) {
4239 4289 xyerror(D_XLATE_MEMB,
4240 4290 "translator member %s is not a member of %s\n",
4241 4291 mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4242 4292 dxp->dx_dst_type, n1, sizeof (n1)));
4243 4293 }
4244 4294
4245 4295 (void) dt_node_cook(mnp, DT_IDFLG_REF);
4246 - dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type);
4296 + dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type,
4297 + B_FALSE);
4247 4298 attr = dt_attr_min(attr, mnp->dn_attr);
4248 4299
4249 4300 if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4250 4301 xyerror(D_XLATE_INCOMPAT,
4251 4302 "translator member %s definition uses "
4252 4303 "incompatible types: \"%s\" = \"%s\"\n",
4253 4304 mnp->dn_membname,
4254 4305 dt_node_type_name(mnp, n1, sizeof (n1)),
4255 4306 dt_node_type_name(mnp->dn_membexpr,
4256 4307 n2, sizeof (n2)));
4257 4308 }
4258 4309 }
4259 4310
4260 4311 dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals);
4261 4312
4262 4313 dxp->dx_souid.di_attr = attr;
4263 4314 dxp->dx_ptrid.di_attr = attr;
4264 4315
4265 - dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
4316 + dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
4266 4317 dt_node_attr_assign(dnp, _dtrace_defattr);
4267 4318
4268 4319 return (dnp);
4269 4320 }
4270 4321
4271 4322 static void
4272 4323 dt_node_provider_cmp_argv(dt_provider_t *pvp, dt_node_t *pnp, const char *kind,
4273 4324 uint_t old_argc, dt_node_t *old_argv, uint_t new_argc, dt_node_t *new_argv)
4274 4325 {
4275 4326 dt_probe_t *prp = pnp->dn_ident->di_data;
4276 4327 uint_t i;
4277 4328
4278 4329 char n1[DT_TYPE_NAMELEN];
4279 4330 char n2[DT_TYPE_NAMELEN];
4280 4331
4281 4332 if (old_argc != new_argc) {
4282 4333 dnerror(pnp, D_PROV_INCOMPAT,
4283 4334 "probe %s:%s %s prototype mismatch:\n"
4284 4335 "\t current: %u arg%s\n\tprevious: %u arg%s\n",
4285 4336 pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, kind,
4286 4337 new_argc, new_argc != 1 ? "s" : "",
4287 4338 old_argc, old_argc != 1 ? "s" : "");
4288 4339 }
4289 4340
4290 4341 for (i = 0; i < old_argc; i++,
4291 4342 old_argv = old_argv->dn_list, new_argv = new_argv->dn_list) {
4292 4343 if (ctf_type_cmp(old_argv->dn_ctfp, old_argv->dn_type,
4293 4344 new_argv->dn_ctfp, new_argv->dn_type) == 0)
4294 4345 continue;
4295 4346
4296 4347 dnerror(pnp, D_PROV_INCOMPAT,
4297 4348 "probe %s:%s %s prototype argument #%u mismatch:\n"
4298 4349 "\t current: %s\n\tprevious: %s\n",
4299 4350 pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, kind, i + 1,
4300 4351 dt_node_type_name(new_argv, n1, sizeof (n1)),
4301 4352 dt_node_type_name(old_argv, n2, sizeof (n2)));
4302 4353 }
4303 4354 }
4304 4355
4305 4356 /*
4306 4357 * Compare a new probe declaration with an existing probe definition (either
4307 4358 * from a previous declaration or cached from the kernel). If the existing
4308 4359 * definition and declaration both have an input and output parameter list,
4309 4360 * compare both lists. Otherwise compare only the output parameter lists.
4310 4361 */
4311 4362 static void
4312 4363 dt_node_provider_cmp(dt_provider_t *pvp, dt_node_t *pnp,
4313 4364 dt_probe_t *old, dt_probe_t *new)
4314 4365 {
4315 4366 dt_node_provider_cmp_argv(pvp, pnp, "output",
4316 4367 old->pr_xargc, old->pr_xargs, new->pr_xargc, new->pr_xargs);
4317 4368
4318 4369 if (old->pr_nargs != old->pr_xargs && new->pr_nargs != new->pr_xargs) {
4319 4370 dt_node_provider_cmp_argv(pvp, pnp, "input",
4320 4371 old->pr_nargc, old->pr_nargs, new->pr_nargc, new->pr_nargs);
4321 4372 }
4322 4373
4323 4374 if (old->pr_nargs == old->pr_xargs && new->pr_nargs != new->pr_xargs) {
4324 4375 if (pvp->pv_flags & DT_PROVIDER_IMPL) {
4325 4376 dnerror(pnp, D_PROV_INCOMPAT,
4326 4377 "provider interface mismatch: %s\n"
4327 4378 "\t current: probe %s:%s has an output prototype\n"
4328 4379 "\tprevious: probe %s:%s has no output prototype\n",
4329 4380 pvp->pv_desc.dtvd_name, pvp->pv_desc.dtvd_name,
4330 4381 new->pr_ident->di_name, pvp->pv_desc.dtvd_name,
4331 4382 old->pr_ident->di_name);
4332 4383 }
4333 4384
4334 4385 if (old->pr_ident->di_gen == yypcb->pcb_hdl->dt_gen)
4335 4386 old->pr_ident->di_flags |= DT_IDFLG_ORPHAN;
4336 4387
4337 4388 dt_idhash_delete(pvp->pv_probes, old->pr_ident);
4338 4389 dt_probe_declare(pvp, new);
4339 4390 }
4340 4391 }
4341 4392
4342 4393 static void
4343 4394 dt_cook_probe(dt_node_t *dnp, dt_provider_t *pvp)
4344 4395 {
4345 4396 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4346 4397 dt_probe_t *prp = dnp->dn_ident->di_data;
4347 4398
4348 4399 dt_xlator_t *dxp;
4349 4400 uint_t i;
4350 4401
4351 4402 char n1[DT_TYPE_NAMELEN];
4352 4403 char n2[DT_TYPE_NAMELEN];
4353 4404
4354 4405 if (prp->pr_nargs == prp->pr_xargs)
4355 4406 return;
4356 4407
4357 4408 for (i = 0; i < prp->pr_xargc; i++) {
4358 4409 dt_node_t *xnp = prp->pr_xargv[i];
4359 4410 dt_node_t *nnp = prp->pr_nargv[prp->pr_mapping[i]];
4360 4411
4361 4412 if ((dxp = dt_xlator_lookup(dtp,
4362 4413 nnp, xnp, DT_XLATE_FUZZY)) != NULL) {
4363 4414 if (dt_provider_xref(dtp, pvp, dxp->dx_id) != 0)
4364 4415 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
4365 4416 continue;
4366 4417 }
4367 4418
4368 4419 if (dt_node_is_argcompat(nnp, xnp))
4369 4420 continue; /* no translator defined and none required */
4370 4421
4371 4422 dnerror(dnp, D_PROV_PRXLATOR, "translator for %s:%s output "
4372 4423 "argument #%u from %s to %s is not defined\n",
4373 4424 pvp->pv_desc.dtvd_name, dnp->dn_ident->di_name, i + 1,
4374 4425 dt_node_type_name(nnp, n1, sizeof (n1)),
4375 4426 dt_node_type_name(xnp, n2, sizeof (n2)));
4376 4427 }
4377 4428 }
4378 4429
4379 4430 /*ARGSUSED*/
4380 4431 static dt_node_t *
4381 4432 dt_cook_provider(dt_node_t *dnp, uint_t idflags)
4382 4433 {
4383 4434 dt_provider_t *pvp = dnp->dn_provider;
4384 4435 dt_node_t *pnp;
4385 4436
4386 4437 /*
4387 4438 * If we're declaring a provider for the first time and it is unknown
4388 4439 * to dtrace(7D), insert the probe definitions into the provider's hash.
4389 4440 * If we're redeclaring a known provider, verify the interface matches.
4390 4441 */
4391 4442 for (pnp = dnp->dn_probes; pnp != NULL; pnp = pnp->dn_list) {
4392 4443 const char *probename = pnp->dn_ident->di_name;
4393 4444 dt_probe_t *prp = dt_probe_lookup(pvp, probename);
4394 4445
4395 4446 assert(pnp->dn_kind == DT_NODE_PROBE);
4396 4447
4397 4448 if (prp != NULL && dnp->dn_provred) {
4398 4449 dt_node_provider_cmp(pvp, pnp,
4399 4450 prp, pnp->dn_ident->di_data);
4400 4451 } else if (prp == NULL && dnp->dn_provred) {
4401 4452 dnerror(pnp, D_PROV_INCOMPAT,
4402 4453 "provider interface mismatch: %s\n"
4403 4454 "\t current: probe %s:%s defined\n"
4404 4455 "\tprevious: probe %s:%s not defined\n",
4405 4456 dnp->dn_provname, dnp->dn_provname,
4406 4457 probename, dnp->dn_provname, probename);
4407 4458 } else if (prp != NULL) {
4408 4459 dnerror(pnp, D_PROV_PRDUP, "probe redeclared: %s:%s\n",
4409 4460 dnp->dn_provname, probename);
4410 4461 } else
4411 4462 dt_probe_declare(pvp, pnp->dn_ident->di_data);
4412 4463
4413 4464 dt_cook_probe(pnp, pvp);
4414 4465 }
4415 4466
4416 4467 return (dnp);
4417 4468 }
4418 4469
4419 4470 /*ARGSUSED*/
4420 4471 static dt_node_t *
4421 4472 dt_cook_none(dt_node_t *dnp, uint_t idflags)
4422 4473 {
4423 4474 return (dnp);
4424 4475 }
4425 4476
4426 4477 static dt_node_t *(*dt_cook_funcs[])(dt_node_t *, uint_t) = {
4427 4478 dt_cook_none, /* DT_NODE_FREE */
4428 4479 dt_cook_none, /* DT_NODE_INT */
4429 4480 dt_cook_none, /* DT_NODE_STRING */
4430 4481 dt_cook_ident, /* DT_NODE_IDENT */
4431 4482 dt_cook_var, /* DT_NODE_VAR */
4432 4483 dt_cook_none, /* DT_NODE_SYM */
4433 4484 dt_cook_none, /* DT_NODE_TYPE */
4434 4485 dt_cook_func, /* DT_NODE_FUNC */
4435 4486 dt_cook_op1, /* DT_NODE_OP1 */
4436 4487 dt_cook_op2, /* DT_NODE_OP2 */
4437 4488 dt_cook_op3, /* DT_NODE_OP3 */
4438 4489 dt_cook_statement, /* DT_NODE_DEXPR */
4439 4490 dt_cook_statement, /* DT_NODE_DFUNC */
4440 4491 dt_cook_aggregation, /* DT_NODE_AGG */
4441 4492 dt_cook_none, /* DT_NODE_PDESC */
4442 4493 dt_cook_clause, /* DT_NODE_CLAUSE */
4443 4494 dt_cook_inline, /* DT_NODE_INLINE */
4444 4495 dt_cook_member, /* DT_NODE_MEMBER */
4445 4496 dt_cook_xlator, /* DT_NODE_XLATOR */
4446 4497 dt_cook_none, /* DT_NODE_PROBE */
4447 4498 dt_cook_provider, /* DT_NODE_PROVIDER */
4448 4499 dt_cook_none /* DT_NODE_PROG */
4449 4500 };
4450 4501
4451 4502 /*
4452 4503 * Recursively cook the parse tree starting at the specified node. The idflags
4453 4504 * parameter is used to indicate the type of reference (r/w) and is applied to
4454 4505 * the resulting identifier if it is a D variable or D aggregation.
4455 4506 */
4456 4507 dt_node_t *
4457 4508 dt_node_cook(dt_node_t *dnp, uint_t idflags)
4458 4509 {
4459 4510 int oldlineno = yylineno;
4460 4511
4461 4512 yylineno = dnp->dn_line;
4462 4513
4463 4514 dnp = dt_cook_funcs[dnp->dn_kind](dnp, idflags);
4464 4515 dnp->dn_flags |= DT_NF_COOKED;
4465 4516
4466 4517 if (dnp->dn_kind == DT_NODE_VAR || dnp->dn_kind == DT_NODE_AGG)
4467 4518 dnp->dn_ident->di_flags |= idflags;
4468 4519
4469 4520 yylineno = oldlineno;
4470 4521 return (dnp);
4471 4522 }
4472 4523
4473 4524 dtrace_attribute_t
4474 4525 dt_node_list_cook(dt_node_t **pnp, uint_t idflags)
4475 4526 {
4476 4527 dtrace_attribute_t attr = _dtrace_defattr;
4477 4528 dt_node_t *dnp, *nnp;
4478 4529
4479 4530 for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) {
4480 4531 nnp = dnp->dn_list;
4481 4532 dnp = *pnp = dt_node_cook(dnp, idflags);
4482 4533 attr = dt_attr_min(attr, dnp->dn_attr);
4483 4534 dnp->dn_list = nnp;
4484 4535 pnp = &dnp->dn_list;
4485 4536 }
4486 4537
4487 4538 return (attr);
4488 4539 }
4489 4540
4490 4541 void
4491 4542 dt_node_list_free(dt_node_t **pnp)
4492 4543 {
4493 4544 dt_node_t *dnp, *nnp;
4494 4545
4495 4546 for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) {
4496 4547 nnp = dnp->dn_list;
4497 4548 dt_node_free(dnp);
4498 4549 }
4499 4550
4500 4551 if (pnp != NULL)
4501 4552 *pnp = NULL;
4502 4553 }
4503 4554
4504 4555 void
4505 4556 dt_node_link_free(dt_node_t **pnp)
4506 4557 {
4507 4558 dt_node_t *dnp, *nnp;
4508 4559
4509 4560 for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) {
4510 4561 nnp = dnp->dn_link;
4511 4562 dt_node_free(dnp);
4512 4563 }
4513 4564
4514 4565 for (dnp = (pnp != NULL ? *pnp : NULL); dnp != NULL; dnp = nnp) {
4515 4566 nnp = dnp->dn_link;
4516 4567 free(dnp);
4517 4568 }
4518 4569
4519 4570 if (pnp != NULL)
4520 4571 *pnp = NULL;
4521 4572 }
4522 4573
4523 4574 dt_node_t *
4524 4575 dt_node_link(dt_node_t *lp, dt_node_t *rp)
4525 4576 {
4526 4577 dt_node_t *dnp;
4527 4578
4528 4579 if (lp == NULL)
4529 4580 return (rp);
4530 4581 else if (rp == NULL)
4531 4582 return (lp);
4532 4583
4533 4584 for (dnp = lp; dnp->dn_list != NULL; dnp = dnp->dn_list)
4534 4585 continue;
4535 4586
4536 4587 dnp->dn_list = rp;
4537 4588 return (lp);
4538 4589 }
4539 4590
4540 4591 /*
4541 4592 * Compute the DOF dtrace_diftype_t representation of a node's type. This is
4542 4593 * called from a variety of places in the library so it cannot assume yypcb
4543 4594 * is valid: any references to handle-specific data must be made through 'dtp'.
4544 4595 */
4545 4596 void
4546 4597 dt_node_diftype(dtrace_hdl_t *dtp, const dt_node_t *dnp, dtrace_diftype_t *tp)
4547 4598 {
↓ open down ↓ |
272 lines elided |
↑ open up ↑ |
4548 4599 if (dnp->dn_ctfp == DT_STR_CTFP(dtp) &&
4549 4600 dnp->dn_type == DT_STR_TYPE(dtp)) {
4550 4601 tp->dtdt_kind = DIF_TYPE_STRING;
4551 4602 tp->dtdt_ckind = CTF_K_UNKNOWN;
4552 4603 } else {
4553 4604 tp->dtdt_kind = DIF_TYPE_CTF;
4554 4605 tp->dtdt_ckind = ctf_type_kind(dnp->dn_ctfp,
4555 4606 ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type));
4556 4607 }
4557 4608
4558 - tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ? DIF_TF_BYREF : 0;
4609 + tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ?
4610 + (dnp->dn_flags & DT_NF_USERLAND) ? DIF_TF_BYUREF :
4611 + DIF_TF_BYREF : 0;
4559 4612 tp->dtdt_pad = 0;
4560 4613 tp->dtdt_size = ctf_type_size(dnp->dn_ctfp, dnp->dn_type);
4561 4614 }
4562 4615
4563 4616 void
4564 4617 dt_node_printr(dt_node_t *dnp, FILE *fp, int depth)
4565 4618 {
4566 4619 char n[DT_TYPE_NAMELEN], buf[BUFSIZ], a[8];
4567 4620 const dtrace_syminfo_t *dts;
4568 4621 const dt_idnode_t *inp;
4569 4622 dt_node_t *arg;
4570 4623
4571 4624 (void) fprintf(fp, "%*s", depth * 2, "");
4572 4625 (void) dt_attr_str(dnp->dn_attr, a, sizeof (a));
4573 4626
4574 4627 if (dnp->dn_ctfp != NULL && dnp->dn_type != CTF_ERR &&
4575 4628 ctf_type_name(dnp->dn_ctfp, dnp->dn_type, n, sizeof (n)) != NULL) {
4576 4629 (void) snprintf(buf, BUFSIZ, "type=<%s> attr=%s flags=", n, a);
4577 4630 } else {
4578 4631 (void) snprintf(buf, BUFSIZ, "type=<%ld> attr=%s flags=",
4579 4632 dnp->dn_type, a);
4580 4633 }
4581 4634
4582 4635 if (dnp->dn_flags != 0) {
4583 4636 n[0] = '\0';
4584 4637 if (dnp->dn_flags & DT_NF_SIGNED)
4585 4638 (void) strcat(n, ",SIGN");
4586 4639 if (dnp->dn_flags & DT_NF_COOKED)
4587 4640 (void) strcat(n, ",COOK");
4588 4641 if (dnp->dn_flags & DT_NF_REF)
4589 4642 (void) strcat(n, ",REF");
4590 4643 if (dnp->dn_flags & DT_NF_LVALUE)
4591 4644 (void) strcat(n, ",LVAL");
4592 4645 if (dnp->dn_flags & DT_NF_WRITABLE)
4593 4646 (void) strcat(n, ",WRITE");
4594 4647 if (dnp->dn_flags & DT_NF_BITFIELD)
4595 4648 (void) strcat(n, ",BITF");
4596 4649 if (dnp->dn_flags & DT_NF_USERLAND)
4597 4650 (void) strcat(n, ",USER");
4598 4651 (void) strcat(buf, n + 1);
4599 4652 } else
4600 4653 (void) strcat(buf, "0");
4601 4654
4602 4655 switch (dnp->dn_kind) {
4603 4656 case DT_NODE_FREE:
4604 4657 (void) fprintf(fp, "FREE <node %p>\n", (void *)dnp);
4605 4658 break;
4606 4659
4607 4660 case DT_NODE_INT:
4608 4661 (void) fprintf(fp, "INT 0x%llx (%s)\n",
4609 4662 (u_longlong_t)dnp->dn_value, buf);
4610 4663 break;
4611 4664
4612 4665 case DT_NODE_STRING:
4613 4666 (void) fprintf(fp, "STRING \"%s\" (%s)\n", dnp->dn_string, buf);
4614 4667 break;
4615 4668
4616 4669 case DT_NODE_IDENT:
4617 4670 (void) fprintf(fp, "IDENT %s (%s)\n", dnp->dn_string, buf);
4618 4671 break;
4619 4672
4620 4673 case DT_NODE_VAR:
4621 4674 (void) fprintf(fp, "VARIABLE %s%s (%s)\n",
4622 4675 (dnp->dn_ident->di_flags & DT_IDFLG_LOCAL) ? "this->" :
4623 4676 (dnp->dn_ident->di_flags & DT_IDFLG_TLS) ? "self->" : "",
4624 4677 dnp->dn_ident->di_name, buf);
4625 4678
4626 4679 if (dnp->dn_args != NULL)
4627 4680 (void) fprintf(fp, "%*s[\n", depth * 2, "");
4628 4681
4629 4682 for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) {
4630 4683 dt_node_printr(arg, fp, depth + 1);
4631 4684 if (arg->dn_list != NULL)
4632 4685 (void) fprintf(fp, "%*s,\n", depth * 2, "");
4633 4686 }
4634 4687
4635 4688 if (dnp->dn_args != NULL)
4636 4689 (void) fprintf(fp, "%*s]\n", depth * 2, "");
4637 4690 break;
4638 4691
4639 4692 case DT_NODE_SYM:
4640 4693 dts = dnp->dn_ident->di_data;
4641 4694 (void) fprintf(fp, "SYMBOL %s`%s (%s)\n",
4642 4695 dts->dts_object, dts->dts_name, buf);
4643 4696 break;
4644 4697
4645 4698 case DT_NODE_TYPE:
4646 4699 if (dnp->dn_string != NULL) {
4647 4700 (void) fprintf(fp, "TYPE (%s) %s\n",
4648 4701 buf, dnp->dn_string);
4649 4702 } else
4650 4703 (void) fprintf(fp, "TYPE (%s)\n", buf);
4651 4704 break;
4652 4705
4653 4706 case DT_NODE_FUNC:
4654 4707 (void) fprintf(fp, "FUNC %s (%s)\n",
4655 4708 dnp->dn_ident->di_name, buf);
4656 4709
4657 4710 for (arg = dnp->dn_args; arg != NULL; arg = arg->dn_list) {
4658 4711 dt_node_printr(arg, fp, depth + 1);
4659 4712 if (arg->dn_list != NULL)
4660 4713 (void) fprintf(fp, "%*s,\n", depth * 2, "");
4661 4714 }
4662 4715 break;
4663 4716
4664 4717 case DT_NODE_OP1:
4665 4718 (void) fprintf(fp, "OP1 %s (%s)\n", opstr(dnp->dn_op), buf);
4666 4719 dt_node_printr(dnp->dn_child, fp, depth + 1);
4667 4720 break;
4668 4721
4669 4722 case DT_NODE_OP2:
4670 4723 (void) fprintf(fp, "OP2 %s (%s)\n", opstr(dnp->dn_op), buf);
4671 4724 dt_node_printr(dnp->dn_left, fp, depth + 1);
4672 4725 dt_node_printr(dnp->dn_right, fp, depth + 1);
4673 4726 break;
4674 4727
4675 4728 case DT_NODE_OP3:
4676 4729 (void) fprintf(fp, "OP3 (%s)\n", buf);
4677 4730 dt_node_printr(dnp->dn_expr, fp, depth + 1);
4678 4731 (void) fprintf(fp, "%*s?\n", depth * 2, "");
4679 4732 dt_node_printr(dnp->dn_left, fp, depth + 1);
4680 4733 (void) fprintf(fp, "%*s:\n", depth * 2, "");
4681 4734 dt_node_printr(dnp->dn_right, fp, depth + 1);
4682 4735 break;
4683 4736
4684 4737 case DT_NODE_DEXPR:
4685 4738 case DT_NODE_DFUNC:
4686 4739 (void) fprintf(fp, "D EXPRESSION attr=%s\n", a);
4687 4740 dt_node_printr(dnp->dn_expr, fp, depth + 1);
4688 4741 break;
4689 4742
4690 4743 case DT_NODE_AGG:
4691 4744 (void) fprintf(fp, "AGGREGATE @%s attr=%s [\n",
4692 4745 dnp->dn_ident->di_name, a);
4693 4746
4694 4747 for (arg = dnp->dn_aggtup; arg != NULL; arg = arg->dn_list) {
4695 4748 dt_node_printr(arg, fp, depth + 1);
4696 4749 if (arg->dn_list != NULL)
4697 4750 (void) fprintf(fp, "%*s,\n", depth * 2, "");
4698 4751 }
4699 4752
4700 4753 if (dnp->dn_aggfun) {
4701 4754 (void) fprintf(fp, "%*s] = ", depth * 2, "");
4702 4755 dt_node_printr(dnp->dn_aggfun, fp, depth + 1);
4703 4756 } else
4704 4757 (void) fprintf(fp, "%*s]\n", depth * 2, "");
4705 4758
4706 4759 if (dnp->dn_aggfun)
4707 4760 (void) fprintf(fp, "%*s)\n", depth * 2, "");
4708 4761 break;
4709 4762
4710 4763 case DT_NODE_PDESC:
4711 4764 (void) fprintf(fp, "PDESC %s:%s:%s:%s [%u]\n",
4712 4765 dnp->dn_desc->dtpd_provider, dnp->dn_desc->dtpd_mod,
4713 4766 dnp->dn_desc->dtpd_func, dnp->dn_desc->dtpd_name,
4714 4767 dnp->dn_desc->dtpd_id);
4715 4768 break;
4716 4769
4717 4770 case DT_NODE_CLAUSE:
4718 4771 (void) fprintf(fp, "CLAUSE attr=%s\n", a);
4719 4772
4720 4773 for (arg = dnp->dn_pdescs; arg != NULL; arg = arg->dn_list)
4721 4774 dt_node_printr(arg, fp, depth + 1);
4722 4775
4723 4776 (void) fprintf(fp, "%*sCTXATTR %s\n", depth * 2, "",
4724 4777 dt_attr_str(dnp->dn_ctxattr, a, sizeof (a)));
4725 4778
4726 4779 if (dnp->dn_pred != NULL) {
4727 4780 (void) fprintf(fp, "%*sPREDICATE /\n", depth * 2, "");
4728 4781 dt_node_printr(dnp->dn_pred, fp, depth + 1);
4729 4782 (void) fprintf(fp, "%*s/\n", depth * 2, "");
4730 4783 }
4731 4784
4732 4785 for (arg = dnp->dn_acts; arg != NULL; arg = arg->dn_list)
4733 4786 dt_node_printr(arg, fp, depth + 1);
4734 4787 break;
4735 4788
4736 4789 case DT_NODE_INLINE:
4737 4790 inp = dnp->dn_ident->di_iarg;
4738 4791
4739 4792 (void) fprintf(fp, "INLINE %s (%s)\n",
4740 4793 dnp->dn_ident->di_name, buf);
4741 4794 dt_node_printr(inp->din_root, fp, depth + 1);
4742 4795 break;
4743 4796
4744 4797 case DT_NODE_MEMBER:
4745 4798 (void) fprintf(fp, "MEMBER %s (%s)\n", dnp->dn_membname, buf);
4746 4799 if (dnp->dn_membexpr)
4747 4800 dt_node_printr(dnp->dn_membexpr, fp, depth + 1);
4748 4801 break;
4749 4802
4750 4803 case DT_NODE_XLATOR:
4751 4804 (void) fprintf(fp, "XLATOR (%s)", buf);
4752 4805
4753 4806 if (ctf_type_name(dnp->dn_xlator->dx_src_ctfp,
4754 4807 dnp->dn_xlator->dx_src_type, n, sizeof (n)) != NULL)
4755 4808 (void) fprintf(fp, " from <%s>", n);
4756 4809
4757 4810 if (ctf_type_name(dnp->dn_xlator->dx_dst_ctfp,
4758 4811 dnp->dn_xlator->dx_dst_type, n, sizeof (n)) != NULL)
4759 4812 (void) fprintf(fp, " to <%s>", n);
4760 4813
4761 4814 (void) fprintf(fp, "\n");
4762 4815
4763 4816 for (arg = dnp->dn_members; arg != NULL; arg = arg->dn_list)
4764 4817 dt_node_printr(arg, fp, depth + 1);
4765 4818 break;
4766 4819
4767 4820 case DT_NODE_PROBE:
4768 4821 (void) fprintf(fp, "PROBE %s\n", dnp->dn_ident->di_name);
4769 4822 break;
4770 4823
4771 4824 case DT_NODE_PROVIDER:
4772 4825 (void) fprintf(fp, "PROVIDER %s (%s)\n",
4773 4826 dnp->dn_provname, dnp->dn_provred ? "redecl" : "decl");
4774 4827 for (arg = dnp->dn_probes; arg != NULL; arg = arg->dn_list)
4775 4828 dt_node_printr(arg, fp, depth + 1);
4776 4829 break;
4777 4830
4778 4831 case DT_NODE_PROG:
4779 4832 (void) fprintf(fp, "PROGRAM attr=%s\n", a);
4780 4833 for (arg = dnp->dn_list; arg != NULL; arg = arg->dn_list)
4781 4834 dt_node_printr(arg, fp, depth + 1);
4782 4835 break;
4783 4836
4784 4837 default:
4785 4838 (void) fprintf(fp, "<bad node %p, kind %d>\n",
4786 4839 (void *)dnp, dnp->dn_kind);
4787 4840 }
4788 4841 }
4789 4842
4790 4843 int
4791 4844 dt_node_root(dt_node_t *dnp)
4792 4845 {
4793 4846 yypcb->pcb_root = dnp;
4794 4847 return (0);
4795 4848 }
4796 4849
4797 4850 /*PRINTFLIKE3*/
4798 4851 void
4799 4852 dnerror(const dt_node_t *dnp, dt_errtag_t tag, const char *format, ...)
4800 4853 {
4801 4854 int oldlineno = yylineno;
4802 4855 va_list ap;
4803 4856
4804 4857 yylineno = dnp->dn_line;
4805 4858
4806 4859 va_start(ap, format);
4807 4860 xyvwarn(tag, format, ap);
4808 4861 va_end(ap);
4809 4862
4810 4863 yylineno = oldlineno;
4811 4864 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
4812 4865 }
4813 4866
4814 4867 /*PRINTFLIKE3*/
4815 4868 void
4816 4869 dnwarn(const dt_node_t *dnp, dt_errtag_t tag, const char *format, ...)
4817 4870 {
4818 4871 int oldlineno = yylineno;
4819 4872 va_list ap;
4820 4873
4821 4874 yylineno = dnp->dn_line;
4822 4875
4823 4876 va_start(ap, format);
4824 4877 xyvwarn(tag, format, ap);
4825 4878 va_end(ap);
4826 4879
4827 4880 yylineno = oldlineno;
4828 4881 }
4829 4882
4830 4883 /*PRINTFLIKE2*/
4831 4884 void
4832 4885 xyerror(dt_errtag_t tag, const char *format, ...)
4833 4886 {
4834 4887 va_list ap;
4835 4888
4836 4889 va_start(ap, format);
4837 4890 xyvwarn(tag, format, ap);
4838 4891 va_end(ap);
4839 4892
4840 4893 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
4841 4894 }
4842 4895
4843 4896 /*PRINTFLIKE2*/
4844 4897 void
4845 4898 xywarn(dt_errtag_t tag, const char *format, ...)
4846 4899 {
4847 4900 va_list ap;
4848 4901
4849 4902 va_start(ap, format);
4850 4903 xyvwarn(tag, format, ap);
4851 4904 va_end(ap);
4852 4905 }
4853 4906
4854 4907 void
4855 4908 xyvwarn(dt_errtag_t tag, const char *format, va_list ap)
4856 4909 {
4857 4910 if (yypcb == NULL)
4858 4911 return; /* compiler is not currently active: act as a no-op */
4859 4912
4860 4913 dt_set_errmsg(yypcb->pcb_hdl, dt_errtag(tag), yypcb->pcb_region,
4861 4914 yypcb->pcb_filetag, yypcb->pcb_fileptr ? yylineno : 0, format, ap);
4862 4915 }
4863 4916
4864 4917 /*PRINTFLIKE1*/
4865 4918 void
4866 4919 yyerror(const char *format, ...)
4867 4920 {
4868 4921 va_list ap;
4869 4922
4870 4923 va_start(ap, format);
4871 4924 yyvwarn(format, ap);
4872 4925 va_end(ap);
4873 4926
4874 4927 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
4875 4928 }
4876 4929
4877 4930 /*PRINTFLIKE1*/
4878 4931 void
4879 4932 yywarn(const char *format, ...)
4880 4933 {
4881 4934 va_list ap;
4882 4935
4883 4936 va_start(ap, format);
4884 4937 yyvwarn(format, ap);
4885 4938 va_end(ap);
4886 4939 }
4887 4940
4888 4941 void
4889 4942 yyvwarn(const char *format, va_list ap)
4890 4943 {
4891 4944 if (yypcb == NULL)
4892 4945 return; /* compiler is not currently active: act as a no-op */
4893 4946
4894 4947 dt_set_errmsg(yypcb->pcb_hdl, dt_errtag(D_SYNTAX), yypcb->pcb_region,
4895 4948 yypcb->pcb_filetag, yypcb->pcb_fileptr ? yylineno : 0, format, ap);
4896 4949
4897 4950 if (strchr(format, '\n') == NULL) {
4898 4951 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4899 4952 size_t len = strlen(dtp->dt_errmsg);
4900 4953 char *p, *s = dtp->dt_errmsg + len;
4901 4954 size_t n = sizeof (dtp->dt_errmsg) - len;
4902 4955
4903 4956 if (yytext[0] == '\0')
4904 4957 (void) snprintf(s, n, " near end of input");
4905 4958 else if (yytext[0] == '\n')
4906 4959 (void) snprintf(s, n, " near end of line");
4907 4960 else {
4908 4961 if ((p = strchr(yytext, '\n')) != NULL)
4909 4962 *p = '\0'; /* crop at newline */
4910 4963 (void) snprintf(s, n, " near \"%s\"", yytext);
4911 4964 }
4912 4965 }
4913 4966 }
4914 4967
4915 4968 void
4916 4969 yylabel(const char *label)
4917 4970 {
4918 4971 dt_dprintf("set label to <%s>\n", label ? label : "NULL");
4919 4972 yypcb->pcb_region = label;
4920 4973 }
4921 4974
4922 4975 int
4923 4976 yywrap(void)
4924 4977 {
4925 4978 return (1); /* indicate that lex should return a zero token for EOF */
4926 4979 }
↓ open down ↓ |
358 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX