Skip to content

Commit cdaacbb

Browse files
committed
[clr-interp] Add support for DOTNET_InterpHalt
This flag adds a `INTOP_BREAKPOINT` instruction at the beginning of the method. This opcode calls the `InterpBreakpoint` method. In order to make use of this debug option, you need to add a breakpoint to this method. An alternative would be to use special instructions to trigger a trap in the debugger, but there is no clean cross platform way to do this currently. Using `__builtin_debugtrap()` on arm64 doesn't allow for step/continue, you would need to set the PC register manually to the next instruction in order to exit the trap, making it a pain to use.
1 parent 97c44df commit cdaacbb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/coreclr/interpreter/compiler.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,15 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
18031803
goto exit_bad_code;
18041804
}
18051805

1806+
m_currentILOffset = -1;
1807+
1808+
#if DEBUG
1809+
if (m_methodName && InterpConfig.InterpHalt() && !strcmp(m_methodName, InterpConfig.InterpHalt()))
1810+
AddIns(INTOP_BREAKPOINT);
1811+
#endif
1812+
18061813
if ((methodInfo->options & CORINFO_OPT_INIT_LOCALS) && m_ILLocalsSize > 0)
18071814
{
1808-
m_currentILOffset = 0;
18091815
AddIns(INTOP_INITLOCALS);
18101816
m_pLastNewIns->data[0] = m_ILLocalsOffset;
18111817
m_pLastNewIns->data[1] = m_ILLocalsSize;

src/coreclr/interpreter/intops.def

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ OPDEF(INTOP_NEWOBJ_VT, "newobj.vt", 5, 1, 1, InterpOpMethodToken)
252252
OPDEF(INTOP_CALL_HELPER_PP, "call.helper.pp", 5, 1, 0, InterpOpThreeInts)
253253

254254
OPDEF(INTOP_ZEROBLK_IMM, "zeroblk.imm", 3, 0, 1, InterpOpInt)
255+
OPDEF(INTOP_BREAKPOINT, "breakpoint", 1, 0, 0, InterpOpNoArgs)
255256
OPDEF(INTOP_FAILFAST, "failfast", 1, 0, 0, InterpOpNoArgs)
256257

257258
// All instructions after this point are IROPS, instructions that are not emitted/executed

src/coreclr/vm/interpexec.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ InterpThreadContext* InterpGetThreadContext()
3131
}
3232
}
3333

34+
#ifdef DEBUG
35+
static void InterpBreakpoint()
36+
{
37+
38+
}
39+
#endif
40+
3441
#define LOCAL_VAR_ADDR(offset,type) ((type*)(stack + (offset)))
3542
#define LOCAL_VAR(offset,type) (*LOCAL_VAR_ADDR(offset, type))
3643
// TODO once we have basic EH support
@@ -60,6 +67,12 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
6067

6168
switch (*ip)
6269
{
70+
#ifdef DEBUG
71+
case INTOP_BREAKPOINT:
72+
InterpBreakpoint();
73+
ip++;
74+
break;
75+
#endif
6376
case INTOP_INITLOCALS:
6477
memset(stack + ip[1], 0, ip[2]);
6578
ip += 3;

0 commit comments

Comments
 (0)