From f9caf2d34f9c1349b17b38146a7b6dd44a8a0438 Mon Sep 17 00:00:00 2001 From: Sukhikh Alexander Date: Fri, 28 Jul 2023 17:50:51 +0300 Subject: [PATCH] [lldb] Fix list frontend Use Clone method for child values to save them between debugging steps. Add tests for these changes Issue: https://gitee.com/open_harmony/dashboard?issue_id=I7OKFW Signed-off-by: Sukhikh Alexander --- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 25 +++------ .../value/change_values/libcxx/list/Makefile | 8 +++ .../libcxx/list/TestChangeListValue.py | 55 +++++++++++++++++++ .../value/change_values/libcxx/list/main.cpp | 11 ++++ 4 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/list/Makefile create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/list/TestChangeListValue.py create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/list/main.cpp diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp index a1953a1c7a22..b6d98944ea72 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp @@ -277,15 +277,11 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(size_t idx) { // we need to copy current_sp into a new object otherwise we will end up with // all items named __value_ - DataExtractor data; - Status error; - current_sp->GetData(data, error); - if (error.Fail()) - return nullptr; - - return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), data, - m_backend.GetExecutionContextRef(), - m_element_type); + // OHOS_LOCAL begin + StreamString name; + name.Printf("[%" PRIu64 "]", (uint64_t)idx); + return current_sp->Clone(ConstString(name.GetString())); + // OHOS_LOCAL end } bool ForwardListFrontEnd::Update() { @@ -387,17 +383,10 @@ lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(size_t idx) { // we need to copy current_sp into a new object otherwise we will end up with // all items named __value_ - DataExtractor data; - Status error; - current_sp->GetData(data, error); - if (error.Fail()) - return lldb::ValueObjectSP(); - StreamString name; name.Printf("[%" PRIu64 "]", (uint64_t)idx); - return CreateValueObjectFromData(name.GetString(), data, - m_backend.GetExecutionContextRef(), - m_element_type); + // OHOS_LOCAL + return current_sp->Clone(ConstString(name.GetString())); } bool ListFrontEnd::Update() { diff --git a/lldb/test/API/python_api/value/change_values/libcxx/list/Makefile b/lldb/test/API/python_api/value/change_values/libcxx/list/Makefile new file mode 100644 index 000000000000..e4e54adc602d --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/list/Makefile @@ -0,0 +1,8 @@ +# OHOS_LOCAL begin +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules +# OHOS_LOCAL end diff --git a/lldb/test/API/python_api/value/change_values/libcxx/list/TestChangeListValue.py b/lldb/test/API/python_api/value/change_values/libcxx/list/TestChangeListValue.py new file mode 100644 index 000000000000..02cfe786400f --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/list/TestChangeListValue.py @@ -0,0 +1,55 @@ +# OHOS_LOCAL begin +""" +Test change libc++ list values. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LibcxxChangeValueTestCase(TestBase): + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def do_single_test(self, var_name, frame): + var = frame.FindVariable(var_name) + self.assertTrue(var.IsValid(), "Got the SBValue for val") + element0 = var.GetChildMemberWithName("[0]") + self.assertTrue(element0.IsValid(), "Got the SBValue for [0]") + result = element0.SetValueFromCString("12345") + self.assertTrue(result, "Setting val returned True.") + result = element0.GetValueAsUnsigned() + self.assertTrue(result == 12345, "Got correct value (12345)") + self.assertTrue(element0.GetValueDidChange(), "LLDB noticed that value changed") + + @add_test_categories(["libc++"]) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772") + def test(self): + """Test that we can change values of libc++ map.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this line.")) + + self.runCmd("run", RUN_SUCCEEDED) + + # Get Frame #0. + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + self.assertState(process.GetState(), lldb.eStateStopped) + thread = lldbutil.get_stopped_thread( + process, lldb.eStopReasonBreakpoint) + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint condition") + frame0 = thread.GetFrameAtIndex(0) + self.assertTrue(frame0.IsValid(), "Got a valid frame.") + + self.do_single_test("L", frame0) + self.do_single_test("FL", frame0) +# OHOS_LOCAL end diff --git a/lldb/test/API/python_api/value/change_values/libcxx/list/main.cpp b/lldb/test/API/python_api/value/change_values/libcxx/list/main.cpp new file mode 100644 index 000000000000..8ef17ee8461d --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/list/main.cpp @@ -0,0 +1,11 @@ +// OHOS_LOCAL begin +#include +#include + +int main() +{ + std::list L = {1, 2, 3, 4}; + std::forward_list FL = {1, 2, 3, 4}; + return 0; // Set break point at this line. +} +// OHOS_LOCAL end -- Gitee