1 /* Test dwarf_cu_info properties.
2 Copyright (C) 2018 Red Hat, Inc.
3 This file is part of elfutils.
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/>. */
23 #include ELFUTILS_HEADER(dw)
26 #include <sys/types.h>
31 /* Yeah, lazy, 16K CUs should be enough for everybody... */
32 #define MAX_UNITS 16384
43 static struct info unit_info[MAX_UNITS];
46 main (int argc, char *argv[])
48 for (int i = 1; i < argc; i++)
50 printf ("file: %s\n", argv[i]);
51 int fd = open (argv[i], O_RDONLY);
52 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
55 printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1));
61 Dwarf_Die cudie, subdie;
65 printf ("Iterate getting all info, compare with dwarf_cu_info.\n");
66 while (dwarf_get_units (dbg, cu, &cu, &version,
67 &unit_type, &cudie, &subdie) == 0)
69 int dietag = dwarf_tag (&cudie);
70 int subtag = dwarf_tag (&subdie);
72 unit_info[u].dietag = dietag;
73 unit_info[u].subtag = subtag;
74 unit_info[u].version = version;
75 unit_info[u].unit_type = unit_type;
77 printf ("%zu cu dietag: %x, subtag: %x, version %" PRIx32
78 ", unit_type %" PRIx8 "\n",
79 u, dietag, subtag, version, unit_type);
82 uint8_t addr_size, off_size;
83 if (dwarf_cu_info (cu,
84 &version, &unit_type, &cudie, &subdie,
85 &unit_id, &addr_size, &off_size) != 0)
87 printf ("Invalid dwarf_cu_info: %s\n", dwarf_errmsg (-1));
91 dietag = dwarf_tag (&cudie);
92 subtag = dwarf_tag (&subdie);
94 if (unit_info[u].dietag != dietag)
96 printf("Unequal dietags\n");
100 if (unit_info[u].subtag != subtag)
102 printf("Unequal subtags\n");
106 if (unit_info[u].version != version)
108 printf("Unequal versions\n");
112 if (unit_info[u].unit_type != unit_type)
114 printf("Unequal unit_types\n");
118 unit_info[u].id = unit_id;
119 unit_info[u].addr_size = addr_size;
120 unit_info[u].off_size = off_size;
122 if (unit_type == DW_UT_skeleton)
124 if (dwarf_cu_info (subdie.cu,
125 &version, &unit_type, &cudie, &subdie,
126 &unit_id, &addr_size, &off_size) != 0)
128 printf ("Invalid subdie dwarf_cu_info: %s\n",
133 dietag = dwarf_tag (&cudie);
134 subtag = dwarf_tag (&subdie);
136 printf ("%zu subdietag: %x, subtag: %x, version %" PRIx32
137 ", unit_type %" PRIx8 "\n",
138 u, dietag, subtag, version, unit_type);
140 /* subdie is now cudie. */
141 if (unit_info[u].subtag != dietag)
143 printf ("Inconsistent subdie tag\n");
147 if (unit_info[u].id != unit_id)
149 printf ("Unequal subdie ids\n");
153 if (unit_info[u].addr_size != addr_size)
155 printf ("Unequal subdie addr_size\n");
159 if (unit_info[u].off_size != off_size)
161 printf ("Unequal subdie off_size\n");
168 printf ("Oops, more than 16K units...\n");
178 printf ("rechecking: %s\n", argv[i]);
179 fd = open (argv[i], O_RDONLY);
180 dbg = dwarf_begin (fd, DWARF_C_READ);
183 printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1));
189 printf ("Iterate no info, compare recorded info with dwarf_cu_info.\n");
190 while (dwarf_get_units (dbg, cu, &cu, NULL, NULL, NULL, NULL) == 0)
194 printf ("Got too many units???\n");
199 uint8_t addr_size, off_size;
200 if (dwarf_cu_info (cu,
201 &version, &unit_type, &cudie, &subdie,
202 &unit_id, &addr_size, &off_size) != 0)
204 printf ("Invalid dwarf_cu_info: %s\n", dwarf_errmsg (-1));
208 int dietag = dwarf_tag (&cudie);
209 int subtag = dwarf_tag (&subdie);
211 printf ("%zu re dietag: %x, subtag: %x, version %" PRIx32
212 ", unit_type %" PRIx8 "\n",
213 u, dietag, subtag, version, unit_type);
215 if (unit_info[u].dietag != dietag)
217 printf("Unequal dietags %x != %x\n", unit_info[u].dietag, dietag);
221 if (unit_info[u].subtag != subtag)
223 printf("Unequal subtags\n");
227 if (unit_info[u].version != version)
229 printf("Unequal versions\n");
233 if (unit_info[u].unit_type != unit_type)
235 printf("Unequal unit_types\n");
239 if (unit_info[u].id != unit_id)
241 printf ("Unequal subdie ids\n");
245 if (unit_info[u].addr_size != addr_size)
247 printf ("Unequal subdie addr_size\n");
251 if (unit_info[u].off_size != off_size)
253 printf ("Unequal subdie off_size\n");
257 if (unit_type == DW_UT_skeleton)
259 if (dwarf_cu_info (subdie.cu,
260 &version, &unit_type, &cudie, &subdie,
261 &unit_id, &addr_size, &off_size) != 0)
263 printf ("Invalid subdie dwarf_cu_info: %s\n",
268 dietag = dwarf_tag (&cudie);
269 subtag = dwarf_tag (&subdie);
271 printf ("%zu subdietag: %x, subtag: %x, version %" PRIx32
272 ", unit_type %" PRIx8 "\n",
273 u, dietag, subtag, version, unit_type);
275 /* subdie is now cudie. */
276 subtag = dwarf_tag (&cudie);
277 if (unit_info[u].subtag != subtag)
279 printf ("Inconsistent subdie tag\n");
283 if (unit_info[u].id != unit_id)
285 printf ("Unequal subdie ids\n");
289 if (unit_info[u].addr_size != addr_size)
291 printf ("Unequal subdie addr_size\n");
295 if (unit_info[u].off_size != off_size)
297 printf ("Unequal subdie off_size\n");
304 printf ("Oops, more than 16K units...\n");
312 printf ("Got not enough units???\n");