xref: /onnv-gate/usr/src/cmd/mdb/common/modules/genunix/nvpair.c (revision 2869:324151eecd58)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2869Sgavinm  * Common Development and Distribution License (the "License").
6*2869Sgavinm  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2869Sgavinm  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/sysinfo.h>
290Sstevel@tonic-gate #include <sys/nvpair.h>
300Sstevel@tonic-gate #include <sys/nvpair_impl.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <ctype.h>
330Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include "nvpair.h"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #define	NVPAIR_VALUE_INDENT	4
380Sstevel@tonic-gate #define	NELEM(a)		(sizeof (a) / sizeof ((a)[0]))
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * nvpair walker
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate int
nvpair_walk_init(mdb_walk_state_t * wsp)440Sstevel@tonic-gate nvpair_walk_init(mdb_walk_state_t *wsp)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate 	nvlist_t nvlist;
470Sstevel@tonic-gate 	nvpriv_t nvpriv;
480Sstevel@tonic-gate 	i_nvp_t *tmp;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
510Sstevel@tonic-gate 		mdb_warn("nvpair does not support global walks\n");
520Sstevel@tonic-gate 		return (WALK_ERR);
530Sstevel@tonic-gate 	}
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	if (mdb_vread(&nvlist, sizeof (nvlist), wsp->walk_addr) == -1) {
560Sstevel@tonic-gate 		mdb_warn("failed to read nvlist at %p", wsp->walk_addr);
570Sstevel@tonic-gate 		return (WALK_ERR);
580Sstevel@tonic-gate 	}
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	if (mdb_vread(&nvpriv, sizeof (nvpriv), nvlist.nvl_priv) == -1) {
610Sstevel@tonic-gate 		mdb_warn("failed to read nvpriv at %p", nvlist.nvl_priv);
620Sstevel@tonic-gate 		return (WALK_ERR);
630Sstevel@tonic-gate 	}
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	tmp = (i_nvp_t *)nvpriv.nvp_list;
660Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tmp;
670Sstevel@tonic-gate 	return (WALK_NEXT);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate int
nvpair_walk_step(mdb_walk_state_t * wsp)710Sstevel@tonic-gate nvpair_walk_step(mdb_walk_state_t *wsp)
720Sstevel@tonic-gate {
730Sstevel@tonic-gate 	int	status;
740Sstevel@tonic-gate 	nvpair_t *nvpair;
750Sstevel@tonic-gate 	i_nvp_t i_nvp, *tmp;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
780Sstevel@tonic-gate 		return (WALK_DONE);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	if (mdb_vread(&i_nvp, sizeof (i_nvp), wsp->walk_addr) == -1) {
810Sstevel@tonic-gate 		mdb_warn("failed to read i_nvp at %p", wsp->walk_addr);
820Sstevel@tonic-gate 		return (WALK_ERR);
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	nvpair = &((i_nvp_t *)wsp->walk_addr)->nvi_nvp;
860Sstevel@tonic-gate 	status = wsp->walk_callback((uintptr_t)nvpair, NULL, wsp->walk_cbdata);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	tmp = i_nvp.nvi_next;
890Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tmp;
900Sstevel@tonic-gate 	return (status);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate 
93789Sahrens /*
94789Sahrens  * ::nvlist [-v]
95789Sahrens  *
96789Sahrens  * Print out an entire nvlist.  This is shorthand for '::walk nvpair |
97789Sahrens  * ::nvpair -rq'.  The '-v' option invokes '::nvpair' without the "-q" option.
98789Sahrens  */
99789Sahrens /*ARGSUSED*/
100789Sahrens int
print_nvlist(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)101*2869Sgavinm print_nvlist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
102789Sahrens {
103789Sahrens 	int verbose = B_FALSE;
104789Sahrens 	mdb_arg_t v;
105789Sahrens 
106789Sahrens 	if (!(flags & DCMD_ADDRSPEC))
107789Sahrens 		return (DCMD_USAGE);
108789Sahrens 
109789Sahrens 	if (mdb_getopts(argc, argv,
110789Sahrens 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
111789Sahrens 	    NULL) != argc)
112789Sahrens 		return (DCMD_USAGE);
113789Sahrens 
114789Sahrens 	v.a_type = MDB_TYPE_STRING;
115789Sahrens 	if (verbose)
116789Sahrens 		v.a_un.a_str = "-r";
117789Sahrens 	else
118789Sahrens 		v.a_un.a_str = "-rq";
119789Sahrens 
120789Sahrens 	return (mdb_pwalk_dcmd("nvpair", "nvpair", 1, &v, addr));
121789Sahrens }
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
124789Sahrens  * ::nvpair [-rq]
125789Sahrens  *
126789Sahrens  * 	-r	Recursively print any nvlist elements
127789Sahrens  * 	-q	Quiet mode; print members only as "name=value"
128789Sahrens  *
129789Sahrens  * Prints out a single nvpair.  By default, all information is printed.  When
130789Sahrens  * given the '-q' option, the type of elements is hidden, and elements are
131789Sahrens  * instead printed simply as 'name=value'.
1320Sstevel@tonic-gate  */
1330Sstevel@tonic-gate typedef struct {
1340Sstevel@tonic-gate 	data_type_t	type;
1350Sstevel@tonic-gate 	int		elem_size;
1360Sstevel@tonic-gate 	char		*type_name;
1370Sstevel@tonic-gate } nvpair_info_t;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate nvpair_info_t nvpair_info[] =  {
1400Sstevel@tonic-gate 	{ DATA_TYPE_BOOLEAN,		1, "boolean" },
1410Sstevel@tonic-gate 	{ DATA_TYPE_BOOLEAN_VALUE,	4, "boolean_value" },
1420Sstevel@tonic-gate 	{ DATA_TYPE_BYTE,		1, "byte" },
1430Sstevel@tonic-gate 	{ DATA_TYPE_INT8,		1, "int8" },
1440Sstevel@tonic-gate 	{ DATA_TYPE_UINT8,		1, "uint8" },
1450Sstevel@tonic-gate 	{ DATA_TYPE_INT16,		2, "int16" },
1460Sstevel@tonic-gate 	{ DATA_TYPE_UINT16,		2, "uint16" },
1470Sstevel@tonic-gate 	{ DATA_TYPE_INT32,		4, "int32" },
1480Sstevel@tonic-gate 	{ DATA_TYPE_UINT32,		4, "uint32" },
1490Sstevel@tonic-gate 	{ DATA_TYPE_INT64,		8, "int64" },
1500Sstevel@tonic-gate 	{ DATA_TYPE_UINT64,		8, "uint64" },
1510Sstevel@tonic-gate 	{ DATA_TYPE_STRING,		0, "string" },
1520Sstevel@tonic-gate 	{ DATA_TYPE_NVLIST,		0, "nvpair_list" },
1530Sstevel@tonic-gate 	{ DATA_TYPE_HRTIME,		8, "hrtime" },
1540Sstevel@tonic-gate 	{ DATA_TYPE_BOOLEAN_ARRAY,	4, "boolean_array" },
1550Sstevel@tonic-gate 	{ DATA_TYPE_BYTE_ARRAY,		1, "byte_array" },
1560Sstevel@tonic-gate 	{ DATA_TYPE_INT8_ARRAY,		1, "int8_array" },
1570Sstevel@tonic-gate 	{ DATA_TYPE_UINT8_ARRAY,	1, "uint8_array" },
1580Sstevel@tonic-gate 	{ DATA_TYPE_INT16_ARRAY,	2, "int16_array" },
1590Sstevel@tonic-gate 	{ DATA_TYPE_UINT16_ARRAY,	2, "uint16_array" },
1600Sstevel@tonic-gate 	{ DATA_TYPE_INT32_ARRAY,	4, "int32_array" },
1610Sstevel@tonic-gate 	{ DATA_TYPE_UINT32_ARRAY,	4, "uint32_array" },
1620Sstevel@tonic-gate 	{ DATA_TYPE_INT64_ARRAY, 	8, "int64_array" },
1630Sstevel@tonic-gate 	{ DATA_TYPE_UINT64_ARRAY,	8, "uint64_array" },
1640Sstevel@tonic-gate 	{ DATA_TYPE_STRING_ARRAY,	0, "string_array" },
1650Sstevel@tonic-gate 	{ DATA_TYPE_NVLIST_ARRAY,	0, "nvpair list_array" }
1660Sstevel@tonic-gate };
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate static void
nvpair_print_value(char * data,int32_t elem_size,int32_t nelem,data_type_t type)1690Sstevel@tonic-gate nvpair_print_value(char *data, int32_t elem_size, int32_t nelem,
1700Sstevel@tonic-gate     data_type_t type)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate 	int32_t i;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	if (elem_size == 0) {
1750Sstevel@tonic-gate 		char *p = data;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 		/* print out all the strings */
1780Sstevel@tonic-gate 		for (i = 0; i < nelem - 1; i++) {
1790Sstevel@tonic-gate 			mdb_printf("'%s' + ", p);
1800Sstevel@tonic-gate 			p += strlen(p) + 1;
1810Sstevel@tonic-gate 		}
1820Sstevel@tonic-gate 		mdb_printf("'%s'", p);
1830Sstevel@tonic-gate 	} else if (type == DATA_TYPE_BOOLEAN_VALUE ||
1840Sstevel@tonic-gate 	    type == DATA_TYPE_BOOLEAN_ARRAY) {
1850Sstevel@tonic-gate 		/* LINTED - pointer alignment */
1860Sstevel@tonic-gate 		boolean_t *p = (boolean_t *)data;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 		for (i = 0; i < nelem; i++) {
1890Sstevel@tonic-gate 			if (i > 0)
1900Sstevel@tonic-gate 				mdb_printf(".");
1910Sstevel@tonic-gate 			mdb_printf("%d", p[i]);
1920Sstevel@tonic-gate 		}
1930Sstevel@tonic-gate 	} else {
1940Sstevel@tonic-gate 		unsigned char	*p = (unsigned char *)data;
1950Sstevel@tonic-gate 		int		size = elem_size * nelem;
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 		/*
1980Sstevel@tonic-gate 		 * if elem_size != 0 then we are printing out an array
1990Sstevel@tonic-gate 		 * where each element is of elem_size
2000Sstevel@tonic-gate 		 */
2010Sstevel@tonic-gate 		mdb_nhconvert(p, p, elem_size);
2020Sstevel@tonic-gate 		mdb_printf("%02x", *p);
2030Sstevel@tonic-gate 		for (i = 1; i < size; i++) {
2040Sstevel@tonic-gate 			if ((i % elem_size) == 0) {
2050Sstevel@tonic-gate 				mdb_nhconvert(&p[i], &p[i], elem_size);
2060Sstevel@tonic-gate 				mdb_printf(".");
2070Sstevel@tonic-gate 			}
2080Sstevel@tonic-gate 			mdb_printf("%02x", p[i]);
2090Sstevel@tonic-gate 		}
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 	mdb_printf("\n");
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*ARGSUSED*/
2150Sstevel@tonic-gate int
nvpair_print(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2160Sstevel@tonic-gate nvpair_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2170Sstevel@tonic-gate {
2180Sstevel@tonic-gate 	nvpair_t	nvpair_tmp, *nvpair;
2190Sstevel@tonic-gate 	int32_t		i, size, nelem, elem_size = 0;
2200Sstevel@tonic-gate 	char		*data = NULL, *data_end = NULL;
2210Sstevel@tonic-gate 	char		*type_name = NULL;
2220Sstevel@tonic-gate 	data_type_t	type = DATA_TYPE_UNKNOWN;
223789Sahrens 	int		quiet = FALSE;
224789Sahrens 	int		recurse = FALSE;
2250Sstevel@tonic-gate 
226789Sahrens 	if (!(flags & DCMD_ADDRSPEC))
227789Sahrens 		return (DCMD_USAGE);
228789Sahrens 
229789Sahrens 	if (mdb_getopts(argc, argv,
230789Sahrens 	    'r', MDB_OPT_SETBITS, TRUE, &recurse,
231789Sahrens 	    'q', MDB_OPT_SETBITS, TRUE, &quiet,
232789Sahrens 	    NULL) != argc)
2330Sstevel@tonic-gate 		return (DCMD_USAGE);
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	/* read in the nvpair header so we can get the size */
2360Sstevel@tonic-gate 	if (mdb_vread(&nvpair_tmp, sizeof (nvpair), addr) == -1) {
2370Sstevel@tonic-gate 		mdb_warn("failed to read nvpair at %p", addr);
2380Sstevel@tonic-gate 		return (DCMD_ERR);
2390Sstevel@tonic-gate 	}
2400Sstevel@tonic-gate 	size = NVP_SIZE(&nvpair_tmp);
2410Sstevel@tonic-gate 	if (size == 0) {
2420Sstevel@tonic-gate 		mdb_warn("nvpair of size zero at %p", addr);
2430Sstevel@tonic-gate 		return (DCMD_OK);
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	/* read in the entire nvpair */
2470Sstevel@tonic-gate 	nvpair = mdb_alloc(size, UM_SLEEP | UM_GC);
2480Sstevel@tonic-gate 	if (mdb_vread(nvpair, size, addr) == -1) {
2490Sstevel@tonic-gate 		mdb_warn("failed to read nvpair and data at %p", addr);
2500Sstevel@tonic-gate 		return (DCMD_ERR);
2510Sstevel@tonic-gate 	}
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	/* lookup type decoding information for this nvpair */
2540Sstevel@tonic-gate 	type = NVP_TYPE(nvpair);
2550Sstevel@tonic-gate 	nelem = NVP_NELEM(nvpair);
2560Sstevel@tonic-gate 	for (i = 0; i < NELEM(nvpair_info); i++) {
2570Sstevel@tonic-gate 		if (nvpair_info[i].type == type) {
2580Sstevel@tonic-gate 			elem_size = nvpair_info[i].elem_size;
2590Sstevel@tonic-gate 			type_name = nvpair_info[i].type_name;
2600Sstevel@tonic-gate 			break;
2610Sstevel@tonic-gate 		}
2620Sstevel@tonic-gate 	}
263789Sahrens 
264789Sahrens 	if (quiet) {
265789Sahrens 		mdb_printf("%s", NVP_NAME(nvpair));
2660Sstevel@tonic-gate 	} else {
267789Sahrens 		/* print out the first line of nvpair info */
268789Sahrens 		mdb_printf("name='%s'", NVP_NAME(nvpair));
269789Sahrens 		if (type_name != NULL) {
270789Sahrens 			mdb_printf(" type=%s", type_name);
271789Sahrens 		} else {
272789Sahrens 			/*
273789Sahrens 			 * If the nvpair type is unknown we print the type
274789Sahrens 			 * number
275789Sahrens 			 */
276789Sahrens 			mdb_printf(" type=0x%x", type);
277789Sahrens 		}
278789Sahrens 		mdb_printf(" items=%d\n", nelem);
2790Sstevel@tonic-gate 	}
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	/* if there is no data and the type is known then we're done */
282789Sahrens 	if ((nelem == 0) && (type_name != NULL)) {
283789Sahrens 		if (quiet)
284789Sahrens 			mdb_printf("(unknown)\n");
2850Sstevel@tonic-gate 		return (DCMD_OK);
286789Sahrens 	}
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	/* get pointers to the data to print out */
2890Sstevel@tonic-gate 	data = (char *)NVP_VALUE(nvpair);
2900Sstevel@tonic-gate 	data_end = (char *)nvpair + NVP_SIZE(nvpair);
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	/*
2930Sstevel@tonic-gate 	 * The value of the name-value pair for a single embedded
2940Sstevel@tonic-gate 	 * list is the nvlist_t structure for the embedded list.
2950Sstevel@tonic-gate 	 * So we print that address out (computed as an offset from
2960Sstevel@tonic-gate 	 * the nvpair address we received as addr).
2970Sstevel@tonic-gate 	 *
2980Sstevel@tonic-gate 	 * The value of the name-value pair for an array of embedded
2990Sstevel@tonic-gate 	 * lists is nelem pointers to nvlist_t structures followed
3000Sstevel@tonic-gate 	 * by the structures themselves.  We display the list
3010Sstevel@tonic-gate 	 * of pointers as the pair's value.
3020Sstevel@tonic-gate 	 */
3030Sstevel@tonic-gate 	if (type == DATA_TYPE_NVLIST) {
3040Sstevel@tonic-gate 		char *p = (char *)addr + (data - (char *)nvpair);
305789Sahrens 		if (recurse) {
306789Sahrens 			if (quiet)
307789Sahrens 				mdb_printf("\n");
308789Sahrens 			mdb_inc_indent(NVPAIR_VALUE_INDENT);
309789Sahrens 			if (mdb_pwalk_dcmd("nvpair", "nvpair", argc, argv,
310789Sahrens 			    (uintptr_t)p) != DCMD_OK)
311789Sahrens 				return (DCMD_ERR);
312789Sahrens 			mdb_dec_indent(NVPAIR_VALUE_INDENT);
313789Sahrens 		} else {
314789Sahrens 			if (!quiet) {
315789Sahrens 				mdb_inc_indent(NVPAIR_VALUE_INDENT);
316789Sahrens 				mdb_printf("value", p);
317789Sahrens 			}
318789Sahrens 			mdb_printf("=%p\n", p);
319789Sahrens 			if (!quiet)
320789Sahrens 				mdb_dec_indent(NVPAIR_VALUE_INDENT);
321789Sahrens 		}
3220Sstevel@tonic-gate 		return (DCMD_OK);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 	} else if (type == DATA_TYPE_NVLIST_ARRAY) {
325789Sahrens 		if (recurse) {
326789Sahrens 			for (i = 0; i < nelem; i++,
327789Sahrens 			    data += sizeof (nvlist_t *)) {
328789Sahrens 				nvlist_t **nl = (nvlist_t **)(void *)data;
329789Sahrens 				if (quiet && i != 0)
330789Sahrens 					mdb_printf("%s", NVP_NAME(nvpair));
331789Sahrens 				mdb_printf("[%d]\n", i);
332789Sahrens 				mdb_inc_indent(NVPAIR_VALUE_INDENT);
333789Sahrens 				if (mdb_pwalk_dcmd("nvpair", "nvpair", argc,
334789Sahrens 				    argv, (uintptr_t)*nl) != DCMD_OK)
335789Sahrens 					return (DCMD_ERR);
336789Sahrens 				mdb_dec_indent(NVPAIR_VALUE_INDENT);
337789Sahrens 			}
338789Sahrens 		} else {
339789Sahrens 			if (!quiet) {
340789Sahrens 				mdb_inc_indent(NVPAIR_VALUE_INDENT);
341789Sahrens 				mdb_printf("value");
342789Sahrens 			}
343789Sahrens 			mdb_printf("=");
344789Sahrens 			for (i = 0; i < nelem; i++,
345789Sahrens 			    data += sizeof (nvlist_t *)) {
346789Sahrens 				nvlist_t **nl = (nvlist_t **)(void *)data;
347789Sahrens 				mdb_printf("%c%p", " "[i == 0], *nl);
348789Sahrens 			}
349789Sahrens 			mdb_printf("\n");
350789Sahrens 			if (!quiet)
351789Sahrens 				mdb_dec_indent(NVPAIR_VALUE_INDENT);
3520Sstevel@tonic-gate 		}
3530Sstevel@tonic-gate 		return (DCMD_OK);
3540Sstevel@tonic-gate 	}
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	/* if it's a string array, skip the index pointers */
3570Sstevel@tonic-gate 	if (type == DATA_TYPE_STRING_ARRAY)
3580Sstevel@tonic-gate 		data += (sizeof (int64_t) * nelem);
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/* if the type is unknown, treat the data as a byte array */
3610Sstevel@tonic-gate 	if (type_name == NULL) {
3620Sstevel@tonic-gate 		elem_size = 1;
3630Sstevel@tonic-gate 		nelem = data_end - data;
3640Sstevel@tonic-gate 	}
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	/*
3670Sstevel@tonic-gate 	 * if the type is of strings, make sure they are printable
3680Sstevel@tonic-gate 	 * otherwise print them out as byte arrays
3690Sstevel@tonic-gate 	 */
3700Sstevel@tonic-gate 	if (elem_size == 0) {
3710Sstevel@tonic-gate 		int32_t	count = 0;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 		i = 0;
3740Sstevel@tonic-gate 		while ((&data[i] < data_end) && (count < nelem)) {
3750Sstevel@tonic-gate 			if (data[i] == '\0')
3760Sstevel@tonic-gate 				count++;
3770Sstevel@tonic-gate 			else if (!isprint(data[i]))
3780Sstevel@tonic-gate 				break;
3790Sstevel@tonic-gate 			i++;
3800Sstevel@tonic-gate 		}
3810Sstevel@tonic-gate 		if (count != nelem) {
3820Sstevel@tonic-gate 			/* there is unprintable data, output as byte array */
3830Sstevel@tonic-gate 			elem_size = 1;
3840Sstevel@tonic-gate 			nelem =  data_end - data;
3850Sstevel@tonic-gate 		}
3860Sstevel@tonic-gate 	}
3870Sstevel@tonic-gate 
388789Sahrens 	if (!quiet) {
389789Sahrens 		mdb_inc_indent(NVPAIR_VALUE_INDENT);
390789Sahrens 		mdb_printf("value=");
391789Sahrens 	} else {
392789Sahrens 		mdb_printf("=");
393789Sahrens 	}
3940Sstevel@tonic-gate 	nvpair_print_value(data, elem_size, nelem, type);
395789Sahrens 	if (!quiet)
396789Sahrens 		mdb_dec_indent(NVPAIR_VALUE_INDENT);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	return (DCMD_OK);
3990Sstevel@tonic-gate }
400