[lldb] Deal gracefully with concurrency in the API instrumentation.
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 10 Dec 2020 17:35:12 +0000 (09:35 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 10 Dec 2020 17:37:49 +0000 (09:37 -0800)
commitac25e8628c443cddd841c6c91d1c9e23e88969e5
tree08ef94431cd80592ca088168e5c0f5b78f1f3448
parent563879b6f9465982b422a69a901e3d84e7cb7764
[lldb] Deal gracefully with concurrency in the API instrumentation.

Prevent lldb from crashing when multiple threads are concurrently
accessing the SB API with reproducer capture enabled.

The API instrumentation records both the input arguments and the return
value, but it cannot block for the duration of the API call. Therefore
we introduce a sequence number that allows to to correlate the function
with its result and add locking to ensure those two parts are emitted
atomically.

Using the sequence number, we can detect situations where the return
value does not succeed the function call, in which case we print an
error saying that concurrency is not (currently) supported. In the
future we might attempt to be smarter and read ahead until we've found
the return value matching the current call.

Differential revision: https://reviews.llvm.org/D92820
lldb/include/lldb/Utility/ReproducerInstrumentation.h
lldb/source/Utility/ReproducerInstrumentation.cpp
lldb/unittests/Utility/ReproducerInstrumentationTest.cpp