[gdb/testsuite] Add gdb.tui/reread.exp

Message ID 20240508123908.14242-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Add gdb.tui/reread.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom de Vries May 8, 2024, 12:39 p.m. UTC
  Add a regression test for commit d68f983f88c ("Fix heap-use-after-free because
all_objfiles_removed triggers tui_display_main").

When building with address sanitizer, and reverting the commit it triggers the
heap-use-after-free.

Tested on aarch64-linux.
---
 gdb/testsuite/gdb.tui/reread.exp | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 gdb/testsuite/gdb.tui/reread.exp


base-commit: 2236c5e384de20b0dd6b2fbc964a7269027cb2d9
  

Comments

Tom Tromey May 8, 2024, 2:50 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Add a regression test for commit d68f983f88c ("Fix heap-use-after-free because
Tom> all_objfiles_removed triggers tui_display_main").

Tom> When building with address sanitizer, and reverting the commit it triggers the
Tom> heap-use-after-free.

Thanks for doing this.
I'd suggest adding a Bug: trailer so this is recorded in the PR.

Other than that, looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.tui/reread.exp b/gdb/testsuite/gdb.tui/reread.exp
new file mode 100644
index 00000000000..ed51c6cdca9
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/reread.exp
@@ -0,0 +1,39 @@ 
+# Copyright 2024 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/>.
+
+# Check that rereading the exec while in TUI doesn't cause trouble.
+# Use to trigger an AddressSanitizer heap-use-after-free, PR31697.
+
+tuiterm_env
+
+# Use main-one-line.c to get the line info at a predictable location without
+# resorting to a dwarf assembly test-case.
+standard_testfile main-one-line.c
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
+    return -1
+}
+
+Term::clean_restart 24 80 $testfile
+
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+remote_exec build sleep 1
+gdb_touch_execfile $binfile
+
+Term::command "start"