PowerAda Edit-Compile-Debug Demo

From OC Systems Wiki!
< PowerAda:APPENDIX D. Demos and Tutorials
Revision as of 00:34, 25 April 2019 by imported>WikiVisor (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This demo will walk you through the steps involved in the Edit-Compile-Debug process using powerada on an implementation of the Dining Philosopher's problem.

This demo will take about 15 minutes to complete.

You should have already created the temporary demo directory and working project, or be in your own project relative to the $POWERADA/demos baseline project. If you have not, please refer to "Required Setup" in the "Introduction" section.

Starting Powerada

If you're not already running the powerada navigator, start it in the temporary demo directory by typing the following:

powerada

In a few seconds, you should see the powerada Navigator window. If the window does not appear, see "Basic Troubleshooting". The powerada Navigator should display the contents of the project root directory; if it does not, navigate there by typing single "=" (equal sign) in the Location/Goto text field near the top of the window. For more on the navigator, see "Navigating" in Chapter 4.

Building the Program

You will be working with the Dining Philosopher's program, located in the diners directory. Navigate to that directory by double-clicking on the diners directory entry in the list (ensure you go into diners and not multi_diners). The powerada Navigator now displays the contents of the diners directory:

edit compile 1.gif

Again, there are no files in your local directory, but the files in the baseline project are visible ("shadowed") in the display.

You can now load the source files and build the program. Select all the Ada source files by click-dragging over all the source files or by control-clicking each source file. Now choose Load from the Build menu to have the Build Manager load the source files into the sublibrary in the working project. The Build Manager will display the Load Window ( See "Powerada Build Windows" in Chapter 4):

edit compile 2.gif

Click the Load button to load the files. When the load job completes, click the Dismiss button on the build window to close it.

Now select the main subprogram source file, diners.ada, in the directory display by left-clicking on it. Choose Bind Main from the Build menu and the Build Manager will display a window to compile and bind the program:

edit compile 3.gif

Click the Bind button to start the job. The Build Manager will compile all the pending units and bind the program. This time, don't dismiss the bind window; you'll use it again to rebind the program after you make source changes. Click the Refresh button in the powerada Navigator window to update the display to contain the newly created diners executable (if you have 'auto-refresh' enabled in your preferences, PowerAda will have automatically updated the display following the bind). Notice that it is displayed in a bold font which indicates that this is a local file in the working project.

Browsing

You can examine the source code of the compiled units of the diners program to become more familiar with it. In the powerada Navigator window right-click with the mouse to display the pop-up menu. Choose Visit Sublibrary and the compiled units will be displayed in the powerada Navigator:

edit compile 4.gif

Find the body of the unit Biological_Simulation in the list of units and select it. Choose Visit Selected Item from the pop-up (MB3) menu and the compiled source will be displayed like this:

edit compile 5.gif

Look at line 9 of the package body Biological_Simulation. We see that Track is an object of type Digestive_System. To understand this subprogram better, it would help if we knew more about the type Digestive_System. Powerada lets us do this quickly and easily. Using the middle mouse button, select the declaration of Track (e.g. click the mouse somewhere in the word Track with the middle mouse button - PowerAda highlights the complete declaration).Now choose Definition Of from the Source menu. Powerada will display the declaration of the type Digestive_System, which in this case is located in the specification of Biological_Simulation. The declaration itself is highlighted so it is easy to find:

edit compile 6.gif

Definition Of is by far the most useful of the browser functions. In general, it will take you to an element's declaration -- but not always. Definition Of is intended to be a less formal (but more generally helpful) concept than "Declaration Of".

Note that Visit is the same as Definition Of in the source browser, so the Visit button, Visit Selected Item element in the popup menu, and Control-V accelerator will all perform this operation.

Now return to the previous view by clicking on the Back button. The Track definition should still be highlighted so just choose Local Uses from the Source menu. This will display where in the current view Track is referenced.

edit compile 7.gif

Note that the window has split into two views. The top view is a "brief" listing of all the lines where Track is referenced; in a large file, you can click the mouse in this window to move the lower view between various uses. When you're done you can press close in the top window main to return the browser to a single main window.

Running the Program

Now you can run the diners demonstration program. Return to the directory containing the diners program by choosing Visit Directory from the pop-up menu. Select the diners program by left-clicking on it. Choose Run Program from the Directory menu and powerada will display the Run Program dialog:

Since diners has no command line arguments, just click on Run or hit return and the dining philosophers will appear in a new window:

edit compile 8.gif

The program will run to completion and you can press Enter to close the window.

Changing the Program

Now you will alter the program slightly, by reducing the number of philosophers, rebuilding diners, and then running the new version with the debugger. This will take you through the edit-compile-debug cycle. Begin by choosing Visit Sublibrary from the pop-up menu. This will display the list of all the compile units in the sublibrary. Select the specification of unit Room and type Control-E or choose Edit from the pop-up menu. Because the source file of Room, rooms.ada, exists only in the baseline, powerada will prompt you with a dialog to select how you want to edit the file:

edit compile 9.gif

On most projects you would usually extract or checkout the source from the CM system, but for demonstration purposes you can just choose Copy from Baseline and Edit to get a local, writable copy of the file. When you click OK, PowerAda will start XEmacs (or your chosen editor) with the local copy of the file rooms.ada:

edit compile 10.gif

Editor Problems?

At this point some users encounter problems with the editor. As shipped, PowerAda designates XEmacs as the default editor. It has a fairly straightforward point-and-click, menu-based interface, but may take some time to come up initially. You may see messages like:

gnuclient: Connection refused
gnuclient: unable to connect to local
Starting XEmacs...

in the window where you started powerada. This is normal, and is in fact a good sign. PowerAda tried first to connect to an already-running XEmacs session and when it found none, it started a new one. If no XEmacs window comes up in, say, 30 seconds, there may be some problem in communication between machines if PowerAda is installed on a different machine from the one you're running the demo on. Contact support@ocsystems.com and we can help get things configured.

Whether or not XEmacs comes up, you may simply prefer to run a different editor, at least until you get a chance to use it a while, and try out the "Getting Started With XEmacs" demo. To change your PowerAda editor preference, choose Preferences under the Project menu, and change the Editor preference as described under "Editor" in Chapter 4. After you've done this, retry the Edit action described as part of the demo above.

Assuming you've gotten rooms.ada into an editor, alter the source by changing (on line 12) the initial value of table_size from 5 to 4. Then save the file and return to the Build Manager bind window. Click the Bind button in the lower left and powerada will load and compile the changed source file and then rebind the diners executable. (You will notice in the Build Manager output that there will be exceptions raised at runtime, but pretend not to notice this at the moment.) Run the program again (by visiting the directory, selecting the program, and choosing Run from the Directory menu), and notice that it appears to hang this time.

Go ahead and close this window. To find out why the program hung, you will debug the program.

Debugging the Program

The diners executable should still be selected so choose Debug Program from the Directory menu. Powerada will display the Debug Program dialog. The default command-line arguments are fine, so click Debug and the debugger will start. Within the Load Target Program dialog, click the Load button, since diners has no command line arguments. The debugger displays the source of the main procedure diners, and indicates that it's ready to run the program.

edit compile 11.gif

For more on the debugger, see Chapter 6, "The PowerAda Debugger: adbg".

We'll guess that an unhandled exception is causing our problem. Select 'Trap All Exceptions' from the Breakpoints menu.

Now run the program under the debugger's control by selecting the Continue button at the top of the adbg window. Notice that the diners program failed when a CONSTRAINT_ERROR was raised on line 103 of roomb.ada, the body of package Room (good guess!). The debugger highlights, in its source window pane, the source line where the program stopped, and the debugger's output window pane shows the output generated when the CONSTRAINT_ERROR exception was raised.

Notice that on the highlighted line of the debugger's source window pane, the unwary programmer had hard-coded the opening of philosopher number 5. An exception was raised because that index value of 5 now exceeds the bounds of the Phil_Windows array, whose upper limit is our new Table_Size of 4.

You can quit the debugger (Quit on the File menu), restore Table_Size to 5, rebuild diners, and rerun it. To do this, edit the source file (which should still be in the XEmacs window) and save it. Revisit the Build Manager bind window and click Bind again. You can now run or debug the corrected program to verify that it works.