AOSD Presentation - University of Alabama

Download Report

Transcript AOSD Presentation - University of Alabama

Weaving a Debugging Aspect into
Domain-Specific Language Grammars
Hui Wu, Jeff Gray, Marjan Mernik, and
Suman Roychoudhury
http://www.cis.uab.edu/wuh/DDF
SAC ’05 PSC Track
Santa Fe, New Mexico USA
March 17, 2005
This Research is Supported by
Eclipse Innovation Grant by IBM
Challenges with DSL Debugging
Editor
Domain Experts program
at DSL level
Compiler
Visualizer
Domain Experts
deal with GPL
subselect me
subselect me
begin
left
right
up
down
end
Translater
public class Robot{
public static void
main(String[] args) {
Robot robot =new Robot(0,0,0);
//move left
robot.move_left();
//move down
robot.move_down();robot.x = 5;
robot.y = 6;
DSL translated into
General Purpose Language (GPL)
Debugge
r
Integrated
Development
Environment
Domain Experts
deal with DSL
Difficulties with Constructing a DSL Debugger

Difficulties with Constructing a DSL Debugger
 A debugger is difficult to build because it depends heavily on
the underlying operating system’s capabilities and lower-level
native code functionality
 Manual construction of the debugger for each new DSL can
be time-consuming, expensive, and error-prone

Motivation of building a DSL Debugger




Domain experts lack knowledge about the underlying GPL
Although techniques for constructing a debugger for a GPL
have been developed over the years, debug support for
DSLs has not been investigated deeply
The underlying GPL can be messy and human unreadable
One line of DSL can be translated into tens of lines of GPL
code
Architecture of DSL Debugging
Framework
Robot DSL
DSL
DSL
is grammar
the input of
isthe
defined
Lexerusing
and
ANTLR
Parser generated
Notation
by
ANTLR
Robot DSL
1
2
3
4
5
6
begin
left
down
up
right
end
corresponding
GPL code
generated in
Java
DSL
translation
process
Robot.java and Mapping.java
//move down
y=y-1;
time=time+1;
……
}
2
1
Additional
Mapping code
generated in
Java
public class Robot
{
public static void main(String[] args) {
……
//move left
x=x-1;
time=time+1;
3
Corresponding GPL
Lexer,
and Parser
Mapping Code
are inputs of Mapping
Eclipse Debugging
Generatedcomponent
Lexer, and Parser
by ANTLR
perspective
jdb
communicates with
communicates
mapping component
with mapping
component
4
Variables
}
import java.util.ArrayList;
Robot DSL Grammar In ANTLR Notation
Debugger
View
public class Mapping {
ArrayList mapping;
public Mapping(){
mapping=new ArrayList();
mapping.add(new Map(1, "Robot.java",2,8));
mapping.add(new Map(2, "Robot.java",10,14));
……
}
}
View
6
5
Mapping
Component
DSL
Editor
Java Command Line Debugger
Robot DSL Debugging Perspective in Eclipse
Mapping Technique to Generate Debugger
Source Code
Mapping
Debug Methods
Mapping
DSL Debugger
Framework (DDF)
The source code mapping process
uses
the
generated
mapping
information to determine which line of
the DSL code is mapped to the
corresponding segment of GPL code.
It indicates the location of the GPL
code segment.
The debug methods mapping
process takes the user’s debugging
commands from the debugger
perspective at the DSL level to
determine what type of debugging
commands need to be issued to a
command line debugger at the GPL
level.
Debugging: A Crosscutting Grammar Concern
Base Grammar
…
command
:( RIGHT
{
fileio.print("
fileio.print("
//move right");
x=x+1;");
What
if thishere
line changes?
Change
Duplicate Debugging Aspect Code
fileio.print("
time=time+1;");
dsllinenumber=dsllinenumber+1;
gplbeginline=fileio.getLinenumber();
gplendline=fileio.getLinenumber();
fileio.print(" ");
}
|LEFT
{
filemap.print(" mapping.add(new Map("+dsllinenumber+",
\"Robot.java\","+gplbeginline+","+gplendline+"));");
fileio.print("
fileio.print("
//move left");
x=x-1;");
Change here
fileio.print("
fileio.print(" ");
}
|
…
time=time+1;");
Change ……
First Approach: Weaving at GPL Level
Lexer
DSL
Grammar
ANTLR
Parser
In Java
Debugging Aspect
Specification
In AspectJ
AspectJ
Compiler
DSL Code
Lexer’
GPL
Parser’
Debugging
Mapping
Code
With Debugging
Aspects Weaved in
In Java
First Approach: Weaving at GPL Level
Generated
Parser code by ANTLR
…
try {
…
// for error handling
Debugging Aspect in AspectJ
{
…
switch ( LA(1)) {
6 after(int commandname):
case RIGHT:
case LEFT:
7
call(void antlr.Parser.match(int))
case UP:
8 && args(commandname)
case DOWN:
9
{ match(commandname); }
case INIT:
10 pointcut count_dsllinenumber():
case SET:
case PRINT:
11
call (void P.command());
{
12 after(): count_dsllinenumber(){
command();
13
{ dsllinenumber=dsllinenumber+1;}
commands();
break;
…
}
case END:
{
System.out.println(" ");
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
First Approach: Weaving at GPL Level
Disadvantages:

The lack of mature aspect weavers for many languages
(e.g., Object Pascal, C, or Ada)

Requires the developer of the DSL to have detailed
knowledge of the code generator within ANTLR in order
to construct the appropriate pointcuts.

In some case, the generated code is unreadable by a
human
Second Approach: Weaving into DSL Grammars
DSL
Grammar
Debugging Aspect
Specification
In Parlanse Function
DSL Code
DMS
DSL Grammar’
With Debugging
Aspect Weaved In
ANTLR
Lexer’
GPL
Parser’
Debugging
Mapping
Code
With Debugging
Aspects Weaved in
In Java
Second Approach: Weaving into DSL Grammars
…
command
:( RIGHT
{
dsllinenumber=dsllinenumber+1;
1.
ANTLR grammar
specification
 Specify
Transform
actual
DSL
Grammar
fileio.print("
//move right");
2. Specify
Java semantic actions
using DMS regular expression
fileio.print("
x=x+1;");
 Unique
contribution
of this paper
fileio.print("
time=time+1;");
3. Generate
ANTLR
Parser
gplbeginline=fileio.getLinenumber();
4. Generate
abstract syntax tree with ANTLR_ACTION nodes
gplendline=fileio.getLinenumber();
 Language
independence.
5. Search
ANTLR_ACTION
nodes from the generated AST
fileio.print(" ");
filemap.print("
mapping.add(new
Map("+dsllinenumber+",
6. Retrieve
ANTLR_ACTION
nodes
and store them in a hash map
\"Robot.java\","+gplbeginline+","+gplendline+"));");
7.
} Retrieve associated string expression from each ANTLR_ACTION node
|LEFT
8.
the regular
Java
parserDebugging
by changing the Aspects
starting production
 Modify
12
Steps
to
Weave
into
{
9. Parse
the associated string expressions as regular Java statement lists
dsllinenumber=dsllinenumber+1;
DSL
Grammar
Level
Using
a Program
fileio.print("
left");
10.Transform
the statement
lists//move
using
the ASTInterface
API
fileio.print("
x=x-1;");
11.Regenerate
the
ANTLR_ACTION
nodes
with debugging
Transformation
Engine
(DMS)
fileio.print("
time=time+1;");
aspectsgplbeginline=fileio.getLinenumber();
weaved in
gplendline=fileio.getLinenumber()
12.Output
the complete ANTLR AST (with modified action nodes)
fileio.print(" ");
filemap.print(" mapping.add(new Map("+dsllinenumber+",
\"Robot.java\","+gplbeginline+","+gplendline+"));");
}
…
DSL Debugger Perspective in Eclipse
Future Work

More complex DSLs and different types of DSLs
need to be investigated

Imperative, declarative, and hybrid DSLs

Domain-Specific Language Unit Test Framework
(DUTF) to complement the DDF

Domain-Specific Language Profiler Framework
(DPF) to monitor the runtime environment and
performance of the DSL
Related Work

SmartTools is a software factory which generate
language development environment based on Java
and XML technologies. But the tools like debugger,
is not in the generation list.

The Language Implementation System on Attribute
Grammars (LISA) tool is a grammar-based system to
generate a compiler, interpreter, and other languagebased tools

JastAdd is a Java based compiler construction system
for AST transformation using JavaCC and tree-building
using JJTree.
Conclusion



This paper describes two different approaches to
modularize the DSL debugger generation process.
The second approach, which weaves debugging
aspects directly into a DSL grammar, offers the most
flexibility.
Drawback of current effort

Initial learning curve for DMS is huge


IDE platform is based solely on IBM Eclipse


AspectANTLR to be developed to remove accidental complexities of
using DMS
support for other IDEs will be needed
Experimentation performed only on a simple imperative DSL

additional experimental validation needed for other types of DSLs
Questions?

Summary of URLs referenced in talk

DSL Debugger Framework


ANTLR


http://www.antlr.org
AspectJ


http://www.cis.uab.edu/wuh/DDF
http://www.aspectj.org
DMS

http://www.semdesigns.com