/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
* Copyright 2015 Joyent, Inc.
* Copyright (c) 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_target.h>
#include <mdb/mdb_argvec.h>
#include <mdb/mdb_string.h>
#include <mdb/mdb_stdlib.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb_ctf_impl.h>
#include <sys/isa_defs.h>
#include <sys/sysmacros.h>
#include <strings.h>
#include <libctf.h>
#include <ctype.h>
typedef struct holeinfo {
} holeinfo_t;
typedef struct printarg {
} printarg_t;
#define IS_CHAR(e) \
#define MEMBER_DELIM_DONE 0
typedef int printarg_f(const char *, const char *,
void *);
static void print_close_sou(printarg_t *, int);
/*
* Given an address, look up the symbol ID of the specified symbol in its
* containing module. We only support lookups for exact matches.
*/
static const char *
{
const char *p;
return (NULL); /* address does not exactly match a symbol */
return (NULL);
return (p);
}
return (NULL); /* address does not fall within a mapping */
return (NULL);
return (name);
}
/*
* This lets dcmds be a little fancy with their processing of type arguments
* while still treating them more or less as a single argument.
* For example, if a command is invokes like this:
*
* ::<dcmd> proc_t ...
*
* this function will just copy "proc_t" into the provided buffer. If the
* command is instead invoked like this:
*
* ::<dcmd> struct proc ...
*
* this function will place the string "struct proc" into the provided buffer
* and increment the caller's argv and argc. This allows the caller to still
* treat the type argument logically as it would an other atomic argument.
*/
int
{
return (DCMD_USAGE);
if (argc <= 1) {
return (DCMD_ABORT);
}
return (DCMD_USAGE);
} else {
}
return (0);
}
/*ARGSUSED*/
int
{
int ret;
if (flags & DCMD_ADDRSPEC)
return (DCMD_USAGE);
return (ret);
if (argc != 1)
return (DCMD_USAGE);
return (DCMD_ERR);
}
if (flags & DCMD_PIPE_OUT)
else
return (DCMD_OK);
}
int
{
int ret;
return (0);
return (ret);
if (argc == 1)
return (0);
}
/*ARGSUSED*/
int
{
const char *member;
int ret;
if (flags & DCMD_ADDRSPEC)
return (DCMD_USAGE);
return (ret);
return (DCMD_USAGE);
return (DCMD_ERR);
}
return (DCMD_ERR);
}
if (flags & DCMD_PIPE_OUT) {
mdb_warn("member %s of type %s is not byte-aligned\n",
return (DCMD_ERR);
}
return (DCMD_OK);
}
mdb_printf("offsetof (%s, %s) = %#lr",
mdb_printf("\n");
return (DCMD_OK);
}
/*ARGSUSED*/
static int
{
/*
* This function is called with every name in the enum. We make
* "arg" be the common prefix, if any.
*/
if (str[0] == 0) {
return (1);
return (0);
}
if (*str == 0) {
str--; /* don't smother a name completely */
}
break;
}
name++;
str++;
}
*str = 0;
}
struct enum_p2_info {
};
static int
{
return (1); /* non-power-of-2; abort processing */
return (0); /* already seen this value */
}
if (bit == 0)
else
} else {
}
}
/* skip the common prefix as necessary */
}
return (0);
}
static int
{
}
static int
{
prefix[0] = 0;
return (-1);
/* push out any final value, with a | if we missed anything */
if (missed != 0)
}
}
return (0);
}
struct enum_cbinfo {
};
static void
{
(void) mdb_inc_indent(indent);
} else {
}
(void) mdb_dec_indent(indent);
mdb_printf("\n");
} else {
}
}
static int
{
if (flags & E_SEARCH_STRING) {
return (0);
} else if (flags & E_SEARCH_VALUE) {
return (0);
}
return (0);
}
void
enum_help(void)
{
mdb_printf("%s",
"Without an address and name, print all values for the enumeration \"enum\".\n"
"With an address, look up a particular value in \"enum\". With a name, look\n"
"up a particular name in \"enum\".\n");
(void) mdb_dec_indent(2);
mdb_printf("\n%<b>OPTIONS%</b>\n");
(void) mdb_inc_indent(2);
mdb_printf("%s",
" -e remove common prefixes from enum names\n"
" -x report enum values in hexadecimal\n");
}
/*ARGSUSED*/
int
{
int i;
NULL);
argc -= i;
argv += i;
return (i);
/*
* Check as an enumeration tag first, and fall back
* to checking for a typedef. Yes, this means that
* anonymous enumerations whose typedefs conflict with
* an enum tag can't be accessed. Don't do that.
*/
return (DCMD_ERR);
}
} else {
return (DCMD_ERR);
}
}
/* resolve it, and make sure we're looking at an enumeration */
return (DCMD_ERR);
}
return (DCMD_ERR);
}
if (argc > 2)
return (DCMD_USAGE);
if (argc == 2) {
if (flags & DCMD_ADDRSPEC) {
mdb_warn("may only specify one of: name, address\n");
return (DCMD_USAGE);
}
} else {
return (DCMD_USAGE);
}
}
if (flags & DCMD_ADDRSPEC) {
search = mdb_get_dot();
}
mdb_warn("value '%lld' out of enumeration range\n",
search);
}
}
if (isp2)
else
}
/* if the enum is a power-of-two one, process it that way */
return (DCMD_OK);
}
prefix[0] = 0;
return (DCMD_ERR);
}
type);
else
type);
return (DCMD_ERR);
}
return (DCMD_OK);
}
static int
{
const char *p;
mdb_var_t *v;
mdb_warn("'%c' may not be used in a variable "
"name\n", *p);
return (DCMD_ABORT);
}
return (DCMD_ERR);
} else {
if (v->v_flags & MDB_NV_RDONLY) {
return (DCMD_ABORT);
}
}
/*
* If there already exists a vcb for this variable, we may be
* calling the dcmd in a loop. We only create a vcb for this
* variable on the first invocation.
*/
return (0);
}
/*ARGSUSED*/
int
{
int offset;
int ret;
return (DCMD_USAGE);
/*
* We are being given a raw offset in lieu of a type and
* member; confirm the number of arguments and argument
* type.
*/
return (DCMD_USAGE);
argv++;
argc--;
mdb_warn("offset must fall on a word boundary\n");
return (DCMD_ABORT);
}
} else {
const char *member;
int ret;
if (ret != 0)
return (ret);
argv++;
argc--;
/*
* If we make it here, we were provided a type name. We should
* only continue if we still have arguments left (e.g. member
* name and potentially a variable name).
*/
if (argc == 0)
return (DCMD_USAGE);
if (offset == -1)
return (DCMD_ABORT);
argv++;
argc--;
return (DCMD_ABORT);
}
}
/*
* If we have any unchewed arguments, a variable name must be present.
*/
if (argc == 1) {
return (DCMD_USAGE);
return (ret);
} else if (argc != 0) {
return (DCMD_USAGE);
}
a = addr;
do {
mdb_printf("%lr\n", a);
mdb_warn("failed to read next pointer from object %p",
a);
return (DCMD_ERR);
}
a = tmp;
return (DCMD_OK);
}
int
{
if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
if (argc >= 2) {
if (ret != 0)
return (ret);
return (DCMD_USAGE);
return (DCMD_ABORT);
}
else
} else {
return (DCMD_ERR);
}
return (DCMD_USAGE);
return (ret);
} else if (argc > 3) {
return (DCMD_USAGE);
}
}
return (DCMD_OK);
}
/*
* Print an integer bitfield in hexadecimal by reading the enclosing byte(s)
* and then shifting and masking the data in the lower bits of a uint64_t.
*/
static int
{
const char *format;
return (0);
return (0);
}
/*
* On big-endian machines, we need to adjust the buf pointer to refer
* to the lowest 'size' bytes in 'value', and we need shift based on
* the offset from the end of the data, not the offset of the start.
*/
#ifdef _BIG_ENDIAN
#endif
mdb_warn("failed to read %lu bytes at %llx",
return (1);
}
/*
* Offsets are counted from opposite ends on little- and
* big-endian machines.
*/
#ifdef _BIG_ENDIAN
#endif
/*
* If the bits we want do not begin on a byte boundary, shift the data
* right so that the value is in the lowest 'cte_bits' of 'value'.
*/
/*
* We default to printing signed bitfields as decimals,
* and unsigned bitfields in hexadecimal. If they specify
* hexadecimal, we treat the field as unsigned.
*/
} else {
/* sign-extend value, and print as a signed decimal */
format = "%#lld";
}
return (0);
}
/*
* Print out a character or integer value. We use some simple heuristics,
* described below, to determine the appropriate radix to use for output.
*/
static int
{
const char *const *fsp;
union {
time_t t;
ipaddr_t I;
} u;
return (0);
mdb_printf("...\n");
return (0);
}
/*
* If the size is not a power-of-two number of bytes in the range 1-8
* then we assume it is a bitfield and print it as such.
*/
mdb_printf("'");
return (1);
mdb_printf("'");
return (0);
}
mdb_warn("failed to read %lu bytes at %llx",
return (1);
}
/*
* We pretty-print some integer based types. time_t values are
* printed as a calendar date and time, and IPv4 addresses as human
* readable dotted quads.
*/
mdb_printf("%Y", u.t);
return (0);
}
mdb_printf("%I", u.I);
return (0);
}
}
/*
* The default format is hexadecimal.
*/
else
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
}
return (0);
}
/*ARGSUSED*/
static int
{
return (0);
if (mdb_ctf_type_encoding(base, &e) != 0) {
return (0);
}
}
/*
* Print out a floating point value. We only provide support for floats in
* the ANSI-C float, double, and long double formats.
*/
/*ARGSUSED*/
static int
{
#ifndef _KMDB
union {
float f;
double d;
long double ld;
} u;
return (0);
if (mdb_ctf_type_encoding(base, &e) == 0) {
if (e.cte_format == CTF_FP_SINGLE &&
sizeof (u.f), addr) != sizeof (u.f)) {
return (1);
}
} else if (e.cte_format == CTF_FP_DOUBLE &&
sizeof (u.d), addr) != sizeof (u.d)) {
return (1);
}
} else if (e.cte_format == CTF_FP_LDOUBLE &&
return (1);
}
} else {
mdb_printf("??? (unsupported FP format %u / %u bits\n",
e.cte_format, e.cte_bits);
}
} else
#else
mdb_printf("<FLOAT>");
#endif
return (0);
}
/*
* Print out a pointer value as a symbol name + offset or a hexadecimal value.
* If the pointer itself is a char *, we attempt to read a bit of the data
* referenced by the pointer and display it if it is a printable ASCII string.
*/
/*ARGSUSED*/
static int
{
return (0);
return (1);
}
return (0);
}
return (0);
}
}
return (0);
}
/*
* Print out a fixed-size array. We special-case arrays of characters
* and attempt to print them out as ASCII strings if possible. For other
* arrays, we iterate over a maximum of pa_armemlim members and call
* mdb_ctf_type_visit() again on each element to print its value.
*/
/*ARGSUSED*/
static int
{
int d, sou;
char *str;
return (0);
mdb_printf("[ ... ]");
return (0);
}
/*
* Determine the base type and size of the array's content. If this
* fails, we cannot print anything and just give up.
*/
return (0);
}
/*
* Read a few bytes and determine if the content appears to be
* printable ASCII characters. If so, read the entire array and
* attempt to display it as a string if it is printable.
*/
return (1);
}
if (strisprint(str)) {
return (0);
}
}
else
limit = r.mta_nelems;
if (limit == 0) {
mdb_printf("[ ... ]");
return (0);
}
if (sou) {
mdb_printf("[\n");
} else {
mdb_printf("[ ");
}
if (limit < r.mta_nelems)
else
}
mdb_warn("failed to print array data");
return (1);
}
}
if (sou) {
print_close_sou(&pa, d);
if (limit < r.mta_nelems) {
mdb_printf("%*s... ]",
} else {
mdb_printf("%*s]",
}
}
/* copy the hole array info, since it may have been grown */
return (0);
}
/*
* Print out a struct or union header. We need only print the open brace
* because mdb_ctf_type_visit() itself will automatically recurse through
* all members of the given struct or union.
*/
/*ARGSUSED*/
static int
{
/*
* We have pretty-printing for some structures where displaying
* structure contents has no value.
*/
mdb_warn("failed to read %s pointer at %llx",
return (1);
}
/*
* Don't print anything further down in the
* structure.
*/
return (0);
}
mdb_warn("failed to read %s pointer at %llx",
return (1);
}
return (0);
}
}
mdb_printf("{ ... }");
else
mdb_printf("{");
return (0);
}
/*
* Print an enum value. We attempt to convert the value to the corresponding
* enum name and print that if possible.
*/
/*ARGSUSED*/
static int
{
const char *ename;
int value;
if (!(flags & PA_SHOWVAL))
return (0);
return (1);
}
else
(void) mdb_inc_indent(8);
mdb_printf(" (");
ename = "???";
}
}
mdb_printf(")");
(void) mdb_dec_indent(8);
return (0);
}
/*
* This will only get called if the structure isn't found in any available CTF
* data.
*/
/*ARGSUSED*/
static int
{
mdb_printf("; ");
else
mdb_printf("<forward declaration of unknown type>");
return (0);
}
static void
{
int bitfield =
size > 8 ||
/*
* The hole is larger than the largest integer type. To
* handle this, we split up the hole at 8-byte-aligned
* boundaries, recursing to print each subsection. For
* normal C structures, we'll loop at most twice.
*/
}
return;
}
if (bitfield)
else
else
mdb_printf("%llx.%lx ",
}
/*
* We fake up a ctf_encoding_t, and use print_int_val() to print
* the value. Holes are always processed as unsigned integers.
*/
bzero(&e, sizeof (e));
e.cte_format = 0;
e.cte_offset = 0;
else
}
/*
* The print_close_sou() function is called for each structure or union
* which has been completed. For structures, we detect and print any holes
* before printing the closing brace.
*/
static void
{
}
/* if the struct is an array element, print a comma after the } */
}
print_int, /* CTF_K_INTEGER */
print_float, /* CTF_K_FLOAT */
print_ptr, /* CTF_K_POINTER */
print_array, /* CTF_K_ARRAY */
print_ptr, /* CTF_K_FUNCTION */
print_sou, /* CTF_K_STRUCT */
print_sou, /* CTF_K_UNION */
print_enum, /* CTF_K_ENUM */
print_tag /* CTF_K_FORWARD */
};
/*
* The elt_print function is used as the mdb_ctf_type_visit callback. For
* each element, we print an appropriate name prefix and then call the
* print subroutine for this type class in the array above.
*/
static int
{
if (d < pap->pa_nooutdepth)
print_close_sou(pap, d);
}
/*
* Reset pa_nooutdepth if we've come back out of the structure we
* didn't want to print.
*/
return (0);
if (!mdb_ctf_type_valid(base) ||
return (-1); /* errno is set for us */
/*
* If basetype is different and informative, concatenate
* <<basetype>> (or <<baset...>> if it doesn't fit)
*
* We just use the end of the buffer to store the type name, and
* only connect it up if that's necessary.
*/
char *basetype;
(void) strlcpy(
}
}
/*
* grow the hole array, if necessary
*/
}
/* compute the next expected offset */
if (kind == CTF_K_INTEGER &&
mdb_ctf_type_encoding(base, &e) == 0)
else {
/* something bad happened, disable hole checking */
}
if (IS_COMPOSITE(kind)) {
hole++;
}
}
else
mdb_printf("%llx.%lx ",
}
/*
* We want to avoid printing a trailing space when
* dealing with pointers in a structure, so we end
* up with:
*
* label_t *t_onfault = 0
*
* If depth is zero, always print the trailing space unless
* we also have a prefix.
*/
mdb_printf(" ");
}
}
if (mdb_ctf_type_encoding(base, &e) == 0) {
size > 8 ||
}
}
if (depth != 0 ||
mdb_warn("unknown ctf for %s type %s kind %d\n",
return (-1);
}
if (rc != 0)
else
return (rc);
}
/*
* Special semantics for pipelines.
*/
static int
{
int enum_value;
union {
} u;
mdb_warn("could not resolve type");
return (-1);
}
/*
* If the user gives -a, then always print out the address of the
* member.
*/
return (0);
}
switch (mdb_ctf_type_kind(base)) {
case CTF_K_POINTER:
return (-1);
}
break;
case CTF_K_ENUM:
return (-1);
}
break;
case CTF_K_INTEGER:
if (mdb_ctf_type_encoding(base, &e) != 0) {
mdb_warn("could not get type encoding\n");
return (-1);
}
/*
* For immediate values, we just print out the value.
*/
}
mdb_warn("failed to read %lu bytes at %p",
return (-1);
}
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
}
mdb_printf("\n");
break;
case CTF_K_FUNCTION:
case CTF_K_FLOAT:
case CTF_K_ARRAY:
case CTF_K_UNKNOWN:
case CTF_K_STRUCT:
case CTF_K_UNION:
case CTF_K_FORWARD:
/*
* For these types, always print the address of the member
*/
break;
default:
break;
}
return (0);
}
static int
{
switch (**strp) {
case '\0':
return (MEMBER_DELIM_DONE);
case '.':
return (MEMBER_DELIM_DOT);
case '[':
return (MEMBER_DELIM_LBR);
case '-':
if (**strp == '>') {
return (MEMBER_DELIM_PTR);
}
/*FALLTHROUGH*/
default:
return (MEMBER_DELIM_ERR);
}
}
static int
{
if (size == sizeof (mdb_tgt_addr_t)) {
return (-1);
}
} else {
return (-1);
}
}
/*
* We've dereferenced at least once, we must be on the real
* target. If we were in the immediate target, reset to the real
* target; it's reset as needed when we return to the print
* routines.
*/
return (0);
}
static int
{
int delim;
char *end;
int kind;
/*
* id always has the unresolved type for printing error messages
* that include the type; rid always has the resolved type for
* use in mdb_ctf_* calls. It is possible for this command to fail,
* however, if the resolved type is in the parent and it is currently
* unavailable. Note that we also can't print out the name of the
* type, since that would also rely on looking up the resolved name.
*/
mdb_warn("failed to resolve type");
return (-1);
}
/*
* If the user fails to specify an initial delimiter, guess -> for
* pointer types and . for non-pointer types.
*/
if (delim == MEMBER_DELIM_ERR)
*last_deref = FALSE;
while (delim != MEMBER_DELIM_DONE) {
switch (delim) {
case MEMBER_DELIM_PTR:
if (kind != CTF_K_POINTER) {
mdb_warn("%s is not a pointer type\n",
return (-1);
}
return (-1);
off = 0;
break;
case MEMBER_DELIM_DOT:
mdb_warn("%s is not a struct or union type\n",
return (-1);
}
break;
case MEMBER_DELIM_LBR:
mdb_warn("no trailing ']'\n");
return (-1);
}
start);
switch (mdb_ctf_type_kind(rid)) {
case CTF_K_POINTER:
return (-1);
if (size <= 0) {
mdb_warn("cannot dereference void "
"type\n");
return (-1);
}
off = 0;
*last_deref = TRUE;
break;
case CTF_K_ARRAY:
mdb_warn("index %r is outside of "
"array bounds [0 .. %r]\n",
}
if (size <= 0) {
mdb_warn("cannot dereference void "
"type\n");
return (-1);
}
off = 0;
break;
default:
mdb_warn("cannot index into non-array, "
"non-pointer type\n");
return (-1);
}
continue;
case MEMBER_DELIM_ERR:
default:
return (-1);
}
*last_deref = FALSE;
/*
* Find the end of the member name; assume that a member
* name is at least one character long.
*/
continue;
return (-1);
}
}
return (0);
}
static int
{
int ret = 0;
return (0);
return (ret);
/*
* This is the reason that tab completion was created. We're going to go
* along and walk the delimiters until we find something a member that
* we don't recognize, at which point we'll try and tab complete it.
* Note that ::print takes multiple args, so this is going to operate on
* whatever the last arg that we have is.
*/
return (1);
/*
* If we hit the case where we actually have no delimiters, than we need
* to make sure that we properly set up the fields the loops would.
*/
if (delim == MEMBER_DELIM_DONE)
while (delim != MEMBER_DELIM_DONE) {
switch (delim) {
case MEMBER_DELIM_PTR:
if (kind != CTF_K_POINTER)
return (1);
break;
case MEMBER_DELIM_DOT:
return (1);
break;
case MEMBER_DELIM_LBR:
/*
* We're not going to try and tab complete the indexes
* here. So for now, punt on it. Also, we're not going
* to try and validate you're within the bounds, just
* that you get the type you asked for.
*/
return (1);
switch (mdb_ctf_type_kind(rid)) {
case CTF_K_POINTER:
break;
case CTF_K_ARRAY:
break;
default:
return (1);
}
break;
case MEMBER_DELIM_ERR:
default:
break;
}
continue;
/*
* We are going to try to resolve this name as a member. There
* are a few two different questions that we need to answer. The
* first is do we recognize this member. The second is are we at
* the end of the string. If we encounter a member that we don't
* recognize before the end, then we have to error out and can't
* complete it. But if there are no more delimiters then we can
* try and complete it.
*/
if (delim != MEMBER_DELIM_DONE)
return (1);
continue;
} else if (ret != 0)
return (1);
if (delim == MEMBER_DELIM_DONE)
member));
}
/*
* If we've reached here, then we need to try and tab complete the last
* field, which is currently member, based on the ctf type id that we
* already have in rid.
*/
}
int
{
int i, dummy;
/*
* This getopts is only here to make the tab completion work better when
* including options in the ::print arguments. None of the values should
* be used. This should only be updated with additional arguments, if
* they are added to cmd_print.
*/
NULL);
argc -= i;
argv += i;
}
/*
* Recursively descend a print a given data structure. We create a struct of
* the relevant print arguments and then call mdb_ctf_type_visit() to do the
* traversal, using elt_print() as the callback for each element.
*/
/*ARGSUSED*/
int
{
int d, i;
/*
* If a new option is added, make sure the getopts above in
* cmd_print_tab is also updated.
*/
NULL);
uflags |= PA_SHOWNAME;
mdb_warn("-p and -i options are incompatible\n");
return (DCMD_ERR);
}
argc -= i;
argv += i;
int ret;
return (DCMD_USAGE);
sizeof (s_name))) != 0)
return (ret);
return (DCMD_ABORT);
}
} else {
argc--;
argv++;
}
return (DCMD_USAGE);
return (DCMD_ERR);
return (DCMD_ERR);
}
else
if (opt_i) {
0, 2, vargv);
}
if (opt_c != MDB_ARR_NOLIMIT)
if (opt_C)
if (opt_l != MDB_ARR_NOLIMIT)
if (opt_L)
if (argc > 0) {
for (i = 0; i < argc; i++) {
int last_deref;
int kind;
&off, &last_deref) != 0) {
err = DCMD_ABORT;
goto out;
}
/*
* If the member string ends with a "[0]"
* (last_deref * is true) and the type is a
* structure or union, * print "->" rather
* than "[0]." in elt_print.
*/
char *end;
"%s", member);
*end = '\0';
} else {
}
} else {
err = DCMD_ABORT;
goto out;
}
}
if (flags & DCMD_PIPE_OUT) {
mdb_warn("failed to print type");
goto out;
}
} else if (off != 0) {
&pa) != 0) {
mdb_warn("failed to print type");
goto out;
}
} else {
&pa) == -1) {
mdb_warn("failed to print type");
goto out;
}
print_close_sou(&pa, d);
}
}
} else if (flags & DCMD_PIPE_OUT) {
mdb_warn("failed to print type");
goto out;
}
} else {
mdb_warn("failed to print type");
goto out;
}
print_close_sou(&pa, d);
}
out:
return (err);
}
void
print_help(void)
{
"-a show address of object\n"
"-C unlimit the length of character arrays\n"
"-c limit limit the length of character arrays\n"
"-d output values in decimal\n"
"-h print holes in structures\n"
"-i interpret address as data of the given type\n"
"-L unlimit the length of standard arrays\n"
"-l limit limit the length of standard arrays\n"
"-n don't print pointers as symbol offsets\n"
"-p interpret address as a physical memory address\n"
"-s depth limit the recursion depth\n"
"-T show type and <<base type>> of object\n"
"-t show type of object\n"
"-x output values in hexadecimal\n"
"\n"
"type may be omitted if the C type of addr can be inferred.\n"
"\n"
"Members may be specified with standard C syntax using the\n"
"array indexing operator \"[index]\", structure member\n"
"operator \".\", or structure pointer operator \"->\".\n"
"\n"
"Offsets must use the $[ expression ] syntax\n");
}
static int
{
union {
} u;
mdb_warn("could not resolve type");
return (DCMD_ABORT);
}
switch (mdb_ctf_type_kind(base)) {
case CTF_K_ENUM:
e.cte_format = CTF_INT_SIGNED;
e.cte_offset = 0;
break;
case CTF_K_INTEGER:
if (mdb_ctf_type_encoding(base, &e) != 0) {
mdb_warn("could not get type encoding");
return (DCMD_ABORT);
}
break;
default:
mdb_warn("expected integer type\n");
return (DCMD_ABORT);
}
if (sign)
/*
* Check to see if our life has been complicated by the presence of
* a bitfield. If it has, we will print it using logic that is only
* slightly different than that found in print_bitfield(), above. (In
* particular, see the comments there for an explanation of the
* endianness differences in this code.)
*/
/*
* Round our size up one byte.
*/
return (DCMD_ABORT);
}
#ifdef _BIG_ENDIAN
#endif
return (DCMD_ERR);
}
#ifdef _BIG_ENDIAN
#endif
/*
* If we have a bit offset within the byte, shift it down.
*/
if (sign) {
}
return (0);
}
return (DCMD_ERR);
}
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
}
return (0);
}
static int
{
}
static int
{
}
/*ARGSUSED*/
static int
{
mdb_warn("could not resolve type\n");
return (DCMD_ABORT);
}
mdb_ctf_type_encoding(base, &e) != 0 ||
mdb_warn("expected 32-bit integer type\n");
return (DCMD_ABORT);
}
return (DCMD_ERR);
}
return (0);
}
/*ARGSUSED*/
static int
{
mdb_warn("could not resolve type\n");
return (DCMD_ABORT);
}
mdb_warn("expected pointer type\n");
return (DCMD_ABORT);
}
return (DCMD_ERR);
}
return (0);
}
/*ARGSUSED*/
static int
{
mdb_warn("could not resolve type");
return (DCMD_ABORT);
}
return (DCMD_ERR);
}
return (DCMD_ERR);
}
return (0);
}
const char *strval;
int value;
return (DCMD_ERR);
}
} else {
}
return (0);
}
mdb_warn("exepected pointer or array type\n");
return (DCMD_ABORT);
}
mdb_warn("can't determine array type");
return (DCMD_ABORT);
}
if (size != 1) {
mdb_warn("string format specifier requires "
"an array of characters\n");
return (DCMD_ABORT);
}
return (DCMD_ERR);
}
return (0);
}
/*ARGSUSED*/
static int
{
mdb_warn("could not resolve in6_addr_t type\n");
return (DCMD_ABORT);
}
mdb_warn("could not resolve type\n");
return (DCMD_ABORT);
}
mdb_warn("could not resolve in6_addr_t type\n");
return (DCMD_ABORT);
}
mdb_warn("requires argument of type in6_addr_t\n");
return (DCMD_ABORT);
}
return (DCMD_ERR);
}
return (0);
}
/*
* To validate the format string specified to ::printf, we run the format
* string through a very simple state machine that restricts us to a subset
* of mdb_printf() functionality.
*/
enum {
};
int
{
int ii;
char *f;
/*
* If argc doesn't have more than what should be the format string,
* ignore it.
*/
if (argc <= 1)
return (0);
/*
* Because we aren't leveraging the lex and yacc engine, we have to
* manually walk the arguments to find both the first and last
*/
if (f == NULL)
return (0);
if (f != NULL) {
ii = 0;
} else {
continue;
if (f != NULL)
break;
}
/* Never found */
return (0);
}
ii++;
}
int
{
if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
mdb_warn("expected a format string\n");
return (DCMD_USAGE);
}
/*
* Our first argument is a format string; rip it apart and run it
* through our state machine to validate that our input is within the
* subset of mdb_printf() format strings that we allow.
*/
/*
* 'dest' must be large enough to hold a copy of the format string,
* plus a NUL and up to 2 additional characters for each conversion
* in the format string. This gives us a bloat factor of 5/2 ~= 3.
* e.g. "%d" (strlen of 2) --> "%lld\0" (need 5 bytes)
*/
for (i = 0; fmt[i] != '\0'; i++) {
switch (state) {
case PRINTF_NOFMT:
break;
case PRINTF_PERC:
f == '?' ? PRINTF_QUES :
break;
case PRINTF_LEFT:
break;
case PRINTF_WIDTH:
break;
case PRINTF_QUES:
state = PRINTF_FMT;
break;
}
if (state != PRINTF_FMT)
continue;
dest--;
/*
* Now check that we have one of our valid format characters.
*/
switch (f) {
case 'a':
case 'A':
case 'p':
break;
case 'd':
case 'q':
case 'R':
*dest++ = 'l';
*dest++ = 'l';
break;
case 'I':
break;
case 'N':
break;
case 'H':
case 'o':
case 'r':
case 'u':
case 'x':
case 'X':
*dest++ = 'l';
*dest++ = 'l';
break;
case 's':
break;
case 'Y':
break;
default:
mdb_warn("illegal format string at or near "
"'%c' (position %d)\n", f, i + 1);
return (DCMD_ABORT);
}
*dest++ = f;
*dest++ = '\0';
}
argc--;
argv++;
/*
* Now we expect a type name.
*/
return (ret);
argv++;
argc--;
return (DCMD_ABORT);
}
if (argc == 0) {
mdb_warn("at least one member must be specified\n");
return (DCMD_USAGE);
}
mdb_warn("%s format specifiers (found %d, expected %d)\n",
return (DCMD_ABORT);
}
for (i = 0; i < argc; i++) {
int ignored;
mdb_warn("expected only type member arguments\n");
return (DCMD_ABORT);
}
/*
* We allow "." to be specified to denote the current
* value of dot.
*/
funcs[i] != printf_int) {
mdb_warn("expected integer or pointer format "
"specifier for '.'\n");
return (DCMD_ABORT);
}
continue;
}
return (DCMD_ABORT);
return (ret);
}
}
return (DCMD_OK);
}
static char _mdb_printf_help[] =
"The format string argument is a printf(3C)-like format string that is a\n"
"subset of the format strings supported by mdb_printf(). The type argument\n"
"is the name of a type to be used to interpret the memory referenced by dot.\n"
"The member should either be a field in the specified structure, or the\n"
"special member '.', denoting the value of dot (and treated as a pointer).\n"
"The number of members must match the number of format specifiers in the\n"
"format string.\n"
"\n"
"The following format specifiers are recognized by ::printf:\n"
"\n"
" %% Prints the '%' symbol.\n"
" %a Prints the member in symbolic form.\n"
" %d Prints the member as a decimal integer. If the member is a signed\n"
" integer type, the output will be signed.\n"
" %H Prints the member as a human-readable size.\n"
" %I Prints the member as an IPv4 address (must be 32-bit integer type).\n"
" %N Prints the member as an IPv6 address (must be of type in6_addr_t).\n"
" %o Prints the member as an unsigned octal integer.\n"
" %p Prints the member as a pointer, in hexadecimal.\n"
" %q Prints the member in signed octal. Honk if you ever use this!\n"
" %r Prints the member as an unsigned value in the current output radix.\n"
" %R Prints the member as a signed value in the current output radix.\n"
" %s Prints the member as a string (requires a pointer or an array of\n"
" characters).\n"
" %u Prints the member as an unsigned decimal integer.\n"
" %x Prints the member in hexadecimal.\n"
" %X Prints the member in hexadecimal, using the characters A-F as the\n"
" digits for the values 10-15.\n"
" %Y Prints the member as a time_t as the string "
"'year month day HH:MM:SS'.\n"
"\n"
"The following field width specifiers are recognized by ::printf:\n"
"\n"
" %n Field width is set to the specified decimal value.\n"
" %? Field width is set to the maximum width of a hexadecimal pointer\n"
" value. This is 8 in an ILP32 environment, and 16 in an LP64\n"
" environment.\n"
"\n"
"The following flag specifers are recognized by ::printf:\n"
"\n"
" %- Left-justify the output within the specified field width. If the\n"
" width of the output is less than the specified field width, the\n"
" output will be padded with blanks on the right-hand side. Without\n"
" %-, values are right-justified by default.\n"
"\n"
" %0 Zero-fill the output field if the output is right-justified and the\n"
" width of the output is less than the specified field width. Without\n"
" %0, right-justified values are prepended with blanks in order to\n"
" fill the field.\n"
"\n"
"Examples: \n"
"\n"
" ::walk proc | "
"::printf \"%-6d %s\\n\" proc_t p_pidp->pid_id p_user.u_psargs\n"
" ::walk thread | "
"::printf \"%?p %3d %a\\n\" kthread_t . t_pri t_startpc\n"
" ::walk zone | "
"::printf \"%-40s %20s\\n\" zone_t zone_name zone_nodename\n"
" ::walk ire | "
"::printf \"%Y %I\\n\" ire_t ire_create_time ire_u.ire4_u.ire4_addr\n"
"\n";
void
printf_help(void)
{
}