MCJUG Presentation - Computer and Information Sciences

Download Report

Transcript MCJUG Presentation - Computer and Information Sciences

Extending the Eclipse Debug Perspective and
JUnit to Support Testing and Debugging of
Domain-Specific Languages
Magic City Java User ’s Group
Hui Wu and Jeff Gray
Department of Computer and Information Sciences
University of Alabama at Birmingham
http://www.cis.uab.edu/wuh
August 16, 2005
1
Categories of End-Users
Spreadsheet
Admin
Assistants
Business
Query Systems
Businessman
Auto Factory
Worker
Scientist
Albert Einstein
Modeling
Language
DSL for
Physics
2
Problems


Computer errors cost economy millions of
dollars each year
 $60 billion per year in US [CNN05, TR02]
The dangers of end-user programming [Har05]
 End-users often lack knowledge of software
development principles
 Inadequate testing and debugging processes
 No testing tools support for end-users
(especially for DSL users)
3
Motivation of Proposed Research
Editor
Domain Experts program
at DSL level
Compiler
Visualizer
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
Domain Experts
deal with GPL
Profiler
Test Engine
Integrated Development
Environment (IDE)
Domain Experts
deal with DSL
4
Mismatch Between Abstraction Levels
ANTLR Grammar
….
commands
: ( c:command cs:commands
|
)
;
command
: ( RIGHT
{
fileio.print("//move right");
fileio.print("x=x+1;");
fileio.print("time=time+1;");
fileio.print(" ");
}
|LEFT
{
fileio.print("//move left");
fileio.print("x=x-1;");
fileio.print("time=time+1;");
fileio.print(" ");
…
Generated Java Parser Code
….
public final void commands() throws RecognitionException, TokenStreamException {
try {
// for error handling
{
switch ( LA(1)) {
case CALL:
case INIT:
case SET:
case PRINT:
{
command();
commands();
break;
}
case END:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
…
public final void function_name() throws RecognitionException,
TokenStreamException {
try {
// for error handling
{
switch ( LA(1)) {
case RIGHT:
{
match(RIGHT);
fileio.print("
//move right");
fileio.print("
move_right();");
fileio.print(" ");
break;
}
case LEFT:
{
match(LEFT);
sllinenumber=dsllinenumber+1;
fileio.print("
//move left");
fileio.print("
move_left();");
fileio.print(" ");
break;
}
5
…
Difficulties with Building DSL Testing Tools

Debuggers and Profilers are difficult to build
because they depend heavily on the
underlying operating system’s capabilities and
lower-level native code functionality

Manual construction of the test tools for each
new DSL can be time-consuming, expensive,
and error-prone
6
Background

Eclipse Debugger
Platform

Eclipse Unit Test
Platform

Design Maintenance
System (DMS)
7
Research Directions
Imperative
DSLs
Debuggers
Unit Test
Engines
Profilers
Declarative
DSLs
Hybrid
DSLs
construction of the same
software tool (e.g., debugging)
to different categories of DSLs
vertical direction corresponds to
the vector representing the
various testing tools that will be
applied to DSLs
8
Research Goal

A Matrix of DSL Testing Tools
Imperative DSL
Debugger
Imperative DSL
Unit Test Engine
Imperative DSL
Profiler
Declarative DSL
Debugger
Declarative DSL
Unit Test Engine
Declarative DSL
Profiler
Hybrid DSL
Debugger
generalized approach
to produce a software
product line of testing
tools for DSLs
Hybrid DSL
Unit Test Engine
Hybrid DSL
Profiler
Future Work
By Product
Weaving Aspects into
DSL Grammars
9
A Horizontal Direction:
Debuggers for Different Types of DSLs

Imperative DSL: Centered around assignment
expressions or control flow statements

Robot Language
…
17
18
19
20
21
22
23
24
25
26
27
28
…
Down:
position(+0,-1)
Down: F_end
M_end
Init position(0,0)
Call left
Call down
Call knight
Set position(5,6)
Call up
Call right
Print position
10
A Horizontal Direction:
Debuggers for Different Types of DSLs

Declarative DSL: declares the relationship
between inputs and outputs.

1
2
3
4
5
6
Feature Definition Language (FDL)
Car : all (Carbody, Transmission, Engine, Horsepower, opt(pullsTrailer))
Transmission : oneof (automatic, manual)
Engine : moreof (electric, gasoline)
Horsepower : oneof (lowPower, mediumPower, highPower)
include pullsTrailer
pullsTrailer requires highPower
11
A Horizontal Direction:
Debuggers for Different Types of DSLs

Hybrid DSL: embedded GPL code within the
DSL description
…
80 functionbodys
81 :(functionbody functionbodys
82
|
83 )
84 ;
85
86 functionbody
87 :(VARIABLES LPAREN op1:OP func_num1 :NUMBER COMMA op2:OP func_num2:NUMBER RPAREN
88
{ funcall="functionbody";
89
dsllinenumber=dsllinenumber+1;
90
fileio.print("x=x"+op1.getText()+func_num1.getText()+";");
91
gplbeginline=fileio.getLinenumber();
92
fileio.print("y=y"+op2.getText()+func_num2.getText()+";");
93
fileio.print("time=time+1;");
94
gplendline=fileio.getLinenumber();
95
filemap.print("mapping.add(newMap("+dsllinenumber+",\"Robot.java\","
96
+gplbeginline+","+gplendline+","+"\""+funcname+"\""
97
+","+"\""+funcall+"\""+"));");
98
}
99 )
100 ;
12
…
Approaches Used in This Project
Syntax-Directed
Translation
Eclipse
Plug-In Based
Software
Development
ANTLR
Design Patterns
Automated
Software
Engineering
Software
Model-View-Controller
Adapter Pattern
Weaving Aspects
into
DSL Grammars
6 after(int commandname):
7
call(void antlr.Parser.match(int))
8 && args(commandname)
9
{ match(commandname); }
10 pointcut count_dsllinenumber():
11
call (void P.command());
12 after(): count_dsllinenumber(){
13
{ dsllinenumber=dsllinenumber+1;}
AspectG
13
DSL Debugger Framework (DDF)
Eclipse Debugging Framework
Debugger Perspective
DSL
GPL
ANTLR
Translator
Source Code
Mapping
Debugging Methods
Mapping
Re-Mapping
Re-interpreter
GPL Debugger Server
14
Processes of DSL Debugger Generation
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
Robot DSL
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
15
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 ……
16
Weaving into DSL Grammars Using AspectG
Debugging Aspect
Specification In AspectG
DSL
Grammar
Parlanse Functions
DSL Code
DMS
DSL Grammar’
With Debugging
Aspect Weaved In
ANTLR
Lexer’
GPL
Parser’
Debugging
Mapping
Code
With Debugging
Aspects Weaved in
In Java 17
Pointcut Model for AspectG
ANTLR Grammar
…
command
:( RIGHT
{
dsllinenumber=dsllinenumber+1;
fileio.print("//move right");
fileio.print("x=x+1;");
fileio.print("time=time+1;");
gplbeginline=fileio.getLinenumber();
gplendline=fileio.getLinenumber();
fileio.print(" ");
filemap.print(" mapping.add(new Map("+
dsllinenumber+", \"Robot.java\","+gplbeginline+
","+gplendline+"));");
}
…
AspectG
pointcut productions():
within(command.*);
pointcut count_gpllinenumber():
within(command.*) &&
match (fileio.print("time=time+1;"));
before(): productions()
{ dsllinenumber=dsllinenumber+1;}
after(): count_gpllinenumber()
{gplbeginline=fileio.getLinenumber();
gplendline=fileio.getLinenumber();}
after(): productions()
{filemap.print(" mapping.add(new Map("+
dsllinenumber+", \"Robot.java\","+gplbeginline+
","+gplendline+"));"); }
18
DSL Debugger Perspective in Eclipse
19
Declarative DSL Debugger
20
Demonstration
21
DSL Unit Test Framework (DUTF)



Similar to the DSL Debugging Framework
architecture and approaches
Complement to the DSL Debugging
Framework, identify the existence of program
errors
To monitor the performance of DSLs at run
time, similar architecture and approaches can
be applied to DSL Profiler Framework (DPF)
to generate DSL profilers
22
DSL Unit Test Perspective in Eclipse
23
DSL Unit Test Perspective in Eclipse
24
Demonstration
25
Summary




End-user developers (e.g., scientist, accountant, and
statistician) are in large number
Software failures caused by program errors pose a
great threat to economy
Testing and Debugging on GPLs have been
investigated for decades, but testing and debugging
DSLs has been neglected.
Several publication reviews, paper citations, and
source code requests indicate the proposed research
is in the right direction.
26
Thank you for coming!
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
27
Backup Slides
28
Experimental Validation of Proposed Work


Various types of DSLs serve as test cases
 Robot Language (imperative DSL)
 FDL (declarative DSL)
 ANTLR grammar (hybrid DSL)
Qualitative Metrics-How well the generated
testing tools behave
 To what degree of success can the DSL
unit test engine detect errors in DSL
program units?
 To what degree can the DSL debugger help
end-users to locate and fix the detected
errors?
29
Related Work

ASF+SDF




Khepera



Does not generate test engines and profilers
ToolBus Integrated Debugging Environment (TIDE), 4
tedious steps to implement debugger for a new language
AspectAsf: weave debugging aspects into all potential
program locations.
Support optimization code debugger
Store transformation information in a database
LISA

Debugger, test engine, and profiler are not the target
language tools, LISA can be used as the front-end of our
framework [HPM+05].
30
Related Work

SmartTools



JTS



Complicated mechanism (e.g., Language extension)
Dose not provide rich transformation ability
JastAdd


Base on Java and XML technologies
Debugger, test engine, and profiler are not target language
tools
Aspect weaving in Compiler construction
Aspect-Oriented Compiler

Aspect weaving in Compiler construction
31
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
32
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());
33
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 cases, the generated code is
unreadable by a human
34
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
35
Second Approach: Weaving into DSL Grammars
…
command
:( RIGHT
{
1.
ANTLR grammar
specification
dsllinenumber=dsllinenumber+1;
 Specify
Transform
actual
DSL
Grammar
2. Specify
Java semantic actions
using
DMS regular expression
fileio.print("
//move
right");
fileio.print("
x=x+1;");
3. Generate
ANTLR
Parser
 Unique
contribution
of this research
fileio.print("
time=time+1;");
4. Generate
abstract syntax tree with ANTLR_ACTION nodes
gplbeginline=fileio.getLinenumber();
 Search
Language
independence.
gplendline=fileio.getLinenumber();
5.
ANTLR_ACTION
nodes from the generated AST
fileio.print(" ");
6. Retrieve
ANTLR_ACTION
nodes
and store them in a hash map
filemap.print("
mapping.add(new
Map("+dsllinenumber+",
\"Robot.java\","+gplbeginline+","+gplendline+"));");
7. Retrieve
associated string expression from each ANTLR_ACTION node
}
8.
the regular
parserDebugging
by changing the Aspects
starting production
|LEFT
 Modify
12 Steps
to Java
Weave
into
9.
{ Parse the associated string expressions as regular Java statement lists
dsllinenumber=dsllinenumber+1;
DSL
Grammar
Level
Using
a Program
10.Transform
the statement
lists//move
using
the ASTInterface
API
fileio.print("
left");
11.Regenerate
the ANTLR_ACTION
nodes
with debugging
fileio.print("
x=x-1;");
Transformation
Engine
(DMS)
time=time+1;");
aspectsfileio.print("
weaved in
gplbeginline=fileio.getLinenumber();
12.Output
the complete ANTLR AST (with modified action nodes)
gplendline=fileio.getLinenumber()
fileio.print(" ");
filemap.print(" mapping.add(new Map("+dsllinenumber+",
\"Robot.java\","+gplbeginline+","+gplendline+"));");
}
…
36