Index: src/processor/cfi_frame_info_unittest.cc |
=================================================================== |
--- a/src/processor/cfi_frame_info_unittest.cc |
+++ b/src/processor/cfi_frame_info_unittest.cc |
@@ -49,70 +49,70 @@ using testing::A; |
using testing::AtMost; |
using testing::DoAll; |
using testing::Return; |
using testing::SetArgumentPointee; |
using testing::Test; |
class MockMemoryRegion: public MemoryRegion { |
public: |
- MOCK_CONST_METHOD0(GetBase, u_int64_t()); |
- MOCK_CONST_METHOD0(GetSize, u_int32_t()); |
- MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(u_int64_t, u_int8_t *)); |
- MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(u_int64_t, u_int16_t *)); |
- MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(u_int64_t, u_int32_t *)); |
- MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(u_int64_t, u_int64_t *)); |
+ MOCK_CONST_METHOD0(GetBase, uint64_t()); |
+ MOCK_CONST_METHOD0(GetSize, uint32_t()); |
+ MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(uint64_t, uint8_t *)); |
+ MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(uint64_t, uint16_t *)); |
+ MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(uint64_t, uint32_t *)); |
+ MOCK_CONST_METHOD2(GetMemoryAtAddress, bool(uint64_t, uint64_t *)); |
}; |
// Handy definitions for all tests. |
struct CFIFixture { |
// Set up the mock memory object to expect no references. |
void ExpectNoMemoryReferences() { |
EXPECT_CALL(memory, GetBase()).Times(0); |
EXPECT_CALL(memory, GetSize()).Times(0); |
- EXPECT_CALL(memory, GetMemoryAtAddress(_, A<u_int8_t *>())).Times(0); |
- EXPECT_CALL(memory, GetMemoryAtAddress(_, A<u_int16_t *>())).Times(0); |
- EXPECT_CALL(memory, GetMemoryAtAddress(_, A<u_int32_t *>())).Times(0); |
- EXPECT_CALL(memory, GetMemoryAtAddress(_, A<u_int64_t *>())).Times(0); |
+ EXPECT_CALL(memory, GetMemoryAtAddress(_, A<uint8_t *>())).Times(0); |
+ EXPECT_CALL(memory, GetMemoryAtAddress(_, A<uint16_t *>())).Times(0); |
+ EXPECT_CALL(memory, GetMemoryAtAddress(_, A<uint32_t *>())).Times(0); |
+ EXPECT_CALL(memory, GetMemoryAtAddress(_, A<uint64_t *>())).Times(0); |
} |
CFIFrameInfo cfi; |
MockMemoryRegion memory; |
- CFIFrameInfo::RegisterValueMap<u_int64_t> registers, caller_registers; |
+ CFIFrameInfo::RegisterValueMap<uint64_t> registers, caller_registers; |
}; |
class Simple: public CFIFixture, public Test { }; |
// FindCallerRegs should fail if no .cfa rule is provided. |
TEST_F(Simple, NoCFA) { |
ExpectNoMemoryReferences(); |
cfi.SetRARule("0"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(".ra: 0", cfi.Serialize()); |
} |
// FindCallerRegs should fail if no .ra rule is provided. |
TEST_F(Simple, NoRA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("0"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(".cfa: 0", cfi.Serialize()); |
} |
TEST_F(Simple, SetCFAAndRARule) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("330903416631436410"); |
cfi.SetRARule("5870666104170902211"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(2U, caller_registers.size()); |
ASSERT_EQ(330903416631436410ULL, caller_registers[".cfa"]); |
ASSERT_EQ(5870666104170902211ULL, caller_registers[".ra"]); |
ASSERT_EQ(".cfa: 330903416631436410 .ra: 5870666104170902211", |
cfi.Serialize()); |
} |
@@ -121,17 +121,17 @@ TEST_F(Simple, SetManyRules) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("$temp1 68737028 = $temp2 61072337 = $temp1 $temp2 -"); |
cfi.SetRARule(".cfa 99804755 +"); |
cfi.SetRegisterRule("register1", ".cfa 54370437 *"); |
cfi.SetRegisterRule("vodkathumbscrewingly", "24076308 .cfa +"); |
cfi.SetRegisterRule("pubvexingfjordschmaltzy", ".cfa 29801007 -"); |
cfi.SetRegisterRule("uncopyrightables", "92642917 .cfa /"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(6U, caller_registers.size()); |
ASSERT_EQ(7664691U, caller_registers[".cfa"]); |
ASSERT_EQ(107469446U, caller_registers[".ra"]); |
ASSERT_EQ(416732599139967ULL, caller_registers["register1"]); |
ASSERT_EQ(31740999U, caller_registers["vodkathumbscrewingly"]); |
ASSERT_EQ(-22136316ULL, caller_registers["pubvexingfjordschmaltzy"]); |
ASSERT_EQ(12U, caller_registers["uncopyrightables"]); |
@@ -145,152 +145,152 @@ TEST_F(Simple, SetManyRules) { |
} |
TEST_F(Simple, RulesOverride) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("330903416631436410"); |
cfi.SetRARule("5870666104170902211"); |
cfi.SetCFARule("2828089117179001"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(2U, caller_registers.size()); |
ASSERT_EQ(2828089117179001ULL, caller_registers[".cfa"]); |
ASSERT_EQ(5870666104170902211ULL, caller_registers[".ra"]); |
ASSERT_EQ(".cfa: 2828089117179001 .ra: 5870666104170902211", |
cfi.Serialize()); |
} |
class Scope: public CFIFixture, public Test { }; |
// There should be no value for .cfa in scope when evaluating the CFA rule. |
TEST_F(Scope, CFALacksCFA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule(".cfa"); |
cfi.SetRARule("0"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
} |
// There should be no value for .ra in scope when evaluating the CFA rule. |
TEST_F(Scope, CFALacksRA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule(".ra"); |
cfi.SetRARule("0"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
} |
// The current frame's registers should be in scope when evaluating |
// the CFA rule. |
TEST_F(Scope, CFASeesCurrentRegs) { |
ExpectNoMemoryReferences(); |
registers[".baraminology"] = 0x06a7bc63e4f13893ULL; |
registers[".ornithorhynchus"] = 0x5e0bf850bafce9d2ULL; |
cfi.SetCFARule(".baraminology .ornithorhynchus +"); |
cfi.SetRARule("0"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(2U, caller_registers.size()); |
ASSERT_EQ(0x06a7bc63e4f13893ULL + 0x5e0bf850bafce9d2ULL, |
caller_registers[".cfa"]); |
} |
// .cfa should be in scope in the return address expression. |
TEST_F(Scope, RASeesCFA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("48364076"); |
cfi.SetRARule(".cfa"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(2U, caller_registers.size()); |
ASSERT_EQ(48364076U, caller_registers[".ra"]); |
} |
// There should be no value for .ra in scope when evaluating the CFA rule. |
TEST_F(Scope, RALacksRA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("0"); |
cfi.SetRARule(".ra"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
} |
// The current frame's registers should be in scope in the return |
// address expression. |
TEST_F(Scope, RASeesCurrentRegs) { |
ExpectNoMemoryReferences(); |
registers["noachian"] = 0x54dc4a5d8e5eb503ULL; |
cfi.SetCFARule("10359370"); |
cfi.SetRARule("noachian"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(2U, caller_registers.size()); |
ASSERT_EQ(0x54dc4a5d8e5eb503ULL, caller_registers[".ra"]); |
} |
// .cfa should be in scope for register rules. |
TEST_F(Scope, RegistersSeeCFA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("6515179"); |
cfi.SetRARule(".cfa"); |
cfi.SetRegisterRule("rogerian", ".cfa"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(3U, caller_registers.size()); |
ASSERT_EQ(6515179U, caller_registers["rogerian"]); |
} |
// The return address should not be in scope for register rules. |
TEST_F(Scope, RegsLackRA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("42740329"); |
cfi.SetRARule("27045204"); |
cfi.SetRegisterRule("$r1", ".ra"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
} |
// Register rules can see the current frame's register values. |
TEST_F(Scope, RegsSeeRegs) { |
ExpectNoMemoryReferences(); |
registers["$r1"] = 0x6ed3582c4bedb9adULL; |
registers["$r2"] = 0xd27d9e742b8df6d0ULL; |
cfi.SetCFARule("88239303"); |
cfi.SetRARule("30503835"); |
cfi.SetRegisterRule("$r1", "$r1 42175211 = $r2"); |
cfi.SetRegisterRule("$r2", "$r2 21357221 = $r1"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(4U, caller_registers.size()); |
ASSERT_EQ(0xd27d9e742b8df6d0ULL, caller_registers["$r1"]); |
ASSERT_EQ(0x6ed3582c4bedb9adULL, caller_registers["$r2"]); |
} |
// Each rule's temporaries are separate. |
TEST_F(Scope, SeparateTempsRA) { |
ExpectNoMemoryReferences(); |
cfi.SetCFARule("$temp1 76569129 = $temp1"); |
cfi.SetRARule("0"); |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
cfi.SetCFARule("$temp1 76569129 = $temp1"); |
cfi.SetRARule("$temp1"); |
- ASSERT_FALSE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_FALSE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
} |
class MockCFIRuleParserHandler: public CFIRuleParser::Handler { |
public: |
MOCK_METHOD1(CFARule, void(const string &)); |
MOCK_METHOD1(RARule, void(const string &)); |
MOCK_METHOD2(RegisterRule, void(const string &, const string &)); |
@@ -422,53 +422,53 @@ class ParseHandlerFixture: public CFIFix |
class ParseHandler: public ParseHandlerFixture, public Test { }; |
TEST_F(ParseHandler, CFARARule) { |
handler.CFARule("reg-for-cfa"); |
handler.RARule("reg-for-ra"); |
registers["reg-for-cfa"] = 0x268a9a4a3821a797ULL; |
registers["reg-for-ra"] = 0x6301b475b8b91c02ULL; |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(0x268a9a4a3821a797ULL, caller_registers[".cfa"]); |
ASSERT_EQ(0x6301b475b8b91c02ULL, caller_registers[".ra"]); |
} |
TEST_F(ParseHandler, RegisterRules) { |
handler.CFARule("reg-for-cfa"); |
handler.RARule("reg-for-ra"); |
handler.RegisterRule("reg1", "reg-for-reg1"); |
handler.RegisterRule("reg2", "reg-for-reg2"); |
registers["reg-for-cfa"] = 0x268a9a4a3821a797ULL; |
registers["reg-for-ra"] = 0x6301b475b8b91c02ULL; |
registers["reg-for-reg1"] = 0x06cde8e2ff062481ULL; |
registers["reg-for-reg2"] = 0xff0c4f76403173e2ULL; |
- ASSERT_TRUE(cfi.FindCallerRegs<u_int64_t>(registers, memory, |
+ ASSERT_TRUE(cfi.FindCallerRegs<uint64_t>(registers, memory, |
&caller_registers)); |
ASSERT_EQ(0x268a9a4a3821a797ULL, caller_registers[".cfa"]); |
ASSERT_EQ(0x6301b475b8b91c02ULL, caller_registers[".ra"]); |
ASSERT_EQ(0x06cde8e2ff062481ULL, caller_registers["reg1"]); |
ASSERT_EQ(0xff0c4f76403173e2ULL, caller_registers["reg2"]); |
} |
struct SimpleCFIWalkerFixture { |
struct RawContext { |
- u_int64_t r0, r1, r2, r3, r4, sp, pc; |
+ uint64_t r0, r1, r2, r3, r4, sp, pc; |
}; |
enum Validity { |
R0_VALID = 0x01, |
R1_VALID = 0x02, |
R2_VALID = 0x04, |
R3_VALID = 0x08, |
R4_VALID = 0x10, |
SP_VALID = 0x20, |
PC_VALID = 0x40 |
}; |
- typedef SimpleCFIWalker<u_int64_t, RawContext> CFIWalker; |
+ typedef SimpleCFIWalker<uint64_t, RawContext> CFIWalker; |
SimpleCFIWalkerFixture() |
: walker(register_map, |
sizeof(register_map) / sizeof(register_map[0])) { } |
static CFIWalker::RegisterSet register_map[7]; |
CFIFrameInfo call_frame_info; |
CFIWalker walker; |
@@ -499,26 +499,26 @@ TEST_F(SimpleWalker, Walk) { |
// cfa -> |
// |
// r0 has been saved on the stack. |
// r1 has been saved in r2. |
// r2 and r3 are not recoverable. |
// r4 is not recoverable, even though it is a callee-saves register. |
// Some earlier frame's unwinder must have failed to recover it. |
- u_int64_t stack_top = 0x83254944b20d5512ULL; |
+ uint64_t stack_top = 0x83254944b20d5512ULL; |
// Saved r0. |
EXPECT_CALL(memory, |
- GetMemoryAtAddress(stack_top, A<u_int64_t *>())) |
+ GetMemoryAtAddress(stack_top, A<uint64_t *>())) |
.WillRepeatedly(DoAll(SetArgumentPointee<1>(0xdc1975eba8602302ULL), |
Return(true))); |
// Saved return address. |
EXPECT_CALL(memory, |
- GetMemoryAtAddress(stack_top + 16, A<u_int64_t *>())) |
+ GetMemoryAtAddress(stack_top + 16, A<uint64_t *>())) |
.WillRepeatedly(DoAll(SetArgumentPointee<1>(0xba5ad6d9acce28deULL), |
Return(true))); |
call_frame_info.SetCFARule("sp 24 +"); |
call_frame_info.SetRARule(".cfa 8 - ^"); |
call_frame_info.SetRegisterRule("r0", ".cfa 24 - ^"); |
call_frame_info.SetRegisterRule("r1", "r2"); |