4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
41 #include <sys/sysmacros.h>
44 #include <dt_program.h>
46 #include <dt_string.h>
48 #include <libproc_compat.h>
50 #include <dt_module.h>
52 typedef struct dt_pid_probe {
53 dtrace_hdl_t *dpp_dtp;
56 struct ps_prochandle *dpp_pr;
65 uint64_t dpp_stret[4];
67 uint_t dpp_last_taken;
71 * Compose the lmid and object name into the canonical representation. We
72 * omit the lmid for the default link map for convenience.
75 dt_pid_objname(char *buf, size_t len, Lmid_t lmid, const char *obj)
78 if (lmid == LM_ID_BASE)
79 (void) strncpy(buf, obj, len);
81 (void) snprintf(buf, len, "LM%lx`%s", lmid, obj);
83 (void) strncpy(buf, obj, len);
88 dt_pid_error(dtrace_hdl_t *dtp, dt_pcb_t *pcb, dt_proc_t *dpr,
89 fasttrap_probe_spec_t *ftp, dt_errtag_t tag, const char *fmt, ...)
100 len = vsnprintf(dpr->dpr_errmsg, sizeof (dpr->dpr_errmsg),
103 if (dpr->dpr_errmsg[len - 2] == '\n')
104 dpr->dpr_errmsg[len - 2] = '\0';
106 dt_set_errmsg(dtp, dt_errtag(tag), pcb->pcb_region,
107 pcb->pcb_filetag, pcb->pcb_fileptr ? yylineno : 0, fmt, ap);
115 dt_pid_per_sym(dt_pid_probe_t *pp, const GElf_Sym *symp, const char *func)
117 dtrace_hdl_t *dtp = pp->dpp_dtp;
118 dt_pcb_t *pcb = pp->dpp_pcb;
119 dt_proc_t *dpr = pp->dpp_dpr;
120 fasttrap_probe_spec_t *ftp;
126 int isdash = strcmp("-", func) == 0;
130 pid = Pstatus(pp->dpp_pr)->pr_pid;
132 pid = proc_getpid(pp->dpp_pr);
135 dt_dprintf("creating probe pid%d:%s:%s:%s\n", (int)pid, pp->dpp_obj,
138 sz = sizeof (fasttrap_probe_spec_t) + (isdash ? 4 :
139 (symp->st_size - 1) * sizeof (ftp->ftps_offs[0]));
141 if ((ftp = dt_alloc(dtp, sz)) == NULL) {
142 dt_dprintf("proc_per_sym: dt_alloc(%lu) failed\n", sz);
143 return (1); /* errno is set for us */
147 (void) strncpy(ftp->ftps_func, func, sizeof (ftp->ftps_func));
149 dt_pid_objname(ftp->ftps_mod, sizeof (ftp->ftps_mod), pp->dpp_lmid,
152 if (!isdash && gmatch("return", pp->dpp_name)) {
153 if (dt_pid_create_return_probe(pp->dpp_pr, dtp, ftp, symp,
154 pp->dpp_stret) < 0) {
155 return (dt_pid_error(dtp, pcb, dpr, ftp,
156 D_PROC_CREATEFAIL, "failed to create return probe "
157 "for '%s': %s", func,
158 dtrace_errmsg(dtp, dtrace_errno(dtp))));
164 if (!isdash && gmatch("entry", pp->dpp_name)) {
165 if (dt_pid_create_entry_probe(pp->dpp_pr, dtp, ftp, symp) < 0) {
166 return (dt_pid_error(dtp, pcb, dpr, ftp,
167 D_PROC_CREATEFAIL, "failed to create entry probe "
168 "for '%s': %s", func,
169 dtrace_errmsg(dtp, dtrace_errno(dtp))));
175 glob = strisglob(pp->dpp_name);
176 if (!glob && nmatches == 0) {
177 off = strtoull(pp->dpp_name, &end, 16);
179 return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_NAME,
180 "'%s' is an invalid probe name", pp->dpp_name));
183 if (off >= symp->st_size) {
184 return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_OFF,
185 "offset 0x%llx outside of function '%s'",
186 (u_longlong_t)off, func));
189 err = dt_pid_create_offset_probe(pp->dpp_pr, pp->dpp_dtp, ftp,
192 if (err == DT_PROC_ERR) {
193 return (dt_pid_error(dtp, pcb, dpr, ftp,
194 D_PROC_CREATEFAIL, "failed to create probe at "
195 "'%s+0x%llx': %s", func, (u_longlong_t)off,
196 dtrace_errmsg(dtp, dtrace_errno(dtp))));
199 if (err == DT_PROC_ALIGN) {
200 return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_ALIGN,
201 "offset 0x%llx is not aligned on an instruction",
207 } else if (glob && !isdash) {
208 if (dt_pid_create_glob_offset_probes(pp->dpp_pr,
209 pp->dpp_dtp, ftp, symp, pp->dpp_name) < 0) {
210 return (dt_pid_error(dtp, pcb, dpr, ftp,
212 "failed to create offset probes in '%s': %s", func,
213 dtrace_errmsg(dtp, dtrace_errno(dtp))));
219 pp->dpp_nmatches += nmatches;
227 dt_pid_sym_filt(void *arg, const GElf_Sym *symp, const char *func)
229 dt_pid_probe_t *pp = arg;
231 if (symp->st_shndx == SHN_UNDEF)
234 if (symp->st_size == 0) {
235 dt_dprintf("st_size of %s is zero\n", func);
239 if (pp->dpp_last_taken == 0 ||
240 symp->st_value != pp->dpp_last.st_value ||
241 symp->st_size != pp->dpp_last.st_size) {
243 * Due to 4524008, _init and _fini may have a bloated st_size.
244 * While this bug has been fixed for a while, old binaries
245 * may exist that still exhibit this problem. As a result, we
246 * don't match _init and _fini though we allow users to
247 * specify them explicitly.
249 if (strcmp(func, "_init") == 0 || strcmp(func, "_fini") == 0)
252 if ((pp->dpp_last_taken = gmatch(func, pp->dpp_func)) != 0) {
253 pp->dpp_last = *symp;
254 return (dt_pid_per_sym(pp, symp, func));
262 dt_pid_per_mod(void *arg, const prmap_t *pmp, const char *obj)
264 dt_pid_probe_t *pp = arg;
265 dtrace_hdl_t *dtp = pp->dpp_dtp;
266 dt_pcb_t *pcb = pp->dpp_pcb;
267 dt_proc_t *dpr = pp->dpp_dpr;
274 (void) Plmid(pp->dpp_pr, pmp->pr_vaddr, &pp->dpp_lmid);
278 if ((pp->dpp_obj = strrchr(obj, '/')) == NULL)
283 if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret1", &sym,
285 pp->dpp_stret[0] = sym.st_value;
287 pp->dpp_stret[0] = 0;
289 if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret2", &sym,
291 pp->dpp_stret[1] = sym.st_value;
293 pp->dpp_stret[1] = 0;
295 if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret4", &sym,
297 pp->dpp_stret[2] = sym.st_value;
299 pp->dpp_stret[2] = 0;
301 if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret8", &sym,
303 pp->dpp_stret[3] = sym.st_value;
305 pp->dpp_stret[3] = 0;
307 pp->dpp_stret[0] = 0;
308 pp->dpp_stret[1] = 0;
309 pp->dpp_stret[2] = 0;
310 pp->dpp_stret[3] = 0;
313 dt_dprintf("%s stret %llx %llx %llx %llx\n", obj,
314 (u_longlong_t)pp->dpp_stret[0], (u_longlong_t)pp->dpp_stret[1],
315 (u_longlong_t)pp->dpp_stret[2], (u_longlong_t)pp->dpp_stret[3]);
318 * If pp->dpp_func contains any globbing meta-characters, we need
319 * to iterate over the symbol table and compare each function name
320 * against the pattern.
322 if (!strisglob(pp->dpp_func)) {
324 * If we fail to lookup the symbol, try interpreting the
325 * function as the special "-" function that indicates that the
326 * probe name should be interpreted as a absolute virtual
327 * address. If that fails and we were matching a specific
328 * function in a specific module, report the error, otherwise
329 * just fail silently in the hopes that some other object will
330 * contain the desired symbol.
332 if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj,
333 pp->dpp_func, &sym, NULL) != 0) {
334 if (strcmp("-", pp->dpp_func) == 0) {
337 GELF_ST_INFO(STB_LOCAL, STT_FUNC);
341 sym.st_size = Pstatus(pp->dpp_pr)->pr_dmodel ==
342 PR_MODEL_ILP32 ? -1U : -1ULL;
344 sym.st_size = ~((Elf64_Xword) 0);
347 } else if (!strisglob(pp->dpp_mod)) {
348 return (dt_pid_error(dtp, pcb, dpr, NULL,
350 "failed to lookup '%s' in module '%s'",
351 pp->dpp_func, pp->dpp_mod));
358 * Only match defined functions of non-zero size.
360 if (GELF_ST_TYPE(sym.st_info) != STT_FUNC ||
361 sym.st_shndx == SHN_UNDEF || sym.st_size == 0)
365 * We don't instrument PLTs -- they're dynamically rewritten,
366 * and, so, inherently dicey to instrument.
369 if (Ppltdest(pp->dpp_pr, sym.st_value) != NULL)
373 (void) Plookup_by_addr(pp->dpp_pr, sym.st_value, pp->dpp_func,
374 DTRACE_FUNCNAMELEN, &sym);
376 return (dt_pid_per_sym(pp, &sym, pp->dpp_func));
378 uint_t nmatches = pp->dpp_nmatches;
380 if (Psymbol_iter_by_addr(pp->dpp_pr, obj, PR_SYMTAB,
381 BIND_ANY | TYPE_FUNC, dt_pid_sym_filt, pp) == 1)
384 if (nmatches == pp->dpp_nmatches) {
386 * If we didn't match anything in the PR_SYMTAB, try
389 if (Psymbol_iter_by_addr(pp->dpp_pr, obj, PR_DYNSYM,
390 BIND_ANY | TYPE_FUNC, dt_pid_sym_filt, pp) == 1)
399 dt_pid_mod_filt(void *arg, const prmap_t *pmp, const char *obj)
401 char name[DTRACE_MODNAMELEN];
402 dt_pid_probe_t *pp = arg;
404 if (gmatch(obj, pp->dpp_mod))
405 return (dt_pid_per_mod(pp, pmp, obj));
408 (void) Plmid(pp->dpp_pr, pmp->pr_vaddr, &pp->dpp_lmid);
413 if ((pp->dpp_obj = strrchr(obj, '/')) == NULL)
418 if (gmatch(pp->dpp_obj, pp->dpp_mod))
419 return (dt_pid_per_mod(pp, pmp, obj));
422 (void) Plmid(pp->dpp_pr, pmp->pr_vaddr, &pp->dpp_lmid);
425 dt_pid_objname(name, sizeof (name), pp->dpp_lmid, pp->dpp_obj);
427 if (gmatch(name, pp->dpp_mod))
428 return (dt_pid_per_mod(pp, pmp, obj));
433 static const prmap_t *
434 dt_pid_fix_mod(dtrace_probedesc_t *pdp, struct ps_prochandle *P)
438 Lmid_t lmid = PR_LMID_EVERY;
447 * Pick apart the link map from the library name.
449 if (strchr(pdp->dtpd_mod, '`') != NULL) {
452 if (strncmp(pdp->dtpd_mod, "LM", 2) != 0 ||
453 !isdigit(pdp->dtpd_mod[2]))
456 lmid = strtoul(&pdp->dtpd_mod[2], &end, 16);
460 if (*end != '`' || strchr(obj, '`') != NULL)
470 if ((pmp = Plmid_to_map(P, lmid, obj)) == NULL)
474 (void) Pobjname(P, pmp->pr_vaddr, m, sizeof (m));
475 if ((obj = strrchr(m, '/')) == NULL)
480 (void) Plmid(P, pmp->pr_vaddr, &lmid);
483 dt_pid_objname(pdp->dtpd_mod, sizeof (pdp->dtpd_mod), lmid, obj);
490 dt_pid_create_pid_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp,
491 dt_pcb_t *pcb, dt_proc_t *dpr)
498 pp.dpp_pr = dpr->dpr_proc;
503 * We can only trace dynamically-linked executables (since we've
504 * hidden some magic in ld.so.1 as well as libc.so.1).
506 if (Pname_to_map(pp.dpp_pr, PR_OBJ_LDSO) == NULL) {
507 return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_DYN,
508 "process %s is not a dynamically-linked executable",
509 &pdp->dtpd_provider[3]));
513 pp.dpp_mod = pdp->dtpd_mod[0] != '\0' ? pdp->dtpd_mod : "*";
514 pp.dpp_func = pdp->dtpd_func[0] != '\0' ? pdp->dtpd_func : "*";
515 pp.dpp_name = pdp->dtpd_name[0] != '\0' ? pdp->dtpd_name : "*";
516 pp.dpp_last_taken = 0;
518 if (strcmp(pp.dpp_func, "-") == 0) {
519 const prmap_t *aout, *pmp;
521 if (pdp->dtpd_mod[0] == '\0') {
522 pp.dpp_mod = pdp->dtpd_mod;
523 (void) strcpy(pdp->dtpd_mod, "a.out");
524 } else if (strisglob(pp.dpp_mod) ||
525 (aout = Pname_to_map(pp.dpp_pr, "a.out")) == NULL ||
526 (pmp = Pname_to_map(pp.dpp_pr, pp.dpp_mod)) == NULL ||
527 aout->pr_vaddr != pmp->pr_vaddr) {
528 return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_LIB,
529 "only the a.out module is valid with the "
533 if (strisglob(pp.dpp_name)) {
534 return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_NAME,
535 "only individual addresses may be specified "
536 "with the '-' function"));
541 * If pp.dpp_mod contains any globbing meta-characters, we need
542 * to iterate over each module and compare its name against the
543 * pattern. An empty module name is treated as '*'.
545 if (strisglob(pp.dpp_mod)) {
546 ret = Pobject_iter(pp.dpp_pr, dt_pid_mod_filt, &pp);
552 * If we can't find a matching module, don't sweat it -- either
553 * we'll fail the enabling because the probes don't exist or
554 * we'll wait for that module to come along.
556 if ((pmp = dt_pid_fix_mod(pdp, pp.dpp_pr)) != NULL) {
557 if ((obj = strchr(pdp->dtpd_mod, '`')) == NULL)
562 ret = dt_pid_per_mod(&pp, pmp, obj);
570 dt_pid_usdt_mapping(void *data, const prmap_t *pmp, const char *oname)
572 struct ps_prochandle *P = data;
580 const char *syms[] = { "___SUNW_dof", "__SUNW_dof" };
584 * The symbol ___SUNW_dof is for lazy-loaded DOF sections, and
585 * __SUNW_dof is for actively-loaded DOF sections. We try to force
586 * in both types of DOF section since the process may not yet have
587 * run the code to instantiate these providers.
589 for (i = 0; i < 2; i++) {
590 if (Pxlookup_by_name(P, PR_LMID_EVERY, oname, syms[i], &sym,
595 if ((mname = strrchr(oname, '/')) == NULL)
600 dt_dprintf("lookup of %s succeeded for %s\n", syms[i], mname);
602 if (Pread(P, &e_type, sizeof (e_type), pmp->pr_vaddr +
603 offsetof(Elf64_Ehdr, e_type)) != sizeof (e_type)) {
604 dt_dprintf("read of ELF header failed");
608 dh.dofhp_dof = sym.st_value;
609 dh.dofhp_addr = (e_type == ET_EXEC) ? 0 : pmp->pr_vaddr;
611 dt_pid_objname(dh.dofhp_mod, sizeof (dh.dofhp_mod),
613 sip.prs_lmid, mname);
620 (fd = pr_open(P, "/dev/dtrace/helper", O_RDWR, 0)) < 0) {
621 dt_dprintf("pr_open of helper device failed: %s\n",
623 return (-1); /* errno is set for us */
626 if (pr_ioctl(P, fd, DTRACEHIOC_ADDDOF, &dh, sizeof (dh)) < 0)
627 dt_dprintf("DOF was rejected for %s\n", dh.dofhp_mod);
633 (void) pr_close(P, fd);
640 dt_pid_create_usdt_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp,
641 dt_pcb_t *pcb, dt_proc_t *dpr)
643 struct ps_prochandle *P = dpr->dpr_proc;
646 assert(DT_MUTEX_HELD(&dpr->dpr_lock));
648 (void) Pupdate_maps(P);
649 if (Pobject_iter(P, dt_pid_usdt_mapping, P) != 0) {
651 (void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_USDT,
652 "failed to instantiate probes for pid %d: %s",
654 (int)Pstatus(P)->pr_pid, strerror(errno));
656 (int)proc_getpid(P), strerror(errno));
664 * Put the module name in its canonical form.
666 (void) dt_pid_fix_mod(pdp, P);
672 dt_pid_get_pid(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *pcb,
676 char *c, *last = NULL, *end;
678 for (c = &pdp->dtpd_provider[0]; *c != '\0'; c++) {
683 if (last == NULL || (*(++last) == '\0')) {
684 (void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_BADPROV,
685 "'%s' is not a valid provider", pdp->dtpd_provider);
690 pid = strtol(last, &end, 10);
692 if (errno != 0 || end == last || end[0] != '\0' || pid <= 0) {
693 (void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_BADPID,
694 "'%s' does not contain a valid pid", pdp->dtpd_provider);
702 dt_pid_create_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *pcb)
704 char provname[DTRACE_PROVNAMELEN];
705 struct ps_prochandle *P;
712 if ((pid = dt_pid_get_pid(pdp, dtp, pcb, NULL)) == -1)
715 if (dtp->dt_ftfd == -1) {
716 if (dtp->dt_fterr == ENOENT) {
717 (void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_NODEV,
718 "pid provider is not installed on this system");
720 (void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_NODEV,
721 "pid provider is not available: %s",
722 strerror(dtp->dt_fterr));
728 (void) snprintf(provname, sizeof (provname), "pid%d", (int)pid);
730 if (gmatch(provname, pdp->dtpd_provider) != 0) {
731 if ((P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE,
733 (void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_GRAB,
734 "failed to grab process %d", (int)pid);
738 dpr = dt_proc_lookup(dtp, P, 0);
740 (void) pthread_mutex_lock(&dpr->dpr_lock);
742 if ((err = dt_pid_create_pid_probes(pdp, dtp, pcb, dpr)) == 0) {
744 * Alert other retained enablings which may match
745 * against the newly created probes.
747 (void) dt_ioctl(dtp, DTRACEIOC_ENABLE, NULL);
750 (void) pthread_mutex_unlock(&dpr->dpr_lock);
751 dt_proc_release(dtp, P);
755 * If it's not strictly a pid provider, we might match a USDT provider.
757 if (strcmp(provname, pdp->dtpd_provider) != 0) {
758 if ((P = dt_proc_grab(dtp, pid, 0, 1)) == NULL) {
759 (void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_GRAB,
760 "failed to grab process %d", (int)pid);
764 dpr = dt_proc_lookup(dtp, P, 0);
766 (void) pthread_mutex_lock(&dpr->dpr_lock);
768 if (!dpr->dpr_usdt) {
769 err = dt_pid_create_usdt_probes(pdp, dtp, pcb, dpr);
770 dpr->dpr_usdt = B_TRUE;
773 (void) pthread_mutex_unlock(&dpr->dpr_lock);
774 dt_proc_release(dtp, P);
777 return (err ? -1 : 0);
781 dt_pid_create_probes_module(dtrace_hdl_t *dtp, dt_proc_t *dpr)
783 dtrace_enable_io_t args;
786 dtrace_probedesc_t *pdp, pd;
788 int ret = 0, found = B_FALSE;
789 char provname[DTRACE_PROVNAMELEN];
791 (void) snprintf(provname, sizeof (provname), "pid%d",
794 for (pgp = dt_list_next(&dtp->dt_programs); pgp != NULL;
795 pgp = dt_list_next(pgp)) {
797 for (stp = dt_list_next(&pgp->dp_stmts); stp != NULL;
798 stp = dt_list_next(stp)) {
800 pdp = &stp->ds_desc->dtsd_ecbdesc->dted_probe;
801 pid = dt_pid_get_pid(pdp, dtp, NULL, dpr);
802 if (pid != dpr->dpr_pid)
809 if (gmatch(provname, pdp->dtpd_provider) != 0 &&
810 dt_pid_create_pid_probes(&pd, dtp, NULL, dpr) != 0)
814 * If it's not strictly a pid provider, we might match
817 if (strcmp(provname, pdp->dtpd_provider) != 0 &&
818 dt_pid_create_usdt_probes(&pd, dtp, NULL, dpr) != 0)
825 * Give DTrace a shot to the ribs to get it to check
826 * out the newly created probes.
830 (void) dt_ioctl(dtp, DTRACEIOC_ENABLE, &args);
837 * libdtrace has a backroom deal with us to ask us for type information on
838 * behalf of pid provider probes when fasttrap doesn't return any type
839 * information. Instead we'll look up the module and see if there is type
840 * information available. However, if there is no type information available due
841 * to a lack of CTF data, then we want to make sure that DTrace still carries on
842 * in face of that. As such we don't have a meaningful exit code about failure.
843 * We emit information about why we failed to the dtrace debug log so someone
844 * can figure it out by asking nicely for DTRACE_DEBUG.
847 dt_pid_get_types(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp,
848 dtrace_argdesc_t *adp, int *nargs)
860 struct ps_prochandle *p;
862 char buf[DTRACE_ARGTYPELEN];
866 int argc = sizeof (argv) / sizeof (ctf_id_t);
869 /* Set up a potential outcome */
874 * If we don't have an entry or return probe then we can just stop right
875 * now as we don't have arguments for offset probes.
877 if (strcmp(pdp->dtpd_name, "entry") != 0 &&
878 strcmp(pdp->dtpd_name, "return") != 0)
881 dmp = dt_module_create(dtp, pdp->dtpd_provider);
883 dt_dprintf("failed to find module for %s\n",
887 if (dt_module_load(dtp, dmp) != 0) {
888 dt_dprintf("failed to load module for %s\n",
894 * We may be working with a module that doesn't have ctf. If that's the
895 * case then we just return now and move on with life.
897 fp = dt_module_getctflib(dtp, dmp, pdp->dtpd_mod);
899 dt_dprintf("no ctf container for %s\n",
903 p = dt_proc_grab(dtp, dmp->dm_pid, 0, PGRAB_RDONLY | PGRAB_FORCE);
905 dt_dprintf("failed to grab pid\n");
908 dt_proc_lock(dtp, p);
911 * Check to see if the D module has a link map ID and separate that out
912 * for properly interrogating libproc.
914 if ((mptr = strchr(pdp->dtpd_mod, '`')) != NULL) {
915 if (strlen(pdp->dtpd_mod) < 3) {
916 dt_dprintf("found weird modname with linkmap, "
917 "aborting: %s\n", pdp->dtpd_mod);
920 if (pdp->dtpd_mod[0] != 'L' || pdp->dtpd_mod[1] != 'M') {
921 dt_dprintf("missing leading 'LM', "
922 "aborting: %s\n", pdp->dtpd_mod);
926 lmid = strtol(pdp->dtpd_mod + 2, &eptr, 16);
927 if (errno == ERANGE || eptr != mptr) {
928 dt_dprintf("failed to parse out lmid, aborting: %s\n",
934 mptr = pdp->dtpd_mod;
938 if (Pxlookup_by_name(p, lmid, mptr, pdp->dtpd_func,
940 dt_dprintf("failed to find function %s in %s`%s\n",
941 pdp->dtpd_func, pdp->dtpd_provider, pdp->dtpd_mod);
945 if (ctf_func_info(fp, si.prs_id, &f) == CTF_ERR) {
946 dt_dprintf("failed to get ctf information for %s in %s`%s\n",
947 pdp->dtpd_func, pdp->dtpd_provider, pdp->dtpd_mod);
952 (void) snprintf(buf, sizeof (buf), "%s`%s", pdp->dtpd_provider,
955 if (strcmp(pdp->dtpd_name, "return") == 0) {
959 bzero(adp, sizeof (dtrace_argdesc_t));
961 adp->dtargd_id = pdp->dtpd_id;
962 adp->dtargd_mapping = adp->dtargd_ndx;
964 * We explicitly leave out the library here, we only care that
965 * it is some int. We are assuming that there is no ctf
966 * container in here that is lying about what an int is.
968 (void) snprintf(adp->dtargd_native, DTRACE_ARGTYPELEN,
969 "user %s`%s", pdp->dtpd_provider, "int");
971 bzero(adp, sizeof (dtrace_argdesc_t));
973 adp->dtargd_id = pdp->dtpd_id;
974 adp->dtargd_mapping = adp->dtargd_ndx;
975 ret = snprintf(adp->dtargd_native, DTRACE_ARGTYPELEN,
977 (void) ctf_type_qname(fp, f.ctc_return, adp->dtargd_native +
978 ret, DTRACE_ARGTYPELEN - ret, buf);
982 if (ctf_func_args(fp, si.prs_id, argc, argv) == CTF_ERR)
985 *nargs = MIN(args, f.ctc_argc);
986 for (i = 0; i < *nargs; i++, adp++) {
987 bzero(adp, sizeof (dtrace_argdesc_t));
989 adp->dtargd_id = pdp->dtpd_id;
990 adp->dtargd_mapping = adp->dtargd_ndx;
991 ret = snprintf(adp->dtargd_native, DTRACE_ARGTYPELEN,
993 (void) ctf_type_qname(fp, argv[i], adp->dtargd_native +
994 ret, DTRACE_ARGTYPELEN - ret, buf);
999 dt_proc_unlock(dtp, p);
1000 dt_proc_release(dtp, p);