[Lldb-commits] [lldb] 9c70a3d - [lldb] Support CTF forward declarations

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 28 19:10:45 PDT 2023


Author: Jonas Devlieghere
Date: 2023-07-28T19:10:36-07:00
New Revision: 9c70a3d9178f46c3eccb2243286deb1830c276f4

URL: https://github.com/llvm/llvm-project/commit/9c70a3d9178f46c3eccb2243286deb1830c276f4
DIFF: https://github.com/llvm/llvm-project/commit/9c70a3d9178f46c3eccb2243286deb1830c276f4.diff

LOG: [lldb] Support CTF forward declarations

Add support for parsing CTF forward declarations and converting them
into LLDB types.

Differential revision: https://reviews.llvm.org/D156483

Added: 
    

Modified: 
    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/test.c

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
index 8c6ee278bbe356..b2cf5cf3191b64 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
+++ b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
@@ -163,6 +163,11 @@ struct CTFUnion : public CTFRecord {
       : CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
 };
 
+struct CTFForward : public CTFType {
+  CTFForward(lldb::user_id_t uid, llvm::StringRef name)
+      : CTFType(eForward, uid, name) {}
+};
+
 } // namespace lldb_private
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H

diff  --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
index 2798bc674471e1..f737db3ed4e4b2 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -525,6 +525,17 @@ SymbolFileCTF::CreateRecord(const CTFRecord &ctf_record) {
                   decl, record_type, lldb_private::Type::ResolveState::Full);
 }
 
+llvm::Expected<lldb::TypeSP>
+SymbolFileCTF::CreateForward(const CTFForward &ctf_forward) {
+  CompilerType forward_compiler_type = m_ast->CreateRecordType(
+      nullptr, OptionalClangModuleID(), eAccessPublic, ctf_forward.name,
+      clang::TTK_Struct, eLanguageTypeC);
+  Declaration decl;
+  return MakeType(ctf_forward.uid, ConstString(ctf_forward.name), 0, nullptr,
+                  LLDB_INVALID_UID, Type::eEncodingIsUID, decl,
+                  forward_compiler_type, Type::ResolveState::Forward);
+}
+
 llvm::Expected<TypeSP> SymbolFileCTF::CreateType(CTFType *ctf_type) {
   if (!ctf_type)
     return llvm::make_error<llvm::StringError>(
@@ -549,9 +560,10 @@ llvm::Expected<TypeSP> SymbolFileCTF::CreateType(CTFType *ctf_type) {
   case CTFType::Kind::eStruct:
   case CTFType::Kind::eUnion:
     return CreateRecord(*static_cast<CTFRecord *>(ctf_type));
+  case CTFType::Kind::eForward:
+    return CreateForward(*static_cast<CTFForward *>(ctf_type));
   case CTFType::Kind::eUnknown:
   case CTFType::Kind::eFloat:
-  case CTFType::Kind::eForward:
   case CTFType::Kind::eSlice:
     return llvm::make_error<llvm::StringError>(
         llvm::formatv("unsupported type (uid = {0}, name = {1}, kind = {2})",
@@ -637,11 +649,12 @@ SymbolFileCTF::ParseType(lldb::offset_t &offset, lldb::user_id_t uid) {
     return std::make_unique<CTFRecord>(static_cast<CTFType::Kind>(kind), uid,
                                        name, variable_length, size, fields);
   }
+  case TypeKind::eForward:
+    return std::make_unique<CTFForward>(uid, name);
   case TypeKind::eUnknown:
     return std::make_unique<CTFType>(static_cast<CTFType::Kind>(kind), uid,
                                      name);
   case TypeKind::eFloat:
-  case TypeKind::eForward:
   case TypeKind::eSlice:
     offset += (variable_length * sizeof(uint32_t));
     break;

diff  --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
index 73854275ff674b..f5a78e5b59a908 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
@@ -225,6 +225,7 @@ class SymbolFileCTF : public lldb_private::SymbolFileCommon {
   llvm::Expected<lldb::TypeSP> CreateEnum(const CTFEnum &ctf_enum);
   llvm::Expected<lldb::TypeSP> CreateFunction(const CTFFunction &ctf_function);
   llvm::Expected<lldb::TypeSP> CreateRecord(const CTFRecord &ctf_record);
+  llvm::Expected<lldb::TypeSP> CreateForward(const CTFForward &ctf_forward);
 
   llvm::StringRef ReadString(lldb::offset_t offset) const;
 

diff  --git a/lldb/test/API/macosx/ctf/test.c b/lldb/test/API/macosx/ctf/test.c
index a844a01f82a3db..30be60320c47ff 100644
--- a/lldb/test/API/macosx/ctf/test.c
+++ b/lldb/test/API/macosx/ctf/test.c
@@ -1,5 +1,7 @@
 #include <stdio.h>
 
+struct ForwardDecl;
+
 typedef int MyInt;
 
 void populate(MyInt i);
@@ -30,6 +32,7 @@ typedef struct MyStruct {
 } MyStructT;
 
 MyStructT foo;
+struct ForwardDecl *forward;
 
 void populate(MyInt i) {
   foo.n.i = i;
@@ -41,6 +44,7 @@ void populate(MyInt i) {
   foo.n.a[3] = 'd';
   foo.n.e = eOne;
   foo.f = NULL;
+  forward = NULL;
 }
 
 int main(int argc, char** argv) {


        


More information about the lldb-commits mailing list