Download presentation
Presentation is loading. Please wait.
Published byWilla Ellis Modified over 9 years ago
1
Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New Mexico USA March 17, 2005 Hui Wu, Jeff Gray, Marjan Mernik, and Suman Roychoudhury http://www.cis.uab.edu/wuh/DDF This Research is Supported by Eclipse Innovation Grant by IBM
2
Challenges with DSL Debugging Domain Experts program at DSL level DSL translated into General Purpose Language (GPL) Domain Experts deal with DSL Integrated Development Environment Editor Compiler Visualizer Debugge r Domain Experts deal with GPL
3
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
4
Architecture of DSL Debugging Framework DSL grammar is defined using ANTLR Notation DSL is the input of the Lexer and Parser generated by ANTLR DSL translation process Robot DSL corresponding GPL code generated in Java Additional Mapping code generated in Java Corresponding GPL and Mapping Code are inputs of Mapping component jdb communicates with mapping component Eclipse Debugging perspective communicates with mapping component
5
Architecture of DSL Debugging Framework Reuse existing GPL standalone command line debugger Generative Programming techniques are used to synthesize debugger mapping code from DSL grammar specification Utilize the debugging methods mapping knowledge and source code mapping information to generate the DSL debugger in Eclipse Map the GPL debugger output messages back to the DSL level through the wrapper interface
6
Mapping Technique to Generate Debugger Source Code Mapping Source Code Mapping 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. DSL Debugger Framework (DDF) Debug Methods Mapping 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.
7
Debugging: A Crosscutting Grammar Concern dsllinenumber=dsllinenumber+1; gplbeginline=fileio.getLinenumber(); gplendline=fileio.getLinenumber(); filemap.print(" mapping.add(new Map("+dsllinenumber+", \"Robot.java\","+gplbeginline+","+gplendline+"));"); … 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(" "); } | … dsllinenumber=dsllinenumber+1; gplbeginline=fileio.getLinenumber(); gplendline=fileio.getLinenumber(); filemap.print(" mapping.add(new Map("+dsllinenumber+", \"Robot.java\","+gplbeginline+","+gplendline+"));"); Base Grammar Duplicate Debugging Aspect Code What if this line changes? Change here Change ……
8
First Approach: Weaving at GPL Level DSL Grammar ANTLR Parser Lexer In Java Debugging Aspect Specification In AspectJ AspectJ Compiler Parser’ Lexer’ With Debugging Aspects Weaved in DSL Code Debugging Mapping Code GPL In Java
9
First Approach: Weaving at GPL Level … 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;} … … try { // for error handling { switch ( LA(1)) { case RIGHT: case LEFT: case UP: case DOWN: case INIT: case SET: case PRINT: { command(); commands(); break; } case END: { System.out.println(" "); break; } default: { throw new NoViableAltException(LT(1), getFilename()); … Generated Parser code by ANTLR Debugging Aspect in AspectJ
10
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
11
Second Approach: Weaving into DSL Grammars DSL Grammar ANTLR Debugging Aspect Specification In Parlanse Function Parser’ Lexer’ With Debugging Aspects Weaved in DSL Code Debugging Mapping Code GPL In Java DMS DSL Grammar’ With Debugging Aspect Weaved In
12
Second Approach: Weaving into DSL Grammars Transform actual DSL Grammar Unique contribution of this paper Language independence. 12 Steps to Weave Debugging Aspects into DSL Grammar Level Using a Program Transformation Engine (DMS) 1. Specify ANTLR grammar specification 2. Specify Java semantic actions using DMS regular expression 3. Generate ANTLR Parser 4. Generate abstract syntax tree with ANTLR_ACTION nodes 5. Search ANTLR_ACTION nodes from the generated AST 6. Retrieve ANTLR_ACTION nodes and store them in a hash map 7. Retrieve associated string expression from each ANTLR_ACTION node 8. Modify the regular Java parser by changing the starting production 9. Parse the associated string expressions as regular Java statement lists 10.Transform the statement lists using the ASTInterface API 11.Regenerate the ANTLR_ACTION nodes with debugging aspects weaved in 12.Output the complete ANTLR AST (with modified action nodes) … 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+"));"); } |LEFT { dsllinenumber=dsllinenumber+1; fileio.print("//move left"); 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+"));"); } …
13
DSL Debugger Perspective in Eclipse
14
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
15
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 language- based tools JastAdd is a Java based compiler construction system for AST transformation using JavaCC and tree- building using JJTree.
16
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 AspectANTLR to be developed to remove accidental complexities of using DMS IDE platform is based solely on IBM Eclipse support for other IDEs will be needed Experimentation performed only on a simple imperative DSL additional experimental validation needed for other types of DSLs
17
Questions? Summary of URLs referenced in talk DSL Debugger Framework http://www.cis.uab.edu/wuh/DDF ANTLR http://www.antlr.org AspectJ http://www.aspectj.org DMS http://www.semdesigns.com
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.