diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2020-01-20 10:27:15 -0800 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2020-01-20 10:30:19 -0800 |
commit | 67420f1b0e9c673ee638f2680fa83f468019004f (patch) | |
tree | acea52949addba1a1f6369ef1c1e1577099f83fd /lldb/utils | |
parent | b37f6d3af100dacf550888aef21787c2b2494ad0 (diff) | |
download | llvm-67420f1b0e9c673ee638f2680fa83f468019004f.zip llvm-67420f1b0e9c673ee638f2680fa83f468019004f.tar.gz llvm-67420f1b0e9c673ee638f2680fa83f468019004f.tar.bz2 |
[lldb/Util] Add a utility to run transparently capture and replay tests.
This patch introduces a small new utility (lldb-repro) 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, 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, the test suite is run
again but this time every invocation of lldb replays the previously
recorded session.
Differential revision: https://reviews.llvm.org/D72823
Diffstat (limited to 'lldb/utils')
-rw-r--r-- | lldb/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/utils/lldb-repro/CMakeLists.txt | 4 | ||||
-rw-r--r-- | lldb/utils/lldb-repro/lldb-repro.py | 60 |
3 files changed, 65 insertions, 0 deletions
diff --git a/lldb/utils/CMakeLists.txt b/lldb/utils/CMakeLists.txt index d08f66f..00c81e6 100644 --- a/lldb/utils/CMakeLists.txt +++ b/lldb/utils/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(lit-cpuid) add_subdirectory(lldb-dotest) +add_subdirectory(lldb-repro) diff --git a/lldb/utils/lldb-repro/CMakeLists.txt b/lldb/utils/lldb-repro/CMakeLists.txt new file mode 100644 index 0000000..0bfcaaa --- /dev/null +++ b/lldb/utils/lldb-repro/CMakeLists.txt @@ -0,0 +1,4 @@ +add_custom_target(lldb-repro) +add_dependencies(lldb-repro lldb-test-deps) +set_target_properties(lldb-repro PROPERTIES FOLDER "lldb utils") +configure_file(lldb-repro.py ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-repro COPYONLY) diff --git a/lldb/utils/lldb-repro/lldb-repro.py b/lldb/utils/lldb-repro/lldb-repro.py new file mode 100644 index 0000000..c925c47 --- /dev/null +++ b/lldb/utils/lldb-repro/lldb-repro.py @@ -0,0 +1,60 @@ +#!/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. +""" + +import sys +import os +import tempfile +import subprocess + + +def help(): + print("usage: {} capture|replay [args]".fmt(sys.argv[0])) + + +def main(): + if len(sys.argv) < 3: + help() + return 1 + + # Compute a hash based on the input arguments and the current working + # directory. + args = ' '.join(sys.argv[3:]) + cwd = os.getcwd() + input_hash = str(hash((cwd, args))) + + # 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') + new_args = [sys.argv[1]] + if sys.argv[2] == "replay": + new_args.extend(['--replay', reproducer_path]) + elif sys.argv[2] == "capture": + new_args.extend([ + '--capture', '--capture-path', reproducer_path, + '--reproducer-auto-generate' + ]) + new_args.extend(sys.argv[1:]) + else: + help() + return 1 + + return subprocess.call(new_args) + + +if __name__ == '__main__': + exit(main()) |