[lldb] Speculative fix to TestGuiExpandThreadsTree

This test relies on being able to unwind from an arbitrary place inside
libc. While I am not sure this is the cause of the observed flakyness,
it is known that we are not able to unwind correctly from some places in
(linux) libc.

This patch adds additional synchronization to ensure that the inferior
is in the main function (instead of pthread guts) when lldb tries to
unwind it. At the very least, it should make the test runs more
predictable/repeatable.
This commit is contained in:
Pavel Labath 2021-09-21 09:55:56 +02:00
parent 0d12c99191
commit 791b6ebc86
4 changed files with 27 additions and 13 deletions

View File

@ -1,3 +1,3 @@
C_SOURCES := main.c
CXX_SOURCES := main.cpp
ENABLE_THREADS := YES
include Makefile.rules

View File

@ -22,7 +22,7 @@ class TestGuiExpandThreadsTree(PExpectTest):
self.build()
self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500))
self.expect("breakpoint set -r thread_start_routine", substrs=["Breakpoint 1", "address ="])
self.expect("breakpoint set -n break_here", substrs=["Breakpoint 1", "address ="])
self.expect("run", substrs=["stop reason ="])
escape_key = chr(27).encode()
@ -33,7 +33,7 @@ class TestGuiExpandThreadsTree(PExpectTest):
self.child.expect_exact("Threads")
# The thread running thread_start_routine should be expanded.
self.child.expect_exact("frame #0: thread_start_routine")
self.child.expect_exact("frame #0: break_here")
# Exit GUI.
self.child.send(escape_key)

View File

@ -1,10 +0,0 @@
#include <pthread.h>
void *thread_start_routine(void *arg) { return NULL; }
int main() {
pthread_t thread;
pthread_create(&thread, NULL, thread_start_routine, NULL);
pthread_join(thread, NULL);
return 0;
}

View File

@ -0,0 +1,24 @@
#include "pseudo_barrier.h"
#include <thread>
pseudo_barrier_t barrier_before;
pseudo_barrier_t barrier_after;
void break_here() {}
void thread_func() {
pseudo_barrier_wait(barrier_before);
break_here();
pseudo_barrier_wait(barrier_after);
}
int main() {
pseudo_barrier_init(barrier_before, 2);
pseudo_barrier_init(barrier_after, 2);
std::thread thread(thread_func);
pseudo_barrier_wait(barrier_before);
pseudo_barrier_wait(barrier_after);
thread.join();
return 0;
}