Skip to content

Commit 9c70a3d

Browse files
committed
[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
1 parent 5ddc371 commit 9c70a3d

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ struct CTFUnion : public CTFRecord {
163163
: CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
164164
};
165165

166+
struct CTFForward : public CTFType {
167+
CTFForward(lldb::user_id_t uid, llvm::StringRef name)
168+
: CTFType(eForward, uid, name) {}
169+
};
170+
166171
} // namespace lldb_private
167172

168173
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H

lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,17 @@ SymbolFileCTF::CreateRecord(const CTFRecord &ctf_record) {
525525
decl, record_type, lldb_private::Type::ResolveState::Full);
526526
}
527527

528+
llvm::Expected<lldb::TypeSP>
529+
SymbolFileCTF::CreateForward(const CTFForward &ctf_forward) {
530+
CompilerType forward_compiler_type = m_ast->CreateRecordType(
531+
nullptr, OptionalClangModuleID(), eAccessPublic, ctf_forward.name,
532+
clang::TTK_Struct, eLanguageTypeC);
533+
Declaration decl;
534+
return MakeType(ctf_forward.uid, ConstString(ctf_forward.name), 0, nullptr,
535+
LLDB_INVALID_UID, Type::eEncodingIsUID, decl,
536+
forward_compiler_type, Type::ResolveState::Forward);
537+
}
538+
528539
llvm::Expected<TypeSP> SymbolFileCTF::CreateType(CTFType *ctf_type) {
529540
if (!ctf_type)
530541
return llvm::make_error<llvm::StringError>(
@@ -549,9 +560,10 @@ llvm::Expected<TypeSP> SymbolFileCTF::CreateType(CTFType *ctf_type) {
549560
case CTFType::Kind::eStruct:
550561
case CTFType::Kind::eUnion:
551562
return CreateRecord(*static_cast<CTFRecord *>(ctf_type));
563+
case CTFType::Kind::eForward:
564+
return CreateForward(*static_cast<CTFForward *>(ctf_type));
552565
case CTFType::Kind::eUnknown:
553566
case CTFType::Kind::eFloat:
554-
case CTFType::Kind::eForward:
555567
case CTFType::Kind::eSlice:
556568
return llvm::make_error<llvm::StringError>(
557569
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) {
637649
return std::make_unique<CTFRecord>(static_cast<CTFType::Kind>(kind), uid,
638650
name, variable_length, size, fields);
639651
}
652+
case TypeKind::eForward:
653+
return std::make_unique<CTFForward>(uid, name);
640654
case TypeKind::eUnknown:
641655
return std::make_unique<CTFType>(static_cast<CTFType::Kind>(kind), uid,
642656
name);
643657
case TypeKind::eFloat:
644-
case TypeKind::eForward:
645658
case TypeKind::eSlice:
646659
offset += (variable_length * sizeof(uint32_t));
647660
break;

lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class SymbolFileCTF : public lldb_private::SymbolFileCommon {
225225
llvm::Expected<lldb::TypeSP> CreateEnum(const CTFEnum &ctf_enum);
226226
llvm::Expected<lldb::TypeSP> CreateFunction(const CTFFunction &ctf_function);
227227
llvm::Expected<lldb::TypeSP> CreateRecord(const CTFRecord &ctf_record);
228+
llvm::Expected<lldb::TypeSP> CreateForward(const CTFForward &ctf_forward);
228229

229230
llvm::StringRef ReadString(lldb::offset_t offset) const;
230231

lldb/test/API/macosx/ctf/test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <stdio.h>
22

3+
struct ForwardDecl;
4+
35
typedef int MyInt;
46

57
void populate(MyInt i);
@@ -30,6 +32,7 @@ typedef struct MyStruct {
3032
} MyStructT;
3133

3234
MyStructT foo;
35+
struct ForwardDecl *forward;
3336

3437
void populate(MyInt i) {
3538
foo.n.i = i;
@@ -41,6 +44,7 @@ void populate(MyInt i) {
4144
foo.n.a[3] = 'd';
4245
foo.n.e = eOne;
4346
foo.f = NULL;
47+
forward = NULL;
4448
}
4549

4650
int main(int argc, char** argv) {

0 commit comments

Comments
 (0)