Skip to content

[lldb] Show value for libcxx and libstdcxx summary and remove pointer value in libcxx container summary #125294

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
Feb 3, 2025

Conversation

ZequanWu
Copy link
Contributor

This has two changes:

  1. Set show value for libcxx and libstdcxx summary provider. This will print the pointer value for both pointer type and reference type.
  2. Remove pointer value printing in libcxx container summary.

Discussion:
https://discourse.llvm.org/t/lldb-hides-raw-pointer-value-for-libcxx-and-libstdcxx-pointer-types-in-summary-string/84226

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2025

@llvm/pr-subscribers-lldb

Author: Zequan Wu (ZequanWu)

Changes

This has two changes:

  1. Set show value for libcxx and libstdcxx summary provider. This will print the pointer value for both pointer type and reference type.
  2. Remove pointer value printing in libcxx container summary.

Discussion:
https://discourse.llvm.org/t/lldb-hides-raw-pointer-value-for-libcxx-and-libstdcxx-pointer-types-in-summary-string/84226


Full diff: https://github.com/llvm/llvm-project/pull/125294.diff

7 Files Affected:

  • (modified) lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (+2-2)
  • (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp (-6)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py (+32-17)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py (+1-4)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py (+1-1)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py (+32-17)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py (+1-1)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 2bf574e97768ec..4b045d12ad4947 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -641,7 +641,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
       .SetSkipPointers(false)
       .SetSkipReferences(false)
       .SetDontShowChildren(true)
-      .SetDontShowValue(true)
+      .SetDontShowValue(false)
       .SetShowMembersOneLiner(false)
       .SetHideItemNames(false);
 
@@ -1204,7 +1204,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
       .SetSkipPointers(false)
       .SetSkipReferences(false)
       .SetDontShowChildren(true)
-      .SetDontShowValue(true)
+      .SetDontShowValue(false)
       .SetShowMembersOneLiner(false)
       .SetHideItemNames(false);
 
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 6d0ccdbbe4a71d..2aa8fdba706348 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -430,12 +430,6 @@ size_t lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::
 
 bool lldb_private::formatters::LibcxxContainerSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  if (valobj.IsPointerType()) {
-    uint64_t value = valobj.GetValueAsUnsigned(0);
-    if (!value)
-      return false;
-    stream.Printf("0x%016" PRIx64 " ", value);
-  }
   return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
                                        nullptr, nullptr, &valobj, false, false);
 }
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
index 3596b546be306a..8f8af60d4e9728 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
@@ -9,22 +9,37 @@
 
 
 class LibcxxDequeDataFormatterTestCase(TestBase):
-    def check_numbers(self, var_name):
-        self.expect(
-            "frame variable " + var_name,
-            substrs=[
-                var_name + " = size=7",
-                "[0] = 1",
-                "[1] = 12",
-                "[2] = 123",
-                "[3] = 1234",
-                "[4] = 12345",
-                "[5] = 123456",
-                "[6] = 1234567",
-                "}",
-            ],
-        )
-
+    def check_numbers(self, var_name, show_ptr = False):
+        if show_ptr:
+            self.expect(
+                "frame variable " + var_name,
+                patterns=[var_name + " = 0x.* size=7"],
+                substrs=[
+                    "[0] = 1",
+                    "[1] = 12",
+                    "[2] = 123",
+                    "[3] = 1234",
+                    "[4] = 12345",
+                    "[5] = 123456",
+                    "[6] = 1234567",
+                    "}",
+                ],
+            )
+        else:
+            self.expect(
+                "frame variable " + var_name,
+                substrs=[
+                    var_name + " = size=7",
+                    "[0] = 1",
+                    "[1] = 12",
+                    "[2] = 123",
+                    "[3] = 1234",
+                    "[4] = 12345",
+                    "[5] = 123456",
+                    "[6] = 1234567",
+                    "}",
+                ],
+            )
         self.expect_expr(
             var_name,
             result_summary="size=7",
@@ -75,7 +90,7 @@ def test_ref_and_ptr(self):
         )
 
         # The reference should display the same was as the value did
-        self.check_numbers("ref")
+        self.check_numbers("ref", True)
 
         # The pointer should just show the right number of elements:
         self.expect("frame variable ptr", substrs=["ptr =", " size=7"])
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
index d5de73ac14ca14..4df4fa1acc8e77 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
@@ -172,7 +172,4 @@ def test_ref_and_ptr(self):
 
         # The pointer should just show the right number of elements:
 
-        ptrAddr = self.findVariable("ptr").GetValue()
-        self.expect_expr(
-            "ptr", result_type="std::span<int, 5> *", result_summary=f"{ptrAddr} size=5"
-        )
+        self.expect("frame variable ptr", patterns=["ptr = 0x.*", " size=5"])
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
index 4154ad3c297fab..47e07a5ce3f5b1 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
@@ -47,7 +47,7 @@ def test_with_run_command(self):
 
         self.expect(
             "frame variable v1_ref",
-            substrs=["v1_ref =  Active Type = int : {", "Value = 12", "}"],
+            patterns=["v1_ref = 0x.* Active Type = int : {", "Value = 12", "}"],
         )
 
         self.expect(
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/libcxx/vector/TestDataFormatterLibcxxVector.py
index a475c15d3da347..cabb7fbaed39a9 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/libcxx/vector/TestDataFormatterLibcxxVector.py
@@ -10,22 +10,37 @@
 
 
 class LibcxxVectorDataFormatterTestCase(TestBase):
-    def check_numbers(self, var_name):
-        self.expect(
-            "frame variable " + var_name,
-            substrs=[
-                var_name + " = size=7",
-                "[0] = 1",
-                "[1] = 12",
-                "[2] = 123",
-                "[3] = 1234",
-                "[4] = 12345",
-                "[5] = 123456",
-                "[6] = 1234567",
-                "}",
-            ],
-        )
-
+    def check_numbers(self, var_name, show_ptr = False):
+        if show_ptr:           
+            self.expect(
+                "frame variable " + var_name,
+                patterns=[var_name + " = 0x.* size=7"],
+                substrs=[
+                    "[0] = 1",
+                    "[1] = 12",
+                    "[2] = 123",
+                    "[3] = 1234",
+                    "[4] = 12345",
+                    "[5] = 123456",
+                    "[6] = 1234567",
+                    "}",
+                ],
+            )
+        else:
+            self.expect(
+                "frame variable " + var_name,
+                substrs=[
+                    var_name + " = size=7",
+                    "[0] = 1",
+                    "[1] = 12",
+                    "[2] = 123",
+                    "[3] = 1234",
+                    "[4] = 12345",
+                    "[5] = 123456",
+                    "[6] = 1234567",
+                    "}",
+                ],
+            )
         self.expect_expr(
             var_name,
             result_summary="size=7",
@@ -174,7 +189,7 @@ def test_ref_and_ptr(self):
         )
 
         # The reference should display the same was as the value did
-        self.check_numbers("ref")
+        self.check_numbers("ref", True)
 
         # The pointer should just show the right number of elements:
 
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index ea4a53fcb4097a..394e221809f7c4 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -30,7 +30,7 @@ def test_with_run_command(self):
         for name in ["v1_ref", "v1_typedef_ref"]:
             self.expect(
                 "frame variable " + name,
-                substrs=[name + " =  Active Type = int : {", "Value = 12", "}"],
+                patterns=[name + " = 0x.*  Active Type = int : {", "Value = 12", "}"],
             )
 
         self.expect(

self.expect_expr(
"ptr", result_type="std::span<int, 5> *", result_summary=f"{ptrAddr} size=5"
)
self.expect("frame variable ptr", patterns=["ptr = 0x.*", " size=5"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SBValue::GetValue essentially uses the summary string provided by summary provider. So it returns "size=5" after I removed the pointer value in libcxx container summary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but you can still use expect_expr to match this. You just need to say result_summary=re.compile("your_pattern")

Copy link

github-actions bot commented Jan 31, 2025

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, better to be consistent, and the pointer value is useful.

self.expect_expr(
"ptr", result_type="std::span<int, 5> *", result_summary=f"{ptrAddr} size=5"
)
self.expect("frame variable ptr", patterns=["ptr = 0x.*", " size=5"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but you can still use expect_expr to match this. You just need to say result_summary=re.compile("your_pattern")

@ZequanWu ZequanWu merged commit e269c2b into llvm:main Feb 3, 2025
7 checks passed
@ZequanWu ZequanWu deleted the ptr-val branch February 3, 2025 19:34
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
… value in libcxx container summary (llvm#125294)

This has two changes:
1. Set show value for libcxx and libstdcxx summary provider. This will
print the pointer value for both pointer type and reference type.
2. Remove pointer value printing in libcxx container summary.

Discussion:

https://discourse.llvm.org/t/lldb-hides-raw-pointer-value-for-libcxx-and-libstdcxx-pointer-types-in-summary-string/84226
2over12 pushed a commit to trailofbits/instafix-llvm that referenced this pull request Mar 12, 2025
…125294)

This includes support for module translation, module import and add tests for both.

Fix llvm#115390
ClangIR cannot currently lower global aliases to LLVM because of missing support for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants