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

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