Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / stap-probe.c
blob36ce2da7847bb5509536e7bfab470f3e3c2cf247
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2012-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include "attributes.h"
20 #if USE_SEMAPHORES
22 #define _SDT_HAS_SEMAPHORES
23 __extension__ unsigned short test_user_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
24 #define TEST test_user_semaphore
26 __extension__ unsigned short test_two_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
27 #define TEST2 test_two_semaphore
29 __extension__ unsigned short test_m4_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
31 __extension__ unsigned short test_pstr_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
33 __extension__ unsigned short test_ps_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
35 __extension__ unsigned short test_xmmreg_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
36 #else
38 int relocation_marker __attribute__ ((unused));
40 #define TEST 1
41 #define TEST2 1
43 #endif
45 #include <sys/sdt.h>
47 /* We only support SystemTap and only the v3 form. */
48 #if _SDT_NOTE_TYPE != 3
49 #error "not using SystemTap v3 probes"
50 #endif
52 struct funcs
54 int val;
56 const char *(*ps) (int);
59 static void
60 m1 (void)
62 /* m1 and m2 are equivalent, but because of some compiler
63 optimizations we have to make each of them unique. This is why
64 we have this dummy variable here. */
65 volatile int dummy = 0;
67 if (TEST2)
68 STAP_PROBE1 (test, two, dummy);
71 static void
72 m2 (void)
74 if (TEST2)
75 STAP_PROBE (test, two);
78 static int
79 f (int x)
81 if (TEST)
82 STAP_PROBE1 (test, user, x);
83 return x+5;
86 static const char *
87 pstr (int val)
89 const char *a = "This is a test message.";
90 const char *b = "This is another test message.";
92 STAP_PROBE3 (test, ps, a, b, val);
94 return val == 0 ? a : b;
97 #ifdef __SSE2__
98 static const char * __attribute__((noinline))
99 use_xmm_reg (int val)
101 volatile register int val_in_reg asm ("xmm0") = val;
103 STAP_PROBE1 (test, xmmreg, val_in_reg);
105 return val == 0 ? "xxx" : "yyy";
107 #else
108 static const char * __attribute__((noinline)) ATTRIBUTE_NOCLONE
109 use_xmm_reg (int val)
111 /* Nothing. */
113 #endif /* __SSE2__ */
115 static void
116 m4 (const struct funcs *fs, int v)
118 STAP_PROBE3 (test, m4, fs->val, fs->ps (v), v);
122 main()
124 struct funcs fs;
126 fs.val = 42;
127 fs.ps = pstr;
129 f (f (23));
130 m1 ();
131 m2 ();
133 m4 (&fs, 0);
134 m4 (&fs, 1);
136 use_xmm_reg (0x1234);
138 return 0; /* last break here */