[gdb/testsuite] Reimplement gdb.gdb/python-interrupts.exp as unittest

The test-case gdb.gdb/python-interrupts.exp:
- runs to captured_command_loop
- sets a breakpoint at set_active_ext_lang
- calls a python command
- verifies the command triggers the breakpoint
- sends a signal and verifies the result

The test-case is fragile, because (f.i. with -flto) it cannot be guaranteed
that captured_command_loop and set_active_ext_lang are available for setting
breakpoints.

Reimplement the test-case as unittest, using:
- execute_command_to_string to capture the output
- try/catch to catch the "Error while executing Python code" exception
- a new hook selftests::hook_set_active_ext_lang to raise the signal

Tested on x86_64-linux.
This commit is contained in:
Tom de Vries
2021-10-19 23:50:50 +02:00
parent 5a8edb756a
commit c82f680a94
4 changed files with 57 additions and 50 deletions

View File

@@ -682,6 +682,12 @@ install_gdb_sigint_handler (struct signal_handler *previous)
previous->handler_saved = 0;
}
#if GDB_SELF_TEST
namespace selftests {
void (*hook_set_active_ext_lang) () = nullptr;
}
#endif
/* Set the currently active extension language to NOW_ACTIVE.
The result is a pointer to a malloc'd block of memory to pass to
restore_active_ext_lang.
@@ -708,6 +714,11 @@ install_gdb_sigint_handler (struct signal_handler *previous)
struct active_ext_lang_state *
set_active_ext_lang (const struct extension_language_defn *now_active)
{
#if GDB_SELF_TEST
if (selftests::hook_set_active_ext_lang)
selftests::hook_set_active_ext_lang ();
#endif
struct active_ext_lang_state *previous
= XCNEW (struct active_ext_lang_state);