1#!/bin/sh 2 3set -eu 4 5bbdbg_help() { 6 /bin/echo -e "NAME" 7 /bin/echo -e "\tbbdbg - debug applications in a target environment built by bitbake" 8 /bin/echo -e 9 /bin/echo -e "SYNOPSIS" 10 /bin/echo -e "\tbbdbg PATH FILE CORE PACKAGES" 11 /bin/echo -e 12 /bin/echo -e "DESCRIPTION" 13 /bin/echo -e "\tPATH is the path to the root of a bitbake build directory" 14 /bin/echo -e "\tFILE is the absolute path to the binary of interest in the target environment" 15 /bin/echo -e "\tCORE is an optional core file generated by FILE. Pass '-' for no core file" 16 /bin/echo -e "\tPACKAGES will be used to populate a temporary rootfs for debugging FILE" 17 /bin/echo -e 18 /bin/echo -e "EXAMPLE" 19 /bin/echo -e "\tbbdbg ~/src/openbmc/openbmc/build/p10bmc \\" 20 /bin/echo -e "\t\t/usr/bin/nvmesensor - \\" 21 /bin/echo -e "\t\tdbus-sensors dbus-sensors-dbg" 22} 23 24trap bbdbg_help EXIT 25 26BBDBG_PATH=$1; shift 27BBDBG_FILE=$1; shift 28BBDBG_CORE=$1; shift 29BBDBG_PKGS=$@ 30 31BBDBG_ROOT=$(mktemp -t --directory bbdbg.XXX) 32BBDBG_LIBS=${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/libsolv-native/usr/lib:${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/libarchive-native/usr/lib 33BBDBG_OPKG=${BBDBG_PATH}/tmp/sysroots-components/$(uname -m)/opkg-native/usr/bin/opkg 34BBDBG_CONF=$(find ${BBDBG_PATH}/tmp/work/*/obmc-phosphor-image -name opkg.conf -exec grep -lE ^src \{\} \;) 35 36bbdbg_cleanup() { 37 rm -rf "$BBDBG_ROOT" 38} 39 40trap bbdbg_cleanup EXIT 41 42bbdbg_opkg() { 43 LD_LIBRARY_PATH=${BBDBG_LIBS} $BBDBG_OPKG -V0 -f $BBDBG_CONF -o $BBDBG_ROOT $@ 44} 45 46set -x 47bbdbg_opkg update 48bbdbg_opkg install $BBDBG_PKGS 49gdb-multiarch -q \ 50 -iex "set solib-absolute-prefix $BBDBG_ROOT" \ 51 -iex "add-auto-load-safe-path $BBDBG_ROOT" \ 52 -iex "set directories $BBDBG_ROOT" \ 53 ${BBDBG_ROOT}${BBDBG_FILE} \ 54 $([ '-' = "${BBDBG_CORE}" ] || echo ${BBDBG_CORE}) 55set +x 56