summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/opensolaris/lib/libdtrace/common
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2013-04-16 19:39:27 +0000
committerpfg <pfg@FreeBSD.org>2013-04-16 19:39:27 +0000
commitc31105ae2f66e8d06f04abc5f07a50a101bd040d (patch)
tree6523c8695ea5a24543023de3b59b99f77ee69835 /cddl/contrib/opensolaris/lib/libdtrace/common
parent8809aa44519a7463681472195068ade5a1283639 (diff)
parent73d9b47b2a7a8df111f99bb69b7879f98cd3b57c (diff)
downloadFreeBSD-src-c31105ae2f66e8d06f04abc5f07a50a101bd040d.zip
FreeBSD-src-c31105ae2f66e8d06f04abc5f07a50a101bd040d.tar.gz
DTrace: print() should try to resolve function pointers
Merge changes from illumos: 3675 DTrace print() should try to resolve function pointers 3676 dt_print_enum hardcodes a value of zero Illumos Revision: b1fa6326238973aeaf12c34fcda75985b6c06be1 Reference: https://www.illumos.org/issues/3675 https://www.illumos.org/issues/3676 Obtained from: Illumos MFC after: 1 month
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libdtrace/common')
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
index 261fc8c..ccfa3da 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
@@ -25,6 +25,9 @@
/*
* Copyright (c) 2011 by Delphix. All rights reserved.
*/
+/*
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ */
/*
* DTrace print() action
@@ -93,6 +96,7 @@
* Print structure passed down recursively through printing algorithm.
*/
typedef struct dt_printarg {
+ dtrace_hdl_t *pa_dtp; /* libdtrace handle */
caddr_t pa_addr; /* base address of trace data */
ctf_file_t *pa_ctfp; /* CTF container */
int pa_depth; /* member depth */
@@ -303,8 +307,8 @@ dt_print_float(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
}
/*
- * A pointer is printed as a fixed-size integer. This is used both for
- * pointers and functions.
+ * A pointer is generally printed as a fixed-size integer. If we have a
+ * function pointer, we try to look up its name.
*/
static void
dt_print_ptr(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
@@ -313,8 +317,23 @@ dt_print_ptr(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
ctf_file_t *ctfp = pap->pa_ctfp;
caddr_t addr = pap->pa_addr + off / NBBY;
size_t size = ctf_type_size(ctfp, base);
-
- dt_print_hex(fp, addr, size);
+ ctf_id_t bid = ctf_type_reference(ctfp, base);
+ uint64_t pc;
+ dtrace_syminfo_t dts;
+ GElf_Sym sym;
+
+ if (bid == CTF_ERR || ctf_type_kind(ctfp, bid) != CTF_K_FUNCTION) {
+ dt_print_hex(fp, addr, size);
+ } else {
+ /* LINTED - alignment */
+ pc = *((uint64_t *)addr);
+ if (dtrace_lookup_by_addr(pap->pa_dtp, pc, &sym, &dts) != 0) {
+ dt_print_hex(fp, addr, size);
+ } else {
+ (void) fprintf(fp, "%s`%s", dts.dts_object,
+ dts.dts_name);
+ }
+ }
}
/*
@@ -459,8 +478,31 @@ dt_print_enum(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
FILE *fp = pap->pa_file;
ctf_file_t *ctfp = pap->pa_ctfp;
const char *ename;
+ ssize_t size;
+ caddr_t addr = pap->pa_addr + off / NBBY;
int value = 0;
+ /*
+ * The C standard says that an enum will be at most the sizeof (int).
+ * But if all the values are less than that, the compiler can use a
+ * smaller size. Thanks standards.
+ */
+ size = ctf_type_size(ctfp, base);
+ switch (size) {
+ case sizeof (uint8_t):
+ value = *(uint8_t *)addr;
+ break;
+ case sizeof (uint16_t):
+ value = *(uint16_t *)addr;
+ break;
+ case sizeof (int32_t):
+ value = *(int32_t *)addr;
+ break;
+ default:
+ (void) fprintf(fp, "<invalid enum size %u>", (uint_t)size);
+ return;
+ }
+
if ((ename = ctf_enum_name(ctfp, base, value)) != NULL)
(void) fprintf(fp, "%s", ename);
else
@@ -635,6 +677,7 @@ dtrace_print(dtrace_hdl_t *dtp, FILE *fp, const char *typename,
}
/* setup the print structure and kick off the main print routine */
+ pa.pa_dtp = dtp;
pa.pa_addr = addr;
pa.pa_ctfp = dt_module_getctf(dtp, dmp);
pa.pa_nest = 0;
OpenPOWER on IntegriCloud