diff options
Diffstat (limited to 'src/etc')
| -rwxr-xr-x | src/etc/dec2flt_table.py | 46 | ||||
| -rw-r--r-- | src/etc/gdb_load_rust_pretty_printers.py | 1 | ||||
| -rw-r--r-- | src/etc/gdb_lookup.py | 7 | ||||
| -rw-r--r-- | src/etc/gdb_providers.py | 35 | ||||
| -rwxr-xr-x | src/etc/generate-deriving-span-tests.py | 62 | ||||
| -rwxr-xr-x | src/etc/generate-keyword-tests.py | 8 | ||||
| -rwxr-xr-x | src/etc/htmldocck.py | 260 | ||||
| -rw-r--r-- | src/etc/lldb_batchmode.py | 69 | ||||
| -rw-r--r-- | src/etc/lldb_providers.py | 186 | ||||
| -rw-r--r-- | src/etc/rust_types.py | 3 |
10 files changed, 426 insertions, 251 deletions
diff --git a/src/etc/dec2flt_table.py b/src/etc/dec2flt_table.py index 9264a8439bb..791186de9c1 100755 --- a/src/etc/dec2flt_table.py +++ b/src/etc/dec2flt_table.py @@ -13,6 +13,7 @@ i.e., within 0.5 ULP of the true value. Adapted from Daniel Lemire's fast_float ``table_generation.py``, available here: <https://github.com/fastfloat/fast_float/blob/main/script/table_generation.py>. """ + from __future__ import print_function from math import ceil, floor, log from collections import deque @@ -34,6 +35,7 @@ STATIC_WARNING = """ // the final binary. """ + def main(): min_exp = minimum_exponent(10) max_exp = maximum_exponent(10) @@ -41,10 +43,10 @@ def main(): print(HEADER.strip()) print() - print('pub const SMALLEST_POWER_OF_FIVE: i32 = {};'.format(min_exp)) - print('pub const LARGEST_POWER_OF_FIVE: i32 = {};'.format(max_exp)) - print('pub const N_POWERS_OF_FIVE: usize = ', end='') - print('(LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;') + print("pub const SMALLEST_POWER_OF_FIVE: i32 = {};".format(min_exp)) + print("pub const LARGEST_POWER_OF_FIVE: i32 = {};".format(max_exp)) + print("pub const N_POWERS_OF_FIVE: usize = ", end="") + print("(LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;") print() print_proper_powers(min_exp, max_exp, bias) @@ -54,7 +56,7 @@ def minimum_exponent(base): def maximum_exponent(base): - return floor(log(1.7976931348623157e+308, base)) + return floor(log(1.7976931348623157e308, base)) def print_proper_powers(min_exp, max_exp, bias): @@ -64,46 +66,46 @@ def print_proper_powers(min_exp, max_exp, bias): # 2^(2b)/(5^−q) with b=64 + int(math.ceil(log2(5^−q))) powers = [] for q in range(min_exp, 0): - power5 = 5 ** -q + power5 = 5**-q z = 0 while (1 << z) < power5: z += 1 if q >= -27: b = z + 127 - c = 2 ** b // power5 + 1 + c = 2**b // power5 + 1 powers.append((c, q)) else: b = 2 * z + 2 * 64 - c = 2 ** b // power5 + 1 + c = 2**b // power5 + 1 # truncate - while c >= (1<<128): + while c >= (1 << 128): c //= 2 powers.append((c, q)) # Add positive exponents for q in range(0, max_exp + 1): - power5 = 5 ** q + power5 = 5**q # move the most significant bit in position - while power5 < (1<<127): + while power5 < (1 << 127): power5 *= 2 # *truncate* - while power5 >= (1<<128): + while power5 >= (1 << 128): power5 //= 2 powers.append((power5, q)) # Print the powers. print(STATIC_WARNING.strip()) - print('#[rustfmt::skip]') - typ = '[(u64, u64); N_POWERS_OF_FIVE]' - print('pub static POWER_OF_FIVE_128: {} = ['.format(typ)) + print("#[rustfmt::skip]") + typ = "[(u64, u64); N_POWERS_OF_FIVE]" + print("pub static POWER_OF_FIVE_128: {} = [".format(typ)) for c, exp in powers: - hi = '0x{:x}'.format(c // (1 << 64)) - lo = '0x{:x}'.format(c % (1 << 64)) - value = ' ({}, {}), '.format(hi, lo) - comment = '// {}^{}'.format(5, exp) - print(value.ljust(46, ' ') + comment) - print('];') + hi = "0x{:x}".format(c // (1 << 64)) + lo = "0x{:x}".format(c % (1 << 64)) + value = " ({}, {}), ".format(hi, lo) + comment = "// {}^{}".format(5, exp) + print(value.ljust(46, " ") + comment) + print("];") -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/src/etc/gdb_load_rust_pretty_printers.py b/src/etc/gdb_load_rust_pretty_printers.py index e05039ce474..73d1e79f961 100644 --- a/src/etc/gdb_load_rust_pretty_printers.py +++ b/src/etc/gdb_load_rust_pretty_printers.py @@ -1,6 +1,7 @@ # Add this folder to the python sys path; GDB Python-interpreter will now find modules in this path import sys from os import path + self_dir = path.dirname(path.realpath(__file__)) sys.path.append(self_dir) diff --git a/src/etc/gdb_lookup.py b/src/etc/gdb_lookup.py index f3ac9c10978..d368f7ed1ec 100644 --- a/src/etc/gdb_lookup.py +++ b/src/etc/gdb_lookup.py @@ -6,8 +6,11 @@ from gdb_providers import * from rust_types import * -_gdb_version_matched = re.search('([0-9]+)\\.([0-9]+)', gdb.VERSION) -gdb_version = [int(num) for num in _gdb_version_matched.groups()] if _gdb_version_matched else [] +_gdb_version_matched = re.search("([0-9]+)\\.([0-9]+)", gdb.VERSION) +gdb_version = ( + [int(num) for num in _gdb_version_matched.groups()] if _gdb_version_matched else [] +) + def register_printers(objfile): objfile.pretty_printers.append(printer) diff --git a/src/etc/gdb_providers.py b/src/etc/gdb_providers.py index e8f9dee07d3..34bb5c39909 100644 --- a/src/etc/gdb_providers.py +++ b/src/etc/gdb_providers.py @@ -21,7 +21,7 @@ def unwrap_unique_or_non_null(unique_or_nonnull): # GDB 14 has a tag class that indicates that extension methods are ok # to call. Use of this tag only requires that printers hide local # attributes and methods by prefixing them with "_". -if hasattr(gdb, 'ValuePrinter'): +if hasattr(gdb, "ValuePrinter"): printer_base = gdb.ValuePrinter else: printer_base = object @@ -98,7 +98,7 @@ class StdStrProvider(printer_base): def _enumerate_array_elements(element_ptrs): - for (i, element_ptr) in enumerate(element_ptrs): + for i, element_ptr in enumerate(element_ptrs): key = "[{}]".format(i) element = element_ptr.dereference() @@ -173,7 +173,8 @@ class StdVecDequeProvider(printer_base): def children(self): return _enumerate_array_elements( - (self._data_ptr + ((self._head + index) % self._cap)) for index in xrange(self._size) + (self._data_ptr + ((self._head + index) % self._cap)) + for index in xrange(self._size) ) @staticmethod @@ -270,7 +271,9 @@ def children_of_btree_map(map): # Yields each key/value pair in the node and in any child nodes. def children_of_node(node_ptr, height): def cast_to_internal(node): - internal_type_name = node.type.target().name.replace("LeafNode", "InternalNode", 1) + internal_type_name = node.type.target().name.replace( + "LeafNode", "InternalNode", 1 + ) internal_type = gdb.lookup_type(internal_type_name) return node.cast(internal_type.pointer()) @@ -293,8 +296,16 @@ def children_of_btree_map(map): # Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays. key_type_size = keys.type.sizeof val_type_size = vals.type.sizeof - key = keys[i]["value"]["value"] if key_type_size > 0 else gdb.parse_and_eval("()") - val = vals[i]["value"]["value"] if val_type_size > 0 else gdb.parse_and_eval("()") + key = ( + keys[i]["value"]["value"] + if key_type_size > 0 + else gdb.parse_and_eval("()") + ) + val = ( + vals[i]["value"]["value"] + if val_type_size > 0 + else gdb.parse_and_eval("()") + ) yield key, val if map["length"] > 0: @@ -352,7 +363,7 @@ class StdOldHashMapProvider(printer_base): self._hashes = self._table["hashes"] self._hash_uint_type = self._hashes.type self._hash_uint_size = self._hashes.type.sizeof - self._modulo = 2 ** self._hash_uint_size + self._modulo = 2**self._hash_uint_size self._data_ptr = self._hashes[ZERO_FIELD]["pointer"] self._capacity_mask = int(self._table["capacity_mask"]) @@ -382,8 +393,14 @@ class StdOldHashMapProvider(printer_base): hashes = self._hash_uint_size * self._capacity align = self._pair_type_size - len_rounded_up = (((((hashes + align) % self._modulo - 1) % self._modulo) & ~( - (align - 1) % self._modulo)) % self._modulo - hashes) % self._modulo + len_rounded_up = ( + ( + (((hashes + align) % self._modulo - 1) % self._modulo) + & ~((align - 1) % self._modulo) + ) + % self._modulo + - hashes + ) % self._modulo pairs_offset = hashes + len_rounded_up pairs_start = gdb.Value(start + pairs_offset).cast(self._pair_type.pointer()) diff --git a/src/etc/generate-deriving-span-tests.py b/src/etc/generate-deriving-span-tests.py index d61693460bc..2e810d7df97 100755 --- a/src/etc/generate-deriving-span-tests.py +++ b/src/etc/generate-deriving-span-tests.py @@ -12,7 +12,8 @@ import os import stat TEST_DIR = os.path.abspath( - os.path.join(os.path.dirname(__file__), '../test/ui/derives/')) + os.path.join(os.path.dirname(__file__), "../test/ui/derives/") +) TEMPLATE = """\ // This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' @@ -56,28 +57,33 @@ ENUM_TUPLE, ENUM_STRUCT, STRUCT_FIELDS, STRUCT_TUPLE = range(4) def create_test_case(type, trait, super_traits, error_count): - string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type] - all_traits = ','.join([trait] + super_traits) - super_traits = ','.join(super_traits) - error_deriving = '#[derive(%s)]' % super_traits if super_traits else '' - - errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count)) + string = [ + ENUM_STRING, + ENUM_STRUCT_VARIANT_STRING, + STRUCT_STRING, + STRUCT_TUPLE_STRING, + ][type] + all_traits = ",".join([trait] + super_traits) + super_traits = ",".join(super_traits) + error_deriving = "#[derive(%s)]" % super_traits if super_traits else "" + + errors = "\n".join("//~%s ERROR" % ("^" * n) for n in range(error_count)) code = string.format(traits=all_traits, errors=errors) return TEMPLATE.format(error_deriving=error_deriving, code=code) def write_file(name, string): - test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name) + test_file = os.path.join(TEST_DIR, "derives-span-%s.rs" % name) # set write permission if file exists, so it can be changed if os.path.exists(test_file): os.chmod(test_file, stat.S_IWUSR) - with open(test_file, 'w') as f: + with open(test_file, "w") as f: f.write(string) # mark file read-only - os.chmod(test_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) + os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) ENUM = 1 @@ -85,29 +91,31 @@ STRUCT = 2 ALL = STRUCT | ENUM traits = { - 'Default': (STRUCT, [], 1), - 'FromPrimitive': (0, [], 0), # only works for C-like enums - - 'Decodable': (0, [], 0), # FIXME: quoting gives horrible spans - 'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans + "Default": (STRUCT, [], 1), + "FromPrimitive": (0, [], 0), # only works for C-like enums + "Decodable": (0, [], 0), # FIXME: quoting gives horrible spans + "Encodable": (0, [], 0), # FIXME: quoting gives horrible spans } -for (trait, supers, errs) in [('Clone', [], 1), - ('PartialEq', [], 2), - ('PartialOrd', ['PartialEq'], 1), - ('Eq', ['PartialEq'], 1), - ('Ord', ['Eq', 'PartialOrd', 'PartialEq'], 1), - ('Debug', [], 1), - ('Hash', [], 1)]: +for trait, supers, errs in [ + ("Clone", [], 1), + ("PartialEq", [], 2), + ("PartialOrd", ["PartialEq"], 1), + ("Eq", ["PartialEq"], 1), + ("Ord", ["Eq", "PartialOrd", "PartialEq"], 1), + ("Debug", [], 1), + ("Hash", [], 1), +]: traits[trait] = (ALL, supers, errs) -for (trait, (types, super_traits, error_count)) in traits.items(): +for trait, (types, super_traits, error_count) in traits.items(): + def mk(ty, t=trait, st=super_traits, ec=error_count): return create_test_case(ty, t, st, ec) if types & ENUM: - write_file(trait + '-enum', mk(ENUM_TUPLE)) - write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT)) + write_file(trait + "-enum", mk(ENUM_TUPLE)) + write_file(trait + "-enum-struct-variant", mk(ENUM_STRUCT)) if types & STRUCT: - write_file(trait + '-struct', mk(STRUCT_FIELDS)) - write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE)) + write_file(trait + "-struct", mk(STRUCT_FIELDS)) + write_file(trait + "-tuple-struct", mk(STRUCT_TUPLE)) diff --git a/src/etc/generate-keyword-tests.py b/src/etc/generate-keyword-tests.py index 77c3d2758c6..28f932acd9d 100755 --- a/src/etc/generate-keyword-tests.py +++ b/src/etc/generate-keyword-tests.py @@ -22,18 +22,16 @@ fn main() { } """ -test_dir = os.path.abspath( - os.path.join(os.path.dirname(__file__), '../test/ui/parser') -) +test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../test/ui/parser")) for kw in sys.argv[1:]: - test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw) + test_file = os.path.join(test_dir, "keyword-%s-as-identifier.rs" % kw) # set write permission if file exists, so it can be changed if os.path.exists(test_file): os.chmod(test_file, stat.S_IWUSR) - with open(test_file, 'wt') as f: + with open(test_file, "wt") as f: f.write(template % (kw, kw, kw)) # mark file read-only diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index 851b01a7458..d6b594aca71 100755 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -127,6 +127,7 @@ import os.path import re import shlex from collections import namedtuple + try: from html.parser import HTMLParser except ImportError: @@ -142,12 +143,28 @@ except ImportError: from htmlentitydefs import name2codepoint # "void elements" (no closing tag) from the HTML Standard section 12.1.2 -VOID_ELEMENTS = {'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', - 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'} +VOID_ELEMENTS = { + "area", + "base", + "br", + "col", + "embed", + "hr", + "img", + "input", + "keygen", + "link", + "menuitem", + "meta", + "param", + "source", + "track", + "wbr", +} # Python 2 -> 3 compatibility try: - unichr # noqa: B018 FIXME: py2 + unichr # noqa: B018 FIXME: py2 except NameError: unichr = chr @@ -158,18 +175,20 @@ channel = os.environ["DOC_RUST_LANG_ORG_CHANNEL"] rust_test_path = None bless = None + class CustomHTMLParser(HTMLParser): """simplified HTML parser. this is possible because we are dealing with very regular HTML from rustdoc; we only have to deal with i) void elements and ii) empty attributes.""" + def __init__(self, target=None): HTMLParser.__init__(self) self.__builder = target or ET.TreeBuilder() def handle_starttag(self, tag, attrs): - attrs = {k: v or '' for k, v in attrs} + attrs = {k: v or "" for k, v in attrs} self.__builder.start(tag, attrs) if tag in VOID_ELEMENTS: self.__builder.end(tag) @@ -178,7 +197,7 @@ class CustomHTMLParser(HTMLParser): self.__builder.end(tag) def handle_startendtag(self, tag, attrs): - attrs = {k: v or '' for k, v in attrs} + attrs = {k: v or "" for k, v in attrs} self.__builder.start(tag, attrs) self.__builder.end(tag) @@ -189,7 +208,7 @@ class CustomHTMLParser(HTMLParser): self.__builder.data(unichr(name2codepoint[name])) def handle_charref(self, name): - code = int(name[1:], 16) if name.startswith(('x', 'X')) else int(name, 10) + code = int(name[1:], 16) if name.startswith(("x", "X")) else int(name, 10) self.__builder.data(unichr(code)) def close(self): @@ -197,7 +216,7 @@ class CustomHTMLParser(HTMLParser): return self.__builder.close() -Command = namedtuple('Command', 'negated cmd args lineno context') +Command = namedtuple("Command", "negated cmd args lineno context") class FailedCheck(Exception): @@ -216,17 +235,17 @@ def concat_multi_lines(f): concatenated.""" lastline = None # set to the last line when the last line has a backslash firstlineno = None - catenated = '' + catenated = "" for lineno, line in enumerate(f): - line = line.rstrip('\r\n') + line = line.rstrip("\r\n") # strip the common prefix from the current line if needed if lastline is not None: common_prefix = os.path.commonprefix([line, lastline]) - line = line[len(common_prefix):].lstrip() + line = line[len(common_prefix) :].lstrip() firstlineno = firstlineno or lineno - if line.endswith('\\'): + if line.endswith("\\"): if lastline is None: lastline = line[:-1] catenated += line[:-1] @@ -234,10 +253,10 @@ def concat_multi_lines(f): yield firstlineno, catenated + line lastline = None firstlineno = None - catenated = '' + catenated = "" if lastline is not None: - print_err(lineno, line, 'Trailing backslash at the end of the file') + print_err(lineno, line, "Trailing backslash at the end of the file") def get_known_directive_names(): @@ -253,12 +272,12 @@ def get_known_directive_names(): "tools/compiletest/src/directive-list.rs", ), "r", - encoding="utf8" + encoding="utf8", ) as fd: content = fd.read() return [ - line.strip().replace('",', '').replace('"', '') - for line in content.split('\n') + line.strip().replace('",', "").replace('"', "") + for line in content.split("\n") if filter_line(line) ] @@ -269,35 +288,42 @@ def get_known_directive_names(): # See <https://github.com/rust-lang/rust/issues/125813#issuecomment-2141953780>. KNOWN_DIRECTIVE_NAMES = get_known_directive_names() -LINE_PATTERN = re.compile(r''' +LINE_PATTERN = re.compile( + r""" //@\s+ (?P<negated>!?)(?P<cmd>[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*) (?P<args>.*)$ -''', re.X | re.UNICODE) +""", + re.X | re.UNICODE, +) def get_commands(template): - with io.open(template, encoding='utf-8') as f: + with io.open(template, encoding="utf-8") as f: for lineno, line in concat_multi_lines(f): m = LINE_PATTERN.search(line) if not m: continue - cmd = m.group('cmd') - negated = (m.group('negated') == '!') + cmd = m.group("cmd") + negated = m.group("negated") == "!" if not negated and cmd in KNOWN_DIRECTIVE_NAMES: continue - args = m.group('args') + args = m.group("args") if args and not args[:1].isspace(): - print_err(lineno, line, 'Invalid template syntax') + print_err(lineno, line, "Invalid template syntax") continue try: args = shlex.split(args) except UnicodeEncodeError: - args = [arg.decode('utf-8') for arg in shlex.split(args.encode('utf-8'))] + args = [ + arg.decode("utf-8") for arg in shlex.split(args.encode("utf-8")) + ] except Exception as exc: raise Exception("line {}: {}".format(lineno + 1, exc)) from None - yield Command(negated=negated, cmd=cmd, args=args, lineno=lineno+1, context=line) + yield Command( + negated=negated, cmd=cmd, args=args, lineno=lineno + 1, context=line + ) def _flatten(node, acc): @@ -312,22 +338,24 @@ def _flatten(node, acc): def flatten(node): acc = [] _flatten(node, acc) - return ''.join(acc) + return "".join(acc) def make_xml(text): - xml = ET.XML('<xml>%s</xml>' % text) + xml = ET.XML("<xml>%s</xml>" % text) return xml def normalize_xpath(path): path = path.replace("{{channel}}", channel) - if path.startswith('//'): - return '.' + path # avoid warnings - elif path.startswith('.//'): + if path.startswith("//"): + return "." + path # avoid warnings + elif path.startswith(".//"): return path else: - raise InvalidCheck('Non-absolute XPath is not supported due to implementation issues') + raise InvalidCheck( + "Non-absolute XPath is not supported due to implementation issues" + ) class CachedFiles(object): @@ -338,12 +366,12 @@ class CachedFiles(object): self.last_path = None def resolve_path(self, path): - if path != '-': + if path != "-": path = os.path.normpath(path) self.last_path = path return path elif self.last_path is None: - raise InvalidCheck('Tried to use the previous path in the first command') + raise InvalidCheck("Tried to use the previous path in the first command") else: return self.last_path @@ -356,10 +384,10 @@ class CachedFiles(object): return self.files[path] abspath = self.get_absolute_path(path) - if not(os.path.exists(abspath) and os.path.isfile(abspath)): - raise FailedCheck('File does not exist {!r}'.format(path)) + if not (os.path.exists(abspath) and os.path.isfile(abspath)): + raise FailedCheck("File does not exist {!r}".format(path)) - with io.open(abspath, encoding='utf-8') as f: + with io.open(abspath, encoding="utf-8") as f: data = f.read() self.files[path] = data return data @@ -370,15 +398,15 @@ class CachedFiles(object): return self.trees[path] abspath = self.get_absolute_path(path) - if not(os.path.exists(abspath) and os.path.isfile(abspath)): - raise FailedCheck('File does not exist {!r}'.format(path)) + if not (os.path.exists(abspath) and os.path.isfile(abspath)): + raise FailedCheck("File does not exist {!r}".format(path)) - with io.open(abspath, encoding='utf-8') as f: + with io.open(abspath, encoding="utf-8") as f: try: tree = ET.fromstringlist(f.readlines(), CustomHTMLParser()) except Exception as e: - raise RuntimeError( # noqa: B904 FIXME: py2 - 'Cannot parse an HTML file {!r}: {}'.format(path, e) + raise RuntimeError( # noqa: B904 FIXME: py2 + "Cannot parse an HTML file {!r}: {}".format(path, e) ) self.trees[path] = tree return self.trees[path] @@ -386,8 +414,8 @@ class CachedFiles(object): def get_dir(self, path): path = self.resolve_path(path) abspath = self.get_absolute_path(path) - if not(os.path.exists(abspath) and os.path.isdir(abspath)): - raise FailedCheck('Directory does not exist {!r}'.format(path)) + if not (os.path.exists(abspath) and os.path.isdir(abspath)): + raise FailedCheck("Directory does not exist {!r}".format(path)) def check_string(data, pat, regexp): @@ -397,8 +425,8 @@ def check_string(data, pat, regexp): elif regexp: return re.search(pat, data, flags=re.UNICODE) is not None else: - data = ' '.join(data.split()) - pat = ' '.join(pat.split()) + data = " ".join(data.split()) + pat = " ".join(pat.split()) return pat in data @@ -444,19 +472,19 @@ def get_tree_count(tree, path): def check_snapshot(snapshot_name, actual_tree, normalize_to_text): - assert rust_test_path.endswith('.rs') - snapshot_path = '{}.{}.{}'.format(rust_test_path[:-3], snapshot_name, 'html') + assert rust_test_path.endswith(".rs") + snapshot_path = "{}.{}.{}".format(rust_test_path[:-3], snapshot_name, "html") try: - with open(snapshot_path, 'r') as snapshot_file: + with open(snapshot_path, "r") as snapshot_file: expected_str = snapshot_file.read().replace("{{channel}}", channel) except FileNotFoundError: if bless: expected_str = None else: - raise FailedCheck('No saved snapshot value') # noqa: B904 FIXME: py2 + raise FailedCheck("No saved snapshot value") # noqa: B904 FIXME: py2 if not normalize_to_text: - actual_str = ET.tostring(actual_tree).decode('utf-8') + actual_str = ET.tostring(actual_tree).decode("utf-8") else: actual_str = flatten(actual_tree) @@ -464,64 +492,66 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text): # 1. Is --bless # 2. Are actual and expected tree different # 3. Are actual and expected text different - if not expected_str \ - or (not normalize_to_text and \ - not compare_tree(make_xml(actual_str), make_xml(expected_str), stderr)) \ - or (normalize_to_text and actual_str != expected_str): - + if ( + not expected_str + or ( + not normalize_to_text + and not compare_tree(make_xml(actual_str), make_xml(expected_str), stderr) + ) + or (normalize_to_text and actual_str != expected_str) + ): if bless: - with open(snapshot_path, 'w') as snapshot_file: + with open(snapshot_path, "w") as snapshot_file: actual_str = actual_str.replace(channel, "{{channel}}") snapshot_file.write(actual_str) else: - print('--- expected ---\n') + print("--- expected ---\n") print(expected_str) - print('\n\n--- actual ---\n') + print("\n\n--- actual ---\n") print(actual_str) print() - raise FailedCheck('Actual snapshot value is different than expected') + raise FailedCheck("Actual snapshot value is different than expected") # Adapted from https://github.com/formencode/formencode/blob/3a1ba9de2fdd494dd945510a4568a3afeddb0b2e/formencode/doctest_xml_compare.py#L72-L120 def compare_tree(x1, x2, reporter=None): if x1.tag != x2.tag: if reporter: - reporter('Tags do not match: %s and %s' % (x1.tag, x2.tag)) + reporter("Tags do not match: %s and %s" % (x1.tag, x2.tag)) return False for name, value in x1.attrib.items(): if x2.attrib.get(name) != value: if reporter: - reporter('Attributes do not match: %s=%r, %s=%r' - % (name, value, name, x2.attrib.get(name))) + reporter( + "Attributes do not match: %s=%r, %s=%r" + % (name, value, name, x2.attrib.get(name)) + ) return False for name in x2.attrib: if name not in x1.attrib: if reporter: - reporter('x2 has an attribute x1 is missing: %s' - % name) + reporter("x2 has an attribute x1 is missing: %s" % name) return False if not text_compare(x1.text, x2.text): if reporter: - reporter('text: %r != %r' % (x1.text, x2.text)) + reporter("text: %r != %r" % (x1.text, x2.text)) return False if not text_compare(x1.tail, x2.tail): if reporter: - reporter('tail: %r != %r' % (x1.tail, x2.tail)) + reporter("tail: %r != %r" % (x1.tail, x2.tail)) return False cl1 = list(x1) cl2 = list(x2) if len(cl1) != len(cl2): if reporter: - reporter('children length differs, %i != %i' - % (len(cl1), len(cl2))) + reporter("children length differs, %i != %i" % (len(cl1), len(cl2))) return False i = 0 for c1, c2 in zip(cl1, cl2): i += 1 if not compare_tree(c1, c2, reporter=reporter): if reporter: - reporter('children %i do not match: %s' - % (i, c1.tag)) + reporter("children %i do not match: %s" % (i, c1.tag)) return False return True @@ -529,14 +559,14 @@ def compare_tree(x1, x2, reporter=None): def text_compare(t1, t2): if not t1 and not t2: return True - if t1 == '*' or t2 == '*': + if t1 == "*" or t2 == "*": return True - return (t1 or '').strip() == (t2 or '').strip() + return (t1 or "").strip() == (t2 or "").strip() def stderr(*args): if sys.version_info.major < 3: - file = codecs.getwriter('utf-8')(sys.stderr) + file = codecs.getwriter("utf-8")(sys.stderr) else: file = sys.stderr @@ -556,21 +586,25 @@ def print_err(lineno, context, err, message=None): def get_nb_matching_elements(cache, c, regexp, stop_at_first): tree = cache.get_tree(c.args[0]) - pat, sep, attr = c.args[1].partition('/@') + pat, sep, attr = c.args[1].partition("/@") if sep: # attribute tree = cache.get_tree(c.args[0]) return check_tree_attr(tree, pat, attr, c.args[2], False) else: # normalized text pat = c.args[1] - if pat.endswith('/text()'): + if pat.endswith("/text()"): pat = pat[:-7] - return check_tree_text(cache.get_tree(c.args[0]), pat, c.args[2], regexp, stop_at_first) + return check_tree_text( + cache.get_tree(c.args[0]), pat, c.args[2], regexp, stop_at_first + ) def check_files_in_folder(c, cache, folder, files): files = files.strip() - if not files.startswith('[') or not files.endswith(']'): - raise InvalidCheck("Expected list as second argument of {} (ie '[]')".format(c.cmd)) + if not files.startswith("[") or not files.endswith("]"): + raise InvalidCheck( + "Expected list as second argument of {} (ie '[]')".format(c.cmd) + ) folder = cache.get_absolute_path(folder) @@ -592,12 +626,18 @@ def check_files_in_folder(c, cache, folder, files): error = 0 if len(files_set) != 0: - print_err(c.lineno, c.context, "Entries not found in folder `{}`: `{}`".format( - folder, files_set)) + print_err( + c.lineno, + c.context, + "Entries not found in folder `{}`: `{}`".format(folder, files_set), + ) error += 1 if len(folder_set) != 0: - print_err(c.lineno, c.context, "Extra entries in folder `{}`: `{}`".format( - folder, folder_set)) + print_err( + c.lineno, + c.context, + "Extra entries in folder `{}`: `{}`".format(folder, folder_set), + ) error += 1 return error == 0 @@ -608,11 +648,11 @@ ERR_COUNT = 0 def check_command(c, cache): try: cerr = "" - if c.cmd in ['has', 'hasraw', 'matches', 'matchesraw']: # string test - regexp = c.cmd.startswith('matches') + if c.cmd in ["has", "hasraw", "matches", "matchesraw"]: # string test + regexp = c.cmd.startswith("matches") # has <path> = file existence - if len(c.args) == 1 and not regexp and 'raw' not in c.cmd: + if len(c.args) == 1 and not regexp and "raw" not in c.cmd: try: cache.get_file(c.args[0]) ret = True @@ -620,24 +660,24 @@ def check_command(c, cache): cerr = str(err) ret = False # hasraw/matchesraw <path> <pat> = string test - elif len(c.args) == 2 and 'raw' in c.cmd: + elif len(c.args) == 2 and "raw" in c.cmd: cerr = "`PATTERN` did not match" ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp) # has/matches <path> <pat> <match> = XML tree test - elif len(c.args) == 3 and 'raw' not in c.cmd: + elif len(c.args) == 3 and "raw" not in c.cmd: cerr = "`XPATH PATTERN` did not match" ret = get_nb_matching_elements(cache, c, regexp, True) != 0 else: - raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd)) + raise InvalidCheck("Invalid number of {} arguments".format(c.cmd)) - elif c.cmd == 'files': # check files in given folder - if len(c.args) != 2: # files <folder path> <file list> + elif c.cmd == "files": # check files in given folder + if len(c.args) != 2: # files <folder path> <file list> raise InvalidCheck("Invalid number of {} arguments".format(c.cmd)) elif c.negated: raise InvalidCheck("{} doesn't support negative check".format(c.cmd)) ret = check_files_in_folder(c, cache, c.args[0], c.args[1]) - elif c.cmd == 'count': # count test + elif c.cmd == "count": # count test if len(c.args) == 3: # count <path> <pat> <count> = count test expected = int(c.args[2]) found = get_tree_count(cache.get_tree(c.args[0]), c.args[1]) @@ -649,15 +689,15 @@ def check_command(c, cache): cerr = "Expected {} occurrences but found {}".format(expected, found) ret = found == expected else: - raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd)) + raise InvalidCheck("Invalid number of {} arguments".format(c.cmd)) - elif c.cmd == 'snapshot': # snapshot test + elif c.cmd == "snapshot": # snapshot test if len(c.args) == 3: # snapshot <snapshot-name> <html-path> <xpath> [snapshot_name, html_path, pattern] = c.args tree = cache.get_tree(html_path) xpath = normalize_xpath(pattern) normalize_to_text = False - if xpath.endswith('/text()'): + if xpath.endswith("/text()"): xpath = xpath[:-7] normalize_to_text = True @@ -671,13 +711,15 @@ def check_command(c, cache): cerr = str(err) ret = False elif len(subtrees) == 0: - raise FailedCheck('XPATH did not match') + raise FailedCheck("XPATH did not match") else: - raise FailedCheck('Expected 1 match, but found {}'.format(len(subtrees))) + raise FailedCheck( + "Expected 1 match, but found {}".format(len(subtrees)) + ) else: - raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd)) + raise InvalidCheck("Invalid number of {} arguments".format(c.cmd)) - elif c.cmd == 'has-dir': # has-dir test + elif c.cmd == "has-dir": # has-dir test if len(c.args) == 1: # has-dir <path> = has-dir test try: cache.get_dir(c.args[0]) @@ -686,22 +728,22 @@ def check_command(c, cache): cerr = str(err) ret = False else: - raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd)) + raise InvalidCheck("Invalid number of {} arguments".format(c.cmd)) - elif c.cmd == 'valid-html': - raise InvalidCheck('Unimplemented valid-html') + elif c.cmd == "valid-html": + raise InvalidCheck("Unimplemented valid-html") - elif c.cmd == 'valid-links': - raise InvalidCheck('Unimplemented valid-links') + elif c.cmd == "valid-links": + raise InvalidCheck("Unimplemented valid-links") else: - raise InvalidCheck('Unrecognized {}'.format(c.cmd)) + raise InvalidCheck("Unrecognized {}".format(c.cmd)) if ret == c.negated: raise FailedCheck(cerr) except FailedCheck as err: - message = '{}{} check failed'.format('!' if c.negated else '', c.cmd) + message = "{}{} check failed".format("!" if c.negated else "", c.cmd) print_err(c.lineno, c.context, str(err), message) except InvalidCheck as err: print_err(c.lineno, c.context, str(err)) @@ -713,18 +755,18 @@ def check(target, commands): check_command(c, cache) -if __name__ == '__main__': +if __name__ == "__main__": if len(sys.argv) not in [3, 4]: - stderr('Usage: {} <doc dir> <template> [--bless]'.format(sys.argv[0])) + stderr("Usage: {} <doc dir> <template> [--bless]".format(sys.argv[0])) raise SystemExit(1) rust_test_path = sys.argv[2] - if len(sys.argv) > 3 and sys.argv[3] == '--bless': + if len(sys.argv) > 3 and sys.argv[3] == "--bless": bless = True else: # We only support `--bless` at the end of the arguments. # This assert is to prevent silent failures. - assert '--bless' not in sys.argv + assert "--bless" not in sys.argv bless = False check(sys.argv[1], get_commands(rust_test_path)) if ERR_COUNT: diff --git a/src/etc/lldb_batchmode.py b/src/etc/lldb_batchmode.py index db1e0035ea0..cf88c53e085 100644 --- a/src/etc/lldb_batchmode.py +++ b/src/etc/lldb_batchmode.py @@ -45,7 +45,7 @@ def normalize_whitespace(s): def breakpoint_callback(frame, bp_loc, dict): """This callback is registered with every breakpoint and makes sure that the - frame containing the breakpoint location is selected """ + frame containing the breakpoint location is selected""" # HACK(eddyb) print a newline to avoid continuing an unfinished line. print("") @@ -79,7 +79,7 @@ def execute_command(command_interpreter, command): if res.Succeeded(): if res.HasResult(): - print(normalize_whitespace(res.GetOutput() or ''), end='\n') + print(normalize_whitespace(res.GetOutput() or ""), end="\n") # If the command introduced any breakpoints, make sure to register # them with the breakpoint @@ -89,20 +89,32 @@ def execute_command(command_interpreter, command): breakpoint_id = new_breakpoints.pop() if breakpoint_id in registered_breakpoints: - print_debug("breakpoint with id %s is already registered. Ignoring." % - str(breakpoint_id)) + print_debug( + "breakpoint with id %s is already registered. Ignoring." + % str(breakpoint_id) + ) else: - print_debug("registering breakpoint callback, id = " + str(breakpoint_id)) - callback_command = ("breakpoint command add -F breakpoint_callback " + - str(breakpoint_id)) + print_debug( + "registering breakpoint callback, id = " + str(breakpoint_id) + ) + callback_command = ( + "breakpoint command add -F breakpoint_callback " + + str(breakpoint_id) + ) command_interpreter.HandleCommand(callback_command, res) if res.Succeeded(): - print_debug("successfully registered breakpoint callback, id = " + - str(breakpoint_id)) + print_debug( + "successfully registered breakpoint callback, id = " + + str(breakpoint_id) + ) registered_breakpoints.add(breakpoint_id) else: - print("Error while trying to register breakpoint callback, id = " + - str(breakpoint_id) + ", message = " + str(res.GetError())) + print( + "Error while trying to register breakpoint callback, id = " + + str(breakpoint_id) + + ", message = " + + str(res.GetError()) + ) else: print(res.GetError()) @@ -117,14 +129,16 @@ def start_breakpoint_listener(target): try: while True: if listener.WaitForEvent(120, event): - if lldb.SBBreakpoint.EventIsBreakpointEvent(event) and \ - lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event) == \ - lldb.eBreakpointEventTypeAdded: + if ( + lldb.SBBreakpoint.EventIsBreakpointEvent(event) + and lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event) + == lldb.eBreakpointEventTypeAdded + ): global new_breakpoints breakpoint = lldb.SBBreakpoint.GetBreakpointFromEvent(event) print_debug("breakpoint added, id = " + str(breakpoint.id)) new_breakpoints.append(breakpoint.id) - except BaseException: # explicitly catch ctrl+c/sysexit + except BaseException: # explicitly catch ctrl+c/sysexit print_debug("breakpoint listener shutting down") # Start the listener and let it run as a daemon @@ -133,7 +147,9 @@ def start_breakpoint_listener(target): listener_thread.start() # Register the listener with the target - target.GetBroadcaster().AddListener(listener, lldb.SBTarget.eBroadcastBitBreakpointChanged) + target.GetBroadcaster().AddListener( + listener, lldb.SBTarget.eBroadcastBitBreakpointChanged + ) def start_watchdog(): @@ -159,6 +175,7 @@ def start_watchdog(): watchdog_thread.daemon = True watchdog_thread.start() + #################################################################################################### # ~main #################################################################################################### @@ -193,8 +210,14 @@ target_error = lldb.SBError() target = debugger.CreateTarget(target_path, None, None, True, target_error) if not target: - print("Could not create debugging target '" + target_path + "': " + - str(target_error) + ". Aborting.", file=sys.stderr) + print( + "Could not create debugging target '" + + target_path + + "': " + + str(target_error) + + ". Aborting.", + file=sys.stderr, + ) sys.exit(1) @@ -204,15 +227,19 @@ start_breakpoint_listener(target) command_interpreter = debugger.GetCommandInterpreter() try: - script_file = open(script_path, 'r') + script_file = open(script_path, "r") for line in script_file: command = line.strip() - if command == "run" or command == "r" or re.match("^process\s+launch.*", command): + if ( + command == "run" + or command == "r" + or re.match("^process\s+launch.*", command) + ): # Before starting to run the program, let the thread sleep a bit, so all # breakpoint added events can be processed time.sleep(0.5) - if command != '': + if command != "": execute_command(command_interpreter, command) except IOError as e: diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py index a42ce111ebc..c24ec8ab310 100644 --- a/src/etc/lldb_providers.py +++ b/src/etc/lldb_providers.py @@ -1,7 +1,12 @@ import sys -from lldb import SBData, SBError, eBasicTypeLong, eBasicTypeUnsignedLong, \ - eBasicTypeUnsignedChar +from lldb import ( + SBData, + SBError, + eBasicTypeLong, + eBasicTypeUnsignedLong, + eBasicTypeUnsignedChar, +) # from lldb.formatters import Logger @@ -50,13 +55,17 @@ class ValueBuilder: def from_int(self, name, value): # type: (str, int) -> SBValue type = self.valobj.GetType().GetBasicType(eBasicTypeLong) - data = SBData.CreateDataFromSInt64Array(self.endianness, self.pointer_size, [value]) + data = SBData.CreateDataFromSInt64Array( + self.endianness, self.pointer_size, [value] + ) return self.valobj.CreateValueFromData(name, data, type) def from_uint(self, name, value): # type: (str, int) -> SBValue type = self.valobj.GetType().GetBasicType(eBasicTypeUnsignedLong) - data = SBData.CreateDataFromUInt64Array(self.endianness, self.pointer_size, [value]) + data = SBData.CreateDataFromUInt64Array( + self.endianness, self.pointer_size, [value] + ) return self.valobj.CreateValueFromData(name, data, type) @@ -127,13 +136,17 @@ class EmptySyntheticProvider: def SizeSummaryProvider(valobj, dict): # type: (SBValue, dict) -> str - return 'size=' + str(valobj.GetNumChildren()) + return "size=" + str(valobj.GetNumChildren()) def vec_to_string(vec): length = vec.GetNumChildren() chars = [vec.GetChildAtIndex(i).GetValueAsUnsigned() for i in range(length)] - return bytes(chars).decode(errors='replace') if PY3 else "".join(chr(char) for char in chars) + return ( + bytes(chars).decode(errors="replace") + if PY3 + else "".join(chr(char) for char in chars) + ) def StdStringSummaryProvider(valobj, dict): @@ -172,7 +185,7 @@ def StdStrSummaryProvider(valobj, dict): error = SBError() process = data_ptr.GetProcess() data = process.ReadMemory(start, length, error) - data = data.decode(encoding='UTF-8') if PY3 else data + data = data.decode(encoding="UTF-8") if PY3 else data return '"%s"' % data @@ -199,9 +212,9 @@ def StdPathSummaryProvider(valobj, dict): data = process.ReadMemory(start, length, error) if PY3: try: - data = data.decode(encoding='UTF-8') + data = data.decode(encoding="UTF-8") except UnicodeDecodeError: - return '%r' % data + return "%r" % data return '"%s"' % data @@ -250,8 +263,10 @@ class StructSyntheticProvider: # type: () -> bool return True + class ClangEncodedEnumProvider: """Pretty-printer for 'clang-encoded' enums support implemented in LLDB""" + DISCRIMINANT_MEMBER_NAME = "$discr$" VALUE_MEMBER_NAME = "value" @@ -260,7 +275,7 @@ class ClangEncodedEnumProvider: self.update() def has_children(self): - return True + return True def num_children(self): if self.is_default: @@ -276,25 +291,32 @@ class ClangEncodedEnumProvider: def get_child_at_index(self, index): if index == 0: - return self.variant.GetChildMemberWithName(ClangEncodedEnumProvider.VALUE_MEMBER_NAME) + return self.variant.GetChildMemberWithName( + ClangEncodedEnumProvider.VALUE_MEMBER_NAME + ) if index == 1: return self.variant.GetChildMemberWithName( - ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME) - + ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME + ) def update(self): all_variants = self.valobj.GetChildAtIndex(0) index = self._getCurrentVariantIndex(all_variants) self.variant = all_variants.GetChildAtIndex(index) - self.is_default = self.variant.GetIndexOfChildWithName( - ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME) == -1 + self.is_default = ( + self.variant.GetIndexOfChildWithName( + ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME + ) + == -1 + ) def _getCurrentVariantIndex(self, all_variants): default_index = 0 for i in range(all_variants.GetNumChildren()): variant = all_variants.GetChildAtIndex(i) discr = variant.GetChildMemberWithName( - ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME) + ClangEncodedEnumProvider.DISCRIMINANT_MEMBER_NAME + ) if discr.IsValid(): discr_unsigned_value = discr.GetValueAsUnsigned() if variant.GetName() == f"$variant${discr_unsigned_value}": @@ -303,6 +325,7 @@ class ClangEncodedEnumProvider: default_index = i return default_index + class TupleSyntheticProvider: """Pretty-printer for tuples and tuple enum variants""" @@ -336,7 +359,9 @@ class TupleSyntheticProvider: else: field = self.type.GetFieldAtIndex(index) element = self.valobj.GetChildMemberWithName(field.name) - return self.valobj.CreateValueFromData(str(index), element.GetData(), element.GetType()) + return self.valobj.CreateValueFromData( + str(index), element.GetData(), element.GetType() + ) def update(self): # type: () -> None @@ -373,7 +398,7 @@ class StdVecSyntheticProvider: def get_child_index(self, name): # type: (str) -> int - index = name.lstrip('[').rstrip(']') + index = name.lstrip("[").rstrip("]") if index.isdigit(): return int(index) else: @@ -383,15 +408,21 @@ class StdVecSyntheticProvider: # type: (int) -> SBValue start = self.data_ptr.GetValueAsUnsigned() address = start + index * self.element_type_size - element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.element_type) + element = self.data_ptr.CreateValueFromAddress( + "[%s]" % index, address, self.element_type + ) return element def update(self): # type: () -> None self.length = self.valobj.GetChildMemberWithName("len").GetValueAsUnsigned() - self.buf = self.valobj.GetChildMemberWithName("buf").GetChildMemberWithName("inner") + self.buf = self.valobj.GetChildMemberWithName("buf").GetChildMemberWithName( + "inner" + ) - self.data_ptr = unwrap_unique_or_non_null(self.buf.GetChildMemberWithName("ptr")) + self.data_ptr = unwrap_unique_or_non_null( + self.buf.GetChildMemberWithName("ptr") + ) self.element_type = self.valobj.GetType().GetTemplateArgumentType(0) self.element_type_size = self.element_type.GetByteSize() @@ -412,7 +443,7 @@ class StdSliceSyntheticProvider: def get_child_index(self, name): # type: (str) -> int - index = name.lstrip('[').rstrip(']') + index = name.lstrip("[").rstrip("]") if index.isdigit(): return int(index) else: @@ -422,7 +453,9 @@ class StdSliceSyntheticProvider: # type: (int) -> SBValue start = self.data_ptr.GetValueAsUnsigned() address = start + index * self.element_type_size - element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.element_type) + element = self.data_ptr.CreateValueFromAddress( + "[%s]" % index, address, self.element_type + ) return element def update(self): @@ -457,7 +490,7 @@ class StdVecDequeSyntheticProvider: def get_child_index(self, name): # type: (str) -> int - index = name.lstrip('[').rstrip(']') + index = name.lstrip("[").rstrip("]") if index.isdigit() and int(index) < self.size: return int(index) else: @@ -467,20 +500,26 @@ class StdVecDequeSyntheticProvider: # type: (int) -> SBValue start = self.data_ptr.GetValueAsUnsigned() address = start + ((index + self.head) % self.cap) * self.element_type_size - element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.element_type) + element = self.data_ptr.CreateValueFromAddress( + "[%s]" % index, address, self.element_type + ) return element def update(self): # type: () -> None self.head = self.valobj.GetChildMemberWithName("head").GetValueAsUnsigned() self.size = self.valobj.GetChildMemberWithName("len").GetValueAsUnsigned() - self.buf = self.valobj.GetChildMemberWithName("buf").GetChildMemberWithName("inner") + self.buf = self.valobj.GetChildMemberWithName("buf").GetChildMemberWithName( + "inner" + ) cap = self.buf.GetChildMemberWithName("cap") if cap.GetType().num_fields == 1: cap = cap.GetChildAtIndex(0) self.cap = cap.GetValueAsUnsigned() - self.data_ptr = unwrap_unique_or_non_null(self.buf.GetChildMemberWithName("ptr")) + self.data_ptr = unwrap_unique_or_non_null( + self.buf.GetChildMemberWithName("ptr") + ) self.element_type = self.valobj.GetType().GetTemplateArgumentType(0) self.element_type_size = self.element_type.GetByteSize() @@ -510,7 +549,7 @@ class StdOldHashMapSyntheticProvider: def get_child_index(self, name): # type: (str) -> int - index = name.lstrip('[').rstrip(']') + index = name.lstrip("[").rstrip("]") if index.isdigit(): return int(index) else: @@ -525,8 +564,14 @@ class StdOldHashMapSyntheticProvider: hashes = self.hash_uint_size * self.capacity align = self.pair_type_size # See `libcore/alloc.rs:padding_needed_for` - len_rounded_up = (((((hashes + align) % self.modulo - 1) % self.modulo) & ~( - (align - 1) % self.modulo)) % self.modulo - hashes) % self.modulo + len_rounded_up = ( + ( + (((hashes + align) % self.modulo - 1) % self.modulo) + & ~((align - 1) % self.modulo) + ) + % self.modulo + - hashes + ) % self.modulo # len_rounded_up = ((hashes + align - 1) & ~(align - 1)) - hashes pairs_offset = hashes + len_rounded_up @@ -535,12 +580,16 @@ class StdOldHashMapSyntheticProvider: table_index = self.valid_indices[index] idx = table_index & self.capacity_mask address = pairs_start + idx * self.pair_type_size - element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.pair_type) + element = self.data_ptr.CreateValueFromAddress( + "[%s]" % index, address, self.pair_type + ) if self.show_values: return element else: key = element.GetChildAtIndex(0) - return self.valobj.CreateValueFromData("[%s]" % index, key.GetData(), key.GetType()) + return self.valobj.CreateValueFromData( + "[%s]" % index, key.GetData(), key.GetType() + ) def update(self): # type: () -> None @@ -551,10 +600,12 @@ class StdOldHashMapSyntheticProvider: self.hashes = self.table.GetChildMemberWithName("hashes") self.hash_uint_type = self.hashes.GetType() self.hash_uint_size = self.hashes.GetType().GetByteSize() - self.modulo = 2 ** self.hash_uint_size + self.modulo = 2**self.hash_uint_size self.data_ptr = self.hashes.GetChildAtIndex(0).GetChildAtIndex(0) - self.capacity_mask = self.table.GetChildMemberWithName("capacity_mask").GetValueAsUnsigned() + self.capacity_mask = self.table.GetChildMemberWithName( + "capacity_mask" + ).GetValueAsUnsigned() self.capacity = (self.capacity_mask + 1) % self.modulo marker = self.table.GetChildMemberWithName("marker").GetType() # type: SBType @@ -564,8 +615,9 @@ class StdOldHashMapSyntheticProvider: self.valid_indices = [] for idx in range(self.capacity): address = self.data_ptr.GetValueAsUnsigned() + idx * self.hash_uint_size - hash_uint = self.data_ptr.CreateValueFromAddress("[%s]" % idx, address, - self.hash_uint_type) + hash_uint = self.data_ptr.CreateValueFromAddress( + "[%s]" % idx, address, self.hash_uint_type + ) hash_ptr = hash_uint.GetChildAtIndex(0).GetChildAtIndex(0) if hash_ptr.GetValueAsUnsigned() != 0: self.valid_indices.append(idx) @@ -592,7 +644,7 @@ class StdHashMapSyntheticProvider: def get_child_index(self, name): # type: (str) -> int - index = name.lstrip('[').rstrip(']') + index = name.lstrip("[").rstrip("]") if index.isdigit(): return int(index) else: @@ -605,19 +657,25 @@ class StdHashMapSyntheticProvider: if self.new_layout: idx = -(idx + 1) address = pairs_start + idx * self.pair_type_size - element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.pair_type) + element = self.data_ptr.CreateValueFromAddress( + "[%s]" % index, address, self.pair_type + ) if self.show_values: return element else: key = element.GetChildAtIndex(0) - return self.valobj.CreateValueFromData("[%s]" % index, key.GetData(), key.GetType()) + return self.valobj.CreateValueFromData( + "[%s]" % index, key.GetData(), key.GetType() + ) def update(self): # type: () -> None table = self.table() inner_table = table.GetChildMemberWithName("table") - capacity = inner_table.GetChildMemberWithName("bucket_mask").GetValueAsUnsigned() + 1 + capacity = ( + inner_table.GetChildMemberWithName("bucket_mask").GetValueAsUnsigned() + 1 + ) ctrl = inner_table.GetChildMemberWithName("ctrl").GetChildAtIndex(0) self.size = inner_table.GetChildMemberWithName("items").GetValueAsUnsigned() @@ -630,16 +688,21 @@ class StdHashMapSyntheticProvider: if self.new_layout: self.data_ptr = ctrl.Cast(self.pair_type.GetPointerType()) else: - self.data_ptr = inner_table.GetChildMemberWithName("data").GetChildAtIndex(0) + self.data_ptr = inner_table.GetChildMemberWithName("data").GetChildAtIndex( + 0 + ) u8_type = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar) - u8_type_size = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar).GetByteSize() + u8_type_size = ( + self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar).GetByteSize() + ) self.valid_indices = [] for idx in range(capacity): address = ctrl.GetValueAsUnsigned() + idx * u8_type_size - value = ctrl.CreateValueFromAddress("ctrl[%s]" % idx, address, - u8_type).GetValueAsUnsigned() + value = ctrl.CreateValueFromAddress( + "ctrl[%s]" % idx, address, u8_type + ).GetValueAsUnsigned() is_present = value & 128 == 0 if is_present: self.valid_indices.append(idx) @@ -691,10 +754,16 @@ class StdRcSyntheticProvider: self.value = self.ptr.GetChildMemberWithName("data" if is_atomic else "value") - self.strong = self.ptr.GetChildMemberWithName("strong").GetChildAtIndex( - 0).GetChildMemberWithName("value") - self.weak = self.ptr.GetChildMemberWithName("weak").GetChildAtIndex( - 0).GetChildMemberWithName("value") + self.strong = ( + self.ptr.GetChildMemberWithName("strong") + .GetChildAtIndex(0) + .GetChildMemberWithName("value") + ) + self.weak = ( + self.ptr.GetChildMemberWithName("weak") + .GetChildAtIndex(0) + .GetChildMemberWithName("value") + ) self.value_builder = ValueBuilder(valobj) @@ -772,7 +841,9 @@ class StdCellSyntheticProvider: def StdRefSummaryProvider(valobj, dict): # type: (SBValue, dict) -> str borrow = valobj.GetChildMemberWithName("borrow").GetValueAsSigned() - return "borrow={}".format(borrow) if borrow >= 0 else "borrow_mut={}".format(-borrow) + return ( + "borrow={}".format(borrow) if borrow >= 0 else "borrow_mut={}".format(-borrow) + ) class StdRefSyntheticProvider: @@ -785,11 +856,16 @@ class StdRefSyntheticProvider: borrow = valobj.GetChildMemberWithName("borrow") value = valobj.GetChildMemberWithName("value") if is_cell: - self.borrow = borrow.GetChildMemberWithName("value").GetChildMemberWithName("value") + self.borrow = borrow.GetChildMemberWithName("value").GetChildMemberWithName( + "value" + ) self.value = value.GetChildMemberWithName("value") else: - self.borrow = borrow.GetChildMemberWithName("borrow").GetChildMemberWithName( - "value").GetChildMemberWithName("value") + self.borrow = ( + borrow.GetChildMemberWithName("borrow") + .GetChildMemberWithName("value") + .GetChildMemberWithName("value") + ) self.value = value.Dereference() self.value_builder = ValueBuilder(valobj) @@ -832,7 +908,7 @@ def StdNonZeroNumberSummaryProvider(valobj, _dict): # FIXME: Avoid printing as character literal, # see https://github.com/llvm/llvm-project/issues/65076. - if inner_inner.GetTypeName() in ['char', 'unsigned char']: - return str(inner_inner.GetValueAsSigned()) + if inner_inner.GetTypeName() in ["char", "unsigned char"]: + return str(inner_inner.GetValueAsSigned()) else: - return inner_inner.GetValue() + return inner_inner.GetValue() diff --git a/src/etc/rust_types.py b/src/etc/rust_types.py index 190fbc13a17..42ec9bed9bd 100644 --- a/src/etc/rust_types.py +++ b/src/etc/rust_types.py @@ -54,7 +54,7 @@ STD_REF_MUT_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefMut<.+>$") STD_REF_CELL_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefCell<.+>$") STD_NONZERO_NUMBER_REGEX = re.compile(r"^(core::([a-z_]+::)+)NonZero<.+>$") STD_PATHBUF_REGEX = re.compile(r"^(std::([a-z_]+::)+)PathBuf$") -STD_PATH_REGEX = re.compile(r"^&(mut )?(std::([a-z_]+::)+)Path$") +STD_PATH_REGEX = re.compile(r"^&(mut )?(std::([a-z_]+::)+)Path$") TUPLE_ITEM_REGEX = re.compile(r"__\d+$") @@ -84,6 +84,7 @@ STD_TYPE_TO_REGEX = { RustType.STD_PATH: STD_PATH_REGEX, } + def is_tuple_fields(fields): # type: (list) -> bool return all(TUPLE_ITEM_REGEX.match(str(field.name)) for field in fields) |
