1#!/usr/bin/ksh 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright 2025 Oxide Computer Company 15# 16 17# 18# Test our ability to recurse through and print information about anonymous 19# structs and unions. Effectively, this is about the resolution capabilities of 20# various dcmds. This is paired with the "anon" program. Note, we have to be 21# very careful to avoid printing addresses into the output data we're comparing 22# against. Make sure to use ::printf for strings rather than ::print or './s' 23# 24 25set -o pipefail 26 27tst_root="$(dirname $0)/.." 28tst_prog="$tst_root/progs/anon" 29 30cat </dev/null > $ODIR/stdout 31 32# 33# Begin with basic offsetof logic on types. This ensures that embedded anonymous 34# entities are at the correct offset. 35# 36$MDB -e "::offsetof struct foo foo" $tst_prog >> $ODIR/stdout 37$MDB -e "::offsetof struct bar bar" $tst_prog >> $ODIR/stdout 38$MDB -e "::offsetof struct bar bar_foo" $tst_prog >> $ODIR/stdout 39$MDB -e "::offsetof struct bar bar_int" $tst_prog >> $ODIR/stdout 40 41$MDB -e "::offsetof struct baz baz_str" $tst_prog >> $ODIR/stdout 42$MDB -e "::offsetof struct baz baz_anon" $tst_prog >> $ODIR/stdout 43$MDB -e "::offsetof struct baz baz_int" $tst_prog >> $ODIR/stdout 44 45$MDB -e "::offsetof struct foobar foobar_int" $tst_prog >> $ODIR/stdout 46$MDB -e "::offsetof struct foobar foo" $tst_prog >> $ODIR/stdout 47$MDB -e "::offsetof struct foobar bar" $tst_prog >> $ODIR/stdout 48$MDB -e "::offsetof struct foobar baz" $tst_prog >> $ODIR/stdout 49$MDB -e "::offsetof struct foobar foobar_anon" $tst_prog >> $ODIR/stdout 50$MDB -e "::offsetof struct foobar a" $tst_prog >> $ODIR/stdout 51$MDB -e "::offsetof struct foobar b" $tst_prog >> $ODIR/stdout 52$MDB -e "::offsetof struct foobar c" $tst_prog >> $ODIR/stdout 53$MDB -e "::offsetof struct foobar d" $tst_prog >> $ODIR/stdout 54$MDB -e "::offsetof struct foobar e" $tst_prog >> $ODIR/stdout 55$MDB -e "::offsetof struct foobar f" $tst_prog >> $ODIR/stdout 56 57# 58# Print ::sizeof to make sure that this aligns with offsetof data. 59# 60$MDB -e "::sizeof struct foo" $tst_prog >> $ODIR/stdout 61$MDB -e "::sizeof struct bar" $tst_prog >> $ODIR/stdout 62$MDB -e "::sizeof struct baz" $tst_prog >> $ODIR/stdout 63$MDB -e "::sizeof struct foobar" $tst_prog >> $ODIR/stdout 64 65# 66# Print the overall structure to make sure we get the <anon> entries we expect. 67# 68$MDB -e "foo::print" $tst_prog >> $ODIR/stdout 69$MDB -e "foo::print foo" $tst_prog >> $ODIR/stdout 70$MDB -e "bar::printf \"%s\\n\" struct bar bar" $tst_prog >> $ODIR/stdout 71$MDB -e "bar::print bar_foo" $tst_prog >> $ODIR/stdout 72$MDB -e "bar::print bar_foo.foo" $tst_prog >> $ODIR/stdout 73$MDB -e "bar::print bar_foo.foo bar_int" $tst_prog >> $ODIR/stdout 74$MDB -e "baz::printf \"%s\\n\" struct baz baz_str" $tst_prog >> $ODIR/stdout 75$MDB -e "baz::printf \"0x%x 0x%x\\n\" struct baz baz_anon baz_int" \ 76 $tst_prog >> $ODIR/stdout 77$MDB -e "foobar::printf \"0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\\n\" struct foobar \ 78 a b c d e f" $tst_prog >> $ODIR/stdout 79$MDB -e "foobar::printf \"%s %s\\n\" struct foobar bar.bar baz.baz_str " \ 80 $tst_prog >> $ODIR/stdout 81$MDB -e "foobar::print struct foobar foobar_int" $tst_prog >> $ODIR/stdout 82$MDB -e "foobar::printf \"0x%x 0x%x 0x%x 0x%x\\n\" struct foobar bar.bar_foo.foo \ 83 bar.bar_int baz.baz_anon foobar_anon" $tst_prog >> $ODIR/stdout 84 85# 86# The stringless structure has no strings, so we can print it without worrying 87# about addresses and make sure we get the appropriate anon names. 88# 89$MDB -e "stringless::print" $tst_prog >> $ODIR/stdout 90$MDB -e "stringless::print -t" $tst_prog >> $ODIR/stdout 91 92# 93# Use the direct offset specification syntax to print a few things as 94# well. This only works with ::print. 95# 96$MDB -e "bar::print \$[8]" $tst_prog >> $ODIR/stdout 97$MDB -e "foobar::print \$[20] \$[2c]" $tst_prog >> $ODIR/stdout 98