diff options
author | Tom Tromey <tromey@adacore.com> | 2024-04-04 08:40:38 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-04-15 09:04:29 -0600 |
commit | bdcd50f901e3db5b773b6462813a50b9649aad57 (patch) | |
tree | 4bbfa95ae833f6f8b254a3945a48235f67c5e1bb /gdb/event-top.c | |
parent | 34d5ac9244ccfe566232469ec3bef1329f0bc42e (diff) | |
download | fsf-binutils-gdb-bdcd50f901e3db5b773b6462813a50b9649aad57.zip fsf-binutils-gdb-bdcd50f901e3db5b773b6462813a50b9649aad57.tar.gz fsf-binutils-gdb-bdcd50f901e3db5b773b6462813a50b9649aad57.tar.bz2 |
Strip trailing newlines from input string
A co-worker noticed a strange situation where "target remote" would
fail due to a trailing newline in the address part of the command.
Eventually he tracked this down to the fact that he was pasting the
command into the terminal, and due to bracketed paste mode, the
newline was being preserved by readline.
It seems to me that we basically never want a trailing newline on a
gdb command, so this patch removes it when handling the readline
result.
Co-Authored-By: Kévin Le Gouguec <legouguec@adacore.com>
Approved-By: Luis Machado <luis.machado@arm.com>
Tested-By: Luis Machado <luis.machado@arm.com>
Diffstat (limited to 'gdb/event-top.c')
-rw-r--r-- | gdb/event-top.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c index 9a02ac6..f0c07ba 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -251,6 +251,14 @@ gdb_rl_callback_handler (char *rl) noexcept static struct gdb_exception gdb_rl_expt; struct ui *ui = current_ui; + /* In bracketed paste mode, pasting a complete line can result in a + literal newline appearing at the end of LINE. However, we never + want this in gdb. */ + size_t len = strlen (rl); + while (len > 0 && (rl[len - 1] == '\r' || rl[len - 1] == '\n')) + --len; + rl[len] = '\0'; + try { /* Ensure the exception is reset on each call. */ |