4c2ad1
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
4c2ad1
From: Fedora GDB patches <invalid@email.com>
4c2ad1
Date: Fri, 27 Oct 2017 21:07:50 +0200
4c2ad1
Subject: gdb-rhbz1325795-framefilters-test.patch
4c2ad1
4c2ad1
;; New test for Python "Cannot locate object file for block" (for RH BZ 1325795).
4c2ad1
;;=fedoratest
4c2ad1
4c2ad1
diff --git a/gdb/testsuite/gdb.python/py-framefilter-thread.c b/gdb/testsuite/gdb.python/py-framefilter-thread.c
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.python/py-framefilter-thread.c
4c2ad1
@@ -0,0 +1,39 @@
4c2ad1
+/* This testcase is part of GDB, the GNU debugger.
4c2ad1
+
4c2ad1
+   Copyright 2016 Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+   This program is free software; you can redistribute it and/or modify
4c2ad1
+   it under the terms of the GNU General Public License as published by
4c2ad1
+   the Free Software Foundation; either version 3 of the License, or
4c2ad1
+   (at your option) any later version.
4c2ad1
+
4c2ad1
+   This program is distributed in the hope that it will be useful,
4c2ad1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+   GNU General Public License for more details.
4c2ad1
+
4c2ad1
+   You should have received a copy of the GNU General Public License
4c2ad1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
4c2ad1
+
4c2ad1
+#include <pthread.h>
4c2ad1
+#include <assert.h>
4c2ad1
+
4c2ad1
+static void *
4c2ad1
+start (void *arg)
4c2ad1
+{
4c2ad1
+  return arg; /* Backtrace end breakpoint */
4c2ad1
+}
4c2ad1
+
4c2ad1
+int
4c2ad1
+main (void)
4c2ad1
+{
4c2ad1
+  pthread_t thread1;
4c2ad1
+  int i;
4c2ad1
+
4c2ad1
+  i = pthread_create (&thread1, NULL, start, NULL);
4c2ad1
+  assert (i == 0);
4c2ad1
+  i = pthread_join (thread1, NULL);
4c2ad1
+  assert (i == 0);
4c2ad1
+
4c2ad1
+  return 0;
4c2ad1
+}
4c2ad1
diff --git a/gdb/testsuite/gdb.python/py-framefilter-thread.exp b/gdb/testsuite/gdb.python/py-framefilter-thread.exp
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.python/py-framefilter-thread.exp
4c2ad1
@@ -0,0 +1,54 @@
4c2ad1
+# Copyright (C) 2016 Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+# This program is free software; you can redistribute it and/or modify
4c2ad1
+# it under the terms of the GNU General Public License as published by
4c2ad1
+# the Free Software Foundation; either version 3 of the License, or
4c2ad1
+# (at your option) any later version.
4c2ad1
+#
4c2ad1
+# This program is distributed in the hope that it will be useful,
4c2ad1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+# GNU General Public License for more details.
4c2ad1
+#
4c2ad1
+# You should have received a copy of the GNU General Public License
4c2ad1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
4c2ad1
+
4c2ad1
+load_lib gdb-python.exp
4c2ad1
+
4c2ad1
+standard_testfile
4c2ad1
+
4c2ad1
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug pthreads}]} {
4c2ad1
+    return -1
4c2ad1
+}
4c2ad1
+
4c2ad1
+# Skip all tests if Python scripting is not enabled.
4c2ad1
+if { [skip_python_tests] } { continue }
4c2ad1
+
4c2ad1
+if ![runto_main] then {
4c2ad1
+    return
4c2ad1
+}
4c2ad1
+gdb_test_no_output "set python print-stack full" \
4c2ad1
+    "Set python print-stack to full"
4c2ad1
+
4c2ad1
+# Load global frame-filters
4c2ad1
+set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
4c2ad1
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
4c2ad1
+    "Load python file"
4c2ad1
+
4c2ad1
+gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
4c2ad1
+gdb_continue_to_breakpoint "Backtrace end breakpoint"
4c2ad1
+
4c2ad1
+# #2  0x00007ffff75f228d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113^M
4c2ad1
+gdb_test "bt no-filters" " in (\\.?_*clone|thread_start) \[^\r\n\]*" "bt no-filters"
4c2ad1
+
4c2ad1
+# #2  0x00007ffff75f228d in 941595343737041 () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113^M
4c2ad1
+# vs.
4c2ad1
+# #2  0x00007ffff75f228d in 941595343737041Traceback (most recent call last):
4c2ad1
+#   File "/home/jkratoch/redhat/rhel/gdb/rhel-7.3/gdb-7.6.1/gdb/testsuite/../data-directory/python/gdb/FrameDecorator.py", line 145, in frame_args
4c2ad1
+#     return self._base.frame_args()
4c2ad1
+#   File "/home/jkratoch/redhat/rhel/gdb/rhel-7.3/gdb-7.6.1/gdb/testsuite/../data-directory/python/gdb/FrameDecorator.py", line 152, in frame_args
4c2ad1
+#     return args.fetch_frame_args()
4c2ad1
+#   File "/home/jkratoch/redhat/rhel/gdb/rhel-7.3/gdb-7.6.1/gdb/testsuite/../data-directory/python/gdb/FrameDecorator.py", line 276, in fetch_frame_args
4c2ad1
+#     block = self.frame.block()
4c2ad1
+# RuntimeError: Cannot locate object file for block.
4c2ad1
+gdb_test "bt" " in \[0-9\]+ \[^\r\n\]*" "bt with filters"
4c2ad1
diff --git a/gdb/testsuite/gdb.python/py-framefilter-thread.py b/gdb/testsuite/gdb.python/py-framefilter-thread.py
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.python/py-framefilter-thread.py
4c2ad1
@@ -0,0 +1,60 @@
4c2ad1
+# Copyright (C) 2016 Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+# This program is free software; you can redistribute it and/or modify
4c2ad1
+# it under the terms of the GNU General Public License as published by
4c2ad1
+# the Free Software Foundation; either version 3 of the License, or
4c2ad1
+# (at your option) any later version.
4c2ad1
+#
4c2ad1
+# This program is distributed in the hope that it will be useful,
4c2ad1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+# GNU General Public License for more details.
4c2ad1
+#
4c2ad1
+# You should have received a copy of the GNU General Public License
4c2ad1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
4c2ad1
+
4c2ad1
+# This file is part of the GDB testsuite.  It tests Python-based
4c2ad1
+# frame-filters.
4c2ad1
+
4c2ad1
+# This test is specifically crafted for RH BZ 1197665.
4c2ad1
+
4c2ad1
+import gdb
4c2ad1
+import itertools
4c2ad1
+from gdb.FrameDecorator import FrameDecorator
4c2ad1
+import copy
4c2ad1
+
4c2ad1
+class Reverse_Function (FrameDecorator):
4c2ad1
+
4c2ad1
+    def __init__(self, fobj):
4c2ad1
+        super(Reverse_Function, self).__init__(fobj)
4c2ad1
+        self.fobj = fobj
4c2ad1
+
4c2ad1
+    def function (self):
4c2ad1
+        # This function call should not fail.
4c2ad1
+        gdb.target_charset ()
4c2ad1
+
4c2ad1
+        fname = str (self.fobj.function())
4c2ad1
+        if (fname == None or fname == ""):
4c2ad1
+            return None
4c2ad1
+        else:
4c2ad1
+            fname = fname[::-1]
4c2ad1
+        return fname
4c2ad1
+
4c2ad1
+class FrameFilter ():
4c2ad1
+
4c2ad1
+    def __init__ (self):
4c2ad1
+        self.name = "Reverse"
4c2ad1
+        self.priority = 100
4c2ad1
+        self.enabled = True
4c2ad1
+        gdb.frame_filters [self.name] = self
4c2ad1
+
4c2ad1
+    def filter (self, frame_iter):
4c2ad1
+        # Python 3.x moved the itertools.imap functionality to map(),
4c2ad1
+        # so check if it is available.
4c2ad1
+        if hasattr(itertools, "imap"):
4c2ad1
+            frame_iter = itertools.imap (Reverse_Function, frame_iter)
4c2ad1
+        else:
4c2ad1
+            frame_iter = map (Reverse_Function, frame_iter)
4c2ad1
+        return frame_iter
4c2ad1
+
4c2ad1
+FrameFilter()