#!/bin/sh
#
#   !!works with Lam-mpi only!!       
#   script to debug one out of a bunch of processes using gdb
# 
# usage:
#
#   lamboot
#   mpirun -np <nproc> lamgdb <proc_to_attach_gdb_to> executable arg1 arg2
#
#   launches gdb on proc_to_attach_gdb_to in a separate window
#   the arguments to executable have to be specified in gdb again:
#
#   (gdb): set args arg1 arg2
#   or
#   (gdb): run arg1 arg2
#
#   on finalization of gdb, all remaining processes of executable are killed
#   (this is not tooo elegant, but it works)
#
# see also:
#   lamgdbm: script to launch all processes in gdb
#
if [ "$LAMRANK" -eq $1 ]
then
   echo "Launching gdb $2 on rank $LAMRANK"
   xterm -sb -title "gdb on proc $LAMRANK" -e /usr/bin/gdb $2 $3 $4
   PROCS=`ps aux | grep -v "grep" | grep -v $0 | grep $2 | awk -F' ' '{printf("%s ",$2)}'`
   echo $PROCS
   kill -9 $PROCS
else
   echo "Launching $2 $3 $4 on rank $LAMRANK"
   ./$2 $3 $4
fi
