Fix crash when TUI window creation fails
authorTom Tromey <tom@tromey.com>
Tue, 16 Jun 2020 23:48:38 +0000 (17:48 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 16 Jun 2020 23:48:38 +0000 (17:48 -0600)
If a TUI window is written in Python, and if the window construction
function fails, then gdb will crash.  This patch fixes the crash.

gdb/ChangeLog
2020-06-16  Tom Tromey  <tom@tromey.com>

* python/py-tui.c (tui_py_window::~tui_py_window): Handle case
where m_window==nullptr.

gdb/testsuite/ChangeLog
2020-06-16  Tom Tromey  <tom@tromey.com>

* gdb.python/tui-window.py (failwin): New function.  Register it
as a TUI window type.
* gdb.python/tui-window.exp: Create new "fail" layout.  Test it.

gdb/ChangeLog
gdb/python/py-tui.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/tui-window.exp
gdb/testsuite/gdb.python/tui-window.py

index 08362f291dee0ef5a811474e5fcae3641782904f..cb3761c1ba741dbef699f5fcf0fece8700d416d9 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-16  Tom Tromey  <tom@tromey.com>
+
+       * python/py-tui.c (tui_py_window::~tui_py_window): Handle case
+       where m_window==nullptr.
+
 2020-06-15  Tom Tromey  <tromey@adacore.com>
 
        * windows-nat.c (windows_nat::handle_output_debug_string):
index ca88f85eb9f9af4b38c2ed9276c9d7d9ab38dfc4..95c71f1d2ddd24185d2983d4c73de7674a019467 100644 (file)
@@ -133,7 +133,10 @@ tui_py_window::~tui_py_window ()
 {
   gdbpy_enter enter_py (get_current_arch (), current_language);
 
-  if (PyObject_HasAttrString (m_window.get (), "close"))
+  /* This can be null if the user-provided Python construction
+     function failed.  */
+  if (m_window != nullptr
+      && PyObject_HasAttrString (m_window.get (), "close"))
     {
       gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "close",
                                               nullptr));
index d2ed9db4ebb7b2d72b3faacaac69f8478f895e54..97fecf6791bf611ba5254b3a2dc0fffa1567ccf2 100644 (file)
@@ -1,3 +1,9 @@
+2020-06-16  Tom Tromey  <tom@tromey.com>
+
+       * gdb.python/tui-window.py (failwin): New function.  Register it
+       as a TUI window type.
+       * gdb.python/tui-window.exp: Create new "fail" layout.  Test it.
+
 2020-06-16  Gary Benson <gbenson@redhat.com>
 
        * gdb.python/py-nested-maps.c (create_map): Add missing return
index 503823a2296d6e45b77890aee275be4631f99e19..f0fdd96e1adbbae61ab567780a9fd65232a94002 100644 (file)
@@ -36,6 +36,7 @@ gdb_test_no_output "source ${remote_python_file}" \
     "source ${testfile}.py"
 
 gdb_test_no_output "tui new-layout test test 1 status 0 cmd 1"
+gdb_test_no_output "tui new-layout fail fail 1 status 0 cmd 1"
 
 if {![Term::enter_tui]} {
     unsupported "TUI not supported"
@@ -49,3 +50,5 @@ Term::check_contents "Window display" "Test: 0"
 Term::resize 51 51
 # Remember that a resize request actually does two resizes...
 Term::check_contents "Window was updated" "Test: 2"
+
+Term::command "layout fail"
index 4deb585f13855eff23400d76bd41f828f1125dd9..f362b8768ae037293ca506c77dca0e2c92efd53a 100644 (file)
@@ -35,3 +35,9 @@ class TestWindow:
         self.count = self.count + 1
 
 gdb.register_window_type("test", TestWindow)
+
+# A TUI window "constructor" that always fails.
+def failwin(win):
+    raise RuntimeError("Whoops")
+
+gdb.register_window_type("fail", failwin)
This page took 0.038043 seconds and 4 git commands to generate.