2013-09-03 23:57:57 +02:00
|
|
|
//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../lib/CodeGen/AsmPrinter/DIE.h"
|
|
|
|
#include "../lib/CodeGen/AsmPrinter/DIEHash.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2014-01-07 12:48:04 +01:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2013-09-03 23:57:57 +02:00
|
|
|
#include "llvm/Support/Format.h"
|
2014-04-25 22:00:34 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-09-03 23:57:57 +02:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2013-10-16 01:00:17 +02:00
|
|
|
|
|
|
|
namespace {
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, Data1) {
|
2013-09-03 23:57:57 +02:00
|
|
|
DIEHash Hash;
|
2013-09-29 13:29:20 +02:00
|
|
|
DIE Die(dwarf::DW_TAG_base_type);
|
|
|
|
DIEInteger Size(4);
|
|
|
|
Die.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Size);
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = Hash.computeTypeSignature(Die);
|
2013-10-17 01:36:20 +02:00
|
|
|
ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// struct {};
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, TrivialType) {
|
2013-10-17 02:10:34 +02:00
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
2013-10-17 01:36:20 +02:00
|
|
|
DIEInteger One(1);
|
2013-10-17 02:10:34 +02:00
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
2013-10-17 01:36:20 +02:00
|
|
|
|
|
|
|
// Line and file number are ignored.
|
2013-10-17 02:10:34 +02:00
|
|
|
Unnamed.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-17 01:36:20 +02:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
|
2013-09-03 23:57:57 +02:00
|
|
|
}
|
2013-10-17 02:10:34 +02:00
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// struct foo { };
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, NamedType) {
|
2013-10-17 02:10:34 +02:00
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEString FooStr(&One, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-17 02:10:34 +02:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// namespace space { struct foo { }; }
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, NamespacedType) {
|
2013-10-17 02:10:34 +02:00
|
|
|
DIE CU(dwarf::DW_TAG_compile_unit);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Space = make_unique<DIE>(dwarf::DW_TAG_namespace);
|
2013-10-17 02:10:34 +02:00
|
|
|
DIEInteger One(1);
|
|
|
|
DIEString SpaceStr(&One, "space");
|
|
|
|
Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr);
|
|
|
|
// DW_AT_declaration is ignored.
|
|
|
|
Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
// sibling?
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type);
|
2013-10-17 02:10:34 +02:00
|
|
|
DIEString FooStr(&One, "foo");
|
|
|
|
Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
DIE &N = *Foo;
|
|
|
|
Space->addChild(std::move(Foo));
|
|
|
|
CU.addChild(std::move(Space));
|
2013-10-17 02:10:34 +02:00
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(N);
|
2013-10-17 02:10:34 +02:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
|
|
|
|
}
|
2013-10-18 00:07:09 +02:00
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// struct { int member; };
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, TypeWithMember) {
|
2013-10-18 00:07:09 +02:00
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Four(4);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
|
|
|
|
|
|
|
|
DIE Int(dwarf::DW_TAG_base_type);
|
|
|
|
DIEString IntStr(&Four, "int");
|
|
|
|
Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr);
|
|
|
|
Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
|
|
|
|
DIEInteger Five(5);
|
|
|
|
Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry IntRef(Int);
|
2014-04-25 22:00:34 +02:00
|
|
|
|
|
|
|
auto Member = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
|
|
DIEString MemberStr(&Four, "member");
|
|
|
|
Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr);
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
2013-10-18 00:07:09 +02:00
|
|
|
Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Unnamed.addChild(std::move(Member));
|
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-18 00:07:09 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
|
|
|
|
}
|
2013-10-21 20:59:40 +02:00
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// struct foo { int mem1, mem2; };
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, ReusedType) {
|
2013-10-21 20:59:40 +02:00
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
|
|
|
|
DIEInteger Four(4);
|
2014-04-25 22:00:34 +02:00
|
|
|
DIE Int(dwarf::DW_TAG_base_type);
|
|
|
|
DIEString IntStr(&Four, "int");
|
|
|
|
Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr);
|
|
|
|
Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
|
|
|
|
DIEInteger Five(5);
|
|
|
|
Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
|
|
|
|
|
|
|
|
DIEEntry IntRef(Int);
|
|
|
|
|
|
|
|
auto Mem1 = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-21 20:59:40 +02:00
|
|
|
DIEString Mem1Str(&Four, "mem1");
|
|
|
|
Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem1Str);
|
|
|
|
DIEInteger Zero(0);
|
2014-02-20 01:54:38 +01:00
|
|
|
Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
2014-04-25 22:00:34 +02:00
|
|
|
Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
|
2013-10-21 20:59:40 +02:00
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Unnamed.addChild(std::move(Mem1));
|
2013-10-21 20:59:40 +02:00
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem2 = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-21 20:59:40 +02:00
|
|
|
DIEString Mem2Str(&Four, "mem2");
|
|
|
|
Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem2Str);
|
2014-02-20 01:54:38 +01:00
|
|
|
Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Four);
|
2013-10-21 20:59:40 +02:00
|
|
|
Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Unnamed.addChild(std::move(Mem2));
|
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-21 20:59:40 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 00:36:50 +02:00
|
|
|
// struct foo { static foo f; };
|
2013-10-21 22:28:30 +02:00
|
|
|
TEST(DIEHashTest, RecursiveType) {
|
2013-10-21 20:59:40 +02:00
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
DIEString FooStr(&One, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-21 20:59:40 +02:00
|
|
|
DIEString MemStr(&One, "mem");
|
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRef(Foo);
|
2013-10-21 20:59:40 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef);
|
|
|
|
// DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-21 20:59:40 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-21 20:59:40 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 00:36:50 +02:00
|
|
|
|
|
|
|
// struct foo { foo *mem; };
|
|
|
|
TEST(DIEHashTest, Pointer) {
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 00:36:50 +02:00
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
|
|
|
|
|
|
|
|
DIE FooPtr(dwarf::DW_TAG_pointer_type);
|
|
|
|
FooPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRef(Foo);
|
2013-10-22 00:36:50 +02:00
|
|
|
FooPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooPtrRef(FooPtr);
|
2013-10-22 00:36:50 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooPtrRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 00:36:50 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 00:36:50 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 01:06:19 +02:00
|
|
|
|
|
|
|
// struct foo { foo &mem; };
|
|
|
|
TEST(DIEHashTest, Reference) {
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 01:06:19 +02:00
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
|
|
|
|
|
|
|
|
DIE FooRef(dwarf::DW_TAG_reference_type);
|
|
|
|
FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooEntry(Foo);
|
2013-10-22 01:06:19 +02:00
|
|
|
FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
|
|
|
|
|
|
|
|
DIE FooRefConst(dwarf::DW_TAG_const_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRefRef(FooRef);
|
2013-10-22 01:06:19 +02:00
|
|
|
FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefRef);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
2013-10-22 01:06:19 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 01:06:19 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 01:06:19 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct foo { foo &&mem; };
|
|
|
|
TEST(DIEHashTest, RValueReference) {
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 01:06:19 +02:00
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
|
|
|
|
|
|
|
|
DIE FooRef(dwarf::DW_TAG_rvalue_reference_type);
|
|
|
|
FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooEntry(Foo);
|
2013-10-22 01:06:19 +02:00
|
|
|
FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
|
|
|
|
|
|
|
|
DIE FooRefConst(dwarf::DW_TAG_const_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRefRef(FooRef);
|
2013-10-22 01:06:19 +02:00
|
|
|
FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefRef);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
2013-10-22 01:06:19 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 01:06:19 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 01:06:19 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 20:14:41 +02:00
|
|
|
|
|
|
|
// struct foo { foo foo::*mem; };
|
|
|
|
TEST(DIEHashTest, PtrToMember) {
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 20:14:41 +02:00
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
|
|
|
|
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooEntry(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
|
2014-02-20 01:54:38 +01:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
|
|
&FooEntry);
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the hash for a pointer-to-member matches regardless of whether the
|
|
|
|
// pointed-to type is a declaration or a definition.
|
|
|
|
//
|
|
|
|
// struct bar; // { };
|
|
|
|
// struct foo { bar foo::*mem; };
|
|
|
|
TEST(DIEHashTest, PtrToMemberDeclDefMatch) {
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
DIEString BarStr(&Eight, "bar");
|
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
uint64_t MD5ResDecl;
|
|
|
|
{
|
|
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
|
|
|
|
Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
|
|
|
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry BarEntry(Bar);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooEntry(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
|
|
&FooEntry);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
}
|
|
|
|
uint64_t MD5ResDef;
|
|
|
|
{
|
|
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
|
|
|
|
Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
|
|
|
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry BarEntry(Bar);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FooEntry(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
|
|
&FooEntry);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(MD5ResDef, MD5ResDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the hash for a pointer-to-member matches regardless of whether the
|
|
|
|
// pointed-to type is a declaration or a definition.
|
|
|
|
//
|
|
|
|
// struct bar; // { };
|
|
|
|
// struct foo { bar bar::*mem; };
|
|
|
|
TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) {
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
DIEString FooStr(&Eight, "foo");
|
|
|
|
DIEString BarStr(&Eight, "bar");
|
|
|
|
DIEString MemStr(&Eight, "mem");
|
|
|
|
uint64_t MD5ResDecl;
|
|
|
|
{
|
|
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
|
|
|
|
Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
|
|
|
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry BarEntry(Bar);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
|
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
|
|
&BarEntry);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
}
|
|
|
|
uint64_t MD5ResDef;
|
|
|
|
{
|
|
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
|
|
|
|
Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
&Zero);
|
|
|
|
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry BarEntry(Bar);
|
2013-10-22 20:14:41 +02:00
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
|
|
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
|
|
&BarEntry);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2013-10-22 20:14:41 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 20:14:41 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 20:14:41 +02:00
|
|
|
}
|
|
|
|
// FIXME: This seems to be a bug in the DWARF type hashing specification that
|
|
|
|
// only uses the brief name hashing for types referenced via DW_AT_type. In
|
|
|
|
// this case the type is referenced via DW_AT_containing_type and full hashing
|
|
|
|
// causes a hash to differ when the containing type is a declaration in one TU
|
|
|
|
// and a definition in another.
|
|
|
|
ASSERT_NE(MD5ResDef, MD5ResDecl);
|
|
|
|
}
|
2013-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
// struct { } a;
|
|
|
|
// struct foo { decltype(a) mem; };
|
|
|
|
TEST(DIEHashTest, RefUnnamedType) {
|
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
|
|
|
DIEString FooStr(&Zero, "foo");
|
|
|
|
DIEString MemStr(&Zero, "mem");
|
|
|
|
|
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
|
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
2013-10-24 19:53:58 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
|
|
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
|
|
|
|
|
|
|
|
DIE UnnamedPtr(dwarf::DW_TAG_pointer_type);
|
|
|
|
UnnamedPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry UnnamedRef(Unnamed);
|
2013-10-24 19:53:58 +02:00
|
|
|
UnnamedPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &UnnamedRef);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry UnnamedPtrRef(UnnamedPtr);
|
2013-10-24 19:53:58 +02:00
|
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &UnnamedPtrRef);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-24 19:53:58 +02:00
|
|
|
|
2013-10-24 20:29:03 +02:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(0x954e026f01c02529ULL, MD5Res);
|
|
|
|
}
|
2013-10-25 20:38:43 +02:00
|
|
|
|
2014-01-31 21:02:55 +01:00
|
|
|
// struct { struct foo { }; };
|
2013-10-25 20:38:43 +02:00
|
|
|
TEST(DIEHashTest, NestedType) {
|
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type);
|
2013-10-25 20:38:43 +02:00
|
|
|
DIEString FooStr(&One, "foo");
|
|
|
|
Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
|
|
|
|
Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Unnamed.addChild(std::move(Foo));
|
2013-10-25 20:38:43 +02:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res);
|
|
|
|
}
|
2013-10-25 22:04:25 +02:00
|
|
|
|
|
|
|
// struct { static void func(); };
|
|
|
|
TEST(DIEHashTest, MemberFunc) {
|
|
|
|
DIE Unnamed(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram);
|
2013-10-25 22:04:25 +02:00
|
|
|
DIEString FuncStr(&One, "func");
|
|
|
|
Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
Unnamed.addChild(std::move(Func));
|
2013-10-25 22:04:25 +02:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
|
|
|
|
}
|
2014-01-31 21:02:58 +01:00
|
|
|
|
|
|
|
// struct A {
|
|
|
|
// static void func();
|
|
|
|
// };
|
|
|
|
TEST(DIEHashTest, MemberFuncFlag) {
|
|
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEString AStr(&One, "A");
|
|
|
|
A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
|
|
|
|
A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram);
|
2014-01-31 21:02:58 +01:00
|
|
|
DIEString FuncStr(&One, "func");
|
|
|
|
DIEString FuncLinkage(&One, "_ZN1A4funcEv");
|
|
|
|
DIEInteger Two(2);
|
|
|
|
Func->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr);
|
|
|
|
Func->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
Func->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
|
|
|
|
Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, &FuncLinkage);
|
|
|
|
Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
A.addChild(std::move(Func));
|
2014-01-31 21:02:58 +01:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
|
|
|
|
}
|
2014-02-20 01:54:40 +01:00
|
|
|
|
|
|
|
// Derived from:
|
|
|
|
// struct A {
|
2014-02-20 01:59:17 +01:00
|
|
|
// const static int PI = -3;
|
2014-02-20 01:54:40 +01:00
|
|
|
// };
|
|
|
|
// A a;
|
2014-02-20 02:27:51 +01:00
|
|
|
TEST(DIEHashTest, MemberSdata) {
|
2014-02-20 01:54:40 +01:00
|
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEString AStr(&One, "A");
|
|
|
|
A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
|
|
|
|
A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
|
|
|
DIEInteger Four(4);
|
|
|
|
DIEInteger Five(5);
|
|
|
|
DIEString FStr(&One, "int");
|
2014-04-25 19:07:55 +02:00
|
|
|
DIE IntTyDIE(dwarf::DW_TAG_base_type);
|
|
|
|
IntTyDIE.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
|
|
|
|
IntTyDIE.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
|
|
|
|
IntTyDIE.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr);
|
2014-02-20 01:54:40 +01:00
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry IntTy(IntTyDIE);
|
2014-04-25 22:00:34 +02:00
|
|
|
auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
|
2014-02-20 01:54:40 +01:00
|
|
|
PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntTy);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PITy(*PITyDIE);
|
2014-04-25 22:00:34 +02:00
|
|
|
auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
|
2014-02-20 01:54:40 +01:00
|
|
|
DIEString PIStr(&One, "PI");
|
|
|
|
DIEInteger Two(2);
|
|
|
|
DIEInteger NegThree(-3);
|
|
|
|
PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr);
|
|
|
|
PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
|
|
|
|
PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PITy);
|
|
|
|
PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, &NegThree);
|
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
A.addChild(std::move(PI));
|
2014-02-20 01:54:40 +01:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
|
|
|
|
}
|
2014-02-20 03:50:45 +01:00
|
|
|
|
|
|
|
// Derived from:
|
|
|
|
// struct A {
|
|
|
|
// const static float PI = 3.14;
|
|
|
|
// };
|
|
|
|
// A a;
|
|
|
|
TEST(DIEHashTest, MemberBlock) {
|
|
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEString AStr(&One, "A");
|
|
|
|
A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
|
|
|
|
A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
|
|
|
|
|
|
|
|
DIEInteger Four(4);
|
|
|
|
DIEString FStr(&One, "float");
|
2014-04-25 22:00:34 +02:00
|
|
|
auto FloatTyDIE = make_unique<DIE>(dwarf::DW_TAG_base_type);
|
2014-02-20 03:50:45 +01:00
|
|
|
FloatTyDIE->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
|
|
|
|
FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Four);
|
|
|
|
FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry FloatTy(*FloatTyDIE);
|
2014-04-25 22:00:34 +02:00
|
|
|
auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
|
2014-02-20 03:50:45 +01:00
|
|
|
PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FloatTy);
|
|
|
|
|
2014-04-25 21:33:43 +02:00
|
|
|
DIEEntry PITy(*PITyDIE);
|
2014-04-25 22:00:34 +02:00
|
|
|
auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
|
2014-02-20 03:50:45 +01:00
|
|
|
DIEString PIStr(&One, "PI");
|
|
|
|
DIEInteger Two(2);
|
|
|
|
PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr);
|
|
|
|
PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
|
|
|
|
PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
|
|
|
|
PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PITy);
|
|
|
|
PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
|
|
|
|
|
2014-04-25 19:07:55 +02:00
|
|
|
DIEBlock PIBlock;
|
2014-02-20 03:50:45 +01:00
|
|
|
DIEInteger Blk1(0xc3);
|
|
|
|
DIEInteger Blk2(0xf5);
|
|
|
|
DIEInteger Blk3(0x48);
|
|
|
|
DIEInteger Blk4(0x40);
|
|
|
|
|
2014-04-25 19:07:55 +02:00
|
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk1);
|
|
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk2);
|
|
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk3);
|
|
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk4);
|
2014-02-20 03:50:45 +01:00
|
|
|
|
2014-04-25 19:07:55 +02:00
|
|
|
PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, &PIBlock);
|
2014-02-20 03:50:45 +01:00
|
|
|
|
2014-04-25 22:00:34 +02:00
|
|
|
A.addChild(std::move(PI));
|
2014-02-20 03:50:45 +01:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
|
|
|
|
}
|
2013-09-03 23:57:57 +02:00
|
|
|
}
|