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 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Use is subject to license terms.
29 #include <sys/sysmacros.h>
31 #include <sys/isa_defs.h>
44 #include <sys/sysctl.h>
45 #include <libproc_compat.h>
57 } dtrace_probespecs[] = {
58 { offsetof(dtrace_probedesc_t, dtpd_provider), DTRACE_PROVNAMELEN },
59 { offsetof(dtrace_probedesc_t, dtpd_mod), DTRACE_MODNAMELEN },
60 { offsetof(dtrace_probedesc_t, dtpd_func), DTRACE_FUNCNAMELEN },
61 { offsetof(dtrace_probedesc_t, dtpd_name), DTRACE_NAMELEN }
65 dtrace_xstr2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec,
66 const char *s, int argc, char *const argv[], dtrace_probedesc_t *pdp)
68 size_t off, len, vlen, wlen;
69 const char *p, *q, *v, *w;
71 char buf[32]; /* for id_t as %d (see below) */
73 if (spec < DTRACE_PROBESPEC_NONE || spec > DTRACE_PROBESPEC_NAME)
74 return (dt_set_errno(dtp, EINVAL));
76 bzero(pdp, sizeof (dtrace_probedesc_t));
77 p = s + strlen(s) - 1;
80 for (len = 0; p >= s && *p != ':'; len++)
81 p--; /* move backward until we find a delimiter */
88 if ((v = strchr(q, '$')) != NULL && v < q + len) {
90 * Set vlen to the length of the variable name and then
91 * reset len to the length of the text prior to '$'. If
92 * the name begins with a digit, interpret it using the
93 * the argv[] array. Otherwise we look in dt_macros.
94 * For the moment, all dt_macros variables are of type
95 * id_t (see dtrace_update() for more details on that).
97 vlen = (size_t)(q + len - v);
98 len = (size_t)(v - q);
101 * If the variable string begins with $$, skip past the
102 * leading dollar sign since $ and $$ are equivalent
103 * macro reference operators in a probe description.
105 if (vlen > 2 && v[1] == '$') {
114 i = strtol(v + 1, (char **)&w, 10);
116 wlen = vlen - (w - v);
118 if (i < 0 || i >= argc || errno != 0)
119 return (dt_set_errno(dtp, EDT_BADSPCV));
124 if (yypcb != NULL && yypcb->pcb_sargv == argv)
125 yypcb->pcb_sflagv[i] |= DT_IDFLG_REF;
127 } else if (vlen > 1) {
128 char *vstr = alloca(vlen);
131 (void) strncpy(vstr, v + 1, vlen - 1);
132 vstr[vlen - 1] = '\0';
133 idp = dt_idhash_lookup(dtp->dt_macros, vstr);
136 return (dt_set_errno(dtp, EDT_BADSPCV));
139 vlen = snprintf(buf, 32, "%d", idp->di_id);
142 return (dt_set_errno(dtp, EDT_BADSPCV));
145 if (spec == DTRACE_PROBESPEC_NONE)
146 return (dt_set_errno(dtp, EDT_BADSPEC));
148 if (len + vlen >= dtrace_probespecs[spec].dtps_len)
149 return (dt_set_errno(dtp, ENAMETOOLONG));
151 off = dtrace_probespecs[spec--].dtps_offset;
152 bcopy(q, (char *)pdp + off, len);
153 bcopy(v, (char *)pdp + off + len, vlen);
154 bcopy(w, (char *)pdp + off + len + vlen, wlen);
157 pdp->dtpd_id = DTRACE_IDNONE;
162 dtrace_str2desc(dtrace_hdl_t *dtp, dtrace_probespec_t spec,
163 const char *s, dtrace_probedesc_t *pdp)
165 return (dtrace_xstr2desc(dtp, spec, s, 0, NULL, pdp));
169 dtrace_id2desc(dtrace_hdl_t *dtp, dtrace_id_t id, dtrace_probedesc_t *pdp)
171 bzero(pdp, sizeof (dtrace_probedesc_t));
174 if (dt_ioctl(dtp, DTRACEIOC_PROBES, pdp) == -1 ||
176 return (dt_set_errno(dtp, EDT_BADID));
182 dtrace_desc2str(const dtrace_probedesc_t *pdp, char *buf, size_t len)
184 if (pdp->dtpd_id == 0) {
185 (void) snprintf(buf, len, "%s:%s:%s:%s", pdp->dtpd_provider,
186 pdp->dtpd_mod, pdp->dtpd_func, pdp->dtpd_name);
188 (void) snprintf(buf, len, "%u", pdp->dtpd_id);
194 dtrace_attr2str(dtrace_attribute_t attr, char *buf, size_t len)
196 const char *name = dtrace_stability_name(attr.dtat_name);
197 const char *data = dtrace_stability_name(attr.dtat_data);
198 const char *class = dtrace_class_name(attr.dtat_class);
200 if (name == NULL || data == NULL || class == NULL)
201 return (NULL); /* one or more invalid attributes */
203 (void) snprintf(buf, len, "%s/%s/%s", name, data, class);
208 dt_getstrattr(char *p, char **qp)
215 if ((q = strchr(p, '/')) == NULL)
225 dtrace_str2attr(const char *str, dtrace_attribute_t *attr)
227 dtrace_stability_t s;
231 if (str == NULL || attr == NULL)
232 return (-1); /* invalid function arguments */
234 *attr = _dtrace_maxattr;
235 p = alloca(strlen(str) + 1);
236 (void) strcpy(p, str);
238 if ((p = dt_getstrattr(p, &q)) == NULL)
241 for (s = 0; s <= DTRACE_STABILITY_MAX; s++) {
242 if (strcasecmp(p, dtrace_stability_name(s)) == 0) {
248 if (s > DTRACE_STABILITY_MAX)
251 if ((p = dt_getstrattr(q, &q)) == NULL)
254 for (s = 0; s <= DTRACE_STABILITY_MAX; s++) {
255 if (strcasecmp(p, dtrace_stability_name(s)) == 0) {
261 if (s > DTRACE_STABILITY_MAX)
264 if ((p = dt_getstrattr(q, &q)) == NULL)
267 for (c = 0; c <= DTRACE_CLASS_MAX; c++) {
268 if (strcasecmp(p, dtrace_class_name(c)) == 0) {
269 attr->dtat_class = c;
274 if (c > DTRACE_CLASS_MAX || (p = dt_getstrattr(q, &q)) != NULL)
281 dtrace_stability_name(dtrace_stability_t s)
284 case DTRACE_STABILITY_INTERNAL: return ("Internal");
285 case DTRACE_STABILITY_PRIVATE: return ("Private");
286 case DTRACE_STABILITY_OBSOLETE: return ("Obsolete");
287 case DTRACE_STABILITY_EXTERNAL: return ("External");
288 case DTRACE_STABILITY_UNSTABLE: return ("Unstable");
289 case DTRACE_STABILITY_EVOLVING: return ("Evolving");
290 case DTRACE_STABILITY_STABLE: return ("Stable");
291 case DTRACE_STABILITY_STANDARD: return ("Standard");
292 default: return (NULL);
297 dtrace_class_name(dtrace_class_t c)
300 case DTRACE_CLASS_UNKNOWN: return ("Unknown");
301 case DTRACE_CLASS_CPU: return ("CPU");
302 case DTRACE_CLASS_PLATFORM: return ("Platform");
303 case DTRACE_CLASS_GROUP: return ("Group");
304 case DTRACE_CLASS_ISA: return ("ISA");
305 case DTRACE_CLASS_COMMON: return ("Common");
306 default: return (NULL);
311 dt_attr_min(dtrace_attribute_t a1, dtrace_attribute_t a2)
313 dtrace_attribute_t am;
315 am.dtat_name = MIN(a1.dtat_name, a2.dtat_name);
316 am.dtat_data = MIN(a1.dtat_data, a2.dtat_data);
317 am.dtat_class = MIN(a1.dtat_class, a2.dtat_class);
323 dt_attr_max(dtrace_attribute_t a1, dtrace_attribute_t a2)
325 dtrace_attribute_t am;
327 am.dtat_name = MAX(a1.dtat_name, a2.dtat_name);
328 am.dtat_data = MAX(a1.dtat_data, a2.dtat_data);
329 am.dtat_class = MAX(a1.dtat_class, a2.dtat_class);
335 * Compare two attributes and return an integer value in the following ranges:
337 * <0 if any of a1's attributes are less than a2's attributes
338 * =0 if all of a1's attributes are equal to a2's attributes
339 * >0 if all of a1's attributes are greater than or equal to a2's attributes
341 * To implement this function efficiently, we subtract a2's attributes from
342 * a1's to obtain a negative result if an a1 attribute is less than its a2
343 * counterpart. We then OR the intermediate results together, relying on the
344 * twos-complement property that if any result is negative, the bitwise union
345 * will also be negative since the highest bit will be set in the result.
348 dt_attr_cmp(dtrace_attribute_t a1, dtrace_attribute_t a2)
350 return (((int)a1.dtat_name - a2.dtat_name) |
351 ((int)a1.dtat_data - a2.dtat_data) |
352 ((int)a1.dtat_class - a2.dtat_class));
356 dt_attr_str(dtrace_attribute_t a, char *buf, size_t len)
358 static const char stability[] = "ipoxuesS";
359 static const char class[] = "uCpgIc";
361 if (a.dtat_name < sizeof (stability) &&
362 a.dtat_data < sizeof (stability) && a.dtat_class < sizeof (class)) {
363 (void) snprintf(buf, len, "[%c/%c/%c]", stability[a.dtat_name],
364 stability[a.dtat_data], class[a.dtat_class]);
366 (void) snprintf(buf, len, "[%u/%u/%u]",
367 a.dtat_name, a.dtat_data, a.dtat_class);
374 dt_version_num2str(dt_version_t v, char *buf, size_t len)
376 uint_t M = DT_VERSION_MAJOR(v);
377 uint_t m = DT_VERSION_MINOR(v);
378 uint_t u = DT_VERSION_MICRO(v);
381 (void) snprintf(buf, len, "%u.%u", M, m);
383 (void) snprintf(buf, len, "%u.%u.%u", M, m, u);
389 dt_version_str2num(const char *s, dt_version_t *vp)
391 int i = 0, n[3] = { 0, 0, 0 };
394 while ((c = *s++) != '\0') {
396 n[i] = n[i] * 10 + c - '0';
397 else if (c != '.' || i++ >= sizeof (n) / sizeof (n[0]) - 1)
401 if (n[0] > DT_VERSION_MAJMAX ||
402 n[1] > DT_VERSION_MINMAX ||
403 n[2] > DT_VERSION_MICMAX)
407 *vp = DT_VERSION_NUMBER(n[0], n[1], n[2]);
413 dt_version_defined(dt_version_t v)
417 for (i = 0; _dtrace_versions[i] != 0; i++) {
418 if (_dtrace_versions[i] == v)
426 dt_cpp_add_arg(dtrace_hdl_t *dtp, const char *str)
430 if (dtp->dt_cpp_argc == dtp->dt_cpp_args) {
431 int olds = dtp->dt_cpp_args;
433 char **argv = realloc(dtp->dt_cpp_argv, sizeof (char *) * news);
438 bzero(&argv[olds], sizeof (char *) * olds);
439 dtp->dt_cpp_argv = argv;
440 dtp->dt_cpp_args = news;
443 if ((arg = strdup(str)) == NULL)
446 assert(dtp->dt_cpp_argc < dtp->dt_cpp_args);
447 dtp->dt_cpp_argv[dtp->dt_cpp_argc++] = arg;
452 dt_cpp_pop_arg(dtrace_hdl_t *dtp)
456 if (dtp->dt_cpp_argc <= 1)
457 return (NULL); /* dt_cpp_argv[0] cannot be popped */
459 arg = dtp->dt_cpp_argv[--dtp->dt_cpp_argc];
460 dtp->dt_cpp_argv[dtp->dt_cpp_argc] = NULL;
467 dt_dprintf(const char *format, ...)
472 va_start(alist, format);
473 (void) fputs("libdtrace DEBUG: ", stderr);
474 (void) vfprintf(stderr, format, alist);
481 dt_ioctl(dtrace_hdl_t *dtp, int val, void *arg)
483 dt_ioctl(dtrace_hdl_t *dtp, u_long val, void *arg)
486 const dtrace_vector_t *v = dtp->dt_vector;
489 /* Avoid sign extension. */
494 return (v->dtv_ioctl(dtp->dt_varg, val, arg));
497 return (ioctl(dtp->dt_fd, val, arg));
504 dt_status(dtrace_hdl_t *dtp, processorid_t cpu)
506 const dtrace_vector_t *v = dtp->dt_vector;
510 return (p_online(cpu, P_STATUS));
513 size_t len = sizeof(maxid);
514 if (sysctlbyname("kern.smp.maxid", &maxid, &len, NULL, 0) != 0)
515 return (cpu == 0 ? 1 : -1);
517 return (cpu <= maxid ? 1 : -1);
521 return (v->dtv_status(dtp->dt_varg, cpu));
525 dt_sysconf(dtrace_hdl_t *dtp, int name)
527 const dtrace_vector_t *v = dtp->dt_vector;
530 return (sysconf(name));
532 return (v->dtv_sysconf(dtp->dt_varg, name));
536 * Wrapper around write(2) to handle partial writes. For maximum safety of
537 * output files and proper error reporting, we continuing writing in the
538 * face of partial writes until write(2) fails or 'buf' is completely written.
539 * We also record any errno in the specified dtrace_hdl_t as well as 'errno'.
542 dt_write(dtrace_hdl_t *dtp, int fd, const void *buf, size_t n)
548 if ((len = write(fd, buf, resid)) <= 0)
552 buf = (char *)buf + len;
555 if (resid == n && n != 0)
556 return (dt_set_errno(dtp, errno));
562 * This function handles all output from libdtrace, as well as the
563 * dtrace_sprintf() case. If we're here due to dtrace_sprintf(), then
564 * dt_sprintf_buflen will be non-zero; in this case, we sprintf into the
565 * specified buffer and return. Otherwise, if output is buffered (denoted by
566 * a NULL fp), we sprintf the desired output into the buffered buffer
567 * (expanding the buffer if required). If we don't satisfy either of these
568 * conditions (that is, if we are to actually generate output), then we call
569 * fprintf with the specified fp. In this case, we need to deal with one of
570 * the more annoying peculiarities of libc's printf routines: any failed
571 * write persistently sets an error flag inside the FILE causing every
572 * subsequent write to fail, but only the caller that initiated the error gets
573 * the errno. Since libdtrace clients often intercept SIGINT, this case is
574 * particularly frustrating since we don't want the EINTR on one attempt to
575 * write to the output file to preclude later attempts to write. This
576 * function therefore does a clearerr() if any error occurred, and saves the
577 * errno for the caller inside the specified dtrace_hdl_t.
581 dt_printf(dtrace_hdl_t *dtp, FILE *fp, const char *format, ...)
588 * On FreeBSD, check if output is currently being re-directed
589 * to another file. If so, output to that file instead of the
590 * one the caller has specified.
592 if (dtp->dt_freopen_fp != NULL)
593 fp = dtp->dt_freopen_fp;
596 va_start(ap, format);
598 if (dtp->dt_sprintf_buflen != 0) {
602 assert(dtp->dt_sprintf_buf != NULL);
604 buf = &dtp->dt_sprintf_buf[len = strlen(dtp->dt_sprintf_buf)];
605 len = dtp->dt_sprintf_buflen - len;
608 if ((n = vsnprintf(buf, len, format, ap)) < 0)
609 n = dt_set_errno(dtp, errno);
621 * Using buffered output is not allowed if a handler has
622 * not been installed.
624 if (dtp->dt_bufhdlr == NULL) {
626 return (dt_set_errno(dtp, EDT_NOBUFFERED));
629 if (dtp->dt_buffered_buf == NULL) {
630 assert(dtp->dt_buffered_size == 0);
631 dtp->dt_buffered_size = 1;
632 dtp->dt_buffered_buf = malloc(dtp->dt_buffered_size);
634 if (dtp->dt_buffered_buf == NULL) {
636 return (dt_set_errno(dtp, EDT_NOMEM));
639 dtp->dt_buffered_offs = 0;
640 dtp->dt_buffered_buf[0] = '\0';
643 if ((needed = vsnprintf(NULL, 0, format, ap)) < 0) {
644 rval = dt_set_errno(dtp, errno);
657 assert(dtp->dt_buffered_offs < dtp->dt_buffered_size);
658 avail = dtp->dt_buffered_size - dtp->dt_buffered_offs;
660 if (needed + 1 < avail)
663 if ((newbuf = realloc(dtp->dt_buffered_buf,
664 dtp->dt_buffered_size << 1)) == NULL) {
666 return (dt_set_errno(dtp, EDT_NOMEM));
669 dtp->dt_buffered_buf = newbuf;
670 dtp->dt_buffered_size <<= 1;
673 if (vsnprintf(&dtp->dt_buffered_buf[dtp->dt_buffered_offs],
674 avail, format, ap) < 0) {
675 rval = dt_set_errno(dtp, errno);
680 dtp->dt_buffered_offs += needed;
681 assert(dtp->dt_buffered_buf[dtp->dt_buffered_offs] == '\0');
686 n = vfprintf(fp, format, ap);
692 return (dt_set_errno(dtp, errno));
699 dt_buffered_flush(dtrace_hdl_t *dtp, dtrace_probedata_t *pdata,
700 const dtrace_recdesc_t *rec, const dtrace_aggdata_t *agg, uint32_t flags)
702 dtrace_bufdata_t data;
704 if (dtp->dt_buffered_offs == 0)
707 data.dtbda_handle = dtp;
708 data.dtbda_buffered = dtp->dt_buffered_buf;
709 data.dtbda_probe = pdata;
710 data.dtbda_recdesc = rec;
711 data.dtbda_aggdata = agg;
712 data.dtbda_flags = flags;
714 if ((*dtp->dt_bufhdlr)(&data, dtp->dt_bufarg) == DTRACE_HANDLE_ABORT)
715 return (dt_set_errno(dtp, EDT_DIRABORT));
717 dtp->dt_buffered_offs = 0;
718 dtp->dt_buffered_buf[0] = '\0';
724 dt_buffered_destroy(dtrace_hdl_t *dtp)
726 free(dtp->dt_buffered_buf);
727 dtp->dt_buffered_buf = NULL;
728 dtp->dt_buffered_offs = 0;
729 dtp->dt_buffered_size = 0;
733 dt_zalloc(dtrace_hdl_t *dtp, size_t size)
737 if (size > 16 * 1024 * 1024) {
738 (void) dt_set_errno(dtp, EDT_NOMEM);
742 if ((data = malloc(size)) == NULL)
743 (void) dt_set_errno(dtp, EDT_NOMEM);
751 dt_alloc(dtrace_hdl_t *dtp, size_t size)
755 if (size > 16 * 1024 * 1024) {
756 (void) dt_set_errno(dtp, EDT_NOMEM);
760 if ((data = malloc(size)) == NULL)
761 (void) dt_set_errno(dtp, EDT_NOMEM);
767 dt_free(dtrace_hdl_t *dtp, void *data)
769 assert(dtp != NULL); /* ensure sane use of this interface */
774 dt_difo_free(dtrace_hdl_t *dtp, dtrace_difo_t *dp)
777 return; /* simplify caller code */
779 dt_free(dtp, dp->dtdo_buf);
780 dt_free(dtp, dp->dtdo_inttab);
781 dt_free(dtp, dp->dtdo_strtab);
782 dt_free(dtp, dp->dtdo_vartab);
783 dt_free(dtp, dp->dtdo_kreltab);
784 dt_free(dtp, dp->dtdo_ureltab);
785 dt_free(dtp, dp->dtdo_xlmtab);
791 * dt_gmatch() is similar to gmatch(3GEN) and dtrace(7D) globbing, but also
792 * implements the behavior that an empty pattern matches any string.
795 dt_gmatch(const char *s, const char *p)
797 return (p == NULL || *p == '\0' || gmatch(s, p));
801 dt_basename(char *str)
803 char *last = strrchr(str, '/');
812 * dt_popc() is a fast implementation of population count. The algorithm is
813 * from "Hacker's Delight" by Henry Warren, Jr with a 64-bit equivalent added.
819 x = x - ((x >> 1) & 0x55555555UL);
820 x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
821 x = (x + (x >> 4)) & 0x0F0F0F0FUL;
826 x = x - ((x >> 1) & 0x5555555555555555ULL);
827 x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
828 x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
834 /* This should be a #warning but for now ignore error. Err: "need td_popc() implementation" */
839 * dt_popcb() is a bitmap-based version of population count that returns the
840 * number of one bits in the specified bitmap 'bp' at bit positions below 'n'.
843 dt_popcb(const ulong_t *bp, ulong_t n)
845 ulong_t maxb = n & BT_ULMASK;
846 ulong_t maxw = n >> BT_ULSHIFT;
852 for (w = 0; w < maxw; w++)
853 popc += dt_popc(bp[w]);
855 return (popc + dt_popc(bp[maxw] & ((1UL << maxb) - 1)));
863 dt_rw_read_held(pthread_rwlock_t *lock)
865 extern int _rw_read_held(struct _rwlock *);
866 return (_rw_read_held((struct _rwlock *)lock));
870 dt_rw_write_held(pthread_rwlock_t *lock)
872 extern int _rw_write_held(struct _rwlock *);
873 return (_rw_write_held((struct _rwlock *)lock));
878 dt_mutex_held(pthread_mutex_t *lock)
881 extern int _mutex_held(struct _lwp_mutex *);
882 return (_mutex_held((struct _lwp_mutex *)lock));
889 dt_string2str(char *s, char *str, int nbytes)
895 * Like snprintf(3C), we don't check the value of str if the
896 * number of bytes is 0.
902 (void) strncpy(str, s, nbytes - 1);
904 * Like snprintf(3C) (and unlike strncpy(3C)), we guarantee
905 * that the string is null-terminated.
907 str[nbytes - 1] = '\0';
909 (void) strcpy(str, s);
916 dtrace_addr2str(dtrace_hdl_t *dtp, uint64_t addr, char *str, int nbytes)
918 dtrace_syminfo_t dts;
921 size_t n = 20; /* for 0x%llx\0 */
925 if ((err = dtrace_lookup_by_addr(dtp, addr, &sym, &dts)) == 0)
926 n += strlen(dts.dts_object) + strlen(dts.dts_name) + 2; /* +` */
930 if (err == 0 && addr != sym.st_value) {
931 (void) snprintf(s, n, "%s`%s+0x%llx", dts.dts_object,
932 dts.dts_name, (u_longlong_t)addr - sym.st_value);
933 } else if (err == 0) {
934 (void) snprintf(s, n, "%s`%s",
935 dts.dts_object, dts.dts_name);
938 * We'll repeat the lookup, but this time we'll specify a NULL
939 * GElf_Sym -- indicating that we're only interested in the
942 if (dtrace_lookup_by_addr(dtp, addr, NULL, &dts) == 0) {
943 (void) snprintf(s, n, "%s`0x%llx", dts.dts_object,
946 (void) snprintf(s, n, "0x%llx", (u_longlong_t)addr);
950 return (dt_string2str(s, str, nbytes));
954 dtrace_uaddr2str(dtrace_hdl_t *dtp, pid_t pid,
955 uint64_t addr, char *str, int nbytes)
957 char name[PATH_MAX], objname[PATH_MAX], c[PATH_MAX * 2];
958 struct ps_prochandle *P = NULL;
963 P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0);
966 (void) snprintf(c, sizeof (c), "0x%jx", (uintmax_t)addr);
967 return (dt_string2str(c, str, nbytes));
970 dt_proc_lock(dtp, P);
972 if (Plookup_by_addr(P, addr, name, sizeof (name), &sym) == 0) {
973 (void) Pobjname(P, addr, objname, sizeof (objname));
975 obj = dt_basename(objname);
977 if (addr > sym.st_value) {
978 (void) snprintf(c, sizeof (c), "%s`%s+0x%llx", obj,
979 name, (u_longlong_t)(addr - sym.st_value));
981 (void) snprintf(c, sizeof (c), "%s`%s", obj, name);
983 } else if (Pobjname(P, addr, objname, sizeof (objname)) != 0) {
984 (void) snprintf(c, sizeof (c), "%s`0x%jx",
985 dt_basename(objname), (uintmax_t)addr);
987 (void) snprintf(c, sizeof (c), "0x%jx", (uintmax_t)addr);
990 dt_proc_unlock(dtp, P);
991 dt_proc_release(dtp, P);
993 return (dt_string2str(c, str, nbytes));