On Wed, 2017-07-26 at 18:00 +0200, Pierre-Marie de Rodat wrote: [...] > diff --git a/gcc/testsuite/python/dwarfutils/__init__.py > b/gcc/testsuite/python/dwarfutils/__init__.py > new file mode 100644 > index 00000000000..246fbbd15be > --- /dev/null > +++ b/gcc/testsuite/python/dwarfutils/__init__.py [...] > +def parse_dwarf(object_file=None, single_cu=True): > + """ > + Fetch and decode DWARF compilation units in `object_file`. > + > + If `single_cu` is True, make sure there is exactly one > compilation unit and
"is True" -> "is true" [...] > --- /dev/null > +++ b/gcc/testsuite/python/dwarfutils/data.py > + > + def get_attr(self, name, single=True, or_error=True): > + """Look for an attribute in this DIE. > + > + :param str|int name: Attribute name, or number if name is > unknown. > + :param bool single: If true, this will raise a KeyError for > + zero/multiple matches and return an Attribute instance > when found. > + Otherwise, return a potentially empty list of > attributes. > + :param bool or_error: When True, if `single` is True and no > attribute "True" -> "true" in two places [...] > + def find(self, predicate=None, tag=None, name=None, > recursive=True, > + single=True): > + """Look for a DIE that satisfies the given expectations. > + > + :param None|(DIE) -> bool predicate: If provided, function > that filters > + out DIEs when it returns False. > + :param str|int|None tag: If provided, filter out DIEs whose > tag does > + not match. > + :param str|None name: If provided, filter out DIEs whose > name (see > + the `name` property) does not match. > + :param bool recursive: If True, perform the search > recursively in > + self's children. > + :param bool single: If True, look for a single DIE and raise > a "True" -> "true", I suppose [...] > +class MatchResult(object): > + """Holder for the result of a DIE tree pattern match.""" > + > + def __init__(self): > + self.dict = {} > + > + self.mismatch_reason = None > + """ > + If left to None, the match succeded. Otherwise, must be set "succeded" -> "succeeded" > + > + def capture(self, name): > + """Return what has been captured by the `name` capture. > + > + This is valid iff the match succeded. here again. [...] > diff --git a/gcc/testsuite/python/dwarfutils/helpers.py > b/gcc/testsuite/python/dwarfutils/helpers.py > new file mode 100644 > index 00000000000..f5e77896ae6 > --- /dev/null > +++ b/gcc/testsuite/python/dwarfutils/helpers.py > @@ -0,0 +1,11 @@ > +import sys > + > + > +def as_ascii(str_or_byte): > + """ > + Python 2/3 compatibility helper. > + > + In Python 2, just return the input. In Python 3, decode the > input as ASCII. > + """ > + return (str_or_byte if sys.version_info.major < 3 else > + str_or_byte.decode('ascii')) Aha! Python 2 and Python 3. Presumably this all runs with LANG=C so that there's no danger of any non-ASCII bytes? (bytes.decode('ascii' will raise a UnicodeDecodeError if any byte >=128). > diff --git a/gcc/testsuite/python/dwarfutils/objdump.py > b/gcc/testsuite/python/dwarfutils/objdump.py > new file mode 100644 > index 00000000000..52cfc06c03b > --- /dev/null > +++ b/gcc/testsuite/python/dwarfutils/objdump.py [...] There's a fair amount of non-trivial parsing going on here. I wonder if it would be helpful to add a "unittest" suite for the parsing? (e.g. to have some precanned fragments of objdump output as strings, and to verify that they're parsed as expected). Note that I'm not a reviewer for the testsuite, so this is just a suggestion. Hope this is constructive Dave