1 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
2 This file is part of Red Hat elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 1998.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat 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 GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 Red Hat elfutils is an included package of the Open Invention Network.
19 An included package of the Open Invention Network is a package for which
20 Open Invention Network licensees cross-license their patents. No patent
21 license is granted, either expressly or impliedly, by designation as an
22 included package. Should you wish to participate in the Open Invention
23 Network licensing program, please visit www.openinventionnetwork.com
24 <http://www.openinventionnetwork.com>. */
30 #include ELFUTILS_HEADER(dw)
36 main (int argc, char *argv[])
40 for (cnt = 1; cnt < argc; ++cnt)
42 int fd = open (argv[cnt], O_RDONLY);
43 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
46 printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
52 Dwarf_Off old_cuoff = 0;
54 while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, NULL, NULL, NULL) == 0)
56 /* Get the DIE for the CU. */
58 if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL)
59 /* Something went wrong. */
67 Dwarf_Abbrev *abbrev = dwarf_getabbrev (&die, offset, &length);
68 if (abbrev == NULL || abbrev == DWARF_END_ABBREV)
69 /* End of the list. */
72 unsigned tag = dwarf_getabbrevtag (abbrev);
75 printf ("dwarf_getabbrevtag at offset %llu returned error: %s\n",
76 (unsigned long long int) offset,
81 unsigned code = dwarf_getabbrevcode (abbrev);
84 printf ("dwarf_getabbrevcode at offset %llu returned error: %s\n",
85 (unsigned long long int) offset,
90 int children = dwarf_abbrevhaschildren (abbrev);
93 printf ("dwarf_abbrevhaschildren at offset %llu returned error: %s\n",
94 (unsigned long long int) offset,
99 printf ("abbrev[%llu]: code = %u, tag = %u, children = %d\n",
100 (unsigned long long int) offset, code, tag, children);
103 if (dwarf_getattrcnt (abbrev, &attrcnt) != 0)
105 printf ("dwarf_getattrcnt at offset %llu returned error: %s\n",
106 (unsigned long long int) offset,
111 unsigned int attr_num;
112 unsigned int attr_form;
115 for (j = 0; j < attrcnt; ++j)
116 if (dwarf_getabbrevattr (abbrev, j, &attr_num, &attr_form,
118 printf ("dwarf_getabbrevattr for abbrev[%llu] and index %zu failed\n",
119 (unsigned long long int) offset, j);
121 printf ("abbrev[%llu]: attr[%zu]: code = %u, form = %u, offset = %" PRIu64 "\n",
122 (unsigned long long int) offset, j, attr_num,
123 attr_form, (uint64_t) aboffset);
131 if (dwarf_end (dbg) != 0)
132 printf ("dwarf_end failed for %s: %s\n", argv[cnt],