The symptom of the bug was that annotations were being printed incorrectly. For example, launching gdb -nw --annotate=2 generated the following output: .gdbinit Ready ��pre-prompt (gdb) ��prompt prompt��post- ��pre-prompt (gdb) ��prompt Notice the "prompt��post-" line, which should be ��post-prompt I compiled gdb, and traced the problem to following lines: event-top.c annotation_suffix = "prompt"; if (from_tty && annotation_level > 1) { 1) printf_unfiltered (("\n\032\032post-")); 2) puts_unfiltered (annotation_suffix); 3) printf_unfiltered (("\n")); } printf_unfiltered and puts_unfiltered print lines out of order, unless "set pagination off" flag is set. That is how "prompt" got printed before "\032post-" The root cause is that printf_unfiltered ends up calling utils.c:fputs_maybe_filtered, which is quite complex, but I think does some buffering. fputs_unfiltered goes straight to file->puts. I worked around the issue in cgdb by passing in "set pagination off" flag. But it should be fixed, printf/puts out of order is surprising.
The gdb-9-branch branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f49692dff8efe149fe3087e2d3abdafca3d062eb commit f49692dff8efe149fe3087e2d3abdafca3d062eb Author: Iain Buclaw <ibuclaw@gdcproject.org> Date: Wed Feb 5 12:45:13 2020 +0100 Make fputs_unfiltered use fputs_maybe_filtered This patch redefines fputs_unfiltered in utils.c, with new behavior to forward parameters to fputs_maybe_filtered. This makes fputs_unfiltered identical to fputs_filtered, except filtering is disabled. Some callers of fputs_unfiltered have been updated to use ui_file_puts where they were using other ui_file_* functions anyway for IO. This fixes the problem I saw with \032\032post-prompt annotation being flushed to stdout in the wrong order. gdb/ChangeLog 2020-02-05 Iain Buclaw <ibuclaw@gdcproject.org> PR gdb/25190: * gdb/remote-sim.c (gdb_os_write_stderr): Update. * gdb/remote.c (remote_console_output): Update. * gdb/ui-file.c (fputs_unfiltered): Rename to... (ui_file_puts): ...this. * gdb/ui-file.h (ui_file_puts): Add declaration. * gdb/utils.c (emit_style_escape): Update. (flush_wrap_buffer): Update. (fputs_maybe_filtered): Update. (fputs_unfiltered): Add function. Change-Id: I17ed5078f71208344f2f8ab634a6518b1af6e213
Fixed for 9.1.
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dfcb27e41d37b8bff178697f5f33ec288387fb01 commit dfcb27e41d37b8bff178697f5f33ec288387fb01 Author: Iain Buclaw <ibuclaw@gdcproject.org> Date: Wed Feb 5 12:45:13 2020 +0100 Make fputs_unfiltered use fputs_maybe_filtered This patch redefines fputs_unfiltered in utils.c, with new behavior to forward parameters to fputs_maybe_filtered. This makes fputs_unfiltered identical to fputs_filtered, except filtering is disabled. Some callers of fputs_unfiltered have been updated to use ui_file_puts where they were using other ui_file_* functions anyway for IO. This fixes the problem I saw with \032\032post-prompt annotation being flushed to stdout in the wrong order. 2020-02-05 Iain Buclaw <ibuclaw@gdcproject.org> PR gdb/25190: * gdb/remote-sim.c (gdb_os_write_stderr): Update. * gdb/remote.c (remote_console_output): Update. * gdb/ui-file.c (fputs_unfiltered): Rename to... (ui_file_puts): ...this. * gdb/ui-file.h (ui_file_puts): Add declaration. * gdb/utils.c (emit_style_escape): Update. (flush_wrap_buffer): Update. (fputs_maybe_filtered): Update. (fputs_unfiltered): Add function. Change-Id: I17ed5078f71208344f2f8ab634a6518b1af6e213
Thank you!