def get_stack_values(): """ Get stack information for current context. """ values = H.unicode_string('') if S.SESSION: try: # Get stack information S.SESSION.send(dbgp.STACK_GET) response = S.SESSION.read() for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) return values
def generate_stack_output(response): values = H.unicode_string('') # Display exception name and message if S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{name}] {message}\n' \ .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message'])) # Walk through elements in response has_output = False try: for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) has_output = True except: pass # When no stack use values from exception if not has_output and S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filename=S.BREAKPOINT_EXCEPTION['filename'])) return values
def get_stack_values(): """ Get stack information for current context. """ values = H.unicode_string('') if S.SESSION: try: # Get stack information S.SESSION.send(dbgp.STACK_GET) response = S.SESSION.read() for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) return values
def generate_stack_output(response): values = H.unicode_string('') # Display exception name and message if S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{name}] {message}\n' \ .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message'])) # Walk through elements in response has_output = False try: for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) has_output = True except: pass # When no stack use values from exception if not has_output and S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filename=S.BREAKPOINT_EXCEPTION['filename'])) return values
def generate_stack_output(response): values = H.unicode_string('') # Display exception name and message if S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{name}] {message}\n' \ .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message'])) has_output = False for level, stackData in response.items(): stack_level = level stack_type = 'file' #child.get(dbgp.STACK_TYPE) stack_file = get_real_path(H.url_decode(stackData['source'])) stack_line = stackData['line'] stack_name = stackData.get( 'name', '') #child.get(dbgp.STACK_WHERE, '{unknown}') stack_namewhat = stackData[ 'namewhat'] #child.get(dbgp.STACK_WHERE, '{unknown}') if stack_namewhat != '': values += H.unicode_string('[{level}] {filename}:{lineno} - {name}({namewhat})\n' \ .format(level=stack_level, type=stack_type, name=stack_name, namewhat = stack_namewhat, lineno=stack_line, filename=stack_file)) else: values += H.unicode_string('[{level}] {filename}:{lineno}\n' \ .format(level=stack_level, type=stack_type, lineno=stack_line, filename=stack_file)) has_output = True # Walk through elements in response #try: # for child in response: # # Get stack attribute values # if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: # stack_level = child.get(dbgp.STACK_LEVEL, 0) # stack_type = child.get(dbgp.STACK_TYPE) # stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) # stack_line = child.get(dbgp.STACK_LINENO, 0) # stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # # Append values # values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ # .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) # has_output = True #except: # pass # When no stack use values from exception if not has_output and S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filename=S.BREAKPOINT_EXCEPTION['filename'])) return values
def generate_stack_output(response): values = H.unicode_string('') # Display exception name and message if S.BREAKPOINT_EXCEPTION: values += H.unicode_string('[{name}] {message}\n' \ .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message'])) # Walk through elements in response has_output = False try: for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values filename = os.path.basename(stack_file) values += H.unicode_string('[{level}] {lineno} {filename} {where} {filepath}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filepath=stack_file, filename=filename)) has_output = True except: pass # When no stack use values from exception if not has_output and S.BREAKPOINT_EXCEPTION: filename = os.path.basename(stack_file) values += H.unicode_string('[{level}] {lineno} {filename} {where} {filepath}\n' \ .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filepath=S.BREAKPOINT_EXCEPTION['filename'], filename=filename)) # Space all out equally lines = values.split('\n') lines_bits = [x.strip().split(' ') for x in lines] bit_widths = [] for line_bits in lines_bits: for i, line_bit in enumerate(line_bits): line_bits[i] = line_bit.strip() if len(bit_widths) <= i: bit_widths.append(0) bit_widths[i] = max(bit_widths[i], len(line_bit.strip())) new_lines = [] for i, line_bits in enumerate(lines_bits): if(len(line_bits) > 1): line_bits[1] = line_bits[1].rjust(bit_widths[1]) new_lines.append(' '.join([b.ljust(bit_widths[j]) for j, b in enumerate(line_bits)])) values = '\n'.join(new_lines) return values
def generate_stack_output(response): values = H.unicode_string('') # Walk through elements in response try: for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) except: pass return values
def generate_stack_output(response): values = H.unicode_string('') # Walk through elements in response try: for child in response: # Get stack attribute values if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK: stack_level = child.get(dbgp.STACK_LEVEL, 0) stack_type = child.get(dbgp.STACK_TYPE) stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME)) stack_line = child.get(dbgp.STACK_LINENO, 0) stack_where = child.get(dbgp.STACK_WHERE, '{unknown}') # Append values values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \ .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file)) except: pass return values
def get_real_path(uri, server=False): """ Get real path Keyword arguments: uri -- Uri of file that needs to be mapped and located server -- Map local path to server path TODO: Fix mapping for root (/) and drive letters (P:/) """ if uri is None: return uri # URLdecode uri uri = H.url_decode(uri) # Split scheme from uri to get absolute path try: # scheme:///path/file => scheme, /path/file # scheme:///C:/path/file => scheme, C:/path/file transport, filename = uri.split(':///', 1) except: filename = uri # Normalize path for comparison and remove duplicate/trailing slashes uri = os.path.normpath(filename) # Pattern for checking if uri is a windows path drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]') # Append leading slash if filesystem is not Windows if not drive_pattern.match(uri) and not os.path.isabs(uri): uri = os.path.normpath('/' + uri) path_mapping = S.get_config_value('path_mapping') if isinstance(path_mapping, dict): # Go through path mappings for server_path, local_path in path_mapping.items(): server_path = os.path.normpath(server_path) local_path = os.path.normpath(local_path) # Replace path if mapping available if server: # Map local path to server path if local_path in uri: uri = uri.replace(local_path, server_path) break else: # Map server path to local path if server_path in uri: uri = uri.replace(server_path, local_path) break else: sublime.set_timeout( lambda: sublime.status_message( "Xdebug: No path mapping defined, returning given path."), 0) # Replace slashes if not drive_pattern.match(uri): uri = uri.replace("\\", "/") # Append scheme if server: return H.url_encode("file://" + uri) return uri
def get_real_path(uri, server=False): """ Get real path Keyword arguments: uri -- Uri of file that needs to be mapped and located server -- Map local path to server path TODO: Fix mapping for root (/) and drive letters (P:/) """ if uri is None: return uri # URLdecode uri uri = H.url_decode(uri) # Split scheme from uri to get absolute path try: # scheme:///path/file => scheme, /path/file # scheme:///C:/path/file => scheme, C:/path/file transport, filename = uri.split(':///', 1) except: filename = uri # Normalize path for comparison and remove duplicate/trailing slashes uri = os.path.normpath(filename) # Pattern for checking if uri is a windows path drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]') # Append leading slash if filesystem is not Windows if not drive_pattern.match(uri) and not os.path.isabs(uri): uri = os.path.normpath('/' + uri) path_mapping = S.get_config_value('path_mapping') if isinstance(path_mapping, dict): # Go through path mappings for server_path, local_path in path_mapping.items(): server_path = os.path.normpath(server_path) local_path = os.path.normpath(local_path) # Replace path if mapping available if server: # Map local path to server path if local_path in uri: uri = uri.replace(local_path, server_path) break else: # Map server path to local path if server_path in uri: uri = uri.replace(server_path, local_path) break else: sublime.set_timeout(lambda: sublime.status_message("Xdebug: No path mapping defined, returning given path."), 0) # Replace slashes if not drive_pattern.match(uri): uri = uri.replace("\\", "/") # Append scheme if server: return H.url_encode("file://" + uri) return uri
def get_real_path(uri, server=False): """ Get real path Keyword arguments: uri -- Uri of file that needs to be mapped and located server -- Map local path to server path TODO: Fix mapping for root (/) and drive letters (P:/) """ if uri is None: return uri # URLdecode uri uri = H.url_decode(uri) # Split scheme from uri to get absolute path try: # scheme:///path/file => scheme, /path/file # scheme:///C:/path/file => scheme, C:/path/file transport, filename = uri.split(':///', 1) except: filename = uri #filename = try_get_local_path_from_mounted_paths(uri) filename = filename.replace( '@', '' ) # remove lua @ which represents "a file" as opposed to something run inline/from a REPL # Normalize path for comparison and remove duplicate/trailing slashes uri = os.path.normpath(filename) # Pattern for checking if uri is a windows path windows_pattern = re.compile('.*\\.*') is_windows_pattern = windows_pattern.match(uri) != None # Prepend leading slash if filesystem is not Windows if not is_windows_pattern and not os.path.isabs(uri): uri = os.path.normpath('/' + uri) path_mapping = get_value(S.KEY_PATH_MAPPING) if isinstance(path_mapping, dict): found_path_mapping = False found_parent_path_mapping = False # Go through path mappings for server_path, local_path in path_mapping.items(): server_path = os.path.normpath(server_path) local_path = os.path.normpath(local_path) # Replace path if mapping available if server: # Map local path to server path if local_path in uri: uri = uri.replace(local_path, server_path) found_path_mapping = True break else: # Map server path to local path if server_path in uri: uri = uri.replace(server_path, local_path) found_path_mapping = True break if not found_path_mapping: if server: found_parent_path_mapping = server_path in uri else: found_parent_path_mapping = local_path in uri # "=[C]" is a special case url for lua C code if not found_path_mapping and not found_parent_path_mapping and uri != '=[C]': server_or_local = 'server' if server else 'local' sublime.set_timeout( lambda: sublime.error_message( "GRLD: No {} path mapping defined for path {}. It's likely that your breakpoints for this file won't be hit! You can set up path mappings in the SublimeTextGRLD package settings." .format(server_or_local, uri)), 0) else: sublime.set_timeout( lambda: sublime.status_message( "GRLD: No path mapping defined, returning given path."), 100) # special transformations for server paths (GRLD expects this) if server: uri = uri.replace("\\", "/") uri = os.path.join("./", uri) uri = "@{}".format(uri) uri = uri.lower() if not is_fs_case_sensitive( ) else uri # <-- Note, lua's path normalize() function returns lowercase paths if fs is case-insensitive (regardless of input) # Append scheme #if server: #return H.url_encode("file://" + uri) return uri