1 /* Copyright (C) 2002, 2004 Red Hat, Inc.
2 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
20 #include ELFUTILS_HEADER(dw)
25 static const Dwarf_Addr testaddr[] =
27 0x804842b, 0x804842c, 0x804843c, 0x8048459, 0x804845a,
28 0x804845b, 0x804845c, 0x8048460, 0x8048465, 0x8048466,
29 0x8048467, 0x8048468, 0x8048470, 0x8048471, 0x8048472
31 #define ntestaddr (sizeof (testaddr) / sizeof (testaddr[0]))
35 main (int argc, char *argv[])
40 for (cnt = 1; cnt < argc; ++cnt)
42 int fd = open (argv[cnt], O_RDONLY);
44 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
47 printf ("%s not usable\n", argv[cnt]);
53 Dwarf_Aranges *aranges;
55 if (dwarf_getaranges (dbg, &aranges, &naranges) != 0)
56 printf ("%s: cannot get aranges\n", argv[cnt]);
59 for (size_t i = 0; i < ntestaddr; ++i)
63 found = dwarf_getarange_addr (aranges, testaddr[i]);
68 if (dwarf_getarangeinfo (found, NULL, NULL, &cu_offset) != 0)
70 puts ("failed to get CU die offset");
78 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
79 || (cuname = dwarf_diename (&cu_die)) == NULL)
81 puts ("failed to get CU die");
85 printf ("CU name: \"%s\"\n", cuname);
89 printf ("%#llx: not in range\n",
90 (unsigned long long int) testaddr[i]);
93 for (size_t i = 0; i < naranges; ++i)
95 Dwarf_Arange *arange = dwarf_onearange (aranges, i);
98 printf ("cannot get arange %zu: %s\n", i, dwarf_errmsg (-1));
106 if (dwarf_getarangeinfo (arange, &start, &length, &cu_offset)
109 printf ("cannot get info from aranges[%zu]\n", i);
114 printf (" [%2zu] start: %#llx, length: %llu, cu: %llu\n",
115 i, (unsigned long long int) start,
116 (unsigned long long int) length,
117 (unsigned long long int) cu_offset);
121 if (dwarf_offdie (dbg, cu_offset, &cu_die) == NULL
122 || (cuname = dwarf_diename (&cu_die)) == NULL)
124 puts ("failed to get CU die");
128 printf ("CU name: \"%s\"\n", cuname);