[Lldb-commits] [lldb] 8262ff4 - [lldb/test] Add a couple of libc++ std::string layouts

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 7 07:20:26 PDT 2022


Author: Pavel Labath
Date: 2022-07-07T16:20:20+02:00
New Revision: 8262ff44c53568564dc919a43fae274c8b748176

URL: https://github.com/llvm/llvm-project/commit/8262ff44c53568564dc919a43fae274c8b748176
DIFF: https://github.com/llvm/llvm-project/commit/8262ff44c53568564dc919a43fae274c8b748176.diff

LOG: [lldb/test] Add a couple of libc++ std::string layouts

.. to the "string simulator" test. These layouts were used at some point in
the past few months, and are already supported by the code.

Added: 
    

Modified: 
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/TestDataFormatterLibcxxStringSimulator.py
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/TestDataFormatterLibcxxStringSimulator.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/TestDataFormatterLibcxxStringSimulator.py
index 76cd64660aab0..e156447121cca 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/TestDataFormatterLibcxxStringSimulator.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/TestDataFormatterLibcxxStringSimulator.py
@@ -8,6 +8,7 @@
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+import functools
 
 
 class LibcxxStringDataFormatterSimulatorTestCase(TestBase):
@@ -23,23 +24,13 @@ def _run_test(self, defines):
         self.expect_var_path("shortstring", summary='"short"')
         self.expect_var_path("longstring", summary='"I am a very long string"')
 
-    def test_v1_layout(self):
-        """ Current v1 layout. """
-        self._run_test([])
-
-    def test_v2_layout(self):
-        """ Current v2 layout. """
-        self._run_test(["ALTERNATE_LAYOUT"])
-
-    def test_v1_layout_bitmasks(self):
-        """ Pre-D123580 v1 layout. """
-        self._run_test(["BITMASKS"])
-
-    def test_v2_layout_bitmasks(self):
-        """ Pre-D123580 v2 layout. """
-        self._run_test(["ALTERNATE_LAYOUT", "BITMASKS"])
-
-    def test_v2_layout_subclass_padding(self):
-        """ Pre-c3d0205ee771 v2 layout. """
-        self._run_test(["ALTERNATE_LAYOUT", "BITMASKS", "SUBCLASS_PADDING"])
-
+for v in [None, "ALTERNATE_LAYOUT"]:
+    for r in range(5):
+        name = "test_r%d"%r
+        defines = ["REVISION=%d"%r]
+        if v:
+            name += "_" + v
+            defines += [v]
+        f = functools.partialmethod(
+                LibcxxStringDataFormatterSimulatorTestCase._run_test, defines)
+        setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp
index 4852dfd456687..33e71044482a7 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/simulator/main.cpp
@@ -2,6 +2,33 @@
 #include <memory>
 #include <type_traits>
 
+#if REVISION == 0
+// Pre-c3d0205ee771 layout.
+#define SUBCLASS_PADDING
+#endif
+#if REVISION <= 1
+// Pre-D123580 layout.
+#define BITMASKS
+#endif
+#if REVISION <= 2
+// Pre-D125496 layout.
+#define SHORT_UNION
+#endif
+#if REVISION == 3
+// Pre-D128285 layout.
+#define PACKED_ANON_STRUCT
+#endif
+// REVISION == 4: current layout
+
+#ifdef PACKED_ANON_STRUCT
+#define BEGIN_PACKED_ANON_STRUCT struct __attribute__((packed)) {
+#define END_PACKED_ANON_STRUCT };
+#else
+#define BEGIN_PACKED_ANON_STRUCT
+#define END_PACKED_ANON_STRUCT
+#endif
+
+
 namespace std {
 namespace __lldb {
 
@@ -110,8 +137,10 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
 #ifdef BITMASKS
     size_type __cap_;
 #else
+    BEGIN_PACKED_ANON_STRUCT
     size_type __is_long_ : 1;
     size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
+    END_PACKED_ANON_STRUCT
 #endif
     size_type __size_;
     pointer __data_;
@@ -124,6 +153,7 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
   };
 
   struct __short {
+#ifdef SHORT_UNION
     union {
 #ifdef BITMASKS
       unsigned char __size_;
@@ -135,6 +165,13 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
 #endif
       value_type __lx;
     };
+#else
+    BEGIN_PACKED_ANON_STRUCT
+    unsigned char __is_long_ : 1;
+    unsigned char __size_ : 7;
+    END_PACKED_ANON_STRUCT
+    char __padding_[sizeof(value_type) - 1];
+#endif
     value_type __data_[__min_cap];
   };
 


        


More information about the lldb-commits mailing list