This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Deal gracefully with concurrency in the API instrumentation.
ClosedPublic

Authored by JDevlieghere on Dec 8 2020, 12:20 AM.

Details

Summary

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 guarantee that the function id and its arguments are emitted as a single unit and that the return value is emitted as a single unit. Every API call is given a monotonically increasing index, which correlates the function with its return value.

Using the index, 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.

Diff Detail

Event Timeline

JDevlieghere created this revision.Dec 8 2020, 12:20 AM
friss added a comment.Dec 9 2020, 8:56 AM

The change itself looks fine, but I'm wondering about the test. There is nothing that really guarantees that the SB calls and return values are going to be intertwined, is there? Does it rely solely on the fact that it's very very unlikely to succeed?

Change test to unit test.

friss accepted this revision.Dec 10 2020, 8:42 AM

This LGTM.
There is one thing that you might want to address, but I'll leave it up to you (and even if you do it can be a different commit): with the introduction of idx variables, it becomes easy to get confused between id and idx(Or CheckID and CheckIndex) in the codebase. Not sure how to disambiguate, or if it's really worth it.

This revision is now accepted and ready to land.Dec 10 2020, 8:42 AM

This LGTM.
There is one thing that you might want to address, but I'll leave it up to you (and even if you do it can be a different commit): with the introduction of idx variables, it becomes easy to get confused between id and idx(Or CheckID and CheckIndex) in the codebase. Not sure how to disambiguate, or if it's really worth it.

Agreed, it's even more confusing because I also use idx for the object index. Let me rename this to sequence.

Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2020, 9:38 AM