MIT Crafts Tool to Easily Debug Domain-Specific Programming Languages

Programming using low-level languages ​​can be a difficult task, requiring years of education, experience, and knowledge. To address this challenge, researchers and companies are investigating domain-specific languages ​​(DSLs) that provide the benefits of programming for a specific use case without the need for esoteric programming knowledge. Because DSLs are more specialized, the program runs faster.

Debugging is a persistent challenge with DSLs

Debugging is a persistent challenge with DSLs. Image courtesy of Alex Shipps/MIT CSAIL via Midjourney

But one issue that has plagued DSLs is ridding the software of errors through debugging. The lack of debugging support for this type of language has sometimes been called the “Achilles heel for DSLs.” To sidestep the challenges of using an existing debugger on a new, specific programming language, researchers from MIT recently announced a new tool called D2X, which makes debugging DSLs significantly easier.

What Are Domains-Specific Languages?

A domain-specific programming language is a computer programming language designed to address a specific problem domain or use case. In contrast to general-purpose programming languages ​​such as Java or Python, which can be used to solve a variety of problems, DSLs are created explicitly to target a particular application or field.

DSLs also offer a high level of abstraction compared to general programming languages. Because of this, DSLs are much simpler to use than standard programming languages.

DSLs allow users to access domain-specific knowledge with ease

DSLs allow users to access domain-specific knowledge with ease. Image courtesy of Meinte Boersma. (Click image to enlarge)

An image-processing DSL, for example, contains pre-written software functions for standard processing tasks like image blurring. A user can simply call a “blur image” function without writing the underlying code to enable such a function.

In this way, DSLs increase the efficiency of software development by allowing users to express concepts and solutions in a language that is tailored to their specific needs. By providing a specialized syntax and a set of features that are optimized for a particular domain, DSLs can make it easier to write correct and maintainable code while reducing the programming expertise required to achieve such functionality.

MIT Develops a “DSL for Creating DSLs”

In 2021, a group of researchers led by MIT PhD student Ajay Brahmakshatriya and MIT Professor Saman Amarasinghe developed a software package called BuildIt said to significantly simplify the task of creating DSLs.

The researchers posit that while it’s almost impossible to write a completely error-free program the first time, these errors often show up later in a development cycle, sometimes 5,000 lines of code in, when it can be very difficult to find bugs. This makes it especially time-consuming and tedious for software engineers to debug once a program is code complete and ready for testing. In addition, existing debuggers don’t understand the specifics of DSLs, making them slow and inefficient.

Building on their BuildIt research, the team at MIT recently introduced a new tool that may solve the debugging challenges of DSLs.

D2X: A Simple Debugging Infrastructure for DSLs

The new tool, called D2X, is a DSL debugging infrastructure compatible with most standard debuggers that doesn’t require any modifications to the debuggers themselves.

D2X is a C++ library composed of two distinct parts: a compiler library, called D2X-C, and a runtime library, called D2X-R. To invoke D2X, a developer must call the D2X-C API to encode DSL-related debug information, such as the source location, in the input of the DSL as well as live variables and their values. Then, the user can invoke the D2X-R library API, providing variables and source information and inserting and removing breakpoints from the DSL.

Mapping of source information with D2X

Mapping of source information with D2X. Image courtesy of MIT

The most important feature of using D2X as an interface is its easy compatibility with existing DSLs. With D2X, the researchers augmented existing DSLs with debugging support by changing as little as 1.4% of the compiler code base. By adding debugging support to DSLs, users have an end-to-end picture of their DSL code. The result should be improved productivity for both the end user and the DSL designer.

In the future, the MIT team would like to merge more features with BuildIt, including editing functions to highlight keywords and autocomplete text. The researchers also intend to add profilers along with debuggers to help developers assess performance issues in their programs.