diff options
-rw-r--r-- | exception_lists/copyright | 2 | ||||
-rw-r--r-- | usr/src/Makefile.master | 5 | ||||
-rw-r--r-- | usr/src/cmd/Makefile.ctf | 19 | ||||
-rw-r--r-- | usr/src/cmd/mdb/common/mdb/mdb_print.c | 24 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-test-utiltest.p5m | 3 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/mdb/Makefile | 2 | ||||
-rwxr-xr-x | usr/src/test/util-tests/tests/mdb/mdbtest | 6 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh | 30 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh.out | 23 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/mdb/progs/Makefile | 5 | ||||
-rw-r--r-- | usr/src/test/util-tests/tests/mdb/progs/bitfields.c | 74 |
11 files changed, 182 insertions, 11 deletions
diff --git a/exception_lists/copyright b/exception_lists/copyright index c3fa203a05..61c4f199bc 100644 --- a/exception_lists/copyright +++ b/exception_lists/copyright @@ -579,4 +579,4 @@ usr/src/uts/i86pc/io/viona/THIRDPARTYLICENSE.descrip # mdb. # usr/src/test/util-tests/tests/mdb/*/*.mdb -usr/src/test/util-tests/tests/mdb/*/*.mdb.out +usr/src/test/util-tests/tests/mdb/*/*.out diff --git a/usr/src/Makefile.master b/usr/src/Makefile.master index 914965a13e..274a11f0a9 100644 --- a/usr/src/Makefile.master +++ b/usr/src/Makefile.master @@ -1130,6 +1130,7 @@ $(RELEASE_BUILD)PROCESS_COMMENT= @?${MCS} -d -a $(RELEASE_CM) STRIP_STABS= $(STRIP) -x $@ $(SRCDBGBLD)STRIP_STABS= : +PROCESS_CTF= : POST_PROCESS_O= POST_PROCESS_S_O= @@ -1137,8 +1138,8 @@ POST_PROCESS_CC_O= POST_PROCESS_A= POST_PROCESS_SO= $(PROCESS_COMMENT) $@ ; $(STRIP_STABS) ; \ $(ELFSIGN_OBJECT) -POST_PROCESS= $(PROCESS_COMMENT) $@ ; $(STRIP_STABS) ; \ - $(ELFSIGN_OBJECT) +POST_PROCESS= $(PROCESS_COMMENT) $@ ; $(PROCESS_CTF) ; \ + $(STRIP_STABS) ; $(ELFSIGN_OBJECT) # # chk4ubin is a tool that inspects a module for a symbol table diff --git a/usr/src/cmd/Makefile.ctf b/usr/src/cmd/Makefile.ctf index 69521551ae..107125ac30 100644 --- a/usr/src/cmd/Makefile.ctf +++ b/usr/src/cmd/Makefile.ctf @@ -21,10 +21,25 @@ # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. +# Copyright 2021 Oxide Computer Company # -POST_PROCESS += ; $(CTFMERGE) $(CTFMRGFLAGS) -L VERSION -o $@ $(OBJS) -POST_PROCESS_O += ; $(CTFCONVERT_O) +# +# The default mode at the moment is to use ctfconvert on object files +# and merge them together. If you set this to 'link' after including +# Makefile.ctf, it will switch that so instead we just do a single +# ctfconvert on the resulting linked binary. +# +CTF_MODE = objs + +POST_objs = ; $(CTFMERGE) $(CTFMRGFLAGS) -L VERSION -o $@ $(OBJS) +POST_O_objs = ; $(CTFCONVERT_O) + +POST_link = $(CTFCONVERT) -L VERSION $@ +POST_O_link = + +PROCESS_CTF = $(POST_$(CTF_MODE)) +POST_PROCESS_O += $(POST_O_$(CTF_MODE)) CFLAGS += $(CTF_FLAGS) CFLAGS64 += $(CTF_FLAGS) diff --git a/usr/src/cmd/mdb/common/mdb/mdb_print.c b/usr/src/cmd/mdb/common/mdb/mdb_print.c index 94164edadb..4c1c0d2555 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_print.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_print.c @@ -27,6 +27,7 @@ * Copyright (c) 2012, 2014 by Delphix. All rights reserved. * Copyright 2020 Joyent, Inc. * Copyright (c) 2014 Nexenta Systems, Inc. All rights reserved. + * Copyright 2021 Oxide Computer Company */ #include <mdb/mdb_modapi.h> @@ -878,6 +879,19 @@ print_bitfield(ulong_t off, printarg_t *pap, ctf_encoding_t *ep) } /* + * Our bitfield may stradle a byte boundary, if so, the calculation of + * size may not correctly capture that. However, off is relative to the + * entire bitfield, so we first have to make that relative to the byte. + */ + if ((off % 8) + ep->cte_bits > NBBY * size) { + size++; + } + + if (size > sizeof (value)) { + mdb_printf("??? (total bitfield too large after alignment"); + } + + /* * 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. @@ -886,6 +900,7 @@ print_bitfield(ulong_t off, printarg_t *pap, ctf_encoding_t *ep) buf += sizeof (value) - size; off += ep->cte_bits; #endif + if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, buf, size, addr) != size) { mdb_warn("failed to read %lu bytes at %llx", (ulong_t)size, addr); @@ -988,12 +1003,15 @@ print_int_val(const char *type, ctf_encoding_t *ep, ulong_t off, } /* - * 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. + * If the size is not a power-of-two number of bytes in the range 1-8 or + * power-of-two number starts in the middle of a byte then we assume it + * is a bitfield and print it as such. */ size = ep->cte_bits / NBBY; - if (size > 8 || (ep->cte_bits % NBBY) != 0 || (size & (size - 1)) != 0) + if (size > 8 || (ep->cte_bits % NBBY) != 0 || (size & (size - 1) || + (off % NBBY) != 0) != 0) { return (print_bitfield(off, pap, ep)); + } if (IS_CHAR(*ep)) return (print_char_val(addr, pap)); diff --git a/usr/src/pkg/manifests/system-test-utiltest.p5m b/usr/src/pkg/manifests/system-test-utiltest.p5m index 8a6d398e4d..5b82b5dbf2 100644 --- a/usr/src/pkg/manifests/system-test-utiltest.p5m +++ b/usr/src/pkg/manifests/system-test-utiltest.p5m @@ -1613,6 +1613,8 @@ file path=opt/util-tests/tests/mdb/numbers/tst.base10.mdb mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.base10.mdb.out mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.binary.mdb mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.binary.mdb.out mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.bitfields.ksh mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.bitfields.ksh.out mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.hex.mdb mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.hex.mdb.out mode=0444 file path=opt/util-tests/tests/mdb/numbers/tst.octal.mdb mode=0444 @@ -1622,6 +1624,7 @@ dir path=opt/util-tests/tests/mdb/options file path=opt/util-tests/tests/mdb/options/tst.autowrap.mdb mode=0444 file path=opt/util-tests/tests/mdb/options/tst.autowrap.mdb.out mode=0444 dir path=opt/util-tests/tests/mdb/progs +file path=opt/util-tests/tests/mdb/progs/bitfields mode=0555 file path=opt/util-tests/tests/mdb/progs/number_symbol mode=0555 dir path=opt/util-tests/tests/mdb/typedef file path=opt/util-tests/tests/mdb/typedef/err.badid-leadnum.ksh mode=0444 diff --git a/usr/src/test/util-tests/tests/mdb/Makefile b/usr/src/test/util-tests/tests/mdb/Makefile index fbf4c74e57..5f27917d40 100644 --- a/usr/src/test/util-tests/tests/mdb/Makefile +++ b/usr/src/test/util-tests/tests/mdb/Makefile @@ -61,6 +61,8 @@ FILES = \ numbers/tst.badnums.ksh \ numbers/tst.base10.mdb \ numbers/tst.base10.mdb.out \ + numbers/tst.bitfields.ksh \ + numbers/tst.bitfields.ksh.out \ numbers/tst.binary.mdb \ numbers/tst.binary.mdb.out \ numbers/tst.hex.mdb \ diff --git a/usr/src/test/util-tests/tests/mdb/mdbtest b/usr/src/test/util-tests/tests/mdb/mdbtest index 3b353619c4..c4483d6c68 100755 --- a/usr/src/test/util-tests/tests/mdb/mdbtest +++ b/usr/src/test/util-tests/tests/mdb/mdbtest @@ -98,10 +98,12 @@ function run_single echo "Executing test $name ... \c" mkdir -p "$odir" >/dev/null || fatal "can't make output directory" if [[ -z "$input" ]]; then - MDB=$mt_mdb $command > "$odir/stdout" 2>"$odir/stderr" + MDB=$mt_mdb ODIR=$odir $command > "$odir/stdout" \ + 2>"$odir/stderr" res=$? else - MDB=$mt_mdb $command < $input > "$odir/stdout" 2>"$odir/stderr" + MDB=$mt_mdb ODIR=$odir $command < $input > "$odir/stdout" \ + 2>"$odir/stderr" res=$? fi diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh b/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh new file mode 100644 index 0000000000..3f39acae92 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh @@ -0,0 +1,30 @@ +#!/usr/bin/ksh +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2021 Oxide Computer Company +# + +# +# Sanity check parts of bitfields. +# + +set -o pipefail + +tst_root="$(dirname $0)/.." +tst_prog="$tst_root/progs/bitfields" +tst_outfile="/tmp/mdb.bitfield.out.$$" +tst_exp="$0.out" + +$MDB -e "first::print -t broken_t" $tst_prog > $ODIR/stdout +$MDB -e "second::print -t broken6491_t" $tst_prog >> $ODIR/stdout diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh.out b/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh.out new file mode 100644 index 0000000000..347415a638 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.bitfields.ksh.out @@ -0,0 +1,23 @@ +broken_t { + unsigned int:3 brk_a :3 = 0x3 + unsigned int:2 brk_b :2 = 0x3 + unsigned int:1 brk_c :1 = 0 + unsigned int:1 brk_d :1 = 0x1 + unsigned int:1 brk_e :1 = 0x1 + unsigned int:1 brk_f :1 = 0x1 + unsigned int:3 brk_g :3 = 0x3 + unsigned int:3 brk_h :3 = 0x5 + unsigned int:5 brk_i :5 = 0x3 + unsigned int:4 brk_j :4 = 0x9 + unsigned int:6 brk_k :6 = 0x13 + unsigned int:1 brk_l :1 = 0 + unsigned int:1 brk_m :1 = 0x1 +} +broken6491_t { + unsigned short:1 a :1 = 0x1 + unsigned short:8 b :8 = 0x2 + unsigned short:3 c :3 = 0 + unsigned short:2 d :2 = 0 + unsigned short:1 e :1 = 0x1 + unsigned short:1 f :1 = 0 +} diff --git a/usr/src/test/util-tests/tests/mdb/progs/Makefile b/usr/src/test/util-tests/tests/mdb/progs/Makefile index cb28d80f2b..832bb90175 100644 --- a/usr/src/test/util-tests/tests/mdb/progs/Makefile +++ b/usr/src/test/util-tests/tests/mdb/progs/Makefile @@ -17,11 +17,14 @@ include $(SRC)/Makefile.master ROOTOPTPKG = $(ROOT)/opt/util-tests TESTDIR = $(ROOTOPTPKG)/tests/mdb/progs -PROGS = number_symbol +PROGS = number_symbol bitfields include $(SRC)/cmd/Makefile.cmd +include $(SRC)/cmd/Makefile.ctf include $(SRC)/test/Makefile.com +CTF_MODE = link + CMDS = $(PROGS:%=$(TESTDIR)/%) $(CMDS) := FILEMODE = 0555 diff --git a/usr/src/test/util-tests/tests/mdb/progs/bitfields.c b/usr/src/test/util-tests/tests/mdb/progs/bitfields.c new file mode 100644 index 0000000000..5a8807c7ad --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/progs/bitfields.c @@ -0,0 +1,74 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2021 oxide Computer Company + */ + +/* + * Test various awkward bitfield cases. In particular, where we have things that + * don't cross byte alignment. + */ + +#include <stdint.h> + +typedef struct broken { + uint32_t brk_a:3; + uint32_t brk_b:2; + uint32_t brk_c:1; + uint32_t brk_d:1; + uint32_t brk_e:1; + uint32_t brk_f:1; + uint32_t brk_g:3; + uint32_t brk_h:3; + uint32_t brk_i:5; + uint32_t brk_j:4; + uint32_t brk_k:6; + uint32_t brk_l:1; + uint32_t brk_m:1; +} broken_t; + +broken_t first = { + .brk_a = 3, + .brk_b = 3, + .brk_c = 0, + .brk_d = 1, + .brk_e = 1, + .brk_f = 1, + .brk_g = 3, + .brk_h = 5, + .brk_i = 3, + .brk_j = 9, + .brk_k = 19, + .brk_l = 0, + .brk_m = 1 +}; + +typedef struct broken6491 { + unsigned short a:1; + unsigned short b:8; + unsigned short c:3; + unsigned short d:2; + unsigned short e:1; + unsigned short f:1; +} broken6491_t; + +broken6491_t second = { + .a = 1, + .b = 2, + .e = 1 +}; + +int +main(void) +{ + return (0); +} |