Page MenuHomePhabricator

[lldb] [test] Extend watchpoint test to wait for thread to start
ClosedPublic

Authored by mgorny on Nov 8 2020, 5:20 AM.

Details

Summary

TestWatchpointMultipleThreads currently accounts for two scenarios:
setting the watchpoint before a new thread starts (presumably, verifying
that it will be propagated to the new thread) and setting it after
the thread starts (presumably, verifying that a new watchpoint is set
on all threads). However, the latter test currently assumes that
the thread will be reported to the debugger before the breakpoint is
hit. This is not the case on FreeBSD and NetBSD.

On NetBSD, new threads do not inherit debug registers from their parent
threads. Instead, LLDB copies them manually after the new thread is
reported. Since the thread is actually reported after the second
breakpoint location, both tests effectively check the same behavior
(i.e. watchpoint being set before the new thread is reported).

On FreeBSD, new threads inherit debug registers and we seem to hit
an interesting race condition. While the thread is reported after
the breakpoint is hit, the kernel seems to construct it and copy
the debug register before that happens. As a result, setting
the watchpoint at the second breakpoint location modifies the debug
registers of the first thread after they have been copied to the second
thread but before the debugger is aware of it. Therefore,
the watchpoint is not propagated to the second thread and the test
fails.

Extend the test to cover all three possible scenarios: setting
watchpoint before the thread is lanched, after it is launched but before
it is guaranteed to have started and after it has actually started. Add
a second barrier to account for the last case. This should ensure that
the second assumption (i.e. that the watchpoint is set on all currently
known threads) is actually tested on FreeBSD and NetBSD.

Diff Detail

Event Timeline

mgorny created this revision.Nov 8 2020, 5:20 AM
mgorny requested review of this revision.Nov 8 2020, 5:20 AM

NB: I'm going to address the FreeBSD problem separately.

labath accepted this revision.Nov 9 2020, 12:44 AM
This revision is now accepted and ready to land.Nov 9 2020, 12:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2020, 2:37 AM