4 lldb-repro is a utility to transparently capture and replay debugger sessions
5 through the command line driver. Its used to test the reproducers by running
8 During the first run, with 'capture' as its first argument, it captures a
9 reproducer for every lldb invocation and saves it to a well-know location
10 derived from the arguments and current working directory.
12 During the second run, with 'replay' as its first argument, the test suite is
13 run again but this time every invocation of lldb replays the previously
26 print("usage: {} capture|replay [args]".format(sys
.argv
[0]))
34 # Compute an MD5 hash based on the input arguments and the current working
37 h
.update(" ".join(sys
.argv
[2:]).encode("utf-8"))
38 h
.update(os
.getcwd().encode("utf-8"))
39 input_hash
= h
.hexdigest()
41 # Use the hash to "uniquely" identify a reproducer path.
42 reproducer_path
= os
.path
.join(tempfile
.gettempdir(), input_hash
)
44 # Create a new lldb invocation with capture or replay enabled.
45 lldb
= os
.path
.join(os
.path
.dirname(sys
.argv
[0]), "lldb")
47 if sys
.argv
[1] == "replay":
48 new_args
.extend(["--replay", reproducer_path
])
49 elif sys
.argv
[1] == "capture":
55 "--reproducer-generate-on-exit",
58 new_args
.extend(sys
.argv
[2:])
63 exit_code
= subprocess
.call(new_args
)
65 # The driver always exists with a zero exit code during replay. Store the
66 # exit code and return that for tests that expect a non-zero exit code.
67 exit_code_path
= os
.path
.join(reproducer_path
, "exit_code.txt")
68 if sys
.argv
[1] == "replay":
69 replay_exit_code
= exit_code
70 with
open(exit_code_path
, "r") as f
:
71 exit_code
= int(f
.read())
72 if replay_exit_code
!= 0:
73 print("error: replay failed with exit code {}".format(replay_exit_code
))
74 print("invocation: " + " ".join(new_args
))
75 # Return 1 if the expected exit code is 0 or vice versa.
76 return 1 if (exit_code
== 0) else 0
77 shutil
.rmtree(reproducer_path
, True)
78 elif sys
.argv
[1] == "capture":
79 with
open(exit_code_path
, "w") as f
:
80 f
.write("%d" % exit_code
)
85 if __name__
== "__main__":