shlogg · Early preview
Nullity @masongyli

Automate Gdb Tty Output With Gnome-terminal And Gdbinit

Automate gdb output redirection with `tty` command in gdb. Create script ~/.gdbtty.sh and edit ~/.gdbinit to redirect output to another terminal. Some shortcomings remain, like popup position control.

tty command in gdb can direct output to another terminal.
Like https://stackoverflow.com/questions/8963208/gdb-display-output-of-target-application-in-a-separate-window
But I want it to be set automatically.
  
  
  Method

Create a script ~/.gdbtty.sh
Its content

#!/bin/bash
gnome-terminal -- bash -c "tty > ~/.gdbtty.txt; exec bash" &
sleep 0.5  # Give it time to open
TTY=$(cat ~/.gdbtty.txt)
echo "set inferior-tty $TTY" > ~/.gdbtty.txt

    
    

    
    




And edit ~/.gdbinit as

shell ~/.gdbtty.sh
source ~/.gdbtty.txt

    
    

    
    




  
  
  Some shortcomings

It's good but...