1 /* Test program for dwarf_lowpc and dwarf_highpc
2 Copyright (C) 2012 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/>. */
21 #include ELFUTILS_HEADER(dwfl)
25 #include <stdio_ext.h>
41 static struct args *args;
44 fail(Dwarf_Off off, const char *name, const char *msg)
46 printf("%s: [%" PRIx64 "] '%s' %s\n", args->file, off, name, msg);
51 handle_die (Dwarf_Die *die, void *arg)
54 Dwarf_Off off = dwarf_dieoffset (die);
56 const char *name = dwarf_diename (die);
58 fail (off, "<no name>", "die without a name");
61 Dwarf_Addr highpc = 0;
62 if (dwarf_lowpc (die, &lowpc) != 0 && dwarf_hasattr (die, DW_AT_low_pc))
63 fail (off, name, "has DW_AT_low_pc but dwarf_lowpc fails");
64 if (dwarf_highpc (die, &highpc) != 0 && dwarf_hasattr (die, DW_AT_high_pc))
65 fail (off, name, "has DW_AT_high_pc but dwarf_highpc fails");
67 /* GCC < 4.7 had a bug where no code CUs got a highpc == lowpc.
68 Allow that, because it is not the main purpose of this test. */
69 if (dwarf_hasattr (die, DW_AT_low_pc)
70 && dwarf_hasattr (die, DW_AT_high_pc)
72 && ! (dwarf_tag (die) == DW_TAG_compile_unit && highpc == lowpc))
74 printf("lowpc: %" PRIx64 ", highpc: %" PRIx64 "lx\n", lowpc, highpc);
75 fail (off, name, "highpc <= lowpc");
83 main (int argc, char *argv[])
88 (void) setlocale (LC_ALL, "");
90 struct args a = { .dwfl = NULL, .cu = NULL };
92 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining,
94 assert (a.dwfl != NULL);
95 a.argv = &argv[remaining];
99 while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL)
101 a.file = dwarf_diename (a.cu);
102 handle_die (a.cu, &a);
103 dwarf_getfuncs (a.cu, &handle_die, &a, 0);