vscode: Add configurations to run the executables under the debugger
[lttng-tools.git] / tests / regression / ust / ust-dl / prog.c
CommitLineData
9d16b343
MJ
1/*
2 * Copyright (C) 2016 Antoine Busque <abusque@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
d8ed06af 8/* _GNU_SOURCE is defined by config.h */
28f23191
JG
9#include <common/compat/errno.hpp>
10
c70c42cc 11#include <dlfcn.h>
d8ed06af 12#include <stdio.h>
d8ed06af 13#include <stdlib.h>
28f23191 14#include <unistd.h>
edf4b93e 15
d8ed06af
MD
16/*
17 * libfoo has a direct dependency on libbar.
18 * libbar has a direct dependency on libzzz.
19 * This test is therefore a mix of dlopen/dlclose and dlmopen/dlclose of
20 * libfoo, and of its direct dependencies.
21 */
f46376a1 22int main(void)
c70c42cc 23{
bc1d8ca0
PP
24 void *h0, *h2, *h3, *h4;
25
26#ifdef HAVE_DLMOPEN
27 void *h1;
28#endif
29
d8ed06af
MD
30 char *error;
31 int (*foo)(void);
c70c42cc 32
d8ed06af
MD
33 h0 = dlopen("libbar.so", RTLD_LAZY);
34 if (!h0) {
35 goto get_error;
36 }
bc1d8ca0
PP
37
38#ifdef HAVE_DLMOPEN
d8ed06af
MD
39 h1 = dlmopen(LM_ID_BASE, "libfoo.so", RTLD_LAZY);
40 if (!h1) {
41 goto get_error;
42 }
bc1d8ca0
PP
43#endif
44
d8ed06af
MD
45 h2 = dlopen("libzzz.so", RTLD_LAZY);
46 if (!h2) {
47 goto get_error;
48 }
49 h3 = dlopen("libfoo.so", RTLD_LAZY);
50 if (!h3) {
51 goto get_error;
52 }
53 h4 = dlopen("libfoo.so", RTLD_LAZY);
54 if (!h4) {
55 goto get_error;
56 }
c70c42cc 57
bc1d8ca0 58 foo = dlsym(h3, "foo");
d8ed06af
MD
59 error = dlerror();
60 if (error != NULL) {
61 goto error;
62 }
c70c42cc 63
d8ed06af 64 foo();
c70c42cc 65
d8ed06af
MD
66 if (dlclose(h0)) {
67 goto get_error;
68 }
bc1d8ca0
PP
69
70#ifdef HAVE_DLMOPEN
d8ed06af
MD
71 if (dlclose(h1)) {
72 goto get_error;
73 }
bc1d8ca0
PP
74#endif
75
d8ed06af
MD
76 if (dlclose(h2)) {
77 goto get_error;
78 }
79 if (dlclose(h3)) {
80 goto get_error;
81 }
82 if (dlclose(h4)) {
83 goto get_error;
84 }
85
86 exit(EXIT_SUCCESS);
87
88get_error:
89 error = dlerror();
90error:
91 fprintf(stderr, "%s\n", error);
92 exit(EXIT_FAILURE);
c70c42cc 93}
This page took 0.057912 seconds and 5 git commands to generate.