File fixup-2-gdb-rhbz1156192-recursive-dlopen-test.patch of Package gdb.17657

Fixup gdb-rhbz1156192-recursive-dlopen-test.patch

- Fix __malloc_check usage to fix "free: invalid pointer" error with
  GLIBC_TUNABLES=glibc.malloc.check=3.
- Handle older libc, for which we run into glibc PR17702:
  Inconsistency detected by ld.so: dl-open.c: 222: dl_open_worker: Assertion \
  `_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT' failed!

---
 gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c |  1 +
 .../gdb.base/gdb-rhbz1156192-recursive-dlopen.exp         | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c
index 17b29904ef..7696666c16 100644
--- a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c
@@ -94,6 +94,7 @@ custom_malloc_hook (size_t size, const void *caller)
   /* Called recursively.  */
   result = malloc (size);
   /* Restore new hooks.  */
+  old_malloc_hook = __malloc_hook;
   __malloc_hook = custom_malloc_hook;
   return result;
 }
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp
index 6e4d3621a3..28e6e465ee 100644
--- a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp
@@ -49,6 +49,21 @@ if { [prepare_for_testing ${testfile}.exp ${executable} ${srcfile} \
     return -1
 }
 
+set supported 0
+gdb_test_multiple "run" "initial trial run" {
+    -re -wrap "exited normally.*" {
+	set supported 1
+	pass $gdb_test_name
+    }
+    -re -wrap "exited with code.*" {
+	untested "failed at $gdb_test_name"
+    }
+}
+
+if { $supported == 0 } {
+    return -1
+}
+
 proc do_test { has_libfoo has_libbar } {
   global hex binfile_lib2 binfile_lib1 gdb_prompt
   set libbar_match "[string_to_regexp $binfile_lib2]"
openSUSE Build Service is sponsored by