JDevlieghere created this revision.
JDevlieghere added reviewers: Michael137, bulbazord, jasonmolenda.
Herald added a project: All.
JDevlieghere requested review of this revision.

Fix CTF parsing of large structs. If the size of a struct exceeds a certain 
threshold, the offset is encoded using two 32-bit integers instead of one.


https://reviews.llvm.org/D156490

Files:
  lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
  lldb/test/API/macosx/ctf/Makefile
  lldb/test/API/macosx/ctf/TestCTF.py
  lldb/test/API/macosx/ctf/test.c

Index: lldb/test/API/macosx/ctf/test.c
===================================================================
--- lldb/test/API/macosx/ctf/test.c
+++ lldb/test/API/macosx/ctf/test.c
@@ -31,8 +31,14 @@
   void (*f)(int);
 } MyStructT;
 
+struct LargeStruct {
+  char buffer[9000];
+  int b;
+};
+
 MyStructT foo;
 struct ForwardDecl *forward;
+struct LargeStruct bar;
 
 void populate(MyInt i) {
   foo.n.i = i;
@@ -45,6 +51,7 @@
   foo.n.e = eOne;
   foo.f = NULL;
   forward = NULL;
+  bar.b = i;
 }
 
 int main(int argc, char** argv) {
Index: lldb/test/API/macosx/ctf/TestCTF.py
===================================================================
--- lldb/test/API/macosx/ctf/TestCTF.py
+++ lldb/test/API/macosx/ctf/TestCTF.py
@@ -37,6 +37,9 @@
 
         symbol_file = self.getBuildArtifact("a.ctf")
 
+        if self.TraceOn():
+            self.runCmd("log enable -v lldb symbol")
+
         self.runCmd("target symbols add {}".format(symbol_file))
         self.expect(
             "target variable foo",
@@ -53,7 +56,6 @@
                 "f = 0x0000000000000000",
             ],
         )
-
         self.expect("target variable foo.n.i", substrs=["(MyInt) foo.n.i = 1"])
         self.expect(
             "target variable foo.n.s", substrs=["(const char *) foo.n.s", '"foo"']
@@ -80,3 +82,12 @@
         )
 
         self.expect(" type lookup ForwardDecl", substrs=["struct ForwardDecl"])
+
+        self.expect(
+            "type lookup LargeStruct",
+            substrs=[
+                "struct LargeStruct",
+                "char buffer[9000]",
+                "int b ",
+            ],
+        )
Index: lldb/test/API/macosx/ctf/Makefile
===================================================================
--- lldb/test/API/macosx/ctf/Makefile
+++ lldb/test/API/macosx/ctf/Makefile
@@ -28,3 +28,4 @@
 		-R __DWARF,__apple_objc \
 		a.ctf a.ctf
 	rm -rf a.out.dSYM
+	rm -rf test.o
Index: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
+++ lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
@@ -254,6 +254,7 @@
 
   static constexpr uint16_t g_ctf_magic = 0xcff1;
   static constexpr uint8_t g_ctf_version = 4;
+  static constexpr uint32_t g_ctf_field_treshold = 8192;
 };
 } // namespace lldb_private
 
Index: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -641,9 +641,15 @@
     for (uint32_t i = 0; i < variable_length; ++i) {
       const uint32_t field_name = m_data.GetU32(&offset);
       const uint32_t type = m_data.GetU32(&offset);
-      const uint16_t field_offset = m_data.GetU16(&offset);
-      const uint16_t padding = m_data.GetU16(&offset);
-      fields.emplace_back(ReadString(field_name), type, field_offset, padding);
+      uint64_t field_offset = 0;
+      if (size < g_ctf_field_treshold) {
+        field_offset = m_data.GetU32(&offset);
+      } else {
+        const uint32_t offset_hi = m_data.GetU32(&offset);
+        const uint32_t offset_lo = m_data.GetU32(&offset);
+        field_offset = (((uint64_t)offset_hi) << 32) | ((uint64_t)offset_lo);
+      }
+      fields.emplace_back(ReadString(field_name), type, field_offset);
     }
     return std::make_unique<CTFRecord>(static_cast<CTFType::Kind>(kind), uid,
                                        name, variable_length, size, fields);
@@ -849,7 +855,6 @@
     if (Symbol *symbol =
             symtab->FindSymbolWithType(eSymbolTypeData, Symtab::eDebugYes,
                                        Symtab::eVisibilityAny, symbol_idx)) {
-
       Variable::RangeList ranges;
       ranges.Append(symbol->GetFileAddress(), symbol->GetByteSize());
 
Index: lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
===================================================================
--- lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
+++ lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
@@ -130,14 +130,12 @@
 struct CTFRecord : public CTFType {
 public:
   struct Field {
-    Field(llvm::StringRef name, uint32_t type, uint16_t offset,
-          uint16_t padding)
-        : name(name), type(type), offset(offset), padding(padding) {}
+    Field(llvm::StringRef name, uint32_t type, uint64_t offset)
+        : name(name), type(type), offset(offset) {}
 
     llvm::StringRef name;
     uint32_t type;
-    uint16_t offset;
-    uint16_t padding;
+    uint64_t offset;
   };
 
   CTFRecord(Kind kind, lldb::user_id_t uid, llvm::StringRef name,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to