[Lldb-commits] [lldb] [lldb][test] Combine libstdc++ and libc++ std::string tests into generic test (PR #147355)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 8 01:01:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Michael Buch (Michael137)
<details>
<summary>Changes</summary>
This combines the libc++ and libstdc++ test cases. The main difference was that the libstdcpp tests had additional tests for references/pointers to std::string. I moved those over.
The libstdc++ formatters don't support `std::u16string`/`std::u32string` yet, so I extracted those into XFAILed test cases.
There were also two test assertions that failed for libstdc++:
1. libstdc++ doesn't obey the capped/uncapped summary options
2. When a summary isn't available for a std::string, libc++ would print "Summary Unavailable", whereas libstdc++ just prints "((null))". This may be better suited for the STL-specific subdirectories, but left it here for now.
I put those in separate XFAILed test-cases.
Split out from https://github.com/llvm/llvm-project/pull/146740
---
Patch is 29.05 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/147355.diff
7 Files Affected:
- (renamed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/Makefile (-3)
- (renamed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py (+128-52)
- (added) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp (+104)
- (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile (-6)
- (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp (-31)
- (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py (-93)
- (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp (-16)
``````````diff
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/Makefile
similarity index 53%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/Makefile
index c825977b1a5dc..99998b20bcb05 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/Makefile
@@ -1,6 +1,3 @@
CXX_SOURCES := main.cpp
-CFLAGS_EXTRAS := -O0
-USE_LIBSTDCPP := 1
-
include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py
similarity index 52%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py
index 2f7fc88e0f449..2991cf870dcd2 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py
@@ -10,7 +10,7 @@
from lldbsuite.test import lldbutil
-class LibcxxStringDataFormatterTestCase(TestBase):
+class StdStringDataFormatterTestCase(TestBase):
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
@@ -18,17 +18,8 @@ def setUp(self):
self.main_spec = lldb.SBFileSpec("main.cpp")
self.namespace = "std"
- @add_test_categories(["libc++"])
- @expectedFailureAll(
- bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
- )
- # Inline namespace is randomly ignored as Clang due to broken lookup inside
- # the std namespace.
- @expectedFailureAll(debug_info="gmodules")
- def test_with_run_command(self):
+ def do_test(self):
"""Test that that file and class static variables display correctly."""
- self.build()
-
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", self.main_spec
)
@@ -47,42 +38,13 @@ def cleanup():
ns = self.namespace
- self.expect(
- "frame variable",
- substrs=[
- '(%s::wstring) wempty = L""' % ns,
- '(%s::wstring) s = L"hello world! מזל טוב!"' % ns,
- '(%s::wstring) S = L"!!!!"' % ns,
- "(const wchar_t *) mazeltov = 0x",
- 'L"מזל טוב"',
- '(%s::string) empty = ""' % ns,
- '(%s::string) q = "hello world"' % ns,
- '(%s::string) Q = "quite a long std::strin with lots of info inside it"'
- % ns,
- '(%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,
- '(%s::u32string) u32_empty = U""' % ns,
- "(%s::string *) null_str = nullptr" % ns,
- ],
- )
+ # Check 'S' pre-assignment.
+ self.expect("frame variable S", substrs=['(%s::wstring) S = L"!!!!"' % ns])
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)
@@ -108,31 +70,145 @@ def cleanup():
self.expect(
"frame variable",
substrs=[
+ '(%s::wstring) wempty = L""' % ns,
+ '(%s::wstring) s = L"hello world! מזל טוב!"' % ns,
'(%s::wstring) S = L"!!!!!"' % ns,
"(const wchar_t *) mazeltov = 0x",
'L"מזל טוב"',
+ '(%s::string) empty = ""' % ns,
'(%s::string) q = "hello world"' % ns,
'(%s::string) Q = "quite a long std::strin with lots of info inside it"'
% ns,
+ "(%s::string *) null_str = nullptr" % ns,
+ ],
+ )
+
+ # Test references and pointers to std::string.
+ var_rq = self.frame().FindVariable("rq")
+ var_rQ = self.frame().FindVariable("rQ")
+ var_pq = self.frame().FindVariable("pq")
+ var_pQ = self.frame().FindVariable("pQ")
+
+ self.assertEqual(var_rq.GetSummary(), '"hello world"', "rq summary wrong")
+ self.assertEqual(
+ var_rQ.GetSummary(),
+ '"quite a long std::strin with lots of info inside it"',
+ "rQ summary wrong",
+ )
+ self.assertEqual(var_pq.GetSummary(), '"hello world"', "pq summary wrong")
+ self.assertEqual(
+ var_pQ.GetSummary(),
+ '"quite a long std::strin with lots of info inside it"',
+ "pQ summary wrong",
+ )
+
+ @expectedFailureAll(
+ bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
+ )
+ # Inline namespace is randomly ignored as Clang due to broken lookup inside
+ # the std namespace.
+ @expectedFailureAll(debug_info="gmodules")
+ @add_test_categories(["libc++"])
+ def test_libcxx(self):
+ self.build(dictionary={"USE_LIBCPP": 1})
+ self.do_test()
+
+ @expectedFailureAll(
+ bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
+ )
+ # Inline namespace is randomly ignored as Clang due to broken lookup inside
+ # the std namespace.
+ @expectedFailureAll(debug_info="gmodules")
+ @add_test_categories(["libstdcxx"])
+ def test_libstdcxx(self):
+ self.build(dictionary={"USE_LIBSTDCPP": 1})
+ self.do_test()
+
+ def do_test_multibyte(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,
'(%s::u16string) u16_string = u"ß水氶"' % ns,
+ '(%s::u16string) u16_empty = u""' % ns,
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns,
'(%s::u32string) u32_empty = U""' % ns,
- "(%s::string *) null_str = nullptr" % ns,
],
)
- # 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", self.main_spec
+ @add_test_categories(["libc++"])
+ def test_multibyte_libcxx(self):
+ self.build(dictionary={"USE_LIBCPP": 1})
+ self.do_test_multibyte()
+
+ @expectedFailureAll(
+ bugnumber="libstdc++ formatters don't support UTF-16/UTF-32 strings yet."
+ )
+ @add_test_categories(["libstdcxx"])
+ def test_multibyte_libstdcxx(self):
+ self.build(dictionary={"USE_LIBSTDCPP": 1})
+ self.do_test_multibyte()
+
+ def do_test_uncapped_summary(self):
+ lldbutil.run_to_source_breakpoint(
+ self, "Set break point at this line.", self.main_spec
+ )
+
+ 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",
)
- 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")
+
+ @add_test_categories(["libc++"])
+ def test_uncapped_libcxx(self):
+ self.build(dictionary={"USE_LIBCPP": 1})
+ self.do_test_uncapped_summary()
+
+ @expectedFailureAll(
+ bugnumber="libstdc++ std::string summary provider doesn't obey summary options."
+ )
+ @add_test_categories(["libstdcxx"])
+ def test_uncapped_libstdcxx(self):
+ self.build(dictionary={"USE_LIBSTDCPP": 1})
+ self.do_test_uncapped_summary()
+
+ def do_test_summary_unavailable(self):
+ """
+ Make sure that if the string is not readable, we give an error.
+ """
+ (_, _, thread, _) = lldbutil.run_to_source_breakpoint(
+ self, "Break here to look at bad string", self.main_spec
+ )
+
+ var = thread.frames[0].FindVariable("in_str")
+ self.assertTrue(var.GetError().Success(), "Found variable")
summary = var.GetSummary()
self.assertEqual(summary, "Summary Unavailable", "No summary for bad value")
+
+ @add_test_categories(["libc++"])
+ def test_unavailable_summary_libcxx(self):
+ self.build(dictionary={"USE_LIBCPP": 1})
+ self.do_test_summary_unavailable()
+
+ @expectedFailureAll(
+ bugnumber="libstdc++ std::string summary provider doesn't output a user-friendly message for invalid strings."
+ )
+ @add_test_categories(["libstdcxx"])
+ def test_unavailable_summary_libstdcxx(self):
+ self.build(dictionary={"USE_LIBSTDCPP": 1})
+ self.do_test_summary_unavailable()
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
new file mode 100644
index 0000000000000..db695ed06f015
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp
@@ -0,0 +1,104 @@
+#include <stdint.h>
+#include <string>
+
+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 TheVeryLongOne(
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "9012345678901234567890123456789012345678901234567890someText123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "123456789012345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890123456789012345678901234567890123456789012345678901234"
+ "567890123456789012345678901234567890123456789012345678901234567890123456"
+ "789012345678901234567890123456789012345678901234567890123456789012345678"
+ "901234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890");
+ 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;
+ auto &rq = q;
+ auto &rQ = Q;
+ std::string *pq = &q;
+ std::string *pQ = &Q;
+
+ 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/libcxx/string/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile
deleted file mode 100644
index c7c91da728d1e..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-CXX_SOURCES := main.cpp
-
-USE_LIBCPP := 1
-
-CXXFLAGS_EXTRAS := -std=c++11 -O0
-include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
deleted file mode 100644
index 373f817a80f7d..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <string>
-#include <stdint.h>
-
-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 TheVeryLongOne("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/147355
More information about the lldb-commits
mailing list