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