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.
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.
11 // ignore-tidy-linelength
13 // min-lldb-version: 310
17 // === GDB TESTS ===================================================================================
20 // gdb-command:print simple
21 // gdbg-check:$1 = {x = 10, y = 20}
22 // gdbr-check:$1 = struct_with_destructor::WithDestructor {x: 10, y: 20}
24 // gdb-command:print noDestructor
25 // gdbg-check:$2 = {a = {x = 10, y = 20}, guard = -1}
26 // gdbr-check:$2 = struct_with_destructor::NoDestructorGuarded {a: struct_with_destructor::NoDestructor {x: 10, y: 20}, guard: -1}
28 // gdb-command:print withDestructor
29 // gdbg-check:$3 = {a = {x = 10, y = 20}, guard = -1}
30 // gdbr-check:$3 = struct_with_destructor::WithDestructorGuarded {a: struct_with_destructor::WithDestructor {x: 10, y: 20}, guard: -1}
32 // gdb-command:print nested
33 // gdbg-check:$4 = {a = {a = {x = 7890, y = 9870}}}
34 // gdbr-check:$4 = struct_with_destructor::NestedOuter {a: struct_with_destructor::NestedInner {a: struct_with_destructor::WithDestructor {x: 7890, y: 9870}}}
37 // === LLDB TESTS ==================================================================================
40 // lldb-command:print simple
41 // lldb-check:[...]$0 = WithDestructor { x: 10, y: 20 }
43 // lldb-command:print noDestructor
44 // lldb-check:[...]$1 = NoDestructorGuarded { a: NoDestructor { x: 10, y: 20 }, guard: -1 }
46 // lldb-command:print withDestructor
47 // lldb-check:[...]$2 = WithDestructorGuarded { a: WithDestructor { x: 10, y: 20 }, guard: -1 }
49 // lldb-command:print nested
50 // lldb-check:[...]$3 = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } }
52 #![allow(unused_variables)]
53 #![feature(omit_gdb_pretty_printer_section)]
54 #![omit_gdb_pretty_printer_section]
61 struct WithDestructor {
66 impl Drop for WithDestructor {
70 struct NoDestructorGuarded {
75 struct WithDestructorGuarded {
84 impl Drop for NestedInner {
93 // The compiler adds a 'destructed' boolean field to structs implementing Drop. This field is used
94 // at runtime to prevent drop() to be executed more than once.
95 // This field must be incorporated by the debug info generation. Otherwise the debugger assumes a
96 // wrong size/layout for the struct.
99 let simple = WithDestructor { x: 10, y: 20 };
101 let noDestructor = NoDestructorGuarded {
102 a: NoDestructor { x: 10, y: 20 },
106 // If the destructor flag field is not incorporated into the debug info for 'WithDestructor'
107 // then the debugger will have an invalid offset for the field 'guard' and thus should not be
108 // able to read its value correctly (dots are padding bytes, D is the boolean destructor flag):
112 // NoDestructorGuarded = 0000....00000000FFFFFFFF
113 // <--------------><------>
114 // NoDestructor guard
117 // withDestructorGuarded = 0000....00000000D.......FFFFFFFF
118 // <--------------><------> // How debug info says it is
119 // WithDestructor guard
121 // <----------------------><------> // How it actually is
122 // WithDestructor guard
126 // NoDestructorGuarded = 000000000000FFFFFFFF
127 // <----------><------>
128 // NoDestructor guard
131 // withDestructorGuarded = 000000000000D...FFFFFFFF
132 // <----------><------> // How debug info says it is
133 // WithDestructor guard
135 // <--------------><------> // How it actually is
136 // WithDestructor guard
138 let withDestructor = WithDestructorGuarded {
139 a: WithDestructor { x: 10, y: 20 },
143 // expected layout (64 bit) = xxxx....yyyyyyyyD.......D...
144 // <--WithDestructor------>
145 // <-------NestedInner-------->
146 // <-------NestedOuter-------->
147 let nested = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } };