f14b49355a0a6064ab4fda5a996adf7b96725c31
[platform/upstream/elfutils.git] / tests / allfcts.c
1 /* Copyright (C) 2005 Red Hat, Inc.
2    This file is part of elfutils.
3
4    This file is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    elfutils is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20
21 #include <fcntl.h>
22 #include ELFUTILS_HEADER(dw)
23 #include <stdio.h>
24 #include <unistd.h>
25
26
27 static int
28 cb (Dwarf_Die *func, void *arg __attribute__ ((unused)))
29 {
30   const char *file = dwarf_decl_file (func);
31   int line = -1;
32   dwarf_decl_line (func, &line);
33   const char *fct = dwarf_diename (func);
34
35   printf ("%s:%d:%s\n", file, line, fct);
36
37   return DWARF_CB_OK;
38 }
39
40
41 int
42 main (int argc, char *argv[])
43 {
44   for (int i = 1; i < argc; ++i)
45     {
46       int fd = open (argv[i], O_RDONLY);
47
48       Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
49       if (dbg != NULL)
50         {
51           Dwarf_Off off = 0;
52           size_t cuhl;
53           Dwarf_Off noff;
54
55           while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0)
56             {
57               Dwarf_Die die_mem;
58               Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem);
59
60               (void) dwarf_getfuncs (die, cb, NULL, 0);
61
62               off = noff;
63             }
64
65           dwarf_end (dbg);
66         }
67
68       close (fd);
69     }
70 }