xref: /illumos-gate/usr/src/test/util-tests/tests/mdb/progs/anon.c (revision 8b184c19c5f61fa8890900f7bab686bf19b543d3)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2025 Oxide Computer Company
14  */
15 
16 /*
17  * This file is paired with the sou/tst.anon.ksh mdb test. It's design to
18  * include a number of structures and unions with anonymous values that we can
19  * test with various commands to make sure we properly resolve member names
20  * through them.
21  */
22 
23 struct foo {
24 	int foo;
25 };
26 
27 struct bar {
28 	const char *bar;
29 	union {
30 		struct foo bar_foo;
31 		int bar_int;
32 	};
33 };
34 
35 struct baz {
36 	struct {
37 		const char *baz_str;
38 		int baz_anon;
39 	};
40 	int baz_int;
41 };
42 
43 struct foobar {
44 	int foobar_int;
45 	union {
46 		struct foo foo;
47 		struct bar bar;
48 		struct baz baz;
49 		struct {
50 			void *foobar_ptr;
51 			int foobar_anon;
52 		};
53 	};
54 	struct {
55 		int a;
56 		int b;
57 		int c;
58 	};
59 	union {
60 		int d;
61 		int e;
62 		int f;
63 	};
64 };
65 
66 struct foo foo = { .foo = 42 };
67 struct bar bar = { .bar = "hello world", .bar_int = 0x7777 };
68 struct baz baz = {
69 	.baz_anon = 0x9999,
70 	.baz_str = "It's a trap?!",
71 	.baz_int = -4
72 };
73 
74 struct foobar foobar = {
75 	.foobar_int = 0xb295,
76 	.bar = { .bar = "Elbereth", .bar_int = 0x7777 },
77 	.a = 0x9876,
78 	.b = 0x12345,
79 	.c = 0xb22b,
80 	.e = 0xfdcba
81 };
82 
83 struct stringless {
84 	union {
85 		struct {
86 			int life;
87 			int hope;
88 		};
89 		int dreams;
90 		union {
91 			char k;
92 			short e;
93 			int f;
94 			long a;
95 		};
96 		double destroy;
97 	};
98 };
99 
100 struct stringless stringless = { .life = 0xaa7777aa, .hope = 0x339999ee };
101 
102 int
main(void)103 main(void)
104 {
105 	return (0);
106 }
107