未验证 提交 f818e296 编写于 作者: S Steve MacLean 提交者: GitHub

Apple silicon debugger (#47834)

* Use PAL_JITWriteEnable in debug/ee/controller.cpp

* Fix breakpoint exception handling on macos

* Fix Arm64SingleStepper for osx W^X

* Fix DebuggerHeapExecutableMemoryPage for W^X

* Fix DebuggerEval::DebuggerEval() during W^X
上级 6c564444
......@@ -1364,6 +1364,9 @@ bool DebuggerController::ApplyPatch(DebuggerControllerPatch *patch)
LPVOID baseAddress = (LPVOID)(patch->address);
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#else // defined(HOST_OSX) && defined(HOST_ARM64)
DWORD oldProt;
if (!VirtualProtect(baseAddress,
......@@ -1373,12 +1376,14 @@ bool DebuggerController::ApplyPatch(DebuggerControllerPatch *patch)
_ASSERTE(!"VirtualProtect of code page failed");
return false;
}
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
patch->opcode = CORDbgGetInstruction(patch->address);
CORDbgInsertBreakpoint((CORDB_ADDRESS_TYPE *)patch->address);
LOG((LF_CORDB, LL_EVERYTHING, "Breakpoint was inserted at %p for opcode %x\n", patch->address, patch->opcode));
#if !defined(HOST_OSX) || !defined(HOST_ARM64)
if (!VirtualProtect(baseAddress,
CORDbg_BREAK_INSTRUCTION_SIZE,
oldProt, &oldProt))
......@@ -1386,6 +1391,7 @@ bool DebuggerController::ApplyPatch(DebuggerControllerPatch *patch)
_ASSERTE(!"VirtualProtect of code page failed");
return false;
}
#endif // !defined(HOST_OSX) || !defined(HOST_ARM64)
}
// TODO: : determine if this is needed for AMD64
#if defined(TARGET_X86) //REVISIT_TODO what is this?!
......@@ -1454,6 +1460,9 @@ bool DebuggerController::UnapplyPatch(DebuggerControllerPatch *patch)
LPVOID baseAddress = (LPVOID)(patch->address);
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#else // defined(HOST_OSX) && defined(HOST_ARM64)
DWORD oldProt;
if (!VirtualProtect(baseAddress,
......@@ -1468,6 +1477,7 @@ bool DebuggerController::UnapplyPatch(DebuggerControllerPatch *patch)
InitializePRD(&(patch->opcode));
return false;
}
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
CORDbgSetInstruction((CORDB_ADDRESS_TYPE *)patch->address, patch->opcode);
......@@ -1476,6 +1486,7 @@ bool DebuggerController::UnapplyPatch(DebuggerControllerPatch *patch)
//header file comment)
InitializePRD(&(patch->opcode));
#if !defined(HOST_OSX) || !defined(HOST_ARM64)
if (!VirtualProtect(baseAddress,
CORDbg_BREAK_INSTRUCTION_SIZE,
oldProt, &oldProt))
......@@ -1483,6 +1494,7 @@ bool DebuggerController::UnapplyPatch(DebuggerControllerPatch *patch)
_ASSERTE(!"VirtualProtect of code page failed");
return false;
}
#endif // !defined(HOST_OSX) || !defined(HOST_ARM64)
}
else
{
......
......@@ -1381,6 +1381,10 @@ DebuggerEval::DebuggerEval(CONTEXT * pContext, DebuggerIPCE_FuncEvalInfo * pEval
{
WRAPPER_NO_CONTRACT;
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
// Allocate the breakpoint instruction info in executable memory.
m_bpInfoSegment = new (interopsafeEXEC, nothrow) DebuggerEvalBreakpointInfoSegment(this);
......
......@@ -1114,6 +1114,10 @@ struct DECLSPEC_ALIGN(4096) DebuggerHeapExecutableMemoryPage
inline void SetNextPage(DebuggerHeapExecutableMemoryPage* nextPage)
{
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
chunks[0].bookkeeping.nextPage = nextPage;
}
......@@ -1124,6 +1128,10 @@ struct DECLSPEC_ALIGN(4096) DebuggerHeapExecutableMemoryPage
inline void SetPageOccupancy(uint64_t newOccupancy)
{
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
// Can't unset first bit of occupancy!
ASSERT((newOccupancy & 0x8000000000000000) != 0);
......@@ -1137,6 +1145,10 @@ struct DECLSPEC_ALIGN(4096) DebuggerHeapExecutableMemoryPage
DebuggerHeapExecutableMemoryPage()
{
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
SetPageOccupancy(0x8000000000000000); // only the first bit is set.
for (uint8_t i = 1; i < sizeof(chunks)/sizeof(chunks[0]); i++)
{
......
......@@ -206,6 +206,9 @@ void Arm64SingleStepper::Apply(T_CONTEXT *pCtx)
// control in the breakpoint fixup logic we can then reset the PC to its proper location.
unsigned int idxNextInstruction = 0;
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
#endif // defined(HOST_OSX) && defined(HOST_ARM64)
if (TryEmulate(pCtx, opcode, false))
{
......
......@@ -5191,11 +5191,11 @@ BOOL HandleHardwareException(PAL_SEHException* ex)
Thread *pThread = GetThread();
if (pThread != NULL && g_pDebugInterface != NULL)
{
// On ARM and ARM64 Linux exception point to the break instruction.
#if (defined(TARGET_ARM) || defined(TARGET_ARM64))
// On ARM and ARM64 exception point to the break instruction.
// See https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf#page=6916&zoom=100,0,152
// at aarch64/exceptions/debug/AArch64.SoftwareBreakpoint
// However, the rest of the code expects that it points to an instruction after the break.
#if defined(__linux__) && (defined(TARGET_ARM) || defined(TARGET_ARM64))
if (ex->GetExceptionRecord()->ExceptionCode == STATUS_BREAKPOINT)
{
SetIP(ex->GetContextRecord(), GetIP(ex->GetContextRecord()) + CORDbg_BREAK_INSTRUCTION_SIZE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册