This repository has been archived by the owner on Apr 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinteractive
executable file
·52 lines (43 loc) · 1.56 KB
/
interactive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ] || [ ! -f "devices/$1.py" ]; then
echo 'Opens interactive Python console inside gdb with slave'
echo 'device already set-up.'
echo 'Usage: ./interactive device_file device_object [gdb_server_port]'
echo
echo 'device_file may be:'
for device_file in `ls devices/`; do
if [[ ! $device_file == __* ]] && [[ $device_file == *.py ]]; then
echo -e "\t${device_file%.*}"
fi
done
echo
echo 'Example: ./interactive stm32f0 STM32F0'
exit 1
fi
GDB_PORT=${3:-4242}
PYTHON_VERSION=$(python2 --version 2>&1)
if [[ ! $PYTHON_VERSION == Python\ 2.7* ]]; then
echo "Python 2.7 is required, your version is $PYTHON_VERSION"
exit 2
fi
# Python launched from GDB won't allow importing modules from the current working dir
# and ignores anything which may have been added to the `sys.path` as a result of using virtualenv.
# This is a (ugly, I am so sorry...) hack which puts those two things back
# to sys.path
VENV_APPEND=""
if [ ! -z "$VIRTUAL_ENV" ]; then
VENV_APPEND="sys.path.append('$VIRTUAL_ENV/lib/python2.7/site-packages')"
fi
PYTHON_HACK="python
import sys
import os
sys.path.append(os.getcwd())
$VENV_APPEND"
# This part sets up device object as a wrapper around the real device.
PYTHON_SETUP="python
import mempoke
from devices.$1 import $2
print 'Device is available as variable \'dev\'.'
dev = $2(mempoke.DeviceMemory())"
REMOTE_DEBUG="target extended :$GDB_PORT"
arm-none-eabi-gdb -batch -ex "$REMOTE_DEBUG" -ex "$PYTHON_HACK" -ex "$PYTHON_SETUP" -x interactive_utils.py