Fix Python unwinder frames regression
authorPedro Alves <palves@redhat.com>
Wed, 5 Jul 2017 23:19:24 +0000 (00:19 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 5 Jul 2017 23:19:24 +0000 (00:19 +0100)
The gdb.python/py-unwind.exp test is crashing GDB / leaving core dumps
in the test dir, even though it all passes cleanly.  The crash is not
visible in gdb.sum/gdb.log because it happens as side effect of the
"quit" command, while flushing the frame cache.

The problem is simply a typo in a 'for' loop's condition, introduced
by a recent change [4fa847d78edd ("Remove MAX_REGISTER_SIZE from
py-unwind.c")], resulting in infinite loop / double-free.

The new test exposes the crash, like:

 Running src/gdb/testsuite/gdb.python/py-unwind.exp ...
 ERROR: Process no longer exists

gdb/ChangeLog:
2017-07-06  Pedro Alves  <palves@redhat.com>

* python/py-unwind.c (pyuw_dealloc_cache): Fix for loop condition.

gdb/testsuite/ChangeLog:
2017-07-06  Pedro Alves  <palves@redhat.com>

* gdb.python/py-unwind.exp: Test flushregs.

gdb/ChangeLog
gdb/python/py-unwind.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-unwind.exp

index 03f30affa594d65a95852fdd9ac40f8a539a91e8..79081421221b361b6cbde847b48b55df8a3e59c0 100644 (file)
@@ -1,3 +1,7 @@
+2017-07-06  Pedro Alves  <palves@redhat.com>
+
+       * python/py-unwind.c (pyuw_dealloc_cache): Fix for loop condition.
+
 2017-07-04  Pedro Alves  <palves@redhat.com>
 
        * gdbtypes.c (recursive_dump_type): Don't reference TYPE_STATIC.
index 1d800a7b7861da6a168440b600fb2862c42b4e4b..acfce7d96c139171b8a03c1819ca7e857822cc64 100644 (file)
@@ -595,7 +595,7 @@ pyuw_dealloc_cache (struct frame_info *this_frame, void *cache)
   TRACE_PY_UNWIND (3, "%s: enter", __FUNCTION__);
   cached_frame_info *cached_frame = (cached_frame_info *) cache;
 
-  for (int i = 0; cached_frame->reg_count; i++)
+  for (int i = 0; i < cached_frame->reg_count; i++)
     xfree (cached_frame->reg[i].data);
 
   xfree (cache);
index 6160c4b398b9bd29b0b9b00ea14b31d24c2b0f52..d6a7252d763e9bc1fa24366f3bed80fa31da6d1b 100644 (file)
@@ -1,3 +1,7 @@
+2017-07-06  Pedro Alves  <palves@redhat.com>
+
+       * gdb.python/py-unwind.exp: Test flushregs.
+
 2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        PR cli/21688
index 0a4d34fdc6ca2f4d527fac0097d88d275d2bc828..625b04c40e3afac3ab91f6e80641dc670d71d3c9 100644 (file)
@@ -51,4 +51,5 @@ gdb_test_sequence "where"  "Backtrace restored by unwinder" {
     "\\r\\n#2 .* main \\(.*\\) at"
 }
 
-
+# Check that the Python unwinder frames can be flushed / released.
+gdb_test "flushregs" "Register cache flushed\\." "flush frames"