本文整理汇总了C++中DICompositeType类的典型用法代码示例。如果您正苦于以下问题:C++ DICompositeType类的具体用法?C++ DICompositeType怎么用?C++ DICompositeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DICompositeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getType
/// Verify - Verify that a subprogram descriptor is well formed.
bool DISubprogram::Verify() const {
if (!DbgNode)
return false;
if (getContext() && !getContext().Verify())
return false;
DICompositeType Ty = getType();
if (!Ty.Verify())
return false;
return true;
}
示例2: getType
/// Verify - Verify that a subprogram descriptor is well formed.
bool DISubprogram::Verify() const {
if (!isSubprogram())
return false;
if (getContext() && !getContext().Verify())
return false;
DICompositeType Ty = getType();
if (!Ty.Verify())
return false;
return DbgNode->getNumOperands() == 20;
}
示例3: addPubTypes
/// addPubTypes - Add type for pubtypes section.
void CompileUnit::addPubTypes(DISubprogram SP) {
DICompositeType SPTy = SP.getType();
unsigned SPTag = SPTy.getTag();
if (SPTag != dwarf::DW_TAG_subroutine_type)
return;
DIArray Args = SPTy.getTypeArray();
for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) {
DIType ATy(Args.getElement(i));
if (!ATy.Verify())
continue;
addGlobalType(ATy);
}
}
示例4: getCompileUnit
/// Verify - Verify that a subprogram descriptor is well formed.
bool DISubprogram::Verify() const {
if (isNull())
return false;
if (getContext().isNull())
return false;
DICompileUnit CU = getCompileUnit();
if (!CU.Verify())
return false;
DICompositeType Ty = getType();
if (!Ty.isNull() && !Ty.Verify())
return false;
return true;
}
示例5: createFunctionHelper
static DISubprogram
createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
StringRef LinkageName, DIFile File, unsigned LineNo,
DICompositeType Ty, bool isLocalToUnit, bool isDefinition,
unsigned ScopeLine, unsigned Flags, bool isOptimized,
Function *Fn, MDNode *TParams, MDNode *Decl, MDNode *Vars,
std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
Value *Elts[] = {
HeaderBuilder::get(dwarf::DW_TAG_subprogram)
.concat(Name)
.concat(Name)
.concat(LinkageName)
.concat(LineNo)
.concat(isLocalToUnit)
.concat(isDefinition)
.concat(0)
.concat(0)
.concat(Flags)
.concat(isOptimized)
.concat(ScopeLine)
.get(VMContext),
File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), Ty,
nullptr, Fn, TParams, Decl, Vars};
DISubprogram S(CreateFunc(Elts));
assert(S.isSubprogram() &&
"createFunction should return a valid DISubprogram");
return S;
}
示例6: getName
/// print - Print type.
void DIType::print(raw_ostream &OS) const {
if (!DbgNode) return;
StringRef Res = getName();
if (!Res.empty())
OS << " [" << Res << "] ";
unsigned Tag = getTag();
OS << " [" << dwarf::TagString(Tag) << "] ";
// TODO : Print context
OS << " ["
<< "line " << getLineNumber() << ", "
<< getSizeInBits() << " bits, "
<< getAlignInBits() << " bit alignment, "
<< getOffsetInBits() << " bit offset"
<< "] ";
if (isPrivate())
OS << " [private] ";
else if (isProtected())
OS << " [protected] ";
if (isForwardDecl())
OS << " [fwd] ";
if (isBasicType())
DIBasicType(DbgNode).print(OS);
else if (isDerivedType()) {
DIDerivedType DTy = DIDerivedType(DbgNode);
DTy.print(OS);
DICompositeType CTy = getDICompositeType(DTy);
if (CTy.Verify())
CTy.print(OS);
}
else if (isCompositeType())
DICompositeType(DbgNode).print(OS);
else {
OS << "Invalid DIType\n";
return;
}
OS << "\n";
}
示例7: DICompositeType
/// PopulateArrayTypeInfo - Populate TypeNo, Aux[] for array from Ty.
void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
bool &HasAux, int Aux[],
std::string &TagName) {
DICompositeType CTy = DICompositeType(Ty.getGV());
DIArray Elements = CTy.getTypeArray();
unsigned short size = 1;
unsigned short Dimension[4]={0,0,0,0};
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIDescriptor Element = Elements.getElement(i);
if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
TypeNo = TypeNo | PIC16Dbg::DT_ARY;
DISubrange SubRange = DISubrange(Element.getGV());
Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
// Each dimension is represented by 2 bytes starting at byte 9.
Aux[8+i*2+0] = Dimension[i];
Aux[8+i*2+1] = Dimension[i] >> 8;
size = size * Dimension[i];
}
}
示例8:
DITypeIdentifierMap
llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
DITypeIdentifierMap Map;
for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(CUi));
DIArray Retain = CU.getRetainedTypes();
for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
if (!isa<MDCompositeType>(Retain[Ti]))
continue;
DICompositeType Ty = cast<MDCompositeType>(Retain[Ti]);
if (MDString *TypeId = Ty.getIdentifier()) {
// Definition has priority over declaration.
// Try to insert (TypeId, Ty) to Map.
std::pair<DITypeIdentifierMap::iterator, bool> P =
Map.insert(std::make_pair(TypeId, Ty));
// If TypeId already exists in Map and this is a definition, replace
// whatever we had (declaration or definition) with the definition.
if (!P.second && !Ty.isForwardDecl())
P.first->second = Ty;
}
}
}
return Map;
}
示例9: createMethod
/// createMethod - Create a new descriptor for the specified C++ method.
DISubprogram DIBuilder::createMethod(DIDescriptor Context,
StringRef Name,
StringRef LinkageName,
DIFile F,
unsigned LineNo, DICompositeType Ty,
bool isLocalToUnit,
bool isDefinition,
unsigned VK, unsigned VIndex,
DIType VTableHolder,
unsigned Flags,
bool isOptimized,
Function *Fn,
MDNode *TParam) {
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
F.getFileNode(),
getNonCompileUnitScope(Context),
MDString::get(VMContext, Name),
MDString::get(VMContext, Name),
MDString::get(VMContext, LinkageName),
ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Ty,
ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
VTableHolder.generateRef(),
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Fn,
TParam,
Constant::getNullValue(Type::getInt32Ty(VMContext)),
MDNode::getTemporary(VMContext, TElts),
// FIXME: Do we want to use different scope/lines?
ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
};
MDNode *Node = MDNode::get(VMContext, Elts);
if (isDefinition)
AllSubprograms.push_back(Node);
DISubprogram S(Node);
assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
return S;
}
示例10: createFunction
/// createFunction - Create a new descriptor for the specified function.
DISubprogram DIBuilder::createFunction(DIDescriptor Context,
StringRef Name,
StringRef LinkageName,
DIFile File, unsigned LineNo,
DICompositeType Ty,
bool isLocalToUnit, bool isDefinition,
unsigned ScopeLine,
unsigned Flags, bool isOptimized,
Function *Fn,
MDNode *TParams,
MDNode *Decl) {
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
File.getFileNode(),
getNonCompileUnitScope(Context),
MDString::get(VMContext, Name),
MDString::get(VMContext, Name),
MDString::get(VMContext, LinkageName),
ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Ty,
ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
NULL,
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Fn,
TParams,
Decl,
MDNode::getTemporary(VMContext, TElts),
ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
};
MDNode *Node = MDNode::get(VMContext, Elts);
// Create a named metadata so that we do not lose this mdnode.
if (isDefinition)
AllSubprograms.push_back(Node);
DISubprogram S(Node);
assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
return S;
}
示例11: createMethod
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
StringRef LinkageName, DIFile F,
unsigned LineNo, DICompositeType Ty,
bool isLocalToUnit, bool isDefinition,
unsigned VK, unsigned VIndex,
DIType VTableHolder, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParam) {
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
assert(getNonCompileUnitScope(Context) &&
"Methods should have both a Context and a context that isn't "
"the compile unit.");
Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
.concat(Name)
.concat(Name)
.concat(LinkageName)
.concat(LineNo)
.concat(isLocalToUnit)
.concat(isDefinition)
.concat(VK)
.concat(VIndex)
.concat(Flags)
.concat(isOptimized)
.concat(LineNo)
// FIXME: Do we want to use different scope/lines?
.get(VMContext),
F.getFileNode(), DIScope(Context).getRef(), Ty,
VTableHolder.getRef(), Fn, TParam, nullptr, nullptr};
MDNode *Node = MDNode::get(VMContext, Elts);
if (isDefinition)
AllSubprograms.push_back(Node);
DISubprogram S(Node);
assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
return S;
}
示例12: switch
/// constructTypeDIE - Construct type DIE from DICompositeType.
void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
// Get core information.
StringRef Name = CTy.getName();
uint64_t Size = CTy.getSizeInBits() >> 3;
unsigned Tag = CTy.getTag();
Buffer.setTag(Tag);
switch (Tag) {
case dwarf::DW_TAG_vector_type:
case dwarf::DW_TAG_array_type:
constructArrayTypeDIE(Buffer, &CTy);
break;
case dwarf::DW_TAG_enumeration_type: {
DIArray Elements = CTy.getTypeArray();
// Add enumerators to enumeration type.
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIE *ElemDie = NULL;
DIDescriptor Enum(Elements.getElement(i));
if (Enum.isEnumerator()) {
ElemDie = constructEnumTypeDIE(DIEnumerator(Enum));
Buffer.addChild(ElemDie);
}
}
}
break;
case dwarf::DW_TAG_subroutine_type: {
// Add return type.
DIArray Elements = CTy.getTypeArray();
DIDescriptor RTy = Elements.getElement(0);
addType(&Buffer, DIType(RTy));
bool isPrototyped = true;
// Add arguments.
for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
DIDescriptor Ty = Elements.getElement(i);
if (Ty.isUnspecifiedParameter()) {
DIE *Arg = new DIE(dwarf::DW_TAG_unspecified_parameters);
Buffer.addChild(Arg);
isPrototyped = false;
} else {
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
addType(Arg, DIType(Ty));
Buffer.addChild(Arg);
}
}
// Add prototype flag.
if (isPrototyped)
addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
}
break;
case dwarf::DW_TAG_structure_type:
case dwarf::DW_TAG_union_type:
case dwarf::DW_TAG_class_type: {
// Add elements to structure type.
DIArray Elements = CTy.getTypeArray();
// A forward struct declared type may not have elements available.
unsigned N = Elements.getNumElements();
if (N == 0)
break;
// Add elements to structure type.
for (unsigned i = 0; i < N; ++i) {
DIDescriptor Element = Elements.getElement(i);
DIE *ElemDie = NULL;
if (Element.isSubprogram()) {
DISubprogram SP(Element);
ElemDie = DD->createSubprogramDIE(DISubprogram(Element));
if (SP.isProtected())
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
dwarf::DW_ACCESS_protected);
else if (SP.isPrivate())
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
dwarf::DW_ACCESS_private);
else
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
dwarf::DW_ACCESS_public);
if (SP.isExplicit())
addUInt(ElemDie, dwarf::DW_AT_explicit, dwarf::DW_FORM_flag, 1);
}
else if (Element.isVariable()) {
DIVariable DV(Element);
ElemDie = new DIE(dwarf::DW_TAG_variable);
addString(ElemDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
DV.getName());
addType(ElemDie, DV.getType());
addUInt(ElemDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
addUInt(ElemDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
addSourceLine(ElemDie, DV);
} else if (Element.isDerivedType())
ElemDie = createMemberDIE(DIDerivedType(Element));
else
continue;
Buffer.addChild(ElemDie);
}
if (CTy.isAppleBlockExtension())
//.........这里部分代码省略.........
示例13: setContainingType
void DICompositeType::setContainingType(DICompositeType ContainingType) {
TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
N->replaceVTableHolder(ContainingType.getRef());
DbgNode = N;
}
示例14: setContainingType
void DICompositeType::setContainingType(DICompositeType ContainingType) {
TrackingMDNodeRef N(*this);
N->replaceOperandWith(5, ContainingType.getRef());
DbgNode = N;
}
示例15: assert
std::unique_ptr<StructInfo> StructInfo::getFromGlobalPointer(Module *module, llvm::StringRef name)
{
GlobalVariable *var = module->getGlobalVariable(name, false);
if (!var || !var->getType() || !var->getType()->isPointerTy()) {
assert(false);
llvm::errs() << "StructInfo: Cannot get global variable " << name << ", or it is not a pointer." << '\n';
return nullptr;
}
PointerType *varDeref = dyn_cast<PointerType>(var->getType()->getElementType());
if (!varDeref || !varDeref->getElementType())
{
assert(false);
llvm::errs() << "StructInfo: Pointer not valid." << '\n';
return nullptr;
}
StructType *structType = dyn_cast<StructType>(varDeref->getElementType());
if (!structType) {
assert(false);
llvm::errs() << "StructInfo: Cannot get struct type." << '\n';
return nullptr;
}
NamedMDNode *mdCuNodes = module->getNamedMetadata("llvm.dbg.cu");
if (!mdCuNodes) {
assert(false);
llvm::errs() << "StructInfo: Cannot find metadata." << '\n';
return nullptr;
}
std::shared_ptr<DITypeIdentifierMap> typeIdentifierMap(new DITypeIdentifierMap(generateDITypeIdentifierMap(mdCuNodes)));
DICompositeType *diStructType = nullptr;
for ( unsigned i = 0; i < mdCuNodes->getNumOperands() && !diStructType; ++i )
{
DICompileUnit diCu(mdCuNodes->getOperand(i));
for ( unsigned j = 0; j < diCu.getGlobalVariables().getNumElements(); ++j )
{
DIGlobalVariable diGlobalVar(diCu.getGlobalVariables().getElement(j));
if (diGlobalVar.getName() != name) {
continue;
}
//Go through pointers until we reach a structure
DIType diStructType(diGlobalVar.getType());
while (diStructType.isDerivedType() && !diStructType.isCompositeType()) {
diStructType = std::unique_ptr<DIDerivedType>(new DIDerivedType(diStructType))->getTypeDerivedFrom().resolve(*typeIdentifierMap);
}
if (!diStructType.isCompositeType()) {
llvm::errs() << "StructInfo: Global variable " << name << " does not point to a composite type: " << diStructType.getName() << '\n';
assert(false);
return nullptr;
}
return std::unique_ptr<StructInfo>(new StructInfo(
module,
structType,
new DICompositeType(diStructType),
typeIdentifierMap));
}
}
assert(false);
llvm::errs() << "StructInfo: Did not find global variable " << name << " in debug information." << '\n';
return nullptr;
}