1deef35fdSEric Schrock /*
2deef35fdSEric Schrock  * CDDL HEADER START
3deef35fdSEric Schrock  *
4deef35fdSEric Schrock  * The contents of this file are subject to the terms of the
5deef35fdSEric Schrock  * Common Development and Distribution License (the "License").
6deef35fdSEric Schrock  * You may not use this file except in compliance with the License.
7deef35fdSEric Schrock  *
8deef35fdSEric Schrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9deef35fdSEric Schrock  * or http://www.opensolaris.org/os/licensing.
10deef35fdSEric Schrock  * See the License for the specific language governing permissions
11deef35fdSEric Schrock  * and limitations under the License.
12deef35fdSEric Schrock  *
13deef35fdSEric Schrock  * When distributing Covered Code, include this CDDL HEADER in each
14deef35fdSEric Schrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15deef35fdSEric Schrock  * If applicable, add the following below this CDDL HEADER, with the
16deef35fdSEric Schrock  * fields enclosed by brackets "[]" replaced with your own identifying
17deef35fdSEric Schrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18deef35fdSEric Schrock  *
19deef35fdSEric Schrock  * CDDL HEADER END
20deef35fdSEric Schrock  */
21deef35fdSEric Schrock /*
22deef35fdSEric Schrock  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23deef35fdSEric Schrock  * Use is subject to license terms.
24deef35fdSEric Schrock  */
25deef35fdSEric Schrock /*
26deef35fdSEric Schrock  * Copyright (c) 2011 by Delphix. All rights reserved.
27deef35fdSEric Schrock  */
28b1fa6326SRobert Mustacchi /*
29b1fa6326SRobert Mustacchi  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
30*6eeafb34SRobert Mustacchi  * Copyright 2022 Oxide Computer Company
31b1fa6326SRobert Mustacchi  */
32deef35fdSEric Schrock 
33deef35fdSEric Schrock /*
34deef35fdSEric Schrock  * DTrace print() action
35deef35fdSEric Schrock  *
36deef35fdSEric Schrock  * This file contains the post-processing logic for the print() action.  The
37deef35fdSEric Schrock  * print action behaves identically to trace() in that it generates a
38deef35fdSEric Schrock  * DTRACEACT_DIFEXPR action, but the action argument field refers to a CTF type
39deef35fdSEric Schrock  * string stored in the DOF string table (similar to printf formats).  We
40deef35fdSEric Schrock  * take the result of the trace action and post-process it in the fashion of
41deef35fdSEric Schrock  * MDB's ::print dcmd.
42deef35fdSEric Schrock  *
43deef35fdSEric Schrock  * This implementation differs from MDB's in the following ways:
44deef35fdSEric Schrock  *
45*6eeafb34SRobert Mustacchi  *	- We do not expose any options or flags.  The behavior of print() is
46deef35fdSEric Schrock  *	  equivalent to "::print -tn".
47deef35fdSEric Schrock  *
48*6eeafb34SRobert Mustacchi  *	- MDB will display "holes" in structures (unused padding between
49deef35fdSEric Schrock  *	  members).
50deef35fdSEric Schrock  *
51*6eeafb34SRobert Mustacchi  *	- When printing arrays of structures, MDB will leave a trailing ','
52deef35fdSEric Schrock  *	  after the last element.
53deef35fdSEric Schrock  *
54deef35fdSEric Schrock  *	- MDB will print time_t types as date and time.
55deef35fdSEric Schrock  *
56deef35fdSEric Schrock  *	- MDB will detect when an enum is actually the OR of several flags,
57deef35fdSEric Schrock  *	  and print it out with the constituent flags separated.
58deef35fdSEric Schrock  *
59deef35fdSEric Schrock  *	- For large arrays, MDB will print the first few members and then
60deef35fdSEric Schrock  *	  print a "..." continuation line.
61deef35fdSEric Schrock  *
62deef35fdSEric Schrock  *	- MDB will break and wrap arrays at 80 columns.
63deef35fdSEric Schrock  *
64deef35fdSEric Schrock  *	- MDB prints out floats and doubles by hand, as it must run in kmdb
65deef35fdSEric Schrock  *	  context.  We're able to leverage the printf() format strings,
66deef35fdSEric Schrock  *	  but the result is a slightly different format.
67deef35fdSEric Schrock  */
68deef35fdSEric Schrock 
69deef35fdSEric Schrock #include <sys/sysmacros.h>
70deef35fdSEric Schrock #include <strings.h>
71deef35fdSEric Schrock #include <stdlib.h>
72deef35fdSEric Schrock #include <alloca.h>
73deef35fdSEric Schrock #include <assert.h>
74deef35fdSEric Schrock #include <ctype.h>
75deef35fdSEric Schrock #include <errno.h>
76deef35fdSEric Schrock #include <limits.h>
77deef35fdSEric Schrock #include <sys/socket.h>
78deef35fdSEric Schrock #include <netdb.h>
79deef35fdSEric Schrock #include <netinet/in.h>
80deef35fdSEric Schrock #include <arpa/inet.h>
81deef35fdSEric Schrock #include <arpa/nameser.h>
82deef35fdSEric Schrock 
83deef35fdSEric Schrock #include <dt_module.h>
84deef35fdSEric Schrock #include <dt_printf.h>
85deef35fdSEric Schrock #include <dt_string.h>
86deef35fdSEric Schrock #include <dt_impl.h>
87deef35fdSEric Schrock 
88deef35fdSEric Schrock /* determines whether the given integer CTF encoding is a character */
89deef35fdSEric Schrock #define	CTF_IS_CHAR(e) \
90deef35fdSEric Schrock 	(((e).cte_format & (CTF_INT_CHAR | CTF_INT_SIGNED)) == \
91deef35fdSEric Schrock 	(CTF_INT_CHAR | CTF_INT_SIGNED) && (e).cte_bits == NBBY)
92deef35fdSEric Schrock /* determines whether the given CTF kind is a struct or union */
93deef35fdSEric Schrock #define	CTF_IS_STRUCTLIKE(k) \
94deef35fdSEric Schrock 	((k) == CTF_K_STRUCT || (k) == CTF_K_UNION)
95deef35fdSEric Schrock 
96deef35fdSEric Schrock /*
97deef35fdSEric Schrock  * Print structure passed down recursively through printing algorithm.
98deef35fdSEric Schrock  */
99deef35fdSEric Schrock typedef struct dt_printarg {
100b1fa6326SRobert Mustacchi 	dtrace_hdl_t	*pa_dtp;	/* libdtrace handle */
101deef35fdSEric Schrock 	caddr_t		pa_addr;	/* base address of trace data */
102deef35fdSEric Schrock 	ctf_file_t	*pa_ctfp;	/* CTF container */
103deef35fdSEric Schrock 	int		pa_depth;	/* member depth */
104deef35fdSEric Schrock 	int		pa_nest;	/* nested array depth */
105deef35fdSEric Schrock 	FILE		*pa_file;	/* output file */
106deef35fdSEric Schrock } dt_printarg_t;
107deef35fdSEric Schrock 
108deef35fdSEric Schrock static int dt_print_member(const char *, ctf_id_t, ulong_t, int, void *);
109deef35fdSEric Schrock 
110deef35fdSEric Schrock /*
111deef35fdSEric Schrock  * Safe version of ctf_type_name() that will fall back to just "<ctfid>" if it
112deef35fdSEric Schrock  * can't resolve the type.
113deef35fdSEric Schrock  */
114deef35fdSEric Schrock static void
dt_print_type_name(ctf_file_t * ctfp,ctf_id_t id,char * buf,size_t buflen)115deef35fdSEric Schrock dt_print_type_name(ctf_file_t *ctfp, ctf_id_t id, char *buf, size_t buflen)
116deef35fdSEric Schrock {
117deef35fdSEric Schrock 	if (ctf_type_name(ctfp, id, buf, buflen) == NULL)
118deef35fdSEric Schrock 		(void) snprintf(buf, buflen, "<%ld>", id);
119deef35fdSEric Schrock }
120deef35fdSEric Schrock 
121deef35fdSEric Schrock /*
122deef35fdSEric Schrock  * Print any necessary trailing braces for structures or unions.  We don't get
123deef35fdSEric Schrock  * invoked when a struct or union ends, so we infer the need to print braces
124deef35fdSEric Schrock  * based on the depth the last time we printed something and the new depth.
125deef35fdSEric Schrock  */
126deef35fdSEric Schrock static void
dt_print_trailing_braces(dt_printarg_t * pap,int depth)127deef35fdSEric Schrock dt_print_trailing_braces(dt_printarg_t *pap, int depth)
128deef35fdSEric Schrock {
129deef35fdSEric Schrock 	int d;
130deef35fdSEric Schrock 
131deef35fdSEric Schrock 	for (d = pap->pa_depth; d > depth; d--) {
132deef35fdSEric Schrock 		(void) fprintf(pap->pa_file, "%*s}%s",
133deef35fdSEric Schrock 		    (d + pap->pa_nest - 1) * 4, "",
134deef35fdSEric Schrock 		    d == depth + 1 ? "" : "\n");
135deef35fdSEric Schrock 	}
136deef35fdSEric Schrock }
137deef35fdSEric Schrock 
138deef35fdSEric Schrock /*
139deef35fdSEric Schrock  * Print the appropriate amount of indentation given the current depth and
140deef35fdSEric Schrock  * array nesting.
141deef35fdSEric Schrock  */
142deef35fdSEric Schrock static void
dt_print_indent(dt_printarg_t * pap)143deef35fdSEric Schrock dt_print_indent(dt_printarg_t *pap)
144deef35fdSEric Schrock {
145deef35fdSEric Schrock 	(void) fprintf(pap->pa_file, "%*s",
146deef35fdSEric Schrock 	    (pap->pa_depth + pap->pa_nest) * 4, "");
147deef35fdSEric Schrock }
148deef35fdSEric Schrock 
149deef35fdSEric Schrock /*
150deef35fdSEric Schrock  * Print a bitfield.  It's worth noting that the D compiler support for
151deef35fdSEric Schrock  * bitfields is currently broken; printing "D`user_desc_t" (pulled in by the
152deef35fdSEric Schrock  * various D provider files) will produce incorrect results compared to
153*6eeafb34SRobert Mustacchi  * "genunix`user_desc_t". However, bitfields that are built via CTF will be
154*6eeafb34SRobert Mustacchi  * fine. Note, this is derived from mdb's print_bifield in mdb_print.c.
155deef35fdSEric Schrock  */
156deef35fdSEric Schrock static void
print_bitfield(dt_printarg_t * pap,ulong_t off,ctf_encoding_t * ep)157deef35fdSEric Schrock print_bitfield(dt_printarg_t *pap, ulong_t off, ctf_encoding_t *ep)
158deef35fdSEric Schrock {
159deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
160deef35fdSEric Schrock 	caddr_t addr = pap->pa_addr + off / NBBY;
161deef35fdSEric Schrock 	uint64_t mask = (1ULL << ep->cte_bits) - 1;
162deef35fdSEric Schrock 	uint64_t value = 0;
163deef35fdSEric Schrock 	uint8_t *buf = (uint8_t *)&value;
164deef35fdSEric Schrock 	uint8_t shift;
165deef35fdSEric Schrock 
166*6eeafb34SRobert Mustacchi 	/*
167*6eeafb34SRobert Mustacchi 	 * Our bitfield may straddle a byte boundary. We explicitly take the
168*6eeafb34SRobert Mustacchi 	 * offset of the bitfield within its byte into account when determining
169*6eeafb34SRobert Mustacchi 	 * the overall amount of data to copy and mask off from the underlying
170*6eeafb34SRobert Mustacchi 	 * data.
171*6eeafb34SRobert Mustacchi 	 */
172*6eeafb34SRobert Mustacchi 	uint_t nbits = ep->cte_bits + (off % NBBY);
173*6eeafb34SRobert Mustacchi 	size_t size = P2ROUNDUP(nbits, NBBY) / NBBY;
174*6eeafb34SRobert Mustacchi 
175*6eeafb34SRobert Mustacchi 	/*
176*6eeafb34SRobert Mustacchi 	 * The resulting size must fit within the 64-bit value that we're using
177*6eeafb34SRobert Mustacchi 	 * to store the value, otherwise the bcopy below could destroy our
178*6eeafb34SRobert Mustacchi 	 * stack. This could be handled, but is not practically worth
179*6eeafb34SRobert Mustacchi 	 * addressing. This choice apes mdb, so if you're considering fixing
180*6eeafb34SRobert Mustacchi 	 * this, fix mdb as well.
181*6eeafb34SRobert Mustacchi 	 */
182*6eeafb34SRobert Mustacchi 	if (size > sizeof (value)) {
183*6eeafb34SRobert Mustacchi 		(void) fprintf(fp, "??? (total bitfield too large after "
184*6eeafb34SRobert Mustacchi 		    "alignment");
185*6eeafb34SRobert Mustacchi 		return;
186*6eeafb34SRobert Mustacchi 	}
187*6eeafb34SRobert Mustacchi 
188deef35fdSEric Schrock 	/*
189deef35fdSEric Schrock 	 * On big-endian machines, we need to adjust the buf pointer to refer
190deef35fdSEric Schrock 	 * to the lowest 'size' bytes in 'value', and we need to shift based on
191deef35fdSEric Schrock 	 * the offset from the end of the data, not the offset of the start.
192deef35fdSEric Schrock 	 */
193deef35fdSEric Schrock #ifdef _BIG_ENDIAN
194deef35fdSEric Schrock 	buf += sizeof (value) - size;
195deef35fdSEric Schrock 	off += ep->cte_bits;
196deef35fdSEric Schrock #endif
197deef35fdSEric Schrock 	bcopy(addr, buf, size);
198deef35fdSEric Schrock 	shift = off % NBBY;
199deef35fdSEric Schrock 
200deef35fdSEric Schrock 	/*
201deef35fdSEric Schrock 	 * Offsets are counted from opposite ends on little- and
202deef35fdSEric Schrock 	 * big-endian machines.
203deef35fdSEric Schrock 	 */
204deef35fdSEric Schrock #ifdef _BIG_ENDIAN
205deef35fdSEric Schrock 	shift = NBBY - shift;
206deef35fdSEric Schrock #endif
207deef35fdSEric Schrock 
208deef35fdSEric Schrock 	/*
209deef35fdSEric Schrock 	 * If the bits we want do not begin on a byte boundary, shift the data
210deef35fdSEric Schrock 	 * right so that the value is in the lowest 'cte_bits' of 'value'.
211deef35fdSEric Schrock 	 */
212deef35fdSEric Schrock 	if (off % NBBY != 0)
213deef35fdSEric Schrock 		value >>= shift;
214deef35fdSEric Schrock 	value &= mask;
215deef35fdSEric Schrock 
216deef35fdSEric Schrock 	(void) fprintf(fp, "%#llx", (u_longlong_t)value);
217deef35fdSEric Schrock }
218deef35fdSEric Schrock 
219deef35fdSEric Schrock /*
220deef35fdSEric Schrock  * Dump the contents of memory as a fixed-size integer in hex.
221deef35fdSEric Schrock  */
222deef35fdSEric Schrock static void
dt_print_hex(FILE * fp,caddr_t addr,size_t size)223deef35fdSEric Schrock dt_print_hex(FILE *fp, caddr_t addr, size_t size)
224deef35fdSEric Schrock {
225deef35fdSEric Schrock 	switch (size) {
226deef35fdSEric Schrock 	case sizeof (uint8_t):
227deef35fdSEric Schrock 		(void) fprintf(fp, "%#x", *(uint8_t *)addr);
228deef35fdSEric Schrock 		break;
229deef35fdSEric Schrock 	case sizeof (uint16_t):
2300979781aSRichard Lowe 		/* LINTED - alignment */
231deef35fdSEric Schrock 		(void) fprintf(fp, "%#x", *(uint16_t *)addr);
232deef35fdSEric Schrock 		break;
233deef35fdSEric Schrock 	case sizeof (uint32_t):
2340979781aSRichard Lowe 		/* LINTED - alignment */
235deef35fdSEric Schrock 		(void) fprintf(fp, "%#x", *(uint32_t *)addr);
236deef35fdSEric Schrock 		break;
237deef35fdSEric Schrock 	case sizeof (uint64_t):
238deef35fdSEric Schrock 		(void) fprintf(fp, "%#llx",
2390979781aSRichard Lowe 		    /* LINTED - alignment */
240deef35fdSEric Schrock 		    (unsigned long long)*(uint64_t *)addr);
241deef35fdSEric Schrock 		break;
242deef35fdSEric Schrock 	default:
243deef35fdSEric Schrock 		(void) fprintf(fp, "<invalid size %u>", (uint_t)size);
244deef35fdSEric Schrock 	}
245deef35fdSEric Schrock }
246deef35fdSEric Schrock 
247deef35fdSEric Schrock /*
248deef35fdSEric Schrock  * Print an integer type.  Before dumping the contents via dt_print_hex(), we
249deef35fdSEric Schrock  * first check the encoding to see if it's part of a bitfield or a character.
250deef35fdSEric Schrock  */
251deef35fdSEric Schrock static void
dt_print_int(ctf_id_t base,ulong_t off,dt_printarg_t * pap)252deef35fdSEric Schrock dt_print_int(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
253deef35fdSEric Schrock {
254deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
255deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
256deef35fdSEric Schrock 	ctf_encoding_t e;
257deef35fdSEric Schrock 	size_t size;
258deef35fdSEric Schrock 	caddr_t addr = pap->pa_addr + off / NBBY;
259deef35fdSEric Schrock 
260deef35fdSEric Schrock 	if (ctf_type_encoding(ctfp, base, &e) == CTF_ERR) {
261deef35fdSEric Schrock 		(void) fprintf(fp, "<unknown encoding>");
262deef35fdSEric Schrock 		return;
263deef35fdSEric Schrock 	}
264deef35fdSEric Schrock 
265deef35fdSEric Schrock 	/*
266deef35fdSEric Schrock 	 * This comes from MDB - it's not clear under what circumstances this
267deef35fdSEric Schrock 	 * would be found.
268deef35fdSEric Schrock 	 */
269deef35fdSEric Schrock 	if (e.cte_format & CTF_INT_VARARGS) {
270deef35fdSEric Schrock 		(void) fprintf(fp, "...");
271deef35fdSEric Schrock 		return;
272deef35fdSEric Schrock 	}
273deef35fdSEric Schrock 
274deef35fdSEric Schrock 	size = e.cte_bits / NBBY;
275*6eeafb34SRobert Mustacchi 	if (dt_is_bitfield(&e, off)) {
276deef35fdSEric Schrock 		print_bitfield(pap, off, &e);
277deef35fdSEric Schrock 		return;
278deef35fdSEric Schrock 	}
279deef35fdSEric Schrock 
280deef35fdSEric Schrock 	/*
281deef35fdSEric Schrock 	 * If this is a character, print it out as such.
282deef35fdSEric Schrock 	 */
283deef35fdSEric Schrock 	if (CTF_IS_CHAR(e)) {
284deef35fdSEric Schrock 		char c = *(char *)addr;
285deef35fdSEric Schrock 		if (isprint(c))
286deef35fdSEric Schrock 			(void) fprintf(fp, "'%c'", c);
287deef35fdSEric Schrock 		else if (c == 0)
288deef35fdSEric Schrock 			(void) fprintf(fp, "'\\0'");
289deef35fdSEric Schrock 		else
290deef35fdSEric Schrock 			(void) fprintf(fp, "'\\%03o'", c);
291deef35fdSEric Schrock 		return;
292deef35fdSEric Schrock 	}
293deef35fdSEric Schrock 
294deef35fdSEric Schrock 	dt_print_hex(fp, addr, size);
295deef35fdSEric Schrock }
296deef35fdSEric Schrock 
297deef35fdSEric Schrock /*
298deef35fdSEric Schrock  * Print a floating point (float, double, long double) value.
299deef35fdSEric Schrock  */
300deef35fdSEric Schrock /* ARGSUSED */
301deef35fdSEric Schrock static void
dt_print_float(ctf_id_t base,ulong_t off,dt_printarg_t * pap)302deef35fdSEric Schrock dt_print_float(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
303deef35fdSEric Schrock {
304deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
305deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
306deef35fdSEric Schrock 	ctf_encoding_t e;
307deef35fdSEric Schrock 	caddr_t addr = pap->pa_addr + off / NBBY;
308deef35fdSEric Schrock 
309deef35fdSEric Schrock 	if (ctf_type_encoding(ctfp, base, &e) == 0) {
310deef35fdSEric Schrock 		if (e.cte_format == CTF_FP_SINGLE &&
311deef35fdSEric Schrock 		    e.cte_bits == sizeof (float) * NBBY) {
3120979781aSRichard Lowe 			/* LINTED - alignment */
313deef35fdSEric Schrock 			(void) fprintf(fp, "%+.7e", *((float *)addr));
314deef35fdSEric Schrock 		} else if (e.cte_format == CTF_FP_DOUBLE &&
315deef35fdSEric Schrock 		    e.cte_bits == sizeof (double) * NBBY) {
3160979781aSRichard Lowe 			/* LINTED - alignment */
317deef35fdSEric Schrock 			(void) fprintf(fp, "%+.7e", *((double *)addr));
318deef35fdSEric Schrock 		} else if (e.cte_format == CTF_FP_LDOUBLE &&
319deef35fdSEric Schrock 		    e.cte_bits == sizeof (long double) * NBBY) {
3200979781aSRichard Lowe 			/* LINTED - alignment */
321deef35fdSEric Schrock 			(void) fprintf(fp, "%+.16LE", *((long double *)addr));
322deef35fdSEric Schrock 		} else {
323deef35fdSEric Schrock 			(void) fprintf(fp, "<unknown encoding>");
324deef35fdSEric Schrock 		}
325deef35fdSEric Schrock 	}
326deef35fdSEric Schrock }
327deef35fdSEric Schrock 
328deef35fdSEric Schrock /*
329b1fa6326SRobert Mustacchi  * A pointer is generally printed as a fixed-size integer.  If we have a
330b1fa6326SRobert Mustacchi  * function pointer, we try to look up its name.
331deef35fdSEric Schrock  */
332deef35fdSEric Schrock static void
dt_print_ptr(ctf_id_t base,ulong_t off,dt_printarg_t * pap)333deef35fdSEric Schrock dt_print_ptr(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
334deef35fdSEric Schrock {
335deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
336deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
337deef35fdSEric Schrock 	caddr_t addr = pap->pa_addr + off / NBBY;
338deef35fdSEric Schrock 	size_t size = ctf_type_size(ctfp, base);
339b1fa6326SRobert Mustacchi 	ctf_id_t bid = ctf_type_reference(ctfp, base);
340b1fa6326SRobert Mustacchi 	uint64_t pc;
341b1fa6326SRobert Mustacchi 	dtrace_syminfo_t dts;
342b1fa6326SRobert Mustacchi 	GElf_Sym sym;
343b1fa6326SRobert Mustacchi 
344b1fa6326SRobert Mustacchi 	if (bid == CTF_ERR || ctf_type_kind(ctfp, bid) != CTF_K_FUNCTION) {
345b1fa6326SRobert Mustacchi 		dt_print_hex(fp, addr, size);
346b1fa6326SRobert Mustacchi 	} else {
347b1fa6326SRobert Mustacchi 		/* LINTED - alignment */
348b1fa6326SRobert Mustacchi 		pc = *((uint64_t *)addr);
349b1fa6326SRobert Mustacchi 		if (dtrace_lookup_by_addr(pap->pa_dtp, pc, &sym, &dts) != 0) {
350b1fa6326SRobert Mustacchi 			dt_print_hex(fp, addr, size);
351b1fa6326SRobert Mustacchi 		} else {
352b1fa6326SRobert Mustacchi 			(void) fprintf(fp, "%s`%s", dts.dts_object,
353b1fa6326SRobert Mustacchi 			    dts.dts_name);
354b1fa6326SRobert Mustacchi 		}
355b1fa6326SRobert Mustacchi 	}
356deef35fdSEric Schrock }
357deef35fdSEric Schrock 
358deef35fdSEric Schrock /*
359deef35fdSEric Schrock  * Print out an array.  This is somewhat complex, as we must manually visit
360deef35fdSEric Schrock  * each member, and recursively invoke ctf_type_visit() for each member.  If
361deef35fdSEric Schrock  * the members are non-structs, then we print them out directly:
362deef35fdSEric Schrock  *
363*6eeafb34SRobert Mustacchi  *	[ 0x14, 0x2e, 0 ]
364deef35fdSEric Schrock  *
365deef35fdSEric Schrock  * If they are structs, then we print out the necessary leading and trailing
366deef35fdSEric Schrock  * braces, to end up with:
367deef35fdSEric Schrock  *
368deef35fdSEric Schrock  *	[
369deef35fdSEric Schrock  *	    type {
370deef35fdSEric Schrock  *	    ...
371deef35fdSEric Schrock  *	    },
372deef35fdSEric Schrock  *	    type {
373deef35fdSEric Schrock  *	    ...
374deef35fdSEric Schrock  *	    }
375deef35fdSEric Schrock  *	]
376deef35fdSEric Schrock  *
377deef35fdSEric Schrock  * We also use a heuristic to detect whether the array looks like a character
378deef35fdSEric Schrock  * array.  If the encoding indicates it's a character, and we have all
379deef35fdSEric Schrock  * printable characters followed by a null byte, then we display it as a
380deef35fdSEric Schrock  * string:
381deef35fdSEric Schrock  *
382deef35fdSEric Schrock  *	[ "string" ]
383deef35fdSEric Schrock  */
384deef35fdSEric Schrock static void
dt_print_array(ctf_id_t base,ulong_t off,dt_printarg_t * pap)385deef35fdSEric Schrock dt_print_array(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
386deef35fdSEric Schrock {
387deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
388deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
389deef35fdSEric Schrock 	caddr_t addr = pap->pa_addr + off / NBBY;
390deef35fdSEric Schrock 	ctf_arinfo_t car;
391deef35fdSEric Schrock 	ssize_t eltsize;
392deef35fdSEric Schrock 	ctf_encoding_t e;
393deef35fdSEric Schrock 	int i;
394deef35fdSEric Schrock 	boolean_t isstring;
395deef35fdSEric Schrock 	int kind;
396deef35fdSEric Schrock 	ctf_id_t rtype;
397deef35fdSEric Schrock 
398deef35fdSEric Schrock 	if (ctf_array_info(ctfp, base, &car) == CTF_ERR) {
399deef35fdSEric Schrock 		(void) fprintf(fp, "0x%p", (void *)addr);
400deef35fdSEric Schrock 		return;
401deef35fdSEric Schrock 	}
402deef35fdSEric Schrock 
403deef35fdSEric Schrock 	if ((eltsize = ctf_type_size(ctfp, car.ctr_contents)) < 0 ||
404deef35fdSEric Schrock 	    (rtype = ctf_type_resolve(ctfp, car.ctr_contents)) == CTF_ERR ||
405deef35fdSEric Schrock 	    (kind = ctf_type_kind(ctfp, rtype)) == CTF_ERR) {
406deef35fdSEric Schrock 		(void) fprintf(fp, "<invalid type %lu>", car.ctr_contents);
407deef35fdSEric Schrock 		return;
408deef35fdSEric Schrock 	}
409deef35fdSEric Schrock 
410deef35fdSEric Schrock 	/* see if this looks like a string */
411deef35fdSEric Schrock 	isstring = B_FALSE;
412deef35fdSEric Schrock 	if (kind == CTF_K_INTEGER &&
413deef35fdSEric Schrock 	    ctf_type_encoding(ctfp, rtype, &e) != CTF_ERR && CTF_IS_CHAR(e)) {
414deef35fdSEric Schrock 		char c;
415deef35fdSEric Schrock 		for (i = 0; i < car.ctr_nelems; i++) {
416deef35fdSEric Schrock 			c = *((char *)addr + eltsize * i);
417deef35fdSEric Schrock 			if (!isprint(c) || c == '\0')
418deef35fdSEric Schrock 				break;
419deef35fdSEric Schrock 		}
420deef35fdSEric Schrock 
421deef35fdSEric Schrock 		if (i != car.ctr_nelems && c == '\0')
422deef35fdSEric Schrock 			isstring = B_TRUE;
423deef35fdSEric Schrock 	}
424deef35fdSEric Schrock 
425deef35fdSEric Schrock 	/*
426deef35fdSEric Schrock 	 * As a slight aesthetic optimization, if we are a top-level type, then
427deef35fdSEric Schrock 	 * don't bother printing out the brackets.  This lets print("foo") look
428deef35fdSEric Schrock 	 * like:
429deef35fdSEric Schrock 	 *
430*6eeafb34SRobert Mustacchi 	 *	string "foo"
431deef35fdSEric Schrock 	 *
432deef35fdSEric Schrock 	 * As D will internally represent this as a char[256] array.
433deef35fdSEric Schrock 	 */
434deef35fdSEric Schrock 	if (!isstring || pap->pa_depth != 0)
435deef35fdSEric Schrock 		(void) fprintf(fp, "[ ");
436deef35fdSEric Schrock 
437deef35fdSEric Schrock 	if (isstring)
438deef35fdSEric Schrock 		(void) fprintf(fp, "\"");
439deef35fdSEric Schrock 
440deef35fdSEric Schrock 	for (i = 0; i < car.ctr_nelems; i++) {
441deef35fdSEric Schrock 		if (isstring) {
442deef35fdSEric Schrock 			char c = *((char *)addr + eltsize * i);
443deef35fdSEric Schrock 			if (c == '\0')
444deef35fdSEric Schrock 				break;
445deef35fdSEric Schrock 			(void) fprintf(fp, "%c", c);
446deef35fdSEric Schrock 		} else {
447deef35fdSEric Schrock 			/*
448deef35fdSEric Schrock 			 * Recursively invoke ctf_type_visit() on each member.
449deef35fdSEric Schrock 			 * We setup a new printarg struct with 'pa_nest' set to
450deef35fdSEric Schrock 			 * indicate that we are within a nested array.
451deef35fdSEric Schrock 			 */
452deef35fdSEric Schrock 			dt_printarg_t pa = *pap;
453deef35fdSEric Schrock 			pa.pa_nest += pap->pa_depth + 1;
454deef35fdSEric Schrock 			pa.pa_depth = 0;
455deef35fdSEric Schrock 			pa.pa_addr = addr + eltsize * i;
456deef35fdSEric Schrock 			(void) ctf_type_visit(ctfp, car.ctr_contents,
457deef35fdSEric Schrock 			    dt_print_member, &pa);
458deef35fdSEric Schrock 
459deef35fdSEric Schrock 			dt_print_trailing_braces(&pa, 0);
460deef35fdSEric Schrock 			if (i != car.ctr_nelems - 1)
461deef35fdSEric Schrock 				(void) fprintf(fp, ", ");
462deef35fdSEric Schrock 			else if (CTF_IS_STRUCTLIKE(kind))
463deef35fdSEric Schrock 				(void) fprintf(fp, "\n");
464deef35fdSEric Schrock 		}
465deef35fdSEric Schrock 	}
466deef35fdSEric Schrock 
467deef35fdSEric Schrock 	if (isstring)
468deef35fdSEric Schrock 		(void) fprintf(fp, "\"");
469deef35fdSEric Schrock 
470deef35fdSEric Schrock 	if (!isstring || pap->pa_depth != 0) {
471deef35fdSEric Schrock 		if (CTF_IS_STRUCTLIKE(kind))
472deef35fdSEric Schrock 			dt_print_indent(pap);
473deef35fdSEric Schrock 		else
474deef35fdSEric Schrock 			(void) fprintf(fp, " ");
475deef35fdSEric Schrock 		(void) fprintf(fp, "]");
476deef35fdSEric Schrock 	}
477deef35fdSEric Schrock }
478deef35fdSEric Schrock 
479deef35fdSEric Schrock /*
480deef35fdSEric Schrock  * This isued by both structs and unions to print the leading brace.
481deef35fdSEric Schrock  */
482deef35fdSEric Schrock /* ARGSUSED */
483deef35fdSEric Schrock static void
dt_print_structlike(ctf_id_t id,ulong_t off,dt_printarg_t * pap)484deef35fdSEric Schrock dt_print_structlike(ctf_id_t id, ulong_t off, dt_printarg_t *pap)
485deef35fdSEric Schrock {
486deef35fdSEric Schrock 	(void) fprintf(pap->pa_file, "{");
487deef35fdSEric Schrock }
488deef35fdSEric Schrock 
489deef35fdSEric Schrock /*
490deef35fdSEric Schrock  * For enums, we try to print the enum name, and fall back to the value if it
491deef35fdSEric Schrock  * can't be determined.  We do not do any fancy flag processing like mdb.
492deef35fdSEric Schrock  */
493deef35fdSEric Schrock /* ARGSUSED */
494deef35fdSEric Schrock static void
dt_print_enum(ctf_id_t base,ulong_t off,dt_printarg_t * pap)495deef35fdSEric Schrock dt_print_enum(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
496deef35fdSEric Schrock {
497deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
498deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
499deef35fdSEric Schrock 	const char *ename;
500b1fa6326SRobert Mustacchi 	ssize_t size;
501b1fa6326SRobert Mustacchi 	caddr_t addr = pap->pa_addr + off / NBBY;
502deef35fdSEric Schrock 	int value = 0;
503deef35fdSEric Schrock 
504b1fa6326SRobert Mustacchi 	/*
505b1fa6326SRobert Mustacchi 	 * The C standard says that an enum will be at most the sizeof (int).
506b1fa6326SRobert Mustacchi 	 * But if all the values are less than that, the compiler can use a
507b1fa6326SRobert Mustacchi 	 * smaller size. Thanks standards.
508b1fa6326SRobert Mustacchi 	 */
509b1fa6326SRobert Mustacchi 	size = ctf_type_size(ctfp, base);
510b1fa6326SRobert Mustacchi 	switch (size) {
511b1fa6326SRobert Mustacchi 	case sizeof (uint8_t):
512b1fa6326SRobert Mustacchi 		value = *(uint8_t *)addr;
513b1fa6326SRobert Mustacchi 		break;
514b1fa6326SRobert Mustacchi 	case sizeof (uint16_t):
5152974b68dSRichard Lowe 		/* LINTED - alignment */
516b1fa6326SRobert Mustacchi 		value = *(uint16_t *)addr;
517b1fa6326SRobert Mustacchi 		break;
518b1fa6326SRobert Mustacchi 	case sizeof (int32_t):
5192974b68dSRichard Lowe 		/* LINTED - alignment */
520b1fa6326SRobert Mustacchi 		value = *(int32_t *)addr;
521b1fa6326SRobert Mustacchi 		break;
522b1fa6326SRobert Mustacchi 	default:
523b1fa6326SRobert Mustacchi 		(void) fprintf(fp, "<invalid enum size %u>", (uint_t)size);
524b1fa6326SRobert Mustacchi 		return;
525b1fa6326SRobert Mustacchi 	}
526b1fa6326SRobert Mustacchi 
527deef35fdSEric Schrock 	if ((ename = ctf_enum_name(ctfp, base, value)) != NULL)
528deef35fdSEric Schrock 		(void) fprintf(fp, "%s", ename);
529deef35fdSEric Schrock 	else
530deef35fdSEric Schrock 		(void) fprintf(fp, "%d", value);
531deef35fdSEric Schrock }
532deef35fdSEric Schrock 
533deef35fdSEric Schrock /*
534deef35fdSEric Schrock  * Forward declaration.  There's not much to do here without the complete
535deef35fdSEric Schrock  * type information, so just print out this fact and drive on.
536deef35fdSEric Schrock  */
537deef35fdSEric Schrock /* ARGSUSED */
538deef35fdSEric Schrock static void
dt_print_tag(ctf_id_t base,ulong_t off,dt_printarg_t * pap)539deef35fdSEric Schrock dt_print_tag(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
540deef35fdSEric Schrock {
541deef35fdSEric Schrock 	(void) fprintf(pap->pa_file, "<forward decl>");
542deef35fdSEric Schrock }
543deef35fdSEric Schrock 
544deef35fdSEric Schrock typedef void dt_printarg_f(ctf_id_t, ulong_t, dt_printarg_t *);
545deef35fdSEric Schrock 
546deef35fdSEric Schrock static dt_printarg_f *const dt_printfuncs[] = {
547deef35fdSEric Schrock 	dt_print_int,		/* CTF_K_INTEGER */
548deef35fdSEric Schrock 	dt_print_float,		/* CTF_K_FLOAT */
549deef35fdSEric Schrock 	dt_print_ptr,		/* CTF_K_POINTER */
550deef35fdSEric Schrock 	dt_print_array,		/* CTF_K_ARRAY */
551deef35fdSEric Schrock 	dt_print_ptr,		/* CTF_K_FUNCTION */
552deef35fdSEric Schrock 	dt_print_structlike,	/* CTF_K_STRUCT */
553deef35fdSEric Schrock 	dt_print_structlike,	/* CTF_K_UNION */
554deef35fdSEric Schrock 	dt_print_enum,		/* CTF_K_ENUM */
555deef35fdSEric Schrock 	dt_print_tag		/* CTF_K_FORWARD */
556deef35fdSEric Schrock };
557deef35fdSEric Schrock 
558deef35fdSEric Schrock /*
559deef35fdSEric Schrock  * Print one member of a structure.  This callback is invoked from
560deef35fdSEric Schrock  * ctf_type_visit() recursively.
561deef35fdSEric Schrock  */
562deef35fdSEric Schrock static int
dt_print_member(const char * name,ctf_id_t id,ulong_t off,int depth,void * data)563deef35fdSEric Schrock dt_print_member(const char *name, ctf_id_t id, ulong_t off, int depth,
564deef35fdSEric Schrock     void *data)
565deef35fdSEric Schrock {
566deef35fdSEric Schrock 	char type[DT_TYPE_NAMELEN];
567deef35fdSEric Schrock 	int kind;
568deef35fdSEric Schrock 	dt_printarg_t *pap = data;
569deef35fdSEric Schrock 	FILE *fp = pap->pa_file;
570deef35fdSEric Schrock 	ctf_file_t *ctfp = pap->pa_ctfp;
571deef35fdSEric Schrock 	boolean_t arraymember;
572deef35fdSEric Schrock 	boolean_t brief;
573deef35fdSEric Schrock 	ctf_encoding_t e;
574deef35fdSEric Schrock 	ctf_id_t rtype;
575deef35fdSEric Schrock 
576deef35fdSEric Schrock 	dt_print_trailing_braces(pap, depth);
577deef35fdSEric Schrock 	/*
578deef35fdSEric Schrock 	 * dt_print_trailing_braces() doesn't include the trailing newline; add
579deef35fdSEric Schrock 	 * it here if necessary.
580deef35fdSEric Schrock 	 */
581deef35fdSEric Schrock 	if (depth < pap->pa_depth)
582deef35fdSEric Schrock 		(void) fprintf(fp, "\n");
583deef35fdSEric Schrock 	pap->pa_depth = depth;
584deef35fdSEric Schrock 
585deef35fdSEric Schrock 	if ((rtype = ctf_type_resolve(ctfp, id)) == CTF_ERR ||
586deef35fdSEric Schrock 	    (kind = ctf_type_kind(ctfp, rtype)) == CTF_ERR ||
587deef35fdSEric Schrock 	    kind < CTF_K_INTEGER || kind > CTF_K_FORWARD) {
588deef35fdSEric Schrock 		dt_print_indent(pap);
589deef35fdSEric Schrock 		(void) fprintf(fp, "%s = <invalid type %lu>", name, id);
590deef35fdSEric Schrock 		return (0);
591deef35fdSEric Schrock 	}
592deef35fdSEric Schrock 
593deef35fdSEric Schrock 	dt_print_type_name(ctfp, id, type, sizeof (type));
594deef35fdSEric Schrock 
595deef35fdSEric Schrock 	arraymember = (pap->pa_nest != 0 && depth == 0);
596deef35fdSEric Schrock 	brief = (arraymember && !CTF_IS_STRUCTLIKE(kind));
597deef35fdSEric Schrock 
598deef35fdSEric Schrock 	if (!brief) {
599deef35fdSEric Schrock 		/*
600deef35fdSEric Schrock 		 * If this is a direct array member and a struct (otherwise
601deef35fdSEric Schrock 		 * brief would be true), then print a trailing newline, as the
602deef35fdSEric Schrock 		 * array printing code doesn't include it because it might be a
603deef35fdSEric Schrock 		 * simple type.
604deef35fdSEric Schrock 		 */
605deef35fdSEric Schrock 		if (arraymember)
606deef35fdSEric Schrock 			(void) fprintf(fp, "\n");
607deef35fdSEric Schrock 		dt_print_indent(pap);
608deef35fdSEric Schrock 
609deef35fdSEric Schrock 		/* always print the type */
610deef35fdSEric Schrock 		(void) fprintf(fp, "%s", type);
611deef35fdSEric Schrock 		if (name[0] != '\0') {
612deef35fdSEric Schrock 			/*
613deef35fdSEric Schrock 			 * For aesthetics, we don't include a space between the
614deef35fdSEric Schrock 			 * type name and member name if the type is a pointer.
615deef35fdSEric Schrock 			 * This will give us "void *foo =" instead of "void *
616deef35fdSEric Schrock 			 * foo =".  Unions also have the odd behavior that the
617deef35fdSEric Schrock 			 * type name is returned as "union ", with a trailing
618deef35fdSEric Schrock 			 * space, so we also avoid printing a space if the type
619deef35fdSEric Schrock 			 * name already ends with a space.
620deef35fdSEric Schrock 			 */
621deef35fdSEric Schrock 			if (type[strlen(type) - 1] != '*' &&
622deef35fdSEric Schrock 			    type[strlen(type) -1] != ' ') {
623deef35fdSEric Schrock 				(void) fprintf(fp, " ");
624deef35fdSEric Schrock 			}
625deef35fdSEric Schrock 			(void) fprintf(fp, "%s", name);
626deef35fdSEric Schrock 
627deef35fdSEric Schrock 			/*
628deef35fdSEric Schrock 			 * If this looks like a bitfield, or is an integer not
629deef35fdSEric Schrock 			 * aligned on a byte boundary, print the number of
630deef35fdSEric Schrock 			 * bits after the name.
631deef35fdSEric Schrock 			 */
632deef35fdSEric Schrock 			if (kind == CTF_K_INTEGER &&
633deef35fdSEric Schrock 			    ctf_type_encoding(ctfp, id, &e) == 0) {
634deef35fdSEric Schrock 				ulong_t bits = e.cte_bits;
635deef35fdSEric Schrock 				ulong_t size = bits / NBBY;
636deef35fdSEric Schrock 
637deef35fdSEric Schrock 				if (bits % NBBY != 0 ||
638deef35fdSEric Schrock 				    off % NBBY != 0 ||
639deef35fdSEric Schrock 				    size > 8 ||
640deef35fdSEric Schrock 				    size != ctf_type_size(ctfp, id)) {
641deef35fdSEric Schrock 					(void) fprintf(fp, " :%lu", bits);
642deef35fdSEric Schrock 				}
643deef35fdSEric Schrock 			}
644deef35fdSEric Schrock 
645deef35fdSEric Schrock 			(void) fprintf(fp, " =");
646deef35fdSEric Schrock 		}
647deef35fdSEric Schrock 		(void) fprintf(fp, " ");
648deef35fdSEric Schrock 	}
649deef35fdSEric Schrock 
650deef35fdSEric Schrock 	dt_printfuncs[kind - 1](rtype, off, pap);
651deef35fdSEric Schrock 
652deef35fdSEric Schrock 	/* direct simple array members are not separated by newlines */
653deef35fdSEric Schrock 	if (!brief)
654deef35fdSEric Schrock 		(void) fprintf(fp, "\n");
655deef35fdSEric Schrock 
656deef35fdSEric Schrock 	return (0);
657deef35fdSEric Schrock }
658deef35fdSEric Schrock 
659deef35fdSEric Schrock /*
660deef35fdSEric Schrock  * Main print function invoked by dt_consume_cpu().
661deef35fdSEric Schrock  */
662deef35fdSEric Schrock int
dtrace_print(dtrace_hdl_t * dtp,FILE * fp,const char * typename,caddr_t addr,size_t len)663deef35fdSEric Schrock dtrace_print(dtrace_hdl_t *dtp, FILE *fp, const char *typename,
664deef35fdSEric Schrock     caddr_t addr, size_t len)
665deef35fdSEric Schrock {
666deef35fdSEric Schrock 	const char *s;
667deef35fdSEric Schrock 	char *object;
668deef35fdSEric Schrock 	dt_printarg_t pa;
669deef35fdSEric Schrock 	ctf_id_t id;
670deef35fdSEric Schrock 	dt_module_t *dmp;
671a386cc11SRobert Mustacchi 	ctf_file_t *ctfp;
672a386cc11SRobert Mustacchi 	int libid;
673deef35fdSEric Schrock 
674deef35fdSEric Schrock 	/*
675deef35fdSEric Schrock 	 * Split the fully-qualified type ID (module`id).  This should
676deef35fdSEric Schrock 	 * always be the format, but if for some reason we don't find the
677deef35fdSEric Schrock 	 * expected value, return 0 to fall back to the generic trace()
678a386cc11SRobert Mustacchi 	 * behavior. In the case of userland CTF modules this will actually be
679a386cc11SRobert Mustacchi 	 * of the format (module`lib`id). This is due to the fact that those
680a386cc11SRobert Mustacchi 	 * modules have multiple CTF containers which `lib` identifies.
681deef35fdSEric Schrock 	 */
682deef35fdSEric Schrock 	for (s = typename; *s != '\0' && *s != '`'; s++)
683deef35fdSEric Schrock 		;
684deef35fdSEric Schrock 
685deef35fdSEric Schrock 	if (*s != '`')
686deef35fdSEric Schrock 		return (0);
687deef35fdSEric Schrock 
688deef35fdSEric Schrock 	object = alloca(s - typename + 1);
689deef35fdSEric Schrock 	bcopy(typename, object, s - typename);
690deef35fdSEric Schrock 	object[s - typename] = '\0';
691a386cc11SRobert Mustacchi 	dmp = dt_module_lookup_by_name(dtp, object);
692a386cc11SRobert Mustacchi 	if (dmp == NULL)
693a386cc11SRobert Mustacchi 		return (0);
694a386cc11SRobert Mustacchi 
695a386cc11SRobert Mustacchi 	if (dmp->dm_pid != 0) {
696a386cc11SRobert Mustacchi 		libid = atoi(s + 1);
697a386cc11SRobert Mustacchi 		s = strchr(s + 1, '`');
698a386cc11SRobert Mustacchi 		if (s == NULL || libid > dmp->dm_nctflibs)
699a386cc11SRobert Mustacchi 			return (0);
700a386cc11SRobert Mustacchi 		ctfp = dmp->dm_libctfp[libid];
701a386cc11SRobert Mustacchi 	} else {
702a386cc11SRobert Mustacchi 		ctfp = dt_module_getctf(dtp, dmp);
703a386cc11SRobert Mustacchi 	}
704a386cc11SRobert Mustacchi 
705deef35fdSEric Schrock 	id = atoi(s + 1);
706deef35fdSEric Schrock 
707deef35fdSEric Schrock 	/*
708deef35fdSEric Schrock 	 * Try to get the CTF kind for this id.  If something has gone horribly
709deef35fdSEric Schrock 	 * wrong and we can't resolve the ID, bail out and let trace() do the
710deef35fdSEric Schrock 	 * work.
711deef35fdSEric Schrock 	 */
712a386cc11SRobert Mustacchi 	if (ctfp == NULL || ctf_type_kind(ctfp, id) == CTF_ERR)
713deef35fdSEric Schrock 		return (0);
714deef35fdSEric Schrock 
715deef35fdSEric Schrock 	/* setup the print structure and kick off the main print routine */
716b1fa6326SRobert Mustacchi 	pa.pa_dtp = dtp;
717deef35fdSEric Schrock 	pa.pa_addr = addr;
718a386cc11SRobert Mustacchi 	pa.pa_ctfp = ctfp;
719deef35fdSEric Schrock 	pa.pa_nest = 0;
720deef35fdSEric Schrock 	pa.pa_depth = 0;
721deef35fdSEric Schrock 	pa.pa_file = fp;
722deef35fdSEric Schrock 	(void) ctf_type_visit(pa.pa_ctfp, id, dt_print_member, &pa);
723deef35fdSEric Schrock 
724deef35fdSEric Schrock 	dt_print_trailing_braces(&pa, 0);
725deef35fdSEric Schrock 
726deef35fdSEric Schrock 	return (len);
727deef35fdSEric Schrock }
728