diff options
author | Mark Wielaard <[email protected]> | 2017-07-26 18:06:21 +0200 |
---|---|---|
committer | Mark Wielaard <[email protected]> | 2017-08-02 13:51:51 +0200 |
commit | 2eb1e3485614f5a4d3cbe8f28efd0d0de980911f (patch) | |
tree | 60ac0cf9df51cf316d3f8ba3b72d0f988749eabc /tests | |
parent | d14fd3bc70b96f29c32e596511c5c8e6bedbb5ca (diff) |
libdw: Add dwarf_default_lower_bound.
Add dwarf_default_lower_bound to get the default lower bound for a language
when not given as attribute for an subrange type. Implementation extracted
from dwarf_aggregate_size.
Add a test to check all known language codes are handled.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ChangeLog | 7 | ||||
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/dwarf_default_lower_bound.c | 83 |
3 files changed, 93 insertions, 2 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 519f25a3..fa3f94ed 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2017-07-26 Mark Wielaard <[email protected]> + + * dwarf_default_lower_bound.c: New test. + * Makefile.am (check_PROGRAMS): Add dwarf_default_lower_bound. + (TESTS): Likewise. + (dwarf_default_lower_bound_LDADD): New variable. + 2017-07-21 Mark Wielaard <[email protected]> * get-lines.c (main): Add dwarf_line_file test. diff --git a/tests/Makefile.am b/tests/Makefile.am index 407c0511..3735084f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -55,7 +55,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ getsrc_die strptr newdata elfstrtab dwfl-proc-attach \ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ - fillfile + fillfile dwarf_default_lower_bound asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -135,7 +135,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh \ run-compress-test.sh \ run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \ - emptyfile vendorelf fillfile + emptyfile vendorelf fillfile dwarf_default_lower_bound if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -505,6 +505,7 @@ zstrptr_LDADD = $(libelf) emptyfile_LDADD = $(libelf) vendorelf_LDADD = $(libelf) fillfile_LDADD = $(libelf) +dwarf_default_lower_bound_LDADD = $(libdw) # We want to test the libelf header against the system elf.h header. # Don't include any -I CPPFLAGS. diff --git a/tests/dwarf_default_lower_bound.c b/tests/dwarf_default_lower_bound.c new file mode 100644 index 00000000..d57424fc --- /dev/null +++ b/tests/dwarf_default_lower_bound.c @@ -0,0 +1,83 @@ +/* Test all DW_LANG constants are handled by dwarf_default_lower_bound. + + Copyright (C) 2016 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <dwarf.h> +#include ELFUTILS_HEADER(dw) +#include "../libdw/known-dwarf.h" + +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> + +static void +test_lang (const char *name, int lang) +{ + Dwarf_Sword low; + int res = dwarf_default_lower_bound (lang, &low); + + /* Assembler is special, it doesn't really have arrays. */ + if (lang == DW_LANG_Mips_Assembler) + { + if (res == 0) + { + printf ("%s shouldn't have a known lower bound\n", name); + exit (-1); + } + printf ("%s: <unknown>\n", name); + return; + } + + if (res != 0) + { + printf ("dwarf_default_lower_bound failed (%d) for %s\n", res, name); + exit (-1); + } + + /* All currently known lower bounds are either zero or one, but + they don't have to. Update test once one is a different value. */ + if (low != 0 && low != 1) + { + printf ("unexpected lower bound %" PRId64 " for %s\n", low, name); + exit (-1); + } + + printf ("%s: %" PRId64 "\n", name, low); +} + +int +main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused))) +{ + Dwarf_Sword low; + /* Bad language code must fail. */ + if (dwarf_default_lower_bound (-1, &low) == 0) + { + printf ("Bad lang code -1 succeeded (%" PRId64 ")\n", low); + exit (-1); + } + + /* Test all known language codes. */ +#define DWARF_ONE_KNOWN_DW_LANG(NAME, CODE) test_lang (#NAME, CODE); + DWARF_ALL_KNOWN_DW_LANG +#undef DWARF_ONE_KNOWN_DW_LANG + + return 0; +} |