Blame SOURCES/gdb-rhbz1325795-framefilters-test.patch

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