summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdtrace/common/dt_subr.c
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@fingolfin.org>2022-10-22 18:22:05 +0000
committerRobert Mustacchi <rm@fingolfin.org>2022-11-10 04:12:39 +0000
commit6eeafb34dceabceff80ed689002b6dc3e060f498 (patch)
treefe7289898a2a9c5fb349b5cd4d5aef9cfc5ea29a /usr/src/lib/libdtrace/common/dt_subr.c
parent603778843038dfbc5672c2565d9ce3dac034609d (diff)
downloadillumos-gate-6eeafb34dceabceff80ed689002b6dc3e060f498.tar.gz
15109 dtrace replicated mdb's bitfield mistakes
15111 dtrace -xtree doesn't always escape strings Reviewed by: Adam Leventhal <adam.leventhal@gmail.com> Approved by: Gordon Ross <gordon.w.ross@gmail.com>
Diffstat (limited to 'usr/src/lib/libdtrace/common/dt_subr.c')
-rw-r--r--usr/src/lib/libdtrace/common/dt_subr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/usr/src/lib/libdtrace/common/dt_subr.c b/usr/src/lib/libdtrace/common/dt_subr.c
index e93617ef59..1958e62f82 100644
--- a/usr/src/lib/libdtrace/common/dt_subr.c
+++ b/usr/src/lib/libdtrace/common/dt_subr.c
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright 2022 Oxide Computer Company
*/
#include <sys/sysmacros.h>
@@ -909,3 +910,25 @@ dtrace_uaddr2str(dtrace_hdl_t *dtp, pid_t pid,
return (dt_string2str(c, str, nbytes));
}
+
+/*
+ * This is a shared implementation to determine if we should treat a type as a
+ * bitfield. The parameters are the CTF encoding and the bit offset of the
+ * integer. This also exists in mdb_print.c. We consider something a bitfield
+ * if:
+ *
+ * o The type is more than 8 bytes. This is a bit of a historical choice from
+ * mdb and is a stranger one. The normal integer handling code generally
+ * doesn't handle integers more than 64-bits in size. Of course neither does
+ * the bitfield code...
+ * o The bit count is not a multiple of 8.
+ * o The size in bytes is not a power of 2.
+ * o The offset is not a multiple of 8.
+ */
+boolean_t
+dt_is_bitfield(const ctf_encoding_t *ep, ulong_t off)
+{
+ size_t bsize = ep->cte_bits / NBBY;
+ return (bsize > 8 || (ep->cte_bits % NBBY) != 0 ||
+ (bsize & (bsize - 1)) != 0 || (off % NBBY) != 0);
+}