def job(args): # Verify command syntax if len(args) > 2: raise errors.BadArgsError('job', 'job[ <job_id> | <auto>[ <app>]]') # Basic checks _establish_default_terminal() _ensure_scheduler_exists('job') # If job name is not provided then probably only one job is active if len(args) == 0 or args[0] == 'auto': try: job_id = csssi.detect_active_job(default_terminal) # No active jobs except csssi.NoActiveJobError: raise errors.CommandFailedError( 'job', 'No active user jobs found. Cannot proceed.') # More than one job is active except csssi.MoreThanOneActiveJobError: raise errors.CommandFailedError( 'job', 'Found more than one job. Cannot proceed.') # Job Id provided else: job_id = args[0] # In case app name is provided app = args[1] if len(args) == 2 else None # Hosts and PIDs will be stored here pid_dict = None # List job nodes and processes try: pid_dict = csssi.ls_job_pids(default_terminal, job_id, app) # Job does not exist except csssi.InvalidJobError: raise errors.CommandFailedError( 'job', '{0} does not seem to be a valid job id'.format(job_id)) # Cannot determine app except csssi.NoRunningAppFoundError: raise errors.CommandFailedError( 'job', 'No application name lookup pattern provided and automatic MPI application detection did not succeed. Ensure job {0} is actually running a distributed application and provide the application name' .format(job_id)) # Launch GDB and attach to PIDs session_manager, msgs = _attach_pids(pid_dict) # Initialize the debugging session return debug_session.init_debugging_mode(session_manager, msgs)
def _ensure_sessions_selected(cmd): '''Verifies that there are sessions selected at this moment.''' if not selected_sessions: raise errors.CommandFailedError( cmd, 'No session(s) selected. Debugging mode failed to start. (Maybe init_debugging_mode() was not called?)' )
def attach(args): def _find_dead_pids_host(host, pids): dead_pids = [] _establish_default_terminal() _ensure_scheduler_exists('jobs') for pid in pids: if not default_terminal.is_pid_alive(pid): host_path = '.'.join(hops.list_hops()) if host: host_path += '.' + host dead_pids.append('{host}:{pid}'.format(host=host_path or 'localhost', pid=pid)) return dead_pids def _find_dead_pids(pid_dict): # Check the status of all provided PIDs dead_pids = [] for host, pids in pid_dict.iteriterms(): # Establish a connection per each process dead_pids.extend(_find_dead_pids_host(host, pids)) return dead_pids def _parse_group_pids(expr): pid_dict = {} for app_instance in re.finditer(r'((?:(\w+):)?(\d+))', expr): host = app_instance.group(2) pid = int(app_instance.group(3)) if pid_dict.has_key(host): pid_dict[host] += [pid] else: pid_dict[host] = [pid] args_string = ' '.join(args) # Verify command syntax if len(args) < 1 or not re.match(r'(?:(?:\w+:)?\d+|\s)+', args_string): raise errors.BadArgsError( 'attach', 'attach [<host>:]<pid>[ [<host>:]<pid> [...]]') # Group by host pid_dict = _parse_group_pids(args_string) # Check the status of all provided PIDs dead_pids = _find_dead_pids(pid_dict) # Stop if all processes are alive if len(dead_pids) != 0: raise errors.CommandFailedError( 'attach', 'Invalid PIDs provided: {0}'.format(' ,'.join(dead_pids))) # Launch GDB and attach to PIDs session_manager, msgs = _attach_pids(pid_dict) # Initialize the debugging session return debug_session.init_debugging_mode(session_manager, msgs)
def _ensure_scheduler_exists(cmd): if not default_terminal_scheduler: try: global default_terminal_scheduler default_terminal_scheduler = csssi.detect_scheduler( default_terminal) except csssi.NoSchedulerFoundError: if not cmd: return False raise errors.CommandFailedError( cmd, 'Unable to detect the scheduling system type on this machine.') return True
def run(self): try: self.term = console.Terminal( hops.list_hops(), target_host=self.host, meta=self.pid, tag=self.tag, prompt_re=r'\(gdb\)\ \r\n', exit_re=r'&"quit\n"|\^exit', ) self.term.connect() gdb_response = self.term.query(self.cmd) try: self.mi_response = mi_interface.parse(gdb_response) except pexpect.ExceptionPexpect as e: raise errors.CommandFailedError('attach', 'attach', e) except Exception as e: self.error = e
def unhop(args): # Verify command syntax if len(args) > 1: raise errors.BadArgsError('unhop', 'unhop[ <number of hops to remove>].') n_hops_to_remove = 1 if len(args) == 1: try: n_hops_to_remove = int(args[0]) except ValueError: raise errors.BadArgsError('unhop', 'unhop[ <number of hops to remove>].') try: for _ in range(n_hops_to_remove): hops.remove_last() except console.NoHopsError: raise errors.CommandFailedError( 'unhop', 'No more hops currently exist. Nothing can be removed') _establish_default_terminal(reestablish=True) return modes.offline, None