You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

285 lines
12 KiB

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