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

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