1 /* Copyright (C) 2002, 2004 Red Hat, Inc.
2 This file is part of Red Hat elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
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>. */
32 #include ELFUTILS_HEADER(dw)
37 static const Dwarf_Addr testaddr[] =
39 0x804842b, 0x804842c, 0x804843c, 0x8048459, 0x804845a,
40 0x804845b, 0x804845c, 0x8048460, 0x8048465, 0x8048466,
41 0x8048467, 0x8048468, 0x8048470, 0x8048471, 0x8048472
43 #define ntestaddr (sizeof (testaddr) / sizeof (testaddr[0]))
47 main (int argc, char *argv[])
52 for (cnt = 1; cnt < argc; ++cnt)
54 int fd = open (argv[cnt], O_RDONLY);
56 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
59 printf ("%s not usable\n", argv[cnt]);
65 Dwarf_Aranges *aranges;
67 if (dwarf_getaranges (dbg, &aranges, &naranges) != 0)
68 printf ("%s: cannot get aranges\n", argv[cnt]);
71 for (size_t i = 0; i < ntestaddr; ++i)
75 found = dwarf_getarange_addr (aranges, testaddr[i]);
80 if (dwarf_getarangeinfo (found, NULL, NULL, &cu_offset) != 0)
82 puts ("failed to get CU die offset");
90 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
91 || (cuname = dwarf_diename (&cu_die)) == NULL)
93 puts ("failed to get CU die");
97 printf ("CU name: \"%s\"\n", cuname);
101 printf ("%#llx: not in range\n",
102 (unsigned long long int) testaddr[i]);
105 for (size_t i = 0; i < naranges; ++i)
107 Dwarf_Arange *arange = dwarf_onearange (aranges, i);
110 printf ("cannot get arange %zu: %s\n", i, dwarf_errmsg (-1));
118 if (dwarf_getarangeinfo (arange, &start, &length, &cu_offset)
121 printf ("cannot get info from aranges[%zu]\n", i);
126 printf (" [%2zu] start: %#llx, length: %llu, cu: %llu\n",
127 i, (unsigned long long int) start,
128 (unsigned long long int) length,
129 (unsigned long long int) cu_offset);
133 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
134 || (cuname = dwarf_diename (&cu_die)) == NULL)
136 puts ("failed to get CU die");
140 printf ("CU name: \"%s\"\n", cuname);