Yes, you want working completion in your gdb

You can pipe commands to gdb, but how to have auto-complete on those commands?

Naive attempts

A initial little try is promising, we can pipe commands to gdb:

~$ echo "show endian" | gdb -q
(gdb) The target endianness is set automatically (currently little endian)
(gdb) quit

The command show endian was executed by gdb just like if we typed it.

Now let us simulate a completion (-e makes echo interpret the special characters such as \t for TAB):

~$ echo -e "show en\t" | gdb -q
(gdb) Ambiguous show command "en    ": endian, environment.
(gdb) quit

It did not work as wanted. The TAB was not read as a request for completion.

~$ cat | gdb -q
(gdb) show en

No better result. Completion via TAB is not possible. gdb simply does not expect terminal commands via pipe. Some people have tried the same with other interactive tools [1].

Note: it is actually not impossible with bash -i (i.e., interactive bash) [2].

The problem

A pipe is different from a pseudo-terminal. See [3] and for more details, [4].

The solution

The solution is to simulate a pseudo-terminal as suggested in [5]:

$ echo -e "show en\t\t\nquit" | python ptypipe.py "" "gdb -q"
show en
quit
(gdb) show en
endian       environment
(gdb) show en
Ambiguous show command "en": endian, environment.
(gdb) quit

Success!

Note that gdb is executed as a sub-process of python.