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

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