Ben Kimock | a561484 | 2024-08-10 02:33:40 | [diff] [blame] | 1 | //@ min-lldb-version: 1800 |
sh8281.kim | 4e54828 | 2013-11-04 06:53:01 | [diff] [blame] | 2 | |
许杰友 Jieyou Xu (Joe) | 6e48b96 | 2024-02-22 12:10:29 | [diff] [blame] | 3 | //@ compile-flags:-g |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame] | 4 | |
| 5 | // === GDB TESTS =================================================================================== |
| 6 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 7 | // gdb-command:set print union on |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 8 | // gdb-command:run |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 9 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 10 | // gdb-command:print case1 |
Ben Kimock | fa0e858 | 2024-08-17 21:31:49 | [diff] [blame] | 11 | // gdb-check:$1 = struct_in_enum::Regular::Case1(0, struct_in_enum::Struct {x: 2088533116, y: 2088533116, z: 31868}) |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 12 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 13 | // gdb-command:print case2 |
Ben Kimock | fa0e858 | 2024-08-17 21:31:49 | [diff] [blame] | 14 | // gdb-check:$2 = struct_in_enum::Regular::Case2(0, 1229782938247303441, 4369) |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 15 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 16 | // gdb-command:print univariant |
Ben Kimock | fa0e858 | 2024-08-17 21:31:49 | [diff] [blame] | 17 | // gdb-check:$3 = struct_in_enum::Univariant::TheOnlyCase(struct_in_enum::Struct {x: 123, y: 456, z: 789}) |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 18 | |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame] | 19 | |
| 20 | // === LLDB TESTS ================================================================================== |
| 21 | |
| 22 | // lldb-command:run |
| 23 | |
Markus Reiter | 96431e4 | 2024-03-15 14:05:57 | [diff] [blame] | 24 | // lldb-command:v case1 |
Markus Reiter | 75fba9d | 2024-03-10 13:55:58 | [diff] [blame] | 25 | // lldb-check:[...] Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 }) |
Markus Reiter | 96431e4 | 2024-03-15 14:05:57 | [diff] [blame] | 26 | // lldb-command:v case2 |
Markus Reiter | 75fba9d | 2024-03-10 13:55:58 | [diff] [blame] | 27 | // lldb-check:[...] Case2(0, 1229782938247303441, 4369) |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame] | 28 | |
Markus Reiter | 96431e4 | 2024-03-15 14:05:57 | [diff] [blame] | 29 | // lldb-command:v univariant |
Markus Reiter | 75fba9d | 2024-03-10 13:55:58 | [diff] [blame] | 30 | // lldb-check:[...] TheOnlyCase(Struct { x: 123, y: 456, z: 789 }) |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame] | 31 | |
Aaron Turon | e0ad0fc | 2014-10-27 22:37:07 | [diff] [blame] | 32 | #![allow(unused_variables)] |
Andrew Paseltiner | 6fa0ff2 | 2015-09-19 20:33:47 | [diff] [blame] | 33 | #![feature(omit_gdb_pretty_printer_section)] |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 34 | #![omit_gdb_pretty_printer_section] |
Erick Tryzelaar | ad5c676 | 2013-08-17 15:37:42 | [diff] [blame] | 35 | |
Steven Fackler | 3dcd215 | 2014-11-06 08:05:53 | [diff] [blame] | 36 | use self::Regular::{Case1, Case2}; |
| 37 | use self::Univariant::TheOnlyCase; |
| 38 | |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 39 | struct Struct { |
Derek Guenther | 730bdb6 | 2014-02-05 22:33:10 | [diff] [blame] | 40 | x: u32, |
| 41 | y: i32, |
| 42 | z: i16 |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // The first element is to ensure proper alignment, irrespective of the machines word size. Since |
| 46 | // the size of the discriminant value is machine dependent, this has be taken into account when |
| 47 | // datatype layout should be predictable as in this case. |
| 48 | enum Regular { |
| 49 | Case1(u64, Struct), |
| 50 | Case2(u64, u64, i16) |
| 51 | } |
| 52 | |
| 53 | enum Univariant { |
Derek Guenther | 730bdb6 | 2014-02-05 22:33:10 | [diff] [blame] | 54 | TheOnlyCase(Struct) |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | fn main() { |
| 58 | |
Vadim Petrochenkov | 1accaa9 | 2015-03-28 15:09:51 | [diff] [blame] | 59 | // In order to avoid endianness trouble all of the following test values consist of a single |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 60 | // repeated byte. This way each interpretation of the union should look the same, no matter if |
| 61 | // this is a big or little endian machine. |
| 62 | |
| 63 | // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452 |
| 64 | // 0b01111100011111000111110001111100 = 2088533116 |
| 65 | // 0b0111110001111100 = 31868 |
| 66 | // 0b01111100 = 124 |
| 67 | let case1 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 }); |
| 68 | |
| 69 | // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441 |
| 70 | // 0b00010001000100010001000100010001 = 286331153 |
| 71 | // 0b0001000100010001 = 4369 |
| 72 | // 0b00010001 = 17 |
| 73 | let case2 = Case2(0, 1229782938247303441, 4369); |
| 74 | |
| 75 | let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 }); |
| 76 | |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame] | 77 | zzz(); // #break |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | fn zzz() {()} |