1 /* Copyright (C) 2002, 2004 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
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/>. */
24 #include ELFUTILS_HEADER(dw)
29 static const Dwarf_Addr testaddr[] =
31 0x804842b, 0x804842c, 0x804843c, 0x8048459, 0x804845a,
32 0x804845b, 0x804845c, 0x8048460, 0x8048465, 0x8048466,
33 0x8048467, 0x8048468, 0x8048470, 0x8048471, 0x8048472
35 #define ntestaddr (sizeof (testaddr) / sizeof (testaddr[0]))
39 main (int argc, char *argv[])
44 for (cnt = 1; cnt < argc; ++cnt)
46 int fd = open (argv[cnt], O_RDONLY);
48 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
51 printf ("%s not usable\n", argv[cnt]);
57 Dwarf_Aranges *aranges;
59 if (dwarf_getaranges (dbg, &aranges, &naranges) != 0)
60 printf ("%s: cannot get aranges\n", argv[cnt]);
63 for (size_t i = 0; i < ntestaddr; ++i)
67 found = dwarf_getarange_addr (aranges, testaddr[i]);
72 if (dwarf_getarangeinfo (found, NULL, NULL, &cu_offset) != 0)
74 puts ("failed to get CU die offset");
82 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
83 || (cuname = dwarf_diename (&cu_die)) == NULL)
85 puts ("failed to get CU die");
89 printf ("CU name: \"%s\"\n", cuname);
93 printf ("%#llx: not in range\n",
94 (unsigned long long int) testaddr[i]);
97 for (size_t i = 0; i < naranges; ++i)
99 Dwarf_Arange *arange = dwarf_onearange (aranges, i);
102 printf ("cannot get arange %zu: %s\n", i, dwarf_errmsg (-1));
110 if (dwarf_getarangeinfo (arange, &start, &length, &cu_offset)
113 printf ("cannot get info from aranges[%zu]\n", i);
118 printf (" [%2zu] start: %#llx, length: %llu, cu: %llu\n",
119 i, (unsigned long long int) start,
120 (unsigned long long int) length,
121 (unsigned long long int) cu_offset);
125 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
126 || (cuname = dwarf_diename (&cu_die)) == NULL)
128 puts ("failed to get CU die");
132 printf ("CU name: \"%s\"\n", cuname);