1 // Copyright 2013 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 // compile-flags:-Z extra-debug-info
12 // debugger:rbreak zzz
15 // debugger:print simple
16 // check:$1 = {x = 10, y = 20}
18 // debugger:print noDestructor
19 // check:$2 = {a = {x = 10, y = 20}, guard = -1}
21 // debugger:print withDestructor
22 // check:$3 = {a = {x = 10, y = 20}, guard = -1}
24 // debugger:print nested
25 // check:$4 = {a = {a = {x = 7890, y = 9870}}}
27 #[allow(unused_variable)];
34 struct WithDestructor {
39 impl Drop for WithDestructor {
43 struct NoDestructorGuarded {
48 struct WithDestructorGuarded {
57 impl Drop for NestedInner {
66 // The compiler adds a 'destructed' boolean field to structs implementing Drop. This field is used
67 // at runtime to prevent drop() to be executed more than once (see middle::trans::adt).
68 // This field must be incorporated by the debug info generation. Otherwise the debugger assumes a
69 // wrong size/layout for the struct.
72 let simple = WithDestructor { x: 10, y: 20 };
74 let noDestructor = NoDestructorGuarded {
75 a: NoDestructor { x: 10, y: 20 },
79 // If the destructor flag field is not incorporated into the debug info for 'WithDestructor'
80 // then the debugger will have an invalid offset for the field 'guard' and thus should not be
81 // able to read its value correctly (dots are padding bytes, D is the boolean destructor flag):
85 // NoDestructorGuarded = 0000....00000000FFFFFFFF
86 // <--------------><------>
90 // withDestructorGuarded = 0000....00000000D.......FFFFFFFF
91 // <--------------><------> // How debug info says it is
92 // WithDestructor guard
94 // <----------------------><------> // How it actually is
95 // WithDestructor guard
99 // NoDestructorGuarded = 000000000000FFFFFFFF
100 // <----------><------>
101 // NoDestructor guard
104 // withDestructorGuarded = 000000000000D...FFFFFFFF
105 // <----------><------> // How debug info says it is
106 // WithDestructor guard
108 // <--------------><------> // How it actually is
109 // WithDestructor guard
111 let withDestructor = WithDestructorGuarded {
112 a: WithDestructor { x: 10, y: 20 },
116 // expected layout (64 bit) = xxxx....yyyyyyyyD.......D...
117 // <--WithDestructor------>
118 // <-------NestedInner-------->
119 // <-------NestedOuter-------->
120 let nested = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } };