Skip to content

Commit

Permalink
[LoongArch64] Initial DFEATURE_EMULATE_SINGLESTEP for LA64. (#105741)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyXu-HF committed Aug 1, 2024
1 parent b284b1c commit e3684bc
Show file tree
Hide file tree
Showing 9 changed files with 620 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/clrdefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if (CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:UNIX_ARM_ABI>)
elseif (CLR_CMAKE_TARGET_ARCH_I386)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:UNIX_X86_ABI>)
elseif (CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
add_definitions(-DFEATURE_EMULATE_SINGLESTEP)
endif()

endif(CLR_CMAKE_TARGET_UNIX)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/ee/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ void DebuggerController::ApplyTraceFlag(Thread *thread)
g_pEEInterface->MarkThreadForDebugStepping(thread, true);
LOG((LF_CORDB,LL_INFO1000, "DC::ApplyTraceFlag marked thread for debug stepping\n"));

SetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread));
SetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread) LOONGARCH64_ARG(thread));
}

//
Expand Down Expand Up @@ -3239,7 +3239,7 @@ void DebuggerController::UnapplyTraceFlag(Thread *thread)

// Always need to unmark for stepping
g_pEEInterface->MarkThreadForDebugStepping(thread, false);
UnsetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread));
UnsetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread) LOONGARCH64_ARG(thread));
}

void DebuggerController::EnableExceptionHook()
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15890,7 +15890,7 @@ BOOL Debugger::IsThreadContextInvalid(Thread *pThread, CONTEXT *pCtx)
if (success)
{
// Check single-step flag
if (IsSSFlagEnabled(reinterpret_cast<DT_CONTEXT *>(pCtx) ARM_ARG(pThread) ARM64_ARG(pThread) RISCV64_ARG(pThread)))
if (IsSSFlagEnabled(reinterpret_cast<DT_CONTEXT *>(pCtx) ARM_ARG(pThread) ARM64_ARG(pThread) RISCV64_ARG(pThread) LOONGARCH64_ARG(pThread)))
{
// Can't hijack a thread whose SS-flag is set. This could lead to races
// with the thread taking the SS-exception.
Expand Down
22 changes: 22 additions & 0 deletions src/coreclr/debug/ee/loongarch64/primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,25 @@ void CopyREGDISPLAY(REGDISPLAY* pDst, REGDISPLAY* pSrc)
CONTEXT tmp;
CopyRegDisplay(pSrc, pDst, &tmp);
}

void SetSSFlag(DT_CONTEXT *, Thread *pThread)
{
_ASSERTE(pThread != NULL);

pThread->EnableSingleStep();
}

void UnsetSSFlag(DT_CONTEXT *, Thread *pThread)
{
_ASSERTE(pThread != NULL);

pThread->DisableSingleStep();
}

// Check if single stepping is enabled.
bool IsSSFlagEnabled(DT_CONTEXT *, Thread *pThread)
{
_ASSERTE(pThread != NULL);

return pThread->IsSingleStepEnabled();
}
23 changes: 7 additions & 16 deletions src/coreclr/debug/inc/loongarch64/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,15 @@ inline bool AddressIsBreakpoint(CORDB_ADDRESS_TYPE* address)
return CORDbgGetInstruction(address) == CORDbg_BREAK_INSTRUCTION;
}

inline void SetSSFlag(DT_CONTEXT *pContext)
{
// TODO-LoongArch64: LoongArch64 doesn't support cpsr.
_ASSERTE(!"unimplemented on LOONGARCH64 yet");
}
class Thread;
// Enable single stepping.
void SetSSFlag(DT_CONTEXT *pCtx, Thread *pThread);

inline void UnsetSSFlag(DT_CONTEXT *pContext)
{
// TODO-LoongArch64: LoongArch64 doesn't support cpsr.
_ASSERTE(!"unimplemented on LOONGARCH64 yet");
}
// Disable single stepping
void UnsetSSFlag(DT_CONTEXT *pCtx, Thread *pThread);

inline bool IsSSFlagEnabled(DT_CONTEXT * pContext)
{
// TODO-LoongArch64: LoongArch64 doesn't support cpsr.
_ASSERTE(!"unimplemented on LOONGARCH64 yet");
return false;
}
// Check if single stepping is enabled.
bool IsSSFlagEnabled(DT_CONTEXT *pCtx, Thread *pThread);


inline bool PRDIsEqual(PRD_TYPE p1, PRD_TYPE p2)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ elseif(CLR_CMAKE_TARGET_ARCH_LOONGARCH64)

set(VM_SOURCES_WKS_ARCH
${ARCH_SOURCES_DIR}/profiler.cpp
${ARCH_SOURCES_DIR}/singlestepper.cpp
gcinfodecoder.cpp
)
elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
Expand Down
Loading

0 comments on commit e3684bc

Please sign in to comment.