]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / api / multithreaded / test_listener_resume.cpp.template
1
2 // LLDB C++ API Test: verify the event description as obtained by calling
3 // SBEvent::GetCStringFromEvent that is received by an
4 // SBListener object registered with a process with a breakpoint.
5
6 #include <atomic>
7 #include <iostream>
8 #include <string>
9 #include <thread>
10
11 %include_SB_APIs%
12
13 #include "common.h"
14
15 using namespace lldb;
16 using namespace std;
17
18 // listener thread control
19 extern atomic<bool> g_done;
20
21 // used by listener thread to communicate a successful process continue command
22 // back to the checking thread.
23
24 multithreaded_queue<bool> g_process_started;
25
26 extern SBListener g_listener;
27
28 void listener_func() {
29   while (!g_done) {
30     SBEvent event;
31     bool got_event = g_listener.WaitForEvent(1, event);
32     if (got_event) {
33       if (!event.IsValid())
34         throw Exception("event is not valid in listener thread");
35
36       SBProcess process = SBProcess::GetProcessFromEvent(event);
37       if (process.GetState() == eStateStopped) {
38         SBError error = process.Continue();
39         if (!error.Success())
40           throw Exception(string("Cannot continue process from listener thread: ")
41                           + error.GetCString());
42         g_process_started.push(true);
43       }
44     }
45   }
46 }
47
48 void check_listener(SBDebugger &dbg) {
49   bool got_message = false;
50   while (!got_message)
51     g_process_started.pop(5, got_message);
52   g_done = true;
53 }