diff options
| author | Mark Wielaard <[email protected]> | 2025-01-30 18:53:25 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2025-03-09 00:11:08 +0100 |
| commit | 48f32e91524119ef40bce33b1bcc7b6687f9a892 (patch) | |
| tree | 1b93c42d99b833dec4625b55a53a2dadb32b46f8 /tests | |
| parent | f49baa1febcb36707cb5acf9974a4faf269a98d6 (diff) | |
libdw: Add dwarf_language and dwarf_language_lower_bound functions.
dwarf_language returns a DW_LNAME constant for a CU Die. If the CU Die
has a DW_AT_language_name attribute dwarf_language will return it and
the DW_AT_language_version attribute value. Otherwise dwarf_language
will lookup the (old style) DW_AT_language attribute and translate the
DW_LANG constant into a DW_LNAME constant and version using a new
static function srclang_to_language.
The dwarf_language_lower_bound function works just like the
dwarf_default_lower_bound function, but takes a DW_LNAME constant
instead of a DW_LANG constant.
Adds a new test to make sure dwarf_language_lower_bound handles all
known DW_LNAME constants.
* NEWS: Add new functions.
* libdw/libdw.map (ELFUTILS_0.193): New section with new functions.
* libdw/libdw.h (dwarf_srclang): Add comment explaining this
returns DW_LANG constants.
(dwarf_language): New function.
(dwarf_default_lower_bound): Add comment explaining this works on
DW_LANG constants.
(dwarf_language_lower_bound): New function.
* libdw/libdwP.h: INTDECL dwarf_language and
dwarf_language_lower_bound.
* libdw/dwarf_srclang.c (srclang_to_language): New function.
(dwarf_language): Likewise.
* libdw/dwarf_default_lower_bound.c (dwarf_language_lower_bound):
New function.
* libdw/dwarf_getfuncs.c (dwarf_getfuncs): Use dwarf_language and
dwarf_language_lower_bound.
* libdw/dwarf_aggregate_size.c (array_size): Likewise.
* tests/dwarf_language_lower_bound.c: New test.
* tests/Makefile.am (check_PROGRAMS): Add dwarf_language_lower_bound.
(TESTS): Likewise.
(dwarf_language_lower_bound_LDADD): New variable.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile.am | 5 | ||||
| -rw-r--r-- | tests/dwarf_language_lower_bound.c | 72 |
2 files changed, 76 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 335f1925..bf5a9b22 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,7 +56,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ elfstrtab dwfl-proc-attach \ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ - fillfile dwarf_default_lower_bound dwarf-die-addr-die \ + fillfile dwarf_default_lower_bound \ + dwarf_language_lower_bound dwarf-die-addr-die \ get-units-invalid get-units-split attr-integrate-skel \ all-dwarf-ranges unit-info next_cfi \ elfcopy addsections xlate_notes elfrdwrnop \ @@ -203,6 +204,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-compress-test.sh \ run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \ emptyfile vendorelf fillfile dwarf_default_lower_bound \ + dwarf_language_lower_bound \ run-dwarf-die-addr-die.sh \ run-get-units-invalid.sh run-get-units-split.sh \ run-attr-integrate-skel.sh \ @@ -864,6 +866,7 @@ emptyfile_LDADD = $(libelf) vendorelf_LDADD = $(libelf) fillfile_LDADD = $(libelf) dwarf_default_lower_bound_LDADD = $(libdw) +dwarf_language_lower_bound_LDADD = $(libdw) dwarf_die_addr_die_LDADD = $(libdw) get_units_invalid_LDADD = $(libdw) get_units_split_LDADD = $(libdw) diff --git a/tests/dwarf_language_lower_bound.c b/tests/dwarf_language_lower_bound.c new file mode 100644 index 00000000..6bb534ac --- /dev/null +++ b/tests/dwarf_language_lower_bound.c @@ -0,0 +1,72 @@ +/* Test all DW_LNAME constants are handled by dwarf_language_lower_bound. + + Copyright (C) 2016 Red Hat, Inc. + Copyright (C) 2024, 2025 Mark J. Wielaard <[email protected]> + 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, Dwarf_Word lang) +{ + Dwarf_Sword low; + int res = dwarf_language_lower_bound (lang, &low); + + if (res != 0) + { + printf ("dwarf_language_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_language_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_LNAME(NAME, CODE) test_lang (#NAME, CODE); + DWARF_ALL_KNOWN_DW_LNAME +#undef DWARF_ONE_KNOWN_DW_LNAME + + return 0; +} |
