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 ?

Thanks.

4 comments

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:
https://github.com/JetBrains/kotlin/blob/ba6da7c40a6cc502508faf6e04fa105b96bc7777/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinLineBreakpointType.java

https://github.com/JetBrains/kotlin/blob/37411c823df28b43a83b4b517e9aee77f312550f/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt

0

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.

0

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.

0

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.

0

Please sign in to leave a comment.