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

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