]> git.proxmox.com Git - rustc.git/blame - src/test/debuginfo/struct-with-destructor.rs
Update unsuspicious file list
[rustc.git] / src / test / debuginfo / struct-with-destructor.rs
CommitLineData
1a4d82fc
JJ
1// min-lldb-version: 310
2
3// compile-flags:-g
4
5// === GDB TESTS ===================================================================================
6
7// gdb-command:run
8// gdb-command:print simple
c30ab7b3
SL
9// gdbg-check:$1 = {x = 10, y = 20}
10// gdbr-check:$1 = struct_with_destructor::WithDestructor {x: 10, y: 20}
1a4d82fc
JJ
11
12// gdb-command:print noDestructor
c30ab7b3
SL
13// gdbg-check:$2 = {a = {x = 10, y = 20}, guard = -1}
14// gdbr-check:$2 = struct_with_destructor::NoDestructorGuarded {a: struct_with_destructor::NoDestructor {x: 10, y: 20}, guard: -1}
1a4d82fc
JJ
15
16// gdb-command:print withDestructor
c30ab7b3
SL
17// gdbg-check:$3 = {a = {x = 10, y = 20}, guard = -1}
18// gdbr-check:$3 = struct_with_destructor::WithDestructorGuarded {a: struct_with_destructor::WithDestructor {x: 10, y: 20}, guard: -1}
1a4d82fc
JJ
19
20// gdb-command:print nested
c30ab7b3
SL
21// gdbg-check:$4 = {a = {a = {x = 7890, y = 9870}}}
22// gdbr-check:$4 = struct_with_destructor::NestedOuter {a: struct_with_destructor::NestedInner {a: struct_with_destructor::WithDestructor {x: 7890, y: 9870}}}
1a4d82fc
JJ
23
24
25// === LLDB TESTS ==================================================================================
26
27// lldb-command:run
28// lldb-command:print simple
f035d41b
XL
29// lldbg-check:[...]$0 = { x = 10 y = 20 }
30// lldbr-check:(struct_with_destructor::WithDestructor) simple = { x = 10 y = 20 }
1a4d82fc
JJ
31
32// lldb-command:print noDestructor
f035d41b
XL
33// lldbg-check:[...]$1 = { a = { x = 10 y = 20 } guard = -1 }
34// lldbr-check:(struct_with_destructor::NoDestructorGuarded) noDestructor = { a = { x = 10 y = 20 } guard = -1 }
1a4d82fc
JJ
35
36// lldb-command:print withDestructor
f035d41b
XL
37// lldbg-check:[...]$2 = { a = { x = 10 y = 20 } guard = -1 }
38// lldbr-check:(struct_with_destructor::WithDestructorGuarded) withDestructor = { a = { x = 10 y = 20 } guard = -1 }
1a4d82fc
JJ
39
40// lldb-command:print nested
f035d41b
XL
41// lldbg-check:[...]$3 = { a = { a = { x = 7890 y = 9870 } } }
42// lldbr-check:(struct_with_destructor::NestedOuter) nested = { a = { a = { x = 7890 y = 9870 } } }
1a4d82fc
JJ
43
44#![allow(unused_variables)]
b039eaaf 45#![feature(omit_gdb_pretty_printer_section)]
1a4d82fc
JJ
46#![omit_gdb_pretty_printer_section]
47
48struct NoDestructor {
49 x: i32,
50 y: i64
51}
52
53struct WithDestructor {
54 x: i32,
55 y: i64
56}
57
58impl Drop for WithDestructor {
59 fn drop(&mut self) {}
60}
61
62struct NoDestructorGuarded {
63 a: NoDestructor,
64 guard: i64
65}
66
67struct WithDestructorGuarded {
68 a: WithDestructor,
69 guard: i64
70}
71
72struct NestedInner {
73 a: WithDestructor
74}
75
76impl Drop for NestedInner {
77 fn drop(&mut self) {}
78}
79
80struct NestedOuter {
81 a: NestedInner
82}
83
84
85// The compiler adds a 'destructed' boolean field to structs implementing Drop. This field is used
94b46f34 86// at runtime to prevent drop() to be executed more than once.
1a4d82fc
JJ
87// This field must be incorporated by the debug info generation. Otherwise the debugger assumes a
88// wrong size/layout for the struct.
89fn main() {
90
91 let simple = WithDestructor { x: 10, y: 20 };
92
93 let noDestructor = NoDestructorGuarded {
94 a: NoDestructor { x: 10, y: 20 },
95 guard: -1
96 };
97
98 // If the destructor flag field is not incorporated into the debug info for 'WithDestructor'
99 // then the debugger will have an invalid offset for the field 'guard' and thus should not be
100 // able to read its value correctly (dots are padding bytes, D is the boolean destructor flag):
101 //
102 // 64 bit
103 //
104 // NoDestructorGuarded = 0000....00000000FFFFFFFF
105 // <--------------><------>
106 // NoDestructor guard
107 //
108 //
109 // withDestructorGuarded = 0000....00000000D.......FFFFFFFF
110 // <--------------><------> // How debug info says it is
111 // WithDestructor guard
112 //
113 // <----------------------><------> // How it actually is
114 // WithDestructor guard
115 //
116 // 32 bit
117 //
118 // NoDestructorGuarded = 000000000000FFFFFFFF
119 // <----------><------>
120 // NoDestructor guard
121 //
122 //
123 // withDestructorGuarded = 000000000000D...FFFFFFFF
124 // <----------><------> // How debug info says it is
125 // WithDestructor guard
126 //
127 // <--------------><------> // How it actually is
128 // WithDestructor guard
129 //
130 let withDestructor = WithDestructorGuarded {
131 a: WithDestructor { x: 10, y: 20 },
132 guard: -1
133 };
134
135 // expected layout (64 bit) = xxxx....yyyyyyyyD.......D...
136 // <--WithDestructor------>
137 // <-------NestedInner-------->
138 // <-------NestedOuter-------->
139 let nested = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } };
140
141 zzz(); // #break
142}
143
144fn zzz() {()}