Refactored dbg_exec/dbg_attach code