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