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 "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_thread_descriptions; 22multithreaded_queue<string> g_frame_functions; 23 24extern SBListener g_listener; 25 26void listener_func() { 27 while (!g_done) { 28 SBEvent event; 29 bool got_event = g_listener.WaitForEvent(1, event); 30 if (got_event) { 31 if (!event.IsValid()) 32 throw Exception("event is not valid in listener thread"); 33 34 // send process description 35 SBProcess process = SBProcess::GetProcessFromEvent(event); 36 SBStream description; 37 38 for (int i = 0; i < process.GetNumThreads(); ++i) { 39 // send each thread description 40 description.Clear(); 41 SBThread thread = process.GetThreadAtIndex(i); 42 thread.GetDescription(description); 43 g_thread_descriptions.push(description.GetData()); 44 45 // send each frame function name 46 uint32_t num_frames = thread.GetNumFrames(); 47 for(int j = 0; j < num_frames; ++j) { 48 const char* function_name = thread.GetFrameAtIndex(j).GetFunction().GetName(); 49 if (function_name) 50 g_frame_functions.push(function_name); 51 } 52 } 53 } 54 } 55} 56 57void check_listener(SBDebugger &dbg) { 58 // check thread description 59 bool got_description = false; 60 string desc = g_thread_descriptions.pop(5, got_description); 61 if (!got_description) 62 throw Exception("Expected at least one thread description string"); 63 64 // check at least one frame has a function name 65 desc = g_frame_functions.pop(5, got_description); 66 if (!got_description) 67 throw Exception("Expected at least one frame function name string"); 68} 69