Skip to content
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

[lldb][test] Add FindGlobalVariables tests for C++ inline static data members #70641

Merged

Conversation

Michael137
Copy link
Member

Tests that LLDB can find inline static data members.

Relies on the debug-info change in: #70639

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 30, 2023

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

Tests that LLDB can find inline static data members.

Relies on the debug-info change in: #70639


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

1 Files Affected:

  • (modified) lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py (+31)
diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
index 530191e8a37ba1b..8944044d5a265c0 100644
--- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -113,6 +113,37 @@ def test_class_with_only_const_static(self):
 
         self.expect_expr("ClassWithOnlyConstStatic::member", result_value="3")
 
+    def check_global_var(self, name: str, expect_type, expect_val):
+        var_list = self.target().FindGlobalVariables(name, lldb.UINT32_MAX)
+        self.assertEqual(len(var_list), 1)
+        varobj = var_list[0]
+        self.assertEqual(varobj.type.name, expect_type)
+        self.assertEqual(varobj.value, expect_val)
+
+    # For debug-info produced by older versions of clang, inline static data members
+    # wouldn't get indexed into the Names accelerator table preventing LLDB from finding
+    # them.
+    @expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"])
+    @expectedFailureAll(debug_info=no_match(["dsym"]))
+    def test_inline_static_members(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(
+            self, "// break here", lldb.SBFileSpec("main.cpp")
+        )
+
+        self.check_global_var("A::int_val", "const int", "1")
+        self.check_global_var("A::int_val_with_address", "const int", "2")
+        self.check_global_var("A::bool_val", "const bool", "true")
+        self.check_global_var("A::enum_val", "Enum", "enum_case2")
+        self.check_global_var("A::enum_bool_val", "EnumBool", "enum_bool_case1")
+        self.check_global_var("A::scoped_enum_val", "ScopedEnum", "scoped_enum_case2")
+
+        self.check_global_var("ClassWithOnlyConstStatic::member", "const int", "3")
+
+        self.check_global_var("ClassWithConstexprs::member", "const int", "2")
+        self.check_global_var("ClassWithConstexprs::enum_val", "Enum", "enum_case2")
+        self.check_global_var("ClassWithConstexprs::scoped_enum_val", "ScopedEnum", "scoped_enum_case2")
+
     # With older versions of Clang, LLDB fails to evaluate classes with only
     # constexpr members when dsymutil is enabled
     @expectedFailureAll(

# wouldn't get indexed into the Names accelerator table preventing LLDB from finding
# them.
@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"])
@expectedFailureAll(debug_info=no_match(["dsym"]))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a separate issue to do with how variable DIEs are parsed when debug maps are present. Will fix in a follow-up

@Michael137 Michael137 changed the title [lldb][test] Add FindGlobalVariables tests for C++ constexpr static data members [lldb][test] Add FindGlobalVariables tests for C++ inline static data members Oct 30, 2023
@github-actions
Copy link

github-actions bot commented Oct 30, 2023

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

Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

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

This will be great to get it (this PR and the related one). The tests LGTM.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

LGTM modulo formatting

@Michael137 Michael137 merged commit 934c573 into llvm:main Nov 6, 2023
3 checks passed
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Nov 6, 2023
…tic data members (llvm#70641)"

This reverts commit 934c573.

We had to revert dependencies of this patch due to test failures
on Linux:
```
4909814
ef3feba
```
Michael137 added a commit that referenced this pull request Nov 7, 2023
…tic data members (#70641)"

Tests that LLDB can find inline static data members.

Relies on the debug-info change in:
#70639
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