13. MyDbgPrint("Address 'add' : %pn", add); // Print address of “add”
__writemsr(IA32_DEBUGCTL, 1); // 0x1D9 Start Branch Recording
tmp = add(10,20); // The Address Here is 0x9db8f258
tmp += add(10,30); // The Address Here is 0x9db8f264
__writemsr(IA32_DEBUGCTL, 0); // End Branch Recording
TOS = __readmsr(MSR_LASTBRANCH_TOS); // 0x1C9 Get Top of the Stack
MyDbgPrint("TOS:%d", TOS);
for( i = 0; i<4 ; i++ ){
FROM_IP[i] = __readmsr(MSR_LASTBRANCH_0_FROM_IP+i); // 0x680 + i
TO_IP[i] = __readmsr(MSR_LASTBRANCH_0_TO_IP+i); // 0x6C0 + i
}
for( i = 0 ; i < 4; i++ ){
MyDbgPrint("FROM_IP%d : 0x%016I64xn", i, FROM_IP[i]);
MyDbgPrint("TO_IP%d : 0x%016I64xn", i, TO_IP[i]);
}
14. Address 'add' : 9DB8F180
TOS:3
FROM_IP0 : 0x000000009db8f258 // From first add() call
TO_IP0 : 0x000000009db8f180 // To “add” function
FROM_IP1 : 0x000000009db8f18c // From end of “add” function (return)
TO_IP1 : 0x000000009db8f25d // To next of “FROM_IP0”
FROM_IP2 : 0x000000009db8f264 // From second add() call
TO_IP2 : 0x000000009db8f180 // To “add” function
FROM_IP3 : 0x000000009db8f18c // From end of “add” function (return)
TO_IP3 : 0x000000009db8f269 // To next of “FROM_IP2”