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