blob: 8b082060aa2b31d1024824d94aca64b7732d2fa2 [file] [log] [blame]
#!/bin/bash
# Copyright 2023 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Launch a debug session with gdb-dashboard and miniterm in separate Tmux
# splits.
# Linux Blackmagic Probe
DEVBMP="/dev/ttyBmpGdb"
FOUND_BMP=$(python -m gonk_tools.find_serial_port -p 'Black Magic Probe' -1) && DEVBMP=$FOUND_BMP
DEVGONK="/dev/ttyGonk"
FOUND_GONK=$(python -m gonk_tools.find_serial_port -p 'GENERIC_F730R8TX' -1) && DEVGONK=$FOUND_GONK
GONK_BAUDRATE=115200
# GDB binary
GDB=arm-none-eabi-gdb
which gdb-multiarch && GDB=gdb-multiarch
# List all active panes in this tab. For example:
#
# 0 /dev/pts/4 (active)
# 1 /dev/pts/7
# 2 /dev/pts/6
# 3 /dev/pts/5
#
tmux_list_panes () {
tmux list-panes -F '#P #{pane_tty} #{?pane_active,(active),}'
}
# Get the current tmux pane in focus
tmux_get_active_pane_id () {
tmux_list_panes | awk '/(active)/ { print $1}'
}
# Get the pane ID for a given TTY.
# Useful for performing an action on a pane not in focus.
tmux_get_pane_id () {
tmux_list_panes | awk "\$0~\"${1}\" { print \$1}"
}
# Get the current pane TTY for a given TTY
tmux_get_active_pane_tty () {
tmux_list_panes | awk '/(active)/ { print $2}'
}
split_tmux_panes () {
ORIGINAL_PANE=$(tmux_get_active_pane_id)
# Make a split for gdb-dashboard
tmux select-pane -t $ORIGINAL_PANE
tmux split-window -h
DASHBOARD_TTY=$(tmux_get_active_pane_tty)
# Make a split for serial output
tmux select-pane -t $ORIGINAL_PANE
tmux split-window -v "sleep 4; python -m serial.tools.miniterm --raw ${DEVGONK} ${GONK_BAUDRATE}"
SERIAL_TTY=$(tmux_get_active_pane_tty)
# Select the original pane and run gdb
tmux select-pane -t $ORIGINAL_PANE
}
tmux_cleanup () {
tmux kill-pane -t $(tmux_get_pane_id $SERIAL_TTY)
tmux kill-pane -t $(tmux_get_pane_id $DASHBOARD_TTY)
}
which tmux && split_tmux_panes
$GDB \
-ex "set confirm off" \
-ex "dashboard -output ${DASHBOARD_TTY}" \
-ex "target extended-remote ${DEVBMP}" \
-ex "monitor version" \
-ex "monitor tpwr enable" \
-ex "monitor swdp_scan" \
-ex "attach 1" \
-ex "load" \
-ex "compare-sections" \
-ex "run" \
$@
which tmux && tmux_cleanup