Skip to content

Instantly share code, notes, and snippets.

@lamontnelson
Created March 29, 2016 02:39
Show Gist options
  • Save lamontnelson/3fa98b5b8d3223a2076d to your computer and use it in GitHub Desktop.
Save lamontnelson/3fa98b5b8d3223a2076d to your computer and use it in GitHub Desktop.
automatically open tmux panes containing gdb attached to processes with the given name
#!/bin/bash
PROC_NAME=${1-"myserver"}
SESSION_NAME=${2-"tmuxgdbsession"}
echo "create tmux session in $SESSION_NAME"
pids=`ps aux | grep "$PROC_NAME" | grep -v grep | awk '{print $2}'`
echo "Attach to pids $(echo $pids | tr -d '\r\n')"
attach_gdb() {
cmd="gdb -p $1"
tmux split-window -t "$SESSION_NAME" "$cmd"
}
tmux new-session -s "$SESSION_NAME" -d
while read -r pid; do
attach_gdb $pid
done <<< "$pids"
tmux kill-pane -t "$SESSION_NAME:0.0"
tmux select-layout -t "$SESSION_NAME:0" even-vertical
tmux attach -t "$SESSION_NAME" || (echo "no processes found" && ps aux | grep "$PROC_NAME" && exit 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment