Debugging the Ballerina Compiler

This article describes how to debug the Ballerina compiler using IntelliJ Idea. We are talking about debugging the compiler itself. Not debugging your Ballerina application.

You might find this useful if you want to understand the internals of how the compiler works.

First, clone the Ballerina repository.

git clone --recursive
git submodule update --init 

Then, open the project from IntelliJ Idea. You can do this by opening the root level pom file as a project.

Now build the project with maven.

mvn idea:idea 
mvn clean install

This should create the ballerina executable at distribution/zip/ballerina/target/ballerina–

We need to use the ballerina compiler in the above SNAPSHOT folder when doing our debugging. Unzip it to a convenient location. (I used /Library/Ballerina)

Now comes the fun part.

Run ballerina in remote debug mode with the following command. (Use the one just built in the above step!. The point is to make sure the code open in the IDEA exactly matches the executable it’s going to debug)

$ BAL_JAVA_DEBUG=5005 /Library/Ballerina/ballerina-0.982.1-SNAPSHOT/bin/ballerina run main.bal 
Please start the remote debugging client to continue...
Listening for transport dt_socket at address: 5005

It is waiting for the remote debugger to connect. In that case, we have to fire up the debugger from IntelliJ IDEA.

Set up the breakpoints as required, and then press the debug button. The debugger will connect to the executable and hit the breakpoints during execution.

Happy debugging!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.