Skip to content

Commit 23fd0c8

Browse files
committed
Add debug info for enums.
Previously enums were reduced to the underlying type. Now the symbolic constants can be used. This is a bug-fixed version of commit 001a396.
1 parent e556882 commit 23fd0c8

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

gen/todebug.cpp

+33-7
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,35 @@ static llvm::DIType dwarfBasicType(Type* type)
149149
static llvm::DIType dwarfEnumType(Type *type)
150150
{
151151
llvm::Type *T = DtoType(type);
152-
Type *t = type->toBasetype();
153152

154-
// FIXME
153+
assert(type->ty == Tenum && "only enums allowed for debug info in dwarfEnumType");
154+
TypeEnum *te = static_cast<TypeEnum *>(type);
155+
llvm::SmallVector<llvm::Value *, 8> subscripts;
156+
for (ArrayIter<Dsymbol> it(te->sym->members); it.more(); it.next())
157+
{
158+
EnumMember *em = it->isEnumMember();
159+
llvm::StringRef Name(em->toChars() /*em->ident->string*/);
160+
uint64_t Val = em->value->toInteger();
161+
llvm::Value *Subscript = gIR->dibuilder.createEnumerator(Name, Val);
162+
subscripts.push_back(Subscript);
163+
}
155164

156-
return llvm::DIType(NULL);
165+
llvm::StringRef Name = te->toChars();
166+
unsigned LineNumber = te->sym->loc.linnum;
167+
llvm::DIFile File = DtoDwarfFile(te->sym->loc);
168+
169+
return gIR->dibuilder.createEnumerationType(
170+
llvm::DIDescriptor(File),
171+
Name,
172+
File,
173+
LineNumber,
174+
getTypeBitSize(T), // size (bits)
175+
getABITypeAlign(T)*8, // align (bits)
176+
gIR->dibuilder.getOrCreateArray(subscripts) // subscripts
177+
#if LDC_LLVM_VER >= 302
178+
, dwarfTypeDescription_impl(te->sym->memtype, NULL)
179+
#endif
180+
);
157181
}
158182

159183
//////////////////////////////////////////////////////////////////////////////////////////////////
@@ -463,12 +487,14 @@ static llvm::DIType dwarfTypeDescription_impl(Type* type, const char* c_name)
463487
Type* t = type->toBasetype();
464488
if (t->ty == Tvoid)
465489
return llvm::DIType(NULL);
466-
else if (t->ty == Tvector)
467-
return dwarfVectorType(type);
468-
else if (t->ty == Tenum)
469-
return dwarfEnumType(type);
470490
else if (t->isintegral() || t->isfloating())
491+
{
492+
if (t->ty == Tvector)
493+
return dwarfVectorType(type);
494+
if (type->ty == Tenum)
495+
return dwarfEnumType(type);
471496
return dwarfBasicType(type);
497+
}
472498
else if (t->ty == Tpointer)
473499
return dwarfPointerType(type);
474500
else if (t->ty == Tarray)

0 commit comments

Comments
 (0)