From f817bae1616852aeae880aa8e6a22407276aa223 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 27 Oct 2016 22:52:32 +0000 Subject: [Test Suite] Pull generateSource into lldbtest Summary: Convert tests using LLDB headers to use generateSource to put the right include paths in place regardless of whether or not you're building a framework. This also abstracted generateSource out of TestPublicAPIHeaders.py into lldbtest.py. Reviewers: tfiala, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D25887 llvm-svn: 285357 --- .../test/api/multithreaded/TestMultithreaded.py | 9 ++ .../lldbsuite/test/api/multithreaded/driver.cpp | 38 --------- .../test/api/multithreaded/driver.cpp.template | 38 +++++++++ .../test/api/multithreaded/listener_test.cpp | 74 ----------------- .../api/multithreaded/listener_test.cpp.template | 74 +++++++++++++++++ .../test/api/multithreaded/lldb-headers.h | 11 --- .../api/multithreaded/test_breakpoint_callback.cpp | 49 ----------- .../test_breakpoint_callback.cpp.template | 49 +++++++++++ .../test_listener_event_description.cpp | 97 ---------------------- .../test_listener_event_description.cpp.template | 97 ++++++++++++++++++++++ .../test_listener_event_process_state.cpp | 63 -------------- .../test_listener_event_process_state.cpp.template | 63 ++++++++++++++ .../api/multithreaded/test_listener_resume.cpp | 53 ------------ .../test_listener_resume.cpp.template | 53 ++++++++++++ 14 files changed, 383 insertions(+), 385 deletions(-) delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template delete mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template (limited to 'lldb/packages/Python/lldbsuite/test/api/multithreaded') diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py b/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py index 970c25107f6..abd252b1e5b 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py @@ -15,6 +15,15 @@ import subprocess class SBBreakpointCallbackCase(TestBase): + def setUp(self): + TestBase.setUp(self) + self.generateSource('driver.cpp') + self.generateSource('listener_test.cpp') + self.generateSource('test_breakpoint_callback.cpp') + self.generateSource('test_listener_event_description.cpp') + self.generateSource('test_listener_event_process_state.cpp') + self.generateSource('test_listener_resume.cpp') + mydir = TestBase.compute_mydir(__file__) @skipIfRemote diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp deleted file mode 100644 index fa0c48e0ecf..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -/// LLDB C API Test Driver - -#include -#include -#include -#include -#include - -#include "lldb-headers.h" - -#include "common.h" - -using namespace std; -using namespace lldb; - -void test(SBDebugger &dbg, std::vector args); - -int main(int argc, char** argv) { - int code = 0; - - SBDebugger::Initialize(); - SBDebugger dbg = SBDebugger::Create(); - - try { - if (!dbg.IsValid()) - throw Exception("invalid debugger"); - vector args(argv + 1, argv + argc); - - test(dbg, args); - } catch (Exception &e) { - cout << "ERROR: " << e.what() << endl; - code = 1; - } - - SBDebugger::Destroy(dbg); - return code; -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template new file mode 100644 index 00000000000..adb1d200655 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template @@ -0,0 +1,38 @@ + +/// LLDB C API Test Driver + +#include +#include +#include +#include +#include + +%include_SB_APIs% + +#include "common.h" + +using namespace std; +using namespace lldb; + +void test(SBDebugger &dbg, std::vector args); + +int main(int argc, char** argv) { + int code = 0; + + SBDebugger::Initialize(); + SBDebugger dbg = SBDebugger::Create(); + + try { + if (!dbg.IsValid()) + throw Exception("invalid debugger"); + vector args(argv + 1, argv + argc); + + test(dbg, args); + } catch (Exception &e) { + cout << "ERROR: " << e.what() << endl; + code = 1; + } + + SBDebugger::Destroy(dbg); + return code; +} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp deleted file mode 100644 index b20868ff94f..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// LLDB test snippet that registers a listener with a process that hits -// a breakpoint. - -#include -#include -#include -#include -#include - -#include "lldb-headers.h" -#include "common.h" - -using namespace lldb; -using namespace std; - -void listener_func(); -void check_listener(SBDebugger &dbg); - -// Listener thread and related variables -atomic g_done; -SBListener g_listener("test-listener"); -thread g_listener_thread; - -void shutdown_listener() { - g_done.store(true); - if (g_listener_thread.joinable()) - g_listener_thread.join(); -} - -void test(SBDebugger &dbg, std::vector args) { - try { - g_done.store(false); - SBTarget target = dbg.CreateTarget(args.at(0).c_str()); - if (!target.IsValid()) throw Exception("invalid target"); - - SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); - if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); - - std::unique_ptr working_dir(get_working_dir()); - - SBError error; - SBProcess process = target.Launch(g_listener, - 0, 0, 0, 0, 0, - working_dir.get(), - 0, - false, - error); - if (!error.Success()) - throw Exception("Error launching process."); - - /* FIXME: the approach below deadlocks - SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); - - // get debugger listener (which is attached to process by default) - g_listener = dbg.GetListener(); - */ - - // FIXME: because a listener is attached to the process at launch-time, - // registering the listener below results in two listeners being attached, - // which is not supported by LLDB. - // register listener - // process.GetBroadcaster().AddListener(g_listener, - // SBProcess::eBroadcastBitStateChanged); - - // start listener thread - g_listener_thread = thread(listener_func); - check_listener(dbg); - - } catch (Exception &e) { - shutdown_listener(); - throw e; - } - shutdown_listener(); -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template new file mode 100644 index 00000000000..e305d1af489 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template @@ -0,0 +1,74 @@ +// LLDB test snippet that registers a listener with a process that hits +// a breakpoint. + +#include +#include +#include +#include +#include + +%include_SB_APIs% +#include "common.h" + +using namespace lldb; +using namespace std; + +void listener_func(); +void check_listener(SBDebugger &dbg); + +// Listener thread and related variables +atomic g_done; +SBListener g_listener("test-listener"); +thread g_listener_thread; + +void shutdown_listener() { + g_done.store(true); + if (g_listener_thread.joinable()) + g_listener_thread.join(); +} + +void test(SBDebugger &dbg, std::vector args) { + try { + g_done.store(false); + SBTarget target = dbg.CreateTarget(args.at(0).c_str()); + if (!target.IsValid()) throw Exception("invalid target"); + + SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); + if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); + + std::unique_ptr working_dir(get_working_dir()); + + SBError error; + SBProcess process = target.Launch(g_listener, + 0, 0, 0, 0, 0, + working_dir.get(), + 0, + false, + error); + if (!error.Success()) + throw Exception("Error launching process."); + + /* FIXME: the approach below deadlocks + SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); + + // get debugger listener (which is attached to process by default) + g_listener = dbg.GetListener(); + */ + + // FIXME: because a listener is attached to the process at launch-time, + // registering the listener below results in two listeners being attached, + // which is not supported by LLDB. + // register listener + // process.GetBroadcaster().AddListener(g_listener, + // SBProcess::eBroadcastBitStateChanged); + + // start listener thread + g_listener_thread = thread(listener_func); + check_listener(dbg); + + } catch (Exception &e) { + shutdown_listener(); + throw e; + } + shutdown_listener(); +} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h b/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h deleted file mode 100644 index da0914b3b07..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef LLDB_HEADERS_H -#define LLDB_HEADERS_H - -#ifdef __APPLE__ -#include -#else -#include "lldb/API/LLDB.h" -#endif - -#endif // LLDB_HEADERS_H diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp deleted file mode 100644 index def31f82b0c..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -// LLDB C++ API Test: verify that the function registered with -// SBBreakpoint.SetCallback() is invoked when a breakpoint is hit. - -#include -#include -#include -#include - -#include "lldb-headers.h" - -#include "common.h" - -using namespace std; -using namespace lldb; - -mutex g_mutex; -condition_variable g_condition; -int g_breakpoint_hit_count = 0; - -bool BPCallback (void *baton, - SBProcess &process, - SBThread &thread, - SBBreakpointLocation &location) { - lock_guard lock(g_mutex); - g_breakpoint_hit_count += 1; - g_condition.notify_all(); - return true; -} - -void test(SBDebugger &dbg, vector args) { - dbg.SetAsync(false); - SBTarget target = dbg.CreateTarget(args.at(0).c_str()); - if (!target.IsValid()) throw Exception("invalid target"); - - SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); - if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); - breakpoint.SetCallback(BPCallback, 0); - - std::unique_ptr working_dir(get_working_dir()); - SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); - - { - unique_lock lock(g_mutex); - g_condition.wait_for(lock, chrono::seconds(5)); - if (g_breakpoint_hit_count != 1) - throw Exception("Breakpoint hit count expected to be 1"); - } -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template new file mode 100644 index 00000000000..4133025aa49 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template @@ -0,0 +1,49 @@ + +// LLDB C++ API Test: verify that the function registered with +// SBBreakpoint.SetCallback() is invoked when a breakpoint is hit. + +#include +#include +#include +#include + +%include_SB_APIs% + +#include "common.h" + +using namespace std; +using namespace lldb; + +mutex g_mutex; +condition_variable g_condition; +int g_breakpoint_hit_count = 0; + +bool BPCallback (void *baton, + SBProcess &process, + SBThread &thread, + SBBreakpointLocation &location) { + lock_guard lock(g_mutex); + g_breakpoint_hit_count += 1; + g_condition.notify_all(); + return true; +} + +void test(SBDebugger &dbg, vector args) { + dbg.SetAsync(false); + SBTarget target = dbg.CreateTarget(args.at(0).c_str()); + if (!target.IsValid()) throw Exception("invalid target"); + + SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); + if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); + breakpoint.SetCallback(BPCallback, 0); + + std::unique_ptr working_dir(get_working_dir()); + SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); + + { + unique_lock lock(g_mutex); + g_condition.wait_for(lock, chrono::seconds(5)); + if (g_breakpoint_hit_count != 1) + throw Exception("Breakpoint hit count expected to be 1"); + } +} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp deleted file mode 100644 index 0d7844dce6d..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp +++ /dev/null @@ -1,97 +0,0 @@ - -// LLDB C++ API Test: verify the event description that is received by an -// SBListener object registered with a process with a breakpoint. - -#include -#include -#include -#include -#include - -#include "lldb-headers.h" - -#include "common.h" - -using namespace lldb; -using namespace std; - -// listener thread control -extern atomic g_done; -extern SBListener g_listener; - -multithreaded_queue g_event_descriptions; -string g_error_desc; - -void listener_func() { - while (!g_done) { - SBEvent event; - bool got_event = g_listener.WaitForEvent(1, event); - - if (got_event) { - if (!event.IsValid()) - throw Exception("event is not valid in listener thread"); - - SBStream description; - event.GetDescription(description); - string str(description.GetData()); - g_event_descriptions.push(str); - } - } -} - -bool check_state(string &state, string &desc, bool got_description) -{ - g_error_desc.clear(); - - if(!got_description) - { - g_error_desc.append("Did not get expected event description"); - return false; - } - - if (desc.find("state-changed") == desc.npos) - g_error_desc.append("Event description incorrect: missing 'state-changed' "); - - if (desc.find("pid = ") == desc.npos) - g_error_desc.append("Event description incorrect: missing process pid "); - - string state_search_str = "state = " + state; - if (desc.find(state_search_str) == desc.npos) - { - string errString = ("Event description incorrect: expected state " - + state - + " but desc was " - + desc); - g_error_desc.append(errString); - } - - if (g_error_desc.length() > 0) - return false; - - cout << "check_state: " << state << " OK\n"; - return true; -} - -void check_listener(SBDebugger &dbg) -{ - bool got_description; - string state; - - // check for "launching" state, this may or may not be present - string desc = g_event_descriptions.pop(5, got_description); - state = "launching"; - if (check_state(state, desc, got_description)) - { - // found a 'launching' state, pop next one from queue - desc = g_event_descriptions.pop(5, got_description); - } - - state = "running"; - if( !check_state(state, desc, got_description) ) - throw Exception(g_error_desc); - - desc = g_event_descriptions.pop(5, got_description); - state = "stopped"; - if( !check_state(state, desc, got_description) ) - throw Exception(g_error_desc); -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template new file mode 100644 index 00000000000..63e3f3631e5 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template @@ -0,0 +1,97 @@ + +// LLDB C++ API Test: verify the event description that is received by an +// SBListener object registered with a process with a breakpoint. + +#include +#include +#include +#include +#include + +%include_SB_APIs% + +#include "common.h" + +using namespace lldb; +using namespace std; + +// listener thread control +extern atomic g_done; +extern SBListener g_listener; + +multithreaded_queue g_event_descriptions; +string g_error_desc; + +void listener_func() { + while (!g_done) { + SBEvent event; + bool got_event = g_listener.WaitForEvent(1, event); + + if (got_event) { + if (!event.IsValid()) + throw Exception("event is not valid in listener thread"); + + SBStream description; + event.GetDescription(description); + string str(description.GetData()); + g_event_descriptions.push(str); + } + } +} + +bool check_state(string &state, string &desc, bool got_description) +{ + g_error_desc.clear(); + + if(!got_description) + { + g_error_desc.append("Did not get expected event description"); + return false; + } + + if (desc.find("state-changed") == desc.npos) + g_error_desc.append("Event description incorrect: missing 'state-changed' "); + + if (desc.find("pid = ") == desc.npos) + g_error_desc.append("Event description incorrect: missing process pid "); + + string state_search_str = "state = " + state; + if (desc.find(state_search_str) == desc.npos) + { + string errString = ("Event description incorrect: expected state " + + state + + " but desc was " + + desc); + g_error_desc.append(errString); + } + + if (g_error_desc.length() > 0) + return false; + + cout << "check_state: " << state << " OK\n"; + return true; +} + +void check_listener(SBDebugger &dbg) +{ + bool got_description; + string state; + + // check for "launching" state, this may or may not be present + string desc = g_event_descriptions.pop(5, got_description); + state = "launching"; + if (check_state(state, desc, got_description)) + { + // found a 'launching' state, pop next one from queue + desc = g_event_descriptions.pop(5, got_description); + } + + state = "running"; + if( !check_state(state, desc, got_description) ) + throw Exception(g_error_desc); + + desc = g_event_descriptions.pop(5, got_description); + state = "stopped"; + if( !check_state(state, desc, got_description) ) + throw Exception(g_error_desc); +} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp deleted file mode 100644 index 574257e98ee..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -// LLDB C++ API Test: verify the event description as obtained by calling -// SBEvent::GetCStringFromEvent that is received by an -// SBListener object registered with a process with a breakpoint. - -#include -#include -#include -#include - -#include "lldb-headers.h" - -#include "common.h" - -using namespace lldb; -using namespace std; - -// listener thread control -extern atomic g_done; - -multithreaded_queue g_frame_functions; - -extern SBListener g_listener; - -void listener_func() { - while (!g_done) { - SBEvent event; - bool got_event = g_listener.WaitForEvent(1, event); - if (got_event) { - if (!event.IsValid()) - throw Exception("event is not valid in listener thread"); - // send process description - SBProcess process = SBProcess::GetProcessFromEvent(event); - if (!process.IsValid()) - throw Exception("process is not valid"); - if (SBProcess::GetStateFromEvent(event) != lldb::eStateStopped || SBProcess::GetRestartedFromEvent(event)) - continue; // Only interested in "stopped" events. - - SBStream description; - - for (int i = 0; i < process.GetNumThreads(); ++i) { - // send each thread description - SBThread thread = process.GetThreadAtIndex(i); - // send each frame function name - uint32_t num_frames = thread.GetNumFrames(); - for(int j = 0; j < num_frames; ++j) { - const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName(); - if (function_name) - g_frame_functions.push(string(function_name)); - } - } - } - } -} - -void check_listener(SBDebugger &dbg) { - // check thread description - bool got_description = false; - string func_name = g_frame_functions.pop(5, got_description); - - if(got_description == false) - throw Exception("Expected at least one frame function"); -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template new file mode 100644 index 00000000000..2926ece4d8d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template @@ -0,0 +1,63 @@ + +// LLDB C++ API Test: verify the event description as obtained by calling +// SBEvent::GetCStringFromEvent that is received by an +// SBListener object registered with a process with a breakpoint. + +#include +#include +#include +#include + +%include_SB_APIs% + +#include "common.h" + +using namespace lldb; +using namespace std; + +// listener thread control +extern atomic g_done; + +multithreaded_queue g_frame_functions; + +extern SBListener g_listener; + +void listener_func() { + while (!g_done) { + SBEvent event; + bool got_event = g_listener.WaitForEvent(1, event); + if (got_event) { + if (!event.IsValid()) + throw Exception("event is not valid in listener thread"); + // send process description + SBProcess process = SBProcess::GetProcessFromEvent(event); + if (!process.IsValid()) + throw Exception("process is not valid"); + if (SBProcess::GetStateFromEvent(event) != lldb::eStateStopped || SBProcess::GetRestartedFromEvent(event)) + continue; // Only interested in "stopped" events. + + SBStream description; + + for (int i = 0; i < process.GetNumThreads(); ++i) { + // send each thread description + SBThread thread = process.GetThreadAtIndex(i); + // send each frame function name + uint32_t num_frames = thread.GetNumFrames(); + for(int j = 0; j < num_frames; ++j) { + const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName(); + if (function_name) + g_frame_functions.push(string(function_name)); + } + } + } + } +} + +void check_listener(SBDebugger &dbg) { + // check thread description + bool got_description = false; + string func_name = g_frame_functions.pop(5, got_description); + + if(got_description == false) + throw Exception("Expected at least one frame function"); +} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp deleted file mode 100644 index 8cf786b1160..00000000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp +++ /dev/null @@ -1,53 +0,0 @@ - -// LLDB C++ API Test: verify the event description as obtained by calling -// SBEvent::GetCStringFromEvent that is received by an -// SBListener object registered with a process with a breakpoint. - -#include -#include -#include -#include - -#include "lldb-headers.h" - -#include "common.h" - -using namespace lldb; -using namespace std; - -// listener thread control -extern atomic g_done; - -// used by listener thread to communicate a successful process continue command -// back to the checking thread. - -multithreaded_queue g_process_started; - -extern SBListener g_listener; - -void listener_func() { - while (!g_done) { - SBEvent event; - bool got_event = g_listener.WaitForEvent(1, event); - if (got_event) { - if (!event.IsValid()) - throw Exception("event is not valid in listener thread"); - - SBProcess process = SBProcess::GetProcessFromEvent(event); - if (process.GetState() == eStateStopped) { - SBError error = process.Continue(); - if (!error.Success()) - throw Exception(string("Cannot continue process from listener thread: ") - + error.GetCString()); - g_process_started.push(true); - } - } - } -} - -void check_listener(SBDebugger &dbg) { - bool got_message = false; - while (!got_message) - g_process_started.pop(5, got_message); - g_done = true; -} diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template new file mode 100644 index 00000000000..4adc9b33887 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template @@ -0,0 +1,53 @@ + +// LLDB C++ API Test: verify the event description as obtained by calling +// SBEvent::GetCStringFromEvent that is received by an +// SBListener object registered with a process with a breakpoint. + +#include +#include +#include +#include + +%include_SB_APIs% + +#include "common.h" + +using namespace lldb; +using namespace std; + +// listener thread control +extern atomic g_done; + +// used by listener thread to communicate a successful process continue command +// back to the checking thread. + +multithreaded_queue g_process_started; + +extern SBListener g_listener; + +void listener_func() { + while (!g_done) { + SBEvent event; + bool got_event = g_listener.WaitForEvent(1, event); + if (got_event) { + if (!event.IsValid()) + throw Exception("event is not valid in listener thread"); + + SBProcess process = SBProcess::GetProcessFromEvent(event); + if (process.GetState() == eStateStopped) { + SBError error = process.Continue(); + if (!error.Success()) + throw Exception(string("Cannot continue process from listener thread: ") + + error.GetCString()); + g_process_started.push(true); + } + } + } +} + +void check_listener(SBDebugger &dbg) { + bool got_message = false; + while (!got_message) + g_process_started.pop(5, got_message); + g_done = true; +} -- cgit v1.2.3