#!/bin/bash # run_debug_app.sh - Launch the MARTe2 Debugging Environment using standard MARTeApp.ex # 1. Environment Setup if [ -f "./env.sh" ]; then source ./env.sh else echo "ERROR: env.sh not found. Ensure you are in the project root." exit 1 fi # 2. Paths MARTE_EX="${MARTe2_DIR}/Build/${TARGET}/App/MARTeApp.ex" BUILD_DIR="$(pwd)/Build/${TARGET}" # Our plugin libraries DEBUG_LIB="${BUILD_DIR}/Components/Interfaces/DebugService/libDebugService.so" TCPLOGGER_LIB="${BUILD_DIR}/Components/Interfaces/TCPLogger/libTcpLogger.so" # Component library base search path COMPONENTS_BUILD_DIR="${MARTe2_Components_DIR}/Build/${TARGET}/Components" # DYNAMICALLY FIND ALL COMPONENT DIRS and add to LD_LIBRARY_PATH ALL_COMPONENT_DIRS=$(find "$COMPONENTS_BUILD_DIR" -type d) for dir in $ALL_COMPONENT_DIRS; do if ls "$dir"/*.so >/dev/null 2>&1; then export LD_LIBRARY_PATH="$dir:$LD_LIBRARY_PATH" fi done # Ensure our build dir and core dir are included export LD_LIBRARY_PATH="${BUILD_DIR}/Components/Interfaces/DebugService:${BUILD_DIR}/Components/Interfaces/TCPLogger:${MARTe2_DIR}/Build/${TARGET}/Core:${LD_LIBRARY_PATH}" # 3. Cleanup echo "Cleaning up lingering processes..." pkill -9 MARTeApp.ex sleep 1 # 4. Validate libraries exist for lib in "$DEBUG_LIB" "$TCPLOGGER_LIB"; do if [ ! -f "$lib" ]; then echo "ERROR: Library not found: $lib" echo "Run: make -f Makefile.gcc core" exit 1 fi done # 5. Launch Application echo "Launching standard MARTeApp.ex with debug_test.cfg..." # LD_PRELOAD ensures our classes are registered before the config is parsed. # MARTeApp.ex does not use dlopen for plugins — preloading is the standard approach. # All required component .so files are collected via the find loop into LD_PRELOAD too. PRELOAD_LIBS="${DEBUG_LIB}:${TCPLOGGER_LIB}" # Collect any additional component .so files referenced by the config for lib in \ "${COMPONENTS_BUILD_DIR}/DataSources/RealTimeThreadSynchronisation/RealTimeThreadSynchronisation.so" \ "${COMPONENTS_BUILD_DIR}/DataSources/LinuxTimer/LinuxTimer.so" \ "${COMPONENTS_BUILD_DIR}/DataSources/LoggerDataSource/LoggerDataSource.so" \ "${COMPONENTS_BUILD_DIR}/GAMs/IOGAM/IOGAM.so"; do if [ -f "$lib" ]; then PRELOAD_LIBS="${PRELOAD_LIBS}:${lib}" fi done export LD_PRELOAD="${PRELOAD_LIBS}" "$MARTE_EX" -f Test/Configurations/debug_test.cfg -l RealTimeLoader -s State1