Author: Raphael Isemann Date: 2026-08-13T21:06:53+01:00 New Revision: cb5775c4091b31bded7c96bf1ed774075e68f9ea
URL: https://github.com/llvm/llvm-project/commit/cb5775c4091b31bded7c96bf1ed774075e68f9ea DIFF: https://github.com/llvm/llvm-project/commit/cb5775c4091b31bded7c96bf1ed774075e68f9ea.diff LOG: [lldb][test] Don't include all SB API headers in TestMultithreaded (#215551) This test compiles 9 C++ test files and uses the `generateSource` function to inject includes for every single SB API header. The `generateSource` call also sets `SOURCE_DIR` so the test knows its current source directory. This patch removes the need for `generateSource` by including the SB API headers we actually need. SOURCE_DIR is now specified using an environment variable in the test. The motivation for this patch is that I want to avoid recompiling these source files unless their source or the included headers change. Currently, this test is one of the slowest in the test suite and needs about half a minute to run. In the future, I want to at least avoid the recompilation time for each test file. Note that we still have another test that includes all SB API headers normally and as a framework, so this does not remove test coverage. Added: lldb/test/API/api/multithreaded/driver.cpp lldb/test/API/api/multithreaded/listener_test.cpp lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp lldb/test/API/api/multithreaded/test_listener_event_description.cpp lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp lldb/test/API/api/multithreaded/test_listener_resume.cpp lldb/test/API/api/multithreaded/test_stop-hook.cpp Modified: lldb/test/API/api/multithreaded/TestMultithreaded.py Removed: lldb/test/API/api/multithreaded/driver.cpp.template lldb/test/API/api/multithreaded/listener_test.cpp.template lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp.template lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp.template lldb/test/API/api/multithreaded/test_listener_event_description.cpp.template lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp.template lldb/test/API/api/multithreaded/test_listener_resume.cpp.template lldb/test/API/api/multithreaded/test_stop-hook.cpp.template ################################################################################ diff --git a/lldb/test/API/api/multithreaded/TestMultithreaded.py b/lldb/test/API/api/multithreaded/TestMultithreaded.py index a81afac8dc812..3a3467936a349 100644 --- a/lldb/test/API/api/multithreaded/TestMultithreaded.py +++ b/lldb/test/API/api/multithreaded/TestMultithreaded.py @@ -16,15 +16,6 @@ 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_breakpoint_location_callback.cpp") - self.generateSource("test_listener_event_description.cpp") - self.generateSource("test_listener_event_process_state.cpp") - self.generateSource("test_listener_resume.cpp") - self.generateSource("test_stop-hook.cpp") - self.generateSource("test_concurrent_unwind.cpp") @skipIfRemote # clang-cl does not support throw or catch (llvm.org/pr24538) @@ -128,10 +119,15 @@ def build_and_test(self, sources, test_name, inferior_source="inferior.cpp"): test_exe = self.getBuildArtifact(test_name) exe = [test_exe, self.getBuildArtifact(self.inferior)] + # Tests locate their support files (e.g. test_stop-hook.cpp's + # some_cmd.py) via the LLDB_TEST_SOURCE_DIR environment variable. + env = dict(os.environ) + env["LLDB_TEST_SOURCE_DIR"] = self.getSourceDir() + # check_call will raise a CalledProcessError if the executable doesn't # return exit code 0 to indicate success. We can let this exception go # - the test harness will recognize it as a test failure. - subprocess.check_call(exe) + subprocess.check_call(exe, env=env) def build_program(self, sources, program): return self.buildDriver(sources, program) diff --git a/lldb/test/API/api/multithreaded/driver.cpp.template b/lldb/test/API/api/multithreaded/driver.cpp similarity index 84% rename from lldb/test/API/api/multithreaded/driver.cpp.template rename to lldb/test/API/api/multithreaded/driver.cpp index 443f4fed7653d..2c0172c7030cb 100644 --- a/lldb/test/API/api/multithreaded/driver.cpp.template +++ b/lldb/test/API/api/multithreaded/driver.cpp @@ -7,10 +7,10 @@ #include <string> #include <vector> #if !defined(_MSC_VER) - #include <signal.h> +#include <signal.h> #endif -%include_SB_APIs% +#include "lldb/API/SBDebugger.h" #include "common.h" @@ -19,7 +19,7 @@ using namespace lldb; void test(SBDebugger &dbg, std::vector<string> args); -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Ignore SIGPIPE. The lldb driver does this as well, // because we seem to get spurious SIGPIPES on some @@ -32,8 +32,7 @@ int main(int argc, char** argv) { SBDebugger::Initialize(); SBDebugger dbg = SBDebugger::Create(); dbg.HandleCommand("settings set symbols.enable-external-lookup false"); - dbg.HandleCommand( - "settings set plugin.process.gdb-remote.packet-timeout 60"); + dbg.HandleCommand("settings set plugin.process.gdb-remote.packet-timeout 60"); try { if (!dbg.IsValid()) diff --git a/lldb/test/API/api/multithreaded/listener_test.cpp.template b/lldb/test/API/api/multithreaded/listener_test.cpp similarity index 77% rename from lldb/test/API/api/multithreaded/listener_test.cpp.template rename to lldb/test/API/api/multithreaded/listener_test.cpp index e305d1af4893f..f4f76c6071fb1 100644 --- a/lldb/test/API/api/multithreaded/listener_test.cpp.template +++ b/lldb/test/API/api/multithreaded/listener_test.cpp @@ -7,8 +7,13 @@ #include <thread> #include <vector> -%include_SB_APIs% #include "common.h" +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" using namespace lldb; using namespace std; @@ -17,7 +22,7 @@ void listener_func(); void check_listener(SBDebugger &dbg); // Listener thread and related variables -atomic<bool> g_done; +atomic<bool> g_done; SBListener g_listener("test-listener"); thread g_listener_thread; @@ -31,20 +36,18 @@ void test(SBDebugger &dbg, std::vector<string> args) { try { g_done.store(false); SBTarget target = dbg.CreateTarget(args.at(0).c_str()); - if (!target.IsValid()) throw Exception("invalid target"); + if (!target.IsValid()) + throw Exception("invalid target"); SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); - if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); + if (!breakpoint.IsValid()) + throw Exception("invalid breakpoint"); std::unique_ptr<char> working_dir(get_working_dir()); SBError error; - SBProcess process = target.Launch(g_listener, - 0, 0, 0, 0, 0, - working_dir.get(), - 0, - false, - 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."); diff --git a/lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp.template b/lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp similarity index 63% rename from lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp.template rename to lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp index 4133025aa495a..3b8e909cef434 100644 --- a/lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp.template +++ b/lldb/test/API/api/multithreaded/test_breakpoint_callback.cpp @@ -2,12 +2,17 @@ // LLDB C++ API Test: verify that the function registered with // SBBreakpoint.SetCallback() is invoked when a breakpoint is hit. -#include <mutex> #include <iostream> -#include <vector> +#include <mutex> #include <string> +#include <vector> -%include_SB_APIs% +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" #include "common.h" @@ -18,10 +23,8 @@ mutex g_mutex; condition_variable g_condition; int g_breakpoint_hit_count = 0; -bool BPCallback (void *baton, - SBProcess &process, - SBThread &thread, - SBBreakpointLocation &location) { +bool BPCallback(void *baton, SBProcess &process, SBThread &thread, + SBBreakpointLocation &location) { lock_guard<mutex> lock(g_mutex); g_breakpoint_hit_count += 1; g_condition.notify_all(); @@ -29,16 +32,18 @@ bool BPCallback (void *baton, } void test(SBDebugger &dbg, vector<string> args) { - dbg.SetAsync(false); + dbg.SetAsync(false); SBTarget target = dbg.CreateTarget(args.at(0).c_str()); - if (!target.IsValid()) throw Exception("invalid target"); + if (!target.IsValid()) + throw Exception("invalid target"); SBBreakpoint breakpoint = target.BreakpointCreateByName("next"); - if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); + if (!breakpoint.IsValid()) + throw Exception("invalid breakpoint"); breakpoint.SetCallback(BPCallback, 0); std::unique_ptr<char> working_dir(get_working_dir()); - SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); + SBProcess process = target.LaunchSimple(0, 0, working_dir.get()); { unique_lock<mutex> lock(g_mutex); diff --git a/lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template b/lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp similarity index 64% rename from lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template rename to lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp index a4bc65ab91331..eea3b9ed65f24 100644 --- a/lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template +++ b/lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp @@ -2,12 +2,19 @@ // LLDB C++ API Test: verify that the function registered with // SBBreakpoint.SetCallback() is invoked when a breakpoint is hit. -#include <mutex> #include <iostream> -#include <vector> +#include <mutex> #include <string> +#include <vector> -%include_SB_APIs% +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBFileSpecList.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" #include "common.h" @@ -18,10 +25,8 @@ mutex g_mutex; condition_variable g_condition; int g_breakpoint_hit_count = 0; -bool BPCallback (void *baton, - SBProcess &process, - SBThread &thread, - SBBreakpointLocation &location) { +bool BPCallback(void *baton, SBProcess &process, SBThread &thread, + SBBreakpointLocation &location) { lock_guard<mutex> lock(g_mutex); g_breakpoint_hit_count += 1; g_condition.notify_all(); @@ -31,7 +36,8 @@ bool BPCallback (void *baton, void test(SBDebugger &dbg, vector<string> args) { dbg.SetAsync(false); SBTarget target = dbg.CreateTarget(args.at(0).c_str()); - if (!target.IsValid()) throw Exception("invalid target"); + if (!target.IsValid()) + throw Exception("invalid target"); // Only look for the breakpoint in the main module. SBFileSpec main_module(args.at(0).c_str(), /*resolve=*/true); @@ -40,14 +46,16 @@ void test(SBDebugger &dbg, vector<string> args) { SBBreakpoint breakpoint = target.BreakpointCreateByName( "next", eFunctionNameTypeFull, module_list, SBFileSpecList()); - if (!breakpoint.IsValid()) throw Exception("invalid breakpoint"); + if (!breakpoint.IsValid()) + throw Exception("invalid breakpoint"); - if(breakpoint.GetNumLocations() != 1) throw Exception("unexpected amount of breakpoint locations"); + if (breakpoint.GetNumLocations() != 1) + throw Exception("unexpected amount of breakpoint locations"); SBBreakpointLocation breakpoint_location = breakpoint.GetLocationAtIndex(0); breakpoint_location.SetCallback(BPCallback, 0); std::unique_ptr<char> working_dir(get_working_dir()); - SBProcess process = target.LaunchSimple (0, 0, working_dir.get()); + SBProcess process = target.LaunchSimple(0, 0, working_dir.get()); { unique_lock<mutex> lock(g_mutex); diff --git a/lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp.template b/lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp similarity index 81% rename from lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp.template rename to lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp index e5101dde79619..72bac46fe46d5 100644 --- a/lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp.template +++ b/lldb/test/API/api/multithreaded/test_concurrent_unwind.cpp @@ -3,15 +3,23 @@ #include <atomic> #include <thread> -%include_SB_APIs% +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBLaunchInfo.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" #include "common.h" using namespace lldb; -void test (SBDebugger &dbg, std::vector<std::string> args) { +void test(SBDebugger &dbg, std::vector<std::string> args) { -SBError error; + SBError error; dbg.SetAsync(false); SBTarget target = dbg.CreateTarget(args.at(0).c_str()); if (!target.IsValid()) @@ -19,8 +27,8 @@ SBError error; // Now set our breakpoint and launch: SBFileSpec main_sourcefile("deep_stack.cpp"); - SBBreakpoint bkpt = target.BreakpointCreateBySourceRegex("Set a breakpoint here", - main_sourcefile); + SBBreakpoint bkpt = target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", main_sourcefile); if (bkpt.GetNumLocations() == 0) throw Exception("Main breakpoint got no locations"); @@ -44,7 +52,7 @@ SBError error; const size_t num_frames = cur_thread.GetNumFrames(); // Now step once to clear the frame cache: cur_thread.StepOver(); - + // Create three threads and set them to getting frames simultaneously, // and make sure we don't deadlock. pseudo_barrier_t rendevous; @@ -52,7 +60,7 @@ SBError error; std::atomic_size_t success(true); std::atomic_size_t largest(0); - auto lambda = [&](size_t stride){ + auto lambda = [&](size_t stride) { pseudo_barrier_wait(rendevous); bool younger = true; while (1) { @@ -72,7 +80,6 @@ SBError error; break; } } - }; std::thread thread1(lambda, 1); @@ -85,7 +92,7 @@ SBError error; thread3.join(); thread4.join(); thread5.join(); - + if (!success) throw Exception("One thread stopped before 1000"); } diff --git a/lldb/test/API/api/multithreaded/test_listener_event_description.cpp b/lldb/test/API/api/multithreaded/test_listener_event_description.cpp new file mode 100644 index 0000000000000..10faa59614898 --- /dev/null +++ b/lldb/test/API/api/multithreaded/test_listener_event_description.cpp @@ -0,0 +1,94 @@ + +// LLDB C++ API Test: verify the event description that is received by an +// SBListener object registered with a process with a breakpoint. + +#include <array> +#include <atomic> +#include <iostream> +#include <string> +#include <thread> + +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBStream.h" + +#include "common.h" + +using namespace lldb; +using namespace std; + +// listener thread control +extern atomic<bool> g_done; +extern SBListener g_listener; + +multithreaded_queue<string> 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/test/API/api/multithreaded/test_listener_event_description.cpp.template b/lldb/test/API/api/multithreaded/test_listener_event_description.cpp.template deleted file mode 100644 index 63e3f3631e5d2..0000000000000 --- a/lldb/test/API/api/multithreaded/test_listener_event_description.cpp.template +++ /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 <atomic> -#include <array> -#include <iostream> -#include <string> -#include <thread> - -%include_SB_APIs% - -#include "common.h" - -using namespace lldb; -using namespace std; - -// listener thread control -extern atomic<bool> g_done; -extern SBListener g_listener; - -multithreaded_queue<string> 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/test/API/api/multithreaded/test_listener_event_process_state.cpp b/lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp new file mode 100644 index 0000000000000..c3e705dbc439f --- /dev/null +++ b/lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp @@ -0,0 +1,72 @@ + +// 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 <atomic> +#include <iostream> +#include <string> +#include <thread> + +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBSymbol.h" +#include "lldb/API/SBThread.h" + +#include "common.h" + +using namespace lldb; +using namespace std; + +// listener thread control +extern atomic<bool> g_done; + +multithreaded_queue<string> 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/test/API/api/multithreaded/test_listener_event_process_state.cpp.template b/lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp.template deleted file mode 100644 index 2926ece4d8d92..0000000000000 --- a/lldb/test/API/api/multithreaded/test_listener_event_process_state.cpp.template +++ /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 <atomic> -#include <iostream> -#include <string> -#include <thread> - -%include_SB_APIs% - -#include "common.h" - -using namespace lldb; -using namespace std; - -// listener thread control -extern atomic<bool> g_done; - -multithreaded_queue<string> 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/test/API/api/multithreaded/test_listener_resume.cpp.template b/lldb/test/API/api/multithreaded/test_listener_resume.cpp similarity index 80% rename from lldb/test/API/api/multithreaded/test_listener_resume.cpp.template rename to lldb/test/API/api/multithreaded/test_listener_resume.cpp index 4adc9b3388793..8854209546c6e 100644 --- a/lldb/test/API/api/multithreaded/test_listener_resume.cpp.template +++ b/lldb/test/API/api/multithreaded/test_listener_resume.cpp @@ -8,7 +8,11 @@ #include <string> #include <thread> -%include_SB_APIs% +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" #include "common.h" @@ -37,8 +41,9 @@ void listener_func() { if (process.GetState() == eStateStopped) { SBError error = process.Continue(); if (!error.Success()) - throw Exception(string("Cannot continue process from listener thread: ") - + error.GetCString()); + throw Exception( + string("Cannot continue process from listener thread: ") + + error.GetCString()); g_process_started.push(true); } } diff --git a/lldb/test/API/api/multithreaded/test_stop-hook.cpp.template b/lldb/test/API/api/multithreaded/test_stop-hook.cpp similarity index 86% rename from lldb/test/API/api/multithreaded/test_stop-hook.cpp.template rename to lldb/test/API/api/multithreaded/test_stop-hook.cpp index 393e717cceb5a..a88892340e613 100644 --- a/lldb/test/API/api/multithreaded/test_stop-hook.cpp.template +++ b/lldb/test/API/api/multithreaded/test_stop-hook.cpp @@ -2,13 +2,23 @@ // is set to a FILE *, lldb can still successfully run a // python command in a stop hook. +#include <cstdlib> #include <errno.h> #include <mutex> #include <stdio.h> #include <string> #include <vector> -%include_SB_APIs% +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBBroadcaster.h" +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" #include "common.h" @@ -44,7 +54,11 @@ void test(SBDebugger &dbg, std::vector<std::string> args) { // one that runs in the stop hook and sets a variable when it // runs, and one that reports out the variable so we can ensure // that we did indeed run the stop hook. - const char *source_dir = "%SOURCE_DIR%"; + // The test sets LLDB_TEST_SOURCE_DIR to the directory containing this + // test's support files (see TestMultithreaded.py). + const char *source_dir = getenv("LLDB_TEST_SOURCE_DIR"); + if (!source_dir) + throw Exception("LLDB_TEST_SOURCE_DIR is not set"); SBFileSpec script_spec(source_dir); script_spec.AppendPathComponent("some_cmd.py"); char path[PATH_MAX]; @@ -54,7 +68,7 @@ void test(SBDebugger &dbg, std::vector<std::string> args) { import_command.append(path); interp.HandleCommand(import_command.c_str(), result); if (!result.Succeeded()) - throw Exception("Couldn't import %SOURCE_DIR%/some_cmd.py"); + throw Exception(std::string("Couldn't import ") + path); SBProcess process = target.LaunchSimple(nullptr, nullptr, nullptr); if (!process.IsValid()) _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
