Print this page
3597 dtrace probe lookup ignores provider, asserts on conflict
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_provider.c
+++ new/usr/src/lib/libdtrace/common/dt_provider.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
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
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
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 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/types.h>
30 28 #include <sys/sysmacros.h>
31 29
32 30 #include <assert.h>
33 31 #include <limits.h>
34 32 #include <strings.h>
35 33 #include <stdlib.h>
36 34 #include <alloca.h>
37 35 #include <unistd.h>
38 36 #include <errno.h>
39 37
40 38 #include <dt_provider.h>
41 39 #include <dt_module.h>
42 40 #include <dt_string.h>
43 41 #include <dt_list.h>
44 42
45 43 static dt_provider_t *
46 44 dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h)
47 45 {
48 46 dt_list_append(&dtp->dt_provlist, pvp);
49 47
50 48 pvp->pv_next = dtp->dt_provs[h];
51 49 dtp->dt_provs[h] = pvp;
52 50 dtp->dt_nprovs++;
53 51
54 52 return (pvp);
55 53 }
56 54
57 55 dt_provider_t *
58 56 dt_provider_lookup(dtrace_hdl_t *dtp, const char *name)
59 57 {
60 58 uint_t h = dt_strtab_hash(name, NULL) % dtp->dt_provbuckets;
61 59 dtrace_providerdesc_t desc;
62 60 dt_provider_t *pvp;
63 61
64 62 for (pvp = dtp->dt_provs[h]; pvp != NULL; pvp = pvp->pv_next) {
65 63 if (strcmp(pvp->pv_desc.dtvd_name, name) == 0)
66 64 return (pvp);
67 65 }
68 66
69 67 if (strisglob(name) || name[0] == '\0') {
70 68 (void) dt_set_errno(dtp, EDT_NOPROV);
71 69 return (NULL);
72 70 }
73 71
74 72 bzero(&desc, sizeof (desc));
75 73 (void) strlcpy(desc.dtvd_name, name, DTRACE_PROVNAMELEN);
76 74
77 75 if (dt_ioctl(dtp, DTRACEIOC_PROVIDER, &desc) == -1) {
78 76 (void) dt_set_errno(dtp, errno == ESRCH ? EDT_NOPROV : errno);
79 77 return (NULL);
80 78 }
81 79
82 80 if ((pvp = dt_provider_create(dtp, name)) == NULL)
83 81 return (NULL); /* dt_errno is set for us */
84 82
85 83 bcopy(&desc, &pvp->pv_desc, sizeof (desc));
86 84 pvp->pv_flags |= DT_PROVIDER_IMPL;
87 85 return (pvp);
88 86 }
89 87
90 88 dt_provider_t *
91 89 dt_provider_create(dtrace_hdl_t *dtp, const char *name)
92 90 {
93 91 dt_provider_t *pvp;
94 92
95 93 if ((pvp = dt_zalloc(dtp, sizeof (dt_provider_t))) == NULL)
96 94 return (NULL);
97 95
98 96 (void) strlcpy(pvp->pv_desc.dtvd_name, name, DTRACE_PROVNAMELEN);
99 97 pvp->pv_probes = dt_idhash_create(pvp->pv_desc.dtvd_name, NULL, 0, 0);
100 98 pvp->pv_gen = dtp->dt_gen;
101 99 pvp->pv_hdl = dtp;
102 100
103 101 if (pvp->pv_probes == NULL) {
104 102 dt_free(dtp, pvp);
105 103 (void) dt_set_errno(dtp, EDT_NOMEM);
106 104 return (NULL);
107 105 }
108 106
109 107 pvp->pv_desc.dtvd_attr.dtpa_provider = _dtrace_prvattr;
110 108 pvp->pv_desc.dtvd_attr.dtpa_mod = _dtrace_prvattr;
111 109 pvp->pv_desc.dtvd_attr.dtpa_func = _dtrace_prvattr;
112 110 pvp->pv_desc.dtvd_attr.dtpa_name = _dtrace_prvattr;
113 111 pvp->pv_desc.dtvd_attr.dtpa_args = _dtrace_prvattr;
114 112
115 113 return (dt_provider_insert(dtp, pvp,
116 114 dt_strtab_hash(name, NULL) % dtp->dt_provbuckets));
117 115 }
118 116
119 117 void
120 118 dt_provider_destroy(dtrace_hdl_t *dtp, dt_provider_t *pvp)
121 119 {
122 120 dt_provider_t **pp;
123 121 uint_t h;
124 122
125 123 assert(pvp->pv_hdl == dtp);
126 124
127 125 h = dt_strtab_hash(pvp->pv_desc.dtvd_name, NULL) % dtp->dt_provbuckets;
128 126 pp = &dtp->dt_provs[h];
129 127
130 128 while (*pp != NULL && *pp != pvp)
131 129 pp = &(*pp)->pv_next;
132 130
133 131 assert(*pp != NULL && *pp == pvp);
134 132 *pp = pvp->pv_next;
135 133
136 134 dt_list_delete(&dtp->dt_provlist, pvp);
137 135 dtp->dt_nprovs--;
138 136
139 137 if (pvp->pv_probes != NULL)
140 138 dt_idhash_destroy(pvp->pv_probes);
141 139
142 140 dt_node_link_free(&pvp->pv_nodes);
143 141 dt_free(dtp, pvp->pv_xrefs);
144 142 dt_free(dtp, pvp);
145 143 }
146 144
147 145 int
148 146 dt_provider_xref(dtrace_hdl_t *dtp, dt_provider_t *pvp, id_t id)
149 147 {
150 148 size_t oldsize = BT_SIZEOFMAP(pvp->pv_xrmax);
151 149 size_t newsize = BT_SIZEOFMAP(dtp->dt_xlatorid);
152 150
153 151 assert(id >= 0 && id < dtp->dt_xlatorid);
154 152
155 153 if (newsize > oldsize) {
156 154 ulong_t *xrefs = dt_zalloc(dtp, newsize);
157 155
158 156 if (xrefs == NULL)
159 157 return (-1);
160 158
161 159 bcopy(pvp->pv_xrefs, xrefs, oldsize);
162 160 dt_free(dtp, pvp->pv_xrefs);
163 161
164 162 pvp->pv_xrefs = xrefs;
165 163 pvp->pv_xrmax = dtp->dt_xlatorid;
166 164 }
167 165
168 166 BT_SET(pvp->pv_xrefs, id);
169 167 return (0);
170 168 }
171 169
172 170 static uint8_t
173 171 dt_probe_argmap(dt_node_t *xnp, dt_node_t *nnp)
174 172 {
175 173 uint8_t i;
176 174
177 175 for (i = 0; nnp != NULL; i++) {
178 176 if (nnp->dn_string != NULL &&
179 177 strcmp(nnp->dn_string, xnp->dn_string) == 0)
180 178 break;
181 179 else
182 180 nnp = nnp->dn_list;
183 181 }
184 182
185 183 return (i);
186 184 }
187 185
188 186 static dt_node_t *
189 187 dt_probe_alloc_args(dt_provider_t *pvp, int argc)
190 188 {
191 189 dt_node_t *args = NULL, *pnp = NULL, *dnp;
192 190 int i;
193 191
194 192 for (i = 0; i < argc; i++, pnp = dnp) {
195 193 if ((dnp = dt_node_xalloc(pvp->pv_hdl, DT_NODE_TYPE)) == NULL)
196 194 return (NULL);
197 195
198 196 dnp->dn_link = pvp->pv_nodes;
199 197 pvp->pv_nodes = dnp;
200 198
201 199 if (args == NULL)
202 200 args = dnp;
203 201 else
204 202 pnp->dn_list = dnp;
205 203 }
206 204
207 205 return (args);
208 206 }
209 207
210 208 static size_t
211 209 dt_probe_keylen(const dtrace_probedesc_t *pdp)
212 210 {
213 211 return (strlen(pdp->dtpd_mod) + 1 +
214 212 strlen(pdp->dtpd_func) + 1 + strlen(pdp->dtpd_name) + 1);
215 213 }
216 214
217 215 static char *
218 216 dt_probe_key(const dtrace_probedesc_t *pdp, char *s)
219 217 {
220 218 (void) snprintf(s, INT_MAX, "%s:%s:%s",
221 219 pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name);
222 220 return (s);
223 221 }
224 222
225 223 /*
226 224 * If a probe was discovered from the kernel, ask dtrace(7D) for a description
227 225 * of each of its arguments, including native and translated types.
228 226 */
229 227 static dt_probe_t *
230 228 dt_probe_discover(dt_provider_t *pvp, const dtrace_probedesc_t *pdp)
231 229 {
232 230 dtrace_hdl_t *dtp = pvp->pv_hdl;
233 231 char *name = dt_probe_key(pdp, alloca(dt_probe_keylen(pdp)));
234 232
235 233 dt_node_t *xargs, *nargs;
236 234 dt_ident_t *idp;
237 235 dt_probe_t *prp;
238 236
239 237 dtrace_typeinfo_t dtt;
240 238 int i, nc, xc;
241 239
242 240 int adc = _dtrace_argmax;
243 241 dtrace_argdesc_t *adv = alloca(sizeof (dtrace_argdesc_t) * adc);
244 242 dtrace_argdesc_t *adp = adv;
245 243
246 244 assert(strcmp(pvp->pv_desc.dtvd_name, pdp->dtpd_provider) == 0);
247 245 assert(pdp->dtpd_id != DTRACE_IDNONE);
248 246
249 247 dt_dprintf("discovering probe %s:%s id=%d\n",
250 248 pvp->pv_desc.dtvd_name, name, pdp->dtpd_id);
251 249
252 250 for (nc = -1, i = 0; i < adc; i++, adp++) {
253 251 bzero(adp, sizeof (dtrace_argdesc_t));
254 252 adp->dtargd_ndx = i;
255 253 adp->dtargd_id = pdp->dtpd_id;
256 254
257 255 if (dt_ioctl(dtp, DTRACEIOC_PROBEARG, adp) != 0) {
258 256 (void) dt_set_errno(dtp, errno);
259 257 return (NULL);
260 258 }
261 259
262 260 if (adp->dtargd_ndx == DTRACE_ARGNONE)
263 261 break; /* all argument descs have been retrieved */
264 262
265 263 nc = MAX(nc, adp->dtargd_mapping);
266 264 }
267 265
268 266 xc = i;
269 267 nc++;
270 268
271 269 /*
272 270 * Now that we have discovered the number of native and translated
273 271 * arguments from the argument descriptions, allocate a new probe ident
274 272 * and corresponding dt_probe_t and hash it into the provider.
275 273 */
276 274 xargs = dt_probe_alloc_args(pvp, xc);
277 275 nargs = dt_probe_alloc_args(pvp, nc);
278 276
279 277 if ((xc != 0 && xargs == NULL) || (nc != 0 && nargs == NULL))
280 278 return (NULL); /* dt_errno is set for us */
281 279
282 280 idp = dt_ident_create(name, DT_IDENT_PROBE,
283 281 DT_IDFLG_ORPHAN, pdp->dtpd_id, _dtrace_defattr, 0,
284 282 &dt_idops_probe, NULL, dtp->dt_gen);
285 283
286 284 if (idp == NULL) {
287 285 (void) dt_set_errno(dtp, EDT_NOMEM);
288 286 return (NULL);
289 287 }
290 288
291 289 if ((prp = dt_probe_create(dtp, idp, 2,
292 290 nargs, nc, xargs, xc)) == NULL) {
293 291 dt_ident_destroy(idp);
294 292 return (NULL);
295 293 }
296 294
297 295 dt_probe_declare(pvp, prp);
298 296
299 297 /*
300 298 * Once our new dt_probe_t is fully constructed, iterate over the
301 299 * cached argument descriptions and assign types to prp->pr_nargv[]
302 300 * and prp->pr_xargv[] and assign mappings to prp->pr_mapping[].
303 301 */
304 302 for (adp = adv, i = 0; i < xc; i++, adp++) {
305 303 if (dtrace_type_strcompile(dtp,
306 304 adp->dtargd_native, &dtt) != 0) {
307 305 dt_dprintf("failed to resolve input type %s "
308 306 "for %s:%s arg #%d: %s\n", adp->dtargd_native,
309 307 pvp->pv_desc.dtvd_name, name, i + 1,
310 308 dtrace_errmsg(dtp, dtrace_errno(dtp)));
311 309
312 310 dtt.dtt_object = NULL;
313 311 dtt.dtt_ctfp = NULL;
314 312 dtt.dtt_type = CTF_ERR;
315 313 } else {
316 314 dt_node_type_assign(prp->pr_nargv[adp->dtargd_mapping],
317 315 dtt.dtt_ctfp, dtt.dtt_type);
318 316 }
319 317
320 318 if (dtt.dtt_type != CTF_ERR && (adp->dtargd_xlate[0] == '\0' ||
321 319 strcmp(adp->dtargd_native, adp->dtargd_xlate) == 0)) {
322 320 dt_node_type_propagate(prp->pr_nargv[
323 321 adp->dtargd_mapping], prp->pr_xargv[i]);
324 322 } else if (dtrace_type_strcompile(dtp,
325 323 adp->dtargd_xlate, &dtt) != 0) {
326 324 dt_dprintf("failed to resolve output type %s "
327 325 "for %s:%s arg #%d: %s\n", adp->dtargd_xlate,
328 326 pvp->pv_desc.dtvd_name, name, i + 1,
329 327 dtrace_errmsg(dtp, dtrace_errno(dtp)));
330 328
331 329 dtt.dtt_object = NULL;
332 330 dtt.dtt_ctfp = NULL;
333 331 dtt.dtt_type = CTF_ERR;
334 332 } else {
335 333 dt_node_type_assign(prp->pr_xargv[i],
336 334 dtt.dtt_ctfp, dtt.dtt_type);
337 335 }
338 336
339 337 prp->pr_mapping[i] = adp->dtargd_mapping;
340 338 prp->pr_argv[i] = dtt;
341 339 }
342 340
343 341 return (prp);
344 342 }
345 343
346 344 /*
347 345 * Lookup a probe declaration based on a known provider and full or partially
348 346 * specified module, function, and name. If the probe is not known to us yet,
349 347 * ask dtrace(7D) to match the description and then cache any useful results.
350 348 */
351 349 dt_probe_t *
352 350 dt_probe_lookup(dt_provider_t *pvp, const char *s)
↓ open down ↓ |
314 lines elided |
↑ open up ↑ |
353 351 {
354 352 dtrace_hdl_t *dtp = pvp->pv_hdl;
355 353 dtrace_probedesc_t pd;
356 354 dt_ident_t *idp;
357 355 size_t keylen;
358 356 char *key;
359 357
360 358 if (dtrace_str2desc(dtp, DTRACE_PROBESPEC_NAME, s, &pd) != 0)
361 359 return (NULL); /* dt_errno is set for us */
362 360
361 + /*
362 + * Make sure the probe is fully specified as being in this provider,
363 + * even if the name is missing that part of the specification,
364 + * otherwise our lookups may match in the wrong provider when we ask
365 + * dtrace(7D).
366 + *
367 + * We always do this because we are explicitly searching _this_
368 + * provider.
369 + */
370 + bcopy(pvp->pv_desc.dtvd_name, pd.dtpd_provider,
371 + DTRACE_PROVNAMELEN);
372 +
363 373 keylen = dt_probe_keylen(&pd);
364 374 key = dt_probe_key(&pd, alloca(keylen));
365 375
366 376 /*
367 377 * If the probe is already declared, then return the dt_probe_t from
368 378 * the existing identifier. This could come from a static declaration
369 379 * or it could have been cached from an earlier call to this function.
370 380 */
371 381 if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL)
372 382 return (idp->di_data);
373 383
374 384 /*
375 385 * If the probe isn't known, use the probe description computed above
376 386 * to ask dtrace(7D) to find the first matching probe.
377 387 */
378 388 if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0)
379 389 return (dt_probe_discover(pvp, &pd));
380 390
381 391 if (errno == ESRCH || errno == EBADF)
382 392 (void) dt_set_errno(dtp, EDT_NOPROBE);
383 393 else
384 394 (void) dt_set_errno(dtp, errno);
385 395
386 396 return (NULL);
387 397 }
388 398
389 399 dt_probe_t *
390 400 dt_probe_create(dtrace_hdl_t *dtp, dt_ident_t *idp, int protoc,
391 401 dt_node_t *nargs, uint_t nargc, dt_node_t *xargs, uint_t xargc)
392 402 {
393 403 dt_module_t *dmp;
394 404 dt_probe_t *prp;
395 405 const char *p;
396 406 uint_t i;
397 407
398 408 assert(idp->di_kind == DT_IDENT_PROBE);
399 409 assert(idp->di_data == NULL);
400 410
401 411 /*
402 412 * If only a single prototype is given, set xargc/s to nargc/s to
403 413 * simplify subsequent use. Note that we can have one or both of nargs
404 414 * and xargs be specified but set to NULL, indicating a void prototype.
405 415 */
406 416 if (protoc < 2) {
407 417 assert(xargs == NULL);
408 418 assert(xargc == 0);
409 419 xargs = nargs;
410 420 xargc = nargc;
411 421 }
412 422
413 423 if ((prp = dt_alloc(dtp, sizeof (dt_probe_t))) == NULL)
414 424 return (NULL);
415 425
416 426 prp->pr_pvp = NULL;
417 427 prp->pr_ident = idp;
418 428
419 429 p = strrchr(idp->di_name, ':');
420 430 assert(p != NULL);
421 431 prp->pr_name = p + 1;
422 432
423 433 prp->pr_nargs = nargs;
424 434 prp->pr_nargv = dt_alloc(dtp, sizeof (dt_node_t *) * nargc);
425 435 prp->pr_nargc = nargc;
426 436 prp->pr_xargs = xargs;
427 437 prp->pr_xargv = dt_alloc(dtp, sizeof (dt_node_t *) * xargc);
428 438 prp->pr_xargc = xargc;
429 439 prp->pr_mapping = dt_alloc(dtp, sizeof (uint8_t) * xargc);
430 440 prp->pr_inst = NULL;
431 441 prp->pr_argv = dt_alloc(dtp, sizeof (dtrace_typeinfo_t) * xargc);
432 442 prp->pr_argc = xargc;
433 443
434 444 if ((prp->pr_nargc != 0 && prp->pr_nargv == NULL) ||
435 445 (prp->pr_xargc != 0 && prp->pr_xargv == NULL) ||
436 446 (prp->pr_xargc != 0 && prp->pr_mapping == NULL) ||
437 447 (prp->pr_argc != 0 && prp->pr_argv == NULL)) {
438 448 dt_probe_destroy(prp);
439 449 return (NULL);
440 450 }
441 451
442 452 for (i = 0; i < xargc; i++, xargs = xargs->dn_list) {
443 453 if (xargs->dn_string != NULL)
444 454 prp->pr_mapping[i] = dt_probe_argmap(xargs, nargs);
445 455 else
446 456 prp->pr_mapping[i] = i;
447 457
448 458 prp->pr_xargv[i] = xargs;
449 459
450 460 if ((dmp = dt_module_lookup_by_ctf(dtp,
451 461 xargs->dn_ctfp)) != NULL)
452 462 prp->pr_argv[i].dtt_object = dmp->dm_name;
453 463 else
454 464 prp->pr_argv[i].dtt_object = NULL;
455 465
456 466 prp->pr_argv[i].dtt_ctfp = xargs->dn_ctfp;
457 467 prp->pr_argv[i].dtt_type = xargs->dn_type;
458 468 }
459 469
460 470 for (i = 0; i < nargc; i++, nargs = nargs->dn_list)
461 471 prp->pr_nargv[i] = nargs;
462 472
463 473 idp->di_data = prp;
464 474 return (prp);
465 475 }
466 476
467 477 void
468 478 dt_probe_declare(dt_provider_t *pvp, dt_probe_t *prp)
469 479 {
470 480 assert(prp->pr_ident->di_kind == DT_IDENT_PROBE);
471 481 assert(prp->pr_ident->di_data == prp);
472 482 assert(prp->pr_pvp == NULL);
473 483
474 484 if (prp->pr_xargs != prp->pr_nargs)
475 485 pvp->pv_flags &= ~DT_PROVIDER_INTF;
476 486
477 487 prp->pr_pvp = pvp;
478 488 dt_idhash_xinsert(pvp->pv_probes, prp->pr_ident);
479 489 }
480 490
481 491 void
482 492 dt_probe_destroy(dt_probe_t *prp)
483 493 {
484 494 dt_probe_instance_t *pip, *pip_next;
485 495 dtrace_hdl_t *dtp;
486 496
487 497 if (prp->pr_pvp != NULL)
488 498 dtp = prp->pr_pvp->pv_hdl;
489 499 else
490 500 dtp = yypcb->pcb_hdl;
491 501
492 502 dt_node_list_free(&prp->pr_nargs);
493 503 dt_node_list_free(&prp->pr_xargs);
494 504
495 505 dt_free(dtp, prp->pr_nargv);
496 506 dt_free(dtp, prp->pr_xargv);
497 507
498 508 for (pip = prp->pr_inst; pip != NULL; pip = pip_next) {
499 509 pip_next = pip->pi_next;
500 510 dt_free(dtp, pip->pi_offs);
501 511 dt_free(dtp, pip->pi_enoffs);
502 512 dt_free(dtp, pip);
503 513 }
504 514
505 515 dt_free(dtp, prp->pr_mapping);
506 516 dt_free(dtp, prp->pr_argv);
507 517 dt_free(dtp, prp);
508 518 }
509 519
510 520 int
511 521 dt_probe_define(dt_provider_t *pvp, dt_probe_t *prp,
512 522 const char *fname, const char *rname, uint32_t offset, int isenabled)
513 523 {
514 524 dtrace_hdl_t *dtp = pvp->pv_hdl;
515 525 dt_probe_instance_t *pip;
516 526 uint32_t **offs;
517 527 uint_t *noffs, *maxoffs;
518 528
519 529 assert(fname != NULL);
520 530
521 531 for (pip = prp->pr_inst; pip != NULL; pip = pip->pi_next) {
522 532 if (strcmp(pip->pi_fname, fname) == 0 &&
523 533 ((rname == NULL && pip->pi_rname[0] == '\0') ||
524 534 (rname != NULL && strcmp(pip->pi_rname, rname)) == 0))
525 535 break;
526 536 }
527 537
528 538 if (pip == NULL) {
529 539 if ((pip = dt_zalloc(dtp, sizeof (*pip))) == NULL)
530 540 return (-1);
531 541
532 542 if ((pip->pi_offs = dt_zalloc(dtp,
533 543 sizeof (uint32_t))) == NULL) {
534 544 dt_free(dtp, pip);
535 545 return (-1);
536 546 }
537 547
538 548 if ((pip->pi_enoffs = dt_zalloc(dtp,
539 549 sizeof (uint32_t))) == NULL) {
540 550 dt_free(dtp, pip->pi_offs);
541 551 dt_free(dtp, pip);
542 552 return (-1);
543 553 }
544 554
545 555 (void) strlcpy(pip->pi_fname, fname, sizeof (pip->pi_fname));
546 556 if (rname != NULL) {
547 557 if (strlen(rname) + 1 > sizeof (pip->pi_rname)) {
548 558 dt_free(dtp, pip->pi_offs);
549 559 dt_free(dtp, pip);
550 560 return (dt_set_errno(dtp, EDT_COMPILER));
551 561 }
552 562 (void) strcpy(pip->pi_rname, rname);
553 563 }
554 564
555 565 pip->pi_noffs = 0;
556 566 pip->pi_maxoffs = 1;
557 567 pip->pi_nenoffs = 0;
558 568 pip->pi_maxenoffs = 1;
559 569
560 570 pip->pi_next = prp->pr_inst;
561 571
562 572 prp->pr_inst = pip;
563 573 }
564 574
565 575 if (isenabled) {
566 576 offs = &pip->pi_enoffs;
567 577 noffs = &pip->pi_nenoffs;
568 578 maxoffs = &pip->pi_maxenoffs;
569 579 } else {
570 580 offs = &pip->pi_offs;
571 581 noffs = &pip->pi_noffs;
572 582 maxoffs = &pip->pi_maxoffs;
573 583 }
574 584
575 585 if (*noffs == *maxoffs) {
576 586 uint_t new_max = *maxoffs * 2;
577 587 uint32_t *new_offs = dt_alloc(dtp, sizeof (uint32_t) * new_max);
578 588
579 589 if (new_offs == NULL)
580 590 return (-1);
581 591
582 592 bcopy(*offs, new_offs, sizeof (uint32_t) * *maxoffs);
583 593
584 594 dt_free(dtp, *offs);
585 595 *maxoffs = new_max;
586 596 *offs = new_offs;
587 597 }
588 598
589 599 dt_dprintf("defined probe %s %s:%s %s() +0x%x (%s)\n",
590 600 isenabled ? "(is-enabled)" : "",
591 601 pvp->pv_desc.dtvd_name, prp->pr_ident->di_name, fname, offset,
592 602 rname != NULL ? rname : fname);
593 603
594 604 assert(*noffs < *maxoffs);
595 605 (*offs)[(*noffs)++] = offset;
596 606
597 607 return (0);
598 608 }
599 609
600 610 /*
601 611 * Lookup the dynamic translator type tag for the specified probe argument and
602 612 * assign the type to the specified node. If the type is not yet defined, add
603 613 * it to the "D" module's type container as a typedef for an unknown type.
604 614 */
605 615 dt_node_t *
606 616 dt_probe_tag(dt_probe_t *prp, uint_t argn, dt_node_t *dnp)
607 617 {
608 618 dtrace_hdl_t *dtp = prp->pr_pvp->pv_hdl;
609 619 dtrace_typeinfo_t dtt;
610 620 size_t len;
611 621 char *tag;
612 622
613 623 len = snprintf(NULL, 0, "__dtrace_%s___%s_arg%u",
614 624 prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn);
615 625
616 626 tag = alloca(len + 1);
617 627
618 628 (void) snprintf(tag, len + 1, "__dtrace_%s___%s_arg%u",
619 629 prp->pr_pvp->pv_desc.dtvd_name, prp->pr_name, argn);
620 630
621 631 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_DDEFS, tag, &dtt) != 0) {
622 632 dtt.dtt_object = DTRACE_OBJ_DDEFS;
623 633 dtt.dtt_ctfp = DT_DYN_CTFP(dtp);
624 634 dtt.dtt_type = ctf_add_typedef(DT_DYN_CTFP(dtp),
625 635 CTF_ADD_ROOT, tag, DT_DYN_TYPE(dtp));
626 636
627 637 if (dtt.dtt_type == CTF_ERR ||
628 638 ctf_update(dtt.dtt_ctfp) == CTF_ERR) {
629 639 xyerror(D_UNKNOWN, "cannot define type %s: %s\n",
630 640 tag, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
631 641 }
632 642 }
633 643
634 644 bzero(dnp, sizeof (dt_node_t));
635 645 dnp->dn_kind = DT_NODE_TYPE;
636 646
637 647 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
638 648 dt_node_attr_assign(dnp, _dtrace_defattr);
639 649
640 650 return (dnp);
641 651 }
642 652
643 653 /*ARGSUSED*/
644 654 static int
645 655 dt_probe_desc(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp, void *arg)
646 656 {
647 657 if (((dtrace_probedesc_t *)arg)->dtpd_id == DTRACE_IDNONE) {
648 658 bcopy(pdp, arg, sizeof (dtrace_probedesc_t));
649 659 return (0);
650 660 }
651 661
652 662 return (1);
653 663 }
654 664
655 665 dt_probe_t *
656 666 dt_probe_info(dtrace_hdl_t *dtp,
657 667 const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip)
658 668 {
659 669 int m_is_glob = pdp->dtpd_mod[0] == '\0' || strisglob(pdp->dtpd_mod);
660 670 int f_is_glob = pdp->dtpd_func[0] == '\0' || strisglob(pdp->dtpd_func);
661 671 int n_is_glob = pdp->dtpd_name[0] == '\0' || strisglob(pdp->dtpd_name);
662 672
663 673 dt_probe_t *prp = NULL;
664 674 const dtrace_pattr_t *pap;
665 675 dt_provider_t *pvp;
666 676 dt_ident_t *idp;
667 677
668 678 /*
669 679 * Attempt to lookup the probe in our existing cache for this provider.
670 680 * If none is found and an explicit probe ID was specified, discover
671 681 * that specific probe and cache its description and arguments.
672 682 */
673 683 if ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) != NULL) {
674 684 size_t keylen = dt_probe_keylen(pdp);
675 685 char *key = dt_probe_key(pdp, alloca(keylen));
676 686
677 687 if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL)
678 688 prp = idp->di_data;
679 689 else if (pdp->dtpd_id != DTRACE_IDNONE)
680 690 prp = dt_probe_discover(pvp, pdp);
681 691 }
682 692
683 693 /*
684 694 * If no probe was found in our cache, convert the caller's partial
685 695 * probe description into a fully-formed matching probe description by
686 696 * iterating over up to at most two probes that match 'pdp'. We then
687 697 * call dt_probe_discover() on the resulting probe identifier.
688 698 */
689 699 if (prp == NULL) {
690 700 dtrace_probedesc_t pd;
691 701 int m;
692 702
693 703 bzero(&pd, sizeof (pd));
694 704 pd.dtpd_id = DTRACE_IDNONE;
695 705
696 706 /*
697 707 * Call dtrace_probe_iter() to find matching probes. Our
698 708 * dt_probe_desc() callback will produce the following results:
699 709 *
700 710 * m < 0 dtrace_probe_iter() found zero matches (or failed).
701 711 * m > 0 dtrace_probe_iter() found more than one match.
702 712 * m = 0 dtrace_probe_iter() found exactly one match.
703 713 */
704 714 if ((m = dtrace_probe_iter(dtp, pdp, dt_probe_desc, &pd)) < 0)
705 715 return (NULL); /* dt_errno is set for us */
706 716
707 717 if ((pvp = dt_provider_lookup(dtp, pd.dtpd_provider)) == NULL)
708 718 return (NULL); /* dt_errno is set for us */
709 719
710 720 /*
711 721 * If more than one probe was matched, then do not report probe
712 722 * information if either of the following conditions is true:
713 723 *
714 724 * (a) The Arguments Data stability of the matched provider is
715 725 * less than Evolving.
716 726 *
717 727 * (b) Any description component that is at least Evolving is
718 728 * empty or is specified using a globbing expression.
719 729 *
720 730 * These conditions imply that providers that provide Evolving
721 731 * or better Arguments Data stability must guarantee that all
722 732 * probes with identical field names in a field of Evolving or
723 733 * better Name stability have identical argument signatures.
724 734 */
725 735 if (m > 0) {
726 736 if (pvp->pv_desc.dtvd_attr.dtpa_args.dtat_data <
727 737 DTRACE_STABILITY_EVOLVING) {
728 738 (void) dt_set_errno(dtp, EDT_UNSTABLE);
729 739 return (NULL);
730 740 }
731 741
732 742
733 743 if (pvp->pv_desc.dtvd_attr.dtpa_mod.dtat_name >=
734 744 DTRACE_STABILITY_EVOLVING && m_is_glob) {
735 745 (void) dt_set_errno(dtp, EDT_UNSTABLE);
736 746 return (NULL);
737 747 }
738 748
739 749 if (pvp->pv_desc.dtvd_attr.dtpa_func.dtat_name >=
740 750 DTRACE_STABILITY_EVOLVING && f_is_glob) {
741 751 (void) dt_set_errno(dtp, EDT_UNSTABLE);
742 752 return (NULL);
743 753 }
744 754
745 755 if (pvp->pv_desc.dtvd_attr.dtpa_name.dtat_name >=
746 756 DTRACE_STABILITY_EVOLVING && n_is_glob) {
747 757 (void) dt_set_errno(dtp, EDT_UNSTABLE);
748 758 return (NULL);
749 759 }
750 760 }
751 761
752 762 /*
753 763 * If we matched a probe exported by dtrace(7D), then discover
754 764 * the real attributes. Otherwise grab the static declaration.
755 765 */
756 766 if (pd.dtpd_id != DTRACE_IDNONE)
757 767 prp = dt_probe_discover(pvp, &pd);
758 768 else
759 769 prp = dt_probe_lookup(pvp, pd.dtpd_name);
760 770
761 771 if (prp == NULL)
762 772 return (NULL); /* dt_errno is set for us */
763 773 }
764 774
765 775 assert(pvp != NULL && prp != NULL);
766 776
767 777 /*
768 778 * Compute the probe description attributes by taking the minimum of
769 779 * the attributes of the specified fields. If no provider is specified
770 780 * or a glob pattern is used for the provider, use Unstable attributes.
771 781 */
772 782 if (pdp->dtpd_provider[0] == '\0' || strisglob(pdp->dtpd_provider))
773 783 pap = &_dtrace_prvdesc;
774 784 else
775 785 pap = &pvp->pv_desc.dtvd_attr;
776 786
777 787 pip->dtp_attr = pap->dtpa_provider;
778 788
779 789 if (!m_is_glob)
780 790 pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_mod);
781 791 if (!f_is_glob)
782 792 pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_func);
783 793 if (!n_is_glob)
784 794 pip->dtp_attr = dt_attr_min(pip->dtp_attr, pap->dtpa_name);
785 795
786 796 pip->dtp_arga = pap->dtpa_args;
787 797 pip->dtp_argv = prp->pr_argv;
788 798 pip->dtp_argc = prp->pr_argc;
789 799
790 800 return (prp);
791 801 }
792 802
793 803 int
794 804 dtrace_probe_info(dtrace_hdl_t *dtp,
795 805 const dtrace_probedesc_t *pdp, dtrace_probeinfo_t *pip)
796 806 {
797 807 return (dt_probe_info(dtp, pdp, pip) != NULL ? 0 : -1);
798 808 }
799 809
800 810 /*ARGSUSED*/
801 811 static int
802 812 dt_probe_iter(dt_idhash_t *ihp, dt_ident_t *idp, dt_probe_iter_t *pit)
803 813 {
804 814 const dt_probe_t *prp = idp->di_data;
805 815
806 816 if (!dt_gmatch(prp->pr_name, pit->pit_pat))
807 817 return (0); /* continue on and examine next probe in hash */
808 818
809 819 (void) strlcpy(pit->pit_desc.dtpd_name, prp->pr_name, DTRACE_NAMELEN);
810 820 pit->pit_desc.dtpd_id = idp->di_id;
811 821 pit->pit_matches++;
812 822
813 823 return (pit->pit_func(pit->pit_hdl, &pit->pit_desc, pit->pit_arg));
814 824 }
815 825
816 826 int
817 827 dtrace_probe_iter(dtrace_hdl_t *dtp,
818 828 const dtrace_probedesc_t *pdp, dtrace_probe_f *func, void *arg)
819 829 {
820 830 const char *provider = pdp ? pdp->dtpd_provider : NULL;
821 831 dtrace_id_t id = DTRACE_IDNONE;
822 832
823 833 dtrace_probedesc_t pd;
824 834 dt_probe_iter_t pit;
825 835 int cmd, rv;
826 836
827 837 bzero(&pit, sizeof (pit));
828 838 pit.pit_hdl = dtp;
829 839 pit.pit_func = func;
830 840 pit.pit_arg = arg;
831 841 pit.pit_pat = pdp ? pdp->dtpd_name : NULL;
832 842
833 843 for (pit.pit_pvp = dt_list_next(&dtp->dt_provlist);
834 844 pit.pit_pvp != NULL; pit.pit_pvp = dt_list_next(pit.pit_pvp)) {
835 845
836 846 if (pit.pit_pvp->pv_flags & DT_PROVIDER_IMPL)
837 847 continue; /* we'll get these later using dt_ioctl() */
838 848
839 849 if (!dt_gmatch(pit.pit_pvp->pv_desc.dtvd_name, provider))
840 850 continue;
841 851
842 852 (void) strlcpy(pit.pit_desc.dtpd_provider,
843 853 pit.pit_pvp->pv_desc.dtvd_name, DTRACE_PROVNAMELEN);
844 854
845 855 if ((rv = dt_idhash_iter(pit.pit_pvp->pv_probes,
846 856 (dt_idhash_f *)dt_probe_iter, &pit)) != 0)
847 857 return (rv);
848 858 }
849 859
850 860 if (pdp != NULL)
851 861 cmd = DTRACEIOC_PROBEMATCH;
852 862 else
853 863 cmd = DTRACEIOC_PROBES;
854 864
855 865 for (;;) {
856 866 if (pdp != NULL)
857 867 bcopy(pdp, &pd, sizeof (pd));
858 868
859 869 pd.dtpd_id = id;
860 870
861 871 if (dt_ioctl(dtp, cmd, &pd) != 0)
862 872 break;
863 873 else if ((rv = func(dtp, &pd, arg)) != 0)
864 874 return (rv);
865 875
866 876 pit.pit_matches++;
867 877 id = pd.dtpd_id + 1;
868 878 }
869 879
870 880 switch (errno) {
871 881 case ESRCH:
872 882 case EBADF:
873 883 return (pit.pit_matches ? 0 : dt_set_errno(dtp, EDT_NOPROBE));
874 884 case EINVAL:
875 885 return (dt_set_errno(dtp, EDT_BADPGLOB));
876 886 default:
877 887 return (dt_set_errno(dtp, errno));
878 888 }
879 889 }
↓ open down ↓ |
507 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX