#!/usr/bin/env python
# This script uses a regex to validate the output of our backtraces.
# The layout we assume is:
#
# +
#
# It currently just checks that the backtrace results in at least one correctly
# formatted entry. It does not directly validate the input since the output
# would not be robust against standard library changes.
#
# TODO: We could have the user pass in the frame number, library name, and
# demangled name. These we can always validate as true in a robust way. On the
# other hand, address and offset are more difficult to validate in a robust way
# in the face of small codegen differences, so without any further thought I
# imagine we can just check the format.
#
# 11 libswiftCore.dylib 0x000000000dce84d0l _fatalErrorMessage(StaticString,
# StaticString, StaticString, UInt, flags : UInt32) -> () + 444
from __future__ import print_function
import argparse
import re
import sys
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Checks that a stacktrace dump follows canonical
formatting.""")
parser.add_argument(
"-u", "--check-unavailable", action='store_true',
help="Checks if any symbols were unavailable")
args = parser.parse_args()
TARGET_RE = re.compile(
"(?P\d+) +(?P