Print this page
12364 mdb trips assertion related to autowrap


   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  28  * Copyright 2015 Joyent, Inc.
  29  * Copyright (c) 2014 Nexenta Systems, Inc. All rights reserved.
  30  */
  31 
  32 #include <mdb/mdb_modapi.h>
  33 #include <mdb/mdb_target.h>
  34 #include <mdb/mdb_argvec.h>
  35 #include <mdb/mdb_string.h>
  36 #include <mdb/mdb_stdlib.h>
  37 #include <mdb/mdb_err.h>
  38 #include <mdb/mdb_debug.h>
  39 #include <mdb/mdb_fmt.h>
  40 #include <mdb/mdb_ctf.h>
  41 #include <mdb/mdb_ctf_impl.h>
  42 #include <mdb/mdb.h>
  43 #include <mdb/mdb_tab.h>
  44 
  45 #include <sys/isa_defs.h>
  46 #include <sys/param.h>
  47 #include <sys/sysmacros.h>
  48 #include <netinet/in.h>


 914          * We default to printing signed bitfields as decimals,
 915          * and unsigned bitfields in hexadecimal.  If they specify
 916          * hexadecimal, we treat the field as unsigned.
 917          */
 918         if ((pap->pa_flags & PA_INTHEX) ||
 919             !(ep->cte_format & CTF_INT_SIGNED)) {
 920                 format = (pap->pa_flags & PA_INTDEC)? "%#llu" : "%#llx";
 921         } else {
 922                 int sshift = sizeof (value) * NBBY - ep->cte_bits;
 923 
 924                 /* sign-extend value, and print as a signed decimal */
 925                 value = ((int64_t)value << sshift) >> sshift;
 926                 format = "%#lld";
 927         }
 928         mdb_printf(format, value);
 929 
 930         return (0);
 931 }
 932 
 933 /*
























 934  * Print out a character or integer value.  We use some simple heuristics,
 935  * described below, to determine the appropriate radix to use for output.
 936  */
 937 static int
 938 print_int_val(const char *type, ctf_encoding_t *ep, ulong_t off,
 939     printarg_t *pap)
 940 {
 941         static const char *const sformat[] = { "%#d", "%#d", "%#d", "%#lld" };
 942         static const char *const uformat[] = { "%#u", "%#u", "%#u", "%#llu" };
 943         static const char *const xformat[] = { "%#x", "%#x", "%#x", "%#llx" };
 944 
 945         mdb_tgt_addr_t addr = pap->pa_addr + off / NBBY;
 946         const char *const *fsp;
 947         size_t size;
 948 
 949         union {
 950                 uint64_t i8;
 951                 uint32_t i4;
 952                 uint16_t i2;
 953                 uint8_t i1;
 954                 time_t t;
 955                 ipaddr_t I;
 956         } u;
 957 
 958         if (!(pap->pa_flags & PA_SHOWVAL))
 959                 return (0);
 960 
 961         if (ep->cte_format & CTF_INT_VARARGS) {
 962                 mdb_printf("...\n");
 963                 return (0);
 964         }
 965 
 966         /*
 967          * If the size is not a power-of-two number of bytes in the range 1-8
 968          * then we assume it is a bitfield and print it as such.
 969          */
 970         size = ep->cte_bits / NBBY;
 971         if (size > 8 || (ep->cte_bits % NBBY) != 0 || (size & (size - 1)) != 0)
 972                 return (print_bitfield(off, pap, ep));
 973 
 974         if (IS_CHAR(*ep)) {
 975                 mdb_printf("'");
 976                 if (mdb_fmt_print(pap->pa_tgt, pap->pa_as,
 977                     addr, 1, 'C') == addr)
 978                         return (1);
 979                 mdb_printf("'");
 980                 return (0);
 981         }
 982 
 983         if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, &u.i8, size, addr) != size) {
 984                 mdb_warn("failed to read %lu bytes at %llx",
 985                     (ulong_t)size, addr);
 986                 return (1);
 987         }
 988 
 989         /*
 990          * We pretty-print some integer based types.  time_t values are
 991          * printed as a calendar date and time, and IPv4 addresses as human
 992          * readable dotted quads.
 993          */
 994         if (!(pap->pa_flags & (PA_INTHEX | PA_INTDEC))) {
 995                 if (strcmp(type, "time_t") == 0 && u.t != 0) {
 996                         mdb_printf("%Y", u.t);
 997                         return (0);
 998                 }
 999                 if (strcmp(type, "ipaddr_t") == 0 ||
1000                     strcmp(type, "in_addr_t") == 0) {
1001                         mdb_printf("%I", u.I);




   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  28  * Copyright 2020 Joyent, Inc.
  29  * Copyright (c) 2014 Nexenta Systems, Inc. All rights reserved.
  30  */
  31 
  32 #include <mdb/mdb_modapi.h>
  33 #include <mdb/mdb_target.h>
  34 #include <mdb/mdb_argvec.h>
  35 #include <mdb/mdb_string.h>
  36 #include <mdb/mdb_stdlib.h>
  37 #include <mdb/mdb_err.h>
  38 #include <mdb/mdb_debug.h>
  39 #include <mdb/mdb_fmt.h>
  40 #include <mdb/mdb_ctf.h>
  41 #include <mdb/mdb_ctf_impl.h>
  42 #include <mdb/mdb.h>
  43 #include <mdb/mdb_tab.h>
  44 
  45 #include <sys/isa_defs.h>
  46 #include <sys/param.h>
  47 #include <sys/sysmacros.h>
  48 #include <netinet/in.h>


 914          * We default to printing signed bitfields as decimals,
 915          * and unsigned bitfields in hexadecimal.  If they specify
 916          * hexadecimal, we treat the field as unsigned.
 917          */
 918         if ((pap->pa_flags & PA_INTHEX) ||
 919             !(ep->cte_format & CTF_INT_SIGNED)) {
 920                 format = (pap->pa_flags & PA_INTDEC)? "%#llu" : "%#llx";
 921         } else {
 922                 int sshift = sizeof (value) * NBBY - ep->cte_bits;
 923 
 924                 /* sign-extend value, and print as a signed decimal */
 925                 value = ((int64_t)value << sshift) >> sshift;
 926                 format = "%#lld";
 927         }
 928         mdb_printf(format, value);
 929 
 930         return (0);
 931 }
 932 
 933 /*
 934  * We want to print an escaped char as e.g. '\0'. We don't use mdb_fmt_print()
 935  * as it won't get auto-wrap right here (although even now, we don't include any
 936  * trailing comma).
 937  */
 938 static int
 939 print_char_val(mdb_tgt_addr_t addr, printarg_t *pap)
 940 {
 941         char cval;
 942         char *s;
 943 
 944         if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, &cval, 1, addr) != 1)
 945                 return (1);
 946 
 947         if (mdb.m_flags & MDB_FL_ADB)
 948                 s = strchr2adb(&cval, 1);
 949         else
 950                 s = strchr2esc(&cval, 1);
 951 
 952         mdb_printf("'%s'", s);
 953         strfree(s);
 954         return (0);
 955 }
 956 
 957 /*
 958  * Print out a character or integer value.  We use some simple heuristics,
 959  * described below, to determine the appropriate radix to use for output.
 960  */
 961 static int
 962 print_int_val(const char *type, ctf_encoding_t *ep, ulong_t off,
 963     printarg_t *pap)
 964 {
 965         static const char *const sformat[] = { "%#d", "%#d", "%#d", "%#lld" };
 966         static const char *const uformat[] = { "%#u", "%#u", "%#u", "%#llu" };
 967         static const char *const xformat[] = { "%#x", "%#x", "%#x", "%#llx" };
 968 
 969         mdb_tgt_addr_t addr = pap->pa_addr + off / NBBY;
 970         const char *const *fsp;
 971         size_t size;
 972 
 973         union {
 974                 uint64_t i8;
 975                 uint32_t i4;
 976                 uint16_t i2;
 977                 uint8_t i1;
 978                 time_t t;
 979                 ipaddr_t I;
 980         } u;
 981 
 982         if (!(pap->pa_flags & PA_SHOWVAL))
 983                 return (0);
 984 
 985         if (ep->cte_format & CTF_INT_VARARGS) {
 986                 mdb_printf("...\n");
 987                 return (0);
 988         }
 989 
 990         /*
 991          * If the size is not a power-of-two number of bytes in the range 1-8
 992          * then we assume it is a bitfield and print it as such.
 993          */
 994         size = ep->cte_bits / NBBY;
 995         if (size > 8 || (ep->cte_bits % NBBY) != 0 || (size & (size - 1)) != 0)
 996                 return (print_bitfield(off, pap, ep));
 997 
 998         if (IS_CHAR(*ep))
 999                 return (print_char_val(addr, pap));






1000 
1001         if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, &u.i8, size, addr) != size) {
1002                 mdb_warn("failed to read %lu bytes at %llx",
1003                     (ulong_t)size, addr);
1004                 return (1);
1005         }
1006 
1007         /*
1008          * We pretty-print some integer based types.  time_t values are
1009          * printed as a calendar date and time, and IPv4 addresses as human
1010          * readable dotted quads.
1011          */
1012         if (!(pap->pa_flags & (PA_INTHEX | PA_INTDEC))) {
1013                 if (strcmp(type, "time_t") == 0 && u.t != 0) {
1014                         mdb_printf("%Y", u.t);
1015                         return (0);
1016                 }
1017                 if (strcmp(type, "ipaddr_t") == 0 ||
1018                     strcmp(type, "in_addr_t") == 0) {
1019                         mdb_printf("%I", u.I);