1 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 1998.
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.
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.
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/>. */
22 #include ELFUTILS_HEADER(dw)
28 main (int argc, char *argv[])
32 for (cnt = 1; cnt < argc; ++cnt)
34 int fd = open (argv[cnt], O_RDONLY);
35 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
38 printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
44 Dwarf_Off old_cuoff = 0;
46 while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, NULL, NULL, NULL) == 0)
48 /* Get the DIE for the CU. */
50 if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL)
51 /* Something went wrong. */
59 Dwarf_Abbrev *abbrev = dwarf_getabbrev (&die, offset, &length);
60 if (abbrev == NULL || abbrev == DWARF_END_ABBREV)
61 /* End of the list. */
64 unsigned tag = dwarf_getabbrevtag (abbrev);
67 printf ("dwarf_getabbrevtag at offset %llu returned error: %s\n",
68 (unsigned long long int) offset,
73 unsigned code = dwarf_getabbrevcode (abbrev);
76 printf ("dwarf_getabbrevcode at offset %llu returned error: %s\n",
77 (unsigned long long int) offset,
82 int children = dwarf_abbrevhaschildren (abbrev);
85 printf ("dwarf_abbrevhaschildren at offset %llu returned error: %s\n",
86 (unsigned long long int) offset,
91 printf ("abbrev[%llu]: code = %u, tag = %u, children = %d\n",
92 (unsigned long long int) offset, code, tag, children);
95 if (dwarf_getattrcnt (abbrev, &attrcnt) != 0)
97 printf ("dwarf_getattrcnt at offset %llu returned error: %s\n",
98 (unsigned long long int) offset,
103 unsigned int attr_num;
104 unsigned int attr_form;
107 for (j = 0; j < attrcnt; ++j)
108 if (dwarf_getabbrevattr (abbrev, j, &attr_num, &attr_form,
110 printf ("dwarf_getabbrevattr for abbrev[%llu] and index %zu failed\n",
111 (unsigned long long int) offset, j);
113 printf ("abbrev[%llu]: attr[%zu]: code = %u, form = %u, offset = %" PRIu64 "\n",
114 (unsigned long long int) offset, j, attr_num,
115 attr_form, (uint64_t) aboffset);
123 if (dwarf_end (dbg) != 0)
124 printf ("dwarf_end failed for %s: %s\n", argv[cnt],