blob: dff452609b416a21a450cb050064652244b66373 [file] [log] [blame]
Tom Tromey581c3f62012-03-21 08:54:32 -06001/* Copyright (C) 2012 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Tom Tromey581c3f62012-03-21 08:54:32 -06003
Mark Wielaardde2ed972012-06-05 17:15:16 +02004 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.
Tom Tromey581c3f62012-03-21 08:54:32 -06008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 elfutils is distributed in the hope that it will be useful, but
Tom Tromey581c3f62012-03-21 08:54:32 -060010 WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
Tom Tromey581c3f62012-03-21 08:54:32 -060013
Mark Wielaardde2ed972012-06-05 17:15:16 +020014 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/>. */
Tom Tromey581c3f62012-03-21 08:54:32 -060016
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#include <dwarf.h>
26
27int
28main (int argc, char *argv[])
29{
30 for (int i = 1; i < argc; ++i)
31 {
32 int fd = open (argv[i], O_RDONLY);
33
34 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
35 if (dbg != NULL)
36 {
37 Dwarf_Off off = 0;
38 size_t cuhl;
39 Dwarf_Off noff;
40
41 while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0)
42 {
43 Dwarf_Die die_mem;
44 Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem);
45
46 Dwarf_Die iter_mem;
47 Dwarf_Die *iter = &iter_mem;
48 dwarf_child (die, &iter_mem);
49
50 while (1)
51 {
52 if (dwarf_tag (iter) == DW_TAG_variable)
53 {
54 Dwarf_Attribute attr_mem;
55 Dwarf_Die form_mem;
56 dwarf_formref_die (dwarf_attr (iter, DW_AT_type,
57 &attr_mem),
58 &form_mem);
59 }
60
61 if (dwarf_siblingof (iter, &iter_mem) != 0)
62 break;
63 }
64
65 off = noff;
66 }
67
68 off = 0;
69 uint64_t type_sig;
70
71 while (dwarf_next_unit (dbg, off, &noff, &cuhl, NULL, NULL, NULL,
72 NULL, &type_sig, NULL) == 0)
73 {
74 Dwarf_Die die_mem;
75 Dwarf_Die *die = dwarf_offdie_types (dbg, off + cuhl, &die_mem);
76
77 if (die == NULL)
78 printf ("fail\n");
79 else
80 printf ("ok\n");
81
82 off = noff;
83 }
84
85 dwarf_end (dbg);
86 }
87
88 close (fd);
89 }
90}