17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
58a40a69gavinm * Common Development and Distribution License (the "License").
68a40a69gavinm * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
228a40a69gavinm * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate#include <sys/sysinfo.h>
277c478bdstevel@tonic-gate#include <sys/nvpair.h>
287c478bdstevel@tonic-gate#include <sys/nvpair_impl.h>
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#include <ctype.h>
317c478bdstevel@tonic-gate#include <mdb/mdb_modapi.h>
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#include "nvpair.h"
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#define	NVPAIR_VALUE_INDENT	4
367c478bdstevel@tonic-gate#define	NELEM(a)		(sizeof (a) / sizeof ((a)[0]))
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate/*
397c478bdstevel@tonic-gate * nvpair walker
407c478bdstevel@tonic-gate */
417c478bdstevel@tonic-gateint
427c478bdstevel@tonic-gatenvpair_walk_init(mdb_walk_state_t *wsp)
437c478bdstevel@tonic-gate{
447c478bdstevel@tonic-gate	nvlist_t nvlist;
457c478bdstevel@tonic-gate	nvpriv_t nvpriv;
467c478bdstevel@tonic-gate	i_nvp_t *tmp;
477c478bdstevel@tonic-gate
48892ad16Toomas Soome	if (wsp->walk_addr == 0) {
497c478bdstevel@tonic-gate		mdb_warn("nvpair does not support global walks\n");
507c478bdstevel@tonic-gate		return (WALK_ERR);
517c478bdstevel@tonic-gate	}
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate	if (mdb_vread(&nvlist, sizeof (nvlist), wsp->walk_addr) == -1) {
547c478bdstevel@tonic-gate		mdb_warn("failed to read nvlist at %p", wsp->walk_addr);
557c478bdstevel@tonic-gate		return (WALK_ERR);
567c478bdstevel@tonic-gate	}
577c478bdstevel@tonic-gate
587c478bdstevel@tonic-gate	if (mdb_vread(&nvpriv, sizeof (nvpriv), nvlist.nvl_priv) == -1) {
597c478bdstevel@tonic-gate		mdb_warn("failed to read nvpriv at %p", nvlist.nvl_priv);
607c478bdstevel@tonic-gate		return (WALK_ERR);
617c478bdstevel@tonic-gate	}
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate	tmp = (i_nvp_t *)nvpriv.nvp_list;
647c478bdstevel@tonic-gate	wsp->walk_addr = (uintptr_t)tmp;
657c478bdstevel@tonic-gate	return (WALK_NEXT);
667c478bdstevel@tonic-gate}
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gateint
697c478bdstevel@tonic-gatenvpair_walk_step(mdb_walk_state_t *wsp)
707c478bdstevel@tonic-gate{
717c478bdstevel@tonic-gate	int	status;
727c478bdstevel@tonic-gate	nvpair_t *nvpair;
737c478bdstevel@tonic-gate	i_nvp_t i_nvp, *tmp;
747c478bdstevel@tonic-gate
75892ad16Toomas Soome	if (wsp->walk_addr == 0)
767c478bdstevel@tonic-gate		return (WALK_DONE);
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate	if (mdb_vread(&i_nvp, sizeof (i_nvp), wsp->walk_addr) == -1) {
797c478bdstevel@tonic-gate		mdb_warn("failed to read i_nvp at %p", wsp->walk_addr);
807c478bdstevel@tonic-gate		return (WALK_ERR);
817c478bdstevel@tonic-gate	}
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate	nvpair = &((i_nvp_t *)wsp->walk_addr)->nvi_nvp;
847c478bdstevel@tonic-gate	status = wsp->walk_callback((uintptr_t)nvpair, NULL, wsp->walk_cbdata);
857c478bdstevel@tonic-gate
867c478bdstevel@tonic-gate	tmp = i_nvp.nvi_next;
877c478bdstevel@tonic-gate	wsp->walk_addr = (uintptr_t)tmp;
887c478bdstevel@tonic-gate	return (status);
897c478bdstevel@tonic-gate}
907c478bdstevel@tonic-gate
91fa9e406ahrens/*
92fa9e406ahrens * ::nvlist [-v]
93fa9e406ahrens *
94fa9e406ahrens * Print out an entire nvlist.  This is shorthand for '::walk nvpair |
95fa9e406ahrens * ::nvpair -rq'.  The '-v' option invokes '::nvpair' without the "-q" option.
96fa9e406ahrens */
97fa9e406ahrens/*ARGSUSED*/
98fa9e406ahrensint
998a40a69gavinmprint_nvlist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
100fa9e406ahrens{
101fa9e406ahrens	int verbose = B_FALSE;
102fa9e406ahrens	mdb_arg_t v;
103fa9e406ahrens
104fa9e406ahrens	if (!(flags & DCMD_ADDRSPEC))
105fa9e406ahrens		return (DCMD_USAGE);
106fa9e406ahrens
107fa9e406ahrens	if (mdb_getopts(argc, argv,
108fa9e406ahrens	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
109fa9e406ahrens	    NULL) != argc)
110fa9e406ahrens		return (DCMD_USAGE);
111fa9e406ahrens
112fa9e406ahrens	v.a_type = MDB_TYPE_STRING;
113fa9e406ahrens	if (verbose)
114fa9e406ahrens		v.a_un.a_str = "-r";
115fa9e406ahrens	else
116fa9e406ahrens		v.a_un.a_str = "-rq";
117fa9e406ahrens
118fa9e406ahrens	return (mdb_pwalk_dcmd("nvpair", "nvpair", 1, &v, addr));
119fa9e406ahrens}
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gate/*
122fa9e406ahrens * ::nvpair [-rq]
123fa9e406ahrens *
124892ad16Toomas Soome *	-r	Recursively print any nvlist elements
125892ad16Toomas Soome *	-q	Quiet mode; print members only as "name=value"
126fa9e406ahrens *
127fa9e406ahrens * Prints out a single nvpair.  By default, all information is printed.  When
128fa9e406ahrens * given the '-q' option, the type of elements is hidden, and elements are
129fa9e406ahrens * instead printed simply as 'name=value'.
1307c478bdstevel@tonic-gate */
1317c478bdstevel@tonic-gatetypedef struct {
1327c478bdstevel@tonic-gate	data_type_t	type;
1337c478bdstevel@tonic-gate	int		elem_size;
1347c478bdstevel@tonic-gate	char		*type_name;
1357c478bdstevel@tonic-gate} nvpair_info_t;
1367c478bdstevel@tonic-gate
1377c478bdstevel@tonic-gatenvpair_info_t nvpair_info[] =  {
1387c478bdstevel@tonic-gate	{ DATA_TYPE_BOOLEAN,		1, "boolean" },
1397c478bdstevel@tonic-gate	{ DATA_TYPE_BOOLEAN_VALUE,	4, "boolean_value" },
1407c478bdstevel@tonic-gate	{ DATA_TYPE_BYTE,		1, "byte" },
1417c478bdstevel@tonic-gate	{ DATA_TYPE_INT8,		1, "int8" },
1427c478bdstevel@tonic-gate	{ DATA_TYPE_UINT8,		1, "uint8" },
1437c478bdstevel@tonic-gate	{ DATA_TYPE_INT16,		2, "int16" },
1447c478bdstevel@tonic-gate	{ DATA_TYPE_UINT16,		2, "uint16" },
1457c478bdstevel@tonic-gate	{ DATA_TYPE_INT32,		4, "int32" },
1467c478bdstevel@tonic-gate	{ DATA_TYPE_UINT32,		4, "uint32" },
1477c478bdstevel@tonic-gate	{ DATA_TYPE_INT64,		8, "int64" },
1487c478bdstevel@tonic-gate	{ DATA_TYPE_UINT64,		8, "uint64" },
1497c478bdstevel@tonic-gate	{ DATA_TYPE_STRING,		0, "string" },
1507c478bdstevel@tonic-gate	{ DATA_TYPE_NVLIST,		0, "nvpair_list" },
1517c478bdstevel@tonic-gate	{ DATA_TYPE_HRTIME,		8, "hrtime" },
1527c478bdstevel@tonic-gate	{ DATA_TYPE_BOOLEAN_ARRAY,	4, "boolean_array" },
1537c478bdstevel@tonic-gate	{ DATA_TYPE_BYTE_ARRAY,		1, "byte_array" },
1547c478bdstevel@tonic-gate	{ DATA_TYPE_INT8_ARRAY,		1, "int8_array" },
1557c478bdstevel@tonic-gate	{ DATA_TYPE_UINT8_ARRAY,	1, "uint8_array" },
1567c478bdstevel@tonic-gate	{ DATA_TYPE_INT16_ARRAY,	2, "int16_array" },
1577c478bdstevel@tonic-gate	{ DATA_TYPE_UINT16_ARRAY,	2, "uint16_array" },
1587c478bdstevel@tonic-gate	{ DATA_TYPE_INT32_ARRAY,	4, "int32_array" },
1597c478bdstevel@tonic-gate	{ DATA_TYPE_UINT32_ARRAY,	4, "uint32_array" },
160892ad16Toomas Soome	{ DATA_TYPE_INT64_ARRAY,	8, "int64_array" },
1617c478bdstevel@tonic-gate	{ DATA_TYPE_UINT64_ARRAY,	8, "uint64_array" },
1627c478bdstevel@tonic-gate	{ DATA_TYPE_STRING_ARRAY,	0, "string_array" },
1637c478bdstevel@tonic-gate	{ DATA_TYPE_NVLIST_ARRAY,	0, "nvpair list_array" }
1647c478bdstevel@tonic-gate};
1657c478bdstevel@tonic-gate
1667c478bdstevel@tonic-gatestatic void
1677c478bdstevel@tonic-gatenvpair_print_value(char *data, int32_t elem_size, int32_t nelem,
1687c478bdstevel@tonic-gate    data_type_t type)
1697c478bdstevel@tonic-gate{
1707c478bdstevel@tonic-gate	int32_t i;
1717c478bdstevel@tonic-gate
1727c478bdstevel@tonic-gate	if (elem_size == 0) {
1737c478bdstevel@tonic-gate		char *p = data;
1747c478bdstevel@tonic-gate
1757c478bdstevel@tonic-gate		/* print out all the strings */
1767c478bdstevel@tonic-gate		for (i = 0; i < nelem - 1; i++) {
1777c478bdstevel@tonic-gate			mdb_printf("'%s' + ", p);
1787c478bdstevel@tonic-gate			p += strlen(p) + 1;
1797c478bdstevel@tonic-gate		}
1807c478bdstevel@tonic-gate		mdb_printf("'%s'", p);
1817c478bdstevel@tonic-gate	} else if (type == DATA_TYPE_BOOLEAN_VALUE ||
1827c478bdstevel@tonic-gate	    type == DATA_TYPE_BOOLEAN_ARRAY) {
1837c478bdstevel@tonic-gate		/* LINTED - pointer alignment */
1847c478bdstevel@tonic-gate		boolean_t *p = (boolean_t *)data;
1857c478bdstevel@tonic-gate
1867c478bdstevel@tonic-gate		for (i = 0; i < nelem; i++) {
1877c478bdstevel@tonic-gate			if (i > 0)
1887c478bdstevel@tonic-gate				mdb_printf(".");
1897c478bdstevel@tonic-gate			mdb_printf("%d", p[i]);
1907c478bdstevel@tonic-gate		}
1917c478bdstevel@tonic-gate	} else {
1927c478bdstevel@tonic-gate		unsigned char	*p = (unsigned char *)data;
1937c478bdstevel@tonic-gate		int		size = elem_size * nelem;
1947c478bdstevel@tonic-gate
1957c478bdstevel@tonic-gate		/*
1967c478bdstevel@tonic-gate		 * if elem_size != 0 then we are printing out an array
1977c478bdstevel@tonic-gate		 * where each element is of elem_size
1987c478bdstevel@tonic-gate		 */
1997c478bdstevel@tonic-gate		mdb_nhconvert(p, p, elem_size);
2007c478bdstevel@tonic-gate		mdb_printf("%02x", *p);
2017c478bdstevel@tonic-gate		for (i = 1; i < size; i++) {
2027c478bdstevel@tonic-gate			if ((i % elem_size) == 0) {
2037c478bdstevel@tonic-gate				mdb_nhconvert(&p[i], &p[i], elem_size);
2047c478bdstevel@tonic-gate				mdb_printf(".");
2057c478bdstevel@tonic-gate			}
2067c478bdstevel@tonic-gate			mdb_printf("%02x", p[i]);
2077c478bdstevel@tonic-gate		}
2087c478bdstevel@tonic-gate	}
2097c478bdstevel@tonic-gate	mdb_printf("\n");
2107c478bdstevel@tonic-gate}
2117c478bdstevel@tonic-gate
2127c478bdstevel@tonic-gate/*ARGSUSED*/
2137c478bdstevel@tonic-gateint
2147c478bdstevel@tonic-gatenvpair_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2157c478bdstevel@tonic-gate{
2167c478bdstevel@tonic-gate	nvpair_t	nvpair_tmp, *nvpair;
2177c478bdstevel@tonic-gate	int32_t		i, size, nelem, elem_size = 0;
2187c478bdstevel@tonic-gate	char		*data = NULL, *data_end = NULL;
2197c478bdstevel@tonic-gate	char		*type_name = NULL;
2207c478bdstevel@tonic-gate	data_type_t	type = DATA_TYPE_UNKNOWN;
221fa9e406ahrens	int		quiet = FALSE;
222fa9e406ahrens	int		recurse = FALSE;
223fa9e406ahrens
224fa9e406ahrens	if (!(flags & DCMD_ADDRSPEC))
225fa9e406ahrens		return (DCMD_USAGE);
2267c478bdstevel@tonic-gate
227fa9e406ahrens	if (mdb_getopts(argc, argv,
228fa9e406ahrens	    'r', MDB_OPT_SETBITS, TRUE, &recurse,
229fa9e406ahrens	    'q', MDB_OPT_SETBITS, TRUE, &quiet,
230fa9e406ahrens	    NULL) != argc)
2317c478bdstevel@tonic-gate		return (DCMD_USAGE);
2327c478bdstevel@tonic-gate
2337c478bdstevel@tonic-gate	/* read in the nvpair header so we can get the size */
2347c478bdstevel@tonic-gate	if (mdb_vread(&nvpair_tmp, sizeof (nvpair), addr) == -1) {
2357c478bdstevel@tonic-gate		mdb_warn("failed to read nvpair at %p", addr);
2367c478bdstevel@tonic-gate		return (DCMD_ERR);
2377c478bdstevel@tonic-gate	}
2387c478bdstevel@tonic-gate	size = NVP_SIZE(&nvpair_tmp);
2397c478bdstevel@tonic-gate	if (size == 0) {
2407c478bdstevel@tonic-gate		mdb_warn("nvpair of size zero at %p", addr);
2417c478bdstevel@tonic-gate		return (DCMD_OK);
2427c478bdstevel@tonic-gate	}
2437c478bdstevel@tonic-gate
2447c478bdstevel@tonic-gate	/* read in the entire nvpair */
2457c478bdstevel@tonic-gate	nvpair = mdb_alloc(size, UM_SLEEP | UM_GC);
2467c478bdstevel@tonic-gate	if (mdb_vread(nvpair, size, addr) == -1) {
2477c478bdstevel@tonic-gate		mdb_warn("failed to read nvpair and data at %p", addr);
2487c478bdstevel@tonic-gate		return (DCMD_ERR);
2497c478bdstevel@tonic-gate	}
2507c478bdstevel@tonic-gate
2517c478bdstevel@tonic-gate	/* lookup type decoding information for this nvpair */
2527c478bdstevel@tonic-gate	type = NVP_TYPE(nvpair);
2537c478bdstevel@tonic-gate	nelem = NVP_NELEM(nvpair);
2547c478bdstevel@tonic-gate	for (i = 0; i < NELEM(nvpair_info); i++) {
2557c478bdstevel@tonic-gate		if (nvpair_info[i].type == type) {
2567c478bdstevel@tonic-gate			elem_size = nvpair_info[i].elem_size;
2577c478bdstevel@tonic-gate			type_name = nvpair_info[i].type_name;
2587c478bdstevel@tonic-gate			break;
2597c478bdstevel@tonic-gate		}
2607c478bdstevel@tonic-gate	}
261fa9e406ahrens
262fa9e406ahrens	if (quiet) {
263fa9e406ahrens		mdb_printf("%s", NVP_NAME(nvpair));
2647c478bdstevel@tonic-gate	} else {
265fa9e406ahrens		/* print out the first line of nvpair info */
266fa9e406ahrens		mdb_printf("name='%s'", NVP_NAME(nvpair));
267fa9e406ahrens		if (type_name != NULL) {
268fa9e406ahrens			mdb_printf(" type=%s", type_name);
269fa9e406ahrens		} else {
270fa9e406ahrens			/*
271fa9e406ahrens			 * If the nvpair type is unknown we print the type
272fa9e406ahrens			 * number
273fa9e406ahrens			 */
274fa9e406ahrens			mdb_printf(" type=0x%x", type);
275fa9e406ahrens		}
276fa9e406ahrens		mdb_printf(" items=%d\n", nelem);
2777c478bdstevel@tonic-gate	}
2787c478bdstevel@tonic-gate
2797c478bdstevel@tonic-gate	/* if there is no data and the type is known then we're done */
280fa9e406ahrens	if ((nelem == 0) && (type_name != NULL)) {
281fa9e406ahrens		if (quiet)
282fa9e406ahrens			mdb_printf("(unknown)\n");
2837c478bdstevel@tonic-gate		return (DCMD_OK);
284fa9e406ahrens	}
2857c478bdstevel@tonic-gate
2867c478bdstevel@tonic-gate	/* get pointers to the data to print out */
2877c478bdstevel@tonic-gate	data = (char *)NVP_VALUE(nvpair);
2887c478bdstevel@tonic-gate	data_end = (char *)nvpair + NVP_SIZE(nvpair);
2897c478bdstevel@tonic-gate
2907c478bdstevel@tonic-gate	/*
2917c478bdstevel@tonic-gate	 * The value of the name-value pair for a single embedded
2927c478bdstevel@tonic-gate	 * list is the nvlist_t structure for the embedded list.
2937c478bdstevel@tonic-gate	 * So we print that address out (computed as an offset from
2947c478bdstevel@tonic-gate	 * the nvpair address we received as addr).
2957c478bdstevel@tonic-gate	 *
2967c478bdstevel@tonic-gate	 * The value of the name-value pair for an array of embedded
2977c478bdstevel@tonic-gate	 * lists is nelem pointers to nvlist_t structures followed
2987c478bdstevel@tonic-gate	 * by the structures themselves.  We display the list
2997c478bdstevel@tonic-gate	 * of pointers as the pair's value.
3007c478bdstevel@tonic-gate	 */
3017c478bdstevel@tonic-gate	if (type == DATA_TYPE_NVLIST) {
3027c478bdstevel@tonic-gate		char *p = (char *)addr + (data - (char *)nvpair);
303fa9e406ahrens		if (recurse) {
304fa9e406ahrens			if (quiet)
305fa9e406ahrens				mdb_printf("\n");
306fa9e406ahrens			mdb_inc_indent(NVPAIR_VALUE_INDENT);
307fa9e406ahrens			if (mdb_pwalk_dcmd("nvpair", "nvpair", argc, argv,
308fa9e406ahrens			    (uintptr_t)p) != DCMD_OK)
309fa9e406ahrens				return (DCMD_ERR);
310fa9e406ahrens			mdb_dec_indent(NVPAIR_VALUE_INDENT);
311fa9e406ahrens		} else {
312fa9e406ahrens			if (!quiet) {
313fa9e406ahrens				mdb_inc_indent(NVPAIR_VALUE_INDENT);
314fa9e406ahrens				mdb_printf("value", p);
315fa9e406ahrens			}
316fa9e406ahrens			mdb_printf("=%p\n", p);
317fa9e406ahrens			if (!quiet)
318fa9e406ahrens				mdb_dec_indent(NVPAIR_VALUE_INDENT);
319fa9e406ahrens		}
3207c478bdstevel@tonic-gate		return (DCMD_OK);
3217c478bdstevel@tonic-gate
3227c478bdstevel@tonic-gate	} else if (type == DATA_TYPE_NVLIST_ARRAY) {
323fa9e406ahrens		if (recurse) {
324fa9e406ahrens			for (i = 0; i < nelem; i++,
325fa9e406ahrens			    data += sizeof (nvlist_t *)) {
326fa9e406ahrens				nvlist_t **nl = (nvlist_t **)(void *)data;
327fa9e406ahrens				if (quiet && i != 0)
328fa9e406ahrens					mdb_printf("%s", NVP_NAME(nvpair));
329fa9e406ahrens				mdb_printf("[%d]\n", i);
330fa9e406ahrens				mdb_inc_indent(NVPAIR_VALUE_INDENT);
331fa9e406ahrens				if (mdb_pwalk_dcmd("nvpair", "nvpair", argc,
332fa9e406ahrens				    argv, (uintptr_t)*nl) != DCMD_OK)
333fa9e406ahrens					return (DCMD_ERR);
334fa9e406ahrens				mdb_dec_indent(NVPAIR_VALUE_INDENT);
335fa9e406ahrens			}
336fa9e406ahrens		} else {
337fa9e406ahrens			if (!quiet) {
338fa9e406ahrens				mdb_inc_indent(NVPAIR_VALUE_INDENT);
339fa9e406ahrens				mdb_printf("value");
340fa9e406ahrens			}
341fa9e406ahrens			mdb_printf("=");
342fa9e406ahrens			for (i = 0; i < nelem; i++,
343fa9e406ahrens			    data += sizeof (nvlist_t *)) {
344fa9e406ahrens				nvlist_t **nl = (nvlist_t **)(void *)data;
345fa9e406ahrens				mdb_printf("%c%p", " "[i == 0], *nl);
346fa9e406ahrens			}
347fa9e406ahrens			mdb_printf("\n");
348fa9e406ahrens			if (!quiet)
349fa9e406ahrens				mdb_dec_indent(NVPAIR_VALUE_INDENT);
3507c478bdstevel@tonic-gate		}
3517c478bdstevel@tonic-gate		return (DCMD_OK);
3527c478bdstevel@tonic-gate	}
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gate	/* if it's a string array, skip the index pointers */
3557c478bdstevel@tonic-gate	if (type == DATA_TYPE_STRING_ARRAY)
3567c478bdstevel@tonic-gate		data += (sizeof (int64_t) * nelem);
3577c478bdstevel@tonic-gate
3587c478bdstevel@tonic-gate	/* if the type is unknown, treat the data as a byte array */
3597c478bdstevel@tonic-gate	if (type_name == NULL) {
3607c478bdstevel@tonic-gate		elem_size = 1;
3617c478bdstevel@tonic-gate		nelem = data_end - data;
3627c478bdstevel@tonic-gate	}
3637c478bdstevel@tonic-gate
3647c478bdstevel@tonic-gate	/*
3657c478bdstevel@tonic-gate	 * if the type is of strings, make sure they are printable
3667c478bdstevel@tonic-gate	 * otherwise print them out as byte arrays
3677c478bdstevel@tonic-gate	 */
3687c478bdstevel@tonic-gate	if (elem_size == 0) {
3697c478bdstevel@tonic-gate		int32_t	count = 0;
3707c478bdstevel@tonic-gate
3717c478bdstevel@tonic-gate		i = 0;
3727c478bdstevel@tonic-gate		while ((&data[i] < data_end) && (count < nelem)) {
3737c478bdstevel@tonic-gate			if (data[i] == '\0')
3747c478bdstevel@tonic-gate				count++;
3757c478bdstevel@tonic-gate			else if (!isprint(data[i]))
3767c478bdstevel@tonic-gate				break;
3777c478bdstevel@tonic-gate			i++;
3787c478bdstevel@tonic-gate		}
3797c478bdstevel@tonic-gate		if (count != nelem) {
3807c478bdstevel@tonic-gate			/* there is unprintable data, output as byte array */
3817c478bdstevel@tonic-gate			elem_size = 1;
3827c478bdstevel@tonic-gate			nelem =  data_end - data;
3837c478bdstevel@tonic-gate		}
3847c478bdstevel@tonic-gate	}
3857c478bdstevel@tonic-gate
386fa9e406ahrens	if (!quiet) {
387fa9e406ahrens		mdb_inc_indent(NVPAIR_VALUE_INDENT);
388fa9e406ahrens		mdb_printf("value=");
389fa9e406ahrens	} else {
390fa9e406ahrens		mdb_printf("=");
391fa9e406ahrens	}
3927c478bdstevel@tonic-gate	nvpair_print_value(data, elem_size, nelem, type);
393fa9e406ahrens	if (!quiet)
394fa9e406ahrens		mdb_dec_indent(NVPAIR_VALUE_INDENT);
3957c478bdstevel@tonic-gate
3967c478bdstevel@tonic-gate	return (DCMD_OK);
3977c478bdstevel@tonic-gate}
398