14 #define DEBUG_TYPE "dwarfdebug"
38 for (
size_t i = 0; i < Values.
size(); ++i) {
39 if (Abbrevs.
getData()[i].getAttribute() == Attr) {
41 assert(isa<DIEString>(V) &&
"String requested. Not a string.");
52 DEBUG(
dbgs() <<
"Adding string " << Str <<
" to hash.\n");
61 void DIEHash::addULEB128(uint64_t
Value) {
62 DEBUG(
dbgs() <<
"Adding ULEB128 " << Value <<
" to hash.\n");
64 uint8_t Byte = Value & 0x7f;
72 void DIEHash::addSLEB128(int64_t Value) {
73 DEBUG(
dbgs() <<
"Adding ULEB128 " << Value <<
" to hash.\n");
76 uint8_t Byte = Value & 0x7f;
78 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
79 ((Value == -1) && ((Byte & 0x40) != 0))));
87 void DIEHash::addParentContext(
const DIE &Parent) {
89 DEBUG(
dbgs() <<
"Adding parent context to hash...\n");
94 const DIE *Cur = &Parent;
95 while (Cur->
getTag() != dwarf::DW_TAG_compile_unit) {
105 const DIE &Die = **
I;
115 DEBUG(
dbgs() <<
"... adding context: " << Name <<
"\n");
122 void DIEHash::collectAttributes(
const DIE &Die, DIEAttrs &Attrs) {
126 #define COLLECT_ATTR(NAME) \
128 Attrs.NAME.Val = Values[i]; \
129 Attrs.NAME.Desc = &Abbrevs.getData()[i]; \
132 for (
size_t i = 0, e = Values.
size(); i != e; ++i) {
136 switch (Abbrevs.
getData()[i].getAttribute()) {
192 void DIEHash::hashShallowTypeReference(dwarf::Attribute
Attribute,
198 addULEB128(Attribute);
202 addParentContext(*Parent);
218 void DIEHash::hashRepeatedTypeReference(dwarf::Attribute Attribute,
219 unsigned DieNumber) {
224 addULEB128(Attribute);
228 addULEB128(DieNumber);
231 void DIEHash::hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
233 assert(Tag != dwarf::DW_TAG_friend &&
"No current LLVM clients emit friend "
234 "tags. Add support here when there's "
238 if ((Tag == dwarf::DW_TAG_pointer_type ||
239 Tag == dwarf::DW_TAG_reference_type ||
240 Tag == dwarf::DW_TAG_rvalue_reference_type ||
241 Tag == dwarf::DW_TAG_ptr_to_member_type) &&
246 Attribute == dwarf::DW_AT_type) {
250 hashShallowTypeReference(Attribute, Entry, Name);
255 unsigned &DieNumber = Numbering[&Entry];
257 hashRepeatedTypeReference(Attribute, DieNumber);
264 addULEB128(Attribute);
268 DieNumber = Numbering.size();
274 void DIEHash::hashAttribute(AttrEntry Attr, dwarf::Tag Tag) {
282 if (
const DIEEntry *EntryAttr = dyn_cast<DIEEntry>(Value)) {
283 hashDIEEntry(Attribute, Tag, *EntryAttr->getEntry());
290 addULEB128(Attribute);
298 case dwarf::DW_FORM_string:
300 "Add support for DW_FORM_string if we ever start emitting them again");
301 case dwarf::DW_FORM_GNU_str_index:
302 case dwarf::DW_FORM_strp:
303 addULEB128(dwarf::DW_FORM_string);
304 addString(cast<DIEString>(Value)->getString());
306 case dwarf::DW_FORM_data1:
307 case dwarf::DW_FORM_data2:
308 case dwarf::DW_FORM_data4:
309 case dwarf::DW_FORM_data8:
310 case dwarf::DW_FORM_udata:
311 addULEB128(dwarf::DW_FORM_sdata);
312 addSLEB128((int64_t)cast<DIEInteger>(Value)->getValue());
321 void DIEHash::hashAttributes(
const DIEAttrs &Attrs, dwarf::Tag Tag) {
322 #define ADD_ATTR(ATTR) \
325 hashAttribute(ATTR, Tag); \
329 ADD_ATTR(Attrs.DW_AT_accessibility);
330 ADD_ATTR(Attrs.DW_AT_address_class);
342 ADD_ATTR(Attrs.DW_AT_containing_type);
344 ADD_ATTR(Attrs.DW_AT_data_bit_offset);
345 ADD_ATTR(Attrs.DW_AT_data_location);
346 ADD_ATTR(Attrs.DW_AT_data_member_location);
347 ADD_ATTR(Attrs.DW_AT_decimal_scale);
349 ADD_ATTR(Attrs.DW_AT_default_value);
363 ADD_ATTR(Attrs.DW_AT_picture_string);
367 ADD_ATTR(Attrs.DW_AT_string_length);
368 ADD_ATTR(Attrs.DW_AT_threads_scaled);
372 ADD_ATTR(Attrs.DW_AT_variable_parameter);
375 ADD_ATTR(Attrs.DW_AT_vtable_elem_location);
382 void DIEHash::addAttributes(
const DIE &Die) {
384 collectAttributes(Die, Attrs);
385 hashAttributes(Attrs, Die.
getTag());
388 void DIEHash::hashNestedType(
const DIE &Die,
StringRef Name) {
403 void DIEHash::computeHash(
const DIE &Die) {
412 for (std::vector<DIE *>::const_iterator
I = Die.
getChildren().begin(),
417 if (
isType((*I)->getTag()) || (*I)->getTag() == dwarf::DW_TAG_subprogram) {
421 hashNestedType(**
I, Name);
444 addParentContext(*Parent);
494 addParentContext(*Parent);
void push_back(const T &Elt)
uint64_t computeCUSignature(const DIE &Die)
Computes the CU signature.
dwarf::Form getForm() const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
#define llvm_unreachable(msg)
#define COLLECT_ATTR(NAME)
uint64_t computeTypeSignature(const DIE &Die)
Computes the type signature.
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
dwarf::Tag getTag() const
void final(MD5Result &result)
Finishes off the hash and puts the result in result.
uint64_t computeDIEODRSignature(const DIE &Die)
Computes the ODR signature.
const std::vector< DIE * > & getChildren() const
dwarf::Attribute getAttribute() const
StringRef getString() const
getString - Grab the string out of the object.
const SmallVectorImpl< DIEValue * > & getValues() const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
const char * AttributeString(unsigned Attribute)
const SmallVectorImpl< DIEAbbrevData > & getData() const
reverse_iterator rbegin()
LLVM Value Representation.
static StringRef getDIEStringAttr(const DIE &Die, uint16_t Attr)
Grabs the string in whichever attribute is passed in and returns a reference to it.
bool empty() const
empty - Check if the string is empty.