File: s-patchable-abc.c

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (45 lines) | stat: -rw-r--r-- 647 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * This is a basic test to verify whether uftrace works on the system.
 */
#include <stdlib.h>
#include <unistd.h>

#if __x86_64__
#define NR_NOPS 5
#elif __aarch64__
#define NR_NOPS 2
#else
#define NR_NOPS 0
#endif

#define __patchable __attribute__((patchable_function_entry(NR_NOPS)))

static int a(void);
static int b(void);
static int c(void);

__patchable static int a(void)
{
	return b() - 1;
}

static int b(void)
{
	return c() + 1;
}

__patchable static int c(void)
{
	return getpid() % 100000;
}

__patchable int main(int argc, char *argv[])
{
	int ret = 0;

	if (argc > 1)
		ret = atoi(argv[1]);

	ret += a();
	return ret ? 0 : 1;
}