mpirun provides some help in starting programs with a debugger.
mpirun -dbg=<name of debugger> -np 2 programstarts program on two machines, with the local one running under the chosen debugger. There are 5 debugger scripts included with mpich which will be located in the mpich/bin directory after executing make. They are named mpirun_dbg.%d where %d can be replaced with dbx, ddd, gdb, totalview, and xxgdb. The appropriate script is invoked when the -dbg option is used with mpirun