diff options
author | Anas Nashif <anas.nashif@intel.com> | 2016-02-01 22:24:21 -0500 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2016-02-05 20:25:30 -0500 |
commit | a49762ccceeb6882b97cb0450d1d6cb9ad45987b (patch) | |
tree | 3b1e6245c7925468c40e8c85ad5a7a4732670d65 /scripts/support | |
parent | c0c155618e6fdb8eb7193e3205a2750a57300942 (diff) |
add debug/debugserver support
Change-Id: I114994cb092870cd57b8e43b197d56ab8ca7db20
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'scripts/support')
-rwxr-xr-x | scripts/support/openocd.sh | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/scripts/support/openocd.sh b/scripts/support/openocd.sh index 039d9345e..f7acbea5c 100755 --- a/scripts/support/openocd.sh +++ b/scripts/support/openocd.sh @@ -1,8 +1,12 @@ #!/bin/sh +# This script is loosly based on a script with same purpose provided +# by RIOT-OS (https://github.com/RIOT-OS/RIOT) + OPENOCD_CMD="${OPENOCD:-openocd} -s ${OPENOCD_DEFAULT_PATH}" OPENOCD_CONFIG=${ZEPHYR_BASE}/boards/${BOARD_NAME}/support/openocd.cfg BIN_NAME=${O}/${KERNEL_BIN_NAME} +ELF_NAME=${O}/${KERNEL_ELF_NAME} test_config() { if [ ! -f "${OPENOCD_CONFIG}" ]; then @@ -41,10 +45,42 @@ do_flash() { echo 'Done flashing' } -do_debugserver() { + +do_debug() { test_config - test_ports + test_bin + # setsid is needed so that Ctrl+C in GDB doesn't kill OpenOCD + [ -z "${SETSID}" ] && SETSID="$(which setsid)" + # temporary file that saves OpenOCD pid + OCD_PIDFILE=$(mktemp -t "openocd_pid.XXXXXXXXXX") + # cleanup after script terminates + trap "cleanup ${OCD_PIDFILE}" EXIT + # don't trap on Ctrl+C, because GDB keeps running + trap '' INT # start OpenOCD as GDB server + ${SETSID} sh -c "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \ + ${OPENOCD_EXTRA_INIT} \ + -c 'tcl_port ${TCL_PORT:-6333}' \ + -c 'telnet_port ${TELNET_PORT:-4444}' \ + -c 'gdb_port ${GDB_PORT:-3333}' \ + -c 'init' \ + -c 'targets' \ + -c 'halt' \ + & \ + echo \$! > $OCD_PIDFILE" & + # connect to the GDB server + ${GDB} ${TUI} -ex "target remote :${GDB_PORT:-3333}" ${ELF_NAME} + # will be called by trap + cleanup() { + OCD_PID="$(cat $OCD_PIDFILE)" + kill ${OCD_PID} &>/dev/null + rm -f "$OCD_PIDFILE" + exit 0 + } +} + +do_debugserver() { + test_config sh -c "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \ -c 'init' \ -c 'targets' \ @@ -62,4 +98,7 @@ case "${CMD}" in debugserver) do_debugserver "$@" ;; + debug) + do_debug "$@" + ;; esac |