diff options
author | Tom Tromey <tom@tromey.com> | 2018-04-18 20:10:43 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-05-04 15:58:09 -0600 |
commit | 56bcdbea2bed27ea83bf0e4fe472ab744b4beaa1 (patch) | |
tree | 8d7b32e4411b6a6f73e51fde7b20f0489d685dc2 /gdb/python | |
parent | a913fffbdee21fdd50e8de0596358be425775678 (diff) | |
download | gdb-56bcdbea2bed27ea83bf0e4fe472ab744b4beaa1.zip gdb-56bcdbea2bed27ea83bf0e4fe472ab744b4beaa1.tar.gz gdb-56bcdbea2bed27ea83bf0e4fe472ab744b4beaa1.tar.bz2 |
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 <tom@tromey.com>
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 <tom@tromey.com>
PR python/22730:
* gdb.python/python.exp: Test multi-line execute.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/python.c | 19 |
1 files changed, 17 insertions, 2 deletions
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) { |