Introduce support to encode Objective-C property information in debugging information generated for an interface.

llvm-svn: 129624
This commit is contained in:
Devang Patel 2011-04-16 00:11:51 +00:00
parent d7a6b974bc
commit eddab1d186
7 changed files with 133 additions and 2 deletions

View File

@ -551,7 +551,12 @@ DW_ATE_unsigned_char = 8
i64, ;; Size in bits
i64, ;; Alignment in bits
i64, ;; Offset in bits
metadata ;; Reference to type derived from
metadata, ;; Reference to type derived from
metadata, ;; (optional) Name of the Objective C property assoicated with
;; Objective-C an ivar
metadata, ;; (optional) Name of the Objective C property getter selector.
metadata, ;; (optional) Name of the Objective C property setter selector.
i32 ;; (optional) Objective C property attributes.
}
</pre>
</div>

View File

@ -146,6 +146,30 @@ namespace llvm {
uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, DIType Ty);
/// createObjCIVar - Create debugging information entry for Objective-C
/// instance variable.
/// @param Name Member name.
/// @param File File where this member is defined.
/// @param LineNo Line number.
/// @param SizeInBits Member size.
/// @param AlignInBits Member alignment.
/// @param OffsetInBits Member offset.
/// @param Flags Flags to encode member attribute, e.g. private
/// @param Ty Parent type.
/// @param PropertyName Name of the Objective C property assoicated with
/// this ivar.
/// @param GetterName Name of the Objective C property getter selector.
/// @param SetterName Name of the Objective C property setter selector.
/// @param PropertyAttributes Objective C property attributes.
DIType createObjCIVar(StringRef Name, DIFile File,
unsigned LineNo, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, DIType Ty,
StringRef PropertyName = StringRef(),
StringRef PropertyGetterName = StringRef(),
StringRef PropertySetterName = StringRef(),
unsigned PropertyAttributes = 0);
/// createClassType - Create debugging information entry for a class.
/// @param Scope Scope in which this class is defined.
/// @param Name class name.

View File

@ -332,6 +332,32 @@ namespace llvm {
/// return base type size.
uint64_t getOriginalTypeSize() const;
StringRef getObjCPropertyName() const { return getStringField(10); }
StringRef getObjCPropertyGetterName() const {
return getStringField(11);
}
StringRef getObjCPropertySetterName() const {
return getStringField(12);
}
bool isReadOnlyObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
}
bool isReadWriteObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
}
bool isAssignObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
}
bool isRetainObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
}
bool isCopyObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
}
bool isNonAtomicObjCProperty() {
return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
}
/// Verify - Verify that a derived type descriptor is well formed.
bool Verify() const;

View File

@ -231,6 +231,10 @@ enum dwarf_constants {
DW_AT_APPLE_major_runtime_vers = 0x3fe5,
DW_AT_APPLE_runtime_class = 0x3fe6,
DW_AT_APPLE_omit_frame_ptr = 0x3fe7,
DW_AT_APPLE_property_name = 0x3fe8,
DW_AT_APPLE_property_getter = 0x3fe9,
DW_AT_APPLE_property_setter = 0x3fea,
DW_AT_APPLE_property_attribute = 0x3feb,
// Attribute form encodings
DW_FORM_addr = 0x01,
@ -584,7 +588,15 @@ enum dwarf_constants {
DW_EH_PE_datarel = 0x30,
DW_EH_PE_funcrel = 0x40,
DW_EH_PE_aligned = 0x50,
DW_EH_PE_indirect = 0x80
DW_EH_PE_indirect = 0x80,
// Apple Objective-C Property Attributes
DW_APPLE_PROPERTY_readonly = 0x01,
DW_APPLE_PROPERTY_readwrite = 0x02,
DW_APPLE_PROPERTY_assign = 0x04,
DW_APPLE_PROPERTY_retain = 0x08,
DW_APPLE_PROPERTY_copy = 0x10,
DW_APPLE_PROPERTY_nonatomic = 0x20
};
/// TagString - Return the string for the specified tag.

View File

@ -236,6 +236,35 @@ DIType DIBuilder::createMemberType(StringRef Name,
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
}
/// createObjCIVar - Create debugging information entry for Objective-C
/// instance variable.
DIType DIBuilder::createObjCIVar(StringRef Name,
DIFile File, unsigned LineNumber,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
DIType Ty, StringRef PropertyName,
StringRef GetterName, StringRef SetterName,
unsigned PropertyAttributes) {
// TAG_member is encoded in DIDerivedType format.
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_member),
File, // Or TheCU ? Ty ?
MDString::get(VMContext, Name),
File,
ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Ty,
MDString::get(VMContext, PropertyName),
MDString::get(VMContext, GetterName),
MDString::get(VMContext, SetterName),
ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
};
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
}
/// createClassType - Create debugging information entry for a class.
DIType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
DIFile File, unsigned LineNumber,

View File

@ -969,5 +969,36 @@ DIE *CompileUnit::createMemberDIE(DIDerivedType DT) {
if (DT.isVirtual())
addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag,
dwarf::DW_VIRTUALITY_virtual);
// Objective-C properties.
StringRef PropertyName = DT.getObjCPropertyName();
if (!PropertyName.empty()) {
addString(MemberDie, dwarf::DW_AT_APPLE_property_name, dwarf::DW_FORM_string,
PropertyName);
StringRef GetterName = DT.getObjCPropertyGetterName();
if (!GetterName.empty())
addString(MemberDie, dwarf::DW_AT_APPLE_property_getter,
dwarf::DW_FORM_string, GetterName);
StringRef SetterName = DT.getObjCPropertySetterName();
if (!SetterName.empty())
addString(MemberDie, dwarf::DW_AT_APPLE_property_setter,
dwarf::DW_FORM_string, SetterName);
unsigned PropertyAttributes = 0;
if (DT.isReadOnlyObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly;
if (DT.isReadWriteObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite;
if (DT.isAssignObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign;
if (DT.isRetainObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain;
if (DT.isCopyObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy;
if (DT.isNonAtomicObjCProperty())
PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic;
if (PropertyAttributes)
addUInt(MemberDie, dwarf::DW_AT_APPLE_property_attribute, 0,
PropertyAttributes);
}
return MemberDie;
}

View File

@ -203,6 +203,10 @@ const char *llvm::dwarf::AttributeString(unsigned Attribute) {
case DW_AT_APPLE_major_runtime_vers: return "DW_AT_APPLE_major_runtime_vers";
case DW_AT_APPLE_runtime_class: return "DW_AT_APPLE_runtime_class";
case DW_AT_APPLE_omit_frame_ptr: return "DW_AT_APPLE_omit_frame_ptr";
case DW_AT_APPLE_property_name: return "DW_AT_APPLE_property_name";
case DW_AT_APPLE_property_getter: return "DW_AT_APPLE_property_getter";
case DW_AT_APPLE_property_setter: return "DW_AT_APPLE_property_setter";
case DW_AT_APPLE_property_attribute: return "DW_AT_APPLE_property_attribute";
}
return 0;
}