Skip to content

Commit

Permalink
Fixing startup issues when launched with gdb, or just in general
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Feb 7, 2024
1 parent a1ace3a commit 89f4b6c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
17 changes: 16 additions & 1 deletion src/apex/apex_preload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
53 changes: 41 additions & 12 deletions src/scripts/apex_exec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 89f4b6c

Please sign in to comment.