|
| 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. |
| 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 | +// xfail-test |
| 12 | + |
| 13 | +// compile-flags:-Z extra-debug-info |
| 14 | +// debugger:break zzz |
| 15 | +// debugger:run |
| 16 | +// debugger:finish |
| 17 | +// debugger:print simple |
| 18 | +// check:$1 = {x = 10, y = 20} |
| 19 | + |
| 20 | +// debugger:print noDestructor |
| 21 | +// check:$2 = {a = {x = 10, y = 20}, guard = -1} |
| 22 | + |
| 23 | +// debugger:print withDestructor |
| 24 | +// check:$3 = {a = {x = 10, y = 20}, guard = -1} |
| 25 | + |
| 26 | +struct NoDestructor { |
| 27 | + x : i32, |
| 28 | + y : i64 |
| 29 | +} |
| 30 | + |
| 31 | +struct WithDestructor { |
| 32 | + x : i32, |
| 33 | + y : i64 |
| 34 | +} |
| 35 | + |
| 36 | +impl Drop for WithDestructor { |
| 37 | + fn finalize(&self) {} |
| 38 | +} |
| 39 | + |
| 40 | +struct NoDestructorGuarded |
| 41 | +{ |
| 42 | + a: NoDestructor, |
| 43 | + guard: i64 |
| 44 | +} |
| 45 | + |
| 46 | +struct WithDestructorGuarded |
| 47 | +{ |
| 48 | + a: WithDestructor, |
| 49 | + guard: i64 |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +// The compiler adds a 'destructed' boolean field to structs implementing Drop. This field is used |
| 54 | +// at runtime to prevent finalize() to be executed more than once (see middle::trans::adt). |
| 55 | +// This field must be incorporated by the debug info generation. Otherwise the debugger assumes a |
| 56 | +// wrong size/layout for the struct. |
| 57 | +fn main() { |
| 58 | + |
| 59 | + let simple = WithDestructor { x: 10, y: 20 }; |
| 60 | + |
| 61 | + let noDestructor = NoDestructorGuarded { |
| 62 | + a: NoDestructor { x: 10, y: 20 }, |
| 63 | + guard: -1 |
| 64 | + }; |
| 65 | + |
| 66 | + // If the destructor flag field is not incorporated into the debug info for 'WithDestructor' |
| 67 | + // then the debugger will have an invalid offset for the field 'guard' and thus should not be |
| 68 | + // able to read its value correctly. |
| 69 | + let withDestructor = WithDestructorGuarded { |
| 70 | + a: WithDestructor { x: 10, y: 20 }, |
| 71 | + guard: -1 |
| 72 | + }; |
| 73 | + |
| 74 | + zzz(); |
| 75 | +} |
| 76 | + |
| 77 | +fn zzz() {()} |
0 commit comments