1 /* Test program for dwarf_cu_dwp_section_info
2 Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdio.h>
22 #include <inttypes.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27
28 #include <dwarf.h>
29 #include ELFUTILS_HEADER(dw)
30
31 int
main(int argc,char * argv[])32 main (int argc, char *argv[])
33 {
34 for (int i = 1; i < argc; i++)
35 {
36 printf ("file: %s\n", argv[i]);
37 int fd = open (argv[i], O_RDONLY);
38 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
39 if (dbg == NULL)
40 {
41 printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1));
42 return -1;
43 }
44
45 Dwarf_CU *cu = NULL;
46 while (dwarf_get_units (dbg, cu, &cu, NULL, NULL, NULL, NULL) == 0)
47 {
48 #define SECTION_INFO(section) do { \
49 printf (#section ": "); \
50 Dwarf_Off offset, size; \
51 if (dwarf_cu_dwp_section_info (cu, DW_SECT_##section, \
52 &offset, &size) == 0) \
53 printf ("0x%" PRIx64 " 0x%" PRIx64 "\n", offset, size); \
54 else \
55 printf ("%s\n", dwarf_errmsg (-1)); \
56 } while (0)
57 SECTION_INFO (INFO);
58 SECTION_INFO (TYPES);
59 SECTION_INFO (ABBREV);
60 SECTION_INFO (LINE);
61 SECTION_INFO (LOCLISTS);
62 SECTION_INFO (STR_OFFSETS);
63 SECTION_INFO (MACRO);
64 SECTION_INFO (RNGLISTS);
65 printf ("\n");
66 }
67
68 dwarf_end (dbg);
69 close (fd);
70 }
71
72 return 0;
73 }
74