pieces.c 2.6 KB

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