#! /bin/ksh

typeset CORE_FILE=''
typeset EXE=''
typeset EXE_WITH_PATH=''

find . -name core | while read CORE_FILE
do
  print '::::::::::::::::::::::::::::::::::::::::::'
  ls -alrFt "${CORE_FILE}"
  print '::::::::::::::::::::::::::::::::::::::::::'
  EXE=$( file "${CORE_FILE}" | awk -F, '{print $2}' )
  if [[ -z "${EXE}" ]]
  then
    print -u2 "Can not find executable corresponding to \"${CORE_FILE}\", continueing."
    continue
  fi
  EXE_WITH_PATH=$( whence -p "${EXE}" )
  if (( $? != 0 ))
  then
    print -u2 "Can not locate executable \"${EXE}\", continueing."
    continue
  fi
  gdb -x "${HOME}/bin/gdb_where_quit.batch" -batch "${EXE_WITH_PATH}" "${CORE_FILE}" 2>&1
done

################# EOF #################
