From a207f6b3a384897be1dab081a0a9a206593029de Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 15 Feb 2024 13:14:43 -0700 Subject: Rewrite "python" command exception handling The "python" command (and the Python implementation of the gdb "source" command) does not handle Python exceptions in the same way as other gdb-facing Python code. In particular, exceptions are turned into a generic error rather than being routed through gdbpy_handle_exception, which takes care of converting to 'quit' as appropriate. I think this was done this way because PyRun_SimpleFile and friends do not propagate the Python exception -- they simply indicate that one occurred. This patch reimplements these functions to respect the general gdb convention here. As a bonus, some Windows-specific code can be removed, as can the _execute_file function. The bulk of this change is tweaking the test suite to match the new way that exceptions are displayed. These changes are largely uninteresting. However, it's worth pointing out the py-error.exp change. Here, the failure changes because the test changes the host charset to something that isn't supported by Python. This then results in a weird error in the new setup. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31354 Acked-By: Tom de Vries Reviewed-By: Eli Zaretskii --- gdb/testsuite/gdb.python/python.exp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gdb/testsuite/gdb.python/python.exp') diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index c0d398c..175a6de 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -132,7 +132,7 @@ gdb_test_multiline "post event insertion" \ "end" "" gdb_test "python print (someVal)" "1" "test post event execution" -gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" \ +gdb_test "python gdb.post_event(str(1))" "RuntimeError.*: Posted event is not callable.*" \ "test non callable class" send_gdb "python gdb.post_event(lambda: invalid())\n" @@ -162,7 +162,7 @@ gdb_test_multiple "python print (\"\\n\" * $lines)" $test { pass $test } } -gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination beforehand: q" +gdb_test "q" "Quit.*" "verify pagination beforehand: q" gdb_test "python if gdb.execute('python print (\"\\\\n\" * $lines)', to_string=True) == \"\\n\" * [expr $lines + 1]: print (\"yes\")" "yes" "gdb.execute does not page" @@ -178,7 +178,7 @@ gdb_test_multiple "python print (\"\\n\" * $lines)" $test { pass $test } } -gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination afterwards: q" +gdb_test "q" "Quit.*" "verify pagination afterwards: q" gdb_test_no_output "set height 0" @@ -223,7 +223,7 @@ runto $lineno # Test gdb.decode_line. gdb_test "python gdb.decode_line(\"main.c:43\")" \ - "gdb.error: No source file named main.c.*" "test decode_line no source named main" + "gdb.error.*: No source file named main.c.*" "test decode_line no source named main" with_test_prefix "test decode_line current location" { gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "decode current line" 1 @@ -253,7 +253,7 @@ with_test_prefix "test decode_line" { gdb_test "python print (symtab\[1\]\[0\].line)" "26" "python.c:26 line number" gdb_test "python gdb.decode_line(\"randomfunc\")" \ - "gdb.error: Function \"randomfunc\" not defined.*" "randomfunc" + "gdb.error.*: Function \"randomfunc\" not defined.*" "randomfunc" gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "func1()" 1 gdb_test "python print (len(symtab))" "2" "func1 length 2" gdb_test "python print (len(symtab\[1\]))" "1" "func1 length 1" -- cgit v1.1