From 56bcdbea2bed27ea83bf0e4fe472ab744b4beaa1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 18 Apr 2018 20:10:43 -0600 Subject: Let gdb.execute handle multi-line commands This changes the Python API so that gdb.execute can now handle multi-line commands, like "commands" or "define". ChangeLog 2018-05-04 Tom Tromey PR python/22730: * NEWS: Mention gdb.execute change. * gdbcmd.h (execute_control_command): Don't declare. * python/python.c (execute_gdb_command): Use read_command_lines_1, execute_control_commands, execute_control_commands_to_string. * cli/cli-script.h (execute_control_commands) (execute_control_commands_to_string): Declare. (execute_control_command): Add from_tty parameter. * cli/cli-script.c (execute_control_commands) (execute_control_commands_to_string): New functions. (execute_user_command): Use execute_control_commands. (execute_control_command_1): Add "from_tty" parameter. Update. (execute_control_command): Likewise. testsuite/ChangeLog 2018-05-04 Tom Tromey PR python/22730: * gdb.python/python.exp: Test multi-line execute. --- gdb/python/python.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/python.c b/gdb/python/python.c index b486be7..db37331 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -588,6 +588,20 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) { struct interp *interp; + std::string arg_copy = arg; + bool first = true; + char *save_ptr = nullptr; + auto reader + = [&] () + { + const char *result = strtok_r (first ? &arg_copy[0] : nullptr, + "\n", &save_ptr); + first = false; + return result; + }; + + counted_command_line lines = read_command_lines_1 (reader, 1, nullptr); + scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); scoped_restore save_uiout = make_scoped_restore (¤t_uiout); @@ -599,9 +613,10 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) scoped_restore preventer = prevent_dont_repeat (); if (to_string) - to_string_res = execute_command_to_string (arg, from_tty); + to_string_res = execute_control_commands_to_string (lines.get (), + from_tty); else - execute_command (arg, from_tty); + execute_control_commands (lines.get (), from_tty); } CATCH (except, RETURN_MASK_ALL) { -- cgit v1.1