From 67420f1b0e9c673ee638f2680fa83f468019004f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 20 Jan 2020 10:27:15 -0800 Subject: [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 --- lldb/utils/CMakeLists.txt | 1 + lldb/utils/lldb-repro/CMakeLists.txt | 4 +++ lldb/utils/lldb-repro/lldb-repro.py | 60 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 lldb/utils/lldb-repro/CMakeLists.txt create mode 100644 lldb/utils/lldb-repro/lldb-repro.py (limited to 'lldb/utils') 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()) -- cgit v1.1