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

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