]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template
Vendor import of lldb release_39 branch r287912:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / api / multithreaded / test_listener_event_process_state.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 multithreaded_queue<string> g_frame_functions;
22
23 extern SBListener g_listener;
24
25 void listener_func() {
26   while (!g_done) {
27     SBEvent event;
28     bool got_event = g_listener.WaitForEvent(1, event);
29     if (got_event) {
30       if (!event.IsValid())
31         throw Exception("event is not valid in listener thread");
32         // send process description
33         SBProcess process = SBProcess::GetProcessFromEvent(event);
34         if (!process.IsValid())
35             throw Exception("process is not valid");
36         if (SBProcess::GetStateFromEvent(event) != lldb::eStateStopped || SBProcess::GetRestartedFromEvent(event))
37             continue; // Only interested in "stopped" events.
38
39         SBStream description;
40
41         for (int i = 0; i < process.GetNumThreads(); ++i) {
42             // send each thread description
43             SBThread thread = process.GetThreadAtIndex(i);
44             // send each frame function name
45             uint32_t num_frames = thread.GetNumFrames();
46             for(int j = 0; j < num_frames; ++j) {
47                 const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName();
48                 if (function_name)
49                     g_frame_functions.push(string(function_name));
50             }
51         }
52     }
53   }
54 }
55
56 void check_listener(SBDebugger &dbg) {
57   // check thread description
58   bool got_description = false;
59   string func_name = g_frame_functions.pop(5, got_description);
60   
61   if(got_description == false)
62     throw Exception("Expected at least one frame function");
63 }