Skip to content

Instantly share code, notes, and snippets.

@simark
Last active May 25, 2016 13:05
Show Gist options
  • Save simark/fd9e9972a782a47b8af1 to your computer and use it in GitHub Desktop.
Save simark/fd9e9972a782a47b8af1 to your computer and use it in GitHub Desktop.
#! /bin/sh
if [ -z "${PI2_ROOT}" ]; then
echo "PI2_ROOT is not set!" >&2
exit 1
fi
if [ $# -ne 2 ]
then
echo "Bad # args. Blech!" >&2
exit 1
fi
# The first argument is the path to python-config.py, ignore it.
case "$2" in
--includes) echo "-I${PI2_ROOT}/usr/include/python3.4m" ;;
--ldflags) echo "-lpython3.4m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions" ;;
--exec-prefix) echo "/usr" ;;
*) echo "Bad arg $2. Blech!" >&2 ; exit 1 ;;
esac
exit 0
1. Mount the pi2's root fs on the host. Set the PI2_ROOT env variable
to where you want it mounted, so we can refer to it later.
host$ export PI2_ROOT=/tmp/rpi-root
host$ export PI2_HOST=142.133.111.232
host$ mkdir -p ${PI2_ROOT} && sshfs -o transform_symlinks simark@${PI2_HOST}:/ ${PI2_ROOT}
2. Create a fake python-config file for gdb's configure to use (see
https://sourceware.org/gdb/wiki/CrossCompilingWithPythonSupport).
Set the ARM_PYTHON_CONFIG shell variable so we can refer to it later
(it doesn't need to be exported).
host$ ARM_PYTHON_CONFIG=/home/emaisin/src/arm-python-config
You can use the attached arm-python-config file as a base. The flags
to use are found by running on the pi2:
pi2$ /usr/lib/python3.4/config-3.4m-arm-linux-gnueabihf/python-config.py --includes
pi2$ /usr/lib/python3.4/config-3.4m-arm-linux-gnueabihf/python-config.py --ldflags
pi2$ /usr/lib/python3.4/config-3.4m-arm-linux-gnueabihf/python-config.py --exec-prefix
3. Configure and build binutils-gdb
host$ ~/src/binutils-gdb/configure \
--host=arm-linux-gnueabihf \
CFLAGS="--sysroot ${PI2_ROOT} -g3 -O0" \
LDFLAGS="--sysroot ${PI2_ROOT}" \
--disable-ld --disable-gold --disable-gas --disable-binutils --disable-gprof --disable-sim \
--with-python=${ARM_PYTHON_CONFIG} --with-expat --enable-tui
4. Mount host build directory on the pi2 and run gdb
pi2$ mkdir -p /home/simark/build/binutils-gdb && sshfs -o cache=no emaisin@142.133.110.144:/home/emaisin/build/binutils-gdb-arm /home/simark/build/binutils-gdb
pi2$ /home/simark/build/binutils-gdb/gdb/gdb --data-directory /home/simark/build/binutils-gdb/gdb/data-directory
Normal:
~/src/binutils-gdb/configure \
CC="ccache gcc" \
CXX="ccache g++" \
--enable-targets=all \
CFLAGS="-g3 -O0" \
CXXFLAGS="-g3 -O0" \
--with-python=/usr/bin/python3 \
--enable-tui \
--with-expat \
--disable-ld --disable-gold --disable-gas --disable-binutils --disable-gprof
C++:
~/src/binutils-gdb/configure \
--enable-build-with-cxx \
CC="ccache gcc" \
CXX="ccache g++" \
--enable-targets=all \
CFLAGS="-g3 -O0" \
CXXFLAGS="-g3 -O0" \
--with-python=/usr/bin/python3 \
--enable-tui \
--with-expat \
--disable-ld --disable-gold --disable-gas --disable-binutils --disable-gprof
ARM cross debugger:
~/src/binutils-gdb/configure --disable-ld --disable-gold --disable-binutils --disable-gprof --disable-sim \
--with-expat --enable-tui --with-python=/usr/bin/python3 \
--target=arm-linux-gnueabihf CFLAGS="-g3 -O0" CXXFLAGS="-g3 -O0"
~/src/binutils-gdb/gdb/gdbserver/configure
# gdbserver running remotely over ssh
load_generic_config "gdbserver"
process_multilib_options ""
# The default compiler for this target.
#set_board_info compiler "[find_gcc]"
# If gdbserver runs in a cross-target arch, the testsuite should use a cross-compiler
set_board_info compiler "arm-linux-gnueabihf-gcc"
set_board_info c++compiler "arm-linux-gnueabihf-g++"
set_board_info rsh_prog "/usr/bin/ssh"
set_board_info rcp_prog "/usr/bin/scp"
set_board_info protocol standard
set_board_info username simark
set_board_info hostname 142.133.111.135
# Path to the gdbserver executable on target board.
set_board_info gdb_server_prog /home/simark/gdbserver
# We will be using the standard GDB remote protocol
set_board_info gdb_protocol "remote"
# Name of the computer whose socket will be used, if required.
set_board_info sockethost "142.133.111.135:"
# Port ID to use for socket connection
#set_board_info gdb,socketport "4004"
# Use techniques appropriate to a stub
set_board_info use_gdb_stub 1
# This gdbserver can only run a process once per session.
set_board_info gdb,do_reload_on_run 1
# There's no support for argument-passing (yet).
set_board_info noargs 1
# Can't do input (or output) in the current gdbserver.
set_board_info gdb,noinferiorio 1
# Can't do hardware watchpoints, in general (it depends on gdbserver support for your target arch)
set_board_info gdb,no_hardware_watchpoints 1
#include <stdio.h>
int loop(int n) {
int i;
int total = 0;
for (i = 0; i < n; i++) {
total += i;
}
return total;
}
int main() {
int res;
res = loop(20);
printf("Result is %d\n", res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment