4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2019 Joyent, Inc.
25 * Copyright (c) 2017 by Delphix. All rights reserved.
26 */
27
28 /*
29 * Format String Decoder
30 *
31 * This file provides the core engine for converting strings of format
32 * characters into formatted output. The various format dcmds invoke the
33 * mdb_fmt_print() function below with a target, address space identifier,
34 * address, count, and format character, and it reads the required data from
35 * the target and prints the formatted output to stdout. Since nearly two
36 * thirds of the format characters can be expressed as simple printf format
37 * strings, we implement the engine using the lookup table below. Each entry
38 * provides either a pointer to a printf format string or a pointer to a
39 * function to perform special processing. For the printf case, the
40 * corresponding data size in bytes is also supplied. The printf processing
41 * code handles 1, 2, 4, and 8-byte reads into an unsigned integer container
42 * of the given size, and then simply calls mdb_iob_printf with the integer
43 * and format string. This handles all printf cases, except when unsigned
44 * promotion of an integer type in the varargs list does not perform the
716 uint_t oflags = mdb.m_flags;
717
718 union {
719 uint64_t i8;
720 uint32_t i4;
721 uint16_t i2;
722 uint8_t i1;
723 double d;
724 } u;
725
726 if (fmt < 0 || fmt > (sizeof (fmttab) / sizeof (fmttab[0]))) {
727 warn("invalid format character -- '%c'\n", fmt);
728 return (addr);
729 }
730
731 if (!(fp->f_type & FMT_NOAUTOWRAP)) {
732 /*
733 * Unless a format has explicitly opted out, we force autowrap
734 * for the duration of mdb_fmt_print().
735 */
736 mdb.m_flags |= MDB_FL_AUTOWRAP;
737 }
738
739 switch (FMT_TYPE(fp->f_type)) {
740 case FMT_FUNC:
741 funcp = (mdb_fmt_func_f *)fp->f_ptr;
742 addr = funcp(t, as, addr, cnt);
743 break;
744
745 case FMT_PRINTF:
746 switch (fp->f_size) {
747 case 1:
748 buf = &u.i1;
749 break;
750 case 2:
751 buf = &u.i2;
752 break;
753 case 4:
754 buf = &u.i4;
755 break;
756 case 8:
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2020 Joyent, Inc.
25 * Copyright (c) 2017 by Delphix. All rights reserved.
26 */
27
28 /*
29 * Format String Decoder
30 *
31 * This file provides the core engine for converting strings of format
32 * characters into formatted output. The various format dcmds invoke the
33 * mdb_fmt_print() function below with a target, address space identifier,
34 * address, count, and format character, and it reads the required data from
35 * the target and prints the formatted output to stdout. Since nearly two
36 * thirds of the format characters can be expressed as simple printf format
37 * strings, we implement the engine using the lookup table below. Each entry
38 * provides either a pointer to a printf format string or a pointer to a
39 * function to perform special processing. For the printf case, the
40 * corresponding data size in bytes is also supplied. The printf processing
41 * code handles 1, 2, 4, and 8-byte reads into an unsigned integer container
42 * of the given size, and then simply calls mdb_iob_printf with the integer
43 * and format string. This handles all printf cases, except when unsigned
44 * promotion of an integer type in the varargs list does not perform the
716 uint_t oflags = mdb.m_flags;
717
718 union {
719 uint64_t i8;
720 uint32_t i4;
721 uint16_t i2;
722 uint8_t i1;
723 double d;
724 } u;
725
726 if (fmt < 0 || fmt > (sizeof (fmttab) / sizeof (fmttab[0]))) {
727 warn("invalid format character -- '%c'\n", fmt);
728 return (addr);
729 }
730
731 if (!(fp->f_type & FMT_NOAUTOWRAP)) {
732 /*
733 * Unless a format has explicitly opted out, we force autowrap
734 * for the duration of mdb_fmt_print().
735 */
736 mdb_iob_set_autowrap(mdb.m_out);
737 }
738
739 switch (FMT_TYPE(fp->f_type)) {
740 case FMT_FUNC:
741 funcp = (mdb_fmt_func_f *)fp->f_ptr;
742 addr = funcp(t, as, addr, cnt);
743 break;
744
745 case FMT_PRINTF:
746 switch (fp->f_size) {
747 case 1:
748 buf = &u.i1;
749 break;
750 case 2:
751 buf = &u.i2;
752 break;
753 case 4:
754 buf = &u.i4;
755 break;
756 case 8:
|