Debian Codegraph @

testsuite/systemtap.unprivileged/loop.c

raw
1 #include <pthread.h>
2 #include <unistd.h>
3 #include "sys/sdt.h"
4
5 extern int libloopfunc (void);
6
7 /* Thread entry point */
8 void *bar (void *b) {
9 int i;
10 int *j = (int *)b;
11 for (i = 0; i < 10; ++i)
12 *j += i;
13 a:
14 return b;
15 }
16
17 /* We need an inline function. */
18 inline int ibar (void) {
19 return libloopfunc ();
20 }
21
22 /* We need a threaded app. It should not be inline,
23 so a .callee("tbar") test will require the GNU_call_site* DWARF goo
24 to match, not just the presence of a mere DW_AT_inline=3 case. */
25 int tbar (void) {
26 void *x;
27 int j = 0;
28 STAP_PROBE(_test_, main_enter);
29 pthread_t thread;
30 pthread_attr_t attr;
31 pthread_attr_init(&attr);
32 pthread_create (& thread, & attr, bar, (void*)& j);
33 pthread_join (thread, & x);
34 return j;
35 }
36
37 int main (int argc, char *argv[]) {
38 int j = 0;
39 /* Don't loop if an argument was passed */
40 /* We split into two cases rather than check in a single loop because
41 * GCC can output screwy debuginfo otherwise (RHBZ1092144) */
42 if (argc > 1) {
43 j += ibar ();
44 j += tbar ();
45 return 0;
46 }
47 for (;;) {
48 j += ibar ();
49 j += tbar ();
50 #if !defined NOSLEEP
51 usleep (250000); /* 1/4 second pause. */
52 #endif
53 }
54 return j;
55 }