1 // LLDB test snippet that registers a listener with a process that hits
10 #include "lldb-headers.h"
17 void check_listener(SBDebugger &dbg);
19 // Listener thread and related variables
21 SBListener g_listener("test-listener");
22 thread g_listener_thread;
24 void shutdown_listener() {
26 if (g_listener_thread.joinable())
27 g_listener_thread.join();
30 void test(SBDebugger &dbg, std::vector<string> args) {
33 SBTarget target = dbg.CreateTarget(args.at(0).c_str());
34 if (!target.IsValid()) throw Exception("invalid target");
36 SBBreakpoint breakpoint = target.BreakpointCreateByName("next");
37 if (!breakpoint.IsValid()) throw Exception("invalid breakpoint");
39 std::unique_ptr<char> working_dir(get_working_dir());
42 SBProcess process = target.Launch(g_listener,
49 throw Exception("Error launching process.");
51 /* FIXME: the approach below deadlocks
52 SBProcess process = target.LaunchSimple (0, 0, working_dir.get());
54 // get debugger listener (which is attached to process by default)
55 g_listener = dbg.GetListener();
58 // FIXME: because a listener is attached to the process at launch-time,
59 // registering the listener below results in two listeners being attached,
60 // which is not supported by LLDB.
62 // process.GetBroadcaster().AddListener(g_listener,
63 // SBProcess::eBroadcastBitStateChanged);
65 // start listener thread
66 g_listener_thread = thread(listener_func);
69 } catch (Exception &e) {