-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
arm_primitives.h
116 lines (91 loc) · 2.95 KB
/
arm_primitives.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//*****************************************************************************
// File: arm_primitives.h
//
//
// ARM/ARM64-specific debugger primitives
//
//*****************************************************************************
#ifndef ARM_PRIMITIVES_H_
#define ARM_PRIMITIVES_H_
//
// Mapping from ICorDebugInfo register numbers to CorDebugRegister
// numbers. Note: this must match the order in corinfo.h.
//
inline CorDebugRegister ConvertRegNumToCorDebugRegister(ICorDebugInfo::RegNum reg)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(reg >= 0);
_ASSERTE(static_cast<size_t>(reg) < ARRAY_SIZE(g_JITToCorDbgReg));
return g_JITToCorDbgReg[reg];
}
inline LPVOID CORDbgGetIP(DT_CONTEXT *context)
{
LIMITED_METHOD_CONTRACT;
return (LPVOID)(size_t)(context->Pc);
}
inline void CORDbgSetInstructionExImpl(CORDB_ADDRESS_TYPE* address,
PRD_TYPE instruction)
{
LIMITED_METHOD_DAC_CONTRACT;
*(PRD_TYPE *)address = instruction;
FlushInstructionCache(GetCurrentProcess(),
address,
sizeof(PRD_TYPE));
}
inline PRD_TYPE CORDbgGetInstructionExImpl(UNALIGNED CORDB_ADDRESS_TYPE* address)
{
LIMITED_METHOD_CONTRACT;
return *(PRD_TYPE *)address;
}
inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address)
{
LIMITED_METHOD_CONTRACT;
CORDbgSetInstruction(address, CORDbg_BREAK_INSTRUCTION);
}
inline void CORDbgInsertBreakpointExImpl(UNALIGNED CORDB_ADDRESS_TYPE *address)
{
LIMITED_METHOD_CONTRACT;
CORDbgSetInstruction(address, CORDbg_BREAK_INSTRUCTION);
}
// After a breakpoint exception, the CPU points to _after_ the break instruction.
// Adjust the IP so that it points at the break instruction. This lets us patch that
// opcode and re-execute what was underneath the bp.
inline void CORDbgAdjustPCForBreakInstruction(DT_CONTEXT* pContext)
{
LIMITED_METHOD_CONTRACT;
#if defined(TARGET_ARM64)
pContext->Pc -= CORDbg_BREAK_INSTRUCTION_SIZE;
#else
// @ARMTODO: ARM appears to leave the PC at the start of the breakpoint (at least according to Windbg,
// which may be adjusting the view).
#endif
return;
}
inline bool AddressIsBreakpoint(CORDB_ADDRESS_TYPE* address)
{
LIMITED_METHOD_CONTRACT;
return CORDbgGetInstruction(address) == CORDbg_BREAK_INSTRUCTION;
}
class Thread;
// Enable single stepping.
void SetSSFlag(DT_CONTEXT *pCtx, Thread *pThread);
// Disable single stepping
void UnsetSSFlag(DT_CONTEXT *pCtx, Thread *pThread);
// Check if single stepping is enabled.
bool IsSSFlagEnabled(DT_CONTEXT *pCtx, Thread *pThread);
inline bool PRDIsEqual(PRD_TYPE p1, PRD_TYPE p2)
{
return p1 == p2;
}
inline void InitializePRD(PRD_TYPE *p1)
{
*p1 = 0;
}
inline bool PRDIsEmpty(PRD_TYPE p1)
{
LIMITED_METHOD_CONTRACT;
return p1 == 0;
}
#endif // ARM_PRIMITIVES_H_