# With this argument the command raises a gdb.GdbError with no message
# string. GDB considers this a bug in the user program, so prints a
# backtrace, and a generic error message.
-mi_gdb_test "-pycmd exp" \
- [multi_line ".*&\"Traceback \\(most recent call last\\):..\"" \
- "&\"\[^\r\n\]+${testfile}.py\[^\r\n\]+\"" \
- "&\"\[^\r\n\]+raise gdb.GdbError\\(\\)..\"" \
- "&\"gdb.GdbError..\"" \
- "\\^error,msg=\"Error occurred in Python\\.\""] \
- "-pycmd exp"
+
+set line1 \
+ [string_to_regexp {Traceback (most recent call last):\n}]
+set line2 \
+ [string cat \
+ [string_to_regexp { File \"}] \
+ "\[^\r\n\]+" \
+ [string_to_regexp ${testfile}.py] \
+ [string_to_regexp {\", line }] \
+ $decimal \
+ [string_to_regexp {, in invoke\n}]]
+set line3 \
+ [string_to_regexp { raise gdb.GdbError()\n}]
+set line4 \
+ [string_to_regexp {gdb.GdbError\n}]
+set errline \
+ [string_to_regexp {^error,msg="Error occurred in Python."}]
+
+set start_line \
+ [string_to_regexp {&"}]
+set end_line \
+ [string_to_regexp {"}]
+
+# With python <= 3.12.
+set re1 \
+ [multi_line \
+ $start_line$line1$end_line \
+ $start_line$line2$end_line \
+ $start_line$line3$end_line \
+ $start_line$line4$end_line \
+ $errline]
+
+# With python >= 3.13.
+set re2 \
+ [multi_line \
+ $start_line$line1$end_line \
+ $start_line$line2$line3$end_line \
+ $start_line$line4$end_line \
+ $errline]
+
+mi_gdb_test "-pycmd exp" ($re1|$re2)
mi_gdb_test "python pycmd2('-pycmd')" \
".*\\^done" \