Print this page
7085 add support for "if" and "else" statements in dtrace
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_cc.c
+++ new/usr/src/lib/libdtrace/common/dt_cc.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, 2014 by Delphix. All rights reserved.
24 25 * Copyright (c) 2013, Joyent Inc. All rights reserved.
25 - * Copyright (c) 2012 by Delphix. All rights reserved.
26 26 * Copyright 2015 Gary Mills
27 27 */
28 28
29 29 /*
30 30 * DTrace D Language Compiler
31 31 *
32 32 * The code in this source file implements the main engine for the D language
33 33 * compiler. The driver routine for the compiler is dt_compile(), below. The
34 34 * compiler operates on either stdio FILEs or in-memory strings as its input
35 35 * and can produce either dtrace_prog_t structures from a D program or a single
36 36 * dtrace_difo_t structure from a D expression. Multiple entry points are
37 37 * provided as wrappers around dt_compile() for the various input/output pairs.
38 38 * The compiler itself is implemented across the following source files:
39 39 *
40 40 * dt_lex.l - lex scanner
41 41 * dt_grammar.y - yacc grammar
42 42 * dt_parser.c - parse tree creation and semantic checking
43 43 * dt_decl.c - declaration stack processing
44 44 * dt_xlator.c - D translator lookup and creation
45 45 * dt_ident.c - identifier and symbol table routines
46 46 * dt_pragma.c - #pragma processing and D pragmas
47 47 * dt_printf.c - D printf() and printa() argument checking and processing
48 48 * dt_cc.c - compiler driver and dtrace_prog_t construction
49 49 * dt_cg.c - DIF code generator
50 50 * dt_as.c - DIF assembler
51 51 * dt_dof.c - dtrace_prog_t -> DOF conversion
52 52 *
53 53 * Several other source files provide collections of utility routines used by
54 54 * these major files. The compiler itself is implemented in multiple passes:
55 55 *
56 56 * (1) The input program is scanned and parsed by dt_lex.l and dt_grammar.y
57 57 * and parse tree nodes are constructed using the routines in dt_parser.c.
58 58 * This node construction pass is described further in dt_parser.c.
59 59 *
60 60 * (2) The parse tree is "cooked" by assigning each clause a context (see the
61 61 * routine dt_setcontext(), below) based on its probe description and then
62 62 * recursively descending the tree performing semantic checking. The cook
63 63 * routines are also implemented in dt_parser.c and described there.
64 64 *
65 65 * (3) For actions that are DIF expression statements, the DIF code generator
66 66 * and assembler are invoked to create a finished DIFO for the statement.
67 67 *
68 68 * (4) The dtrace_prog_t data structures for the program clauses and actions
69 69 * are built, containing pointers to any DIFOs created in step (3).
70 70 *
71 71 * (5) The caller invokes a routine in dt_dof.c to convert the finished program
72 72 * into DOF format for use in anonymous tracing or enabling in the kernel.
73 73 *
74 74 * In the implementation, steps 2-4 are intertwined in that they are performed
75 75 * in order for each clause as part of a loop that executes over the clauses.
76 76 *
77 77 * The D compiler currently implements nearly no optimization. The compiler
78 78 * implements integer constant folding as part of pass (1), and a set of very
79 79 * simple peephole optimizations as part of pass (3). As with any C compiler,
80 80 * a large number of optimizations are possible on both the intermediate data
81 81 * structures and the generated DIF code. These possibilities should be
82 82 * investigated in the context of whether they will have any substantive effect
83 83 * on the overall DTrace probe effect before they are undertaken.
84 84 */
85 85
86 86 #include <sys/types.h>
87 87 #include <sys/wait.h>
88 88 #include <sys/sysmacros.h>
89 89
90 90 #include <assert.h>
91 91 #include <strings.h>
92 92 #include <signal.h>
93 93 #include <unistd.h>
94 94 #include <stdlib.h>
95 95 #include <stdio.h>
96 96 #include <errno.h>
97 97 #include <ucontext.h>
98 98 #include <limits.h>
99 99 #include <ctype.h>
100 100 #include <dirent.h>
101 101 #include <dt_module.h>
102 102 #include <dt_program.h>
103 103 #include <dt_provider.h>
104 104 #include <dt_printf.h>
105 105 #include <dt_pid.h>
106 106 #include <dt_grammar.h>
107 107 #include <dt_ident.h>
108 108 #include <dt_string.h>
109 109 #include <dt_impl.h>
110 110
111 111 static const dtrace_diftype_t dt_void_rtype = {
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
112 112 DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, 0
113 113 };
114 114
115 115 static const dtrace_diftype_t dt_int_rtype = {
116 116 DIF_TYPE_CTF, CTF_K_INTEGER, 0, 0, sizeof (uint64_t)
117 117 };
118 118
119 119 static void *dt_compile(dtrace_hdl_t *, int, dtrace_probespec_t, void *,
120 120 uint_t, int, char *const[], FILE *, const char *);
121 121
122 -
123 122 /*ARGSUSED*/
124 123 static int
125 124 dt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
126 125 {
127 126 idp->di_flags &= ~(DT_IDFLG_REF | DT_IDFLG_MOD |
128 127 DT_IDFLG_DIFR | DT_IDFLG_DIFW);
129 128 return (0);
130 129 }
131 130
132 131 /*ARGSUSED*/
133 132 static int
134 133 dt_idpragma(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
135 134 {
136 135 yylineno = idp->di_lineno;
137 136 xyerror(D_PRAGMA_UNUSED, "unused #pragma %s\n", (char *)idp->di_iarg);
138 137 return (0);
139 138 }
140 139
141 140 static dtrace_stmtdesc_t *
142 141 dt_stmt_create(dtrace_hdl_t *dtp, dtrace_ecbdesc_t *edp,
143 142 dtrace_attribute_t descattr, dtrace_attribute_t stmtattr)
144 143 {
145 144 dtrace_stmtdesc_t *sdp = dtrace_stmt_create(dtp, edp);
146 145
147 146 if (sdp == NULL)
148 147 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
149 148
150 149 assert(yypcb->pcb_stmt == NULL);
151 150 yypcb->pcb_stmt = sdp;
152 151
153 152 sdp->dtsd_descattr = descattr;
154 153 sdp->dtsd_stmtattr = stmtattr;
155 154
156 155 return (sdp);
157 156 }
158 157
159 158 static dtrace_actdesc_t *
160 159 dt_stmt_action(dtrace_hdl_t *dtp, dtrace_stmtdesc_t *sdp)
161 160 {
162 161 dtrace_actdesc_t *new;
163 162
164 163 if ((new = dtrace_stmt_action(dtp, sdp)) == NULL)
165 164 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
166 165
167 166 return (new);
168 167 }
169 168
170 169 /*
171 170 * Utility function to determine if a given action description is destructive.
172 171 * The dtdo_destructive bit is set for us by the DIF assembler (see dt_as.c).
173 172 */
174 173 static int
175 174 dt_action_destructive(const dtrace_actdesc_t *ap)
176 175 {
177 176 return (DTRACEACT_ISDESTRUCTIVE(ap->dtad_kind) || (ap->dtad_kind ==
178 177 DTRACEACT_DIFEXPR && ap->dtad_difo->dtdo_destructive));
179 178 }
180 179
181 180 static void
182 181 dt_stmt_append(dtrace_stmtdesc_t *sdp, const dt_node_t *dnp)
183 182 {
184 183 dtrace_ecbdesc_t *edp = sdp->dtsd_ecbdesc;
185 184 dtrace_actdesc_t *ap, *tap;
186 185 int commit = 0;
187 186 int speculate = 0;
188 187 int datarec = 0;
189 188
190 189 /*
191 190 * Make sure that the new statement jibes with the rest of the ECB.
192 191 */
193 192 for (ap = edp->dted_action; ap != NULL; ap = ap->dtad_next) {
194 193 if (ap->dtad_kind == DTRACEACT_COMMIT) {
195 194 if (commit) {
196 195 dnerror(dnp, D_COMM_COMM, "commit( ) may "
197 196 "not follow commit( )\n");
198 197 }
199 198
200 199 if (datarec) {
201 200 dnerror(dnp, D_COMM_DREC, "commit( ) may "
202 201 "not follow data-recording action(s)\n");
203 202 }
204 203
205 204 for (tap = ap; tap != NULL; tap = tap->dtad_next) {
206 205 if (!DTRACEACT_ISAGG(tap->dtad_kind))
207 206 continue;
208 207
209 208 dnerror(dnp, D_AGG_COMM, "aggregating actions "
210 209 "may not follow commit( )\n");
211 210 }
212 211
213 212 commit = 1;
214 213 continue;
215 214 }
216 215
217 216 if (ap->dtad_kind == DTRACEACT_SPECULATE) {
218 217 if (speculate) {
219 218 dnerror(dnp, D_SPEC_SPEC, "speculate( ) may "
220 219 "not follow speculate( )\n");
221 220 }
222 221
223 222 if (commit) {
224 223 dnerror(dnp, D_SPEC_COMM, "speculate( ) may "
225 224 "not follow commit( )\n");
226 225 }
227 226
228 227 if (datarec) {
229 228 dnerror(dnp, D_SPEC_DREC, "speculate( ) may "
230 229 "not follow data-recording action(s)\n");
231 230 }
232 231
233 232 speculate = 1;
234 233 continue;
235 234 }
236 235
237 236 if (DTRACEACT_ISAGG(ap->dtad_kind)) {
238 237 if (speculate) {
239 238 dnerror(dnp, D_AGG_SPEC, "aggregating actions "
240 239 "may not follow speculate( )\n");
241 240 }
242 241
243 242 datarec = 1;
244 243 continue;
245 244 }
246 245
247 246 if (speculate) {
248 247 if (dt_action_destructive(ap)) {
249 248 dnerror(dnp, D_ACT_SPEC, "destructive actions "
250 249 "may not follow speculate( )\n");
251 250 }
252 251
253 252 if (ap->dtad_kind == DTRACEACT_EXIT) {
254 253 dnerror(dnp, D_EXIT_SPEC, "exit( ) may not "
255 254 "follow speculate( )\n");
256 255 }
257 256 }
258 257
259 258 /*
260 259 * Exclude all non data-recording actions.
261 260 */
262 261 if (dt_action_destructive(ap) ||
263 262 ap->dtad_kind == DTRACEACT_DISCARD)
264 263 continue;
265 264
266 265 if (ap->dtad_kind == DTRACEACT_DIFEXPR &&
267 266 ap->dtad_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_CTF &&
268 267 ap->dtad_difo->dtdo_rtype.dtdt_size == 0)
269 268 continue;
270 269
271 270 if (commit) {
272 271 dnerror(dnp, D_DREC_COMM, "data-recording actions "
273 272 "may not follow commit( )\n");
274 273 }
275 274
276 275 if (!speculate)
277 276 datarec = 1;
278 277 }
279 278
280 279 if (dtrace_stmt_add(yypcb->pcb_hdl, yypcb->pcb_prog, sdp) != 0)
281 280 longjmp(yypcb->pcb_jmpbuf, dtrace_errno(yypcb->pcb_hdl));
282 281
283 282 if (yypcb->pcb_stmt == sdp)
284 283 yypcb->pcb_stmt = NULL;
285 284 }
286 285
287 286 /*
288 287 * For the first element of an aggregation tuple or for printa(), we create a
289 288 * simple DIF program that simply returns the immediate value that is the ID
290 289 * of the aggregation itself. This could be optimized in the future by
291 290 * creating a new in-kernel dtad_kind that just returns an integer.
292 291 */
293 292 static void
294 293 dt_action_difconst(dtrace_actdesc_t *ap, uint_t id, dtrace_actkind_t kind)
295 294 {
296 295 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
297 296 dtrace_difo_t *dp = dt_zalloc(dtp, sizeof (dtrace_difo_t));
298 297
299 298 if (dp == NULL)
300 299 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
301 300
302 301 dp->dtdo_buf = dt_alloc(dtp, sizeof (dif_instr_t) * 2);
303 302 dp->dtdo_inttab = dt_alloc(dtp, sizeof (uint64_t));
304 303
305 304 if (dp->dtdo_buf == NULL || dp->dtdo_inttab == NULL) {
306 305 dt_difo_free(dtp, dp);
307 306 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
308 307 }
309 308
310 309 dp->dtdo_buf[0] = DIF_INSTR_SETX(0, 1); /* setx DIF_INTEGER[0], %r1 */
311 310 dp->dtdo_buf[1] = DIF_INSTR_RET(1); /* ret %r1 */
312 311 dp->dtdo_len = 2;
313 312 dp->dtdo_inttab[0] = id;
314 313 dp->dtdo_intlen = 1;
315 314 dp->dtdo_rtype = dt_int_rtype;
316 315
317 316 ap->dtad_difo = dp;
318 317 ap->dtad_kind = kind;
319 318 }
320 319
321 320 static void
322 321 dt_action_clear(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
323 322 {
324 323 dt_ident_t *aid;
325 324 dtrace_actdesc_t *ap;
326 325 dt_node_t *anp;
327 326
328 327 char n[DT_TYPE_NAMELEN];
329 328 int argc = 0;
330 329
331 330 for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
332 331 argc++; /* count up arguments for error messages below */
333 332
334 333 if (argc != 1) {
335 334 dnerror(dnp, D_CLEAR_PROTO,
336 335 "%s( ) prototype mismatch: %d args passed, 1 expected\n",
337 336 dnp->dn_ident->di_name, argc);
338 337 }
339 338
340 339 anp = dnp->dn_args;
341 340 assert(anp != NULL);
342 341
343 342 if (anp->dn_kind != DT_NODE_AGG) {
344 343 dnerror(dnp, D_CLEAR_AGGARG,
345 344 "%s( ) argument #1 is incompatible with prototype:\n"
346 345 "\tprototype: aggregation\n\t argument: %s\n",
347 346 dnp->dn_ident->di_name,
348 347 dt_node_type_name(anp, n, sizeof (n)));
349 348 }
350 349
351 350 aid = anp->dn_ident;
352 351
353 352 if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
354 353 dnerror(dnp, D_CLEAR_AGGBAD,
355 354 "undefined aggregation: @%s\n", aid->di_name);
356 355 }
357 356
358 357 ap = dt_stmt_action(dtp, sdp);
359 358 dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
360 359 ap->dtad_arg = DT_ACT_CLEAR;
361 360 }
362 361
363 362 static void
364 363 dt_action_normalize(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
365 364 {
366 365 dt_ident_t *aid;
367 366 dtrace_actdesc_t *ap;
368 367 dt_node_t *anp, *normal;
369 368 int denormal = (strcmp(dnp->dn_ident->di_name, "denormalize") == 0);
370 369
371 370 char n[DT_TYPE_NAMELEN];
372 371 int argc = 0;
373 372
374 373 for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
375 374 argc++; /* count up arguments for error messages below */
376 375
377 376 if ((denormal && argc != 1) || (!denormal && argc != 2)) {
378 377 dnerror(dnp, D_NORMALIZE_PROTO,
379 378 "%s( ) prototype mismatch: %d args passed, %d expected\n",
380 379 dnp->dn_ident->di_name, argc, denormal ? 1 : 2);
381 380 }
382 381
383 382 anp = dnp->dn_args;
384 383 assert(anp != NULL);
385 384
386 385 if (anp->dn_kind != DT_NODE_AGG) {
387 386 dnerror(dnp, D_NORMALIZE_AGGARG,
388 387 "%s( ) argument #1 is incompatible with prototype:\n"
389 388 "\tprototype: aggregation\n\t argument: %s\n",
390 389 dnp->dn_ident->di_name,
391 390 dt_node_type_name(anp, n, sizeof (n)));
392 391 }
393 392
394 393 if ((normal = anp->dn_list) != NULL && !dt_node_is_scalar(normal)) {
395 394 dnerror(dnp, D_NORMALIZE_SCALAR,
396 395 "%s( ) argument #2 must be of scalar type\n",
397 396 dnp->dn_ident->di_name);
398 397 }
399 398
400 399 aid = anp->dn_ident;
401 400
402 401 if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
403 402 dnerror(dnp, D_NORMALIZE_AGGBAD,
404 403 "undefined aggregation: @%s\n", aid->di_name);
405 404 }
406 405
407 406 ap = dt_stmt_action(dtp, sdp);
408 407 dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
409 408
410 409 if (denormal) {
411 410 ap->dtad_arg = DT_ACT_DENORMALIZE;
412 411 return;
413 412 }
414 413
415 414 ap->dtad_arg = DT_ACT_NORMALIZE;
416 415
417 416 assert(normal != NULL);
418 417 ap = dt_stmt_action(dtp, sdp);
419 418 dt_cg(yypcb, normal);
420 419
421 420 ap->dtad_difo = dt_as(yypcb);
422 421 ap->dtad_kind = DTRACEACT_LIBACT;
423 422 ap->dtad_arg = DT_ACT_NORMALIZE;
424 423 }
425 424
426 425 static void
427 426 dt_action_trunc(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
428 427 {
429 428 dt_ident_t *aid;
430 429 dtrace_actdesc_t *ap;
431 430 dt_node_t *anp, *trunc;
432 431
433 432 char n[DT_TYPE_NAMELEN];
434 433 int argc = 0;
435 434
436 435 for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
437 436 argc++; /* count up arguments for error messages below */
438 437
439 438 if (argc > 2 || argc < 1) {
440 439 dnerror(dnp, D_TRUNC_PROTO,
441 440 "%s( ) prototype mismatch: %d args passed, %s expected\n",
442 441 dnp->dn_ident->di_name, argc,
443 442 argc < 1 ? "at least 1" : "no more than 2");
444 443 }
445 444
446 445 anp = dnp->dn_args;
447 446 assert(anp != NULL);
448 447 trunc = anp->dn_list;
449 448
450 449 if (anp->dn_kind != DT_NODE_AGG) {
451 450 dnerror(dnp, D_TRUNC_AGGARG,
452 451 "%s( ) argument #1 is incompatible with prototype:\n"
453 452 "\tprototype: aggregation\n\t argument: %s\n",
454 453 dnp->dn_ident->di_name,
455 454 dt_node_type_name(anp, n, sizeof (n)));
456 455 }
457 456
458 457 if (argc == 2) {
459 458 assert(trunc != NULL);
460 459 if (!dt_node_is_scalar(trunc)) {
461 460 dnerror(dnp, D_TRUNC_SCALAR,
462 461 "%s( ) argument #2 must be of scalar type\n",
463 462 dnp->dn_ident->di_name);
464 463 }
465 464 }
466 465
467 466 aid = anp->dn_ident;
468 467
469 468 if (aid->di_gen == dtp->dt_gen && !(aid->di_flags & DT_IDFLG_MOD)) {
470 469 dnerror(dnp, D_TRUNC_AGGBAD,
471 470 "undefined aggregation: @%s\n", aid->di_name);
472 471 }
473 472
474 473 ap = dt_stmt_action(dtp, sdp);
475 474 dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_LIBACT);
476 475 ap->dtad_arg = DT_ACT_TRUNC;
477 476
478 477 ap = dt_stmt_action(dtp, sdp);
479 478
480 479 if (argc == 1) {
481 480 dt_action_difconst(ap, 0, DTRACEACT_LIBACT);
482 481 } else {
483 482 assert(trunc != NULL);
484 483 dt_cg(yypcb, trunc);
485 484 ap->dtad_difo = dt_as(yypcb);
486 485 ap->dtad_kind = DTRACEACT_LIBACT;
487 486 }
488 487
489 488 ap->dtad_arg = DT_ACT_TRUNC;
490 489 }
491 490
492 491 static void
493 492 dt_action_printa(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
494 493 {
495 494 dt_ident_t *aid, *fid;
496 495 dtrace_actdesc_t *ap;
497 496 const char *format;
498 497 dt_node_t *anp, *proto = NULL;
499 498
500 499 char n[DT_TYPE_NAMELEN];
501 500 int argc = 0, argr = 0;
502 501
503 502 for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
504 503 argc++; /* count up arguments for error messages below */
505 504
506 505 switch (dnp->dn_args->dn_kind) {
507 506 case DT_NODE_STRING:
508 507 format = dnp->dn_args->dn_string;
509 508 anp = dnp->dn_args->dn_list;
510 509 argr = 2;
511 510 break;
512 511 case DT_NODE_AGG:
513 512 format = NULL;
514 513 anp = dnp->dn_args;
515 514 argr = 1;
516 515 break;
517 516 default:
518 517 format = NULL;
519 518 anp = dnp->dn_args;
520 519 argr = 1;
521 520 }
522 521
523 522 if (argc < argr) {
524 523 dnerror(dnp, D_PRINTA_PROTO,
525 524 "%s( ) prototype mismatch: %d args passed, %d expected\n",
526 525 dnp->dn_ident->di_name, argc, argr);
527 526 }
528 527
529 528 assert(anp != NULL);
530 529
531 530 while (anp != NULL) {
532 531 if (anp->dn_kind != DT_NODE_AGG) {
533 532 dnerror(dnp, D_PRINTA_AGGARG,
534 533 "%s( ) argument #%d is incompatible with "
535 534 "prototype:\n\tprototype: aggregation\n"
536 535 "\t argument: %s\n", dnp->dn_ident->di_name, argr,
537 536 dt_node_type_name(anp, n, sizeof (n)));
538 537 }
539 538
540 539 aid = anp->dn_ident;
541 540 fid = aid->di_iarg;
542 541
543 542 if (aid->di_gen == dtp->dt_gen &&
544 543 !(aid->di_flags & DT_IDFLG_MOD)) {
545 544 dnerror(dnp, D_PRINTA_AGGBAD,
546 545 "undefined aggregation: @%s\n", aid->di_name);
547 546 }
548 547
549 548 /*
550 549 * If we have multiple aggregations, we must be sure that
551 550 * their key signatures match.
552 551 */
553 552 if (proto != NULL) {
554 553 dt_printa_validate(proto, anp);
555 554 } else {
556 555 proto = anp;
557 556 }
558 557
559 558 if (format != NULL) {
560 559 yylineno = dnp->dn_line;
561 560
562 561 sdp->dtsd_fmtdata =
563 562 dt_printf_create(yypcb->pcb_hdl, format);
564 563 dt_printf_validate(sdp->dtsd_fmtdata,
565 564 DT_PRINTF_AGGREGATION, dnp->dn_ident, 1,
566 565 fid->di_id, ((dt_idsig_t *)aid->di_data)->dis_args);
567 566 format = NULL;
568 567 }
569 568
570 569 ap = dt_stmt_action(dtp, sdp);
571 570 dt_action_difconst(ap, anp->dn_ident->di_id, DTRACEACT_PRINTA);
572 571
573 572 anp = anp->dn_list;
574 573 argr++;
575 574 }
576 575 }
577 576
578 577 static void
579 578 dt_action_printflike(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp,
580 579 dtrace_actkind_t kind)
581 580 {
582 581 dt_node_t *anp, *arg1;
583 582 dtrace_actdesc_t *ap = NULL;
584 583 char n[DT_TYPE_NAMELEN], *str;
585 584
586 585 assert(DTRACEACT_ISPRINTFLIKE(kind));
587 586
588 587 if (dnp->dn_args->dn_kind != DT_NODE_STRING) {
589 588 dnerror(dnp, D_PRINTF_ARG_FMT,
590 589 "%s( ) argument #1 is incompatible with prototype:\n"
591 590 "\tprototype: string constant\n\t argument: %s\n",
592 591 dnp->dn_ident->di_name,
593 592 dt_node_type_name(dnp->dn_args, n, sizeof (n)));
594 593 }
595 594
596 595 arg1 = dnp->dn_args->dn_list;
597 596 yylineno = dnp->dn_line;
598 597 str = dnp->dn_args->dn_string;
599 598
600 599
601 600 /*
602 601 * If this is an freopen(), we use an empty string to denote that
603 602 * stdout should be restored. For other printf()-like actions, an
604 603 * empty format string is illegal: an empty format string would
605 604 * result in malformed DOF, and the compiler thus flags an empty
606 605 * format string as a compile-time error. To avoid propagating the
607 606 * freopen() special case throughout the system, we simply transpose
608 607 * an empty string into a sentinel string (DT_FREOPEN_RESTORE) that
609 608 * denotes that stdout should be restored.
610 609 */
611 610 if (kind == DTRACEACT_FREOPEN) {
612 611 if (strcmp(str, DT_FREOPEN_RESTORE) == 0) {
613 612 /*
614 613 * Our sentinel is always an invalid argument to
615 614 * freopen(), but if it's been manually specified, we
616 615 * must fail now instead of when the freopen() is
617 616 * actually evaluated.
618 617 */
619 618 dnerror(dnp, D_FREOPEN_INVALID,
620 619 "%s( ) argument #1 cannot be \"%s\"\n",
621 620 dnp->dn_ident->di_name, DT_FREOPEN_RESTORE);
622 621 }
623 622
624 623 if (str[0] == '\0')
625 624 str = DT_FREOPEN_RESTORE;
626 625 }
627 626
628 627 sdp->dtsd_fmtdata = dt_printf_create(dtp, str);
629 628
630 629 dt_printf_validate(sdp->dtsd_fmtdata, DT_PRINTF_EXACTLEN,
631 630 dnp->dn_ident, 1, DTRACEACT_AGGREGATION, arg1);
632 631
633 632 if (arg1 == NULL) {
634 633 dif_instr_t *dbuf;
635 634 dtrace_difo_t *dp;
636 635
637 636 if ((dbuf = dt_alloc(dtp, sizeof (dif_instr_t))) == NULL ||
638 637 (dp = dt_zalloc(dtp, sizeof (dtrace_difo_t))) == NULL) {
639 638 dt_free(dtp, dbuf);
640 639 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
641 640 }
642 641
643 642 dbuf[0] = DIF_INSTR_RET(DIF_REG_R0); /* ret %r0 */
644 643
645 644 dp->dtdo_buf = dbuf;
646 645 dp->dtdo_len = 1;
647 646 dp->dtdo_rtype = dt_int_rtype;
648 647
649 648 ap = dt_stmt_action(dtp, sdp);
650 649 ap->dtad_difo = dp;
651 650 ap->dtad_kind = kind;
652 651 return;
653 652 }
654 653
655 654 for (anp = arg1; anp != NULL; anp = anp->dn_list) {
656 655 ap = dt_stmt_action(dtp, sdp);
657 656 dt_cg(yypcb, anp);
658 657 ap->dtad_difo = dt_as(yypcb);
659 658 ap->dtad_kind = kind;
660 659 }
661 660 }
662 661
663 662 static void
664 663 dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
665 664 {
666 665 int ctflib;
667 666
668 667 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
669 668 boolean_t istrace = (dnp->dn_ident->di_id == DT_ACT_TRACE);
670 669 const char *act = istrace ? "trace" : "print";
671 670
672 671 if (dt_node_is_void(dnp->dn_args)) {
673 672 dnerror(dnp->dn_args, istrace ? D_TRACE_VOID : D_PRINT_VOID,
674 673 "%s( ) may not be applied to a void expression\n", act);
675 674 }
676 675
677 676 if (dt_node_resolve(dnp->dn_args, DT_IDENT_XLPTR) != NULL) {
678 677 dnerror(dnp->dn_args, istrace ? D_TRACE_DYN : D_PRINT_DYN,
679 678 "%s( ) may not be applied to a translated pointer\n", act);
680 679 }
681 680
682 681 if (dnp->dn_args->dn_kind == DT_NODE_AGG) {
683 682 dnerror(dnp->dn_args, istrace ? D_TRACE_AGG : D_PRINT_AGG,
684 683 "%s( ) may not be applied to an aggregation%s\n", act,
685 684 istrace ? "" : " -- did you mean printa()?");
686 685 }
687 686
688 687 dt_cg(yypcb, dnp->dn_args);
689 688
690 689 /*
691 690 * The print() action behaves identically to trace(), except that it
692 691 * stores the CTF type of the argument (if present) within the DOF for
693 692 * the DIFEXPR action. To do this, we set the 'dtsd_strdata' to point
694 693 * to the fully-qualified CTF type ID for the result of the DIF
695 694 * action. We use the ID instead of the name to handles complex types
696 695 * like arrays and function pointers that can't be resolved by
697 696 * ctf_type_lookup(). This is later processed by dtrace_dof_create()
698 697 * and turned into a reference into the string table so that we can
699 698 * get the type information when we process the data after the fact. In
700 699 * the case where we are referring to userland CTF data, we also need to
701 700 * to identify which ctf container in question we care about and encode
702 701 * that within the name.
703 702 */
704 703 if (dnp->dn_ident->di_id == DT_ACT_PRINT) {
705 704 dt_node_t *dret;
706 705 size_t n;
707 706 dt_module_t *dmp;
708 707
709 708 dret = yypcb->pcb_dret;
710 709 dmp = dt_module_lookup_by_ctf(dtp, dret->dn_ctfp);
711 710
712 711 if (dmp->dm_pid != 0) {
713 712 ctflib = dt_module_getlibid(dtp, dmp, dret->dn_ctfp);
714 713 assert(ctflib >= 0);
715 714 n = snprintf(NULL, 0, "%s`%d`%d", dmp->dm_name,
716 715 ctflib, dret->dn_type) + 1;
717 716 } else {
718 717 n = snprintf(NULL, 0, "%s`%d", dmp->dm_name,
719 718 dret->dn_type) + 1;
720 719 }
721 720 sdp->dtsd_strdata = dt_alloc(dtp, n);
722 721 if (sdp->dtsd_strdata == NULL)
723 722 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
724 723 if (dmp->dm_pid != 0) {
725 724 (void) snprintf(sdp->dtsd_strdata, n, "%s`%d`%d",
726 725 dmp->dm_name, ctflib, dret->dn_type);
727 726 } else {
728 727 (void) snprintf(sdp->dtsd_strdata, n, "%s`%d",
729 728 dmp->dm_name, dret->dn_type);
730 729 }
731 730 }
732 731
733 732 ap->dtad_difo = dt_as(yypcb);
734 733 ap->dtad_kind = DTRACEACT_DIFEXPR;
735 734 }
736 735
737 736 static void
738 737 dt_action_tracemem(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
739 738 {
740 739 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
741 740
742 741 dt_node_t *addr = dnp->dn_args;
743 742 dt_node_t *max = dnp->dn_args->dn_list;
744 743 dt_node_t *size;
745 744
746 745 char n[DT_TYPE_NAMELEN];
747 746
748 747 if (dt_node_is_integer(addr) == 0 && dt_node_is_pointer(addr) == 0) {
749 748 dnerror(addr, D_TRACEMEM_ADDR,
750 749 "tracemem( ) argument #1 is incompatible with "
751 750 "prototype:\n\tprototype: pointer or integer\n"
752 751 "\t argument: %s\n",
753 752 dt_node_type_name(addr, n, sizeof (n)));
754 753 }
755 754
756 755 if (dt_node_is_posconst(max) == 0) {
757 756 dnerror(max, D_TRACEMEM_SIZE, "tracemem( ) argument #2 must "
758 757 "be a non-zero positive integral constant expression\n");
759 758 }
760 759
761 760 if ((size = max->dn_list) != NULL) {
762 761 if (size->dn_list != NULL) {
763 762 dnerror(size, D_TRACEMEM_ARGS, "tracemem ( ) prototype "
764 763 "mismatch: expected at most 3 args\n");
765 764 }
766 765
767 766 if (!dt_node_is_scalar(size)) {
768 767 dnerror(size, D_TRACEMEM_DYNSIZE, "tracemem ( ) "
769 768 "dynamic size (argument #3) must be of "
770 769 "scalar type\n");
771 770 }
772 771
773 772 dt_cg(yypcb, size);
774 773 ap->dtad_difo = dt_as(yypcb);
775 774 ap->dtad_difo->dtdo_rtype = dt_int_rtype;
776 775 ap->dtad_kind = DTRACEACT_TRACEMEM_DYNSIZE;
777 776
778 777 ap = dt_stmt_action(dtp, sdp);
779 778 }
780 779
781 780 dt_cg(yypcb, addr);
782 781 ap->dtad_difo = dt_as(yypcb);
783 782 ap->dtad_kind = DTRACEACT_TRACEMEM;
784 783
785 784 ap->dtad_difo->dtdo_rtype.dtdt_flags |= DIF_TF_BYREF;
786 785 ap->dtad_difo->dtdo_rtype.dtdt_size = max->dn_value;
787 786 }
788 787
789 788 static void
790 789 dt_action_stack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *arg0)
791 790 {
792 791 ap->dtad_kind = DTRACEACT_STACK;
793 792
794 793 if (dtp->dt_options[DTRACEOPT_STACKFRAMES] != DTRACEOPT_UNSET) {
795 794 ap->dtad_arg = dtp->dt_options[DTRACEOPT_STACKFRAMES];
796 795 } else {
797 796 ap->dtad_arg = 0;
798 797 }
799 798
800 799 if (arg0 != NULL) {
801 800 if (arg0->dn_list != NULL) {
802 801 dnerror(arg0, D_STACK_PROTO, "stack( ) prototype "
803 802 "mismatch: too many arguments\n");
804 803 }
805 804
806 805 if (dt_node_is_posconst(arg0) == 0) {
807 806 dnerror(arg0, D_STACK_SIZE, "stack( ) size must be a "
808 807 "non-zero positive integral constant expression\n");
809 808 }
810 809
811 810 ap->dtad_arg = arg0->dn_value;
812 811 }
813 812 }
814 813
815 814 static void
816 815 dt_action_stack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
817 816 {
818 817 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
819 818 dt_action_stack_args(dtp, ap, dnp->dn_args);
820 819 }
821 820
822 821 static void
823 822 dt_action_ustack_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap, dt_node_t *dnp)
824 823 {
825 824 uint32_t nframes = 0;
826 825 uint32_t strsize = 0; /* default string table size */
827 826 dt_node_t *arg0 = dnp->dn_args;
828 827 dt_node_t *arg1 = arg0 != NULL ? arg0->dn_list : NULL;
829 828
830 829 assert(dnp->dn_ident->di_id == DT_ACT_JSTACK ||
831 830 dnp->dn_ident->di_id == DT_ACT_USTACK);
832 831
833 832 if (dnp->dn_ident->di_id == DT_ACT_JSTACK) {
834 833 if (dtp->dt_options[DTRACEOPT_JSTACKFRAMES] != DTRACEOPT_UNSET)
835 834 nframes = dtp->dt_options[DTRACEOPT_JSTACKFRAMES];
836 835
837 836 if (dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE] != DTRACEOPT_UNSET)
838 837 strsize = dtp->dt_options[DTRACEOPT_JSTACKSTRSIZE];
839 838
840 839 ap->dtad_kind = DTRACEACT_JSTACK;
841 840 } else {
842 841 assert(dnp->dn_ident->di_id == DT_ACT_USTACK);
843 842
844 843 if (dtp->dt_options[DTRACEOPT_USTACKFRAMES] != DTRACEOPT_UNSET)
845 844 nframes = dtp->dt_options[DTRACEOPT_USTACKFRAMES];
846 845
847 846 ap->dtad_kind = DTRACEACT_USTACK;
848 847 }
849 848
850 849 if (arg0 != NULL) {
851 850 if (!dt_node_is_posconst(arg0)) {
852 851 dnerror(arg0, D_USTACK_FRAMES, "ustack( ) argument #1 "
853 852 "must be a non-zero positive integer constant\n");
854 853 }
855 854 nframes = (uint32_t)arg0->dn_value;
856 855 }
857 856
858 857 if (arg1 != NULL) {
859 858 if (arg1->dn_kind != DT_NODE_INT ||
860 859 ((arg1->dn_flags & DT_NF_SIGNED) &&
861 860 (int64_t)arg1->dn_value < 0)) {
862 861 dnerror(arg1, D_USTACK_STRSIZE, "ustack( ) argument #2 "
863 862 "must be a positive integer constant\n");
864 863 }
865 864
866 865 if (arg1->dn_list != NULL) {
867 866 dnerror(arg1, D_USTACK_PROTO, "ustack( ) prototype "
868 867 "mismatch: too many arguments\n");
869 868 }
870 869
871 870 strsize = (uint32_t)arg1->dn_value;
872 871 }
873 872
874 873 ap->dtad_arg = DTRACE_USTACK_ARG(nframes, strsize);
875 874 }
876 875
877 876 static void
878 877 dt_action_ustack(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
879 878 {
880 879 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
881 880 dt_action_ustack_args(dtp, ap, dnp);
882 881 }
883 882
884 883 static void
885 884 dt_action_setopt(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
886 885 {
887 886 dtrace_actdesc_t *ap;
888 887 dt_node_t *arg0, *arg1;
889 888
890 889 /*
891 890 * The prototype guarantees that we are called with either one or
892 891 * two arguments, and that any arguments that are present are strings.
893 892 */
894 893 arg0 = dnp->dn_args;
895 894 arg1 = arg0->dn_list;
896 895
897 896 ap = dt_stmt_action(dtp, sdp);
898 897 dt_cg(yypcb, arg0);
899 898 ap->dtad_difo = dt_as(yypcb);
900 899 ap->dtad_kind = DTRACEACT_LIBACT;
901 900 ap->dtad_arg = DT_ACT_SETOPT;
902 901
903 902 ap = dt_stmt_action(dtp, sdp);
904 903
905 904 if (arg1 == NULL) {
906 905 dt_action_difconst(ap, 0, DTRACEACT_LIBACT);
907 906 } else {
908 907 dt_cg(yypcb, arg1);
909 908 ap->dtad_difo = dt_as(yypcb);
910 909 ap->dtad_kind = DTRACEACT_LIBACT;
911 910 }
912 911
913 912 ap->dtad_arg = DT_ACT_SETOPT;
914 913 }
915 914
916 915 /*ARGSUSED*/
917 916 static void
918 917 dt_action_symmod_args(dtrace_hdl_t *dtp, dtrace_actdesc_t *ap,
919 918 dt_node_t *dnp, dtrace_actkind_t kind)
920 919 {
921 920 assert(kind == DTRACEACT_SYM || kind == DTRACEACT_MOD ||
922 921 kind == DTRACEACT_USYM || kind == DTRACEACT_UMOD ||
923 922 kind == DTRACEACT_UADDR);
924 923
925 924 dt_cg(yypcb, dnp);
926 925 ap->dtad_difo = dt_as(yypcb);
927 926 ap->dtad_kind = kind;
928 927 ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (uint64_t);
929 928 }
930 929
931 930 static void
932 931 dt_action_symmod(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp,
933 932 dtrace_actkind_t kind)
934 933 {
935 934 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
936 935 dt_action_symmod_args(dtp, ap, dnp->dn_args, kind);
937 936 }
938 937
939 938 /*ARGSUSED*/
940 939 static void
941 940 dt_action_ftruncate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
942 941 {
943 942 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
944 943
945 944 /*
946 945 * Library actions need a DIFO that serves as an argument. As
947 946 * ftruncate() doesn't take an argument, we generate the constant 0
948 947 * in a DIFO; this constant will be ignored when the ftruncate() is
949 948 * processed.
950 949 */
951 950 dt_action_difconst(ap, 0, DTRACEACT_LIBACT);
952 951 ap->dtad_arg = DT_ACT_FTRUNCATE;
953 952 }
954 953
955 954 /*ARGSUSED*/
956 955 static void
957 956 dt_action_stop(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
958 957 {
959 958 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
960 959
961 960 ap->dtad_kind = DTRACEACT_STOP;
962 961 ap->dtad_arg = 0;
963 962 }
964 963
965 964 /*ARGSUSED*/
966 965 static void
967 966 dt_action_breakpoint(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
968 967 {
969 968 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
970 969
971 970 ap->dtad_kind = DTRACEACT_BREAKPOINT;
972 971 ap->dtad_arg = 0;
973 972 }
974 973
975 974 /*ARGSUSED*/
976 975 static void
977 976 dt_action_panic(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
978 977 {
979 978 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
980 979
981 980 ap->dtad_kind = DTRACEACT_PANIC;
982 981 ap->dtad_arg = 0;
983 982 }
984 983
985 984 static void
986 985 dt_action_chill(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
987 986 {
988 987 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
989 988
990 989 dt_cg(yypcb, dnp->dn_args);
991 990 ap->dtad_difo = dt_as(yypcb);
992 991 ap->dtad_kind = DTRACEACT_CHILL;
993 992 }
994 993
995 994 static void
996 995 dt_action_raise(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
997 996 {
998 997 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
999 998
1000 999 dt_cg(yypcb, dnp->dn_args);
1001 1000 ap->dtad_difo = dt_as(yypcb);
1002 1001 ap->dtad_kind = DTRACEACT_RAISE;
1003 1002 }
1004 1003
1005 1004 static void
1006 1005 dt_action_exit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1007 1006 {
1008 1007 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
1009 1008
1010 1009 dt_cg(yypcb, dnp->dn_args);
1011 1010 ap->dtad_difo = dt_as(yypcb);
1012 1011 ap->dtad_kind = DTRACEACT_EXIT;
1013 1012 ap->dtad_difo->dtdo_rtype.dtdt_size = sizeof (int);
1014 1013 }
1015 1014
1016 1015 static void
1017 1016 dt_action_speculate(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1018 1017 {
1019 1018 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
1020 1019
1021 1020 dt_cg(yypcb, dnp->dn_args);
1022 1021 ap->dtad_difo = dt_as(yypcb);
1023 1022 ap->dtad_kind = DTRACEACT_SPECULATE;
1024 1023 }
1025 1024
1026 1025 static void
1027 1026 dt_action_commit(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1028 1027 {
1029 1028 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
1030 1029
1031 1030 dt_cg(yypcb, dnp->dn_args);
1032 1031 ap->dtad_difo = dt_as(yypcb);
1033 1032 ap->dtad_kind = DTRACEACT_COMMIT;
1034 1033 }
1035 1034
1036 1035 static void
1037 1036 dt_action_discard(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1038 1037 {
1039 1038 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
1040 1039
1041 1040 dt_cg(yypcb, dnp->dn_args);
1042 1041 ap->dtad_difo = dt_as(yypcb);
1043 1042 ap->dtad_kind = DTRACEACT_DISCARD;
1044 1043 }
1045 1044
1046 1045 static void
1047 1046 dt_compile_fun(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1048 1047 {
1049 1048 switch (dnp->dn_expr->dn_ident->di_id) {
1050 1049 case DT_ACT_BREAKPOINT:
1051 1050 dt_action_breakpoint(dtp, dnp->dn_expr, sdp);
1052 1051 break;
1053 1052 case DT_ACT_CHILL:
1054 1053 dt_action_chill(dtp, dnp->dn_expr, sdp);
1055 1054 break;
1056 1055 case DT_ACT_CLEAR:
1057 1056 dt_action_clear(dtp, dnp->dn_expr, sdp);
1058 1057 break;
1059 1058 case DT_ACT_COMMIT:
1060 1059 dt_action_commit(dtp, dnp->dn_expr, sdp);
1061 1060 break;
1062 1061 case DT_ACT_DENORMALIZE:
1063 1062 dt_action_normalize(dtp, dnp->dn_expr, sdp);
1064 1063 break;
1065 1064 case DT_ACT_DISCARD:
1066 1065 dt_action_discard(dtp, dnp->dn_expr, sdp);
1067 1066 break;
1068 1067 case DT_ACT_EXIT:
1069 1068 dt_action_exit(dtp, dnp->dn_expr, sdp);
1070 1069 break;
1071 1070 case DT_ACT_FREOPEN:
1072 1071 dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_FREOPEN);
1073 1072 break;
1074 1073 case DT_ACT_FTRUNCATE:
1075 1074 dt_action_ftruncate(dtp, dnp->dn_expr, sdp);
1076 1075 break;
1077 1076 case DT_ACT_MOD:
1078 1077 dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_MOD);
1079 1078 break;
1080 1079 case DT_ACT_NORMALIZE:
1081 1080 dt_action_normalize(dtp, dnp->dn_expr, sdp);
1082 1081 break;
1083 1082 case DT_ACT_PANIC:
1084 1083 dt_action_panic(dtp, dnp->dn_expr, sdp);
1085 1084 break;
1086 1085 case DT_ACT_PRINT:
1087 1086 dt_action_trace(dtp, dnp->dn_expr, sdp);
1088 1087 break;
1089 1088 case DT_ACT_PRINTA:
1090 1089 dt_action_printa(dtp, dnp->dn_expr, sdp);
1091 1090 break;
1092 1091 case DT_ACT_PRINTF:
1093 1092 dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF);
1094 1093 break;
1095 1094 case DT_ACT_RAISE:
1096 1095 dt_action_raise(dtp, dnp->dn_expr, sdp);
1097 1096 break;
1098 1097 case DT_ACT_SETOPT:
1099 1098 dt_action_setopt(dtp, dnp->dn_expr, sdp);
1100 1099 break;
1101 1100 case DT_ACT_SPECULATE:
1102 1101 dt_action_speculate(dtp, dnp->dn_expr, sdp);
1103 1102 break;
1104 1103 case DT_ACT_STACK:
1105 1104 dt_action_stack(dtp, dnp->dn_expr, sdp);
1106 1105 break;
1107 1106 case DT_ACT_STOP:
1108 1107 dt_action_stop(dtp, dnp->dn_expr, sdp);
1109 1108 break;
1110 1109 case DT_ACT_SYM:
1111 1110 dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_SYM);
1112 1111 break;
1113 1112 case DT_ACT_SYSTEM:
1114 1113 dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM);
1115 1114 break;
1116 1115 case DT_ACT_TRACE:
1117 1116 dt_action_trace(dtp, dnp->dn_expr, sdp);
1118 1117 break;
1119 1118 case DT_ACT_TRACEMEM:
1120 1119 dt_action_tracemem(dtp, dnp->dn_expr, sdp);
1121 1120 break;
1122 1121 case DT_ACT_TRUNC:
1123 1122 dt_action_trunc(dtp, dnp->dn_expr, sdp);
1124 1123 break;
1125 1124 case DT_ACT_UADDR:
1126 1125 dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UADDR);
1127 1126 break;
1128 1127 case DT_ACT_UMOD:
1129 1128 dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_UMOD);
1130 1129 break;
1131 1130 case DT_ACT_USYM:
1132 1131 dt_action_symmod(dtp, dnp->dn_expr, sdp, DTRACEACT_USYM);
1133 1132 break;
1134 1133 case DT_ACT_USTACK:
1135 1134 case DT_ACT_JSTACK:
1136 1135 dt_action_ustack(dtp, dnp->dn_expr, sdp);
1137 1136 break;
1138 1137 default:
1139 1138 dnerror(dnp->dn_expr, D_UNKNOWN, "tracing function %s( ) is "
1140 1139 "not yet supported\n", dnp->dn_expr->dn_ident->di_name);
1141 1140 }
1142 1141 }
1143 1142
1144 1143 static void
1145 1144 dt_compile_exp(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1146 1145 {
1147 1146 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp);
1148 1147
1149 1148 dt_cg(yypcb, dnp->dn_expr);
1150 1149 ap->dtad_difo = dt_as(yypcb);
1151 1150 ap->dtad_difo->dtdo_rtype = dt_void_rtype;
1152 1151 ap->dtad_kind = DTRACEACT_DIFEXPR;
1153 1152 }
1154 1153
1155 1154 static void
1156 1155 dt_compile_agg(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp)
1157 1156 {
1158 1157 dt_ident_t *aid, *fid;
1159 1158 dt_node_t *anp, *incr = NULL;
1160 1159 dtrace_actdesc_t *ap;
1161 1160 uint_t n = 1, argmax;
1162 1161 uint64_t arg = 0;
1163 1162
1164 1163 /*
1165 1164 * If the aggregation has no aggregating function applied to it, then
1166 1165 * this statement has no effect. Flag this as a programming error.
1167 1166 */
1168 1167 if (dnp->dn_aggfun == NULL) {
1169 1168 dnerror(dnp, D_AGG_NULL, "expression has null effect: @%s\n",
1170 1169 dnp->dn_ident->di_name);
1171 1170 }
1172 1171
1173 1172 aid = dnp->dn_ident;
1174 1173 fid = dnp->dn_aggfun->dn_ident;
1175 1174
1176 1175 if (dnp->dn_aggfun->dn_args != NULL &&
1177 1176 dt_node_is_scalar(dnp->dn_aggfun->dn_args) == 0) {
1178 1177 dnerror(dnp->dn_aggfun, D_AGG_SCALAR, "%s( ) argument #1 must "
1179 1178 "be of scalar type\n", fid->di_name);
1180 1179 }
1181 1180
1182 1181 /*
1183 1182 * The ID of the aggregation itself is implicitly recorded as the first
1184 1183 * member of each aggregation tuple so we can distinguish them later.
1185 1184 */
1186 1185 ap = dt_stmt_action(dtp, sdp);
1187 1186 dt_action_difconst(ap, aid->di_id, DTRACEACT_DIFEXPR);
1188 1187
1189 1188 for (anp = dnp->dn_aggtup; anp != NULL; anp = anp->dn_list) {
1190 1189 ap = dt_stmt_action(dtp, sdp);
1191 1190 n++;
1192 1191
1193 1192 if (anp->dn_kind == DT_NODE_FUNC) {
1194 1193 if (anp->dn_ident->di_id == DT_ACT_STACK) {
1195 1194 dt_action_stack_args(dtp, ap, anp->dn_args);
1196 1195 continue;
1197 1196 }
1198 1197
1199 1198 if (anp->dn_ident->di_id == DT_ACT_USTACK ||
1200 1199 anp->dn_ident->di_id == DT_ACT_JSTACK) {
1201 1200 dt_action_ustack_args(dtp, ap, anp);
1202 1201 continue;
1203 1202 }
1204 1203
1205 1204 switch (anp->dn_ident->di_id) {
1206 1205 case DT_ACT_UADDR:
1207 1206 dt_action_symmod_args(dtp, ap,
1208 1207 anp->dn_args, DTRACEACT_UADDR);
1209 1208 continue;
1210 1209
1211 1210 case DT_ACT_USYM:
1212 1211 dt_action_symmod_args(dtp, ap,
1213 1212 anp->dn_args, DTRACEACT_USYM);
1214 1213 continue;
1215 1214
1216 1215 case DT_ACT_UMOD:
1217 1216 dt_action_symmod_args(dtp, ap,
1218 1217 anp->dn_args, DTRACEACT_UMOD);
1219 1218 continue;
1220 1219
1221 1220 case DT_ACT_SYM:
1222 1221 dt_action_symmod_args(dtp, ap,
1223 1222 anp->dn_args, DTRACEACT_SYM);
1224 1223 continue;
1225 1224
1226 1225 case DT_ACT_MOD:
1227 1226 dt_action_symmod_args(dtp, ap,
1228 1227 anp->dn_args, DTRACEACT_MOD);
1229 1228 continue;
1230 1229
1231 1230 default:
1232 1231 break;
1233 1232 }
1234 1233 }
1235 1234
1236 1235 dt_cg(yypcb, anp);
1237 1236 ap->dtad_difo = dt_as(yypcb);
1238 1237 ap->dtad_kind = DTRACEACT_DIFEXPR;
1239 1238 }
1240 1239
1241 1240 if (fid->di_id == DTRACEAGG_LQUANTIZE) {
1242 1241 /*
1243 1242 * For linear quantization, we have between two and four
1244 1243 * arguments in addition to the expression:
1245 1244 *
1246 1245 * arg1 => Base value
1247 1246 * arg2 => Limit value
1248 1247 * arg3 => Quantization level step size (defaults to 1)
1249 1248 * arg4 => Quantization increment value (defaults to 1)
1250 1249 */
1251 1250 dt_node_t *arg1 = dnp->dn_aggfun->dn_args->dn_list;
1252 1251 dt_node_t *arg2 = arg1->dn_list;
1253 1252 dt_node_t *arg3 = arg2->dn_list;
1254 1253 dt_idsig_t *isp;
1255 1254 uint64_t nlevels, step = 1, oarg;
1256 1255 int64_t baseval, limitval;
1257 1256
1258 1257 if (arg1->dn_kind != DT_NODE_INT) {
1259 1258 dnerror(arg1, D_LQUANT_BASETYPE, "lquantize( ) "
1260 1259 "argument #1 must be an integer constant\n");
1261 1260 }
1262 1261
1263 1262 baseval = (int64_t)arg1->dn_value;
1264 1263
1265 1264 if (baseval < INT32_MIN || baseval > INT32_MAX) {
1266 1265 dnerror(arg1, D_LQUANT_BASEVAL, "lquantize( ) "
1267 1266 "argument #1 must be a 32-bit quantity\n");
1268 1267 }
1269 1268
1270 1269 if (arg2->dn_kind != DT_NODE_INT) {
1271 1270 dnerror(arg2, D_LQUANT_LIMTYPE, "lquantize( ) "
1272 1271 "argument #2 must be an integer constant\n");
1273 1272 }
1274 1273
1275 1274 limitval = (int64_t)arg2->dn_value;
1276 1275
1277 1276 if (limitval < INT32_MIN || limitval > INT32_MAX) {
1278 1277 dnerror(arg2, D_LQUANT_LIMVAL, "lquantize( ) "
1279 1278 "argument #2 must be a 32-bit quantity\n");
1280 1279 }
1281 1280
1282 1281 if (limitval < baseval) {
1283 1282 dnerror(dnp, D_LQUANT_MISMATCH,
1284 1283 "lquantize( ) base (argument #1) must be less "
1285 1284 "than limit (argument #2)\n");
1286 1285 }
1287 1286
1288 1287 if (arg3 != NULL) {
1289 1288 if (!dt_node_is_posconst(arg3)) {
1290 1289 dnerror(arg3, D_LQUANT_STEPTYPE, "lquantize( ) "
1291 1290 "argument #3 must be a non-zero positive "
1292 1291 "integer constant\n");
1293 1292 }
1294 1293
1295 1294 if ((step = arg3->dn_value) > UINT16_MAX) {
1296 1295 dnerror(arg3, D_LQUANT_STEPVAL, "lquantize( ) "
1297 1296 "argument #3 must be a 16-bit quantity\n");
1298 1297 }
1299 1298 }
1300 1299
1301 1300 nlevels = (limitval - baseval) / step;
1302 1301
1303 1302 if (nlevels == 0) {
1304 1303 dnerror(dnp, D_LQUANT_STEPLARGE,
1305 1304 "lquantize( ) step (argument #3) too large: must "
1306 1305 "have at least one quantization level\n");
1307 1306 }
1308 1307
1309 1308 if (nlevels > UINT16_MAX) {
1310 1309 dnerror(dnp, D_LQUANT_STEPSMALL, "lquantize( ) step "
1311 1310 "(argument #3) too small: number of quantization "
1312 1311 "levels must be a 16-bit quantity\n");
1313 1312 }
1314 1313
1315 1314 arg = (step << DTRACE_LQUANTIZE_STEPSHIFT) |
1316 1315 (nlevels << DTRACE_LQUANTIZE_LEVELSHIFT) |
1317 1316 ((baseval << DTRACE_LQUANTIZE_BASESHIFT) &
1318 1317 DTRACE_LQUANTIZE_BASEMASK);
1319 1318
1320 1319 assert(arg != 0);
1321 1320
1322 1321 isp = (dt_idsig_t *)aid->di_data;
1323 1322
1324 1323 if (isp->dis_auxinfo == 0) {
1325 1324 /*
1326 1325 * This is the first time we've seen an lquantize()
1327 1326 * for this aggregation; we'll store our argument
1328 1327 * as the auxiliary signature information.
1329 1328 */
1330 1329 isp->dis_auxinfo = arg;
1331 1330 } else if ((oarg = isp->dis_auxinfo) != arg) {
1332 1331 /*
1333 1332 * If we have seen this lquantize() before and the
1334 1333 * argument doesn't match the original argument, pick
1335 1334 * the original argument apart to concisely report the
1336 1335 * mismatch.
1337 1336 */
1338 1337 int obaseval = DTRACE_LQUANTIZE_BASE(oarg);
1339 1338 int onlevels = DTRACE_LQUANTIZE_LEVELS(oarg);
1340 1339 int ostep = DTRACE_LQUANTIZE_STEP(oarg);
1341 1340
1342 1341 if (obaseval != baseval) {
1343 1342 dnerror(dnp, D_LQUANT_MATCHBASE, "lquantize( ) "
1344 1343 "base (argument #1) doesn't match previous "
1345 1344 "declaration: expected %d, found %d\n",
1346 1345 obaseval, (int)baseval);
1347 1346 }
1348 1347
1349 1348 if (onlevels * ostep != nlevels * step) {
1350 1349 dnerror(dnp, D_LQUANT_MATCHLIM, "lquantize( ) "
1351 1350 "limit (argument #2) doesn't match previous"
1352 1351 " declaration: expected %d, found %d\n",
1353 1352 obaseval + onlevels * ostep,
1354 1353 (int)baseval + (int)nlevels * (int)step);
1355 1354 }
1356 1355
1357 1356 if (ostep != step) {
1358 1357 dnerror(dnp, D_LQUANT_MATCHSTEP, "lquantize( ) "
1359 1358 "step (argument #3) doesn't match previous "
1360 1359 "declaration: expected %d, found %d\n",
1361 1360 ostep, (int)step);
1362 1361 }
1363 1362
1364 1363 /*
1365 1364 * We shouldn't be able to get here -- one of the
1366 1365 * parameters must be mismatched if the arguments
1367 1366 * didn't match.
1368 1367 */
1369 1368 assert(0);
1370 1369 }
1371 1370
1372 1371 incr = arg3 != NULL ? arg3->dn_list : NULL;
1373 1372 argmax = 5;
1374 1373 }
1375 1374
1376 1375 if (fid->di_id == DTRACEAGG_LLQUANTIZE) {
1377 1376 /*
1378 1377 * For log/linear quantizations, we have between one and five
1379 1378 * arguments in addition to the expression:
1380 1379 *
1381 1380 * arg1 => Factor
1382 1381 * arg2 => Low magnitude
1383 1382 * arg3 => High magnitude
1384 1383 * arg4 => Number of steps per magnitude
1385 1384 * arg5 => Quantization increment value (defaults to 1)
1386 1385 */
1387 1386 dt_node_t *llarg = dnp->dn_aggfun->dn_args->dn_list;
1388 1387 uint64_t oarg, order, v;
1389 1388 dt_idsig_t *isp;
1390 1389 int i;
1391 1390
1392 1391 struct {
1393 1392 char *str; /* string identifier */
1394 1393 int badtype; /* error on bad type */
1395 1394 int badval; /* error on bad value */
1396 1395 int mismatch; /* error on bad match */
1397 1396 int shift; /* shift value */
1398 1397 uint16_t value; /* value itself */
1399 1398 } args[] = {
1400 1399 { "factor", D_LLQUANT_FACTORTYPE,
1401 1400 D_LLQUANT_FACTORVAL, D_LLQUANT_FACTORMATCH,
1402 1401 DTRACE_LLQUANTIZE_FACTORSHIFT },
1403 1402 { "low magnitude", D_LLQUANT_LOWTYPE,
1404 1403 D_LLQUANT_LOWVAL, D_LLQUANT_LOWMATCH,
1405 1404 DTRACE_LLQUANTIZE_LOWSHIFT },
1406 1405 { "high magnitude", D_LLQUANT_HIGHTYPE,
1407 1406 D_LLQUANT_HIGHVAL, D_LLQUANT_HIGHMATCH,
1408 1407 DTRACE_LLQUANTIZE_HIGHSHIFT },
1409 1408 { "linear steps per magnitude", D_LLQUANT_NSTEPTYPE,
1410 1409 D_LLQUANT_NSTEPVAL, D_LLQUANT_NSTEPMATCH,
1411 1410 DTRACE_LLQUANTIZE_NSTEPSHIFT },
1412 1411 { NULL }
1413 1412 };
1414 1413
1415 1414 assert(arg == 0);
1416 1415
1417 1416 for (i = 0; args[i].str != NULL; i++) {
1418 1417 if (llarg->dn_kind != DT_NODE_INT) {
1419 1418 dnerror(llarg, args[i].badtype, "llquantize( ) "
1420 1419 "argument #%d (%s) must be an "
1421 1420 "integer constant\n", i + 1, args[i].str);
1422 1421 }
1423 1422
1424 1423 if ((uint64_t)llarg->dn_value > UINT16_MAX) {
1425 1424 dnerror(llarg, args[i].badval, "llquantize( ) "
1426 1425 "argument #%d (%s) must be an unsigned "
1427 1426 "16-bit quantity\n", i + 1, args[i].str);
1428 1427 }
1429 1428
1430 1429 args[i].value = (uint16_t)llarg->dn_value;
1431 1430
1432 1431 assert(!(arg & (UINT16_MAX << args[i].shift)));
1433 1432 arg |= ((uint64_t)args[i].value << args[i].shift);
1434 1433 llarg = llarg->dn_list;
1435 1434 }
1436 1435
1437 1436 assert(arg != 0);
1438 1437
1439 1438 if (args[0].value < 2) {
1440 1439 dnerror(dnp, D_LLQUANT_FACTORSMALL, "llquantize( ) "
1441 1440 "factor (argument #1) must be two or more\n");
1442 1441 }
1443 1442
1444 1443 if (args[1].value >= args[2].value) {
1445 1444 dnerror(dnp, D_LLQUANT_MAGRANGE, "llquantize( ) "
1446 1445 "high magnitude (argument #3) must be greater "
1447 1446 "than low magnitude (argument #2)\n");
1448 1447 }
1449 1448
1450 1449 if (args[3].value < args[0].value) {
1451 1450 dnerror(dnp, D_LLQUANT_FACTORNSTEPS, "llquantize( ) "
1452 1451 "factor (argument #1) must be less than or "
1453 1452 "equal to the number of linear steps per "
1454 1453 "magnitude (argument #4)\n");
1455 1454 }
1456 1455
1457 1456 for (v = args[0].value; v < args[3].value; v *= args[0].value)
1458 1457 continue;
1459 1458
1460 1459 if ((args[3].value % args[0].value) || (v % args[3].value)) {
1461 1460 dnerror(dnp, D_LLQUANT_FACTOREVEN, "llquantize( ) "
1462 1461 "factor (argument #1) must evenly divide the "
1463 1462 "number of steps per magnitude (argument #4), "
1464 1463 "and the number of steps per magnitude must evenly "
1465 1464 "divide a power of the factor\n");
1466 1465 }
1467 1466
1468 1467 for (i = 0, order = 1; i < args[2].value; i++) {
1469 1468 if (order * args[0].value > order) {
1470 1469 order *= args[0].value;
1471 1470 continue;
1472 1471 }
1473 1472
1474 1473 dnerror(dnp, D_LLQUANT_MAGTOOBIG, "llquantize( ) "
1475 1474 "factor (%d) raised to power of high magnitude "
1476 1475 "(%d) overflows 64-bits\n", args[0].value,
1477 1476 args[2].value);
1478 1477 }
1479 1478
1480 1479 isp = (dt_idsig_t *)aid->di_data;
1481 1480
1482 1481 if (isp->dis_auxinfo == 0) {
1483 1482 /*
1484 1483 * This is the first time we've seen an llquantize()
1485 1484 * for this aggregation; we'll store our argument
1486 1485 * as the auxiliary signature information.
1487 1486 */
1488 1487 isp->dis_auxinfo = arg;
1489 1488 } else if ((oarg = isp->dis_auxinfo) != arg) {
1490 1489 /*
1491 1490 * If we have seen this llquantize() before and the
1492 1491 * argument doesn't match the original argument, pick
1493 1492 * the original argument apart to concisely report the
1494 1493 * mismatch.
1495 1494 */
1496 1495 int expected = 0, found = 0;
1497 1496
1498 1497 for (i = 0; expected == found; i++) {
1499 1498 assert(args[i].str != NULL);
1500 1499
1501 1500 expected = (oarg >> args[i].shift) & UINT16_MAX;
1502 1501 found = (arg >> args[i].shift) & UINT16_MAX;
1503 1502 }
1504 1503
1505 1504 dnerror(dnp, args[i - 1].mismatch, "llquantize( ) "
1506 1505 "%s (argument #%d) doesn't match previous "
1507 1506 "declaration: expected %d, found %d\n",
1508 1507 args[i - 1].str, i, expected, found);
1509 1508 }
1510 1509
1511 1510 incr = llarg;
1512 1511 argmax = 6;
1513 1512 }
1514 1513
1515 1514 if (fid->di_id == DTRACEAGG_QUANTIZE) {
1516 1515 incr = dnp->dn_aggfun->dn_args->dn_list;
1517 1516 argmax = 2;
1518 1517 }
1519 1518
1520 1519 if (incr != NULL) {
1521 1520 if (!dt_node_is_scalar(incr)) {
1522 1521 dnerror(dnp, D_PROTO_ARG, "%s( ) increment value "
1523 1522 "(argument #%d) must be of scalar type\n",
1524 1523 fid->di_name, argmax);
1525 1524 }
1526 1525
1527 1526 if ((anp = incr->dn_list) != NULL) {
1528 1527 int argc = argmax;
1529 1528
1530 1529 for (; anp != NULL; anp = anp->dn_list)
1531 1530 argc++;
1532 1531
1533 1532 dnerror(incr, D_PROTO_LEN, "%s( ) prototype "
1534 1533 "mismatch: %d args passed, at most %d expected",
1535 1534 fid->di_name, argc, argmax);
1536 1535 }
1537 1536
1538 1537 ap = dt_stmt_action(dtp, sdp);
1539 1538 n++;
1540 1539
1541 1540 dt_cg(yypcb, incr);
1542 1541 ap->dtad_difo = dt_as(yypcb);
1543 1542 ap->dtad_difo->dtdo_rtype = dt_void_rtype;
1544 1543 ap->dtad_kind = DTRACEACT_DIFEXPR;
1545 1544 }
1546 1545
1547 1546 assert(sdp->dtsd_aggdata == NULL);
1548 1547 sdp->dtsd_aggdata = aid;
1549 1548
1550 1549 ap = dt_stmt_action(dtp, sdp);
1551 1550 assert(fid->di_kind == DT_IDENT_AGGFUNC);
1552 1551 assert(DTRACEACT_ISAGG(fid->di_id));
1553 1552 ap->dtad_kind = fid->di_id;
1554 1553 ap->dtad_ntuple = n;
1555 1554 ap->dtad_arg = arg;
1556 1555
1557 1556 if (dnp->dn_aggfun->dn_args != NULL) {
1558 1557 dt_cg(yypcb, dnp->dn_aggfun->dn_args);
1559 1558 ap->dtad_difo = dt_as(yypcb);
1560 1559 }
1561 1560 }
1562 1561
1563 1562 static void
1564 1563 dt_compile_one_clause(dtrace_hdl_t *dtp, dt_node_t *cnp, dt_node_t *pnp)
1565 1564 {
1566 1565 dtrace_ecbdesc_t *edp;
1567 1566 dtrace_stmtdesc_t *sdp;
1568 1567 dt_node_t *dnp;
1569 1568
1570 1569 yylineno = pnp->dn_line;
1571 1570 dt_setcontext(dtp, pnp->dn_desc);
1572 1571 (void) dt_node_cook(cnp, DT_IDFLG_REF);
1573 1572
1574 1573 if (DT_TREEDUMP_PASS(dtp, 2))
1575 1574 dt_node_printr(cnp, stderr, 0);
1576 1575
1577 1576 if ((edp = dt_ecbdesc_create(dtp, pnp->dn_desc)) == NULL)
1578 1577 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1579 1578
1580 1579 assert(yypcb->pcb_ecbdesc == NULL);
1581 1580 yypcb->pcb_ecbdesc = edp;
1582 1581
1583 1582 if (cnp->dn_pred != NULL) {
1584 1583 dt_cg(yypcb, cnp->dn_pred);
1585 1584 edp->dted_pred.dtpdd_difo = dt_as(yypcb);
1586 1585 }
1587 1586
1588 1587 if (cnp->dn_acts == NULL) {
1589 1588 dt_stmt_append(dt_stmt_create(dtp, edp,
1590 1589 cnp->dn_ctxattr, _dtrace_defattr), cnp);
1591 1590 }
1592 1591
1593 1592 for (dnp = cnp->dn_acts; dnp != NULL; dnp = dnp->dn_list) {
1594 1593 assert(yypcb->pcb_stmt == NULL);
1595 1594 sdp = dt_stmt_create(dtp, edp, cnp->dn_ctxattr, cnp->dn_attr);
1596 1595
1597 1596 switch (dnp->dn_kind) {
1598 1597 case DT_NODE_DEXPR:
1599 1598 if (dnp->dn_expr->dn_kind == DT_NODE_AGG)
1600 1599 dt_compile_agg(dtp, dnp->dn_expr, sdp);
1601 1600 else
1602 1601 dt_compile_exp(dtp, dnp, sdp);
1603 1602 break;
1604 1603 case DT_NODE_DFUNC:
1605 1604 dt_compile_fun(dtp, dnp, sdp);
1606 1605 break;
1607 1606 case DT_NODE_AGG:
1608 1607 dt_compile_agg(dtp, dnp, sdp);
1609 1608 break;
1610 1609 default:
1611 1610 dnerror(dnp, D_UNKNOWN, "internal error -- node kind "
1612 1611 "%u is not a valid statement\n", dnp->dn_kind);
1613 1612 }
1614 1613
1615 1614 assert(yypcb->pcb_stmt == sdp);
1616 1615 dt_stmt_append(sdp, dnp);
1617 1616 }
1618 1617
1619 1618 assert(yypcb->pcb_ecbdesc == edp);
1620 1619 dt_ecbdesc_release(dtp, edp);
1621 1620 dt_endcontext(dtp);
1622 1621 yypcb->pcb_ecbdesc = NULL;
1623 1622 }
1624 1623
1625 1624 static void
1626 1625 dt_compile_clause(dtrace_hdl_t *dtp, dt_node_t *cnp)
1627 1626 {
1628 1627 dt_node_t *pnp;
1629 1628
1630 1629 for (pnp = cnp->dn_pdescs; pnp != NULL; pnp = pnp->dn_list)
1631 1630 dt_compile_one_clause(dtp, cnp, pnp);
1632 1631 }
1633 1632
1634 1633 static void
1635 1634 dt_compile_xlator(dt_node_t *dnp)
1636 1635 {
1637 1636 dt_xlator_t *dxp = dnp->dn_xlator;
1638 1637 dt_node_t *mnp;
1639 1638
1640 1639 for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
1641 1640 assert(dxp->dx_membdif[mnp->dn_membid] == NULL);
1642 1641 dt_cg(yypcb, mnp);
1643 1642 dxp->dx_membdif[mnp->dn_membid] = dt_as(yypcb);
1644 1643 }
1645 1644 }
1646 1645
1647 1646 void
1648 1647 dt_setcontext(dtrace_hdl_t *dtp, dtrace_probedesc_t *pdp)
1649 1648 {
1650 1649 const dtrace_pattr_t *pap;
1651 1650 dt_probe_t *prp;
1652 1651 dt_provider_t *pvp;
1653 1652 dt_ident_t *idp;
1654 1653 char attrstr[8];
1655 1654 int err;
1656 1655
1657 1656 /*
1658 1657 * Both kernel and pid based providers are allowed to have names
1659 1658 * ending with what could be interpreted as a number. We assume it's
1660 1659 * a pid and that we may need to dynamically create probes for
1661 1660 * that process if:
1662 1661 *
1663 1662 * (1) The provider doesn't exist, or,
1664 1663 * (2) The provider exists and has DTRACE_PRIV_PROC privilege.
1665 1664 *
1666 1665 * On an error, dt_pid_create_probes() will set the error message
1667 1666 * and tag -- we just have to longjmp() out of here.
1668 1667 */
1669 1668 if (isdigit(pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) &&
1670 1669 ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) == NULL ||
1671 1670 pvp->pv_desc.dtvd_priv.dtpp_flags & DTRACE_PRIV_PROC) &&
1672 1671 dt_pid_create_probes(pdp, dtp, yypcb) != 0) {
1673 1672 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1674 1673 }
1675 1674
1676 1675 /*
1677 1676 * Call dt_probe_info() to get the probe arguments and attributes. If
1678 1677 * a representative probe is found, set 'pap' to the probe provider's
1679 1678 * attributes. Otherwise set 'pap' to default Unstable attributes.
1680 1679 */
1681 1680 if ((prp = dt_probe_info(dtp, pdp, &yypcb->pcb_pinfo)) == NULL) {
1682 1681 pap = &_dtrace_prvdesc;
1683 1682 err = dtrace_errno(dtp);
1684 1683 bzero(&yypcb->pcb_pinfo, sizeof (dtrace_probeinfo_t));
1685 1684 yypcb->pcb_pinfo.dtp_attr = pap->dtpa_provider;
1686 1685 yypcb->pcb_pinfo.dtp_arga = pap->dtpa_args;
1687 1686 } else {
1688 1687 pap = &prp->pr_pvp->pv_desc.dtvd_attr;
1689 1688 err = 0;
1690 1689 }
1691 1690
1692 1691 if (err == EDT_NOPROBE && !(yypcb->pcb_cflags & DTRACE_C_ZDEFS)) {
1693 1692 xyerror(D_PDESC_ZERO, "probe description %s:%s:%s:%s does not "
1694 1693 "match any probes\n", pdp->dtpd_provider, pdp->dtpd_mod,
1695 1694 pdp->dtpd_func, pdp->dtpd_name);
1696 1695 }
1697 1696
1698 1697 if (err != EDT_NOPROBE && err != EDT_UNSTABLE && err != 0)
1699 1698 xyerror(D_PDESC_INVAL, "%s\n", dtrace_errmsg(dtp, err));
1700 1699
1701 1700 dt_dprintf("set context to %s:%s:%s:%s [%u] prp=%p attr=%s argc=%d\n",
1702 1701 pdp->dtpd_provider, pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name,
1703 1702 pdp->dtpd_id, (void *)prp, dt_attr_str(yypcb->pcb_pinfo.dtp_attr,
1704 1703 attrstr, sizeof (attrstr)), yypcb->pcb_pinfo.dtp_argc);
1705 1704
1706 1705 /*
1707 1706 * Reset the stability attributes of D global variables that vary
1708 1707 * based on the attributes of the provider and context itself.
1709 1708 */
1710 1709 if ((idp = dt_idhash_lookup(dtp->dt_globals, "probeprov")) != NULL)
1711 1710 idp->di_attr = pap->dtpa_provider;
1712 1711 if ((idp = dt_idhash_lookup(dtp->dt_globals, "probemod")) != NULL)
1713 1712 idp->di_attr = pap->dtpa_mod;
1714 1713 if ((idp = dt_idhash_lookup(dtp->dt_globals, "probefunc")) != NULL)
1715 1714 idp->di_attr = pap->dtpa_func;
1716 1715 if ((idp = dt_idhash_lookup(dtp->dt_globals, "probename")) != NULL)
1717 1716 idp->di_attr = pap->dtpa_name;
1718 1717 if ((idp = dt_idhash_lookup(dtp->dt_globals, "args")) != NULL)
1719 1718 idp->di_attr = pap->dtpa_args;
1720 1719
1721 1720 yypcb->pcb_pdesc = pdp;
1722 1721 yypcb->pcb_probe = prp;
1723 1722 }
1724 1723
1725 1724 /*
1726 1725 * Reset context-dependent variables and state at the end of cooking a D probe
1727 1726 * definition clause. This ensures that external declarations between clauses
1728 1727 * do not reference any stale context-dependent data from the previous clause.
1729 1728 */
1730 1729 void
1731 1730 dt_endcontext(dtrace_hdl_t *dtp)
1732 1731 {
1733 1732 static const char *const cvars[] = {
1734 1733 "probeprov", "probemod", "probefunc", "probename", "args", NULL
1735 1734 };
1736 1735
1737 1736 dt_ident_t *idp;
1738 1737 int i;
1739 1738
1740 1739 for (i = 0; cvars[i] != NULL; i++) {
1741 1740 if ((idp = dt_idhash_lookup(dtp->dt_globals, cvars[i])) != NULL)
1742 1741 idp->di_attr = _dtrace_defattr;
1743 1742 }
1744 1743
1745 1744 yypcb->pcb_pdesc = NULL;
1746 1745 yypcb->pcb_probe = NULL;
1747 1746 }
1748 1747
1749 1748 static int
1750 1749 dt_reduceid(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp)
1751 1750 {
1752 1751 if (idp->di_vers != 0 && idp->di_vers > dtp->dt_vmax)
1753 1752 dt_idhash_delete(dhp, idp);
1754 1753
1755 1754 return (0);
1756 1755 }
1757 1756
1758 1757 /*
1759 1758 * When dtrace_setopt() is called for "version", it calls dt_reduce() to remove
1760 1759 * any identifiers or translators that have been previously defined as bound to
1761 1760 * a version greater than the specified version. Therefore, in our current
1762 1761 * version implementation, establishing a binding is a one-way transformation.
1763 1762 * In addition, no versioning is currently provided for types as our .d library
1764 1763 * files do not define any types and we reserve prefixes DTRACE_ and dtrace_
1765 1764 * for our exclusive use. If required, type versioning will require more work.
1766 1765 */
1767 1766 int
1768 1767 dt_reduce(dtrace_hdl_t *dtp, dt_version_t v)
1769 1768 {
1770 1769 char s[DT_VERSION_STRMAX];
1771 1770 dt_xlator_t *dxp, *nxp;
1772 1771
1773 1772 if (v > dtp->dt_vmax)
1774 1773 return (dt_set_errno(dtp, EDT_VERSREDUCED));
1775 1774 else if (v == dtp->dt_vmax)
1776 1775 return (0); /* no reduction necessary */
1777 1776
1778 1777 dt_dprintf("reducing api version to %s\n",
1779 1778 dt_version_num2str(v, s, sizeof (s)));
1780 1779
1781 1780 dtp->dt_vmax = v;
1782 1781
1783 1782 for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = nxp) {
1784 1783 nxp = dt_list_next(dxp);
1785 1784 if ((dxp->dx_souid.di_vers != 0 && dxp->dx_souid.di_vers > v) ||
1786 1785 (dxp->dx_ptrid.di_vers != 0 && dxp->dx_ptrid.di_vers > v))
1787 1786 dt_list_delete(&dtp->dt_xlators, dxp);
1788 1787 }
1789 1788
1790 1789 (void) dt_idhash_iter(dtp->dt_macros, (dt_idhash_f *)dt_reduceid, dtp);
1791 1790 (void) dt_idhash_iter(dtp->dt_aggs, (dt_idhash_f *)dt_reduceid, dtp);
1792 1791 (void) dt_idhash_iter(dtp->dt_globals, (dt_idhash_f *)dt_reduceid, dtp);
1793 1792 (void) dt_idhash_iter(dtp->dt_tls, (dt_idhash_f *)dt_reduceid, dtp);
1794 1793
1795 1794 return (0);
1796 1795 }
1797 1796
1798 1797 /*
1799 1798 * Fork and exec the cpp(1) preprocessor to run over the specified input file,
1800 1799 * and return a FILE handle for the cpp output. We use the /dev/fd filesystem
1801 1800 * here to simplify the code by leveraging file descriptor inheritance.
1802 1801 */
1803 1802 static FILE *
1804 1803 dt_preproc(dtrace_hdl_t *dtp, FILE *ifp)
1805 1804 {
1806 1805 int argc = dtp->dt_cpp_argc;
1807 1806 char **argv = malloc(sizeof (char *) * (argc + 5));
1808 1807 FILE *ofp = tmpfile();
1809 1808
1810 1809 char ipath[20], opath[20]; /* big enough for /dev/fd/ + INT_MAX + \0 */
1811 1810 char verdef[32]; /* big enough for -D__SUNW_D_VERSION=0x%08x + \0 */
1812 1811
1813 1812 struct sigaction act, oact;
1814 1813 sigset_t mask, omask;
1815 1814
1816 1815 int wstat, estat;
1817 1816 pid_t pid;
1818 1817 off64_t off;
1819 1818 int c;
1820 1819
1821 1820 if (argv == NULL || ofp == NULL) {
1822 1821 (void) dt_set_errno(dtp, errno);
1823 1822 goto err;
1824 1823 }
1825 1824
1826 1825 /*
1827 1826 * If the input is a seekable file, see if it is an interpreter file.
1828 1827 * If we see #!, seek past the first line because cpp will choke on it.
1829 1828 * We start cpp just prior to the \n at the end of this line so that
1830 1829 * it still sees the newline, ensuring that #line values are correct.
1831 1830 */
1832 1831 if (isatty(fileno(ifp)) == 0 && (off = ftello64(ifp)) != -1) {
1833 1832 if ((c = fgetc(ifp)) == '#' && (c = fgetc(ifp)) == '!') {
1834 1833 for (off += 2; c != '\n'; off++) {
1835 1834 if ((c = fgetc(ifp)) == EOF)
1836 1835 break;
1837 1836 }
1838 1837 if (c == '\n')
1839 1838 off--; /* start cpp just prior to \n */
1840 1839 }
1841 1840 (void) fflush(ifp);
1842 1841 (void) fseeko64(ifp, off, SEEK_SET);
1843 1842 }
1844 1843
1845 1844 (void) snprintf(ipath, sizeof (ipath), "/dev/fd/%d", fileno(ifp));
1846 1845 (void) snprintf(opath, sizeof (opath), "/dev/fd/%d", fileno(ofp));
1847 1846
1848 1847 bcopy(dtp->dt_cpp_argv, argv, sizeof (char *) * argc);
1849 1848
1850 1849 (void) snprintf(verdef, sizeof (verdef),
1851 1850 "-D__SUNW_D_VERSION=0x%08x", dtp->dt_vmax);
1852 1851 argv[argc++] = verdef;
1853 1852
1854 1853 switch (dtp->dt_stdcmode) {
1855 1854 case DT_STDC_XA:
1856 1855 case DT_STDC_XT:
1857 1856 argv[argc++] = "-D__STDC__=0";
1858 1857 break;
1859 1858 case DT_STDC_XC:
1860 1859 argv[argc++] = "-D__STDC__=1";
1861 1860 break;
1862 1861 }
1863 1862
1864 1863 argv[argc++] = ipath;
1865 1864 argv[argc++] = opath;
1866 1865 argv[argc] = NULL;
1867 1866
1868 1867 /*
1869 1868 * libdtrace must be able to be embedded in other programs that may
1870 1869 * include application-specific signal handlers. Therefore, if we
1871 1870 * need to fork to run cpp(1), we must avoid generating a SIGCHLD
1872 1871 * that could confuse the containing application. To do this,
1873 1872 * we block SIGCHLD and reset its disposition to SIG_DFL.
1874 1873 * We restore our signal state once we are done.
1875 1874 */
1876 1875 (void) sigemptyset(&mask);
1877 1876 (void) sigaddset(&mask, SIGCHLD);
1878 1877 (void) sigprocmask(SIG_BLOCK, &mask, &omask);
1879 1878
1880 1879 bzero(&act, sizeof (act));
1881 1880 act.sa_handler = SIG_DFL;
1882 1881 (void) sigaction(SIGCHLD, &act, &oact);
1883 1882
1884 1883 if ((pid = fork1()) == -1) {
1885 1884 (void) sigaction(SIGCHLD, &oact, NULL);
1886 1885 (void) sigprocmask(SIG_SETMASK, &omask, NULL);
1887 1886 (void) dt_set_errno(dtp, EDT_CPPFORK);
1888 1887 goto err;
1889 1888 }
1890 1889
1891 1890 if (pid == 0) {
1892 1891 (void) execvp(dtp->dt_cpp_path, argv);
1893 1892 _exit(errno == ENOENT ? 127 : 126);
1894 1893 }
1895 1894
1896 1895 do {
1897 1896 dt_dprintf("waiting for %s (PID %d)\n", dtp->dt_cpp_path,
1898 1897 (int)pid);
1899 1898 } while (waitpid(pid, &wstat, 0) == -1 && errno == EINTR);
1900 1899
1901 1900 (void) sigaction(SIGCHLD, &oact, NULL);
1902 1901 (void) sigprocmask(SIG_SETMASK, &omask, NULL);
1903 1902
1904 1903 dt_dprintf("%s returned exit status 0x%x\n", dtp->dt_cpp_path, wstat);
1905 1904 estat = WIFEXITED(wstat) ? WEXITSTATUS(wstat) : -1;
1906 1905
1907 1906 if (estat != 0) {
1908 1907 switch (estat) {
1909 1908 case 126:
1910 1909 (void) dt_set_errno(dtp, EDT_CPPEXEC);
1911 1910 break;
1912 1911 case 127:
1913 1912 (void) dt_set_errno(dtp, EDT_CPPENT);
1914 1913 break;
1915 1914 default:
1916 1915 (void) dt_set_errno(dtp, EDT_CPPERR);
1917 1916 }
1918 1917 goto err;
1919 1918 }
1920 1919
1921 1920 free(argv);
1922 1921 (void) fflush(ofp);
1923 1922 (void) fseek(ofp, 0, SEEK_SET);
1924 1923 return (ofp);
1925 1924
1926 1925 err:
1927 1926 free(argv);
1928 1927 (void) fclose(ofp);
1929 1928 return (NULL);
1930 1929 }
1931 1930
1932 1931 static void
1933 1932 dt_lib_depend_error(dtrace_hdl_t *dtp, const char *format, ...)
1934 1933 {
1935 1934 va_list ap;
1936 1935
1937 1936 va_start(ap, format);
1938 1937 dt_set_errmsg(dtp, NULL, NULL, NULL, 0, format, ap);
1939 1938 va_end(ap);
1940 1939 }
1941 1940
1942 1941 int
1943 1942 dt_lib_depend_add(dtrace_hdl_t *dtp, dt_list_t *dlp, const char *arg)
1944 1943 {
1945 1944 dt_lib_depend_t *dld;
1946 1945 const char *end;
1947 1946
1948 1947 assert(arg != NULL);
1949 1948
1950 1949 if ((end = strrchr(arg, '/')) == NULL)
1951 1950 return (dt_set_errno(dtp, EINVAL));
1952 1951
1953 1952 if ((dld = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL)
1954 1953 return (-1);
1955 1954
1956 1955 if ((dld->dtld_libpath = dt_alloc(dtp, MAXPATHLEN)) == NULL) {
1957 1956 dt_free(dtp, dld);
1958 1957 return (-1);
1959 1958 }
1960 1959
1961 1960 (void) strlcpy(dld->dtld_libpath, arg, end - arg + 2);
1962 1961 if ((dld->dtld_library = strdup(arg)) == NULL) {
1963 1962 dt_free(dtp, dld->dtld_libpath);
1964 1963 dt_free(dtp, dld);
1965 1964 return (dt_set_errno(dtp, EDT_NOMEM));
1966 1965 }
1967 1966
1968 1967 dt_list_append(dlp, dld);
1969 1968 return (0);
1970 1969 }
1971 1970
1972 1971 dt_lib_depend_t *
1973 1972 dt_lib_depend_lookup(dt_list_t *dld, const char *arg)
1974 1973 {
1975 1974 dt_lib_depend_t *dldn;
1976 1975
1977 1976 for (dldn = dt_list_next(dld); dldn != NULL;
1978 1977 dldn = dt_list_next(dldn)) {
1979 1978 if (strcmp(dldn->dtld_library, arg) == 0)
1980 1979 return (dldn);
1981 1980 }
1982 1981
1983 1982 return (NULL);
1984 1983 }
1985 1984
1986 1985 /*
1987 1986 * Go through all the library files, and, if any library dependencies exist for
1988 1987 * that file, add it to that node's list of dependents. The result of this
1989 1988 * will be a graph which can then be topologically sorted to produce a
1990 1989 * compilation order.
1991 1990 */
1992 1991 static int
1993 1992 dt_lib_build_graph(dtrace_hdl_t *dtp)
1994 1993 {
1995 1994 dt_lib_depend_t *dld, *dpld;
1996 1995
1997 1996 for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
1998 1997 dld = dt_list_next(dld)) {
1999 1998 char *library = dld->dtld_library;
2000 1999
2001 2000 for (dpld = dt_list_next(&dld->dtld_dependencies); dpld != NULL;
2002 2001 dpld = dt_list_next(dpld)) {
2003 2002 dt_lib_depend_t *dlda;
2004 2003
2005 2004 if ((dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep,
2006 2005 dpld->dtld_library)) == NULL) {
2007 2006 dt_lib_depend_error(dtp,
2008 2007 "Invalid library dependency in %s: %s\n",
2009 2008 dld->dtld_library, dpld->dtld_library);
2010 2009
2011 2010 return (dt_set_errno(dtp, EDT_COMPILER));
2012 2011 }
2013 2012
2014 2013 if ((dt_lib_depend_add(dtp, &dlda->dtld_dependents,
2015 2014 library)) != 0) {
2016 2015 return (-1); /* preserve dt_errno */
2017 2016 }
2018 2017 }
2019 2018 }
2020 2019 return (0);
2021 2020 }
2022 2021
2023 2022 static int
2024 2023 dt_topo_sort(dtrace_hdl_t *dtp, dt_lib_depend_t *dld, int *count)
2025 2024 {
2026 2025 dt_lib_depend_t *dpld, *dlda, *new;
2027 2026
2028 2027 dld->dtld_start = ++(*count);
2029 2028
2030 2029 for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL;
2031 2030 dpld = dt_list_next(dpld)) {
2032 2031 dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep,
2033 2032 dpld->dtld_library);
2034 2033 assert(dlda != NULL);
2035 2034
2036 2035 if (dlda->dtld_start == 0 &&
2037 2036 dt_topo_sort(dtp, dlda, count) == -1)
2038 2037 return (-1);
2039 2038 }
2040 2039
2041 2040 if ((new = dt_zalloc(dtp, sizeof (dt_lib_depend_t))) == NULL)
2042 2041 return (-1);
2043 2042
2044 2043 if ((new->dtld_library = strdup(dld->dtld_library)) == NULL) {
2045 2044 dt_free(dtp, new);
2046 2045 return (dt_set_errno(dtp, EDT_NOMEM));
2047 2046 }
2048 2047
2049 2048 new->dtld_start = dld->dtld_start;
2050 2049 new->dtld_finish = dld->dtld_finish = ++(*count);
2051 2050 dt_list_prepend(&dtp->dt_lib_dep_sorted, new);
2052 2051
2053 2052 dt_dprintf("library %s sorted (%d/%d)\n", new->dtld_library,
2054 2053 new->dtld_start, new->dtld_finish);
2055 2054
2056 2055 return (0);
2057 2056 }
2058 2057
2059 2058 static int
2060 2059 dt_lib_depend_sort(dtrace_hdl_t *dtp)
2061 2060 {
2062 2061 dt_lib_depend_t *dld, *dpld, *dlda;
2063 2062 int count = 0;
2064 2063
2065 2064 if (dt_lib_build_graph(dtp) == -1)
2066 2065 return (-1); /* preserve dt_errno */
2067 2066
2068 2067 /*
2069 2068 * Perform a topological sort of the graph that hangs off
2070 2069 * dtp->dt_lib_dep. The result of this process will be a
2071 2070 * dependency ordered list located at dtp->dt_lib_dep_sorted.
2072 2071 */
2073 2072 for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
2074 2073 dld = dt_list_next(dld)) {
2075 2074 if (dld->dtld_start == 0 &&
2076 2075 dt_topo_sort(dtp, dld, &count) == -1)
2077 2076 return (-1); /* preserve dt_errno */;
2078 2077 }
2079 2078
2080 2079 /*
2081 2080 * Check the graph for cycles. If an ancestor's finishing time is
2082 2081 * less than any of its dependent's finishing times then a back edge
2083 2082 * exists in the graph and this is a cycle.
2084 2083 */
2085 2084 for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
2086 2085 dld = dt_list_next(dld)) {
2087 2086 for (dpld = dt_list_next(&dld->dtld_dependents); dpld != NULL;
2088 2087 dpld = dt_list_next(dpld)) {
2089 2088 dlda = dt_lib_depend_lookup(&dtp->dt_lib_dep_sorted,
2090 2089 dpld->dtld_library);
2091 2090 assert(dlda != NULL);
2092 2091
2093 2092 if (dlda->dtld_finish > dld->dtld_finish) {
2094 2093 dt_lib_depend_error(dtp,
2095 2094 "Cyclic dependency detected: %s => %s\n",
2096 2095 dld->dtld_library, dpld->dtld_library);
2097 2096
2098 2097 return (dt_set_errno(dtp, EDT_COMPILER));
2099 2098 }
2100 2099 }
2101 2100 }
2102 2101
2103 2102 return (0);
2104 2103 }
2105 2104
2106 2105 static void
2107 2106 dt_lib_depend_free(dtrace_hdl_t *dtp)
2108 2107 {
2109 2108 dt_lib_depend_t *dld, *dlda;
2110 2109
2111 2110 while ((dld = dt_list_next(&dtp->dt_lib_dep)) != NULL) {
2112 2111 while ((dlda = dt_list_next(&dld->dtld_dependencies)) != NULL) {
2113 2112 dt_list_delete(&dld->dtld_dependencies, dlda);
2114 2113 dt_free(dtp, dlda->dtld_library);
2115 2114 dt_free(dtp, dlda->dtld_libpath);
2116 2115 dt_free(dtp, dlda);
2117 2116 }
2118 2117 while ((dlda = dt_list_next(&dld->dtld_dependents)) != NULL) {
2119 2118 dt_list_delete(&dld->dtld_dependents, dlda);
2120 2119 dt_free(dtp, dlda->dtld_library);
2121 2120 dt_free(dtp, dlda->dtld_libpath);
2122 2121 dt_free(dtp, dlda);
2123 2122 }
2124 2123 dt_list_delete(&dtp->dt_lib_dep, dld);
2125 2124 dt_free(dtp, dld->dtld_library);
2126 2125 dt_free(dtp, dld->dtld_libpath);
2127 2126 dt_free(dtp, dld);
2128 2127 }
2129 2128
2130 2129 while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) {
2131 2130 dt_list_delete(&dtp->dt_lib_dep_sorted, dld);
2132 2131 dt_free(dtp, dld->dtld_library);
2133 2132 dt_free(dtp, dld);
2134 2133 }
2135 2134 }
2136 2135
2137 2136 /*
2138 2137 * Open all the .d library files found in the specified directory and
2139 2138 * compile each one of them. We silently ignore any missing directories and
2140 2139 * other files found therein. We only fail (and thereby fail dt_load_libs()) if
2141 2140 * we fail to compile a library and the error is something other than #pragma D
2142 2141 * depends_on. Dependency errors are silently ignored to permit a library
2143 2142 * directory to contain libraries which may not be accessible depending on our
2144 2143 * privileges.
2145 2144 */
2146 2145 static int
2147 2146 dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
2148 2147 {
2149 2148 struct dirent *dp;
2150 2149 const char *p, *end;
2151 2150 DIR *dirp;
2152 2151
2153 2152 char fname[PATH_MAX];
2154 2153 FILE *fp;
2155 2154 void *rv;
2156 2155 dt_lib_depend_t *dld;
2157 2156
2158 2157 if ((dirp = opendir(path)) == NULL) {
2159 2158 dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno));
2160 2159 return (0);
2161 2160 }
2162 2161
2163 2162 /* First, parse each file for library dependencies. */
2164 2163 while ((dp = readdir(dirp)) != NULL) {
2165 2164 if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d"))
2166 2165 continue; /* skip any filename not ending in .d */
2167 2166
2168 2167 (void) snprintf(fname, sizeof (fname),
2169 2168 "%s/%s", path, dp->d_name);
2170 2169
2171 2170 if ((fp = fopen(fname, "rF")) == NULL) {
2172 2171 dt_dprintf("skipping library %s: %s\n",
2173 2172 fname, strerror(errno));
2174 2173 continue;
2175 2174 }
2176 2175
2177 2176 /*
2178 2177 * Skip files whose name match an already processed library
2179 2178 */
2180 2179 for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL;
2181 2180 dld = dt_list_next(dld)) {
2182 2181 end = strrchr(dld->dtld_library, '/');
2183 2182 /* dt_lib_depend_add ensures this */
2184 2183 assert(end != NULL);
2185 2184 if (strcmp(end + 1, dp->d_name) == 0)
2186 2185 break;
2187 2186 }
2188 2187
2189 2188 if (dld != NULL) {
2190 2189 dt_dprintf("skipping library %s, already processed "
2191 2190 "library with the same name: %s", dp->d_name,
2192 2191 dld->dtld_library);
2193 2192 (void) fclose(fp);
2194 2193 continue;
2195 2194 }
2196 2195
2197 2196 dtp->dt_filetag = fname;
2198 2197 if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0) {
2199 2198 (void) fclose(fp);
2200 2199 return (-1); /* preserve dt_errno */
2201 2200 }
2202 2201
2203 2202 rv = dt_compile(dtp, DT_CTX_DPROG,
2204 2203 DTRACE_PROBESPEC_NAME, NULL,
2205 2204 DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp, NULL);
2206 2205
2207 2206 if (rv != NULL && dtp->dt_errno &&
2208 2207 (dtp->dt_errno != EDT_COMPILER ||
2209 2208 dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) {
2210 2209 (void) fclose(fp);
2211 2210 return (-1); /* preserve dt_errno */
2212 2211 }
2213 2212
2214 2213 if (dtp->dt_errno)
2215 2214 dt_dprintf("error parsing library %s: %s\n",
2216 2215 fname, dtrace_errmsg(dtp, dtrace_errno(dtp)));
2217 2216
2218 2217 (void) fclose(fp);
2219 2218 dtp->dt_filetag = NULL;
2220 2219 }
2221 2220
2222 2221 (void) closedir(dirp);
2223 2222
2224 2223 return (0);
2225 2224 }
2226 2225
2227 2226 /*
2228 2227 * Perform a topological sorting of all the libraries found across the entire
2229 2228 * dt_lib_path. Once sorted, compile each one in topological order to cache its
2230 2229 * inlines and translators, etc. We silently ignore any missing directories and
2231 2230 * other files found therein. We only fail (and thereby fail dt_load_libs()) if
2232 2231 * we fail to compile a library and the error is something other than #pragma D
2233 2232 * depends_on. Dependency errors are silently ignored to permit a library
2234 2233 * directory to contain libraries which may not be accessible depending on our
2235 2234 * privileges.
2236 2235 */
2237 2236 static int
2238 2237 dt_load_libs_sort(dtrace_hdl_t *dtp)
2239 2238 {
2240 2239 dtrace_prog_t *pgp;
2241 2240 FILE *fp;
2242 2241 dt_lib_depend_t *dld;
2243 2242
2244 2243 /*
2245 2244 * Finish building the graph containing the library dependencies
2246 2245 * and perform a topological sort to generate an ordered list
2247 2246 * for compilation.
2248 2247 */
2249 2248 if (dt_lib_depend_sort(dtp) == -1)
2250 2249 goto err;
2251 2250
2252 2251 for (dld = dt_list_next(&dtp->dt_lib_dep_sorted); dld != NULL;
2253 2252 dld = dt_list_next(dld)) {
2254 2253
2255 2254 if ((fp = fopen(dld->dtld_library, "r")) == NULL) {
2256 2255 dt_dprintf("skipping library %s: %s\n",
2257 2256 dld->dtld_library, strerror(errno));
2258 2257 continue;
2259 2258 }
2260 2259
2261 2260 dtp->dt_filetag = dld->dtld_library;
2262 2261 pgp = dtrace_program_fcompile(dtp, fp, DTRACE_C_EMPTY, 0, NULL);
2263 2262 (void) fclose(fp);
2264 2263 dtp->dt_filetag = NULL;
2265 2264
2266 2265 if (pgp == NULL && (dtp->dt_errno != EDT_COMPILER ||
2267 2266 dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND)))
2268 2267 goto err;
2269 2268
2270 2269 if (pgp == NULL) {
2271 2270 dt_dprintf("skipping library %s: %s\n",
2272 2271 dld->dtld_library,
2273 2272 dtrace_errmsg(dtp, dtrace_errno(dtp)));
2274 2273 } else {
2275 2274 dld->dtld_loaded = B_TRUE;
2276 2275 dt_program_destroy(dtp, pgp);
2277 2276 }
2278 2277 }
2279 2278
2280 2279 dt_lib_depend_free(dtp);
2281 2280 return (0);
2282 2281
2283 2282 err:
2284 2283 dt_lib_depend_free(dtp);
2285 2284 return (-1); /* preserve dt_errno */
2286 2285 }
2287 2286
2288 2287 /*
2289 2288 * Load the contents of any appropriate DTrace .d library files. These files
2290 2289 * contain inlines and translators that will be cached by the compiler. We
2291 2290 * defer this activity until the first compile to permit libdtrace clients to
2292 2291 * add their own library directories and so that we can properly report errors.
2293 2292 */
2294 2293 static int
2295 2294 dt_load_libs(dtrace_hdl_t *dtp)
2296 2295 {
2297 2296 dt_dirpath_t *dirp;
2298 2297
2299 2298 if (dtp->dt_cflags & DTRACE_C_NOLIBS)
2300 2299 return (0); /* libraries already processed */
2301 2300
2302 2301 dtp->dt_cflags |= DTRACE_C_NOLIBS;
2303 2302
2304 2303 /*
2305 2304 * /usr/lib/dtrace is always at the head of the list. The rest of the
2306 2305 * list is specified in the precedence order the user requested. Process
2307 2306 * everything other than the head first. DTRACE_C_NOLIBS has already
2308 2307 * been spcified so dt_vopen will ensure that there is always one entry
2309 2308 * in dt_lib_path.
2310 2309 */
2311 2310 for (dirp = dt_list_next(dt_list_next(&dtp->dt_lib_path));
2312 2311 dirp != NULL; dirp = dt_list_next(dirp)) {
2313 2312 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) {
2314 2313 dtp->dt_cflags &= ~DTRACE_C_NOLIBS;
2315 2314 return (-1); /* errno is set for us */
2316 2315 }
2317 2316 }
2318 2317
2319 2318 /* Handle /usr/lib/dtrace */
2320 2319 dirp = dt_list_next(&dtp->dt_lib_path);
2321 2320 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) {
2322 2321 dtp->dt_cflags &= ~DTRACE_C_NOLIBS;
2323 2322 return (-1); /* errno is set for us */
2324 2323 }
2325 2324
2326 2325 if (dt_load_libs_sort(dtp) < 0)
2327 2326 return (-1); /* errno is set for us */
2328 2327
2329 2328 return (0);
2330 2329 }
2331 2330
2332 2331 static void *
2333 2332 dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
2334 2333 uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s)
2335 2334 {
2336 2335 dt_node_t *dnp;
2337 2336 dt_decl_t *ddp;
2338 2337 dt_pcb_t pcb;
2339 2338 void *volatile rv;
2340 2339 int err;
2341 2340
2342 2341 if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) {
2343 2342 (void) dt_set_errno(dtp, EINVAL);
2344 2343 return (NULL);
2345 2344 }
2346 2345
2347 2346 if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0)
2348 2347 return (NULL); /* errno is set for us */
2349 2348
2350 2349 if (dtp->dt_globals->dh_nelems != 0)
2351 2350 (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
2352 2351
2353 2352 if (dtp->dt_tls->dh_nelems != 0)
2354 2353 (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
2355 2354
2356 2355 if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
2357 2356 return (NULL); /* errno is set for us */
2358 2357
2359 2358 dt_pcb_push(dtp, &pcb);
2360 2359
2361 2360 pcb.pcb_fileptr = fp;
2362 2361 pcb.pcb_string = s;
2363 2362 pcb.pcb_strptr = s;
2364 2363 pcb.pcb_strlen = s ? strlen(s) : 0;
2365 2364 pcb.pcb_sargc = argc;
2366 2365 pcb.pcb_sargv = argv;
2367 2366 pcb.pcb_sflagv = argc ? calloc(argc, sizeof (ushort_t)) : NULL;
2368 2367 pcb.pcb_pspec = pspec;
2369 2368 pcb.pcb_cflags = dtp->dt_cflags | cflags;
2370 2369 pcb.pcb_amin = dtp->dt_amin;
2371 2370 pcb.pcb_yystate = -1;
2372 2371 pcb.pcb_context = context;
2373 2372 pcb.pcb_token = context;
2374 2373
2375 2374 if (context != DT_CTX_DPROG)
2376 2375 yybegin(YYS_EXPR);
2377 2376 else if (cflags & DTRACE_C_CTL)
2378 2377 yybegin(YYS_CONTROL);
2379 2378 else
2380 2379 yybegin(YYS_CLAUSE);
2381 2380
2382 2381 if ((err = setjmp(yypcb->pcb_jmpbuf)) != 0)
2383 2382 goto out;
2384 2383
2385 2384 if (yypcb->pcb_sargc != 0 && yypcb->pcb_sflagv == NULL)
2386 2385 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2387 2386
2388 2387 yypcb->pcb_idents = dt_idhash_create("ambiguous", NULL, 0, 0);
2389 2388 yypcb->pcb_locals = dt_idhash_create("clause local", NULL,
2390 2389 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
2391 2390
2392 2391 if (yypcb->pcb_idents == NULL || yypcb->pcb_locals == NULL)
2393 2392 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2394 2393
2395 2394 /*
2396 2395 * Invoke the parser to evaluate the D source code. If any errors
2397 2396 * occur during parsing, an error function will be called and we
2398 2397 * will longjmp back to pcb_jmpbuf to abort. If parsing succeeds,
2399 2398 * we optionally display the parse tree if debugging is enabled.
2400 2399 */
2401 2400 if (yyparse() != 0 || yypcb->pcb_root == NULL)
2402 2401 xyerror(D_EMPTY, "empty D program translation unit\n");
2403 2402
2404 2403 yybegin(YYS_DONE);
2405 2404
2406 2405 if (cflags & DTRACE_C_CTL)
2407 2406 goto out;
2408 2407
2409 2408 if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 1))
2410 2409 dt_node_printr(yypcb->pcb_root, stderr, 0);
2411 2410
↓ open down ↓ |
2279 lines elided |
↑ open up ↑ |
2412 2411 if (yypcb->pcb_pragmas != NULL)
2413 2412 (void) dt_idhash_iter(yypcb->pcb_pragmas, dt_idpragma, NULL);
2414 2413
2415 2414 if (argc > 1 && !(yypcb->pcb_cflags & DTRACE_C_ARGREF) &&
2416 2415 !(yypcb->pcb_sflagv[argc - 1] & DT_IDFLG_REF)) {
2417 2416 xyerror(D_MACRO_UNUSED, "extraneous argument '%s' ($%d is "
2418 2417 "not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1);
2419 2418 }
2420 2419
2421 2420 /*
2421 + * Perform sugar transformations (for "if" / "else") and replace the
2422 + * existing clause chain with the new one.
2423 + */
2424 + if (context == DT_CTX_DPROG) {
2425 + dt_node_t *dnp, *next_dnp;
2426 + dt_node_t *new_list = NULL;
2427 +
2428 + for (dnp = yypcb->pcb_root->dn_list;
2429 + dnp != NULL; dnp = next_dnp) {
2430 + /* remove this node from the list */
2431 + next_dnp = dnp->dn_list;
2432 + dnp->dn_list = NULL;
2433 +
2434 + if (dnp->dn_kind == DT_NODE_CLAUSE)
2435 + dnp = dt_compile_sugar(dtp, dnp);
2436 + /* append node to the new list */
2437 + new_list = dt_node_link(new_list, dnp);
2438 + }
2439 + yypcb->pcb_root->dn_list = new_list;
2440 + }
2441 +
2442 + /*
2422 2443 * If we have successfully created a parse tree for a D program, loop
2423 2444 * over the clauses and actions and instantiate the corresponding
2424 2445 * libdtrace program. If we are parsing a D expression, then we
2425 2446 * simply run the code generator and assembler on the resulting tree.
2426 2447 */
2427 2448 switch (context) {
2428 2449 case DT_CTX_DPROG:
2429 2450 assert(yypcb->pcb_root->dn_kind == DT_NODE_PROG);
2430 2451
2431 2452 if ((dnp = yypcb->pcb_root->dn_list) == NULL &&
2432 2453 !(yypcb->pcb_cflags & DTRACE_C_EMPTY))
2433 2454 xyerror(D_EMPTY, "empty D program translation unit\n");
2434 2455
2435 2456 if ((yypcb->pcb_prog = dt_program_create(dtp)) == NULL)
2436 2457 longjmp(yypcb->pcb_jmpbuf, dtrace_errno(dtp));
2437 2458
2438 2459 for (; dnp != NULL; dnp = dnp->dn_list) {
2439 2460 switch (dnp->dn_kind) {
2440 2461 case DT_NODE_CLAUSE:
2462 + if (DT_TREEDUMP_PASS(dtp, 4))
2463 + dt_printd(dnp, stderr, 0);
2441 2464 dt_compile_clause(dtp, dnp);
2442 2465 break;
2443 2466 case DT_NODE_XLATOR:
2444 2467 if (dtp->dt_xlatemode == DT_XL_DYNAMIC)
2445 2468 dt_compile_xlator(dnp);
2446 2469 break;
2447 2470 case DT_NODE_PROVIDER:
2448 2471 (void) dt_node_cook(dnp, DT_IDFLG_REF);
2449 2472 break;
2450 2473 }
2451 2474 }
2452 2475
2453 2476 yypcb->pcb_prog->dp_xrefs = yypcb->pcb_asxrefs;
2454 2477 yypcb->pcb_prog->dp_xrefslen = yypcb->pcb_asxreflen;
2455 2478 yypcb->pcb_asxrefs = NULL;
2456 2479 yypcb->pcb_asxreflen = 0;
2457 2480
2458 2481 rv = yypcb->pcb_prog;
2459 2482 break;
2460 2483
2461 2484 case DT_CTX_DEXPR:
2462 2485 (void) dt_node_cook(yypcb->pcb_root, DT_IDFLG_REF);
2463 2486 dt_cg(yypcb, yypcb->pcb_root);
2464 2487 rv = dt_as(yypcb);
2465 2488 break;
2466 2489
2467 2490 case DT_CTX_DTYPE:
2468 2491 ddp = (dt_decl_t *)yypcb->pcb_root; /* root is really a decl */
2469 2492 err = dt_decl_type(ddp, arg);
2470 2493 dt_decl_free(ddp);
2471 2494
2472 2495 if (err != 0)
2473 2496 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2474 2497
2475 2498 rv = NULL;
2476 2499 break;
2477 2500 }
2478 2501
2479 2502 out:
2480 2503 if (context != DT_CTX_DTYPE && yypcb->pcb_root != NULL &&
2481 2504 DT_TREEDUMP_PASS(dtp, 3))
2482 2505 dt_node_printr(yypcb->pcb_root, stderr, 0);
2483 2506
2484 2507 if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 ||
2485 2508 lseek64(dtp->dt_cdefs_fd, 0, SEEK_SET) == -1 ||
2486 2509 ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR))
2487 2510 dt_dprintf("failed to update CTF cache: %s\n", strerror(errno));
2488 2511
2489 2512 if (dtp->dt_ddefs_fd != -1 && (ftruncate64(dtp->dt_ddefs_fd, 0) == -1 ||
2490 2513 lseek64(dtp->dt_ddefs_fd, 0, SEEK_SET) == -1 ||
2491 2514 ctf_write(dtp->dt_ddefs->dm_ctfp, dtp->dt_ddefs_fd) == CTF_ERR))
2492 2515 dt_dprintf("failed to update CTF cache: %s\n", strerror(errno));
2493 2516
2494 2517 if (yypcb->pcb_fileptr && (cflags & DTRACE_C_CPP))
2495 2518 (void) fclose(yypcb->pcb_fileptr); /* close dt_preproc() file */
2496 2519
2497 2520 dt_pcb_pop(dtp, err);
2498 2521 (void) dt_set_errno(dtp, err);
2499 2522 return (err ? NULL : rv);
2500 2523 }
2501 2524
2502 2525 dtrace_prog_t *
2503 2526 dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
2504 2527 dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[])
2505 2528 {
2506 2529 return (dt_compile(dtp, DT_CTX_DPROG,
2507 2530 spec, NULL, cflags, argc, argv, NULL, s));
2508 2531 }
2509 2532
2510 2533 dtrace_prog_t *
2511 2534 dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp,
2512 2535 uint_t cflags, int argc, char *const argv[])
2513 2536 {
2514 2537 return (dt_compile(dtp, DT_CTX_DPROG,
2515 2538 DTRACE_PROBESPEC_NAME, NULL, cflags, argc, argv, fp, NULL));
2516 2539 }
2517 2540
2518 2541 int
2519 2542 dtrace_type_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_typeinfo_t *dtt)
2520 2543 {
2521 2544 (void) dt_compile(dtp, DT_CTX_DTYPE,
2522 2545 DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, NULL, s);
2523 2546 return (dtp->dt_errno ? -1 : 0);
2524 2547 }
2525 2548
2526 2549 int
2527 2550 dtrace_type_fcompile(dtrace_hdl_t *dtp, FILE *fp, dtrace_typeinfo_t *dtt)
2528 2551 {
2529 2552 (void) dt_compile(dtp, DT_CTX_DTYPE,
2530 2553 DTRACE_PROBESPEC_NONE, dtt, 0, 0, NULL, fp, NULL);
2531 2554 return (dtp->dt_errno ? -1 : 0);
2532 2555 }
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX