1 2// LLDB C++ API Test: verify the event description that is received by an 3// SBListener object registered with a process with a breakpoint. 4 5#include <atomic> 6#include <array> 7#include <iostream> 8#include <string> 9#include <thread> 10 11#include "lldb-headers.h" 12 13#include "common.h" 14 15using namespace lldb; 16using namespace std; 17 18// listener thread control 19extern atomic<bool> g_done; 20 21multithreaded_queue<string> g_event_descriptions; 22 23extern SBListener g_listener; 24 25void 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 33 SBStream description; 34 event.GetDescription(description); 35 string str(description.GetData()); 36 g_event_descriptions.push(str); 37 } 38 } 39} 40 41void check_listener(SBDebugger &dbg) { 42 array<string, 2> expected_states = {"running", "stopped"}; 43 for(string & state : expected_states) { 44 bool got_description = false; 45 string desc = g_event_descriptions.pop(5, got_description); 46 47 if (!got_description) 48 throw Exception("Did not get expected event description"); 49 50 51 if (desc.find("state-changed") == desc.npos) 52 throw Exception("Event description incorrect: missing 'state-changed'"); 53 54 string state_search_str = "state = " + state; 55 if (desc.find(state_search_str) == desc.npos) 56 throw Exception("Event description incorrect: expected state " 57 + state 58 + " but desc was " 59 + desc); 60 61 if (desc.find("pid = ") == desc.npos) 62 throw Exception("Event description incorrect: missing process pid"); 63 } 64} 65