[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] Resolve nested types when parsing structures (PR #66879)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 20 08:10:40 PDT 2023


================
@@ -462,3 +462,96 @@ TEST_F(DWARFASTParserClangTests, TestDefaultTemplateParamParsing) {
     }
   }
 }
+
+TEST_F(DWARFASTParserClangTests, EnsureNestedTypesOfTypeAreParsed) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+    - Info
+    - B
+    - C
+    - Mask
+    - Enum
+  debug_abbrev:
+    - Table:
+        - Code:            0x1
+          Tag:             DW_TAG_compile_unit
+          Children:        DW_CHILDREN_yes
+          Attributes:
+            - Attribute:       DW_AT_language
+              Form:            DW_FORM_data2
+        - Code:            0x2
+          Tag:             DW_TAG_structure_type
+          Children:        DW_CHILDREN_yes
+          Attributes:
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_strp
+        - Code:            0x3
+          Tag:             DW_TAG_union_type
+          Children:        DW_CHILDREN_no
+          Attributes:
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_strp
+        - Code:            0x4
+          Tag:             DW_TAG_structure_type
+          Children:        DW_CHILDREN_no
+          Attributes:
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_strp
+        - Code:            0x5
+          Tag:             DW_TAG_enumeration_type
+          Children:        DW_CHILDREN_yes
----------------
Michael137 wrote:

It might be worth just writing an API test instead. The yaml looks fine to me and we could use it to write a unit-test as a follow-up, but we'll have to jump through some hoops to get the unit-test down the code-path we want anyway. So an API test would be sufficient.

See reference example: https://github.com/llvm/llvm-project/blob/main/lldb/test/API/lang/cpp/bool/TestCPPBool.py

Put your test program into a `main.cpp` and call the relevant member types from the expression evaluator using `self.expect_expr()` in the python test file. E.g., for this change the test would like:
```
class NestedTypesTestCase(TestBase):                                                   
    def test_with_run_command(self):                                               
        """Test that referencing nested types work in the expression parser"""                   
        self.build()                                                               
        lldbutil.run_to_source_breakpoint(                                         
            self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")                   
        )                                                                          
                                                                                   
        self.expect_expr(                                                          
            "Info::Mask::Enum",                             
            result_type=......,
            result_value=....,                                                  
        )                                                                          
        self.expect_expr("Info::B::val", result_type=..., result_value=...)
```

Let me know if you need more details on this.

https://github.com/llvm/llvm-project/pull/66879


More information about the lldb-commits mailing list