2011-12-08 13:07:15 +00:00
|
|
|
*****
|
|
|
|
|
Debug
|
|
|
|
|
*****
|
|
|
|
|
|
2017-05-22 15:18:52 -04:00
|
|
|
Open the preferences dialog (menu `Edit->Preferences...`) and click on the
|
2011-12-08 13:07:15 +00:00
|
|
|
`Debugger` item on the left; set the button `Break on exceptions` to *Enabled*:
|
|
|
|
|
this will enable by default a special breakpoint every time an exception is
|
2016-05-11 14:31:24 +03:00
|
|
|
raised. Click on `Close` to close dialog.
|
2011-12-08 13:07:15 +00:00
|
|
|
|
2019-09-10 11:51:52 +02:00
|
|
|
Now click on the `Build & Debug sdc.adb` toolbar button: GNAT Studio
|
|
|
|
|
automatically switches to the *Debug* perspective as shown in the menu
|
|
|
|
|
`Window->Perspectives`, and new windows have appeared: the variables window,
|
|
|
|
|
the breakpoints view and the debugger console at the bottom, and the call
|
|
|
|
|
stack window on the right.
|
2011-12-08 13:07:15 +00:00
|
|
|
|
|
|
|
|
You can also look at the various debug menu item and tool bar buttons which are
|
|
|
|
|
now activated.
|
|
|
|
|
|
|
|
|
|
On the call stack window (you can use the menu `Debug->Data->Call Stack` to
|
2016-07-05 08:01:33 +03:00
|
|
|
open it if you do not have it displayed), select the local configuration menu:
|
|
|
|
|
various pieces of information can be displayed or removed in the call stack.
|
|
|
|
|
From this local configuration menu, add the `Frame Number` info by clicking on
|
|
|
|
|
it.
|
2011-12-08 13:07:15 +00:00
|
|
|
|
2019-03-12 17:26:45 +01:00
|
|
|
Now click on the `Debug continue` button and type `input.txt` in the text input
|
2016-06-06 17:28:38 +03:00
|
|
|
field. Check that 'Stop at beginning of main subprogram' and 'Use exec dir
|
|
|
|
|
instead of current dir' are not selected. Click on `OK`: the debugger should
|
|
|
|
|
stop on an exception (`Constraint_Error` in the file :file:`stack.adb`, at line
|
|
|
|
|
49).
|
2011-12-08 13:07:15 +00:00
|
|
|
|
2012-10-05 15:06:58 +00:00
|
|
|
Go up in the call stack by clicking on the `tokens.process` frame (frame number
|
|
|
|
|
will vary, depending on your GNAT version and platform).
|
2011-12-08 13:07:15 +00:00
|
|
|
|
|
|
|
|
If you move the mouse over the parameter `T` at line 64, a tool tip is
|
|
|
|
|
displayed showing the value of `T`. You have probably noticed that tool tips,
|
|
|
|
|
like menus, are contextual: depending on the current session and on the entity
|
|
|
|
|
selected, different information is displayed.
|
|
|
|
|
|
2020-10-02 15:37:13 +02:00
|
|
|
Select the contextual menu `Debug->Display T`: this will open the
|
|
|
|
|
`Debugger Variables` view, displaying graphically the contents of the different
|
2011-12-08 13:07:15 +00:00
|
|
|
fields of `T`, each clearly separated.
|
|
|
|
|
|
2020-02-21 14:04:28 +00:00
|
|
|
Special colors are used in the data display depending on your theme: one
|
|
|
|
|
for pointers that can be dereferenced by a double-click (double click
|
|
|
|
|
on `T.val`); another one for fields that have been modified since last step.
|
2011-12-08 13:07:15 +00:00
|
|
|
|
|
|
|
|
From the T box, right-click to display the contextual menu and select `View
|
|
|
|
|
memory at address of T`: a memory view is opened on top of the source editors.
|
|
|
|
|
Use the `up` and `down` arrows on the right to visit memory.
|
|
|
|
|
|
|
|
|
|
Click in the memory dump, and modify it by typing numbers. Notice the red color
|
|
|
|
|
for modified values; click on `Undo Changes` to cancel the modifications; then
|
2013-10-23 19:44:22 +00:00
|
|
|
close the memory window by e.g. clicking on the `x` icon in the tab or pressing
|
2011-12-08 13:07:15 +00:00
|
|
|
:kbd:`Ctrl-W`.
|
|
|
|
|
|
2012-10-05 15:06:58 +00:00
|
|
|
In the call stack, go back to the `stack.push` frame. Move the mouse
|
2011-12-08 13:07:15 +00:00
|
|
|
over `Last` and let the debugger display its value: 0. From the contextual
|
|
|
|
|
menu, select `Goto declaration of Last`: this will jump to the line 16 of
|
|
|
|
|
:file:`stack.adb`, where you can see that `Last` is a `Natural`. Now click on
|
|
|
|
|
the `Goto Previous Location` button in the tool bar: we're now back at line 49
|
|
|
|
|
where we can see that for a `Push` procedure, `Last` should be incremented, and
|
|
|
|
|
not decremented.
|
|
|
|
|
|
|
|
|
|
Fix the line to `Last := Last + 1;`
|
|
|
|
|
|
2019-03-12 17:26:45 +01:00
|
|
|
Save the file (:kbd:`Ctrl-S`); End the debug session: `Debug terminate` toolbar
|
|
|
|
|
button; Rebuild (press :kbd:`F4` key); Rerun (menu `Build->Run->sdc`, click on
|
2011-12-08 13:07:15 +00:00
|
|
|
`Execute`): the program now completes as expected. Close the execution window.
|