blob: 0f7a1cdaed496e7c4d1b14b6d5a1c8e40d39ebca [file] [log] [blame]
#!/bin/sh
set -eu
bbdbg_help() {
/bin/echo -e "NAME"
/bin/echo -e "\tbbdbg - debug applications in a target environment built by bitbake"
/bin/echo -e
/bin/echo -e "SYNOPSIS"
/bin/echo -e "\tbbdbg PATH FILE CORE PACKAGES"
/bin/echo -e
/bin/echo -e "DESCRIPTION"
/bin/echo -e "\tPATH is the path to the root of a bitbake build directory"
/bin/echo -e "\tFILE is the absolute path to the binary of interest in the target environment"
/bin/echo -e "\tCORE is an optional core file generated by FILE. Pass '-' for no core file"
/bin/echo -e "\tPACKAGES will be used to populate a temporary rootfs for debugging FILE"
/bin/echo -e
/bin/echo -e "EXAMPLE"
/bin/echo -e "\tbbdbg ~/src/openbmc/openbmc/build/p10bmc \\"
/bin/echo -e "\t\t/usr/bin/nvmesensor - \\"
/bin/echo -e "\t\tdbus-sensors dbus-sensors-dbg"
}
trap bbdbg_help EXIT
BBDBG_PATH=$1; shift
BBDBG_FILE=$1; shift
BBDBG_CORE=$1; shift
BBDBG_PKGS=$@
BBDBG_ROOT=$(mktemp -t --directory bbdbg.XXX)
BBDBG_LIBS=${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/libsolv-native/usr/lib:${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/libarchive-native/usr/lib
BBDBG_OPKG=${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/opkg-native/usr/bin/opkg
BBDBG_CONF=$(find ${BBDBG_PATH}/tmp/work/*/obmc-phosphor-image -name opkg.conf -exec grep -lE ^src \{\} \;)
bbdbg_cleanup() {
rm -rf "$BBDBG_ROOT"
}
trap bbdbg_cleanup EXIT
bbdbg_opkg() {
LD_LIBRARY_PATH=${BBDBG_LIBS} $BBDBG_OPKG -V0 -f $BBDBG_CONF -o $BBDBG_ROOT $@
}
set -x
bbdbg_opkg update
bbdbg_opkg install $BBDBG_PKGS
gdb-multiarch -q \
-iex "set solib-absolute-prefix $BBDBG_ROOT" \
-iex "add-auto-load-safe-path $BBDBG_ROOT" \
-iex "set directories $BBDBG_ROOT" \
${BBDBG_ROOT}${BBDBG_FILE} \
$([ '-' = "${BBDBG_CORE}" ] || echo ${BBDBG_CORE})
set +x