Custom language debugger

I try to figure out how to implement a debugger for a custom language.
The custom language is interpreted by an interpreter written java. The interpreter contains a bunch of "eval" methods.
My idea is to remap a breakpoint in custom-language code to a java breakpoint in one of those "eval" method (with some condition).

Is it feasible, and if so what direction should I take ? Should I use JavaBreakpointAware ? Should I implement a LocationManager ? BreakpointHandler ? CustomBreakpointType ?



Hi, it should be possible to implement it the same way kotlin, scala and other jvm based languages debuggers work. I would start with:

  • create your own breakpoint type, extend JavaLineBreakpointType
  • create and register JavaBreakpointHandlerFactory for your breakpoint type
  • create and register your own PositionManager to be able to map jdi Locations to your sources and back
  • to start java debug session copy the code from/around `com.intellij.debugger.impl.GenericDebuggerRunner#attachVirtualMachine`

as a reference see:


Hi Egor

Thanks for your help.

I started to implement the required components and I have some difficulties with the PositionManager.
My problem is to implement the byteCode to custom language mapping. (i.e. getSourcePosition)

The interpreter contains 8 evalXYZ methods. Any breakpoint in custom language is remapped to one of those evalXYZ.
As soon as there is 2 custom-language-breakpoints matching the same evalXYZ method: 
I don't know how to find the correct SourcePosition based only on the jdi Location.

I don't have a one-to-one mapping between byte code location to custom language source position.
I have "one byteCode location to many SourcePosition".

I don't know if the Kotlin debugger is facing the same problem, and if it does I didn't understood how it is solved.


Kotlin is compiled and not interpreted, so there's no such problem there. If jdi location is not mapped to the source line I'm not sure how to implement this. When you stop in java debugger it has jdi location (basically an offset inside a method) and call stack frames.

This may be possible to solve if the interpreter received extra information about the source it interpret, for example line number or something like that. Not sure this will help the currect PositionManager (as it only receives Location), but with some modifications it should be at least feasible.


The interpreter knows exactly the custom language source position. So I think that if I can place a hook when the breakpoint is hit, I can inspect the internal data of the interpreter and focus on the required line in custom language.


Please sign in to leave a comment.