Blame SOURCES/gdb-rhbz1197665-fix-applyframefilter-backport.patch

7b26da
commit 21909fa1c6d934bfa0c7ad3ef95909db48f6f756
7b26da
Author: Tom Tromey <tromey@redhat.com>
7b26da
Date:   Wed Jan 22 08:10:01 2014 -0700
7b26da
7b26da
    fix crash in frame filters
7b26da
    
7b26da
    apply_frame_filter calls ensure_python_env before computing the
7b26da
    gdbarch to use.  This means that python_gdbarch can be NULL while in
7b26da
    Python code, and if a frame filter depends on this somehow (easy to
7b26da
    do), gdb will crash.
7b26da
    
7b26da
    The fix is to compute the gdbarch first.
7b26da
    
7b26da
    Built and regtested on x86-64 Fedora 18.
7b26da
    New test case included.
7b26da
    
7b26da
    2014-01-23  Tom Tromey  <tromey@redhat.com>
7b26da
    
7b26da
    	PR python/16491:
7b26da
    	* python/py-framefilter.c (apply_frame_filter): Call
7b26da
    	ensure_python_env after computing gdbarch.
7b26da
    
7b26da
    2014-01-23  Tom Tromey  <tromey@redhat.com>
7b26da
    
7b26da
    	PR python/16491:
7b26da
    	* gdb.python/py-framefilter.py (Reverse_Function.function): Read a
7b26da
    	string from an inferior frame.
7b26da
    	* gdb.python/py-framefilter-mi.exp: Update.
7b26da
7b26da
Index: gdb-7.6.1/gdb/python/py-framefilter.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/python/py-framefilter.c
7b26da
+++ gdb-7.6.1/gdb/python/py-framefilter.c
7b26da
@@ -1468,18 +1468,18 @@ apply_frame_filter (struct frame_info *f
7b26da
   PyObject *item;
7b26da
   htab_t levels_printed;
7b26da
 
7b26da
-  cleanups = ensure_python_env (gdbarch, current_language);
7b26da
-
7b26da
   TRY_CATCH (except, RETURN_MASK_ALL)
7b26da
     {
7b26da
       gdbarch = get_frame_arch (frame);
7b26da
     }
7b26da
   if (except.reason < 0)
7b26da
     {
7b26da
-      gdbpy_convert_exception (except);
7b26da
-      goto error;
7b26da
+      /* Let gdb try to print the stack trace.  */
7b26da
+      return PY_BT_NO_FILTERS;
7b26da
     }
7b26da
 
7b26da
+  cleanups = ensure_python_env (gdbarch, current_language);
7b26da
+
7b26da
   iterable = bootstrap_python_frame_filters (frame, frame_low, frame_high);
7b26da
 
7b26da
   if (iterable == NULL)
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-mi.exp
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/testsuite/gdb.python/py-framefilter-mi.exp
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-mi.exp
7b26da
@@ -66,10 +66,10 @@ mi_continue_to_line [gdb_get_line_number
7b26da
   "step to breakpoint"
7b26da
 
7b26da
 mi_gdb_test "-stack-list-frames" \
7b26da
-    "\\^done,stack=\\\[frame={level=\"0\",addr=\"$hex\",func=\"cnuf_dne\".*},frame={level=\"1\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"2\",addr=\"$hex\",func=\"bcnuf\".*},frame={level=\"3\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"22\",addr=\"$hex\",func=\"1cnuf\".*,children=\\\[frame={level=\"23\",addr=\"$hex\",func=\"func2\".*}\\\]},frame={level=\"24\",addr=\"$hex\",func=\"3cnuf\".*},frame={level=\"27\",addr=\"$hex\",func=\"niam\".*}\\\].*" \
7b26da
+    "\\^done,stack=\\\[frame={level=\"0\",addr=\"$hex\",func=\"cnuf_dne.*\".*},frame={level=\"1\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"2\",addr=\"$hex\",func=\"bcnuf\".*},frame={level=\"3\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"22\",addr=\"$hex\",func=\"1cnuf\".*,children=\\\[frame={level=\"23\",addr=\"$hex\",func=\"func2\".*}\\\]},frame={level=\"24\",addr=\"$hex\",func=\"3cnuf\".*},frame={level=\"27\",addr=\"$hex\",func=\"niam\".*}\\\].*" \
7b26da
     "filtered stack listing"
7b26da
 mi_gdb_test "-stack-list-frames 0 3" \
7b26da
-    "\\^done,stack=\\\[frame={level=\"0\",addr=\"$hex\",func=\"cnuf_dne\".*},frame={level=\"1\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"2\",addr=\"$hex\",func=\"bcnuf\".*},frame={level=\"3\",addr=\"$hex\",func=\"acnuf\".*}\\\]" \
7b26da
+    "\\^done,stack=\\\[frame={level=\"0\",addr=\"$hex\",func=\"cnuf_dne.*\".*},frame={level=\"1\",addr=\"$hex\",func=\"acnuf\".*},frame={level=\"2\",addr=\"$hex\",func=\"bcnuf\".*},frame={level=\"3\",addr=\"$hex\",func=\"acnuf\".*}\\\]" \
7b26da
     "filtered stack list 0 3"
7b26da
 mi_gdb_test "-stack-list-frames 22 24" \
7b26da
     "\\^done,stack=\\\[frame={level=\"22\",addr=\"$hex\",func=\"1cnuf\".*,children=\\\[frame={level=\"23\",addr=\"$hex\",func=\"func2\".*}\\\]},frame={level=\"24\",addr=\"$hex\",func=\"3cnuf\".*}\\\]" \
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter.py
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/testsuite/gdb.python/py-framefilter.py
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter.py
7b26da
@@ -30,8 +30,11 @@ class Reverse_Function (FrameDecorator):
7b26da
         fname = str (self.fobj.function())
7b26da
         if (fname == None or fname == ""):
7b26da
             return None
7b26da
+        if fname == 'end_func':
7b26da
+            extra = self.fobj.inferior_frame().read_var('str').string()
7b26da
         else:
7b26da
-            fname = fname[::-1]
7b26da
+            extra = ''
7b26da
+        fname = fname[::-1] + extra
7b26da
         return fname
7b26da
 
7b26da
 class Dummy (FrameDecorator):
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv-gdb.py.in
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv-gdb.py.in
7b26da
@@ -0,0 +1,48 @@
7b26da
+# Copyright (C) 2013 Free Software Foundation, Inc.
7b26da
+
7b26da
+# This program is free software; you can redistribute it and/or modify
7b26da
+# it under the terms of the GNU General Public License as published by
7b26da
+# the Free Software Foundation; either version 3 of the License, or
7b26da
+# (at your option) any later version.
7b26da
+#
7b26da
+# This program is distributed in the hope that it will be useful,
7b26da
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+# GNU General Public License for more details.
7b26da
+#
7b26da
+# You should have received a copy of the GNU General Public License
7b26da
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7b26da
+
7b26da
+# This file is part of the GDB testsuite.  It tests Python-based
7b26da
+# frame-filters.
7b26da
+import gdb
7b26da
+import itertools
7b26da
+from gdb.FrameDecorator import FrameDecorator
7b26da
+
7b26da
+
7b26da
+class FrameObjFile ():
7b26da
+
7b26da
+    def __init__ (self):
7b26da
+        self.name = "Filter1"
7b26da
+        self.priority = 1
7b26da
+        self.enabled = False
7b26da
+        gdb.current_progspace().frame_filters ["Progspace" + self.name] = self
7b26da
+        gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self
7b26da
+
7b26da
+    def filter (self, frame_iter):
7b26da
+        return frame_iter
7b26da
+
7b26da
+class FrameObjFile2 ():
7b26da
+
7b26da
+    def __init__ (self):
7b26da
+        self.name = "Filter2"
7b26da
+        self.priority = 100
7b26da
+        self.enabled = True
7b26da
+        gdb.current_progspace().frame_filters ["Progspace" + self.name] = self
7b26da
+        gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self
7b26da
+
7b26da
+    def filter (self, frame_iter):
7b26da
+        return frame_iter
7b26da
+
7b26da
+FrameObjFile()
7b26da
+FrameObjFile2()
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv.exp
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv.exp
7b26da
@@ -0,0 +1,76 @@
7b26da
+# Copyright (C) 2013-2015 Free Software Foundation, Inc.
7b26da
+
7b26da
+# This program is free software; you can redistribute it and/or modify
7b26da
+# it under the terms of the GNU General Public License as published by
7b26da
+# the Free Software Foundation; either version 3 of the License, or
7b26da
+# (at your option) any later version.
7b26da
+#
7b26da
+# This program is distributed in the hope that it will be useful,
7b26da
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+# GNU General Public License for more details.
7b26da
+#
7b26da
+# You should have received a copy of the GNU General Public License
7b26da
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7b26da
+
7b26da
+# This file is part of the GDB testsuite.  It tests Python-based
7b26da
+# frame-filters.
7b26da
+
7b26da
+# This test is specifically crafted for RH BZ 1197665.
7b26da
+
7b26da
+load_lib gdb-python.exp
7b26da
+
7b26da
+standard_testfile py-framefilter.c
7b26da
+
7b26da
+# We cannot use prepare_for_testing as we have to set the safe-patch
7b26da
+# to check objfile and progspace printers.
7b26da
+if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
7b26da
+    return -1
7b26da
+}
7b26da
+
7b26da
+# Start with a fresh gdb.
7b26da
+gdb_exit
7b26da
+gdb_start
7b26da
+
7b26da
+# Skip all tests if Python scripting is not enabled.
7b26da
+if { [skip_python_tests] } { continue }
7b26da
+
7b26da
+# Make the -gdb.py script available to gdb, it is automagically loaded by gdb.
7b26da
+# Care is taken to put it in the same directory as the binary so that
7b26da
+# gdb will find it.
7b26da
+set remote_obj_python_file \
7b26da
+    [remote_download \
7b26da
+	 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
7b26da
+	 ${subdir}/${testfile}-gdb.py]
7b26da
+
7b26da
+gdb_reinitialize_dir $srcdir/$subdir
7b26da
+gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
7b26da
+    "set auto-load safe-path"
7b26da
+gdb_load ${binfile}
7b26da
+# Verify gdb loaded the script.
7b26da
+gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
7b26da
+    "Test auto-load had loaded python scripts"
7b26da
+
7b26da
+if ![runto_main] then {
7b26da
+    perror "couldn't run to breakpoint"
7b26da
+    return
7b26da
+}
7b26da
+gdb_test_no_output "set python print-stack full" \
7b26da
+    "Set python print-stack to full"
7b26da
+
7b26da
+# Load global frame-filters
7b26da
+set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
7b26da
+gdb_test_no_output "python execfile ('${remote_python_file}')" \
7b26da
+    "Load python file"
7b26da
+
7b26da
+gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
7b26da
+gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"]
7b26da
+gdb_continue_to_breakpoint "Inner test breakpoint"
7b26da
+
7b26da
+# Test multiple local blocks.
7b26da
+gdb_test "bt full no-filters" \
7b26da
+    ".*#0.*end_func.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" \
7b26da
+    "bt full no-filters"
7b26da
+gdb_test "bt full" \
7b26da
+    ".*#0.*cnuf_dne.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" \
7b26da
+    "bt full with filters"
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv.py
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.python/rhbz1197665-apply-frame-filter-segv.py
7b26da
@@ -0,0 +1,56 @@
7b26da
+# Copyright (C) 2013-2015 Free Software Foundation, Inc.
7b26da
+
7b26da
+# This program is free software; you can redistribute it and/or modify
7b26da
+# it under the terms of the GNU General Public License as published by
7b26da
+# the Free Software Foundation; either version 3 of the License, or
7b26da
+# (at your option) any later version.
7b26da
+#
7b26da
+# This program is distributed in the hope that it will be useful,
7b26da
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+# GNU General Public License for more details.
7b26da
+#
7b26da
+# You should have received a copy of the GNU General Public License
7b26da
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7b26da
+
7b26da
+# This file is part of the GDB testsuite.  It tests Python-based
7b26da
+# frame-filters.
7b26da
+
7b26da
+# This test is specifically crafted for RH BZ 1197665.
7b26da
+
7b26da
+import gdb
7b26da
+import itertools
7b26da
+from gdb.FrameDecorator import FrameDecorator
7b26da
+import copy
7b26da
+
7b26da
+class Reverse_Function (FrameDecorator):
7b26da
+
7b26da
+    def __init__(self, fobj):
7b26da
+        super(Reverse_Function, self).__init__(fobj)
7b26da
+        self.fobj = fobj
7b26da
+
7b26da
+    def function (self):
7b26da
+        # This function call should not fail.
7b26da
+        gdb.target_charset ()
7b26da
+
7b26da
+        fname = str (self.fobj.function())
7b26da
+        if (fname == None or fname == ""):
7b26da
+            return None
7b26da
+        else:
7b26da
+            fname = fname[::-1]
7b26da
+        return fname
7b26da
+
7b26da
+class FrameFilter ():
7b26da
+
7b26da
+    def __init__ (self):
7b26da
+        self.name = "Reverse"
7b26da
+        self.priority = 100
7b26da
+        self.enabled = True
7b26da
+        gdb.frame_filters [self.name] = self
7b26da
+
7b26da
+    def filter (self, frame_iter):
7b26da
+        frame_iter = itertools.imap (Reverse_Function,
7b26da
+                                     frame_iter)
7b26da
+        return frame_iter
7b26da
+
7b26da
+FrameFilter()