summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorJan Vrany <jan.vrany@labware.com>2022-12-16 11:38:28 +0000
committerJan Vrany <jan.vrany@labware.com>2022-12-16 11:38:28 +0000
commit429f0cd1396203204754141681b1bc65bd3f5259 (patch)
tree22bde7421acfcaa257a7b1187e877e055ec086db /gdb
parentd88cb738e6a7a7179dfaff8af78d69250c852af1 (diff)
downloadbinutils-gdb-429f0cd1396203204754141681b1bc65bd3f5259.tar.gz
gdb/testsuite: add test for Python commands redefining itself
This commit adds a test that creates a Python command that redefines itself during its execution. This is to test use-after-free in execute_command (). This test needs run with ASan enabled in order to fail when it should. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.python/py-cmd.exp30
1 files changed, 30 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
index aa95a459f46..48c3e18f1cc 100644
--- a/gdb/testsuite/gdb.python/py-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-cmd.exp
@@ -300,3 +300,33 @@ gdb_test_multiple "test_multiline" $test {
pass $test
}
}
+
+# Test command redefining itself
+
+proc_with_prefix test_command_redefining_itself {} {
+ # Start with a fresh gdb
+ clean_restart
+
+
+ gdb_test_multiline "input command redefining itself" \
+ "python" "" \
+ "class redefine_cmd (gdb.Command):" "" \
+ " def __init__ (self, msg):" "" \
+ " super (redefine_cmd, self).__init__ (\"redefine_cmd\", gdb.COMMAND_OBSCURE)" "" \
+ " self._msg = msg" "" \
+ " def invoke (self, arg, from_tty):" "" \
+ " print (\"redefine_cmd output, msg = %s\" % self._msg)" "" \
+ " redefine_cmd (arg)" "" \
+ "redefine_cmd (\"XXX\")" "" \
+ "end" ""
+
+ gdb_test "redefine_cmd AAA" \
+ "redefine_cmd output, msg = XXX" \
+ "call command redefining itself 1"
+
+ gdb_test "redefine_cmd BBB" \
+ "redefine_cmd output, msg = AAA" \
+ "call command redefining itself 2"
+}
+
+test_command_redefining_itself