]> git.proxmox.com Git - rustc.git/blob - src/test/debuginfo/packed-struct.rs
c476e9fe0796fa71438c99e307252e86f36c7ca0
[rustc.git] / src / test / debuginfo / packed-struct.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12 // min-lldb-version: 310
13 // ignore-gdb-version: 7.11.90 - 7.12
14
15 // compile-flags:-g
16
17 // === GDB TESTS ===================================================================================
18
19 // gdb-command:run
20
21 // gdb-command:print packed
22 // gdbg-check:$1 = {x = 123, y = 234, z = 345}
23 // gdbr-check:$1 = packed_struct::Packed {x: 123, y: 234, z: 345}
24
25 // gdb-command:print packedInPacked
26 // gdbg-check:$2 = {a = 1111, b = {x = 2222, y = 3333, z = 4444}, c = 5555, d = {x = 6666, y = 7777, z = 8888}}
27 // gdbr-check:$2 = packed_struct::PackedInPacked {a: 1111, b: packed_struct::Packed {x: 2222, y: 3333, z: 4444}, c: 5555, d: packed_struct::Packed {x: 6666, y: 7777, z: 8888}}
28
29 // gdb-command:print packedInUnpacked
30 // gdbg-check:$3 = {a = -1111, b = {x = -2222, y = -3333, z = -4444}, c = -5555, d = {x = -6666, y = -7777, z = -8888}}
31 // gdbr-check:$3 = packed_struct::PackedInUnpacked {a: -1111, b: packed_struct::Packed {x: -2222, y: -3333, z: -4444}, c: -5555, d: packed_struct::Packed {x: -6666, y: -7777, z: -8888}}
32
33 // gdb-command:print unpackedInPacked
34 // gdbg-check:$4 = {a = 987, b = {x = 876, y = 765, z = 654, w = 543}, c = {x = 432, y = 321, z = 210, w = 109}, d = -98}
35 // gdbr-check:$4 = packed_struct::UnpackedInPacked {a: 987, b: packed_struct::Unpacked {x: 876, y: 765, z: 654, w: 543}, c: packed_struct::Unpacked {x: 432, y: 321, z: 210, w: 109}, d: -98}
36
37 // gdb-command:print sizeof(packed)
38 // gdb-check:$5 = 14
39
40 // gdb-command:print sizeof(packedInPacked)
41 // gdb-check:$6 = 40
42
43
44 // === LLDB TESTS ==================================================================================
45
46 // lldb-command:run
47
48 // lldb-command:print packed
49 // lldb-check:[...]$0 = Packed { x: 123, y: 234, z: 345 }
50
51 // lldb-command:print packedInPacked
52 // lldb-check:[...]$1 = PackedInPacked { a: 1111, b: Packed { x: 2222, y: 3333, z: 4444 }, c: 5555, d: Packed { x: 6666, y: 7777, z: 8888 } }
53
54 // lldb-command:print packedInUnpacked
55 // lldb-check:[...]$2 = PackedInUnpacked { a: -1111, b: Packed { x: -2222, y: -3333, z: -4444 }, c: -5555, d: Packed { x: -6666, y: -7777, z: -8888 } }
56
57 // lldb-command:print unpackedInPacked
58 // lldb-check:[...]$3 = UnpackedInPacked { a: 987, b: Unpacked { x: 876, y: 765, z: 654, w: 543 }, c: Unpacked { x: 432, y: 321, z: 210, w: 109 }, d: -98 }
59
60 // lldb-command:print sizeof(packed)
61 // lldb-check:[...]$4 = 14
62
63 // lldb-command:print sizeof(packedInPacked)
64 // lldb-check:[...]$5 = 40
65
66 #![allow(unused_variables)]
67 #![feature(omit_gdb_pretty_printer_section)]
68 #![omit_gdb_pretty_printer_section]
69
70 #[repr(packed)]
71 struct Packed {
72 x: i16,
73 y: i32,
74 z: i64
75 }
76
77 #[repr(packed)]
78 struct PackedInPacked {
79 a: i32,
80 b: Packed,
81 c: i64,
82 d: Packed
83 }
84
85 // layout (64 bit): aaaa bbbb bbbb bbbb bb.. .... cccc cccc dddd dddd dddd dd..
86 struct PackedInUnpacked {
87 a: i32,
88 b: Packed,
89 c: i64,
90 d: Packed
91 }
92
93 // layout (64 bit): xx.. yyyy zz.. .... wwww wwww
94 struct Unpacked {
95 x: i16,
96 y: i32,
97 z: i16,
98 w: i64
99 }
100
101 // layout (64 bit): aabb bbbb bbbb bbbb bbbb bbbb bbcc cccc cccc cccc cccc cccc ccdd dddd dd
102 #[repr(packed)]
103 struct UnpackedInPacked {
104 a: i16,
105 b: Unpacked,
106 c: Unpacked,
107 d: i64
108 }
109
110 fn main() {
111 let packed = Packed { x: 123, y: 234, z: 345 };
112
113 let packedInPacked = PackedInPacked {
114 a: 1111,
115 b: Packed { x: 2222, y: 3333, z: 4444 },
116 c: 5555,
117 d: Packed { x: 6666, y: 7777, z: 8888 }
118 };
119
120 let packedInUnpacked = PackedInUnpacked {
121 a: -1111,
122 b: Packed { x: -2222, y: -3333, z: -4444 },
123 c: -5555,
124 d: Packed { x: -6666, y: -7777, z: -8888 }
125 };
126
127 let unpackedInPacked = UnpackedInPacked {
128 a: 987,
129 b: Unpacked { x: 876, y: 765, z: 654, w: 543 },
130 c: Unpacked { x: 432, y: 321, z: 210, w: 109 },
131 d: -98
132 };
133
134 zzz(); // #break
135 }
136
137 fn zzz() {()}