implptr.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 implptr.S.
  14. This came from Jakub's gcc-patches email implementing
  15. DW_OP_GNU_implicit_pointer.
  16. Note that it is not ever compiled, implptr.S is used instead.
  17. However, it is used to extract breakpoint line numbers. */
  18. struct S
  19. {
  20. int *x, y;
  21. };
  22. int u[6];
  23. static inline void
  24. add (struct S *a, struct S *b, int c)
  25. {
  26. *a->x += *b->x; /* baz breakpoint */
  27. a->y += b->y;
  28. u[c + 0]++;
  29. a = (struct S *) 0;
  30. u[c + 1]++;
  31. a = b;
  32. u[c + 2]++;
  33. }
  34. int
  35. foo (int i)
  36. {
  37. int j = i;
  38. struct S p[2] = { {&i, i * 2}, {&j, j * 2} };
  39. add (&p[0], &p[1], 0);
  40. p[0].x = &j;
  41. p[1].x = &i;
  42. add (&p[0], &p[1], 3);
  43. return i + j; /* foo breakpoint */
  44. }
  45. typedef int *intp;
  46. typedef intp *intpp;
  47. typedef intpp *intppp;
  48. int __attribute__ ((noinline, used, noclone))
  49. bar (int i)
  50. {
  51. intp j = &i;
  52. intpp k = &j;
  53. intppp l = &k;
  54. i++; /* bar breakpoint */
  55. return i;
  56. }
  57. int main ()
  58. {
  59. return bar(5) + foo (23);
  60. }