]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/dlmopen.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / dlmopen.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2021-2023 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20 #define _GNU_SOURCE
21 #include <dlfcn.h>
22 #include <stddef.h>
23 #include <assert.h>
24 #include <unistd.h>
25
26 volatile int wait_for_gdb = 1;
27
28 int
29 main (void)
30 {
31 void *handle[4];
32 int (*fun) (int);
33 Lmid_t lmid;
34 int dl;
35
36 handle[0] = dlmopen (LM_ID_NEWLM, DSO1_NAME, RTLD_LAZY | RTLD_LOCAL);
37 assert (handle[0] != NULL);
38
39 dlinfo (handle[0], RTLD_DI_LMID, &lmid);
40
41 handle[1] = dlopen (DSO1_NAME, RTLD_LAZY | RTLD_LOCAL);
42 assert (handle[1] != NULL);
43
44 handle[2] = dlmopen (LM_ID_NEWLM, DSO1_NAME, RTLD_LAZY | RTLD_LOCAL);
45 assert (handle[2] != NULL);
46
47 handle[3] = dlmopen (lmid, DSO2_NAME, RTLD_LAZY | RTLD_LOCAL);
48 assert (handle[3] != NULL);
49
50 alarm (20);
51 while (wait_for_gdb != 0)
52 usleep (1);
53
54 for (dl = 0; dl < 4; ++dl)
55 {
56 fun = dlsym (handle[dl], "inc");
57 assert (fun != NULL);
58
59 fun (42);
60
61 dlclose (handle[dl]);
62 }
63
64 return 0; /* bp.main */
65 }