/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/nvpair_impl.h>
#include <ctype.h>
#include <mdb/mdb_modapi.h>
#include "nvpair.h"
#define NELEM(a) (sizeof (a) / sizeof ((a)[0]))
/*
* nvpair walker
*/
int
{
mdb_warn("nvpair does not support global walks\n");
return (WALK_ERR);
}
return (WALK_ERR);
}
return (WALK_ERR);
}
return (WALK_NEXT);
}
int
{
int status;
return (WALK_DONE);
return (WALK_ERR);
}
return (status);
}
/*
* ::nvlist [-v]
*
* Print out an entire nvlist. This is shorthand for '::walk nvpair |
* ::nvpair -rq'. The '-v' option invokes '::nvpair' without the "-q" option.
*/
/*ARGSUSED*/
int
{
mdb_arg_t v;
if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
return (DCMD_USAGE);
v.a_type = MDB_TYPE_STRING;
if (verbose)
else
}
/*
* ::nvpair [-rq]
*
* -r Recursively print any nvlist elements
* -q Quiet mode; print members only as "name=value"
*
* Prints out a single nvpair. By default, all information is printed. When
* given the '-q' option, the type of elements is hidden, and elements are
* instead printed simply as 'name=value'.
*/
typedef struct {
int elem_size;
char *type_name;
{ DATA_TYPE_STRING, 0, "string" },
{ DATA_TYPE_NVLIST, 0, "nvpair_list" },
{ DATA_TYPE_STRING_ARRAY, 0, "string_array" },
{ DATA_TYPE_NVLIST_ARRAY, 0, "nvpair list_array" }
};
static void
{
int32_t i;
if (elem_size == 0) {
char *p = data;
/* print out all the strings */
for (i = 0; i < nelem - 1; i++) {
mdb_printf("'%s' + ", p);
p += strlen(p) + 1;
}
mdb_printf("'%s'", p);
} else if (type == DATA_TYPE_BOOLEAN_VALUE ||
type == DATA_TYPE_BOOLEAN_ARRAY) {
/* LINTED - pointer alignment */
for (i = 0; i < nelem; i++) {
if (i > 0)
mdb_printf(".");
mdb_printf("%d", p[i]);
}
} else {
unsigned char *p = (unsigned char *)data;
/*
* if elem_size != 0 then we are printing out an array
* where each element is of elem_size
*/
mdb_nhconvert(p, p, elem_size);
mdb_printf("%02x", *p);
for (i = 1; i < size; i++) {
if ((i % elem_size) == 0) {
mdb_nhconvert(&p[i], &p[i], elem_size);
mdb_printf(".");
}
mdb_printf("%02x", p[i]);
}
}
mdb_printf("\n");
}
/*ARGSUSED*/
int
{
if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
return (DCMD_USAGE);
/* read in the nvpair header so we can get the size */
return (DCMD_ERR);
}
if (size == 0) {
return (DCMD_OK);
}
/* read in the entire nvpair */
return (DCMD_ERR);
}
/* lookup type decoding information for this nvpair */
for (i = 0; i < NELEM(nvpair_info); i++) {
break;
}
}
if (quiet) {
} else {
/* print out the first line of nvpair info */
} else {
/*
* If the nvpair type is unknown we print the type
* number
*/
}
}
/* if there is no data and the type is known then we're done */
if (quiet)
mdb_printf("(unknown)\n");
return (DCMD_OK);
}
/* get pointers to the data to print out */
/*
* The value of the name-value pair for a single embedded
* list is the nvlist_t structure for the embedded list.
* So we print that address out (computed as an offset from
* the nvpair address we received as addr).
*
* The value of the name-value pair for an array of embedded
* lists is nelem pointers to nvlist_t structures followed
* by the structures themselves. We display the list
* of pointers as the pair's value.
*/
if (type == DATA_TYPE_NVLIST) {
if (recurse) {
if (quiet)
mdb_printf("\n");
return (DCMD_ERR);
} else {
if (!quiet) {
mdb_printf("value", p);
}
mdb_printf("=%p\n", p);
if (!quiet)
}
return (DCMD_OK);
} else if (type == DATA_TYPE_NVLIST_ARRAY) {
if (recurse) {
for (i = 0; i < nelem; i++,
if (quiet && i != 0)
mdb_printf("[%d]\n", i);
return (DCMD_ERR);
}
} else {
if (!quiet) {
mdb_printf("value");
}
mdb_printf("=");
for (i = 0; i < nelem; i++,
}
mdb_printf("\n");
if (!quiet)
}
return (DCMD_OK);
}
/* if it's a string array, skip the index pointers */
if (type == DATA_TYPE_STRING_ARRAY)
/* if the type is unknown, treat the data as a byte array */
elem_size = 1;
}
/*
* if the type is of strings, make sure they are printable
* otherwise print them out as byte arrays
*/
if (elem_size == 0) {
i = 0;
if (data[i] == '\0')
count++;
break;
i++;
}
/* there is unprintable data, output as byte array */
elem_size = 1;
}
}
if (!quiet) {
mdb_printf("value=");
} else {
mdb_printf("=");
}
if (!quiet)
return (DCMD_OK);
}