Ported to new debug information format introduced in llvm 2.7

This commit is contained in:
Alexey Prokhin 2010-10-30 20:57:32 +04:00
parent 24c92d3a7c
commit d0c7a5a3cb
5 changed files with 113 additions and 426 deletions

View file

@ -195,7 +195,7 @@ add_definitions(
-DIN_LLVM -DIN_LLVM
-D_DH -D_DH
-DOPAQUE_VTBLS -DOPAQUE_VTBLS
-DDISABLE_DEBUG_INFO #-DDISABLE_DEBUG_INFO
) )
if(UNIX) if(UNIX)

View file

@ -1,180 +0,0 @@
// Generated by llvm2cpp - DO NOT MODIFY!
#include <llvm/Module.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Constants.h>
#include <llvm/GlobalVariable.h>
#include <llvm/Function.h>
#include <llvm/CallingConv.h>
#include <llvm/BasicBlock.h>
#include <llvm/Instructions.h>
#include <llvm/InlineAsm.h>
#include <llvm/Attributes.h>
#include <llvm/Support/MathExtras.h>
#include <llvm/Pass.h>
#include <llvm/PassManager.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Assembly/PrintModulePass.h>
#include <algorithm>
void RegisterDwarfSymbols(llvm::Module* mod) {
using namespace llvm;
// Type Definitions
std::vector<const Type*>StructTy_llvm_dbg_anchor_type_fields;
StructTy_llvm_dbg_anchor_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_anchor_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructType* StructTy_llvm_dbg_anchor_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_anchor_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.anchor.type", StructTy_llvm_dbg_anchor_type);
std::vector<const Type*>StructTy_llvm_dbg_basictype_type_fields;
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
std::vector<const Type*>StructTy_1_fields;
StructType* StructTy_1 = StructType::get(mod->getContext(), StructTy_1_fields, /*isPacked=*/false);
PointerType* PointerTy_0 = PointerType::get(StructTy_1,0);
StructTy_llvm_dbg_basictype_type_fields.push_back(PointerTy_0);
PointerType* PointerTy_2 = PointerType::get(IntegerType::get(mod->getContext(), 8),0);
StructTy_llvm_dbg_basictype_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_basictype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_basictype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructType* StructTy_llvm_dbg_basictype_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_basictype_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.basictype.type", StructTy_llvm_dbg_basictype_type);
std::vector<const Type*>StructTy_llvm_dbg_compile_unit_type_fields;
StructTy_llvm_dbg_compile_unit_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_compile_unit_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_compile_unit_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_compile_unit_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_compile_unit_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_compile_unit_type_fields.push_back(PointerTy_2);
StructType* StructTy_llvm_dbg_compile_unit_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_compile_unit_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.compile_unit.type", StructTy_llvm_dbg_compile_unit_type);
std::vector<const Type*>StructTy_llvm_dbg_compositetype_type_fields;
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_compositetype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_compositetype_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_compositetype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_compositetype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_compositetype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_compositetype_type_fields.push_back(PointerTy_0);
StructType* StructTy_llvm_dbg_compositetype_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_compositetype_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.compositetype.type", StructTy_llvm_dbg_compositetype_type);
std::vector<const Type*>StructTy_llvm_dbg_derivedtype_type_fields;
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_derivedtype_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_derivedtype_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_derivedtype_type_fields.push_back(PointerTy_0);
StructType* StructTy_llvm_dbg_derivedtype_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_derivedtype_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.derivedtype.type", StructTy_llvm_dbg_derivedtype_type);
std::vector<const Type*>StructTy_llvm_dbg_global_variable_type_fields;
StructTy_llvm_dbg_global_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_global_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_global_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 1));
StructTy_llvm_dbg_global_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 1));
StructTy_llvm_dbg_global_variable_type_fields.push_back(PointerTy_0);
StructType* StructTy_llvm_dbg_global_variable_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_global_variable_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.global_variable.type", StructTy_llvm_dbg_global_variable_type);
std::vector<const Type*>StructTy_llvm_dbg_subprogram_type_fields;
StructTy_llvm_dbg_subprogram_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_subprogram_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_subprogram_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_subprogram_type_fields.push_back(IntegerType::get(mod->getContext(), 1));
StructTy_llvm_dbg_subprogram_type_fields.push_back(IntegerType::get(mod->getContext(), 1));
StructType* StructTy_llvm_dbg_subprogram_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_subprogram_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.subprogram.type", StructTy_llvm_dbg_subprogram_type);
std::vector<const Type*>StructTy_llvm_dbg_variable_type_fields;
StructTy_llvm_dbg_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_variable_type_fields.push_back(PointerTy_2);
StructTy_llvm_dbg_variable_type_fields.push_back(PointerTy_0);
StructTy_llvm_dbg_variable_type_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_llvm_dbg_variable_type_fields.push_back(PointerTy_0);
StructType* StructTy_llvm_dbg_variable_type = StructType::get(mod->getContext(), StructTy_llvm_dbg_variable_type_fields, /*isPacked=*/false);
mod->addTypeName("llvm.dbg.variable.type", StructTy_llvm_dbg_variable_type);
std::vector<const Type*>FuncTy_3_args;
FuncTy_3_args.push_back(PointerTy_0);
FunctionType* FuncTy_3 = FunctionType::get(
/*Result=*/Type::getVoidTy(mod->getContext()),
/*Params=*/FuncTy_3_args,
/*isVarArg=*/false);
std::vector<const Type*>FuncTy_4_args;
FuncTy_4_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_4_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_4_args.push_back(PointerTy_0);
FunctionType* FuncTy_4 = FunctionType::get(
/*Result=*/Type::getVoidTy(mod->getContext()),
/*Params=*/FuncTy_4_args,
/*isVarArg=*/false);
std::vector<const Type*>FuncTy_5_args;
FuncTy_5_args.push_back(PointerTy_0);
FuncTy_5_args.push_back(PointerTy_0);
FunctionType* FuncTy_5 = FunctionType::get(
/*Result=*/Type::getVoidTy(mod->getContext()),
/*Params=*/FuncTy_5_args,
/*isVarArg=*/false);
// Function Declarations
Function* func_llvm_dbg_func_start = Function::Create(
/*Type=*/FuncTy_3,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"llvm.dbg.func.start", mod); // (external, no body)
func_llvm_dbg_func_start->setCallingConv(CallingConv::C);
Function* func_llvm_dbg_stoppoint = Function::Create(
/*Type=*/FuncTy_4,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"llvm.dbg.stoppoint", mod); // (external, no body)
func_llvm_dbg_stoppoint->setCallingConv(CallingConv::C);
Function* func_llvm_dbg_declare = Function::Create(
/*Type=*/FuncTy_5,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"llvm.dbg.declare", mod); // (external, no body)
func_llvm_dbg_declare->setCallingConv(CallingConv::C);
Function* func_llvm_dbg_region_end = Function::Create(
/*Type=*/FuncTy_3,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"llvm.dbg.region.end", mod); // (external, no body)
func_llvm_dbg_region_end->setCallingConv(CallingConv::C);
}

View file

@ -864,11 +864,7 @@ void DtoConstInitGlobal(VarDeclaration* vd)
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
// do debug info // do debug info
if (global.params.symdebug) if (global.params.symdebug)
{ DtoDwarfGlobalVariable(gvar, vd);
LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV();
// keep a reference so GDCE doesn't delete it !
gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType()));
}
#endif #endif
} }
} }

View file

@ -21,60 +21,6 @@ using namespace llvm::dwarf;
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
#define DBG_NULL ( LLConstant::getNullValue(DBG_TYPE) )
#define DBG_TYPE ( getPtrToType(llvm::StructType::get(gIR->context(),NULL,NULL)) )
#define DBG_CAST(X) ( llvm::ConstantExpr::getBitCast(X, DBG_TYPE) )
#define DBG_TAG(X) ( llvm::ConstantExpr::getAdd( DtoConstUint( X ), DtoConstUint( llvm::LLVMDebugVersion ) ) )
//////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Emits a global variable, LLVM Dwarf style, only declares.
* @param type Type of variable.
* @param name Name.
* @return The global variable.
*/
static LLGlobalVariable* emitDwarfGlobalDecl(const LLStructType* type, const char* name, bool linkonce=false)
{
LLGlobalValue::LinkageTypes linkage = linkonce
? DEBUGINFO_LINKONCE_LINKAGE_TYPE
: LLGlobalValue::InternalLinkage;
LLGlobalVariable* gv = new LLGlobalVariable(*gIR->module, type, true, linkage, NULL, name);
gv->setSection("llvm.metadata");
return gv;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
static const llvm::StructType* getDwarfCompileUnitType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type"));
}
static const llvm::StructType* getDwarfSubProgramType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type"));
}
static const llvm::StructType* getDwarfVariableType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type"));
}
static const llvm::StructType* getDwarfDerivedTypeType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type"));
}
static const llvm::StructType* getDwarfBasicTypeType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type"));
}
static const llvm::StructType* getDwarfCompositeTypeType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type"));
}
static const llvm::StructType* getDwarfGlobalVariableType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type"));
}
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
// get the module the symbol is in, or - for template instances - the current module // get the module the symbol is in, or - for template instances - the current module
@ -102,6 +48,21 @@ static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, con
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
llvm::DIFile DtoDwarfFile(Loc loc, llvm::DICompileUnit compileUnit)
{
llvm::StringRef path;
llvm::StringRef name;
llvm::StringRef dir;
if (loc.filename) {
path = llvm::StringRef(loc.filename);
name = llvm::StringRef(basename(loc.filename));
dir = path.substr(0, path.size() - name.size());
}
return gIR->difactory.CreateFile(name, dir, compileUnit);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
static llvm::DIBasicType dwarfBasicType(Type* type, llvm::DICompileUnit compileUnit) static llvm::DIBasicType dwarfBasicType(Type* type, llvm::DICompileUnit compileUnit)
{ {
Type* t = type->toBasetype(); Type* t = type->toBasetype();
@ -128,7 +89,7 @@ static llvm::DIBasicType dwarfBasicType(Type* type, llvm::DICompileUnit compileU
return gIR->difactory.CreateBasicType( return gIR->difactory.CreateBasicType(
compileUnit, // context compileUnit, // context
type->toChars(), // name type->toChars(), // name
llvm::DICompileUnit(NULL), // compile unit DtoDwarfFile(Loc(gIR->dmodule, 0), DtoDwarfCompileUnit(gIR->dmodule)), // file
0, // line number 0, // line number
getTypeBitSize(T), // size (bits) getTypeBitSize(T), // size (bits)
getABITypeAlign(T)*8, // align (bits) getABITypeAlign(T)*8, // align (bits)
@ -159,7 +120,7 @@ static llvm::DIDerivedType dwarfDerivedType(Type* type, llvm::DICompileUnit comp
DW_TAG_pointer_type, // tag DW_TAG_pointer_type, // tag
compileUnit, // context compileUnit, // context
"", // name "", // name
llvm::DICompileUnit(NULL), // compile unit DtoDwarfFile(Loc(gIR->dmodule, 0), DtoDwarfCompileUnit(gIR->dmodule)), // file
0, // line number 0, // line number
getTypeBitSize(T), // size (bits) getTypeBitSize(T), // size (bits)
getABITypeAlign(T)*8, // align (bits) getABITypeAlign(T)*8, // align (bits)
@ -172,7 +133,7 @@ static llvm::DIDerivedType dwarfDerivedType(Type* type, llvm::DICompileUnit comp
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DICompileUnit compileUnit, llvm::DICompileUnit definedCU, const char* c_name, unsigned offset) static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DICompileUnit compileUnit, llvm::DIFile file, const char* c_name, unsigned offset)
{ {
const LLType* T = DtoType(type); const LLType* T = DtoType(type);
Type* t = type->toBasetype(); Type* t = type->toBasetype();
@ -187,7 +148,7 @@ static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DI
DW_TAG_member, // tag DW_TAG_member, // tag
compileUnit, // context compileUnit, // context
c_name, // name c_name, // name
definedCU, // compile unit file, // file
linnum, // line number linnum, // line number
getTypeBitSize(T), // size (bits) getTypeBitSize(T), // size (bits)
getABITypeAlign(T)*8, // align (bits) getABITypeAlign(T)*8, // align (bits)
@ -203,12 +164,12 @@ static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DI
static void add_base_fields( static void add_base_fields(
ClassDeclaration* sd, ClassDeclaration* sd,
llvm::DICompileUnit compileUnit, llvm::DICompileUnit compileUnit,
llvm::DICompileUnit definedCU, llvm::DIFile file,
std::vector<LLConstant*>& elems) std::vector<llvm::DIDescriptor>& elems)
{ {
if (sd->baseClass) if (sd->baseClass)
{ {
add_base_fields(sd->baseClass, compileUnit, definedCU, elems); add_base_fields(sd->baseClass, compileUnit, file, elems);
} }
ArrayIter<VarDeclaration> it(sd->fields); ArrayIter<VarDeclaration> it(sd->fields);
@ -217,11 +178,12 @@ static void add_base_fields(
for (; !it.done(); it.next()) for (; !it.done(); it.next())
{ {
VarDeclaration* vd = it.get(); VarDeclaration* vd = it.get();
LLGlobalVariable* ptr = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, definedCU, vd->toChars(), vd->offset).getGV(); elems.push_back(dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, file, vd->toChars(), vd->offset));
elems.push_back(DBG_CAST(ptr));
} }
} }
//FIXME: This does not use llvm's DIFactory as it can't //FIXME: This does not use llvm's DIFactory as it can't
// handle recursive types properly. // handle recursive types properly.
static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit) static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit)
@ -230,38 +192,28 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
Type* t = type->toBasetype(); Type* t = type->toBasetype();
// defaults // defaults
LLConstant* name = getNullPtr(getVoidPtrType()); llvm::StringRef name;
LLGlobalVariable* members = NULL;
unsigned linnum = 0; unsigned linnum = 0;
llvm::DICompileUnit definedCU; llvm::DIFile file;
// prepare tag and members // prepare tag and members
unsigned tag; unsigned tag;
// declare final global variable // elements
LLGlobalVariable* gv = NULL; std::vector<llvm::DIDescriptor> elems;
// pointer to ir->diCompositeType
llvm::DICompositeType *diCompositeType = 0;
llvm::DICompositeType derivedFrom;
// dynamic array // dynamic array
if (t->ty == Tarray) if (t->ty == Tarray)
{ {
tag = DW_TAG_structure_type; tag = DW_TAG_structure_type;
elems.push_back(dwarfMemberType(0, Type::tsize_t, compileUnit, file, "length", 0));
LLGlobalVariable* len = dwarfMemberType(0, Type::tsize_t, compileUnit, llvm::DICompileUnit(NULL), "length", 0).getGV(); elems.push_back(dwarfMemberType(0, t->nextOf()->pointerTo(), compileUnit, file, "ptr", global.params.is64bit?8:4));
assert(len); file = DtoDwarfFile(Loc(gIR->dmodule, 0), DtoDwarfCompileUnit(gIR->dmodule));
LLGlobalVariable* ptr = dwarfMemberType(0, t->nextOf()->pointerTo(), compileUnit, llvm::DICompileUnit(NULL), "ptr", global.params.is64bit?8:4).getGV();
assert(ptr);
const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2);
std::vector<LLConstant*> elems(2);
elems[0] = DBG_CAST(len);
elems[1] = DBG_CAST(ptr);
LLConstant* ca = LLConstantArray::get(at, elems);
members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
members->setSection("llvm.metadata");
name = DtoConstStringPtr(t->toChars(), "llvm.metadata");
} }
// struct/class // struct/class
@ -272,11 +224,13 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
{ {
TypeStruct* ts = (TypeStruct*)t; TypeStruct* ts = (TypeStruct*)t;
sd = ts->sym; sd = ts->sym;
tag = DW_TAG_structure_type;
} }
else else
{ {
TypeClass* tc = (TypeClass*)t; TypeClass* tc = (TypeClass*)t;
sd = tc->sym; sd = tc->sym;
tag = DW_TAG_class_type;
} }
assert(sd); assert(sd);
@ -290,26 +244,28 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
IrStruct* ir = sd->ir.irStruct; IrStruct* ir = sd->ir.irStruct;
assert(ir); assert(ir);
if (!ir->diCompositeType.isNull()) if ((llvm::MDNode*)ir->diCompositeType != 0)
return ir->diCompositeType; return ir->diCompositeType;
// set to handle recursive types properly diCompositeType = &ir->diCompositeType;
gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype"); name = sd->toChars();
// set bogus initializer to satisfy asserts in DICompositeType constructor
std::vector<LLConstant*> initvals(11);
initvals[0] = DBG_TAG(DW_TAG_structure_type);
for (int i = 1; i < initvals.size(); ++i)
initvals[i] = LLConstant::getNullValue(getDwarfCompositeTypeType()->getContainedType(i));
gv->setInitializer(LLConstantStruct::get(getDwarfCompositeTypeType(), initvals));
ir->diCompositeType = llvm::DICompositeType(gv);
tag = DW_TAG_structure_type;
name = DtoConstStringPtr(sd->toChars(), "llvm.metadata");
linnum = sd->loc.linnum; linnum = sd->loc.linnum;
definedCU = DtoDwarfCompileUnit(getDefinedModule(sd)); file = DtoDwarfFile(sd->loc, DtoDwarfCompileUnit(getDefinedModule(sd)));
// set diCompositeType to handle recursive types properly
ir->diCompositeType = gIR->difactory.CreateCompositeTypeEx(
tag, // tag
compileUnit, // context
name, // name
file, // compile unit where defined
linnum, // line number where defined
LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getTypeBitSize(T), false), // size in bits
LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getABITypeAlign(T)*8, false), // alignment in bits
LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 0, false), // offset in bits,
0, // flags
derivedFrom, // DerivedFrom
llvm::DIArray(0)
);
std::vector<LLConstant*> elems;
if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one
{ {
if (t->ty == Tstruct) if (t->ty == Tstruct)
@ -320,20 +276,18 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
for (; !it.done(); it.next()) for (; !it.done(); it.next())
{ {
VarDeclaration* vd = it.get(); VarDeclaration* vd = it.get();
LLGlobalVariable* ptr = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, definedCU, vd->toChars(), vd->offset).getGV(); llvm::DIDerivedType dt = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, file, vd->toChars(), vd->offset);
elems.push_back(DBG_CAST(ptr)); elems.push_back(dt);
} }
} }
else else
{ {
add_base_fields(ir->aggrdecl->isClassDeclaration(), compileUnit, definedCU, elems); ClassDeclaration *classDecl = ir->aggrdecl->isClassDeclaration();
add_base_fields(classDecl, compileUnit, file, elems);
if (classDecl->baseClass)
derivedFrom = dwarfCompositeType(classDecl->baseClass->getType(), compileUnit);
} }
} }
const LLArrayType* at = LLArrayType::get(DBG_TYPE, elems.size());
LLConstant* ca = LLConstantArray::get(at, elems);
members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
members->setSection("llvm.metadata");
} }
// unsupported composite type // unsupported composite type
@ -342,54 +296,24 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
assert(0 && "unsupported compositetype for debug info"); assert(0 && "unsupported compositetype for debug info");
} }
std::vector<LLConstant*> vals(11); llvm::DIArray elemsArray =
gIR->difactory.GetOrCreateArray(elems.data(), elems.size());
// tag llvm::DICompositeType ret = gIR->difactory.CreateCompositeTypeEx(
vals[0] = DBG_TAG(tag); tag, // tag
compileUnit, // context
// context name, // name
vals[1] = DBG_CAST(compileUnit.getGV()); file, // compile unit where defined
linnum, // line number where defined
// name LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getTypeBitSize(T), false), // size in bits
vals[2] = name; LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getABITypeAlign(T)*8, false), // alignment in bits
LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 0, false), // offset in bits,
// compile unit where defined 0, // flags
if (definedCU.getGV()) derivedFrom, // DerivedFrom
vals[3] = DBG_CAST(definedCU.getGV()); elemsArray);
else if (diCompositeType)
vals[3] = DBG_NULL; *diCompositeType = ret;
return ret;
// line number where defined
vals[4] = DtoConstInt(linnum);
// size in bits
vals[5] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getTypeBitSize(T), false);
// alignment in bits
vals[6] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getABITypeAlign(T)*8, false);
// offset in bits
vals[7] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 0, false);
// FIXME: dont know what this is
vals[8] = DtoConstUint(0);
// FIXME: ditto
vals[9] = DBG_NULL;
// members array
if (members)
vals[10] = DBG_CAST(members);
else
vals[10] = DBG_NULL;
// set initializer
if (!gv)
gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype");
LLConstant* initia = LLConstantStruct::get(getDwarfCompositeTypeType(), vals);
gv->setInitializer(initia);
return llvm::DICompositeType(gv);
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
@ -408,7 +332,7 @@ static llvm::DIGlobalVariable dwarfGlobalVariable(LLGlobalVariable* ll, VarDecla
vd->mangle(), // name vd->mangle(), // name
vd->toPrettyChars(), // displayname vd->toPrettyChars(), // displayname
vd->toChars(), // linkage name vd->toChars(), // linkage name
DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit DtoDwarfFile(vd->loc, DtoDwarfCompileUnit(getDefinedModule(vd))), // file
vd->loc.linnum, // line num vd->loc.linnum, // line num
dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type
vd->protection == PROTprivate, // is local to unit vd->protection == PROTprivate, // is local to unit
@ -433,7 +357,7 @@ static llvm::DIVariable dwarfVariable(VarDeclaration* vd, llvm::DIType type)
tag, // tag tag, // tag
gIR->func()->diSubprogram, // context gIR->func()->diSubprogram, // context
vd->toChars(), // name vd->toChars(), // name
DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit DtoDwarfFile(vd->loc, DtoDwarfCompileUnit(getDefinedModule(vd))), // file
vd->loc.linnum, // line num vd->loc.linnum, // line num
type // type type // type
); );
@ -485,7 +409,7 @@ void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd)
// get type description // get type description
llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL); llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL);
if (TD.isNull()) if ((llvm::MDNode*)TD == 0)
return; // unsupported return; // unsupported
// get variable description // get variable description
@ -505,10 +429,10 @@ llvm::DICompileUnit DtoDwarfCompileUnit(Module* m)
// we might be generating for an import // we might be generating for an import
IrModule* irmod = getIrModule(m); IrModule* irmod = getIrModule(m);
if (!irmod->diCompileUnit.isNull()) if ((llvm::MDNode*)irmod->diCompileUnit != 0)
{ {
assert (irmod->diCompileUnit.getGV()->getParent() == gIR->module //assert (irmod->diCompileUnit.getGV()->getParent() == gIR->module
&& "debug info compile unit belongs to incorrect llvm module!"); // && "debug info compile unit belongs to incorrect llvm module!");
return irmod->diCompileUnit; return irmod->diCompileUnit;
} }
@ -517,7 +441,7 @@ llvm::DICompileUnit DtoDwarfCompileUnit(Module* m)
if (!FileName::absolute(srcpath.c_str())) { if (!FileName::absolute(srcpath.c_str())) {
llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory(); llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory();
tmp.appendComponent(srcpath); tmp.appendComponent(srcpath);
srcpath = tmp.toString(); srcpath = tmp.str();
if (!srcpath.empty() && *srcpath.rbegin() != '/' && *srcpath.rbegin() != '\\') if (!srcpath.empty() && *srcpath.rbegin() != '/' && *srcpath.rbegin() != '\\')
srcpath = srcpath + '/'; srcpath = srcpath + '/';
} }
@ -533,12 +457,6 @@ llvm::DICompileUnit DtoDwarfCompileUnit(Module* m)
false // isOptimized false // isOptimized
); );
// if the linkage stays internal, we can't llvm-link the generated modules together:
// llvm's DwarfWriter uses path and filename to determine the symbol name and we'd
// end up with duplicate symbols
irmod->diCompileUnit.getGV()->setLinkage(DEBUGINFO_LINKONCE_LINKAGE_TYPE);
irmod->diCompileUnit.getGV()->setName(std::string("llvm.dbg.compile_unit_") + srcpath + m->srcfile->name->toChars());
return irmod->diCompileUnit; return irmod->diCompileUnit;
} }
@ -550,7 +468,7 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd)
LOG_SCOPE; LOG_SCOPE;
llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule); llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule);
llvm::DICompileUnit definition = DtoDwarfCompileUnit(getDefinedModule(fd)); llvm::DIFile file = DtoDwarfFile(fd->loc, DtoDwarfCompileUnit(getDefinedModule(fd)));
// FIXME: duplicates ? // FIXME: duplicates ?
return gIR->difactory.CreateSubprogram( return gIR->difactory.CreateSubprogram(
@ -558,12 +476,12 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd)
fd->toPrettyChars(), // name fd->toPrettyChars(), // name
fd->toPrettyChars(), // display name fd->toPrettyChars(), // display name
fd->mangle(), // linkage name fd->mangle(), // linkage name
definition, // compile unit file, // file
fd->loc.linnum, // line no fd->loc.linnum, // line no
//FIXME: what's this type for? //FIXME: what's this type for?
llvm::DIType(NULL), // type llvm::DIType(NULL), // type
fd->protection == PROTprivate, // is local to unit fd->protection == PROTprivate, // is local to unit
context.getGV() == definition.getGV() // isdefinition gIR->dmodule == getDefinedModule(fd) // isdefinition
); );
} }
@ -582,7 +500,7 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char
prettyname, // name prettyname, // name
prettyname, // display name prettyname, // display name
mangledname, // linkage name mangledname, // linkage name
context, // compile unit DtoDwarfFile(Loc(gIR->dmodule, 0), context), // compile unit
0, // line no 0, // line no
//FIXME: what's this type for? //FIXME: what's this type for?
llvm::DIType(NULL), // type llvm::DIType(NULL), // type
@ -609,8 +527,9 @@ void DtoDwarfFuncStart(FuncDeclaration* fd)
Logger::println("D to dwarf funcstart"); Logger::println("D to dwarf funcstart");
LOG_SCOPE; LOG_SCOPE;
assert(!fd->ir.irFunc->diSubprogram.isNull()); assert((llvm::MDNode*)fd->ir.irFunc->diSubprogram != 0);
gIR->difactory.InsertSubprogramStart(fd->ir.irFunc->diSubprogram, gIR->scopebb()); //TODO:
//gIR->difactory.InsertSubprogramStart(fd->ir.irFunc->diSubprogram, gIR->scopebb());
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
@ -620,8 +539,9 @@ void DtoDwarfFuncEnd(FuncDeclaration* fd)
Logger::println("D to dwarf funcend"); Logger::println("D to dwarf funcend");
LOG_SCOPE; LOG_SCOPE;
assert(!fd->ir.irFunc->diSubprogram.isNull()); assert((llvm::MDNode*)fd->ir.irFunc->diSubprogram != 0);
gIR->difactory.InsertRegionEnd(fd->ir.irFunc->diSubprogram, gIR->scopebb()); //TODO:
//gIR->difactory.InsertRegionEnd(fd->ir.irFunc->diSubprogram, gIR->scopebb());
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
@ -630,13 +550,9 @@ void DtoDwarfStopPoint(unsigned ln)
{ {
Logger::println("D to dwarf stoppoint at line %u", ln); Logger::println("D to dwarf stoppoint at line %u", ln);
LOG_SCOPE; LOG_SCOPE;
// TODO: possibly it is wrong.
gIR->difactory.InsertStopPoint( llvm::DebugLoc loc = llvm::DebugLoc::get(ln, 0, DtoDwarfCompileUnit(gIR->dmodule));
DtoDwarfCompileUnit(getDefinedModule(gIR->func()->decl)), // compile unit gIR->ir->SetCurrentDebugLocation(loc);
ln, // line no
0, // col no
gIR->scopebb()
);
} }
#endif #endif

View file

@ -116,10 +116,8 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
// debug info // debug info
if (global.params.symdebug) { if (global.params.symdebug)
RegisterDwarfSymbols(ir.module);
DtoDwarfCompileUnit(this); DtoDwarfCompileUnit(this);
}
#endif #endif
// handle invalid 'objectø module // handle invalid 'objectø module
@ -162,15 +160,6 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
// generate ModuleInfo // generate ModuleInfo
genmoduleinfo(); genmoduleinfo();
// emit usedArray
if (!ir.usedArray.empty())
{
const LLArrayType* usedTy = LLArrayType::get(getVoidPtrType(), ir.usedArray.size());
LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray);
LLGlobalVariable* usedArray = new LLGlobalVariable(*ir.module, usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used");
usedArray->setSection("llvm.metadata");
}
// verify the llvm // verify the llvm
if (!noVerify) { if (!noVerify) {
std::string verifyErr; std::string verifyErr;
@ -429,11 +418,8 @@ llvm::Function* build_module_ctor()
// debug info // debug info
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
LLGlobalVariable* subprog; if(global.params.symdebug)
if(global.params.symdebug) { DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV();
builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
}
#endif #endif
for (size_t i=0; i<n; i++) { for (size_t i=0; i<n; i++) {
@ -442,12 +428,6 @@ llvm::Function* build_module_ctor()
call->setCallingConv(DtoCallingConv(0, LINKd)); call->setCallingConv(DtoCallingConv(0, LINKd));
} }
// debug info end
#ifndef DISABLE_DEBUG_INFO
if(global.params.symdebug)
builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
#endif
builder.CreateRetVoid(); builder.CreateRetVoid();
return fn; return fn;
} }
@ -478,11 +458,8 @@ static llvm::Function* build_module_dtor()
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
// debug info // debug info
LLGlobalVariable* subprog; if(global.params.symdebug)
if(global.params.symdebug) { DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV();
builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
}
#endif #endif
for (size_t i=0; i<n; i++) { for (size_t i=0; i<n; i++) {
@ -491,12 +468,6 @@ static llvm::Function* build_module_dtor()
call->setCallingConv(DtoCallingConv(0, LINKd)); call->setCallingConv(DtoCallingConv(0, LINKd));
} }
#ifndef DISABLE_DEBUG_INFO
// debug info end
if(global.params.symdebug)
builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
#endif
builder.CreateRetVoid(); builder.CreateRetVoid();
return fn; return fn;
} }
@ -527,11 +498,9 @@ static llvm::Function* build_module_unittest()
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
// debug info // debug info
LLGlobalVariable* subprog; llvm::DISubprogram subprog;
if(global.params.symdebug) { if(global.params.symdebug)
subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
}
#endif #endif
for (size_t i=0; i<n; i++) { for (size_t i=0; i<n; i++) {
@ -540,12 +509,6 @@ static llvm::Function* build_module_unittest()
call->setCallingConv(DtoCallingConv(0, LINKd)); call->setCallingConv(DtoCallingConv(0, LINKd));
} }
#ifndef DISABLE_DEBUG_INFO
// debug info end
if(global.params.symdebug)
builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
#endif
builder.CreateRetVoid(); builder.CreateRetVoid();
return fn; return fn;
} }
@ -588,11 +551,9 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
// debug info // debug info
#ifndef DISABLE_DEBUG_INFO #ifndef DISABLE_DEBUG_INFO
LLGlobalVariable* subprog; llvm::DISubprogram subprog;
if(global.params.symdebug) { if(global.params.symdebug)
subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()).getGV(); subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str());
builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
}
#endif #endif
// get current beginning // get current beginning
@ -605,12 +566,6 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
// replace beginning // replace beginning
builder.CreateStore(thismref, mref); builder.CreateStore(thismref, mref);
#ifndef DISABLE_DEBUG_INFO
// debug info end
if(global.params.symdebug)
builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
#endif
// return // return
builder.CreateRetVoid(); builder.CreateRetVoid();