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.
28 #include <sys/sysmacros.h>
30 #include <sys/isa_defs.h>
43 #include <sys/sysctl.h>
44 #include <libproc_compat.h>
56 } dtrace_probespecs[] = {
57 { offsetof(dtrace_probedesc_t, dtpd_provider), DTRACE_PROVNAMELEN },
58 { offsetof(dtrace_probedesc_t, dtpd_mod), DTRACE_MODNAMELEN },
59 { offsetof(dtrace_probedesc_t, dtpd_func), DTRACE_FUNCNAMELEN },
60 { offsetof(dtrace_probedesc_t, dtpd_name), DTRACE_NAMELEN }
64 dtrace_xstr2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec,
65 const char *s, int argc, char *const argv[], dtrace_probedesc_t *pdp)
67 size_t off, len, vlen, wlen;
68 const char *p, *q, *v, *w;
70 char buf[32]; /* for id_t as %d (see below) */
72 if (spec < DTRACE_PROBESPEC_NONE || spec > DTRACE_PROBESPEC_NAME)
73 return (dt_set_errno(dtp, EINVAL));
75 bzero(pdp, sizeof (dtrace_probedesc_t));
76 p = s + strlen(s) - 1;
79 for (len = 0; p >= s && *p != ':'; len++)
80 p--; /* move backward until we find a delimiter */
87 if ((v = strchr(q, '$')) != NULL && v < q + len) {
89 * Set vlen to the length of the variable name and then
90 * reset len to the length of the text prior to '$'. If
91 * the name begins with a digit, interpret it using the
92 * the argv[] array. Otherwise we look in dt_macros.
93 * For the moment, all dt_macros variables are of type
94 * id_t (see dtrace_update() for more details on that).
96 vlen = (size_t)(q + len - v);
97 len = (size_t)(v - q);
100 * If the variable string begins with $$, skip past the
101 * leading dollar sign since $ and $$ are equivalent
102 * macro reference operators in a probe description.
104 if (vlen > 2 && v[1] == '$') {
113 i = strtol(v + 1, (char **)&w, 10);
115 wlen = vlen - (w - v);
117 if (i < 0 || i >= argc || errno != 0)
118 return (dt_set_errno(dtp, EDT_BADSPCV));
123 if (yypcb != NULL && yypcb->pcb_sargv == argv)
124 yypcb->pcb_sflagv[i] |= DT_IDFLG_REF;
126 } else if (vlen > 1) {
127 char *vstr = alloca(vlen);
130 (void) strncpy(vstr, v + 1, vlen - 1);
131 vstr[vlen - 1] = '\0';
132 idp = dt_idhash_lookup(dtp->dt_macros, vstr);
135 return (dt_set_errno(dtp, EDT_BADSPCV));
138 vlen = snprintf(buf, 32, "%d", idp->di_id);
141 return (dt_set_errno(dtp, EDT_BADSPCV));
144 if (spec == DTRACE_PROBESPEC_NONE)
145 return (dt_set_errno(dtp, EDT_BADSPEC));
147 if (len + vlen >= dtrace_probespecs[spec].dtps_len)
148 return (dt_set_errno(dtp, ENAMETOOLONG));
150 off = dtrace_probespecs[spec--].dtps_offset;
151 bcopy(q, (char *)pdp + off, len);
152 bcopy(v, (char *)pdp + off + len, vlen);
153 bcopy(w, (char *)pdp + off + len + vlen, wlen);
156 pdp->dtpd_id = DTRACE_IDNONE;
161 dtrace_str2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec,
162 const char *s, dtrace_probedesc_t *pdp)
164 return (dtrace_xstr2desc(dtp, spec, s, 0, NULL, pdp));
168 dtrace_id2desc(dtrace_hdl_t *dtp, dtrace_id_t id, dtrace_probedesc_t *pdp)
170 bzero(pdp, sizeof (dtrace_probedesc_t));
173 if (dt_ioctl(dtp, DTRACEIOC_PROBES, pdp) == -1 ||
175 return (dt_set_errno(dtp, EDT_BADID));
181 dtrace_desc2str(const dtrace_probedesc_t *pdp, char *buf, size_t len)
183 if (pdp->dtpd_id == 0) {
184 (void) snprintf(buf, len, "%s:%s:%s:%s", pdp->dtpd_provider,
185 pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name);
187 (void) snprintf(buf, len, "%u", pdp->dtpd_id);
193 dtrace_attr2str(dtrace_attribute_t attr, char *buf, size_t len)
195 const char *name = dtrace_stability_name(attr.dtat_name);
196 const char *data = dtrace_stability_name(attr.dtat_data);
197 const char *class = dtrace_class_name(attr.dtat_class);
199 if (name == NULL || data == NULL || class == NULL)
200 return (NULL); /* one or more invalid attributes */
202 (void) snprintf(buf, len, "%s/%s/%s", name, data, class);
207 dt_getstrattr(char *p, char **qp)
214 if ((q = strchr(p, '/')) == NULL)
224 dtrace_str2attr(const char *str, dtrace_attribute_t *attr)
226 dtrace_stability_t s;
230 if (str == NULL || attr == NULL)
231 return (-1); /* invalid function arguments */
233 *attr = _dtrace_maxattr;
234 p = alloca(strlen(str) + 1);
235 (void) strcpy(p, str);
237 if ((p = dt_getstrattr(p, &q)) == NULL)
240 for (s = 0; s <= DTRACE_STABILITY_MAX; s++) {
241 if (strcasecmp(p, dtrace_stability_name(s)) == 0) {
247 if (s > DTRACE_STABILITY_MAX)
250 if ((p = dt_getstrattr(q, &q)) == NULL)
253 for (s = 0; s <= DTRACE_STABILITY_MAX; s++) {
254 if (strcasecmp(p, dtrace_stability_name(s)) == 0) {
260 if (s > DTRACE_STABILITY_MAX)
263 if ((p = dt_getstrattr(q, &q)) == NULL)
266 for (c = 0; c <= DTRACE_CLASS_MAX; c++) {
267 if (strcasecmp(p, dtrace_class_name(c)) == 0) {
268 attr->dtat_class = c;
273 if (c > DTRACE_CLASS_MAX || (p = dt_getstrattr(q, &q)) != NULL)
280 dtrace_stability_name(dtrace_stability_t s)
283 case DTRACE_STABILITY_INTERNAL: return ("Internal");
284 case DTRACE_STABILITY_PRIVATE: return ("Private");
285 case DTRACE_STABILITY_OBSOLETE: return ("Obsolete");
286 case DTRACE_STABILITY_EXTERNAL: return ("External");
287 case DTRACE_STABILITY_UNSTABLE: return ("Unstable");
288 case DTRACE_STABILITY_EVOLVING: return ("Evolving");
289 case DTRACE_STABILITY_STABLE: return ("Stable");
290 case DTRACE_STABILITY_STANDARD: return ("Standard");
291 default: return (NULL);
296 dtrace_class_name(dtrace_class_t c)
299 case DTRACE_CLASS_UNKNOWN: return ("Unknown");
300 case DTRACE_CLASS_CPU: return ("CPU");
301 case DTRACE_CLASS_PLATFORM: return ("Platform");
302 case DTRACE_CLASS_GROUP: return ("Group");
303 case DTRACE_CLASS_ISA: return ("ISA");
304 case DTRACE_CLASS_COMMON: return ("Common");
305 default: return (NULL);
310 dt_attr_min(dtrace_attribute_t a1, dtrace_attribute_t a2)
312 dtrace_attribute_t am;
314 am.dtat_name = MIN(a1.dtat_name, a2.dtat_name);
315 am.dtat_data = MIN(a1.dtat_data, a2.dtat_data);
316 am.dtat_class = MIN(a1.dtat_class, a2.dtat_class);
322 dt_attr_max(dtrace_attribute_t a1, dtrace_attribute_t a2)
324 dtrace_attribute_t am;
326 am.dtat_name = MAX(a1.dtat_name, a2.dtat_name);
327 am.dtat_data = MAX(a1.dtat_data, a2.dtat_data);
328 am.dtat_class = MAX(a1.dtat_class, a2.dtat_class);
334 * Compare two attributes and return an integer value in the following ranges:
336 * <0 if any of a1's attributes are less than a2's attributes
337 * =0 if all of a1's attributes are equal to a2's attributes
338 * >0 if all of a1's attributes are greater than or equal to a2's attributes
340 * To implement this function efficiently, we subtract a2's attributes from
341 * a1's to obtain a negative result if an a1 attribute is less than its a2
342 * counterpart. We then OR the intermediate results together, relying on the
343 * twos-complement property that if any result is negative, the bitwise union
344 * will also be negative since the highest bit will be set in the result.
347 dt_attr_cmp(dtrace_attribute_t a1, dtrace_attribute_t a2)
349 return (((int)a1.dtat_name - a2.dtat_name) |
350 ((int)a1.dtat_data - a2.dtat_data) |
351 ((int)a1.dtat_class - a2.dtat_class));
355 dt_attr_str(dtrace_attribute_t a, char *buf, size_t len)
357 static const char stability[] = "ipoxuesS";
358 static const char class[] = "uCpgIc";
360 if (a.dtat_name < sizeof (stability) &&
361 a.dtat_data < sizeof (stability) && a.dtat_class < sizeof (class)) {
362 (void) snprintf(buf, len, "[%c/%c/%c]", stability[a.dtat_name],
363 stability[a.dtat_data], class[a.dtat_class]);
365 (void) snprintf(buf, len, "[%u/%u/%u]",
366 a.dtat_name, a.dtat_data, a.dtat_class);
373 dt_version_num2str(dt_version_t v, char *buf, size_t len)
375 uint_t M = DT_VERSION_MAJOR(v);
376 uint_t m = DT_VERSION_MINOR(v);
377 uint_t u = DT_VERSION_MICRO(v);
380 (void) snprintf(buf, len, "%u.%u", M, m);
382 (void) snprintf(buf, len, "%u.%u.%u", M, m, u);
388 dt_version_str2num(const char *s, dt_version_t *vp)
390 int i = 0, n[3] = { 0, 0, 0 };
393 while ((c = *s++) != '\0') {
395 n[i] = n[i] * 10 + c - '0';
396 else if (c != '.' || i++ >= sizeof (n) / sizeof (n[0]) - 1)
400 if (n[0] > DT_VERSION_MAJMAX ||
401 n[1] > DT_VERSION_MINMAX ||
402 n[2] > DT_VERSION_MICMAX)
406 *vp = DT_VERSION_NUMBER(n[0], n[1], n[2]);
412 dt_version_defined(dt_version_t v)
416 for (i = 0; _dtrace_versions[i] != 0; i++) {
417 if (_dtrace_versions[i] == v)
425 dt_cpp_add_arg(dtrace_hdl_t *dtp, const char *str)
429 if (dtp->dt_cpp_argc == dtp->dt_cpp_args) {
430 int olds = dtp->dt_cpp_args;
432 char **argv = realloc(dtp->dt_cpp_argv, sizeof (char *) * news);
437 bzero(&argv[olds], sizeof (char *) * olds);
438 dtp->dt_cpp_argv = argv;
439 dtp->dt_cpp_args = news;
442 if ((arg = strdup(str)) == NULL)
445 assert(dtp->dt_cpp_argc < dtp->dt_cpp_args);
446 dtp->dt_cpp_argv[dtp->dt_cpp_argc++] = arg;
451 dt_cpp_pop_arg(dtrace_hdl_t *dtp)
455 if (dtp->dt_cpp_argc <= 1)
456 return (NULL); /* dt_cpp_argv[0] cannot be popped */
458 arg = dtp->dt_cpp_argv[--dtp->dt_cpp_argc];
459 dtp->dt_cpp_argv[dtp->dt_cpp_argc] = NULL;
466 dt_dprintf(const char *format, ...)
471 va_start(alist, format);
472 (void) fputs("libdtrace DEBUG: ", stderr);
473 (void) vfprintf(stderr, format, alist);
480 dt_ioctl(dtrace_hdl_t *dtp, int val, void *arg)
482 dt_ioctl(dtrace_hdl_t *dtp, u_long val, void *arg)
485 const dtrace_vector_t *v = dtp->dt_vector;
488 /* Avoid sign extension. */
493 return (v->dtv_ioctl(dtp->dt_varg, val, arg));
496 return (ioctl(dtp->dt_fd, val, arg));
503 dt_status(dtrace_hdl_t *dtp, processorid_t cpu)
505 const dtrace_vector_t *v = dtp->dt_vector;
509 return (p_online(cpu, P_STATUS));
512 size_t len = sizeof(maxid);
513 if (sysctlbyname("kern.smp.maxid", &maxid, &len, NULL, 0) != 0)
514 return (cpu == 0 ? 1 : -1);
516 return (cpu <= maxid ? 1 : -1);
520 return (v->dtv_status(dtp->dt_varg, cpu));
524 dt_sysconf(dtrace_hdl_t *dtp, int name)
526 const dtrace_vector_t *v = dtp->dt_vector;
529 return (sysconf(name));
531 return (v->dtv_sysconf(dtp->dt_varg, name));
535 * Wrapper around write(2) to handle partial writes. For maximum safety of
536 * output files and proper error reporting, we continuing writing in the
537 * face of partial writes until write(2) fails or 'buf' is completely written.
538 * We also record any errno in the specified dtrace_hdl_t as well as 'errno'.
541 dt_write(dtrace_hdl_t *dtp, int fd, const void *buf, size_t n)
547 if ((len = write(fd, buf, resid)) <= 0)
551 buf = (char *)buf + len;
554 if (resid == n && n != 0)
555 return (dt_set_errno(dtp, errno));
561 * This function handles all output from libdtrace, as well as the
562 * dtrace_sprintf() case. If we're here due to dtrace_sprintf(), then
563 * dt_sprintf_buflen will be non-zero; in this case, we sprintf into the
564 * specified buffer and return. Otherwise, if output is buffered (denoted by
565 * a NULL fp), we sprintf the desired output into the buffered buffer
566 * (expanding the buffer if required). If we don't satisfy either of these
567 * conditions (that is, if we are to actually generate output), then we call
568 * fprintf with the specified fp. In this case, we need to deal with one of
569 * the more annoying peculiarities of libc's printf routines: any failed
570 * write persistently sets an error flag inside the FILE causing every
571 * subsequent write to fail, but only the caller that initiated the error gets
572 * the errno. Since libdtrace clients often intercept SIGINT, this case is
573 * particularly frustrating since we don't want the EINTR on one attempt to
574 * write to the output file to preclude later attempts to write. This
575 * function therefore does a clearerr() if any error occurred, and saves the
576 * errno for the caller inside the specified dtrace_hdl_t.
580 dt_printf(dtrace_hdl_t *dtp, FILE *fp, const char *format, ...)
587 * On FreeBSD, check if output is currently being re-directed
588 * to another file. If so, output to that file instead of the
589 * one the caller has specified.
591 if (dtp->dt_freopen_fp != NULL)
592 fp = dtp->dt_freopen_fp;
595 va_start(ap, format);
597 if (dtp->dt_sprintf_buflen != 0) {
601 assert(dtp->dt_sprintf_buf != NULL);
603 buf = &dtp->dt_sprintf_buf[len = strlen(dtp->dt_sprintf_buf)];
604 len = dtp->dt_sprintf_buflen - len;
607 if ((n = vsnprintf(buf, len, format, ap)) < 0)
608 n = dt_set_errno(dtp, errno);
620 * It's not legal to use buffered ouput if there is not a
621 * handler for buffered output.
623 if (dtp->dt_bufhdlr == NULL) {
625 return (dt_set_errno(dtp, EDT_NOBUFFERED));
628 if (dtp->dt_buffered_buf == NULL) {
629 assert(dtp->dt_buffered_size == 0);
630 dtp->dt_buffered_size = 1;
631 dtp->dt_buffered_buf = malloc(dtp->dt_buffered_size);
633 if (dtp->dt_buffered_buf == NULL) {
635 return (dt_set_errno(dtp, EDT_NOMEM));
638 dtp->dt_buffered_offs = 0;
639 dtp->dt_buffered_buf[0] = '\0';
642 if ((needed = vsnprintf(NULL, 0, format, ap)) < 0) {
643 rval = dt_set_errno(dtp, errno);
656 assert(dtp->dt_buffered_offs < dtp->dt_buffered_size);
657 avail = dtp->dt_buffered_size - dtp->dt_buffered_offs;
659 if (needed + 1 < avail)
662 if ((newbuf = realloc(dtp->dt_buffered_buf,
663 dtp->dt_buffered_size << 1)) == NULL) {
665 return (dt_set_errno(dtp, EDT_NOMEM));
668 dtp->dt_buffered_buf = newbuf;
669 dtp->dt_buffered_size <<= 1;
672 if (vsnprintf(&dtp->dt_buffered_buf[dtp->dt_buffered_offs],
673 avail, format, ap) < 0) {
674 rval = dt_set_errno(dtp, errno);
679 dtp->dt_buffered_offs += needed;
680 assert(dtp->dt_buffered_buf[dtp->dt_buffered_offs] == '\0');
684 n = vfprintf(fp, format, ap);
690 return (dt_set_errno(dtp, errno));
697 dt_buffered_flush(dtrace_hdl_t *dtp, dtrace_probedata_t *pdata,
698 const dtrace_recdesc_t *rec, const dtrace_aggdata_t *agg, uint32_t flags)
700 dtrace_bufdata_t data;
702 if (dtp->dt_buffered_offs == 0)
705 data.dtbda_handle = dtp;
706 data.dtbda_buffered = dtp->dt_buffered_buf;
707 data.dtbda_probe = pdata;
708 data.dtbda_recdesc = rec;
709 data.dtbda_aggdata = agg;
710 data.dtbda_flags = flags;
712 if ((*dtp->dt_bufhdlr)(&data, dtp->dt_bufarg) == DTRACE_HANDLE_ABORT)
713 return (dt_set_errno(dtp, EDT_DIRABORT));
715 dtp->dt_buffered_offs = 0;
716 dtp->dt_buffered_buf[0] = '\0';
722 dt_buffered_destroy(dtrace_hdl_t *dtp)
724 free(dtp->dt_buffered_buf);
725 dtp->dt_buffered_buf = NULL;
726 dtp->dt_buffered_offs = 0;
727 dtp->dt_buffered_size = 0;
731 dt_zalloc(dtrace_hdl_t *dtp, size_t size)
735 if (size > 16 * 1024 * 1024) {
736 (void) dt_set_errno(dtp, EDT_NOMEM);
740 if ((data = malloc(size)) == NULL)
741 (void) dt_set_errno(dtp, EDT_NOMEM);
749 dt_alloc(dtrace_hdl_t *dtp, size_t size)
753 if (size > 16 * 1024 * 1024) {
754 (void) dt_set_errno(dtp, EDT_NOMEM);
758 if ((data = malloc(size)) == NULL)
759 (void) dt_set_errno(dtp, EDT_NOMEM);
765 dt_free(dtrace_hdl_t *dtp, void *data)
767 assert(dtp != NULL); /* ensure sane use of this interface */
772 dt_difo_free(dtrace_hdl_t *dtp, dtrace_difo_t *dp)
775 return; /* simplify caller code */
777 dt_free(dtp, dp->dtdo_buf);
778 dt_free(dtp, dp->dtdo_inttab);
779 dt_free(dtp, dp->dtdo_strtab);
780 dt_free(dtp, dp->dtdo_vartab);
781 dt_free(dtp, dp->dtdo_kreltab);
782 dt_free(dtp, dp->dtdo_ureltab);
783 dt_free(dtp, dp->dtdo_xlmtab);
789 * dt_gmatch() is similar to gmatch(3GEN) and dtrace(7D) globbing, but also
790 * implements the behavior that an empty pattern matches any string.
793 dt_gmatch(const char *s, const char *p)
795 return (p == NULL || *p == '\0' || gmatch(s, p));
799 dt_basename(char *str)
801 char *last = strrchr(str, '/');
810 * dt_popc() is a fast implementation of population count. The algorithm is
811 * from "Hacker's Delight" by Henry Warren, Jr with a 64-bit equivalent added.
817 x = x - ((x >> 1) & 0x55555555UL);
818 x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
819 x = (x + (x >> 4)) & 0x0F0F0F0FUL;
824 x = x - ((x >> 1) & 0x5555555555555555ULL);
825 x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
826 x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
832 /* This should be a #warning but for now ignore error. Err: "need td_popc() implementation" */
837 * dt_popcb() is a bitmap-based version of population count that returns the
838 * number of one bits in the specified bitmap 'bp' at bit positions below 'n'.
841 dt_popcb(const ulong_t *bp, ulong_t n)
843 ulong_t maxb = n & BT_ULMASK;
844 ulong_t maxw = n >> BT_ULSHIFT;
850 for (w = 0; w < maxw; w++)
851 popc += dt_popc(bp[w]);
853 return (popc + dt_popc(bp[maxw] & ((1UL << maxb) - 1)));
861 dt_rw_read_held(pthread_rwlock_t *lock)
863 extern int _rw_read_held(struct _rwlock *);
864 return (_rw_read_held((struct _rwlock *)lock));
868 dt_rw_write_held(pthread_rwlock_t *lock)
870 extern int _rw_write_held(struct _rwlock *);
871 return (_rw_write_held((struct _rwlock *)lock));
876 dt_mutex_held(pthread_mutex_t *lock)
879 extern int _mutex_held(struct _lwp_mutex *);
880 return (_mutex_held((struct _lwp_mutex *)lock));
887 dt_string2str(char *s, char *str, int nbytes)
893 * Like snprintf(3C), we don't check the value of str if the
894 * number of bytes is 0.
900 (void) strncpy(str, s, nbytes - 1);
902 * Like snprintf(3C) (and unlike strncpy(3C)), we guarantee
903 * that the string is null-terminated.
905 str[nbytes - 1] = '\0';
907 (void) strcpy(str, s);
914 dtrace_addr2str(dtrace_hdl_t *dtp, uint64_t addr, char *str, int nbytes)
916 dtrace_syminfo_t dts;
919 size_t n = 20; /* for 0x%llx\0 */
923 if ((err = dtrace_lookup_by_addr(dtp, addr, &sym, &dts)) == 0)
924 n += strlen(dts.dts_object) + strlen(dts.dts_name) + 2; /* +` */
928 if (err == 0 && addr != sym.st_value) {
929 (void) snprintf(s, n, "%s`%s+0x%llx", dts.dts_object,
930 dts.dts_name, (u_longlong_t)addr - sym.st_value);
931 } else if (err == 0) {
932 (void) snprintf(s, n, "%s`%s",
933 dts.dts_object, dts.dts_name);
936 * We'll repeat the lookup, but this time we'll specify a NULL
937 * GElf_Sym -- indicating that we're only interested in the
940 if (dtrace_lookup_by_addr(dtp, addr, NULL, &dts) == 0) {
941 (void) snprintf(s, n, "%s`0x%llx", dts.dts_object,
944 (void) snprintf(s, n, "0x%llx", (u_longlong_t)addr);
948 return (dt_string2str(s, str, nbytes));
952 dtrace_uaddr2str(dtrace_hdl_t *dtp, pid_t pid,
953 uint64_t addr, char *str, int nbytes)
955 char name[PATH_MAX], objname[PATH_MAX], c[PATH_MAX * 2];
956 struct ps_prochandle *P = NULL;
961 P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0);
964 (void) snprintf(c, sizeof (c), "0x%jx", (uintmax_t)addr);
965 return (dt_string2str(c, str, nbytes));
968 dt_proc_lock(dtp, P);
970 if (Plookup_by_addr(P, addr, name, sizeof (name), &sym) == 0) {
971 (void) Pobjname(P, addr, objname, sizeof (objname));
973 obj = dt_basename(objname);
975 if (addr > sym.st_value) {
976 (void) snprintf(c, sizeof (c), "%s`%s+0x%llx", obj,
977 name, (u_longlong_t)(addr - sym.st_value));
979 (void) snprintf(c, sizeof (c), "%s`%s", obj, name);
981 } else if (Pobjname(P, addr, objname, sizeof (objname)) != 0) {
982 (void) snprintf(c, sizeof (c), "%s`0x%jx",
983 dt_basename(objname), (uintmax_t)addr);
985 (void) snprintf(c, sizeof (c), "0x%jx", (uintmax_t)addr);
988 dt_proc_unlock(dtp, P);
989 dt_proc_release(dtp, P);
991 return (dt_string2str(c, str, nbytes));