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