Bug 30636 - [gdb/tui] Secondary prompt overwritten
Summary: [gdb/tui] Secondary prompt overwritten
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: tui (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 14.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-14 11:23 UTC by Tom de Vries
Modified: 2023-07-26 11:33 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2023-07-14 11:23:20 UTC
Consider this gdb session:
...
$ gdb -q
(gdb) define foo
Type commands for definition of "foo".
End with a line saying just "end".
>bar
>end
(gdb) show user
User command "foo":
  bar

(gdb) 
...

Now let's try the same in TUI:
...
(gdb) define foo   
Type commands for definition of "foo".
End with a line saying just "end".
(gdb) show user
User command "foo":
  bar

(gdb) 
...

The secondary prompt lines are not terminated with a \n, and are consequently overwritten.

With this tentative patch:
...
diff --git a/gdb/top.c b/gdb/top.c
index 90ddc5f5ea7..f9b967c5c64 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -77,6 +77,7 @@
 
 #if defined(TUI)
 # include "tui/tui.h"
+# include "tui/tui-io.h"
 #endif
 
 #ifndef O_NOCTTY
@@ -958,6 +959,9 @@ gdb_readline_wrapper_line (gdb::unique_xmalloc_ptr<char> &&line)
   saved_after_char_processing_hook = after_char_processing_hook;
   after_char_processing_hook = NULL;
 
+  if (tui_active)
+    tui_inject_newline_into_command_window ();
+
   /* Prevent parts of the prompt from being redisplayed if annotations
      are enabled, and readline's state getting out of sync.  We'll
      reinstall the callback handler, which puts the terminal in raw
...
we get instead:
...
(gdb) define foo
Type commands for definition of "foo".
End with a line saying just "end".
>bar
>end
(gdb) show user
User command "foo":
  bar

(gdb) 
...
Comment 2 Sourceware Commits 2023-07-26 11:32:12 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=87c9b0289d73382cc72adb84d221b0a8ceb33ef8

commit 87c9b0289d73382cc72adb84d221b0a8ceb33ef8
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jul 26 13:31:53 2023 +0200

    [gdb/tui] Fix secondary prompt
    
    With CLI, a session defining a command looks like:
    ...
    (gdb) define foo
    Type commands for definition of "foo".
    End with a line saying just "end".
    >bar
    >end
    (gdb)
    ...
    
    With TUI however, we get the same secondary prompts, and type the same, but
    are left with:
    ...
    (gdb) define foo
    Type commands for definition of "foo".
    End with a line saying just "end".
    (gdb)
    ...
    
    Fix this by calling tui_inject_newline_into_command_window in
    gdb_readline_wrapper_line, as is done in tui_command_line_handler.
    
    Tested on x86_64-linux.
    
    PR tui/30636
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30636
Comment 3 Tom de Vries 2023-07-26 11:33:02 UTC
Fixed.