Skip to content

[lldb][test] Merge MSVC STL std::(u8)string tests into generic directory #147525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(overwritten_zero.data())[3] = 'd';
std::string TheVeryLongOne(
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -std=c++20

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf8
"""
Test std::u8string summary with MSVC's STL.
Test std::u8string summary.
"""


Expand All @@ -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")
)
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include <cstdio>
#include <string>

#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.");
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading