From 14f1b3e8826ce43b978db93a62d1166055db5394 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:26:05 +0000 Subject: Vendor import of lldb trunk r290819: https://llvm.org/svn/llvm-project/lldb/trunk@290819 --- .../TestPublicAPIHeaders.py | 57 ++++--------- .../lldbsuite/test/api/listeners/TestListener.py | 38 ++++++--- .../multiple-debuggers/TestMultipleDebuggers.py | 22 +++-- .../multiple-debuggers/multi-process-driver.cpp | 2 +- .../lldbsuite/test/api/multiple-targets/Makefile | 8 ++ .../api/multiple-targets/TestMultipleTargets.py | 44 ++++++++++ .../lldbsuite/test/api/multiple-targets/main.cpp | 31 +++++++ .../test/api/multithreaded/TestMultithreaded.py | 49 +++++++---- .../lldbsuite/test/api/multithreaded/driver.cpp | 38 --------- .../test/api/multithreaded/driver.cpp.template | 48 +++++++++++ .../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 | 58 ------------- .../test_listener_event_process_state.cpp.template | 63 ++++++++++++++ .../api/multithreaded/test_listener_resume.cpp | 53 ------------ .../test_listener_resume.cpp.template | 53 ++++++++++++ 21 files changed, 561 insertions(+), 454 deletions(-) create mode 100644 packages/Python/lldbsuite/test/api/multiple-targets/Makefile create mode 100644 packages/Python/lldbsuite/test/api/multiple-targets/TestMultipleTargets.py create mode 100644 packages/Python/lldbsuite/test/api/multiple-targets/main.cpp delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/driver.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template delete mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp create mode 100644 packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template (limited to 'packages/Python/lldbsuite/test/api') diff --git a/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py b/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py index 0ed2df3ceab17..dd6dbe0a37ed8 100644 --- a/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py +++ b/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py @@ -6,21 +6,22 @@ should compile and link with the LLDB framework.""" from __future__ import print_function - -import os, re +import os +import re from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class SBDirCheckerCase(TestBase): mydir = TestBase.compute_mydir(__file__) def setUp(self): TestBase.setUp(self) - self.template = 'main.cpp.template' self.source = 'main.cpp' self.exe_name = 'a.out' + self.generateSource(self.source) @skipIfNoSBHeaders def test_sb_api_directory(self): @@ -30,60 +31,38 @@ class SBDirCheckerCase(TestBase): if not (self.platformIsDarwin() and self.getArchitecture() == "x86_64"): self.skipTest("This test is only for LLDB.framework built 64-bit") if self.getArchitecture() == "i386": - self.skipTest("LLDB is 64-bit and cannot be linked to 32-bit test program.") + self.skipTest( + "LLDB is 64-bit and cannot be linked to 32-bit test program.") - # Generate main.cpp, build it, and execute. - self.generate_main_cpp() self.buildDriver(self.source, self.exe_name) self.sanity_check_executable(self.exe_name) - def generate_main_cpp(self): - """Generate main.cpp from main.cpp.template.""" - temp = os.path.join(os.getcwd(), self.template) - with open(temp, 'r') as f: - content = f.read() - - public_api_dir = os.path.join(os.environ["LLDB_SRC"], "include", "lldb", "API") - - # Look under the include/lldb/API directory and add #include statements - # for all the SB API headers. - public_headers = os.listdir(public_api_dir) - # For different platforms, the include statement can vary. - if self.platformIsDarwin(): - include_stmt = "'#include <%s>' % os.path.join('LLDB', header)" - if self.getPlatform() == "freebsd" or self.getPlatform() == "linux" or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile': - include_stmt = "'#include <%s>' % os.path.join(public_api_dir, header)" - list = [eval(include_stmt) for header in public_headers if (header.startswith("SB") and - header.endswith(".h"))] - includes = '\n'.join(list) - new_content = content.replace('%include_SB_APIs%', includes) - src = os.path.join(os.getcwd(), self.source) - with open(src, 'w') as f: - f.write(new_content) - - # The main.cpp has been generated, add a teardown hook to remove it. - self.addTearDownHook(lambda: os.remove(src)) - def sanity_check_executable(self, exe_name): """Sanity check executable compiled from the auto-generated program.""" exe = os.path.join(os.getcwd(), exe_name) self.runCmd("file %s" % exe, CURRENT_EXECUTABLE_SET) - self.line_to_break = line_number(self.source, '// Set breakpoint here.') + self.line_to_break = line_number( + self.source, '// Set breakpoint here.') - env_cmd = "settings set target.env-vars %s=%s" %(self.dylibPath, self.getLLDBLibraryEnvVal()) + env_cmd = "settings set target.env-vars %s=%s" % ( + self.dylibPath, self.getLLDBLibraryEnvVal()) if self.TraceOn(): print("Set environment to: ", env_cmd) self.runCmd(env_cmd) - self.addTearDownHook(lambda: self.dbg.HandleCommand("settings remove target.env-vars %s" % self.dylibPath)) + self.addTearDownHook( + lambda: self.dbg.HandleCommand( + "settings remove target.env-vars %s" % + self.dylibPath)) - lldbutil.run_break_set_by_file_and_line (self, self.source, self.line_to_break, num_expected_locations = -1) + lldbutil.run_break_set_by_file_and_line( + self, self.source, self.line_to_break, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - 'stop reason = breakpoint']) + substrs=['stopped', + 'stop reason = breakpoint']) self.runCmd('frame variable') diff --git a/packages/Python/lldbsuite/test/api/listeners/TestListener.py b/packages/Python/lldbsuite/test/api/listeners/TestListener.py index bd8c204e78cb5..65232f0141026 100644 --- a/packages/Python/lldbsuite/test/api/listeners/TestListener.py +++ b/packages/Python/lldbsuite/test/api/listeners/TestListener.py @@ -15,6 +15,7 @@ from lldbsuite.test import lldbutil import six + class ListenToModuleLoadedEvents (TestBase): mydir = TestBase.compute_mydir(__file__) @@ -24,14 +25,17 @@ class ListenToModuleLoadedEvents (TestBase): TestBase.setUp(self) self.build() - def test_receiving_breakpoint_added (self): + def test_receiving_breakpoint_added(self): """Test that we get breakpoint added events, waiting on event classes on the debugger""" my_listener = lldb.SBListener("test_listener") - - my_listener.StartListeningForEventClass(self.dbg, lldb.SBTarget.GetBroadcasterClassName(), lldb.SBTarget.eBroadcastBitBreakpointChanged) - exe = os.path.join (os.getcwd(), "a.out") + my_listener.StartListeningForEventClass( + self.dbg, + lldb.SBTarget.GetBroadcasterClassName(), + lldb.SBTarget.eBroadcastBitBreakpointChanged) + + exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) @@ -39,17 +43,29 @@ class ListenToModuleLoadedEvents (TestBase): event = lldb.SBEvent() my_listener.WaitForEvent(1, event) - + self.assertTrue(event.IsValid(), "Got a valid event.") - self.assertTrue(lldb.SBBreakpoint.EventIsBreakpointEvent(event), "It is a breakpoint event.") - self.assertTrue(lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event) == lldb.eBreakpointEventTypeAdded, "It is a breakpoint added event.") - self.assertTrue(bkpt == lldb.SBBreakpoint.GetBreakpointFromEvent(event), "It is our breakpoint.") + self.assertTrue( + lldb.SBBreakpoint.EventIsBreakpointEvent(event), + "It is a breakpoint event.") + self.assertTrue(lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent( + event) == lldb.eBreakpointEventTypeAdded, "It is a breakpoint added event.") + self.assertTrue( + bkpt == lldb.SBBreakpoint.GetBreakpointFromEvent(event), + "It is our breakpoint.") # Now make sure if we stop listening for events we don't get them: - my_listener.StopListeningForEventClass(self.dbg, lldb.SBTarget.GetBroadcasterClassName(), lldb.SBTarget.eBroadcastBitBreakpointChanged) - my_listener.StopListeningForEvents(target.GetBroadcaster(), lldb.SBTarget.eBroadcastBitBreakpointChanged) + my_listener.StopListeningForEventClass( + self.dbg, + lldb.SBTarget.GetBroadcasterClassName(), + lldb.SBTarget.eBroadcastBitBreakpointChanged) + my_listener.StopListeningForEvents( + target.GetBroadcaster(), + lldb.SBTarget.eBroadcastBitBreakpointChanged) bkpt2 = target.BreakpointCreateByName("main") my_listener.WaitForEvent(1, event) - self.assertTrue(not event.IsValid(), "We don't get events we aren't listening to.") + self.assertTrue( + not event.IsValid(), + "We don't get events we aren't listening to.") diff --git a/packages/Python/lldbsuite/test/api/multiple-debuggers/TestMultipleDebuggers.py b/packages/Python/lldbsuite/test/api/multiple-debuggers/TestMultipleDebuggers.py index ca2b986ce740e..20e41f0f4121a 100644 --- a/packages/Python/lldbsuite/test/api/multiple-debuggers/TestMultipleDebuggers.py +++ b/packages/Python/lldbsuite/test/api/multiple-debuggers/TestMultipleDebuggers.py @@ -3,8 +3,8 @@ from __future__ import print_function - -import os, re +import os +import re import subprocess import lldb @@ -12,16 +12,23 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestMultipleSimultaneousDebuggers(TestBase): mydir = TestBase.compute_mydir(__file__) @skipIfNoSBHeaders - @expectedFlakeyDarwin() - @expectedFailureAll(archs="i[3-6]86", bugnumber="multi-process-driver.cpp creates an x64 target") - @expectedFailureAll(oslist=["windows", "linux", "freebsd"], bugnumber="llvm.org/pr20282") + @expectedFailureAll( + archs="i[3-6]86", + bugnumber="multi-process-driver.cpp creates an x64 target") + @expectedFailureAll( + oslist=[ + "windows", + "linux", + "freebsd"], + bugnumber="llvm.org/pr20282") def test_multiple_debuggers(self): - env = {self.dylibPath : self.getLLDBLibraryEnvVal()} + env = {self.dylibPath: self.getLLDBLibraryEnvVal()} self.driver_exe = os.path.join(os.getcwd(), "multi-process-driver") self.buildDriver('multi-process-driver.cpp', self.driver_exe) @@ -41,4 +48,5 @@ class TestMultipleSimultaneousDebuggers(TestBase): check_call([self.driver_exe, self.inferior_exe], env=env) else: with open(os.devnull, 'w') as fnull: - check_call([self.driver_exe, self.inferior_exe], env=env, stdout=fnull, stderr=fnull) + check_call([self.driver_exe, self.inferior_exe], + env=env, stdout=fnull, stderr=fnull) diff --git a/packages/Python/lldbsuite/test/api/multiple-debuggers/multi-process-driver.cpp b/packages/Python/lldbsuite/test/api/multiple-debuggers/multi-process-driver.cpp index 1c2689ff6c4f6..448304d83c75b 100644 --- a/packages/Python/lldbsuite/test/api/multiple-debuggers/multi-process-driver.cpp +++ b/packages/Python/lldbsuite/test/api/multiple-debuggers/multi-process-driver.cpp @@ -25,7 +25,7 @@ #include #include -#define NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS 20 +#define NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS 10 #define DEBUG 0 diff --git a/packages/Python/lldbsuite/test/api/multiple-targets/Makefile b/packages/Python/lldbsuite/test/api/multiple-targets/Makefile new file mode 100644 index 0000000000000..bee559c8ecdd1 --- /dev/null +++ b/packages/Python/lldbsuite/test/api/multiple-targets/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../make + +MAKE_DSYM := NO + +ENABLE_THREADS := YES +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/api/multiple-targets/TestMultipleTargets.py b/packages/Python/lldbsuite/test/api/multiple-targets/TestMultipleTargets.py new file mode 100644 index 0000000000000..decb3fd4f0c59 --- /dev/null +++ b/packages/Python/lldbsuite/test/api/multiple-targets/TestMultipleTargets.py @@ -0,0 +1,44 @@ +"""Test the lldb public C++ api when creating multiple targets simultaneously.""" + +from __future__ import print_function + + +import os +import re +import subprocess + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestMultipleTargets(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @skipIfNoSBHeaders + @skipIfHostIncompatibleWithRemote + @expectedFailureAll( + oslist=["windows", "freebsd"], + bugnumber="llvm.org/pr20282") + def test_multiple_targets(self): + env = {self.dylibPath: self.getLLDBLibraryEnvVal()} + + self.driver_exe = os.path.join(os.getcwd(), "multi-target") + self.buildDriver('main.cpp', self.driver_exe) + self.addTearDownHook(lambda: os.remove(self.driver_exe)) + self.signBinary(self.driver_exe) + +# check_call will raise a CalledProcessError if multi-process-driver 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. + + if self.TraceOn(): + print("Running test %s" % self.driver_exe) + check_call([self.driver_exe, self.driver_exe], env=env) + else: + with open(os.devnull, 'w') as fnull: + check_call([self.driver_exe, self.driver_exe], + env=env, stdout=fnull, stderr=fnull) diff --git a/packages/Python/lldbsuite/test/api/multiple-targets/main.cpp b/packages/Python/lldbsuite/test/api/multiple-targets/main.cpp new file mode 100644 index 0000000000000..35fb4e0d613ed --- /dev/null +++ b/packages/Python/lldbsuite/test/api/multiple-targets/main.cpp @@ -0,0 +1,31 @@ +#include + +#include "lldb/API/LLDB.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" + +using namespace lldb; +int main (int argc, char **argv) +{ + // We are expecting the program path and a path to an executable to load + if (argc != 2) + return 1; + const char *program_file = argv[1]; + SBDebugger::Initialize(); + SBDebugger debugger = SBDebugger::Create(false); + auto lambda = [&](){ + SBError error; + SBTarget target = debugger.CreateTarget(program_file, nullptr, nullptr, + false, error); + }; + + // Create 3 targets at the same time and make sure we don't crash. + std::thread thread1(lambda); + std::thread thread2(lambda); + std::thread thread3(lambda); + thread1.join(); + thread2.join(); + thread3.join(); + SBDebugger::Terminate(); + return 0; +} diff --git a/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py b/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py index 7959bb73de020..0d6a6002d5221 100644 --- a/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py +++ b/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py @@ -5,19 +5,31 @@ from __future__ import print_function # __package__ = "lldbsuite.test" -import os, re +import os +import re from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil 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 @skipIfNoSBHeaders - @skipIfWindows # clang-cl does not support throw or catch (llvm.org/pr24538) + # clang-cl does not support throw or catch (llvm.org/pr24538) + @skipIfWindows def test_breakpoint_callback(self): """Test the that SBBreakpoint callback is invoked when a breakpoint is hit. """ self.build_and_test('driver.cpp test_breakpoint_callback.cpp', @@ -25,40 +37,44 @@ class SBBreakpointCallbackCase(TestBase): @skipIfRemote @skipIfNoSBHeaders - @skipIfWindows # clang-cl does not support throw or catch (llvm.org/pr24538) + # clang-cl does not support throw or catch (llvm.org/pr24538) + @skipIfWindows @expectedFlakeyFreeBSD def test_sb_api_listener_event_description(self): """ Test the description of an SBListener breakpoint event is valid.""" - self.build_and_test('driver.cpp listener_test.cpp test_listener_event_description.cpp', - 'test_listener_event_description') + self.build_and_test( + 'driver.cpp listener_test.cpp test_listener_event_description.cpp', + 'test_listener_event_description') pass @skipIfRemote @skipIfNoSBHeaders - @skipIfWindows # clang-cl does not support throw or catch (llvm.org/pr24538) + # clang-cl does not support throw or catch (llvm.org/pr24538) + @skipIfWindows @expectedFlakeyFreeBSD - @expectedFailureAll("llvm.org/pr23139", oslist=["linux"], compiler="gcc", compiler_version=[">=","4.9"], archs=["x86_64"]) def test_sb_api_listener_event_process_state(self): """ Test that a registered SBListener receives events when a process changes state. """ - self.build_and_test('driver.cpp listener_test.cpp test_listener_event_process_state.cpp', - 'test_listener_event_process_state') + self.build_and_test( + 'driver.cpp listener_test.cpp test_listener_event_process_state.cpp', + 'test_listener_event_process_state') pass - @skipIfRemote @skipIfNoSBHeaders - @skipIfWindows # clang-cl does not support throw or catch (llvm.org/pr24538) + # clang-cl does not support throw or catch (llvm.org/pr24538) + @skipIfWindows @expectedFlakeyFreeBSD @expectedFailureAll(oslist=["linux"]) def test_sb_api_listener_resume(self): """ Test that a process can be resumed from a non-main thread. """ - self.build_and_test('driver.cpp listener_test.cpp test_listener_resume.cpp', - 'test_listener_resume') + self.build_and_test( + 'driver.cpp listener_test.cpp test_listener_resume.cpp', + 'test_listener_resume') pass - def build_and_test(self, sources, test_name, args = None): + def build_and_test(self, sources, test_name, args=None): """ Build LLDB test from sources, and run expecting 0 exit code """ # These tests link against host lldb API. @@ -66,7 +82,8 @@ class SBBreakpointCallbackCase(TestBase): # because remote is disabled, we can assume that the os is the same # still need to check architecture if self.getLldbArchitecture() != self.getArchitecture(): - self.skipTest("This test is only run if the target arch is the same as the lldb binary arch") + self.skipTest( + "This test is only run if the target arch is the same as the lldb binary arch") self.inferior = 'inferior_program' self.buildProgram('inferior.cpp', self.inferior) @@ -79,7 +96,7 @@ class SBBreakpointCallbackCase(TestBase): self.signBinary(test_exe) exe = [test_exe, self.inferior] - env = {self.dylibPath : self.getLLDBLibraryEnvVal()} + env = {self.dylibPath: self.getLLDBLibraryEnvVal()} if self.TraceOn(): print("Running test %s" % " ".join(exe)) check_call(exe, env=env) diff --git a/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp b/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp deleted file mode 100644 index fa0c48e0ecfbe..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template new file mode 100644 index 0000000000000..f4bd021632cec --- /dev/null +++ b/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template @@ -0,0 +1,48 @@ + +/// LLDB C API Test Driver + +#include +#include +#include +#include +#include +#if !defined(_MSC_VER) + #include +#endif + +%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) { + +// Ignore SIGPIPE. The lldb driver does this as well, +// because we seem to get spurious SIGPIPES on some +// Unixen that take the driver down. +#if !defined(_MSC_VER) + signal(SIGPIPE, SIG_IGN); +#endif + 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/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp b/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp deleted file mode 100644 index b20868ff94f4a..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template new file mode 100644 index 0000000000000..e305d1af4893f --- /dev/null +++ b/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/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h b/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h deleted file mode 100644 index da0914b3b0716..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp b/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp deleted file mode 100644 index def31f82b0c7a..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template new file mode 100644 index 0000000000000..4133025aa495a --- /dev/null +++ b/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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp deleted file mode 100644 index 0d7844dce6d09..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template new file mode 100644 index 0000000000000..63e3f3631e5d2 --- /dev/null +++ b/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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp deleted file mode 100644 index a79c5cb2a08bc..0000000000000 --- a/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp +++ /dev/null @@ -1,58 +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); - 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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template new file mode 100644 index 0000000000000..2926ece4d8d92 --- /dev/null +++ b/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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp deleted file mode 100644 index 8cf786b116033..0000000000000 --- a/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/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template b/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template new file mode 100644 index 0000000000000..4adc9b3388793 --- /dev/null +++ b/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