diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/breakpoint')
13 files changed, 402 insertions, 15 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py index c0c2267a8362..871363b7aed3 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py @@ -45,14 +45,6 @@ class BreakpointOptionsTestCase(TestBase): extra_options="-K 0", num_expected_locations=1) - # This should create a breakpoint 0 locations. - lldbutil.run_break_set_by_file_and_line( - self, - "main.cpp", - self.line, - extra_options="-m 0", - num_expected_locations=0) - # Run the program. self.runCmd("run", RUN_SUCCEEDED) @@ -68,8 +60,6 @@ class BreakpointOptionsTestCase(TestBase): "1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.line, "2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % - self.line, - "3: file = 'main.cpp', line = %d, exact_match = 1, locations = 0" % self.line]) # Continue the program, there should be another stop. diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp index 363b90003d76..b2e8f523c84d 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_options/main.cpp @@ -1,8 +1,4 @@ -// Set break point at this line. - extern "C" int foo(void); -int -main (int argc, char **argv) -{ +int main (int argc, char **argv) { // Set break point at this line. return foo(); } diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile new file mode 100644 index 000000000000..3665ae323e7b --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../../make + +ENABLE_THREADS := YES +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py new file mode 100644 index 000000000000..21fe084d3dfb --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/TestHWBreakMultiThread.py @@ -0,0 +1,114 @@ +""" +Test hardware breakpoints for multiple threads. +""" + +from __future__ import print_function + + +import os +import time +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +# Hardware breakpoints are supported only by platforms mentioned in oslist. +@skipUnlessPlatform(oslist=['linux']) +class HardwareBreakpointMultiThreadTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + mydir = TestBase.compute_mydir(__file__) + + # LLDB supports hardware breakpoints for arm and aarch64 architectures. + @skipIf(archs=no_match(['arm', 'aarch64'])) + @expectedFailureAndroid + def test_hw_break_set_delete_multi_thread(self): + self.build() + self.setTearDownCleanup() + self.break_multi_thread('delete') + + # LLDB supports hardware breakpoints for arm and aarch64 architectures. + @skipIf(archs=no_match(['arm', 'aarch64'])) + @expectedFailureAndroid + def test_hw_break_set_disable_multi_thread(self): + self.build() + self.setTearDownCleanup() + self.break_multi_thread('disable') + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.first_stop = line_number( + self.source, 'Starting thread creation with hardware breakpoint set') + + def break_multi_thread(self, removal_type): + """Test that lldb hardware breakpoints work for multiple threads.""" + self.runCmd( + "file %s" % + os.path.join( + os.getcwd(), + 'a.out'), + CURRENT_EXECUTABLE_SET) + + # Stop in main before creating any threads. + lldbutil.run_break_set_by_file_and_line( + self, None, self.first_stop, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # Now set a hardware breakpoint in thread function. + self.expect("breakpoint set -b hw_break_function --hardware", + substrs=[ + 'Breakpoint', + 'hw_break_function', + 'address = 0x']) + + # We should stop in hw_break_function function for 4 threads. + count = 0 + + while count < 2 : + + self.runCmd("process continue") + + # We should be stopped in hw_break_function + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=[ + 'stop reason = breakpoint', + 'hw_break_function']) + + # Continue the loop and test that we are stopped 4 times. + count += 1 + + if removal_type == 'delete': + self.runCmd("settings set auto-confirm true") + + # Now 'breakpoint delete' should just work fine without confirmation + # prompt from the command interpreter. + self.expect("breakpoint delete", + startstr="All breakpoints removed") + + # Restore the original setting of auto-confirm. + self.runCmd("settings clear auto-confirm") + + elif removal_type == 'disable': + self.expect("breakpoint disable", + startstr="All breakpoints disabled.") + + # Continue. Program should exit without stopping anywhere. + self.runCmd("process continue") + + # Process should have stopped and exited with status = 0 + self.expect("process status", PROCESS_STOPPED, + patterns=['Process .* exited with status = 0']) diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp new file mode 100644 index 000000000000..d13393095c61 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/hardware_breakpoints/hardware_breakpoint_on_multiple_threads/main.cpp @@ -0,0 +1,51 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <chrono> +#include <cstdio> +#include <mutex> +#include <random> +#include <thread> + +#define NUM_OF_THREADS 4 + +std::mutex hw_break_mutex; + +void +hw_break_function (uint32_t thread_index) { + printf ("%s called by Thread #%u...\n", __FUNCTION__, thread_index); +} + + +void +thread_func (uint32_t thread_index) { + printf ("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index); + + hw_break_mutex.lock(); + + hw_break_function(thread_index); // Call hw_break_function + + hw_break_mutex.unlock(); +} + + +int main (int argc, char const *argv[]) +{ + std::thread threads[NUM_OF_THREADS]; + + printf ("Starting thread creation with hardware breakpoint set...\n"); + + for (auto &thread : threads) + thread = std::thread{thread_func, std::distance(threads, &thread)}; + + for (auto &thread : threads) + thread.join(); + + return 0; +} diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile new file mode 100644 index 000000000000..e7a1cab7e195 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../make + +DYLIB_NAME := foo +DYLIB_CXX_SOURCES := foo.cpp +CXX_SOURCES := main.cpp +CFLAGS_EXTRAS += -fPIC + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py new file mode 100644 index 000000000000..26041c313e57 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/TestMoveNearest.py @@ -0,0 +1,63 @@ +from __future__ import print_function + + +import unittest2 +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestMoveNearest(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line1 = line_number('foo.h', '// !BR1') + self.line2 = line_number('foo.h', '// !BR2') + self.line_main = line_number('main.cpp', '// !BR_main') + + def test(self): + """Test target.move-to-nearest logic""" + + self.build() + target = self.dbg.CreateTarget("a.out") + self.assertTrue(target, VALID_TARGET) + + lldbutil.run_break_set_by_symbol(self, 'main', sym_exact=True) + environment = self.registerSharedLibrariesWithTarget(target, ["foo"]) + process = target.LaunchSimple(None, environment, self.get_process_working_directory()) + self.assertEquals(process.GetState(), lldb.eStateStopped) + + # Regardless of the -m value the breakpoint should have exactly one + # location on the foo functions + self.runCmd("settings set target.move-to-nearest-code true") + lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1, + loc_exact=True, extra_options="-m 1") + lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2, + loc_exact=True, extra_options="-m 1") + + self.runCmd("settings set target.move-to-nearest-code false") + lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1, + loc_exact=True, extra_options="-m 0") + lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2, + loc_exact=True, extra_options="-m 0") + + + # Make sure we set a breakpoint in main with -m 1 for various lines in + # the function declaration + # "int" + lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', + self.line_main-1, extra_options="-m 1") + # "main()" + lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', + self.line_main, extra_options="-m 1") + # "{" + lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', + self.line_main+1, extra_options="-m 1") + # "return .." + lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', + self.line_main+2, extra_options="-m 1") diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp new file mode 100644 index 000000000000..8dad0a23f368 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.cpp @@ -0,0 +1,3 @@ +#include "foo.h" + +int call_foo1() { return foo1(); } diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h new file mode 100644 index 000000000000..060b91f5a5ea --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/foo.h @@ -0,0 +1,6 @@ +LLDB_TEST_API inline int foo1() { return 1; } // !BR1 + +LLDB_TEST_API inline int foo2() { return 2; } // !BR2 + +LLDB_TEST_API extern int call_foo1(); +LLDB_TEST_API extern int call_foo2(); diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp new file mode 100644 index 000000000000..c9295a5c7d3c --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/move_nearest/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" + +int call_foo2() { return foo2(); } + +int +main() // !BR_main +{ + return call_foo1() + call_foo2(); +} diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile new file mode 100644 index 000000000000..f89b52a972e9 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/Makefile @@ -0,0 +1,9 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +ifneq (,$(findstring icc,$(CC))) + CXXFLAGS += -debug inline-debug-info +endif + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py new file mode 100644 index 000000000000..00ddc628607c --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py @@ -0,0 +1,120 @@ +""" +Test that breakpoints do not affect stepping. +Check for correct StopReason when stepping to the line with breakpoint +which chould be eStopReasonBreakpoint in general, +and eStopReasonPlanComplete when breakpoint's condition fails. +""" + +from __future__ import print_function + +import unittest2 +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class StepOverBreakpointsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + self.build() + exe = os.path.join(os.getcwd(), "a.out") + src = lldb.SBFileSpec("main.cpp") + + # Create a target by the debugger. + self.target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + + # Setup four breakpoints, two of them with false condition + self.line1 = line_number('main.cpp', "breakpoint_1") + self.line4 = line_number('main.cpp', "breakpoint_4") + + self.breakpoint1 = self.target.BreakpointCreateByLocation(src, self.line1) + self.assertTrue( + self.breakpoint1 and self.breakpoint1.GetNumLocations() == 1, + VALID_BREAKPOINT) + + self.breakpoint2 = self.target.BreakpointCreateBySourceRegex("breakpoint_2", src) + self.breakpoint2.GetLocationAtIndex(0).SetCondition('false') + + self.breakpoint3 = self.target.BreakpointCreateBySourceRegex("breakpoint_3", src) + self.breakpoint3.GetLocationAtIndex(0).SetCondition('false') + + self.breakpoint4 = self.target.BreakpointCreateByLocation(src, self.line4) + + # Start debugging + self.process = self.target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertIsNotNone(self.process, PROCESS_IS_VALID) + self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint1) + self.assertIsNotNone(self.thread, "Didn't stop at breakpoint 1.") + + def test_step_instruction(self): + # Count instructions between breakpoint_1 and breakpoint_4 + contextList = self.target.FindFunctions('main', lldb.eFunctionNameTypeAuto) + self.assertEquals(contextList.GetSize(), 1) + symbolContext = contextList.GetContextAtIndex(0) + function = symbolContext.GetFunction() + self.assertTrue(function) + instructions = function.GetInstructions(self.target) + addr_1 = self.breakpoint1.GetLocationAtIndex(0).GetAddress() + addr_4 = self.breakpoint4.GetLocationAtIndex(0).GetAddress() + for i in range(instructions.GetSize()) : + addr = instructions.GetInstructionAtIndex(i).GetAddress() + if (addr == addr_1) : index_1 = i + if (addr == addr_4) : index_4 = i + + steps_expected = index_4 - index_1 + step_count = 0 + # Step from breakpoint_1 to breakpoint_4 + while True: + self.thread.StepInstruction(True) + step_count = step_count + 1 + self.assertEquals(self.process.GetState(), lldb.eStateStopped) + self.assertTrue(self.thread.GetStopReason() == lldb.eStopReasonPlanComplete or + self.thread.GetStopReason() == lldb.eStopReasonBreakpoint) + if (self.thread.GetStopReason() == lldb.eStopReasonBreakpoint) : + # we should not stop on breakpoint_2 and _3 because they have false condition + self.assertEquals(self.thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), self.line4) + # breakpoint_2 and _3 should not affect step count + self.assertTrue(step_count >= steps_expected) + break + + # Run the process until termination + self.process.Continue() + self.assertEquals(self.process.GetState(), lldb.eStateExited) + + @skipIf(bugnumber="llvm.org/pr31972", hostoslist=["windows"]) + def test_step_over(self): + #lldb.DBG.EnableLog("lldb", ["step","breakpoint"]) + + self.thread.StepOver() + # We should be stopped at the breakpoint_2 line with stop plan complete reason + self.assertEquals(self.process.GetState(), lldb.eStateStopped) + self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete) + + self.thread.StepOver() + # We should be stopped at the breakpoint_3 line with stop plan complete reason + self.assertEquals(self.process.GetState(), lldb.eStateStopped) + self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete) + + self.thread.StepOver() + # We should be stopped at the breakpoint_4 + self.assertEquals(self.process.GetState(), lldb.eStateStopped) + self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonBreakpoint) + thread1 = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint4) + self.assertEquals(self.thread, thread1, "Didn't stop at breakpoint 4.") + + # Check that stepping does not affect breakpoint's hit count + self.assertEquals(self.breakpoint1.GetHitCount(), 1) + self.assertEquals(self.breakpoint2.GetHitCount(), 0) + self.assertEquals(self.breakpoint3.GetHitCount(), 0) + self.assertEquals(self.breakpoint4.GetHitCount(), 1) + + # Run the process until termination + self.process.Continue() + self.assertEquals(self.process.GetState(), lldb.eStateExited) + diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp new file mode 100644 index 000000000000..8cfd34b73b55 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/step_over_breakpoint/main.cpp @@ -0,0 +1,12 @@ + +int func() { return 1; } + +int +main(int argc, char const *argv[]) +{ + int a = 0; // breakpoint_1 + int b = func(); // breakpoint_2 + a = b + func(); // breakpoint_3 + return 0; // breakpoint_4 +} + |
