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

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