1 /* Test program for dwfl_getmodules bug.
2 Copyright (C) 2008 Red Hat, Inc.
3 This file is part of elfutils.
4
5 This file 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 elfutils is distributed in the hope that it will be useful, but
11 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 #include <config.h>
19 #include <stdio.h>
20 #include <fcntl.h>
21 #include <assert.h>
22 #include ELFUTILS_HEADER(dwfl)
23 #include ELFUTILS_HEADER(elf)
24
25 static const Dwfl_Callbacks cb =
26 {
27 NULL,
28 NULL,
29 NULL,
30 NULL,
31 };
32
33 int
main(int argc,char ** argv)34 main (int argc, char **argv)
35 {
36 assert (argc == 2);
37
38 Dwfl *dwfl = dwfl_begin (&cb);
39
40 int fd = open (argv[1], O_RDONLY);
41 assert (fd != -1);
42
43 Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
44 (void) dwfl_core_file_report (dwfl, elf, argv[0]);
45
46 /* testcore-noncontig contains a shared library mapped between
47 non-contiguous segments of another shared library:
48
49 [...]
50 7f14e458c000-7f14e45ae000 00000000 139264 /usr/lib64/ld-2.17.so (1)
51 7f14e4795000-7f14e4798000 00000000 12288 /usr/lib64/firefox/liblgpllibs.so (2)
52 7f14e4798000-7f14e479d000 00003000 20480 /usr/lib64/firefox/liblgpllibs.so
53 7f14e479d000-7f14e479f000 00008000 8192 /usr/lib64/firefox/liblgpllibs.so
54 7f14e479f000-7f14e47a0000 00009000 4096 /usr/lib64/firefox/liblgpllibs.so
55 7f14e47a0000-7f14e47a1000 0000a000 4096 /usr/lib64/firefox/liblgpllibs.so (3)
56 7f14e47ad000-7f14e47ae000 00021000 4096 /usr/lib64/ld-2.17.so (4)
57 7f14e47ae000-7f14e47af000 00022000 4096 /usr/lib64/ld-2.17.so */
58
59 /* First segment of the non-contiguous module (1). */
60 int seg = dwfl_addrsegment (dwfl, 0x7f14e458c000, NULL);
61 assert (seg == 32);
62
63 /* First segment of the module within the non-contiguous module's address
64 range (2). */
65 seg = dwfl_addrsegment (dwfl, 0x7f14e4795000, NULL);
66 assert (seg == 33);
67
68 /* Last segment of the module within the non-contiguous module's
69 address range (3). */
70 seg = dwfl_addrsegment (dwfl, 0x7f14e47a0000, NULL);
71 assert (seg == 37);
72
73 /* First segment of non-contiguous module following its address space
74 gap (4). */
75 seg = dwfl_addrsegment (dwfl, 0x7f14e47ad000, NULL);
76 assert (seg == 40);
77
78 dwfl_end (dwfl);
79 elf_end (elf);
80
81 return 0;
82 }
83