[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GPS is also a graphical front-end for text-based debuggers such as GDB. A knowledge of the basics of the underlying debugger used by GPS will help understanding how GPS works and what kind of functionalities it provides.
Please refer to the debugger-specific documentation - e.g. the GDB documentation (gdb.html) - for more details.
The integrated debugger provided by GPS is using an improved version of the GVD engine, so the functionalities between GVD and GPS are very similar. If you are familiar with GVD, you may be interested in reading 11.9 Upgrading from GVD to GPS which explains the differences between the two environments.
Debugging is tightly integrated with the other components of GPS. For example, it is possible to edit files and navigate through your sources while debugging.
To start a debug session, go to the menu Debug->Initialize
, and choose
either the name of your executable, if you have specified the name of
your main program(s) in the project properties, or start an empty debug
session using the <no main file>
item. It is then possible to load
any file to debug, by using the menu Debug->Debug->Load File...
Note that you can create multiple debuggers by using the Initialize
menu several times: this will create a new debugger each time.
All the debugger-related actions (e.g. stepping, running) are performed on
the current debugger, which is represented by the current debugger console.
To switch between debuggers, simply select its corresponding console.
After the debugger has been initialized, you have access to two new windows:
the data window (in the top of the working area), and the debugger console
(in a new page, after the Messages and Shell windows).
All the menus under Debugger
are now also accessible, and you also have access to additional contextual
menus, in particular in the source editor where it is possible to easily
display variables, set breakpoints, and get automatic display
(via tool tips) of object values.
When you want to quit the debugger without quitting GPS, go to the menu
Debug->Terminate Current
, that will terminate your current debug
session, or the menu Debug->Terminate
that will terminate all your
debug sessions at once.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Debug
entry in the menu bar provides operations that act at a
global level. Key shortcuts are available for the most common operations, and
are displayed in the menus themselves.
Here is a detailed list of the menu items that can be found in the menu bar:
gdb
) used
to handle the low level debugging.
Terminate Current
if there
is only one debugger open.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Opens a file selection dialog that allows you to choose a program to debug. The program to debug is either an executable for native debugging, or a partially linked module for cross environments (e.g VxWorks).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When supported by the underlying debugger, clicking on a thread will change the context (variables, call stack, source file) displayed, allowing you to inspect the stack of the selected thread.
As for the thread window, the process being debugged needs to be stopped before using this window.
p/x var
) or a procedure call in the program being
debugged (e.g call my_proc
).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The call stack window gives a list of frames corresponding to the current execution stack for the current thread/task.
The bottom frame corresponds to the outermost frame where the thread is currently stopped. This frame corresponds to the first function executed by the current thread (e.g main if the main thread is in C). You can click on any frame to switch to the caller's context, this will update the display in the source window. See also the up and down buttons in the tool bar to go up and down one frame in the call stack.
The contextual menu (right mouse button) allows you to choose which information you want to display in the call stack window (via check buttons):
By default, only the subprogram name is displayed.
You can hide the call stack window by closing it, as for other windows, and
show it again using the menu Data->Call Stack
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The data window contains all the graphic boxes that can be accessed using the Data->Display menu items, or the data window Display Expression... contextual menu, or the source window Display contextual menu items, or finally the graph command in the debugger console.
For each of these commands, a box is displayed in the data window with the following information:
C
, Ada
, C++
) and will
organize them accordingly.
For example, each field of a record/struct/class, or each item of an
array will be displayed separately. For each subcomponent, a thin box
is displayed to distinguish it from the other components.
A contextual menu, that takes into account the current component selected by the mouse, gives access to the following capabilities:
A contextual menu can be accessed in the canvas itself (point the mouse to an empty area in the canvas, and click on the right mouse button) with the following entries:
p/x var
) or a procedure call in the program being
debugged (e.g call my_proc
).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Automatic scrolling is also provided if you move the mouse while dragging an item near the borders of the data window. As long as the mouse remains close to the border and the button is pressed on the item, the data window is scrolled and the item is moved. This provides an easy way to move an item a long distance from its initial position.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can easily dereference these (that is to say see the value pointed to) by double-clicking on the blue text itself.
As another example, if you choose to display the value of local variables in the data window (Display->Display Local Variables), then only the variables whose value has changed are highlighted, the others are left in black.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Double-clicking on this icon will expand the hidden part, and clicking on any sub-rectangle in the display of the variable will hide that part and replace it with that icon.
See also the description of the contextual menu to automatically show or hide all the contents of an item. Note also that one alternative to hiding subcomponents is to clone them in a separate item (see the contextual menu again).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The breakpoint editor can be accessed from the menu Data->Edit Breakpoints. It gives access to the different kind of breakpoints: on source location, subprogram, address, variables, exceptions.
The top area provides an interface to easily create the different kinds of breakpoints, while the bottom area lists the existing breakpoints and their characteristics.
It is possible to access to advanced breakpoint characteristics for a given breakpoint, by first selecting a breakpoint in the list, and then by clicking on the Advanced button, which will display a new dialog window where you can specify commands to run automatically after a breakpoint is hit, or specify how many times a selected breakpoint will be ignored. If running VxWorks AE, you can also change the Scope and Action of breakpoints.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In VxWorks AE breakpoints have two extra properties:
These two properties can be set/changed through the advanced breakpoints characteristics by clicking on the Advanced button. There are two ways of setting these properties:
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The memory window allows you to display the contents of memory by specifying either an address, or a variable name.
To display memory contents, enter the address using the C hexadecimal notation: 0xabcd, or the name of a variable, e.g foo, in the Location text entry. In the latter case, its address is computed automatically. Then either press Enter or click on the View button. This will display the memory with the corresponding addresses in the bottom text area.
You can also specify the unit size (Byte, Halfword or Word), the format (Hexadecimal, Decimal, Octal or ASCII), and you can display the corresponding ASCII value at the same time.
The up and down arrows as well as the Page up and Page down keys in the memory text area allows you to walk through the memory in order of ascending/descending addresses respectively.
Finally, you can modify a memory area by simply clicking on the location you want to modify, and by entering the new values. Modified values will appear in a different color (red by default) and will only be taken into account (i.e written to the target) when you click on the Submit changes button. Clicking on the Undo changes or going up/down in the memory will undo your editing.
Clicking on Close will close the memory window, canceling your last pending changes, if any.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When debugging, the left area of each source editor provides the following information:
The second area in the source window is a text window on the right that displays the source files, with syntax highlighting. If you leave the cursor over a variable, a tooltip will appear showing the value of this variable. Automatic tooltips can be disabled in the preferences menu. See preferences dialog.
When the debugger is active, the contextual menu of the source window
contains a sub menu called Debug
providing the following entries.
Note that these entries are dynamic: they will apply to the entity found under the cursor when the menu is displayed (depending on the current language). In addition, if a selection has been made in the source window the text of the selection will be used instead. This allows you to display more complex expressions easily (for example by adding some comments to your code with the complex expressions you want to be able to display in the debugger).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
It is sometimes convenient to look at the assembly code for the subprogram or source line you are currently debugging.
You can open the assembly window by using the menu Debug->Data->Assembly
.
The current assembly instruction is highlighted with a green arrow on its left. The instructions corresponding to the current source line are highlighted in red by default. This allows you to easily see where the program counter will point to, once you have pressed the "Next" button on the tool bar.
Moving to the next assembly instruction is done through the "Nexti" (next instruction) button in the tool bar. If you choose "Stepi" instead (step instruction), this will also jump to the subprogram being called.
For efficiency reasons, only a small part of the assembly code around the current instruction is displayed. You can specify in the preferences dialog how many instructions are displayed by default. Also, you can easily display the instructions immediately preceding or following the currently displayed instructions by pressing one of the Page up or Page down keys, or by using the contextual menu in the assembly window.
A convenient complement when debugging at the assembly level is the
ability of displaying the contents of machine registers.
When the debugger supports it (as gdb does), you can select the
Data->Display Registers
menu to get an item in the canvas that will
show the current contents of each machine register, and that will be updated
every time one of them changes.
You might also choose to look at a single register.
With gdb, select the Data->Display Any Expression
, entering
something like
output /x $eax |
in the field, and selecting the toggle button "Expression is a subprogram call". This will create a new canvas item that will be refreshed every time the value of the register (in this case eax) changes.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is the text window located at the bottom of the main window. In this console, you have direct access to the underlying debugger, and can send commands (you need to refer to the underlying debugger's documentation, but usually typing help will give you an overview of the commands available).
If the underlying debugger allows it, pressing Tab in this window will provide completion for the command that is being typed (or for its arguments).
There are also additional commands defined to provide a simple text interface to some graphical features.
Here is the complete list of such commands. The arguments between square brackets are optional and can be omitted.
graph (print|display) expression [dependent on display_num] [link_name name]
The command graph print
will create a frozen item, that is not
automatically refreshed when the debugger stops, whereas graph display
displays an automatically refreshed item.
The new item is associated with a number, that is visible in its title bar. These numbers can be used to create links between the items, using the second argument to the command, dependent on. The link itself (i.e. the line) can be given a name that is automatically displayed, using the third argument.
graph (print|display) `command`
For instance, if you want to display the value of a variable in hexadecimal rather than the default decimal with gdb, you should use a command like:
graph display `print /x my_variable` |
This will evaluate the command between back-quotes every time the debugger stops, and display this in the canvas. The lines that have changed will be automatically highlighted (in red by default).
This command is the one used by default to display the value of registers for instance.
graph (enable|disable) display display_num [display_num ...]
Using the graph enable
command will force the item to be automatically
refreshed every time the debugger stops, whereas the graph disable
command will freeze the item.
graph undisplay display_num
view (source|asm|source_asm)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section outlines the differences between GVD and GPS, and also lists some of the advantages of GPS compared to GVD.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
--debug
--pargs
and executable-file
arguments in GVD.
--debugger
--dargs
option.
--target
For example, the equivalent of the following command line:
$ gvd --debugger=gdb-5 executable --pargs 1 2 3 |
would be
$ gps --debug='executable 1 2 3' --debugger=gdb-5 |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
File->xxx
Debug->Debug->xxx
Program->xxx
Debug->xxx
Data->xxx
Debug->Data->xxx
The menu File->New Debugger...
is replaced by the combination of
the menu Debug->Initialize
and the project properties, available
under Project->Edit Project Properties
where you can similarly
specify your Debugger Host (called Tools Host), your
Program Host, the Protocol used by the underlying debugger
to communicate with the target, and the name of the debugger.
To conveniently switch between multiple debugger configurations, we
recommend to use a scenario variable and set different properties based
on the value of this variable. See
7.3 Scenarios and Configuration Variables and
14. Working in a Cross Environment for more details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Run
Debug->Run...
(F2)
Start
Step
Stepi
Debug->Step Instruction
(Shift-F5)
Next
Nexti
Debug->Next Instruction
(Shift-F6)
Finish
Cont
Up
Down
Interrupt
Debug->Interrupt
(Control-Blackslash)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Debug
sub-menu.
The only difference is the contextual menu Show
used to display
the assembly dump of the current code. It is replaced by the menu
Debug->Data->Assembly
, see 11.7 The Assembly Window for more
details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Project View
and the File View
in GPS.
When using the --debug
command line switch and no explicit project
file, GPS will automatically create a project file in a way very
similar to what GVD does to display its file explorer, and available under
the Project View
.
In addition, the File View
gives access to any file in your file
system, even if it is not available as part of the debug information.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When not using project files, you get access to the following advantages in GPS:
When using project files, you will get, in addition to the advantages listed above:
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |