clang can create "same file split DWARF" with -gsplit-dwarf=single.
This will produce plain DWARF and DWO debug sections in the same file.

Use dwarf_begin_type with DWARF_T_DWO in try_split_file to support
this (without DWARF_T_DWO the "plain" Dwarf would "win").

Add a simple testfile-frob-single and add a run-unit-info.sh check to
see the split DWARF is found.

        * libdw/libdw_find_split_unit.c (try_split_file): Use
        DWARF_T_DWO with dwarf_begin_type. Use INTUSE for both
        dwarf_begin_type and dwarf_end.
        * tests/testfile-frob-single.bz2: New test file.
        * tests/run-unit-info.sh: Use testfile-frob-single for test.
        * tests/Makefile.am (EXTRA_DIST): Add testfile-frob-single.bz2

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdw/libdw_find_split_unit.c  |   5 +++--
 tests/Makefile.am              |   1 +
 tests/run-unit-info.sh         |  17 +++++++++++++++++
 tests/testfile-frob-single.bz2 | Bin 0 -> 1139 bytes
 4 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 tests/testfile-frob-single.bz2

diff --git a/libdw/libdw_find_split_unit.c b/libdw/libdw_find_split_unit.c
index f4f34c5d9622..92a32f10a8c5 100644
--- a/libdw/libdw_find_split_unit.c
+++ b/libdw/libdw_find_split_unit.c
@@ -47,7 +47,8 @@ try_split_file (Dwarf_CU *cu, const char *dwo_path)
   int split_fd = open (dwo_path, O_RDONLY);
   if (split_fd != -1)
     {
-      Dwarf *split_dwarf = dwarf_begin (split_fd, DWARF_C_READ);
+      Dwarf *split_dwarf = INTUSE(dwarf_begin_type) (split_fd, DWARF_C_READ,
+                                                    DWARF_T_DWO);
       if (split_dwarf != NULL)
        {
          Dwarf_CU *split = NULL;
@@ -76,7 +77,7 @@ try_split_file (Dwarf_CU *cu, const char *dwo_path)
                }
            }
          if (cu->split == (Dwarf_CU *) -1)
-           dwarf_end (split_dwarf);
+           INTUSE (dwarf_end) (split_dwarf);
        }
       /* Always close, because we don't want to run out of file
         descriptors.  See also the elf_fcntl ELF_C_FDDONE call
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 06abcffed4a3..2a76d52bdb70 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -599,6 +599,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             run-attr-integrate-skel.sh \
             run-all-dwarf-ranges.sh testfilesplitranges4.debug.bz2 \
             testfile-ranges-hello.dwo.bz2 testfile-ranges-world.dwo.bz2 \
+            testfile-frob-single.bz2 \
             run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh \
             testfile-riscv64.bz2 testfile-riscv64-s.bz2 \
             testfile-riscv64-core.bz2 \
diff --git a/tests/run-unit-info.sh b/tests/run-unit-info.sh
index 158b633d311f..cbdd42322769 100755
--- a/tests/run-unit-info.sh
+++ b/tests/run-unit-info.sh
@@ -79,6 +79,23 @@ Iterate no info, compare recorded info with dwarf_cu_info.
 
 EOF
 
+# Single file split-dwarf. dwo sections in the plain debug file.
+#
+# echo "int frob (void) { return 42; }" \
+# | clang -g -gsplit-dwarf=single -xc - -c -o testfile-frob-single
+testfiles testfile-frob-single
+testrun_compare ${abs_builddir}/unit-info testfile-frob-single <<\EOF
+file: testfile-frob-single
+Iterate getting all info, compare with dwarf_cu_info.
+0 cu dietag: 4a, subtag: 11, version 5, unit_type 4
+0 subdietag: 11, subtag: 0, version 5, unit_type 5
+rechecking: testfile-frob-single
+Iterate no info, compare recorded info with dwarf_cu_info.
+0 re dietag: 4a, subtag: 11, version 5, unit_type 4
+0 subdietag: 11, subtag: 0, version 5, unit_type 5
+
+EOF
+
 # Self test (not on obj files, since those need relocation first).
 testrun_on_self_exe ${abs_builddir}/unit-info
 testrun_on_self_lib ${abs_builddir}/unit-info
diff --git a/tests/testfile-frob-single.bz2 b/tests/testfile-frob-single.bz2
new file mode 100644
index 
0000000000000000000000000000000000000000..3510d74d06ff39785d3ca8597a9a650caa797715
GIT binary patch
literal 1139
zcmV-(1dRJaT4*^jL0KkKS$$a<=Kus&|NsC0|Ns8`_uc#bw_5-2-|*RRL{LXSMMfw@
zKolYm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