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