xref: /llvm-project/lldb/test/API/functionalities/thread/step_out/main.cpp (revision 71c4da83b67a485f0cfacbce8b46eaa497df900e)
1 // This test is intended to create a situation in which two threads are stopped
2 // at a breakpoint and the debugger issues a step-out command.
3 
4 #include "pseudo_barrier.h"
5 #include <thread>
6 
7 pseudo_barrier_t g_barrier;
8 
9 volatile int g_test = 0;
10 
step_out_of_here()11 void step_out_of_here() {
12   g_test += 5; // Set breakpoint here
13 }
14 
15 void *
thread_func()16 thread_func ()
17 {
18     // Wait until both threads are running
19     pseudo_barrier_wait(g_barrier);
20 
21     // Do something
22     step_out_of_here(); // But we might still be here
23 
24     // Return
25     return NULL;  // Expect to stop here after step-out.
26 }
27 
main()28 int main ()
29 {
30     // Don't let either thread do anything until they're both ready.
31     pseudo_barrier_init(g_barrier, 2);
32 
33     // Create two threads
34     std::thread thread_1(thread_func);
35     std::thread thread_2(thread_func);
36 
37     // Wait for the threads to finish
38     thread_1.join();
39     thread_2.join();
40 
41     return 0;
42 }
43