Graduation Project

Download Report

Transcript Graduation Project

Masters Project
Reverse Engineering state machine diagrams from
C/C++ code
Vanderlande Industries B.V. (Veghel)
Dennie van Zeeland
Slide 1, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Outline
• Introduction
- Vanderlande Industries
- FSC
• Project goal
• Tools
- CPP2XMI
• Approach
• Extensions / Improvements
• Problems
Slide 2, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (1)
• Vanderlande Industries (VI)
- Veghel, near A50
- Automated material handling systems:
• distribution centres
- Nike, Friesche Vlag, Amazon.de, Audi
- FALCON project by ESI, VI, 3TU (SET)
• baggage handling at airports
- Eindhoven Airport, Schiphol, Heathrow (T5), Honk Kong I.A.
• express parcel sortation facilities
- DHL, DPD, TNT Express Worldwide, UPS, Integra2 (Madrid)
Slide 3, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (2)
• Flow System Controller (FSC)
- Controls the product flows in conveyor systems for transport and
sortation
- Controls all motors, photocells and other active components
- Send and receive control and status information
-
Realtime Control of equipment
Separated GUI
Standard interfaces with equipment
Fully configurable for all VI sorting equipment
Slide 4, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (3)
- Flow System Controller
Slide 5, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (4)
- Flow System Controller
Slide 6, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (5)
- Flow System Controller
Slide 7, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Project goal (1)
• Reverse Engineering documentation from C/C++ source code
-
-
-
Why:
• Limited documentation available for V5/V6
• V7 is being developed from scratch
• Extracting dynamic behavior from source code for V7
• Identifying requirements
• Identifying possible flaws in current versions
What kind of documentation
• UML models
- Class diagrams
- Sequence diagrams
- Activity diagrams
- State machine diagrams
Sparse amount of documentation available
• Engineering manual
- Description of components
Slide 8, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Project goal (2)
• Reverse Engineering documentation from C/C++ source code
-
-
Investigating current state of the art tools
Extracting State Machine diagrams from code (main focus)
• Preprocessing source code
• Parsing source code
• Finding patterns in source code of state machines
• Creating diagrams
Extracting Class diagrams from code (if time left)
Slide 9, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Tools
• No tools are applicable to FSC
- FSC is written in object oriented C
- Current tools only work on C++
- No tools are available for state machine extraction
• current tool is very specific for FSC (thus not generally applicable for any
software system)
• No complete state machine can be extracted
• Cpp2XMI
- LaQuSo (Laboratory for Quality Software)
- C++ to UML-diagrams
• Class diagram
• Sequence diagram
• Activity diagram
Slide 10, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Abstract Syntax
CPP2XMI
Tree in XML-format
CPPML
C++ Source
Code
Preprocessor
Pre-processed
C++ Source
Code
Columbus
Parser &
Exporter
Library
Filter
XMI
Class Diagram in
XML (XMI)-format
Filtered
Columbus
CPPML
Diagram
Extractor
XMI (with
layout)
Filtered
Columbus XMI
Class, Sequence,
Activity Diagram in
XML (XMI)-format
Slide 11, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
CPP2XMI
Add Layout
using ClassLayout
Abstract
Syntax Tree
(CPPML
filtered)
Parser for
CPPML
Store
(internal
datastructure
)
Collaboration
Organizer
Activity
Organizer
Store
(internal
datastructure
)
Add Layout
using DotLayout
Add Layout
using
SeuenceLayout
Store
(internal
datastructure
) + Layout
Form XMItags / Write
to File
UML model
in XMI 1.1
(with layout)
Slide 12, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Approach
• Implement a simple state machine extractor for FSC
- Find 1 specific pattern
- Integrate state machine extractor into CPP2XMI
• Create 2nd parser for CPPML
• Storage in internal data structures
• State Machine organizer
• Adding layout (position information)
• XMI writer / DOT writer
- Extending with extra patterns
• Proof of concept on source code of a component of FSC
Slide 13, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
CPP2XMI
Parser for
CPPML
Abstract
Syntax Tree
(CPPML
filtered)
Add Layout
using ClassLayout
Collaboration
Organizer
Store
(internal
datastructure
)
Activity
Organizer
X
Second
Parser for
CPPML for
Objective C
State
Machine
Organizer
Could be
improved
Store
(internal
datastructure
)
Add Layout
using DotLayout
Add Layout
using
SeuenceLayout
Add Layout
using
StateDotLayout
Store
(internal
datastructure
) + Layout
Form XMItags / Write
to File
UML model
in XMI 1.1
(with layout)
Slide 14, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Example
Source Code
CPPML
static void obj_control(Obj
*obj, ObjEvent event)
{…
switch (obj->state) {
case State_A:
switch (event) {
case event1:
…
obj->state = State_B;
break;
case event2:
…
obj->state = State_C;
…
break;}
break;
case State_B:
switch (event) {
case event1:
…
obj->state = State_B;
…
break;
case event3:
…
obj->state = State_C;
…
break;}
break;
default;}}
<struc:Function id='id109‘ name='OBJ_control'>
<statm:Switch id='id110'>
<statm:hasCondition>
{obj->state}
</statm:hasCondition>
<statm:Block id='id118'>
<statm:Switch id='id119'>
{event}
<statm:hasSubstatement>
<statm:Block id='id121'>
<expr:Assignment id='id122'
kind='askAssignEql'>
{obj->state}
<expr:Id name='STATE_B' id='id127'/>
</expr:Assignment>
<statm:Break id='id128'/>
</statm:Switch>
<stat:Switch> … </stat:Switch>
…
<statm:CaseLabel id='id135'>
<statm:hasCaseValue>
<expr:Id name='EVENT1' id='id136'/>
</statm:hasCaseValue>
<statm:namesNextStatement ref='id122'/>
</statm:CaseLabel>
…
Slide 15, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Example
Source Code
static void obj_control(Obj
*obj, ObjEvent event)
{…
switch (obj->state) {
case State_A:
switch (event) {
case event1:
…
obj->state = State_B;
…
break;
case event2:
…
obj->state = State_C;
…
break;}
break;
case State_B:
switch (event) {
case event1:
…
obj->state = State_A;
…
break;
case event3:
…
obj->state = State_C;
…
break;}
break;
default;}}
State Machine Diagram
STATE_A
EVENT2
EVENT1
EVENT1
STATE_C
EVENT3
STATE_B
Slide 16, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Extensions / Improvements to CPP2XMI
• Done:
- Implemented a state machine extractor for FSC
• 2nd parser for CPPML
• Internal data structures storage system
• Database storage
• State Machine organizer
• Layout / position information
• XMI writer
• DOT writer (integration of Graphviz toolset)
- Improved command line options
- Implemented a GUI
- Updated old CPP2XMI to support Java Generics
Slide 17, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Examples extracted from FSC (V6)
Slide 18, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Examples extracted from FSC (V6)
Slide 19, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Examples extracted from FSC (V6)
Slide 20, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Extensions / Improvements to CPP2XMI
• To do:
- Find more false negatives and their corresponding patterns, implement
those.
- Add more information to state transitions (conditional state transitions)
- Map overlapping states and transitions
- Write documentation
- Apply tool to V5 / V6
Slide 21, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Extensions / Improvements to CPP2XMI
Further improvements to CPP2XMI
- Create class diagram from Objective C
• basic idea:
- Find patterns
- Make a classification system
- Based on this classification, determine the classes, methods
and attributes
- Make diagrams
- XMI conversion
- Improve performance issues (due to choice of parser)
Slide 22, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Problems encountered
•
Preprocessing issues
-
•
CPPML should have a tree-structure (1 on 1 with AST)
-
•
•
JDOM (Memory peak level: 1,8GB)
SAX (will not solve memory peaks)
Bug in XMI-part
-
•
However it’s a DAG, which makes pattern recognition is tricky
CPP2XMI doesn’t extract controlstatements (do, while, if,
switch break, continue, etc.) correctly (for C)
Performance issues with CPPML parser
-
•
Columbus Parser doesn’t understand anonymous structs/enums
Duplicate id’s, which raises errors when importing XMI into case-tools
(Enterprise Architect)
Position information not part of XMI
-
Enterprise Architect doesn’t do anything with position information
Slide 23, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Questions?
Slide 24, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland