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

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