Chapter 10
Modelica Algorithmic Subset Debugger
This chapter presents a comprehensive Modelica debugger for an extended algorithmic subset of the Modelica language called MetaModelica. This replaces debugging of algorithmic code using primitive means such as print statements or asserts which is complex, time-consuming and error- prone.
The debugger is portable since it is based on transparent source code instrumentation techniques that are independent of the implementation platform.
The usual debugging functionality found in debuggers for procedural or traditional object-oriented languages is supported, such as setting and removing breakpoints, stepping, inspecting variables, etc. The debugger is integrated with Eclipse.
10.1The Eclipse-based Debugging Environment
The debugging framework is based on the Eclipse environment and is implememented as a set of plugins which are available from Modelica Development Tooling (MDT) environment. Some of the debugger functionality is presented below. In the right part a variable value is explored. In the top-left part the stack trace is presented. In the middle-left part the execution point is presented.
The debugger provides the following general functionalities:
-
Adding/Removing breakpoints.
-
Step Over – moves to the next line, skipping the function calls.
-
Step In – takes the user into the function call.
-
Step Return – complete the execution of the function and takes the user back to the point from where the function is called.
-
Suspend – interrupts the running program.
Figure 10 72. Debugging functionality.
To be able to run in debug mode, one has to go through the following steps:
All these steps are presented below using images.
10.2.1Create mos file
In order to debug Modelica code we need to load the Modelica files into the OpenModelica Compiler. For this we can write a small script file like this,
setCommandLineOptions({"+d=rml,noevalfunc","+g=MetaModelica"});
setEnvironmentVar("MODELICAUSERCFLAGS","-g");
loadFile("HelloWorld.mo");
getErrorString();
HelloWorld(120.0);
getErrorString();
So lets say that we want to debug HelloWorld.mo . For that we must load it into the compiler using the script file. Put all the Modelica files there in the script file to be loaded. We should also initiate the debugger by calling the starting function, in the above code HelloWorld(120.0);
10.2.2Setting the debug configuration
While the Modelica perspective is activated the user should click on the bug icon on the toolbar and select Debug in order to access the dialog for building debug configurations.
Figure 10 73. Accessing the debug configuration dialog.
To create the debug configuration, right click on the classification Modelica Development Tooling (MDT) GDB and select New as in figure below. Then give a name to the configuration, select the debugging executable to be executed and give it command line parameters. There are several tabs in which the user can select additional debug configuration settings like the environment in which the executable should be run.
Note that we require Gnu Debugger (GDB) for debugging session. We must specify the GDB location, also we must pass our script file as an argument to OMC.
Figure 10 74. Creating the Debug Configuration.
10.2.3Setting/Deleting Breakpoints
The Eclipse interface allows to add/remove breakpoints. At the moment only line number based breakpoints are supported. Other alternative to set the breakpoints is; function breakpoints.
Figure 10 75. Setting/deleting breakpoints.
Figure 10 76. Starting the debugging session.
Figure 10 77. Eclipse will ask if the user wants to switch to the debugging perspective.
10.3Debugging OpenModelica -
Compile and create OpenModelica executable as usual.
-
Go to /trunk/testsuite/bootstrapping and run command ../../build/bin/omc.exe MainTest.mos
-
Now run make –f LinkMain.makefile.mingw (choose the right make file depending on your platform), this will create main.exe in the same directory.
-
Now in the debug configuration as explained in Section 10.2.2 choose main.exe as the program.
10.4The Debugging Perspective
The debug view primarily consists of two main views:
-
Stack Frames View
-
Variables View
The stack frame view, shown in the figure below, shows a list of frames that indicates how the flow had moved from one function to another or from one file to another. This allows backtracing of the code. It is very much possible to select the previous frame in the stack and inspect the values of the variables in that frame. However, it is not possible to select any of the previous frame and start debugging from there. Each frame is shown as .
The Variables view shows the list of variables at a certain point in the program, containing four colums:
-
Name – the variable name.
-
Declared Type – the Modelica type of the variable.
-
Value – the variable value.
-
Actual Type – the mapped C type.
By preserving the stack frames and variables it is possible to keep track of the variables values. If the value of any variable is changed while stepping then that variable will be highlighted yellow (the standard Eclipse way of showing the change).
Figure 10 78. The debugging perspective.
Figure 10 79. Switching between perspectives.
Share with your friends: |