Bug 22340 - attach in gdb/mi doesn't display prompt
Summary: attach in gdb/mi doesn't display prompt
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-23 20:53 UTC by Mike Gulick
Modified: 2017-10-23 20:53 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 Mike Gulick 2017-10-23 20:53:22 UTC
When using gdb in mi mode (gdb -i=mi), the "(gdb)" prompt is not displayed properly when running the "attach" command.  This is reproducible in emacs gdb mode.  I also tested this with the 'gdbgui' tool, which also gets confused as to whether gdb is ready to accept more input after attaching to a process.

The issue seems to be that the gdb output doesn't print the "(gdb)\n" prompt immediately after printing "^done" (output is from GDB 8.0.1):

    (gdb) 
    attach 31473
    &"attach 31473\n"
    ~"Attaching to process 31473\n"
    =thread-group-started,id="i1",pid="31473"
    =thread-created,id="1",group-id="i1"
--> ^done
    ~"Reading symbols from /bin/sleep..."
    ~"(no debugging symbols found)...done.\n"
    =library-loaded,id="/lib/x86_64-linux-gnu/libc.so.6",target-name="/lib/x86_64-linux-gnu/libc.so.6",host-name="/lib/x86_64-linux-gnu/libc.so.6",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007f3869fd34a0",to="0x00007f386a0ff943"}]
    =library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007f386a35fae0",to="0x00007f386a378140"}]
    ~"Reading symbols from /lib/x86_64-linux-gnu/libc.so.6..."
    ~"(no debugging symbols found)...done.\n"
    ~"Reading symbols from /lib64/ld-linux-x86-64.so.2..."
    ~"(no debugging symbols fou2nd)...done.\n"
    ~"0x00007f386a06df10 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6\n"
    *stopped,frame={addr="0x00007f386a06df10",func="nanosleep",args=[],from="/lib/x86_64-linux-gnu/libc.so.6"},thread-id="1",stopped-threads="all",core="5"
--> (gdb) 

I get the impression from the GDB/MI syntax (https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html#GDB_002fMI-Output-Syntax) that a result record *must* be immediately followed by a "(gdb)\n" prompt.

This behavior apparently changed in GDB 7.8 (I only very recently started using GDB/MI mode, so never noticed this change).  A git bisect points at this commit: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=329ea57934a9d4b250a0b417af1ec47bc2d0ceb6

Up until GDB 7.11, I could work around this by running 'maint set target-async off'.  This restored the previous prompting behavior, and this make emacs work as expected.  However this stopped working in GDB 7.11.  It looks like this behavior changed with this commit: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=0b333c5e7d6c3fc65d37ffa11bd21ba52c4adb25.

Reproduction steps:

$ emacs --version
GNU Emacs 24.4.1
$ sleep 1000 &
[1] 14132
$ emacs -nw
...
>> M-x gdb
>> Run gdb (like this): gdb -n -i=mi
...
GNU gdb (GDB) 8.0.50.20171023-git
...
(gdb) attach 14132
Attaching to process 14132
(gdb) Reading symbols from /bin/sleep...(no debugging symbols found)...done.
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...(no debugging symbols found)...done.
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
0x00007f29a9214f10 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6

---

Also tested on Emacs 25.1.1 (Debian 9), with no change in behavior.

I'm inclined to point the finger at gdb's mi mode rather than emacs, since 'gdbgui' also fails under similar conditions, but an emacs fix would be just as good.