slide 1, presentation: reverse engineering state diagrams from c/c++ code, 29-10-2008 | dennie van...
TRANSCRIPT
Slide 1, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Masters Project
Reverse Engineering state machine diagrams from C/C++ code
Vanderlande Industries B.V. (Veghel)
Dennie van Zeeland
Slide 2, 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 3, 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 4, 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 5, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (3)
- Flow System Controller
Slide 6, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (4)
- Flow System Controller
Slide 7, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Introduction (5)
- Flow System Controller
Slide 8, 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 9, 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 10, 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 11, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
CPP2XMI
C++ Source Code
Pre-processor
Pre-processed C++ Source
Code
XMI
Filtered Columbus
CPPML
CPPML
Filtered Columbus XMI
Columbus Parser & Exporter
Diagram Extractor
Library Filter
XMI (with layout)
Abstract Syntax Tree in XML-
format
Abstract Syntax Tree in XML-
format
Class Diagram in XML (XMI)-formatClass Diagram in XML (XMI)-format
Class, Sequence, Activity Diagram in XML (XMI)-format
Class, Sequence, Activity Diagram in XML (XMI)-format
Slide 12, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
CPP2XMI
Parser for CPPML
Store (internal
datastructure)
CollaborationOrganizer
ActivityOrganizer
Store (internal
datastructure)
Add Layout using
Seuence-Layout
Form XMI-tags / Write
to File
Store (internal
datastructure) + Layout
Add Layout using Dot-
Layout
Add Layout using Class-
Layout
Abstract Syntax Tree
(CPPML filtered)
UML model in XMI 1.1
(with layout)
Slide 13, 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 14, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
CPP2XMI
Parser for CPPML
Store (internal
datastructure)
CollaborationOrganizer
ActivityOrganizer
Store (internal
datastructure)
State Machine
Organizer
Add Layout using
Seuence-Layout
Form XMI-tags / Write
to File
Store (internal
datastructure) + Layout
Add Layout using
StateDot-Layout
Add Layout using Dot-
Layout
Add Layout using Class-
Layout
Abstract Syntax Tree
(CPPML filtered)
UML model in XMI 1.1
(with layout)
Second Parser for CPPML for Objective C
Could be improvedCould be improved
XX
Slide 15, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
ExampleSource Code CPPMLstatic 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 16, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
ExampleSource Code State Machine Diagramstatic 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_A
STATE_B
STATE_CEVENT1 EVENT1
EVENT3
EVENT2
Slide 17, 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 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
Examples extracted from FSC (V6)
Slide 21, 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 22, 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 23, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Problems encountered
• Preprocessing issues - Columbus Parser doesn’t understand anonymous structs/enums
• CPPML should have a tree-structure (1 on 1 with AST)- 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- JDOM (Memory peak level: 1,8GB)- SAX (will not solve memory peaks)
• Bug in XMI-part - 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 24, Presentation: Reverse Engineering state diagrams from C/C++ code, 29-10-2008 | Dennie van Zeeland
Questions?