diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-09-10 12:04:04 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-09-10 12:04:04 +0000 |
commit | d9442afba1bd65fd0b5c93b67922eaed923445e2 (patch) | |
tree | 4cf657a31d92a6a17d07dd8a81e85bd00fe22d39 /lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize | |
parent | 3729b17cff53b536d2019b2d4c90e2a6f17754d1 (diff) | |
download | bcm5719-llvm-d9442afba1bd65fd0b5c93b67922eaed923445e2.tar.gz bcm5719-llvm-d9442afba1bd65fd0b5c93b67922eaed923445e2.zip |
[lldb] Readd missing functionalities/breakpoint tests
It seems when I restructured the test folders the functionalities/breakpoint
was deleted. This just reverts this change and re-adds the tests.
llvm-svn: 371512
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize')
3 files changed, 349 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py new file mode 100644 index 00000000000..086203ec54a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/TestBreakpointSerialization.py @@ -0,0 +1,291 @@ +""" +Test breakpoint serialization. +""" + +from __future__ import print_function + + +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class BreakpointSerialization(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @add_test_categories(['pyapi']) + def test_resolvers(self): + """Use Python APIs to test that we serialize resolvers.""" + self.build() + self.setup_targets_and_cleanup() + self.do_check_resolvers() + + def test_filters(self): + """Use Python APIs to test that we serialize search filters correctly.""" + self.build() + self.setup_targets_and_cleanup() + self.do_check_filters() + + def test_options(self): + """Use Python APIs to test that we serialize breakpoint options correctly.""" + self.build() + self.setup_targets_and_cleanup() + self.do_check_options() + + def test_appending(self): + """Use Python APIs to test that we serialize breakpoint options correctly.""" + self.build() + self.setup_targets_and_cleanup() + self.do_check_appending() + + def test_name_filters(self): + """Use python APIs to test that reading in by name works correctly.""" + self.build() + self.setup_targets_and_cleanup() + self.do_check_names() + + def setup_targets_and_cleanup(self): + def cleanup (): + self.RemoveTempFile(self.bkpts_file_path) + + if self.orig_target.IsValid(): + self.dbg.DeleteTarget(self.orig_target) + self.dbg.DeleteTarget(self.copy_target) + + self.addTearDownHook(cleanup) + self.RemoveTempFile(self.bkpts_file_path) + + exe = self.getBuildArtifact("a.out") + + # Create the targets we are making breakpoints in and copying them to: + self.orig_target = self.dbg.CreateTarget(exe) + self.assertTrue(self.orig_target, VALID_TARGET) + + self.copy_target = self.dbg.CreateTarget(exe) + self.assertTrue(self.copy_target, VALID_TARGET) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.bkpts_file_path = self.getBuildArtifact("breakpoints.json") + self.bkpts_file_spec = lldb.SBFileSpec(self.bkpts_file_path) + + def check_equivalence(self, source_bps, do_write = True): + + error = lldb.SBError() + + if (do_write): + error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps) + self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) + + copy_bps = lldb.SBBreakpointList(self.copy_target) + error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, copy_bps) + self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) + + num_source_bps = source_bps.GetSize() + num_copy_bps = copy_bps.GetSize() + self.assertTrue(num_source_bps == num_copy_bps, "Didn't get same number of input and output breakpoints - orig: %d copy: %d"%(num_source_bps, num_copy_bps)) + + for i in range(0, num_source_bps): + source_bp = source_bps.GetBreakpointAtIndex(i) + source_desc = lldb.SBStream() + source_bp.GetDescription(source_desc, False) + source_text = source_desc.GetData() + + # I am assuming here that the breakpoints will get written out in breakpoint ID order, and + # read back in ditto. That is true right now, and I can't see any reason to do it differently + # but if we do we can go to writing the breakpoints one by one, or sniffing the descriptions to + # see which one is which. + copy_id = source_bp.GetID() + copy_bp = copy_bps.FindBreakpointByID(copy_id) + self.assertTrue(copy_bp.IsValid(), "Could not find copy breakpoint %d."%(copy_id)) + + copy_desc = lldb.SBStream() + copy_bp.GetDescription(copy_desc, False) + copy_text = copy_desc.GetData() + + # These two should be identical. + # print ("Source text for %d is %s."%(i, source_text)) + self.assertTrue (source_text == copy_text, "Source and dest breakpoints are not identical: \nsource: %s\ndest: %s"%(source_text, copy_text)) + + def do_check_resolvers(self): + """Use Python APIs to check serialization of breakpoint resolvers""" + + empty_module_list = lldb.SBFileSpecList() + empty_cu_list = lldb.SBFileSpecList() + blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) + + # It isn't actually important for these purposes that these breakpoint + # actually have locations. + source_bps = lldb.SBBreakpointList(self.orig_target) + source_bps.Append(self.orig_target.BreakpointCreateByLocation("blubby.c", 666)) + # Make sure we do one breakpoint right: + self.check_equivalence(source_bps) + source_bps.Clear() + + source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list)) + source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list)) + source_bps.Append(self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec)) + + # And some number greater than one: + self.check_equivalence(source_bps) + + def do_check_filters(self): + """Use Python APIs to check serialization of breakpoint filters.""" + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec("SomeBinary")) + module_list.Append(lldb.SBFileSpec("SomeOtherBinary")) + + cu_list = lldb.SBFileSpecList() + cu_list.Append(lldb.SBFileSpec("SomeCU.c")) + cu_list.Append(lldb.SBFileSpec("AnotherCU.c")) + cu_list.Append(lldb.SBFileSpec("ThirdCU.c")) + + blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) + + # It isn't actually important for these purposes that these breakpoint + # actually have locations. + source_bps = lldb.SBBreakpointList(self.orig_target) + bkpt = self.orig_target.BreakpointCreateByLocation(blubby_file_spec, 666, 0, module_list) + source_bps.Append(bkpt) + + # Make sure we do one right: + self.check_equivalence(source_bps) + source_bps.Clear() + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, module_list, cu_list) + source_bps.Append(bkpt) + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, module_list, cu_list) + source_bps.Append(bkpt) + bkpt = self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec) + source_bps.Append(bkpt) + + # And some number greater than one: + self.check_equivalence(source_bps) + + def do_check_options(self): + """Use Python APIs to check serialization of breakpoint options.""" + + empty_module_list = lldb.SBFileSpecList() + empty_cu_list = lldb.SBFileSpecList() + blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) + + # It isn't actually important for these purposes that these breakpoint + # actually have locations. + source_bps = lldb.SBBreakpointList(self.orig_target) + + bkpt = self.orig_target.BreakpointCreateByLocation( + lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) + bkpt.SetEnabled(False) + bkpt.SetOneShot(True) + bkpt.SetThreadID(10) + source_bps.Append(bkpt) + + # Make sure we get one right: + self.check_equivalence(source_bps) + source_bps.Clear() + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) + bkpt.SetIgnoreCount(10) + bkpt.SetThreadName("grubby") + source_bps.Append(bkpt) + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) + bkpt.SetCondition("gonna remove this") + bkpt.SetCondition("") + source_bps.Append(bkpt) + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list) + bkpt.SetCondition("something != something_else") + bkpt.SetQueueName("grubby") + bkpt.AddName("FirstName") + bkpt.AddName("SecondName") + bkpt.SetScriptCallbackBody('\tprint("I am a function that prints.")\n\tprint("I don\'t do anything else")\n') + source_bps.Append(bkpt) + + bkpt = self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec) + cmd_list = lldb.SBStringList() + cmd_list.AppendString("frame var") + cmd_list.AppendString("thread backtrace") + + bkpt.SetCommandLineCommands(cmd_list) + source_bps.Append(bkpt) + + self.check_equivalence(source_bps) + + def do_check_appending(self): + """Use Python APIs to check appending to already serialized options.""" + + empty_module_list = lldb.SBFileSpecList() + empty_cu_list = lldb.SBFileSpecList() + blubby_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "blubby.c")) + + # It isn't actually important for these purposes that these breakpoint + # actually have locations. + + all_bps = lldb.SBBreakpointList(self.orig_target) + source_bps = lldb.SBBreakpointList(self.orig_target) + + bkpt = self.orig_target.BreakpointCreateByLocation( + lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) + bkpt.SetEnabled(False) + bkpt.SetOneShot(True) + bkpt.SetThreadID(10) + source_bps.Append(bkpt) + all_bps.Append(bkpt) + + error = lldb.SBError() + error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps) + self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) + + source_bps.Clear() + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list) + bkpt.SetIgnoreCount(10) + bkpt.SetThreadName("grubby") + source_bps.Append(bkpt) + all_bps.Append(bkpt) + + bkpt = self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list) + bkpt.SetCondition("something != something_else") + bkpt.SetQueueName("grubby") + bkpt.AddName("FirstName") + bkpt.AddName("SecondName") + + source_bps.Append(bkpt) + all_bps.Append(bkpt) + + error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps, True) + self.assertTrue(error.Success(), "Failed appending breakpoints to file: %s."%(error.GetCString())) + + self.check_equivalence(all_bps) + + def do_check_names(self): + bkpt = self.orig_target.BreakpointCreateByLocation( + lldb.SBFileSpec("blubby.c"), 666, 333, 0, lldb.SBFileSpecList()) + good_bkpt_name = "GoodBreakpoint" + write_bps = lldb.SBBreakpointList(self.orig_target) + bkpt.AddName(good_bkpt_name) + write_bps.Append(bkpt) + + error = lldb.SBError() + error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, write_bps) + self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString())) + + copy_bps = lldb.SBBreakpointList(self.copy_target) + names_list = lldb.SBStringList() + names_list.AppendString("NoSuchName") + + error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, names_list, copy_bps) + self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) + self.assertTrue(copy_bps.GetSize() == 0, "Found breakpoints with a nonexistent name.") + + names_list.AppendString(good_bkpt_name) + error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, names_list, copy_bps) + self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString())) + self.assertTrue(copy_bps.GetSize() == 1, "Found the matching breakpoint.") diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c new file mode 100644 index 00000000000..b1ed4465c1d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/serialize/main.c @@ -0,0 +1,53 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include <stdio.h> + +// This simple program is to demonstrate the capability of the lldb command +// "breakpoint modify -i <count> breakpt-id" to set the number of times a +// breakpoint is skipped before stopping. Ignore count can also be set upon +// breakpoint creation by 'breakpoint set ... -i <count>'. + +int a(int); +int b(int); +int c(int); + +int a(int val) +{ + if (val <= 1) + return b(val); + else if (val >= 3) + return c(val); // a(3) -> c(3) Find the call site of c(3). + + return val; +} + +int b(int val) +{ + return c(val); +} + +int c(int val) +{ + return val + 3; // Find the line number of function "c" here. +} + +int main (int argc, char const *argv[]) +{ + int A1 = a(1); // a(1) -> b(1) -> c(1) + printf("a(1) returns %d\n", A1); + + int B2 = b(2); // b(2) -> c(2) Find the call site of b(2). + printf("b(2) returns %d\n", B2); + + int A3 = a(3); // a(3) -> c(3) Find the call site of a(3). + printf("a(3) returns %d\n", A3); + + int C1 = c(5); // Find the call site of c in main. + printf ("c(5) returns %d\n", C1); + return 0; +} |