File: userspace-probe-sdt-binary.c

package info (click to toggle)
ltt-control 2.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,400 kB
  • sloc: cpp: 192,720; sh: 29,271; ansic: 10,960; python: 7,419; makefile: 3,534; java: 109; xml: 46
file content (77 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * SPDX-FileCopyrightText: 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

/*
 * The order of inclusion is important here: including sdt.h _before_ the probe
 * declarations ensures that semaphore-protected SDT probes (which we don't support) are not
 * generated. See SYSTEMTAP(2) for more details.
 */
/* clang-format off */
#include <sys/sdt.h>
#include "foobar_provider.h"
/* clang-format on */

#include "libfoo.h"
#include "sema.h"

#include <dlfcn.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
	void *handle;
	void (*bar_function)();

	FOOBAR_TP1();
	FOOBAR_TP2();
	/*
	 * This SDT tracepoint has an argument. Argument extraction is not supported
	 * at the moment, but tracing of the tracepoint should work.
	 */
	FOOBAR_TP_WITH_ARG(42);

	/* Call a function containing an SDT tracepoint in shared object. */
	foo_function();

	/*
	 * Load a shared object and call a function containing an SDT
	 * tracepoint
	 */
	handle = dlopen("libbar.so", RTLD_LAZY);
	if (!handle) {
		fprintf(stderr, "Can't dlopen libbar.so");
		return -1;
	}
	bar_function = (void (*)()) dlsym(handle, "bar_function");
	bar_function();
	dlclose(handle);

	/* This tracepoint has 2 call sites in this binary. */
	FOOBAR_TP2();

	/*
	 * This function is defined in libfoo and in libzzz. For a test, libzzz is
	 * LD_PRELOADed and should override this function.
	 */
	overridable_function();

	/*
	 * This function is calling a SDT tracepoint that is guarded by a
	 * semaphore.
	 */
	sema_function();
	return 0;
}