49028b030632a93f2cb93844f6a405ed60a26d46
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / pieces.c
1 /* Copyright (C) 2010 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 /* The original program corresponding to pieces.S.
19 This came from https://bugzilla.redhat.com/show_bug.cgi?id=589467
20 Note that it is not ever compiled, pieces.S is used instead.
21 However, it is used to extract breakpoint line numbers. */
22
23 struct A { int i; int j; };
24 struct B { int : 4; int i : 12; int j : 12; int : 4; };
25
26 __attribute__((noinline)) void
27 bar (int x)
28 {
29 asm volatile ("" : : "r" (x) : "memory");
30 }
31
32 __attribute__((noinline)) int
33 f1 (int k)
34 {
35 struct A a = { 4, k + 6 };
36 asm ("" : "+r" (a.i));
37 a.j++;
38 bar (a.i); /* { dg-final { gdb-test 20 "a.i" "4" } } */
39 bar (a.j); /* { dg-final { gdb-test 20 "a.j" "14" } } */
40 return a.i + a.j; /* f1 breakpoint */
41 }
42
43 __attribute__((noinline)) int
44 f2 (int k)
45 {
46 int a[2] = { 4, k + 6 };
47 asm ("" : "+r" (a[0]));
48 a[1]++;
49 bar (a[0]); /* { dg-final { gdb-test 31 "a\[0\]" "4" } } */
50 bar (a[1]); /* { dg-final { gdb-test 31 "a\[1\]" "14" } } */
51 return a[0] + a[1]; /* f2 breakpoint */
52 }
53
54 __attribute__((noinline)) int
55 f3 (int k)
56 {
57 struct B a = { 4, k + 6 };
58 asm ("" : "+r" (a.i));
59 a.j++;
60 bar (a.i); /* { dg-final { gdb-test 42 "a.i" "4" } } */
61 bar (a.j); /* { dg-final { gdb-test 42 "a.j" "14" } } */
62 return a.i + a.j; /* f3 breakpoint */
63 }
64
65 __attribute__((noinline)) int
66 f4 (int k)
67 {
68 int a[2] = { k, k };
69 asm ("" : "+r" (a[0]));
70 a[1]++;
71 bar (a[0]);
72 bar (a[1]);
73 return a[0] + a[1]; /* f4 breakpoint */
74 }
75
76 __attribute__((noinline)) int
77 f5 (int k)
78 {
79 struct A a = { k, k };
80 asm ("" : "+r" (a.i));
81 a.j++;
82 bar (a.i);
83 bar (a.j);
84 return a.i + a.j; /* f5 breakpoint */
85 }
86
87 int
88 main (void)
89 {
90 int k;
91 asm ("" : "=r" (k) : "0" (7));
92 f1 (k);
93 f2 (k);
94 f3 (k);
95 f4 (k);
96 f5 (k);
97 return 0;
98 }
This page took 0.031282 seconds and 3 git commands to generate.