Tests: fix: test_list_triggers_cli fails to list userspace-probe-sdt trigger
[lttng-tools.git] / tests / utils / testapp / userspace-probe-sdt-binary / userspace-probe-sdt-binary.c
CommitLineData
a9c2df2b 1/*
9d16b343 2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
a9c2df2b 3 *
9d16b343 4 * SPDX-License-Identifier: LGPL-2.1-or-later
a9c2df2b 5 *
a9c2df2b 6 */
9d16b343 7
a9c2df2b
FD
8#ifndef _GNU_SOURCE
9#define _GNU_SOURCE
10#endif
11
2f101846
JG
12/*
13 * The order of inclusion is important here: including sdt.h _before_ the probe
14 * declarations ensures that semaphore-protected SDT probes (which we don't support) are not
15 * generated. See SYSTEMTAP(2) for more details.
16 */
17/* clang-format off */
18#include <sys/sdt.h>
28f23191 19#include "foobar_provider.h"
2f101846
JG
20/* clang-format on */
21
28f23191
JG
22#include "libfoo.h"
23#include "sema.h"
24
a9c2df2b
FD
25#include <dlfcn.h>
26#include <fcntl.h>
27#include <stdbool.h>
28#include <stdint.h>
29#include <stdio.h>
30#include <sys/stat.h>
31#include <sys/types.h>
32
a9c2df2b
FD
33int main(int argc, char *argv[])
34{
35 void *handle;
36 void (*bar_function)();
37
38 FOOBAR_TP1();
39 FOOBAR_TP2();
40 /*
a12fbf64
JG
41 * This SDT tracepoint has an argument. Argument extraction is not supported
42 * at the moment, but tracing of the tracepoint should work.
a9c2df2b
FD
43 */
44 FOOBAR_TP_WITH_ARG(42);
45
a12fbf64 46 /* Call a function containing an SDT tracepoint in shared object. */
a9c2df2b
FD
47 foo_function();
48
49 /*
a12fbf64 50 * Load a shared object and call a function containing an SDT
a9c2df2b
FD
51 * tracepoint
52 */
53 handle = dlopen("libbar.so", RTLD_LAZY);
54 if (!handle) {
55 fprintf(stderr, "Can't dlopen libbar.so");
56 return -1;
57 }
28f23191 58 bar_function = (void (*)()) dlsym(handle, "bar_function");
a9c2df2b
FD
59 bar_function();
60 dlclose(handle);
61
a12fbf64 62 /* This tracepoint has 2 call sites in this binary. */
a9c2df2b
FD
63 FOOBAR_TP2();
64
65 /*
a12fbf64
JG
66 * This function is defined in libfoo and in libzzz. For a test, libzzz is
67 * LD_PRELOADed and should override this function.
a9c2df2b
FD
68 */
69 overridable_function();
70
71 /*
72 * This function is calling a SDT tracepoint that is guarded by a
73 * semaphore.
74 */
75 sema_function();
76 return 0;
77}
This page took 0.042546 seconds and 4 git commands to generate.