diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py index 7ae5687af2cf4..c4a5fe2f97bae 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py @@ -124,6 +124,11 @@ def test_libstdcxx(self): self.build(dictionary={"USE_LIBSTDCPP": 1}) self.do_test() + @add_test_categories(["msvcstl"]) + def test_msvc(self): + self.build() + self.do_test() + def do_test_multibyte(self): lldbutil.run_to_source_breakpoint( self, "Set break point at this line.", self.main_spec @@ -134,9 +139,6 @@ def do_test_multibyte(self): self.expect( "frame variable", substrs=[ - '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, - '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' - % ns, '(%s::u16string) u16_string = u"ß水氶"' % ns, '(%s::u16string) u16_empty = u""' % ns, '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns, @@ -157,6 +159,11 @@ def test_multibyte_libstdcxx(self): self.build(dictionary={"USE_LIBSTDCPP": 1}) self.do_test_multibyte() + @add_test_categories(["msvcstl"]) + def test_multibyte_msvc(self): + self.build() + self.do_test_multibyte() + def do_test_uncapped_summary(self): (_, _, thread, _) = lldbutil.run_to_source_breakpoint( self, "Set break point at this line.", self.main_spec @@ -187,6 +194,11 @@ def test_uncapped_libstdcxx(self): self.build(dictionary={"USE_LIBSTDCPP": 1}) self.do_test_uncapped_summary() + @add_test_categories(["msvcstl"]) + def test_uncapped_msvc(self): + self.build() + self.do_test_uncapped_summary() + def do_test_summary_unavailable(self): """ Make sure that if the string is not readable, we give an error. @@ -212,3 +224,67 @@ def test_unavailable_summary_libcxx(self): def test_unavailable_summary_libstdcxx(self): self.build(dictionary={"USE_LIBSTDCPP": 1}) self.do_test_summary_unavailable() + + @add_test_categories(["msvcstl"]) + def test_unavailable_summary_msvc(self): + self.build() + self.do_test_summary_unavailable() + + def do_test_overwritten(self): + lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", self.main_spec + ) + + self.expect_var_path("overwritten_zero", summary='"abc"') + + @add_test_categories(["libc++"]) + def test_overwritten_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test_overwritten() + + @expectedFailureAll( + bugnumber="libstdc++ format for non-null terminated std::string currently diverges from MSVC and libc++ formatter." + ) + @add_test_categories(["libstdcxx"]) + def test_overwritten_libstdcxx(self): + self.build(dictionary={"USE_LIBSTDCPP": 1}) + self.do_test_overwritten() + + @add_test_categories(["msvcstl"]) + def test_overwritten_msvc(self): + self.build() + self.do_test_overwritten() + + def do_test_embedded_null(self): + lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", self.main_spec + ) + + ns = self.namespace + + self.expect( + "frame variable", + substrs=[ + '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, + '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' + % ns, + ], + ) + + @add_test_categories(["libc++"]) + def test_embedded_null_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test_embedded_null() + + @expectedFailureAll( + bugnumber="libstdc++ formatters incorrectly format std::string with embedded '\0' characters." + ) + @add_test_categories(["libstdcxx"]) + def test_embedded_null_libstdcxx(self): + self.build(dictionary={"USE_LIBSTDCPP": 1}) + self.do_test_embedded_null() + + @add_test_categories(["msvcstl"]) + def test_embedded_null_msvc(self): + self.build() + self.do_test_embedded_null() diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp index db695ed06f015..f22c890861d01 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp @@ -13,6 +13,8 @@ int main() { std::string empty(""); std::string q("hello world"); std::string Q("quite a long std::strin with lots of info inside it"); + std::string overwritten_zero("abc"); + const_cast(overwritten_zero.data())[3] = 'd'; std::string TheVeryLongOne( "123456789012345678901234567890123456789012345678901234567890123456789012" "345678901234567890123456789012345678901234567890123456789012345678901234" diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/Makefile similarity index 61% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/Makefile rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/Makefile index 99998b20bcb05..4f79c0a900c3a 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/Makefile +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/Makefile @@ -1,3 +1,4 @@ CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -std=c++20 include Makefile.rules diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/TestDataFormatterMsvcStlU8String.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/TestDataFormatterStdU8String.py similarity index 53% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/TestDataFormatterMsvcStlU8String.py rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/TestDataFormatterStdU8String.py index f181f520f5d85..f5d7dc5c3b79b 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/TestDataFormatterMsvcStlU8String.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/TestDataFormatterStdU8String.py @@ -1,6 +1,6 @@ # coding=utf8 """ -Test std::u8string summary with MSVC's STL. +Test std::u8string summary. """ @@ -10,14 +10,8 @@ from lldbsuite.test import lldbutil -class MsvcStlU8StringDataFormatterTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - - @add_test_categories(["msvcstl"]) - def test_with_run_command(self): - """Test that that file and class static variables display correctly.""" - self.build() - +class StdU8StringDataFormatterTestCase(TestBase): + def do_test(self): lldbutil.run_to_source_breakpoint( self, "Set break point at this line.", lldb.SBFileSpec("main.cpp") ) @@ -31,3 +25,20 @@ def test_with_run_command(self): '(std::u8string) u8_text = u8"ABC"', ], ) + + @expectedFailureAll(bugnumber="No libc++ formatters for std::u8string yet.") + @add_test_categories(["libc++"]) + def test_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test() + + @expectedFailureAll(bugnumber="No libstdc++ formatters for std::u8string yet.") + @add_test_categories(["libstdcxx"]) + def test_libstdcxx(self): + self.build(dictionary={"USE_LIBSTDCPP": 1}) + self.do_test() + + @add_test_categories(["msvcstl"]) + def test_msvc(self): + self.build() + self.do_test() diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/main.cpp similarity index 52% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/main.cpp rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/main.cpp index e01af9fa08e7e..3db9d6380f61e 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/main.cpp +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/u8string/main.cpp @@ -1,14 +1,12 @@ +#include #include -#ifndef _MSVC_STL_VERSION -// this is more of a sanity check that the categories work as expected -#error Not using MSVC STL -#endif - int main() { std::u8string u8_string_small(u8"🍄"); std::u8string u8_string(u8"❤️👍📄📁😃🧑‍🌾"); std::u8string u8_empty(u8""); std::u8string u8_text(u8"ABC"); - u8_text.assign(u8"ABCd"); // Set break point at this line. + u8_text.assign(u8"ABCd"); + + std::puts("// Set break point at this line."); } diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/TestDataFormatterMsvcStlString.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/TestDataFormatterMsvcStlString.py deleted file mode 100644 index e49ea84dbdf47..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/TestDataFormatterMsvcStlString.py +++ /dev/null @@ -1,120 +0,0 @@ -# coding=utf8 -""" -Test std::*string summaries with MSVC's STL. -""" - - -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class MsvcStlStringDataFormatterTestCase(TestBase): - NO_DEBUG_INFO_TESTCASE = True - - @add_test_categories(["msvcstl"]) - def test_with_run_command(self): - """Test that that file and class static variables display correctly.""" - self.build() - - main_spec = lldb.SBFileSpec("main.cpp") - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( - self, "Set break point at this line.", main_spec - ) - frame = thread.frames[0] - - # This is the function to remove the custom formats in order to have a - # clean slate for the next test case. - def cleanup(): - self.runCmd("type format clear", check=False) - self.runCmd("type summary clear", check=False) - self.runCmd("type filter clear", check=False) - self.runCmd("type synth clear", check=False) - - # Execute the cleanup function during test case tear down. - self.addTearDownHook(cleanup) - - self.expect( - "frame variable", - substrs=[ - '(std::wstring) wempty = L""', - '(std::wstring) s = L"hello world! מזל טוב!"', - '(std::wstring) S = L"!!!!"', - "(const wchar_t *) mazeltov = 0x", - 'L"מזל טוב"', - '(std::string) empty = ""', - '(std::string) q = "hello world"', - '(std::string) Q = "quite a long std::strin with lots of info inside it"', - '(std::string) overwritten_zero = "abc"', - '(std::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', - '(std::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"', - '(std::u16string) u16_string = u"ß水氶"', - '(std::u16string) u16_empty = u""', - '(std::u32string) u32_string = U"🍄🍅🍆🍌"', - '(std::u32string) u32_empty = U""', - "(std::string *) null_str = nullptr", - ], - ) - - thread.StepOver() - - TheVeryLongOne = frame.FindVariable("TheVeryLongOne") - summaryOptions = lldb.SBTypeSummaryOptions() - summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) - uncappedSummaryStream = lldb.SBStream() - TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) - uncappedSummary = uncappedSummaryStream.GetData() - self.assertGreater( - uncappedSummary.find("someText"), - 0, - "uncappedSummary does not include the full string", - ) - summaryOptions.SetCapping(lldb.eTypeSummaryCapped) - cappedSummaryStream = lldb.SBStream() - TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) - cappedSummary = cappedSummaryStream.GetData() - self.assertLessEqual( - cappedSummary.find("someText"), 0, "cappedSummary includes the full string" - ) - - self.expect_expr( - "s", result_type="std::wstring", result_summary='L"hello world! מזל טוב!"' - ) - - self.expect_expr("q", result_type="std::string", result_summary='"hello world"') - - self.expect_expr( - "Q", - result_type="std::string", - result_summary='"quite a long std::strin with lots of info inside it"', - ) - - self.expect( - "frame variable", - substrs=[ - '(std::wstring) S = L"!!!!!"', - "(const wchar_t *) mazeltov = 0x", - 'L"מזל טוב"', - '(std::string) q = "hello world"', - '(std::string) Q = "quite a long std::strin with lots of info inside it"', - '(std::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', - '(std::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"', - '(std::u16string) u16_string = u"ß水氶"', - '(std::u32string) u32_string = U"🍄🍅🍆🍌"', - '(std::u32string) u32_empty = U""', - "(std::string *) null_str = nullptr", - ], - ) - - # Finally, make sure that if the string is not readable, we give an error: - bkpt_2 = target.BreakpointCreateBySourceRegex( - "Break here to look at bad string", main_spec - ) - self.assertEqual(bkpt_2.GetNumLocations(), 1, "Got one location") - threads = lldbutil.continue_to_breakpoint(process, bkpt_2) - self.assertEqual(len(threads), 1, "Stopped at second breakpoint") - frame = threads[0].frames[0] - var = frame.FindVariable("in_str") - self.assertTrue(var.GetError().Success(), "Made variable") - self.assertIsNone(var.GetSummary()) diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/main.cpp deleted file mode 100644 index fcfb5d48e9bb1..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/main.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include - -#include - -#ifndef _MSVC_STL_VERSION -// this is more of a sanity check that the categories work as expected -#error Not using MSVC STL -#endif - -static size_t touch_string(std::string &in_str) { - return in_str.size(); // Break here to look at bad string -} - -int main() { - std::wstring wempty(L""); - std::wstring s(L"hello world! מזל טוב!"); - std::wstring S(L"!!!!"); - const wchar_t *mazeltov = L"מזל טוב"; - std::string empty(""); - std::string q("hello world"); - std::string Q("quite a long std::strin with lots of info inside it"); - std::string overwritten_zero("abc"); - const_cast(overwritten_zero.data())[3] = 'd'; - // clang-format off - std::string TheVeryLongOne("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890someText1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - // clang-format on - std::string IHaveEmbeddedZeros("a\0b\0c\0d", 7); - std::wstring IHaveEmbeddedZerosToo( - L"hello world!\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監", 38); - std::u16string u16_string(u"ß水氶"); - std::u16string u16_empty(u""); - std::u32string u32_string(U"🍄🍅🍆🍌"); - std::u32string u32_empty(U""); - std::string *null_str = nullptr; - - S.assign(L"!!!!!"); // Set break point at this line. - std::string *not_a_string = (std::string *)0x0; - touch_string(*not_a_string); - return 0; -} diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/Makefile deleted file mode 100644 index 58558e6e15f78..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -CXX_SOURCES := main.cpp - -CXXFLAGS_EXTRAS := -std=c++20 -O0 -include Makefile.rules