A Practical Guide to Ballerina Remote Debugging

Ballerina is an open source general purpose programming language and platform designed by WSO2. It is an easy to write programming language that just works, and suitable for cloud-era application programmers.

What is debugging?

Debugging could be known as the process of detecting and removing of existing and potential errors (also called as “bugs”) in a software code that can cause it to behave unexpectedly or crash. To prevent incorrect operation of a software or system, debugging is used to find and resolve the bugs or defects.

Starting a Remote Debug Session

In this article, I will walkthrough on how to remote debug a simple Hello World program in Ballerina.

A simple Hello World program in Ballerina looks as follows:

Now let's get into the action! 😃

Follow the below steps to start a remote debug session in VSCode:

  1. Click the Run icon in the left menu or press the Control + Shift + D keys, to launch the Debugger view(for Mac — Command + Shift +D).

2. Click on create a launch.json file and then select Ballerina Debug.

3. Once we select the Ballerina Debug option, a launch.json file will be opened. Here we can give the relevant configurations for remote debug (eg: debuggeeHost, debbuggeePort).

4. Select the .bal file to be debugged (In the screenshot it is main.bal).

5. Add the debug points you require by clicking in front of the line numbers of the required file.

6. Open the terminal and execute the ballerina run command in debug mode as follows:

Following are the supported remote debugging commands in Ballerina:

  • Debugging a ballerina package/ single file
  • Debugging ballerina tests
  • Debugging ballerina tests during the build

7. Once we run the ballerina run command in debug mode, the terminal will show the following log:

8. After seeing the above log, select Ballerina Remote from the drop down available in the upper left corner.

9. Now click the Run button in the upper left corner to start remote debugging.

Once the debug point gets hit, the VSCode looks as follows:

All the above mentioned steps can be simply seen in the below GIF:

That’s all folk!s. In this article, you learned what is debugging and how to start a remote debug session in Ballerina.

Thank you for reading and see you in the next post. Happy Debugging! 😃

Software Engineer at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store