1 // RUN: %dexter --fail-lt 1.0 -w \
2 // RUN: --builder 'clang' --debugger 'lldb' \
3 // RUN: --cflags "-g -O2" -v -- %s
4 // RUN: %dexter --fail-lt 1.0 -w \
5 // RUN: --builder 'clang' --debugger 'lldb' \
6 // RUN: --cflags "-g -O0" -- %s
7
8 // REQUIRES: lldb
9 // UNSUPPORTED: system-windows
10
11 //// Check that the debugging experience with __attribute__((optnone)) at O2
12 //// matches O0. Test simple structs and methods.
13
14 long a_global_ptr[] = { 0xCAFEBABEL, 0xFEEDBEEFL };
15
16 namespace {
17
18 struct A {
19 int a;
20 float b;
21
22 enum B {
23 A_VALUE = 0x1,
24 B_VALUE = 0x2
25 };
26
27 struct some_data {
28 enum B other_b;
29 enum B other_other_b;
30 };
31
32 struct other_data {
33 union {
34 void *raw_ptr;
35 long *long_ptr;
36 float *float_ptr;
37 } a;
38 struct some_data b;
39 struct some_data c;
40 };
41 private:
42 struct other_data _data;
43
44 public:
getOtherData__anonc881d7a00111::A45 struct other_data *getOtherData() { return &_data; }
46
47 __attribute__((always_inline,nodebug))
setSomeData1__anonc881d7a00111::A48 void setSomeData1(A::B value, A::B other_value) {
49 struct other_data *data = getOtherData();
50 data->b.other_b = value;
51 data->b.other_other_b = other_value;
52 }
53
54 __attribute__((always_inline))
setSomeData2__anonc881d7a00111::A55 void setSomeData2(A::B value, A::B other_value) {
56 struct other_data *data = getOtherData();
57 data->c.other_b = value;
58 data->c.other_other_b = other_value;
59 }
60
setOtherData__anonc881d7a00111::A61 void setOtherData() {
62 setSomeData2(A_VALUE, B_VALUE);
63 getOtherData()->a.long_ptr = &a_global_ptr[0];
64 }
65
66 __attribute__((optnone))
A__anonc881d7a00111::A67 A() {
68 __builtin_memset(this, 0xFF, sizeof(*this));
69 } //DexLabel('break_0')
70 // DexExpectWatchValue('a', '-1', on_line=ref('break_0'))
71 //// Check b is NaN by comparing it to itself.
72 // DexExpectWatchValue('this->b == this->b', 'false', on_line=ref('break_0'))
73 // DexExpectWatchValue('_data.a.raw_ptr == -1', 'true', on_line=ref('break_0'))
74 // DexExpectWatchValue('_data.a.float_ptr == -1', 'true', on_line=ref('break_0'))
75 // DexExpectWatchValue('_data.a.float_ptr == -1', 'true', on_line=ref('break_0'))
76 // DexExpectWatchValue('a_global_ptr[0]', 0xcafebabe, on_line=ref('break_0'))
77 // DexExpectWatchValue('a_global_ptr[1]', 0xfeedbeef, on_line=ref('break_0'))
78
79 __attribute__((optnone))
~A__anonc881d7a00111::A80 ~A() {
81 *getOtherData()->a.long_ptr = 0xADDF00DL;
82 } //DexLabel('break_1')
83 // DexExpectWatchValue('_data.a.raw_ptr == a_global_ptr', 'true', on_line=ref('break_1'))
84 // DexExpectWatchValue('a_global_ptr[0]', 0xaddf00d, on_line=ref('break_1'))
85
86 __attribute__((optnone))
getData__anonc881d7a00111::A87 long getData() {
88 setSomeData1(B_VALUE, A_VALUE);
89 setOtherData();
90 return getOtherData()->a.long_ptr[1]; //DexLabel('break_2')
91 }
92 // DexExpectWatchValue('_data.b.other_b', 'B_VALUE', on_line=ref('break_2'))
93 // DexExpectWatchValue('_data.b.other_other_b', 'A_VALUE', on_line=ref('break_2'))
94 };
95
96 } // anonymous namespace
97
main()98 int main() {
99 int result = 0;
100 {
101 A a;
102 result = a.getData();
103 }
104 return result;
105 }
106