#define ndwarf_scnnames (sizeof (dwarf_scnnames) / sizeof (dwarf_scnnames[0]))
static Dwarf *
-check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
+check_section (Dwarf *result, size_t shstrndx, Elf_Scn *scn, bool inscngrp)
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr;
/* We recognize the DWARF section by their names. This is not very
safe and stable but the best we can do. */
- const char *scnname = elf_strptr (result->elf, ehdr->e_shstrndx,
+ const char *scnname = elf_strptr (result->elf, shstrndx,
shdr->sh_name);
if (scnname == NULL)
{
static Dwarf *
-global_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr)
+global_read (Dwarf *result, Elf *elf, size_t shstrndx)
{
Elf_Scn *scn = NULL;
while (result != NULL && (scn = elf_nextscn (elf, scn)) != NULL)
- result = check_section (result, ehdr, scn, false);
+ result = check_section (result, shstrndx, scn, false);
return valid_p (result);
}
static Dwarf *
-scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, Elf_Scn *scngrp)
+scngrp_read (Dwarf *result, Elf *elf, size_t shstrndx, Elf_Scn *scngrp)
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scngrp, &shdr_mem);
return NULL;
}
- result = check_section (result, ehdr, scn, true);
+ result = check_section (result, shstrndx, scn, true);
if (result == NULL)
break;
}
if (cmd == DWARF_C_READ || cmd == DWARF_C_RDWR)
{
+ /* All sections are recognized by name, so pass the section header
+ string index along to easily get the section names. */
+ size_t shstrndx;
+ if (elf_getshdrstrndx (elf, &shstrndx) != 0)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ return NULL;
+ }
+
/* If the caller provides a section group we get the DWARF
sections only from this setion group. Otherwise we search
for the first section with the required name. Further
sections with the name are ignored. The DWARF specification
does not really say this is allowed. */
if (scngrp == NULL)
- return global_read (result, elf, ehdr);
+ return global_read (result, elf, shstrndx);
else
- return scngrp_read (result, elf, ehdr, scngrp);
+ return scngrp_read (result, elf, shstrndx, scngrp);
}
else if (cmd == DWARF_C_WRITE)
{
run-all-dwarf-ranges.sh run-unit-info.sh \
run-reloc-bpf.sh \
run-next-cfi.sh run-next-cfi-self.sh \
- run-copyadd-sections.sh run-copymany-sections.sh
+ run-copyadd-sections.sh run-copymany-sections.sh \
+ run-typeiter-many.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh \
testfile-riscv64.bz2 testfile-riscv64-s.bz2 \
testfile-riscv64-core.bz2 \
- run-copyadd-sections.sh run-copymany-sections.sh
+ run-copyadd-sections.sh run-copymany-sections.sh \
+ run-typeiter-many.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2018 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/>.
+
+. $srcdir/test-subr.sh
+
+
+# Like run-typeiter.sh but we first add many sections to make sure
+# dwarf_begin actually recognizes the debug section names.
+testfiles testfile-debug-types
+
+testrun ${abs_builddir}/addsections 65535 testfile-debug-types
+testrun_compare ${abs_builddir}/typeiter2 testfile-debug-types <<\EOF
+ok A [68]
+ok B [38]
+EOF
+
+exit 0