Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>
Subject: [PATCH 1/3] fix crash in frame filters
Date: Wed, 22 Jan 2014 16:00:00 -0000	[thread overview]
Message-ID: <1390406399-26664-2-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1390406399-26664-1-git-send-email-tromey@redhat.com>

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-22  Tom Tromey  <tromey@redhat.com>

	PR python/16491:
	* python/py-framefilter.c (apply_frame_filter): Call
	ensure_python_env after computing gdbarch.

2014-01-22  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.
---
 gdb/ChangeLog                                  | 6 ++++++
 gdb/python/py-framefilter.c                    | 8 ++++----
 gdb/testsuite/ChangeLog                        | 7 +++++++
 gdb/testsuite/gdb.python/py-framefilter-mi.exp | 4 ++--
 gdb/testsuite/gdb.python/py-framefilter.py     | 5 ++++-
 5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 76ce4e5..c6a29ef 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1477,18 +1477,18 @@ apply_frame_filter (struct frame_info *frame, int flags,
   if (!gdb_python_initialized)
     return PY_BT_NO_FILTERS;
 
-  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)
diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
index 58c8d35..0c5f5d4 100644
--- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
@@ -66,10 +66,10 @@ mi_continue_to_line [gdb_get_line_number {Backtrace end breakpoint} ${srcfile}]
   "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\".*}\\\]" \
diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py
index 1cf8c22..25b3368 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.py
+++ b/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):
-- 
1.8.1.4


  parent reply	other threads:[~2014-01-22 16:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 17:51 [PATCH 0/3] frame filter fixes, proposed for 7.7 Tom Tromey
2014-01-22 16:00 ` [PATCH 3/3] avoid python exception in FrameDecorator.py Tom Tromey
2014-01-22 16:00 ` Tom Tromey [this message]
2014-01-22 19:58   ` [PATCH 1/3] fix crash in frame filters Phil Muldoon
2014-01-23  6:04     ` Joel Brobecker
2014-01-22 16:50 ` [PATCH 2/3] fix erroneous error-handling in frame filter code Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390406399-26664-2-git-send-email-tromey@redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox