Fix: tests: missing frame pointer for callstack test on some compiler
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events-callstack / gen-syscall-events-callstack.c
CommitLineData
591ee332
FD
1/*
2 * Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <fcntl.h>
19#include <signal.h>
20#include <stdbool.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/syscall.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "utils.h"
29
30/**
31 * The process waits for the creation of a file passed as argument from an
32 * external processes to execute a syscall and exiting. This is useful for tests
33 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
34 * events generated by our test process only.
35 */
36
51c2fb6c
FD
37#if defined(__clang__)
38#define nooptimization __attribute__((noinline)) __attribute__((optnone))
39#else
40#define nooptimization __attribute__((noinline)) __attribute__((optimize(0)))
41#endif
42
591ee332
FD
43volatile int val = 0;
44
51c2fb6c 45long nooptimization
591ee332
FD
46my_gettid(void)
47{
48 long ret;
49#ifdef __x86_64
50 asm volatile
51 (
52 "syscall"
53 : "=a" (ret)
54 : "0"(__NR_gettid)
55 : "cc", "rcx", "r11", "memory"
56 );
57#elif __i386
58 asm volatile
59 (
60 "int $0x80"
61 : "=a" (ret)
62 : "0"(__NR_gettid)
63 : "cc", "edi", "esi", "memory"
64 );
65#else
66#error "Userspace callstack test not supported for this architecture."
67#endif
68 return ret;
69}
70
51c2fb6c 71int nooptimization
591ee332
FD
72fct_c(void)
73{
74 return my_gettid();
75}
76
51c2fb6c 77int nooptimization
591ee332
FD
78fct_b(void)
79{
80 val += fct_c();
81 return val;
82}
83
51c2fb6c 84int nooptimization
591ee332
FD
85fct_a(void)
86{
87 val += fct_b();
88 return val;
89}
90
91int main(int argc, char **argv)
92{
93 int ret = 0;
94 char *start_file;
95
96 if (argc != 2) {
97 fprintf(stderr, "Error: Missing argument\n");
98 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
99 ret = -1;
100 goto error;
101 }
102
103 start_file = argv[1];
104
105 /*
106 * Wait for the start_file to be created by an external process
107 * (typically the test script) before executing the syscall
108 */
109 ret = wait_on_file(start_file);
110 if (ret != 0) {
111 goto error;
112 }
113
114 /* Start the callchain to the syscall */
115 ret = fct_a();
116
117 /* Return success */
118 if (ret >= 0) {
119 ret = 0;
120 }
121
122error:
123 return ret;
124}
This page took 0.029418 seconds and 4 git commands to generate.