1*7304104dSAndroid Build Coastguard Worker /* Test all DW_LANG constants are handled by dwarf_default_lower_bound.
2*7304104dSAndroid Build Coastguard Worker
3*7304104dSAndroid Build Coastguard Worker Copyright (C) 2016 Red Hat, Inc.
4*7304104dSAndroid Build Coastguard Worker This file is part of elfutils.
5*7304104dSAndroid Build Coastguard Worker
6*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify
7*7304104dSAndroid Build Coastguard Worker it under the terms of the GNU General Public License as published by
8*7304104dSAndroid Build Coastguard Worker the Free Software Foundation; either version 3 of the License, or
9*7304104dSAndroid Build Coastguard Worker (at your option) any later version.
10*7304104dSAndroid Build Coastguard Worker
11*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but
12*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of
13*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*7304104dSAndroid Build Coastguard Worker GNU General Public License for more details.
15*7304104dSAndroid Build Coastguard Worker
16*7304104dSAndroid Build Coastguard Worker You should have received a copy of the GNU General Public License
17*7304104dSAndroid Build Coastguard Worker along with this program. If not, see <http://www.gnu.org/licenses/>. */
18*7304104dSAndroid Build Coastguard Worker
19*7304104dSAndroid Build Coastguard Worker #ifdef HAVE_CONFIG_H
20*7304104dSAndroid Build Coastguard Worker # include <config.h>
21*7304104dSAndroid Build Coastguard Worker #endif
22*7304104dSAndroid Build Coastguard Worker
23*7304104dSAndroid Build Coastguard Worker #include <dwarf.h>
24*7304104dSAndroid Build Coastguard Worker #include ELFUTILS_HEADER(dw)
25*7304104dSAndroid Build Coastguard Worker #include "../libdw/known-dwarf.h"
26*7304104dSAndroid Build Coastguard Worker
27*7304104dSAndroid Build Coastguard Worker #include <inttypes.h>
28*7304104dSAndroid Build Coastguard Worker #include <stdio.h>
29*7304104dSAndroid Build Coastguard Worker #include <stdlib.h>
30*7304104dSAndroid Build Coastguard Worker
31*7304104dSAndroid Build Coastguard Worker static void
test_lang(const char * name,int lang)32*7304104dSAndroid Build Coastguard Worker test_lang (const char *name, int lang)
33*7304104dSAndroid Build Coastguard Worker {
34*7304104dSAndroid Build Coastguard Worker Dwarf_Sword low;
35*7304104dSAndroid Build Coastguard Worker int res = dwarf_default_lower_bound (lang, &low);
36*7304104dSAndroid Build Coastguard Worker
37*7304104dSAndroid Build Coastguard Worker /* Assembler is special, it doesn't really have arrays. */
38*7304104dSAndroid Build Coastguard Worker if (lang == DW_LANG_Mips_Assembler)
39*7304104dSAndroid Build Coastguard Worker {
40*7304104dSAndroid Build Coastguard Worker if (res == 0)
41*7304104dSAndroid Build Coastguard Worker {
42*7304104dSAndroid Build Coastguard Worker printf ("%s shouldn't have a known lower bound\n", name);
43*7304104dSAndroid Build Coastguard Worker exit (-1);
44*7304104dSAndroid Build Coastguard Worker }
45*7304104dSAndroid Build Coastguard Worker printf ("%s: <unknown>\n", name);
46*7304104dSAndroid Build Coastguard Worker return;
47*7304104dSAndroid Build Coastguard Worker }
48*7304104dSAndroid Build Coastguard Worker
49*7304104dSAndroid Build Coastguard Worker if (res != 0)
50*7304104dSAndroid Build Coastguard Worker {
51*7304104dSAndroid Build Coastguard Worker printf ("dwarf_default_lower_bound failed (%d) for %s\n", res, name);
52*7304104dSAndroid Build Coastguard Worker exit (-1);
53*7304104dSAndroid Build Coastguard Worker }
54*7304104dSAndroid Build Coastguard Worker
55*7304104dSAndroid Build Coastguard Worker /* All currently known lower bounds are either zero or one, but
56*7304104dSAndroid Build Coastguard Worker they don't have to. Update test once one is a different value. */
57*7304104dSAndroid Build Coastguard Worker if (low != 0 && low != 1)
58*7304104dSAndroid Build Coastguard Worker {
59*7304104dSAndroid Build Coastguard Worker printf ("unexpected lower bound %" PRId64 " for %s\n", low, name);
60*7304104dSAndroid Build Coastguard Worker exit (-1);
61*7304104dSAndroid Build Coastguard Worker }
62*7304104dSAndroid Build Coastguard Worker
63*7304104dSAndroid Build Coastguard Worker printf ("%s: %" PRId64 "\n", name, low);
64*7304104dSAndroid Build Coastguard Worker }
65*7304104dSAndroid Build Coastguard Worker
66*7304104dSAndroid Build Coastguard Worker int
main(int argc,char * argv[])67*7304104dSAndroid Build Coastguard Worker main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused)))
68*7304104dSAndroid Build Coastguard Worker {
69*7304104dSAndroid Build Coastguard Worker Dwarf_Sword low;
70*7304104dSAndroid Build Coastguard Worker /* Bad language code must fail. */
71*7304104dSAndroid Build Coastguard Worker if (dwarf_default_lower_bound (-1, &low) == 0)
72*7304104dSAndroid Build Coastguard Worker {
73*7304104dSAndroid Build Coastguard Worker printf ("Bad lang code -1 succeeded (%" PRId64 ")\n", low);
74*7304104dSAndroid Build Coastguard Worker exit (-1);
75*7304104dSAndroid Build Coastguard Worker }
76*7304104dSAndroid Build Coastguard Worker
77*7304104dSAndroid Build Coastguard Worker /* Test all known language codes. */
78*7304104dSAndroid Build Coastguard Worker #define DWARF_ONE_KNOWN_DW_LANG(NAME, CODE) test_lang (#NAME, CODE);
79*7304104dSAndroid Build Coastguard Worker DWARF_ALL_KNOWN_DW_LANG
80*7304104dSAndroid Build Coastguard Worker #undef DWARF_ONE_KNOWN_DW_LANG
81*7304104dSAndroid Build Coastguard Worker
82*7304104dSAndroid Build Coastguard Worker return 0;
83*7304104dSAndroid Build Coastguard Worker }
84