def listen(self): """ Create socket server which listens for connection on configured port. """ # Create socket server server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if server: # Configure socket server try: server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.settimeout(1) server.bind((self.host, self.port)) server.listen(1) self.listening = True self.socket = None except: e = sys.exc_info()[1] debug('Failed to create socket: %s' % e) # Substitute exception with readable (custom) message if isinstance(e, TypeError) and not H.is_number(self.port): e = 'Configured port is not a valid integer.' elif isinstance(e, socket.gaierror) and self.host != '': e = 'Hostname (%s) is not specified in hosts file or is an IPv6 address.' % self.host elif hasattr(e, 'errno'): address_or_port = 'address (%s:%d)' % (self.host, self.port) if self.host != '' else 'port (%d)' % self.port if e.errno == errno.EADDRINUSE: e = 'Another application is already listening on configured %s.' % address_or_port elif e.errno == errno.EADDRNOTAVAIL: e = 'Configured %s is not accessible.' % address_or_port raise ProtocolListenException(e) # Accept incoming connection on configured port while self.listening: try: self.socket, address = server.accept() self.listening = False except socket.timeout: pass # Check if a connection has been made if self.socket: self.connected = True self.socket.settimeout(None) else: self.connected = False self.listening = False # Close socket server try: server.close() except: pass server = None # Return socket connection return self.socket else: raise ProtocolListenException('Could not create socket server.')
def init(self): if not is_connected(): return # Connection initialization init = S.SESSION.read() # More detailed internal information on properties S.SESSION.send(dbgp.FEATURE_SET, n='show_hidden', v=1) S.SESSION.read() # Set max children limit max_children = get_value(S.KEY_MAX_CHILDREN) if max_children is not False and max_children is not True and ( H.is_number(max_children) or H.is_digit(max_children)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_CHILDREN, v=max_children) S.SESSION.read() # Set max data limit max_data = get_value(S.KEY_MAX_DATA) if max_data is not False and max_data is not True and ( H.is_number(max_data) or H.is_digit(max_data)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_DATA, v=max_data) S.SESSION.read() # Set max depth limit max_depth = get_value(S.KEY_MAX_DEPTH) if max_depth is not False and max_depth is not True and ( H.is_number(max_depth) or H.is_digit(max_depth)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_DEPTH, v=max_depth) S.SESSION.read() # Set breakpoints for files for filename, breakpoint_data in S.BREAKPOINT.items(): if breakpoint_data: for lineno, bp in breakpoint_data.items(): if bp['enabled']: self.set_breakpoint(filename, lineno, bp['expression']) debug('breakpoint_set: ' + filename + ':' + lineno) # Set breakpoints for exceptions break_on_exception = get_value(S.KEY_BREAK_ON_EXCEPTION) if isinstance(break_on_exception, list): for exception_name in break_on_exception: self.set_exception(exception_name) # Determine if client should break at first line on connect if get_value(S.KEY_BREAK_ON_START): # Get init attribute values fileuri = init.get(dbgp.INIT_FILEURI) filename = get_real_path(fileuri) # Show debug/status output self.status_message('Xdebug: Break on start') info('Break on start: ' + filename) # Store line number of breakpoint for displaying region marker S.BREAKPOINT_ROW = {'filename': filename, 'lineno': 1} # Focus/Open file window view self.timeout(lambda: show_file(filename, 1)) # Context variables context = self.get_context_values() self.timeout(lambda: show_content(DATA_CONTEXT, context)) # Stack history stack = self.get_stack_values() if not stack: stack = H.unicode_string( '[{level}] {filename}.{where}:{lineno}\n'.format( level=0, where='{main}', lineno=1, filename=fileuri)) self.timeout(lambda: show_content(DATA_STACK, stack)) # Watch expressions self.watch_expression() else: # Tell script to run it's process self.run_command('xdebug_execute', {'command': 'run'})
def init(self): if not is_connected(): return # Connection initialization init = S.SESSION.read() # More detailed internal information on properties S.SESSION.send(dbgp.FEATURE_SET, n='show_hidden', v=1) S.SESSION.read() # Set max children limit max_children = get_value(S.KEY_MAX_CHILDREN) if max_children is not False and max_children is not True and (H.is_number(max_children) or H.is_digit(max_children)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_CHILDREN, v=max_children) S.SESSION.read() # Set max data limit max_data = get_value(S.KEY_MAX_DATA) if max_data is not False and max_data is not True and (H.is_number(max_data) or H.is_digit(max_data)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_DATA, v=max_data) S.SESSION.read() # Set max depth limit max_depth = get_value(S.KEY_MAX_DEPTH) if max_depth is not False and max_depth is not True and (H.is_number(max_depth) or H.is_digit(max_depth)): S.SESSION.send(dbgp.FEATURE_SET, n=dbgp.FEATURE_NAME_MAX_DEPTH, v=max_depth) S.SESSION.read() # Set breakpoints for files for filename, breakpoint_data in S.BREAKPOINT.items(): if breakpoint_data: for lineno, bp in breakpoint_data.items(): if bp['enabled']: self.set_breakpoint(filename, lineno, bp['expression']) debug('breakpoint_set: ' + filename + ':' + lineno) # Set breakpoints for exceptions break_on_exception = get_value(S.KEY_BREAK_ON_EXCEPTION) if isinstance(break_on_exception, list): for exception_name in break_on_exception: self.set_exception(exception_name) # Determine if client should break at first line on connect if get_value(S.KEY_BREAK_ON_START): # Get init attribute values fileuri = init.get(dbgp.INIT_FILEURI) filename = get_real_path(fileuri) # Show debug/status output self.status_message('Xdebug: Break on start') info('Break on start: ' + filename) # Store line number of breakpoint for displaying region marker S.BREAKPOINT_ROW = {'filename': filename, 'lineno': 1} # Focus/Open file window view self.timeout(lambda: show_file(filename, 1)) # Context variables context = self.get_context_values() self.timeout(lambda: show_content(DATA_CONTEXT, context)) # Stack history stack = self.get_stack_values() if not stack: stack = H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' .format(level=0, where='{main}', lineno=1, filename=fileuri)) self.timeout(lambda: show_content(DATA_STACK, stack)) # Watch expressions self.watch_expression() else: # Tell script to run it's process self.run_command('xdebug_execute', {'command': 'run'})