Skip to content

Commit e3684bc

Browse files
authored
[LoongArch64] Initial DFEATURE_EMULATE_SINGLESTEP for LA64. (#105741)
1 parent b284b1c commit e3684bc

File tree

9 files changed

+620
-20
lines changed

9 files changed

+620
-20
lines changed

src/coreclr/clrdefinitions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ if (CLR_CMAKE_TARGET_UNIX)
2828
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:UNIX_ARM_ABI>)
2929
elseif (CLR_CMAKE_TARGET_ARCH_I386)
3030
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:UNIX_X86_ABI>)
31+
elseif (CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
32+
add_definitions(-DFEATURE_EMULATE_SINGLESTEP)
3133
endif()
3234

3335
endif(CLR_CMAKE_TARGET_UNIX)

src/coreclr/debug/ee/controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,7 @@ void DebuggerController::ApplyTraceFlag(Thread *thread)
32023202
g_pEEInterface->MarkThreadForDebugStepping(thread, true);
32033203
LOG((LF_CORDB,LL_INFO1000, "DC::ApplyTraceFlag marked thread for debug stepping\n"));
32043204

3205-
SetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread));
3205+
SetSSFlag(reinterpret_cast<DT_CONTEXT *>(context) ARM_ARG(thread) ARM64_ARG(thread) RISCV64_ARG(thread) LOONGARCH64_ARG(thread));
32063206
}
32073207

32083208
//
@@ -3239,7 +3239,7 @@ void DebuggerController::UnapplyTraceFlag(Thread *thread)
32393239

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

32453245
void DebuggerController::EnableExceptionHook()

src/coreclr/debug/ee/debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15890,7 +15890,7 @@ BOOL Debugger::IsThreadContextInvalid(Thread *pThread, CONTEXT *pCtx)
1589015890
if (success)
1589115891
{
1589215892
// Check single-step flag
15893-
if (IsSSFlagEnabled(reinterpret_cast<DT_CONTEXT *>(pCtx) ARM_ARG(pThread) ARM64_ARG(pThread) RISCV64_ARG(pThread)))
15893+
if (IsSSFlagEnabled(reinterpret_cast<DT_CONTEXT *>(pCtx) ARM_ARG(pThread) ARM64_ARG(pThread) RISCV64_ARG(pThread) LOONGARCH64_ARG(pThread)))
1589415894
{
1589515895
// Can't hijack a thread whose SS-flag is set. This could lead to races
1589615896
// with the thread taking the SS-exception.

src/coreclr/debug/ee/loongarch64/primitives.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,25 @@ void CopyREGDISPLAY(REGDISPLAY* pDst, REGDISPLAY* pSrc)
1010
CONTEXT tmp;
1111
CopyRegDisplay(pSrc, pDst, &tmp);
1212
}
13+
14+
void SetSSFlag(DT_CONTEXT *, Thread *pThread)
15+
{
16+
_ASSERTE(pThread != NULL);
17+
18+
pThread->EnableSingleStep();
19+
}
20+
21+
void UnsetSSFlag(DT_CONTEXT *, Thread *pThread)
22+
{
23+
_ASSERTE(pThread != NULL);
24+
25+
pThread->DisableSingleStep();
26+
}
27+
28+
// Check if single stepping is enabled.
29+
bool IsSSFlagEnabled(DT_CONTEXT *, Thread *pThread)
30+
{
31+
_ASSERTE(pThread != NULL);
32+
33+
return pThread->IsSingleStepEnabled();
34+
}

src/coreclr/debug/inc/loongarch64/primitives.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,15 @@ inline bool AddressIsBreakpoint(CORDB_ADDRESS_TYPE* address)
219219
return CORDbgGetInstruction(address) == CORDbg_BREAK_INSTRUCTION;
220220
}
221221

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

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

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

241232

242233
inline bool PRDIsEqual(PRD_TYPE p1, PRD_TYPE p2)

src/coreclr/vm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ elseif(CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
842842

843843
set(VM_SOURCES_WKS_ARCH
844844
${ARCH_SOURCES_DIR}/profiler.cpp
845+
${ARCH_SOURCES_DIR}/singlestepper.cpp
845846
gcinfodecoder.cpp
846847
)
847848
elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)

0 commit comments

Comments
 (0)