From 256fa94d299e65d6e28e9bbbcf33bb2c122eec90 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 3 Jul 2025 15:04:57 +0100 Subject: [PATCH 1/2] [lldb][test] Consolidate libstdc++ and libc++ vector formatter tests into generic test The libstdc++ test was a subset of the tests in libc++. This test moves the libc++ test into `generic` and removes the `libstdc++` tests. I retained the `-D_GLIBCXX_DEBUG` test cases though. Split out from https://github.com/llvm/llvm-project/pull/146740 --- .../{libstdcpp => generic}/vector/Makefile | 3 - .../vector/TestDataFormatterStdVector.py} | 43 +++- .../generic/vector/main.cpp | 40 ++++ .../data-formatter-stl/libcxx/vector/Makefile | 6 - .../data-formatter-stl/libcxx/vector/main.cpp | 41 ---- .../vector/TestDataFormatterStdVector.py | 220 ------------------ .../libstdcpp/vector/main.cpp | 31 --- 7 files changed, 76 insertions(+), 308 deletions(-) rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libstdcpp => generic}/vector/Makefile (57%) rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libcxx/vector/TestDataFormatterLibcxxVector.py => generic/vector/TestDataFormatterStdVector.py} (84%) create mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/Makefile similarity index 57% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/Makefile index 654e4b15bd568..99998b20bcb05 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/Makefile @@ -1,6 +1,3 @@ CXX_SOURCES := main.cpp -CXXFLAGS := -O0 -USE_LIBSTDCPP := 1 - include Makefile.rules diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/TestDataFormatterStdVector.py similarity index 84% rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/TestDataFormatterStdVector.py index 13341a9b274be..ba8b10450f4fc 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/TestDataFormatterStdVector.py @@ -2,14 +2,13 @@ Test lldb data formatter subsystem. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil -class LibcxxVectorDataFormatterTestCase(TestBase): +class StdVectorDataFormatterTestCase(TestBase): def check_numbers(self, var_name, show_ptr=False): patterns = [] substrs = [ @@ -52,10 +51,8 @@ def check_numbers(self, var_name, show_ptr=False): self.expect("frame variable " + var_name + "[2]", substrs=["123"]) self.expect("frame variable " + var_name + "[3]", substrs=["1234"]) - @add_test_categories(["libc++"]) - def test_with_run_command(self): + def do_test(self): """Test that that file and class static variables display correctly.""" - self.build() (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec("main.cpp", False) ) @@ -170,10 +167,25 @@ def cleanup(): self.expect("frame variable strings", substrs=["vector has 0 items"]) + @add_test_categories(["libstdcxx"]) + def test_libstdcxx(self): + self.build(dictionary={"USE_LIBSTDCPP": 1}) + self.do_test() + + @add_test_categories(["libstdcxx"]) + def test_libstdcxx_debug(self): + self.build( + dictionary={"USE_LIBSTDCPP": 1, "CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"} + ) + self.do_test() + @add_test_categories(["libc++"]) - def test_ref_and_ptr(self): + def test_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test() + + def do_test_ref_and_ptr(self): """Test that that file and class static variables display correctly.""" - self.build() (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False) ) @@ -186,3 +198,20 @@ def test_ref_and_ptr(self): self.expect("frame variable ptr", substrs=["ptr =", " size=7"]) self.expect("expression ptr", substrs=["$", "size=7"]) + + @add_test_categories(["libstdcxx"]) + def test_ref_and_ptr_libstdcxx(self): + self.build(dictionary={"USE_LIBSTDCPP": 1}) + self.do_test_ref_and_ptr() + + @add_test_categories(["libstdcxx"]) + def test_ref_and_ptr_libstdcxx_debug(self): + self.build( + dictionary={"USE_LIBSTDCPP": 1, "CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"} + ) + self.do_test_ref_and_ptr() + + @add_test_categories(["libc++"]) + def test_ref_and_ptr_libcxx(self): + self.build(dictionary={"USE_LIBCPP": 1}) + self.do_test_ref_and_ptr() diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp new file mode 100644 index 0000000000000..19cd1893bd22a --- /dev/null +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +typedef std::vector int_vect; +typedef std::vector string_vect; + +template +void by_ref_and_ptr(std::vector &ref, std::vector *ptr) { + // Stop here to check by ref + return; +} + +int main() { + int_vect numbers; + (numbers.push_back(1)); // break here + (numbers.push_back(12)); // break here + (numbers.push_back(123)); + (numbers.push_back(1234)); + (numbers.push_back(12345)); // break here + (numbers.push_back(123456)); + (numbers.push_back(1234567)); + by_ref_and_ptr(numbers, &numbers); + + printf("break here"); + numbers.clear(); + + (numbers.push_back(7)); // break here + + string_vect strings; + (strings.push_back(std::string("goofy"))); + (strings.push_back(std::string("is"))); + (strings.push_back(std::string("smart"))); + printf("break here"); + (strings.push_back(std::string("!!!"))); + + printf("break here"); + strings.clear(); + + return 0; // break here +} diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile deleted file mode 100644 index 564cbada74e08..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -CXX_SOURCES := main.cpp - -USE_LIBCPP := 1 - -CXXFLAGS_EXTRAS := -O0 -include Makefile.rules diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp deleted file mode 100644 index 0e1dbe4f03e2b..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -typedef std::vector int_vect; -typedef std::vector string_vect; - -template -void by_ref_and_ptr(std::vector &ref, std::vector *ptr) { - // Stop here to check by ref - return; -} - -int main() -{ - int_vect numbers; - (numbers.push_back(1)); // break here - (numbers.push_back(12)); // break here - (numbers.push_back(123)); - (numbers.push_back(1234)); - (numbers.push_back(12345)); // break here - (numbers.push_back(123456)); - (numbers.push_back(1234567)); - by_ref_and_ptr(numbers, &numbers); - - printf("break here"); - numbers.clear(); - - (numbers.push_back(7)); // break here - - string_vect strings; - (strings.push_back(std::string("goofy"))); - (strings.push_back(std::string("is"))); - (strings.push_back(std::string("smart"))); - printf("break here"); - (strings.push_back(std::string("!!!"))); - - printf("break here"); - strings.clear(); - - return 0; // break here -} diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py deleted file mode 100644 index 6cfd17a39304e..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py +++ /dev/null @@ -1,220 +0,0 @@ -""" -Test lldb data formatter subsystem. -""" - - -from typing import Optional -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class StdVectorDataFormatterTestCase(TestBase): - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line number to break at. - self.line = line_number("main.cpp", "// Set break point at this line.") - - @add_test_categories(["libstdcxx"]) - @expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc") - def test_with_run_command(self): - self.with_run_command() - - @add_test_categories(["libstdcxx"]) - @expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc") - def test_with_run_command_debug(self): - build_args = {"CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"} - self.with_run_command(build_args) - - def with_run_command(self, dictionary: Optional[dict] = None): - """Test that that file and class static variables display correctly.""" - self.build(dictionary=dictionary) - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.") - - self.runCmd("run", RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint. - self.expect( - "thread list", - STOPPED_DUE_TO_BREAKPOINT, - substrs=["stopped", "stop reason = breakpoint"], - ) - - # 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) - - # empty vectors (and storage pointers SHOULD BOTH BE NULL..) - self.expect("frame variable numbers", substrs=["numbers = size=0"]) - - self.runCmd("c") - - # first value added - self.expect( - "frame variable numbers", substrs=["numbers = size=1", "[0] = 1", "}"] - ) - - # add some more data - self.runCmd("c") - - self.expect( - "frame variable numbers", - substrs=[ - "numbers = size=4", - "[0] = 1", - "[1] = 12", - "[2] = 123", - "[3] = 1234", - "}", - ], - ) - - self.expect( - "expression numbers", - substrs=[ - "$", - "size=4", - "[0] = 1", - "[1] = 12", - "[2] = 123", - "[3] = 1234", - "}", - ], - ) - - # check access to synthetic children - self.runCmd( - 'type summary add --summary-string "item 0 is ${var[0]}" std::int_vect int_vect' - ) - self.expect("frame variable numbers", substrs=["item 0 is 1"]) - - self.runCmd( - 'type summary add --summary-string "item 0 is ${svar[0]}" std::int_vect int_vect' - ) - # import time - # time.sleep(19) - self.expect("frame variable numbers", substrs=["item 0 is 1"]) - # move on with synths - self.runCmd("type summary delete std::int_vect") - self.runCmd("type summary delete int_vect") - - # add some more data - self.runCmd("c") - - self.expect( - "frame variable numbers", - substrs=[ - "numbers = size=7", - "[0] = 1", - "[1] = 12", - "[2] = 123", - "[3] = 1234", - "[4] = 12345", - "[5] = 123456", - "[6] = 1234567", - "}", - ], - ) - - self.expect( - "expression numbers", - substrs=[ - "$", - "size=7", - "[0] = 1", - "[1] = 12", - "[2] = 123", - "[3] = 1234", - "[4] = 12345", - "[5] = 123456", - "[6] = 1234567", - "}", - ], - ) - - # check access-by-index - self.expect("frame variable numbers[0]", substrs=["1"]) - self.expect("frame variable numbers[1]", substrs=["12"]) - self.expect("frame variable numbers[2]", substrs=["123"]) - self.expect("frame variable numbers[3]", substrs=["1234"]) - - # but check that expression does not rely on us - # (when expression gets to call into STL code correctly, we will have to find - # another way to check this) - self.expect( - "expression numbers[6]", matching=False, error=True, substrs=["1234567"] - ) - - # check that MightHaveChildren() gets it right - self.assertTrue( - self.frame().FindVariable("numbers").MightHaveChildren(), - "numbers.MightHaveChildren() says False for non empty!", - ) - - # clear out the vector and see that we do the right thing once again - self.runCmd("c") - - self.expect("frame variable numbers", substrs=["numbers = size=0"]) - - self.runCmd("c") - - # first value added - self.expect( - "frame variable numbers", substrs=["numbers = size=1", "[0] = 7", "}"] - ) - - # check if we can display strings - self.runCmd("c") - - self.expect("frame variable strings", substrs=["goofy", "is", "smart"]) - - self.expect("expression strings", substrs=["goofy", "is", "smart"]) - - # test summaries based on synthetic children - self.runCmd( - 'type summary add std::string_vect string_vect --summary-string "vector has ${svar%#} items" -e' - ) - self.expect( - "frame variable strings", - substrs=["vector has 3 items", "goofy", "is", "smart"], - ) - - self.expect( - "expression strings", substrs=["vector has 3 items", "goofy", "is", "smart"] - ) - - self.runCmd("c") - - self.expect("frame variable strings", substrs=["vector has 4 items"]) - - # check access-by-index - self.expect("frame variable strings[0]", substrs=["goofy"]) - self.expect("frame variable strings[1]", substrs=["is"]) - - # but check that expression does not rely on us - # (when expression gets to call into STL code correctly, we will have to find - # another way to check this) - self.expect( - "expression strings[0]", matching=False, error=True, substrs=["goofy"] - ) - - # check that MightHaveChildren() gets it right - self.assertTrue( - self.frame().FindVariable("strings").MightHaveChildren(), - "strings.MightHaveChildren() says False for non empty!", - ) - - self.runCmd("c") - - self.expect("frame variable strings", substrs=["vector has 0 items"]) diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp deleted file mode 100644 index 010917995e401..0000000000000 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -typedef std::vector int_vect; -typedef std::vector string_vect; - -int main() -{ - int_vect numbers; - numbers.push_back(1); // Set break point at this line. - numbers.push_back(12); // Set break point at this line. - numbers.push_back(123); - numbers.push_back(1234); - numbers.push_back(12345); // Set break point at this line. - numbers.push_back(123456); - numbers.push_back(1234567); - - numbers.clear(); // Set break point at this line. - - numbers.push_back(7); // Set break point at this line. - - string_vect strings; // Set break point at this line. - strings.push_back(std::string("goofy")); - strings.push_back(std::string("is")); - strings.push_back(std::string("smart")); - - strings.push_back(std::string("!!!")); // Set break point at this line. - - strings.clear(); // Set break point at this line. - - return 0;// Set break point at this line. -} From 6c01239d411141b818c3b0b29b396a7e5371bee2 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 3 Jul 2025 15:24:06 +0100 Subject: [PATCH 2/2] fixup! remove redundant braces --- .../generic/vector/main.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp index 19cd1893bd22a..ec7ef7f84310e 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/vector/main.cpp @@ -12,26 +12,26 @@ void by_ref_and_ptr(std::vector &ref, std::vector *ptr) { int main() { int_vect numbers; - (numbers.push_back(1)); // break here - (numbers.push_back(12)); // break here - (numbers.push_back(123)); - (numbers.push_back(1234)); - (numbers.push_back(12345)); // break here - (numbers.push_back(123456)); - (numbers.push_back(1234567)); + numbers.push_back(1); // break here + numbers.push_back(12); // break here + numbers.push_back(123); + numbers.push_back(1234); + numbers.push_back(12345); // break here + numbers.push_back(123456); + numbers.push_back(1234567); by_ref_and_ptr(numbers, &numbers); printf("break here"); numbers.clear(); - (numbers.push_back(7)); // break here + numbers.push_back(7); // break here string_vect strings; - (strings.push_back(std::string("goofy"))); - (strings.push_back(std::string("is"))); - (strings.push_back(std::string("smart"))); + strings.push_back(std::string("goofy")); + strings.push_back(std::string("is")); + strings.push_back(std::string("smart")); printf("break here"); - (strings.push_back(std::string("!!!"))); + strings.push_back(std::string("!!!")); printf("break here"); strings.clear();