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

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