2020-01-21 02:27:15 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""lldb-repro
|
|
|
|
|
|
|
|
lldb-repro is a utility to transparently capture and replay debugger sessions
|
|
|
|
through the command line driver. Its used to test the reproducers by running
|
|
|
|
the test suite twice.
|
|
|
|
|
|
|
|
During the first run, with 'capture' as its first argument, it captures a
|
|
|
|
reproducer for every lldb invocation and saves it to a well-know location
|
|
|
|
derived from the arguments and current working directory.
|
|
|
|
|
|
|
|
During the second run, with 'replay' as its first argument, the test suite is
|
|
|
|
run again but this time every invocation of lldb replays the previously
|
|
|
|
recorded session.
|
|
|
|
"""
|
|
|
|
|
2020-01-31 07:51:29 +08:00
|
|
|
import hashlib
|
2020-01-21 02:27:15 +08:00
|
|
|
import os
|
2020-01-31 07:51:29 +08:00
|
|
|
import shutil
|
2020-01-21 02:27:15 +08:00
|
|
|
import subprocess
|
2020-01-31 07:51:29 +08:00
|
|
|
import sys
|
|
|
|
import tempfile
|
2020-01-21 02:27:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
def help():
|
2020-01-23 02:46:43 +08:00
|
|
|
print("usage: {} capture|replay [args]".format(sys.argv[0]))
|
2020-01-21 02:27:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-01-23 02:46:43 +08:00
|
|
|
if len(sys.argv) < 2:
|
2020-01-21 02:27:15 +08:00
|
|
|
help()
|
|
|
|
return 1
|
|
|
|
|
2020-01-24 08:35:42 +08:00
|
|
|
# Compute an MD5 hash based on the input arguments and the current working
|
2020-01-21 02:27:15 +08:00
|
|
|
# directory.
|
2020-01-24 08:35:42 +08:00
|
|
|
h = hashlib.md5()
|
2020-01-24 13:41:46 +08:00
|
|
|
h.update(' '.join(sys.argv[2:]).encode('utf-8'))
|
|
|
|
h.update(os.getcwd().encode('utf-8'))
|
2020-01-24 08:35:42 +08:00
|
|
|
input_hash = h.hexdigest()
|
2020-01-21 02:27:15 +08:00
|
|
|
|
|
|
|
# Use the hash to "uniquely" identify a reproducer path.
|
|
|
|
reproducer_path = os.path.join(tempfile.gettempdir(), input_hash)
|
|
|
|
|
|
|
|
# Create a new lldb invocation with capture or replay enabled.
|
|
|
|
lldb = os.path.join(os.path.dirname(sys.argv[0]), 'lldb')
|
2020-01-23 02:46:43 +08:00
|
|
|
new_args = [lldb]
|
2020-01-24 13:46:47 +08:00
|
|
|
cleanup = False
|
2020-01-23 02:46:43 +08:00
|
|
|
if sys.argv[1] == "replay":
|
2020-01-21 02:27:15 +08:00
|
|
|
new_args.extend(['--replay', reproducer_path])
|
2020-01-24 13:46:47 +08:00
|
|
|
cleanup = True
|
2020-01-23 02:46:43 +08:00
|
|
|
elif sys.argv[1] == "capture":
|
2020-01-21 02:27:15 +08:00
|
|
|
new_args.extend([
|
|
|
|
'--capture', '--capture-path', reproducer_path,
|
|
|
|
'--reproducer-auto-generate'
|
|
|
|
])
|
2020-01-23 02:46:43 +08:00
|
|
|
new_args.extend(sys.argv[2:])
|
2020-01-21 02:27:15 +08:00
|
|
|
else:
|
|
|
|
help()
|
|
|
|
return 1
|
|
|
|
|
2020-01-24 13:46:47 +08:00
|
|
|
exit_code = subprocess.call(new_args)
|
|
|
|
if cleanup:
|
|
|
|
shutil.rmtree(reproducer_path, True)
|
|
|
|
return exit_code
|
2020-01-21 02:27:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
exit(main())
|