diff --git a/src/apex/apex_preload.cpp b/src/apex/apex_preload.cpp index 7091ace0..3aea7ae9 100644 --- a/src/apex/apex_preload.cpp +++ b/src/apex/apex_preload.cpp @@ -49,9 +49,24 @@ extern "C" { static int (*main_real)(int, char**, char**); int apex_preload_main(int argc, char** argv, char** envp) { + // FIRST! check to see if this is a bash script. if so, DO NOTHING + size_t len{strlen(argv[0])}; + if (len > 4 && strncmp(argv[0] + (len - 4), "bash", 4)) { + return main_real(argc, argv, envp); + } + // FIRST! check to see if this is a [t]csh script. if so, DO NOTHING + if (len > 3 && strncmp(argv[0] + (len - 3), "csh", 3)) { + return main_real(argc, argv, envp); + } + // FIRST! check to see if this is gdb. if so, DO NOTHING (should get caught by the apex_exec script though) + if (len > 3 && strncmp(argv[0] + (len - 3), "gdb", 3)) { + return main_real(argc, argv, envp); + } // prevent re-entry static int _reentry = 0; - if(_reentry > 0) return -1; + if(_reentry > 0) { + return main_real(argc, argv, envp); + } _reentry = 1; int ret{0}; diff --git a/src/scripts/apex_exec b/src/scripts/apex_exec index 222f1c9e..be1cd441 100755 --- a/src/scripts/apex_exec +++ b/src/scripts/apex_exec @@ -628,33 +628,60 @@ fi echo_screen "APEX_LD_LIBRARY_PATH: ${APEX_LD_LIBRARY_PATH}" echo_screen "APEX_LD_PRELOAD: ${APEX_LD_PRELOAD}" +if [ $debug = yes ] ; then + if [ "${myrank}" == "0" ] ; then + rm -f ./.gdbcmds + fi +fi + if [ $apple = 1 ]; then - export DYLD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH} - export DYLD_INSERT_LIBRARIES=${APEX_LD_PRELOAD} - export DYLD_FORCE_FLAT_NAMESPACE=1 if [ $debug = yes ] ; then - echo "_regexp-env DYLD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH}" >> ./.gdbcmds - echo "_regexp-env DYLD_INSERT_LIBRARIES=${APEX_LD_PRELOAD}" >> ./.gdbcmds - echo "_regexp-env DYLD_FORCE_FLAT_NAMESPACE=1" >> ./.gdbcmds - debugger="lldb -s ./.gdbcmds --" + if [ "${myrank}" == "0" ] ; then + echo "_regexp-env DYLD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH}" >> ./.gdbcmds + echo "_regexp-env DYLD_INSERT_LIBRARIES=${APEX_LD_PRELOAD}" >> ./.gdbcmds + echo "_regexp-env DYLD_FORCE_FLAT_NAMESPACE=1" >> ./.gdbcmds if [ $# -gt 1 ] ; then echo "settings set target.run-args ${*:2}" >> .gdb_commands fi + else + # Give rank 0 enough time to write the .gdbcmds file + until [ -f ./.gdbcmds ] ; do + sleep 1 + done + fi + debugger="lldb -s ./.gdbcmds --" + else + export DYLD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH} + export DYLD_INSERT_LIBRARIES=${APEX_LD_PRELOAD} + export DYLD_FORCE_FLAT_NAMESPACE=1 fi else - export LD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH} - export LD_PRELOAD=${APEX_LD_PRELOAD} - # Not sure if the DL auditor is necessary - #export LD_AUDIT=${APEX_LD_AUDIT} if [ $debug = yes ] ; then + if [ "${myrank}" == "0" ] ; then echo "set env LD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH}" >> ./.gdbcmds echo "set env LD_PRELOAD=${APEX_LD_PRELOAD}" >> ./.gdbcmds + if [ $mpi = yes ]; then + echo "run" >> ./.gdbcmds + #echo "bt" >> ./.gdbcmds + echo "quit" >> ./.gdbcmds + fi + else + # Give rank 0 enough time to write the .gdbcmds file + until [ -f ./.gdbcmds ] ; do + sleep 1 + done + fi #echo "set env LD_AUDIT=${APEX_LD_AUDIT}" >> ./.gdbcmds if [ $hip = yes ] ; then debugger="rocgdb -x ./.gdbcmds --args" else debugger="gdb -x ./.gdbcmds --args" fi + else + export LD_LIBRARY_PATH=${APEX_LD_LIBRARY_PATH} + export LD_PRELOAD=${APEX_LD_PRELOAD} + # Not sure if the DL auditor is necessary + #export LD_AUDIT=${APEX_LD_AUDIT} fi fi @@ -733,7 +760,9 @@ else retval=$? unset LD_PRELOAD unset DYLD_INSERT_LIBRARIES - rm -f ./.gdbcmds + if [ "${myrank}" == "0" ] ; then + rm -f ./.gdbcmds + fi if [ ${retval} != 0 ] ; then echo "Error ${retval}!" count=`ldd ${MPI_LIB2} | grep -c tcmalloc`