[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Although programming languages generally have common aspects, they are
rarely expressed in the same manner. For instance, in ANSI C,
dereferencing a pointer p
is accomplished by *p
, but in
Modula-2, it is accomplished by p^
. Values can also be
represented (and displayed) differently. Hex numbers in C appear as
`0x1ae', while in Modula-2 they appear as `1AEH'.
Language-specific information is built into GDB for some languages, allowing you to express operations like the above in your program's native language, and allowing GDB to output values in a manner consistent with the syntax of your program's native language. The language you use to build expressions is called the working language.
15.1 Switching Between Source Languages Switching between source languages 15.2 Displaying the Language Displaying the language 15.3 Type and Range Checking Type and range checks 15.4 Supported Languages Supported languages 15.5 Unsupported Languages Unsupported languages
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
There are two ways to control the working language--either have GDB
set it automatically, or select it manually yourself. You can use the
set language
command for either purpose. On startup, GDB
defaults to setting the language automatically. The working language is
used to determine how expressions you type are interpreted, how values
are printed, etc.
In addition to the working language, every source file that
GDB knows about has its own working language. For some object
file formats, the compiler might indicate which language a particular
source file is in. However, most of the time GDB infers the
language from the name of the file. The language of a source file
controls whether C++ names are demangled--this way backtrace
can
show each frame appropriately for its own language. There is no way to
set the language of a source file from within GDB, but you can
set the language associated with a filename extension. See section Displaying the Language.
This is most commonly a problem when you use a program, such
as cfront
or f2c
, that generates C but is written in
another language. In that case, make the
program use #line
directives in its C output; that way
GDB will know the correct language of the source code of the original
program, and will display that source code, not the generated C code.
15.1.1 List of Filename Extensions and Languages Filename extensions and languages. 15.1.2 Setting the Working Language Setting the working language manually 15.1.3 Having GDB Infer the Source Language Having GDB infer the source language
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If a source file name ends in one of the following extensions, then GDB infers that its language is the one indicated.
In addition, you may set the language associated with a filename extension. See section Displaying the Language.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you allow GDB to set the language automatically, expressions are interpreted the same way in your debugging session and your program.
If you wish, you may set the language manually. To do this, issue the
command `set language lang', where lang is the name of
a language, such as
c
or modula-2
.
For a list of the supported languages, type `set language'.
Setting the language manually prevents GDB from updating the working language automatically. This can lead to confusion if you try to debug a program when the working language is not the same as the source language, when an expression is acceptable to both languages--but means different things. For instance, if the current source file were written in C, and GDB was parsing Modula-2, a command such as:
print a = b + c |
might not have the effect you intended. In C, this means to add
b
and c
and place the result in a
. The result
printed would be the value of a
. In Modula-2, this means to compare
a
to the result of b+c
, yielding a BOOLEAN
value.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To have GDB set the working language automatically, use `set language local' or `set language auto'. GDB then infers the working language. That is, when your program stops in a frame (usually by encountering a breakpoint), GDB sets the working language to the language recorded for the function in that frame. If the language for a frame is unknown (that is, if the function or block corresponding to the frame was defined in a source file that does not have a recognized extension), the current working language is not changed, and GDB issues a warning.
This may not seem necessary for most programs, which are written entirely in one source language. However, program modules and libraries written in one source language can be used by a main program written in a different source language. Using `set language auto' in this case frees you from having to set the working language manually.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following commands help you find out which language is the working language, and also what language source files were written in.
show language
print
to
build and compute expressions that may involve variables in your program.
info frame
info source
In unusual circumstances, you may have source files with extensions not in the standard list. You can then set the extension associated with a language explicitly:
set extension-language ext language
info extensions
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Warning: In this release, the GDB commands for type and range checking are included, but they do not yet have any effect. This section documents the intended facilities.
Some languages are designed to guard you against making seemingly common errors through a series of compile- and run-time checks. These include checking the type of arguments to functions and operators, and making sure mathematical overflows are caught at run time. Checks such as these help to ensure a program's correctness once it has been compiled by eliminating type mismatches, and providing active checks for range errors when your program is running.
GDB can check for conditions like the above if you wish.
Although GDB does not check the statements in your program,
it can check expressions entered directly into GDB for
evaluation via the print
command, for example. As with the
working language, GDB can also decide whether or not to check
automatically based on your program's source language.
See section Supported Languages, for the default
settings of supported languages.
15.3.1 An Overview of Type Checking An overview of type checking 15.3.2 An Overview of Range Checking An overview of range checking
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some languages, such as Modula-2, are strongly typed, meaning that the arguments to operators and functions have to be of the correct type, otherwise an error occurs. These checks prevent type mismatch errors from ever causing any run-time problems. For example,
1 + 2 => 3 but error--> 1 + 2.3 |
The second example fails because the CARDINAL
1 is not
type-compatible with the REAL
2.3.
For the expressions you use in GDB commands, you can tell the GDB type checker to skip checking; to treat any mismatches as errors and abandon the expression; or to only issue warnings when type mismatches occur, but evaluate the expression anyway. When you choose the last of these, GDB evaluates expressions like the second example above, but also issues a warning.
Even if you turn type checking off, there may be other reasons
related to type that prevent GDB from evaluating an expression.
For instance, GDB does not know how to add an int
and
a struct foo
. These particular type errors have nothing to do
with the language in use, and usually arise from expressions, such as
the one described above, which make little sense to evaluate anyway.
Each language defines to what degree it is strict about type. For instance, both Modula-2 and C require the arguments to arithmetical operators to be numbers. In C, enumerated types and pointers can be represented as numbers, so that they are valid arguments to mathematical operators. See section Supported Languages, for further details on specific languages.
GDB provides some additional commands for controlling the type checker:
set check type auto
set check type on
set check type off
set check type warn
show type
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In some languages (such as Modula-2), it is an error to exceed the bounds of a type; this is enforced with run-time checks. Such range checking is meant to ensure program correctness by making sure computations do not overflow, or indices on an array element access do not exceed the bounds of the array.
For expressions you use in GDB commands, you can tell GDB to treat range errors in one of three ways: ignore them, always treat them as errors and abandon the expression, or issue warnings but evaluate the expression anyway.
A range error can result from numerical overflow, from exceeding an array index bound, or when you type a constant that is not a member of any type. Some languages, however, do not treat overflows as an error. In many implementations of C, mathematical overflow causes the result to "wrap around" to lower values--for example, if m is the largest integer value, and s is the smallest, then
m + 1 => s |
This, too, is specific to individual languages, and in some cases specific to individual compilers or machines. See section Supported Languages, for further details on specific languages.
GDB provides some additional commands for controlling the range checker:
set check range auto
set check range on
set check range off
set check range warn
show range
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB supports C, C++, D, Objective-C, Fortran, Java, OpenCL C, Pascal,
assembly, Modula-2, and Ada.
Some GDB features may be used in expressions regardless of the
language you use: the GDB @
and ::
operators,
and the `{type}addr' construct (see section Expressions) can be used with the constructs of any supported
language.
The following sections detail to what degree each source language is supported by GDB. These sections are not meant to be language tutorials or references, but serve only as a reference guide to what the GDB expression parser accepts, and what input and output formats should look like for different languages. There are many good books written on each of these languages; please look to these for a language reference or tutorial.
15.4.1 C and C++ 15.4.2 D 15.4.3 Objective-C 15.4.4 OpenCL C 15.4.5 Fortran 15.4.6 Pascal 15.4.7 Modula-2 15.4.8 Ada
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Since C and C++ are so closely related, many features of GDB apply to both languages. Whenever this is the case, we discuss those languages together.
The C++ debugging facilities are jointly implemented by the C++
compiler and GDB. Therefore, to debug your C++ code
effectively, you must compile your C++ programs with a supported
C++ compiler, such as GNU g++
, or the HP ANSI C++
compiler (aCC
).
15.4.1.1 C and C++ Operators C and C++ operators 15.4.1.2 C and C++ Constants C and C++ constants 15.4.1.3 C++ Expressions C++ expressions 15.4.1.4 C and C++ Defaults Default settings for C and C++ 15.4.1.5 C and C++ Type and Range Checks C and C++ type and range checks 15.4.1.6 GDB and C 15.4.1.7 GDB Features for C++ GDB features for C++ 15.4.1.8 Decimal Floating Point format Numbers in Decimal Floating Point format
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Operators must be defined on values of specific types. For instance,
+
is defined on numbers, but not on structures. Operators are
often defined on groups of types.
For the purposes of C and C++, the following definitions hold:
int
with any of its storage-class
specifiers; char
; enum
; and, for C++, bool
.
float
, double
, and
long double
(if supported by the target platform).
(type *)
.
The following operators are supported. They are listed here in order of increasing precedence:
,
=
op=
a op= b
,
and translated to a = a op b
.
op=
and =
have the same precedence.
op is any one of the operators |
, ^
, &
,
<<
, >>
, +
, -
, *
, /
, %
.
?:
a ? b : c
can be thought
of as: if a then b else c. a should be of an
integral type.
||
&&
|
^
&
==, !=
<, >, <=, >=
<<, >>
@
+, -
*, /, %
++, --
*
++
.
&
++
.
For debugging C++, GDB implements a use of `&' beyond what is allowed in the C++ language itself: you can use `&(&ref)' to examine the address where a C++ reference variable (declared with `&ref') is stored.
-
++
.
!
++
.
~
++
.
., ->
struct
and union
data.
.*, ->*
[]
a[i]
is defined as
*(a+i)
. Same precedence as ->
.
()
->
.
::
struct
, union
,
and class
types.
::
::
,
above.
If an operator is redefined in the user code, GDB usually attempts to invoke the redefined version instead of using the operator's predefined meaning.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB allows you to express the constants of C and C++ in the following ways:
long
value.
float
(as opposed to the default double
) type; or with
a letter `l' or `L', which specifies a long double
constant.
'
), or a number--the ordinal value of the corresponding character
(usually its ASCII value). Within quotes, the single character may
be represented by a letter or by escape sequences, which are of
the form `\nnn', where nnn is the octal representation
of the character's ordinal value; or of the form `\x', where
`x' is a predefined special character--for example,
`\n' for newline.
Wide character constants can be written by prefixing a character constant with `L', as in C. For example, `L'x'' is the wide form of `x'. The target wide character set is used when computing the value of this constant (see section 10.19 Character Sets).
"
). Any valid character constant (as described
above) may appear. Double quotes within the string must be preceded by
a backslash, so for instance `"a\"b'c"' is a string of five
characters.
Wide string constants can be written by prefixing a string constant with `L', as in C. The target wide character set is used when computing the value of this constant (see section 10.19 Character Sets).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB expression handling can interpret most C++ expressions.
Warning: GDB can only debug C++ code if you use the proper compiler and the proper debug format. Currently, GDB works best when debugging C++ code that is compiled with the most recent version of GCC possible. The DWARF debugging format is preferred; GCC defaults to this on most popular platforms. Other compilers and/or debug formats are likely to work badly or not at all when using GDB to debug C++ code. See section 4.1 Compiling for Debugging.
count = aml->GetOriginal(x, y) |
this
following the same rules as C++. using
declarations in the current scope are also respected by GDB.
It does perform integral conversions and promotions, floating-point promotions, arithmetic conversions, pointer conversions, conversions of class objects to base classes, and standard conversions such as those of functions or arrays to pointers; it requires an exact match on the number of function arguments.
Overload resolution is always performed, unless you have specified
set overload-resolution off
. See section GDB Features for C++.
You must specify set overload-resolution off
in order to use an
explicit function signature to call an overloaded function, as in
p 'foo(char,int)'('x', 13) |
The GDB command-completion facility can simplify this; see Command Completion.
In the parameter list shown when GDB displays a frame, the values of reference variables are not displayed (unlike other variables); this avoids clutter, since references are often used for large structures. The address of a reference variable is always shown, unless you have specified `set print address off'.
::
---your
expressions can use it just as expressions in your program do. Since
one scope may be defined in another, you can use ::
repeatedly if
necessary, for example in an expression like
`scope1::scope2::name'. GDB also allows
resolving name scope by reference to source files, in both C and C++
debugging (see section Program Variables).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you allow GDB to set type and range checking automatically, they
both default to off
whenever the working language changes to
C or C++. This happens regardless of whether you or GDB
selects the working language.
If you allow GDB to set the language automatically, it recognizes source files whose names end with `.c', `.C', or `.cc', etc, and when GDB enters code compiled from one of these files, it sets the working language to C or C++. See section Having GDB Infer the Source Language, for further details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
By default, when GDB parses C or C++ expressions, type checking is not used. However, if you turn type checking on, GDB considers two variables type equivalent if:
typedef
.
Range checking, if turned on, is done on mathematical operations. Array indices are not checked, since they are often used to index a pointer that is not itself an array.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The set print union
and show print union
commands apply to
the union
type. When set to `on', any union
that is
inside a struct
or class
is also printed. Otherwise, it
appears as `{...}'.
The @
operator aids in the debugging of dynamic arrays, formed
with pointers and a memory allocation function. See section Expressions.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some GDB commands are particularly useful with C++, and some are designed specifically for use with C++. Here is a summary:
breakpoint menus
rbreak regex
catch throw
catch catch
ptype typename
set print demangle
show print demangle
set print asm-demangle
show print asm-demangle
set print object
show print object
set print vtbl
show print vtbl
vtbl
commands do not work on programs compiled with the HP
ANSI C++ compiler (aCC
).)
set overload-resolution on
set overload-resolution off
show overload-resolution
Overloaded symbol names
symbol(types)
rather than just symbol. You can
also use the GDB command-line word completion facilities to list the
available choices, or to finish the type list for you.
See section Command Completion, for details on how to do this.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB can examine, set and perform computations with numbers in
decimal floating point format, which in the C language correspond to the
_Decimal32
, _Decimal64
and _Decimal128
types as
specified by the extension to support decimal floating-point arithmetic.
There are two encodings in use, depending on the architecture: BID (Binary Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for PowerPC. GDB will use the appropriate encoding for the configured target.
Because of a limitation in `libdecnumber', the library used by GDB to manipulate decimal floating point numbers, it is not possible to convert (using a cast, for example) integers wider than 32-bit to decimal float.
In addition, in order to imitate GDB's behaviour with binary floating point computations, error checking in decimal float operations ignores underflow, overflow and divide by zero exceptions.
In the PowerPC architecture, GDB provides a set of pseudo-registers
to inspect _Decimal128
values stored in floating point registers.
See PowerPC for more details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB can be used to debug programs written in D and compiled with GDC, LDC or DMD compilers. Currently GDB supports only one D specific feature -- dynamic arrays.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section provides information about some commands and command options that are useful for debugging Objective-C code. See also info classes, and info selectors, for a few more commands specific to Objective-C support.
15.4.3.1 Method Names in Commands 15.4.3.2 The Print Command With Objective-C
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following commands have been extended to accept Objective-C method names as line specifications:
clear
break
info line
jump
list
A fully qualified Objective-C method name is specified as
-[Class methodName] |
where the minus sign is used to indicate an instance method and a
plus sign (not shown) is used to indicate a class method. The class
name Class and method name methodName are enclosed in
brackets, similar to the way messages are specified in Objective-C
source code. For example, to set a breakpoint at the create
instance method of class Fruit
in the program currently being
debugged, enter:
break -[Fruit create] |
To list ten program lines around the initialize
class method,
enter:
list +[NSText initialize] |
In the current version of GDB, the plus or minus sign is required. In future versions of GDB, the plus or minus sign will be optional, but you can use it to narrow the search. It is also possible to specify just a method name:
break create |
You must specify the complete method name, including any colons. If
your program's source files contain more than one create
method,
you'll be presented with a numbered list of classes that implement that
method. Indicate your choice by number, or type `0' to exit if
none apply.
As another example, to clear a breakpoint established at the
makeKeyAndOrderFront:
method of the NSWindow
class, enter:
clear -[NSWindow makeKeyAndOrderFront:] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The print command has also been extended to accept methods. For example:
print -[object hash] |
will tell GDB to send the hash
message to object
and print the result. Also, an additional command has been added,
print-object
or po
for short, which is meant to print
the description of an object. However, this command may only work
with certain Objective-C libraries that have a particular hook
function, _NSPrintForDebugger
, defined.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section provides information about GDBs OpenCL C support.
15.4.4.1 OpenCL C Datatypes 15.4.4.2 OpenCL C Expressions 15.4.4.3 OpenCL C Operators
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB supports the builtin scalar and vector datatypes specified
by OpenCL 1.1. In addition the half- and double-precision floating point
data types of the cl_khr_fp16
and cl_khr_fp64
OpenCL
extensions are also known to GDB.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB supports accesses to vector components including the access as lvalue where possible. Since OpenCL C is based on C99 most C expressions supported by GDB can be used as well.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB supports the operators specified by OpenCL 1.1 for scalar and vector data types.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB can be used to debug programs written in Fortran, but it currently supports only the features of Fortran 77 language.
Some Fortran compilers (GNU Fortran 77 and Fortran 95 compilers among them) append an underscore to the names of variables and functions. When you debug programs compiled by those compilers, you will need to refer to variables and functions with a trailing underscore.
15.4.5.1 Fortran Operators and Expressions Fortran operators and expressions 15.4.5.2 Fortran Defaults Default settings for Fortran 15.4.5.3 Special Fortran Commands Special GDB commands for Fortran
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Operators must be defined on values of specific types. For instance,
+
is defined on numbers, but not on characters or other non-
arithmetic types. Operators are often defined on groups of types.
**
:
%
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Fortran symbols are usually case-insensitive, so GDB by default uses case-insensitive matches for Fortran symbols. You can change that with the `set case-insensitive' command, see 16. Examining the Symbol Table, for the details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB has some commands to support Fortran-specific features, such as displaying common blocks.
info common [common-name]
COMMON
block whose name is common-name. With no argument, the names of
all COMMON
blocks visible at the current program location are
printed.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Debugging Pascal programs which use sets, subranges, file variables, or nested functions does not currently work. GDB does not support entering expressions, printing values, or similar features using Pascal syntax.
The Pascal-specific command set print pascal_static-members
controls whether static members of Pascal objects are displayed.
See section pascal_static-members.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The extensions made to GDB to support Modula-2 only support output from the GNU Modula-2 compiler (which is currently being developed). Other Modula-2 compilers are not currently supported, and attempting to debug executables produced by them is most likely to give an error as GDB reads in the executable's symbol table.
15.4.7.1 Operators Built-in operators 15.4.7.2 Built-in Functions and Procedures Built-in functions and procedures 15.4.7.3 Constants Modula-2 constants 15.4.7.4 Modula-2 Types Modula-2 types 15.4.7.5 Modula-2 Defaults Default settings for Modula-2 15.4.7.6 Deviations from Standard Modula-2 Deviations from standard Modula-2 15.4.7.7 Modula-2 Type and Range Checks Modula-2 type and range checks 15.4.7.8 The Scope Operators ::
and.
The scope operators ::
and.
15.4.7.9 GDB and Modula-2
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Operators must be defined on values of specific types. For instance,
+
is defined on numbers, but not on structures. Operators are
often defined on groups of types. For the purposes of Modula-2, the
following definitions hold:
INTEGER
, CARDINAL
, and
their subranges.
CHAR
and its subranges.
REAL
.
POINTER TO
type
.
SET
and BITSET
types.
BOOLEAN
.
The following operators are supported, and appear in order of increasing precedence:
,
:=
:=
value is
value.
<, >
<=, >=
<
.
=, <>, #
<
. In GDB scripts, only <>
is
available for inequality, since #
conflicts with the script
comment character.
IN
<
.
OR
AND, &
@
+, -
*
/
*
.
DIV, MOD
*
.
-
INTEGER
and REAL
data.
^
NOT
^
.
.
RECORD
field selector. Defined on RECORD
data. Same
precedence as ^
.
[]
ARRAY
data. Same precedence as ^
.
()
PROCEDURE
objects. Same precedence
as ^
.
::, .
Warning: Set expressions and their operations are not yet supported, so GDB treats the use of the operatorIN
, or the use of operators+
,-
,*
,/
,=
, ,<>
,#
,<=
, and>=
on sets as an error.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Modula-2 also makes available several built-in procedures and functions. In describing these, the following metavariables are used:
ARRAY
variable.
CHAR
constant or variable.
SET OF mtype
(where mtype is the type of m).
All Modula-2 built-in procedures also return a result, described below.
ABS(n)
CAP(c)
CHR(i)
DEC(v)
DEC(v,i)
EXCL(m,s)
FLOAT(i)
HIGH(a)
INC(v)
INC(v,i)
INCL(m,s)
MAX(t)
MIN(t)
ODD(i)
ORD(x)
SIZE(x)
TRUNC(r)
TSIZE(x)
VAL(t,i)
Warning: Sets and their operations are not yet supported, so GDB treats the use of proceduresINCL
andEXCL
as an error.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GDB allows you to express the constants of Modula-2 in the following ways:
'
) or double ("
). They may
also be expressed by their ordinal value (their ASCII value, usually)
followed by a `C'.
'
) or double ("
).
Escape sequences in the style of C are also allowed. See section C and C++ Constants, for a brief explanation of escape
sequences.
TRUE
and
FALSE
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Currently GDB can print the following data types in Modula-2 syntax: array types, record types, set types, pointer types, procedure types, enumerated types, subrange types and base types. You can also print the contents of variables declared using these type. This section gives a number of simple source code examples together with sample GDB sessions.
The first example contains the following section of code:
VAR s: SET OF CHAR ; r: [20..40] ; |
and you can request GDB to interrogate the type and value of
r
and s
.
(gdb) print s {'A'..'C', 'Z'} (gdb) ptype s SET OF CHAR (gdb) print r 21 (gdb) ptype r [20..40] |
Likewise if your source code declares s
as:
VAR s: SET ['A'..'Z'] ; |
then you may query the type of s
by:
(gdb) ptype s type = SET ['A'..'Z'] |
Note that at present you cannot interactively manipulate set expressions using the debugger.
The following example shows how you might declare an array in Modula-2 and how you can interact with GDB to print its type and contents:
VAR s: ARRAY [-10..10] OF CHAR ; |
(gdb) ptype s ARRAY [-10..10] OF CHAR |
Note that the array handling is not yet complete and although the type
is printed correctly, expression handling still assumes that all
arrays have a lower bound of zero and not -10
as in the example
above.
Here are some more type related Modula-2 examples:
TYPE colour = (blue, red, yellow, green) ; t = [blue..yellow] ; VAR s: t ; BEGIN s := blue ; |
The GDB interaction shows how you can query the data type and value of a variable.
(gdb) print s $1 = blue (gdb) ptype t type = [blue..yellow] |
In this example a Modula-2 array is declared and its contents
displayed. Observe that the contents are written in the same way as
their C
counterparts.
VAR s: ARRAY [1..5] OF CARDINAL ; BEGIN s[1] := 1 ; |
(gdb) print s $1 = {1, 0, 0, 0, 0} (gdb) ptype s type = ARRAY [1..5] OF CARDINAL |
The Modula-2 language interface to GDB also understands pointer types as shown in this example:
VAR s: POINTER TO ARRAY [1..5] OF CARDINAL ; BEGIN NEW(s) ; s^[1] := 1 ; |
and you can request that GDB describes the type of s
.
(gdb) ptype s type = POINTER TO ARRAY [1..5] OF CARDINAL |
GDB handles compound types as we can see in this example. Here we combine array types, record types, pointer types and subrange types:
TYPE foo = RECORD f1: CARDINAL ; f2: CHAR ; f3: myarray ; END ; myarray = ARRAY myrange OF CARDINAL ; myrange = [-2..2] ; VAR s: POINTER TO ARRAY myrange OF foo ; |
and you can ask GDB to describe the type of s
as shown
below.
(gdb) ptype s type = POINTER TO ARRAY [-2..2] OF foo = RECORD f1 : CARDINAL; f2 : CHAR; f3 : ARRAY [-2..2] OF CARDINAL; END |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If type and range checking are set automatically by GDB, they
both default to on
whenever the working language changes to
Modula-2. This happens regardless of whether you or GDB
selected the working language.
If you allow GDB to set the language automatically, then entering code compiled from a file whose name ends with `.mod' sets the working language to Modula-2. See section Having GDB Infer the Source Language, for further details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A few changes have been made to make Modula-2 programs easier to debug. This is done primarily via loosening its type strictness:
:=
) returns the value of its right-hand
argument.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Warning: in this release, GDB does not yet perform type or range checking.
GDB considers two Modula-2 variables type equivalent if:
TYPE
t1 = t2
statement
As long as type checking is enabled, any attempt to combine variables whose types are not equivalent is an error.
Range checking is done on all mathematical operations, assignment, array index bounds, and all built-in functions and procedures.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
::
and .
There are a few subtle differences between the Modula-2 scope operator
(.
) and the GDB scope operator (::
). The two have
similar syntax:
module . id scope :: id |
where scope is the name of a module or a procedure, module the name of a module, and id is any declared identifier within your program, except another module.
Using the ::
operator makes GDB search the scope
specified by scope for the identifier id. If it is not
found in the specified scope, then GDB searches all scopes
enclosing the one specified by scope.
Using the .
operator makes GDB search the current scope for
the identifier specified by id that was imported from the
definition module specified by module. With this operator, it is
an error if the identifier id was not imported from definition
module module, or if id is not an identifier in
module.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some GDB commands have little use when debugging Modula-2 programs.
Five subcommands of set print
and show print
apply
specifically to C and C++: `vtbl', `demangle',
`asm-demangle', `object', and `union'. The first four
apply to C++, and the last to the C union
type, which has no direct
analogue in Modula-2.
The @
operator (see section Expressions), while available
with any language, is not useful with Modula-2. Its
intent is to aid the debugging of dynamic arrays, which cannot be
created in Modula-2 as they can in C or C++. However, because an
address can be specified by an integral constant, the construct
`{type}adrexp' is still useful.
In GDB scripts, the Modula-2 inequality operator #
is
interpreted as the beginning of a comment. Use <>
instead.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The extensions made to GDB for Ada only support output from the GNU Ada (GNAT) compiler. Other Ada compilers are not currently supported, and attempting to debug executables produced by them is most likely to be difficult.
15.4.8.1 Introduction General remarks on the Ada syntax and semantics supported by Ada mode in GDB. 15.4.8.2 Omissions from Ada Restrictions on the Ada expression syntax. 15.4.8.3 Additions to Ada Extensions of the Ada expression syntax. 15.4.8.4 Stopping at the Very Beginning Debugging the program during elaboration. 15.4.8.5 Ada Exceptions Ada exceptions handling. 15.4.8.6 Extensions for Ada Tasks Listing and setting breakpoints in tasks. 15.4.8.7 Tasking Support when Debugging Core Files 15.4.8.8 Tasking Support when using the Ravenscar Profile 15.4.8.9 Debugging Generic Units Dealing with generic instantiations. 15.4.8.10 Set commands for Ada New settable GDB parameters for Ada. 15.4.8.11 Known Peculiarities of Ada Mode Known peculiarities of Ada mode.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Ada mode of GDB supports a fairly large subset of Ada expression syntax, with some extensions. The philosophy behind the design of this subset is
Thus, for brevity, the debugger acts as if all names declared in user-written packages are directly visible, even if they are not visible according to Ada rules, thus making it unnecessary to fully qualify most names with their packages, regardless of context. Where this causes ambiguity, GDB asks the user's intent.
The debugger will start in Ada mode if it detects an Ada main program. As for other languages, it will enter Ada mode when stopped in a program that was translated from an Ada source file.
While in Ada mode, you may use `--' for comments. This is useful mostly for documenting command files. The standard GDB comment (`#') still works at the beginning of a line in Ada mode, but not in the middle (to allow based literals).
The debugger supports limited overloading. Given a subprogram call in which
the function symbol has multiple definitions, it will use the number of
actual parameters and some information about their types to attempt to narrow
the set of definitions. It also makes very limited use of context, preferring
procedures to functions in the context of the call
command, and
functions to procedures elsewhere.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here are the notable omissions from the subset:
in
) operator.
Characters.Latin_1
are not available and
concatenation is not implemented. Thus, escape characters in strings are
not currently available.
and
, or
,
xor
, not
, and relational tests other than equality)
are not implemented.
(gdb) set An_Array := (1, 2, 3, 4, 5, 6) (gdb) set An_Array := (1, others => 0) (gdb) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6) (gdb) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9)) (gdb) set A_Record := (1, "Peter", True); (gdb) set A_Record := (Name => "Peter", Id => 1, Alive => True) |
Changing a
discriminant's value by assigning an aggregate has an
undefined effect if that discriminant is used within the record.
However, you can first modify discriminants by directly assigning to
them (which normally would not be allowed in Ada), and then performing an
aggregate assignment. For example, given a variable A_Rec
declared to have a type such as:
type Rec (Len : Small_Integer := 0) is record Id : Integer; Vals : IntArray (1 .. Len); end record; |
you can assign a value with a different size of Vals
with two
assignments:
(gdb) set A_Rec.Len := 4 (gdb) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4)) |
As this example also illustrates, GDB is very loose about the usual
rules concerning aggregates. You may leave out some of the
components of an array or record aggregate (such as the Len
component in the assignment to A_Rec
above); they will retain their
original values upon assignment. You may freely use dynamic values as
indices in component associations. You may even use overlapping or
redundant component associations, although which component values are
assigned in such cases is not defined.
new
operator is not implemented.
True
and False
, when not part of a qualified name,
are interpreted as if implicitly prefixed by Standard
, regardless of
context.
Should your program
redefine these names in a package or procedure (at best a dubious practice),
you will have to use fully qualified names to access their new definitions.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As it does for other languages, GDB makes certain generic extensions to Ada (see section 10.1 Expressions):
E@N
displays the values of E and the
N-1 adjacent variables following it in memory as an array. In
Ada, this operator is generally not necessary, since its prime use is
in displaying parts of an array, and slicing will usually do this in
Ada. However, there are occasional uses when debugging programs in
which certain debugging information has been optimized away.
B::var
means "the variable named var that
appears in function or file B." When B is a file name,
you must typically surround it in single quotes.
{type} addr
means "the variable of type
type that appears at address addr."
In addition, GDB provides a few other shortcuts and outright additions specific to Ada:
(gdb) set x := y + 3 (gdb) print A(tmp := y + 1) |
(gdb) break f (gdb) condition 1 (report(i); k += 1; A(k) > 100) |
"One line.["0a"]Next line.["0a"]" |
Ada.Characters.Latin_1.LF
)
after each period.
(gdb) print 'max(x, y) |
(3 => 10, 17, 1) |
That is, in contrast to valid Ada, only the first component has a =>
clause.
(gdb) print <JMPBUF_SAVE>[0] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
It is sometimes necessary to debug the program during elaboration, and
before reaching the main procedure.
As defined in the Ada Reference
Manual, the elaboration code is invoked from a procedure called
adainit
. To run your program up to the beginning of
elaboration, simply use the following two commands:
tbreak adainit
and run
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The debugger can be used to stop the program execution when an exception is raised. For more details, see 5.1.3 Setting Catchpoints.
info exceptions
info exceptions regexp
info exceptions
command permits the user to examine all
defined Ada exceptions within the program being debugged. With a regular
expression, regexp, as argument, prints out only those exceptions
whose name matches regexp.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Support for Ada tasks is analogous to that for threads (see section 4.10 Debugging Programs with Multiple Threads). GDB provides the following task-related commands:
info tasks
(gdb) info tasks ID TID P-ID Pri State Name 1 8088000 0 15 Child Activation Wait main_task 2 80a4000 1 15 Accept Statement b 3 809a800 1 15 Child Activation Wait a * 4 80ae800 3 15 Runnable c |
In this listing, the asterisk before the last task indicates it to be the task currently being inspected.
Unactivated
Runnable
Terminated
Child Activation Wait
Accept Statement
Waiting on entry call
Async Select Wait
Delay Sleep
Child Termination Wait
Wait Child in Term Alt
Accepting RV with taskno
info task taskno
(gdb) info tasks ID TID P-ID Pri State Name 1 8077880 0 15 Child Activation Wait main_task * 2 807c468 1 15 Runnable task_1 (gdb) info task 2 Ada Task: 0x807c468 Name: task_1 Thread: 0x807f378 Parent: 1 (main_task) Base Priority: 15 State: Runnable |
task
(gdb) info tasks ID TID P-ID Pri State Name 1 8077870 0 15 Child Activation Wait main_task * 2 807c458 1 15 Runnable t (gdb) task [Current task is 2] |
task taskno
thread threadno
command (see section 4.10 Debugging Programs with Multiple Threads). It switches the context of debugging
from the current task to the given task.
(gdb) info tasks ID TID P-ID Pri State Name 1 8077870 0 15 Child Activation Wait main_task * 2 807c458 1 15 Runnable t (gdb) task 1 [Switching to task 1] #0 0x8067726 in pthread_cond_wait () (gdb) bt #0 0x8067726 in pthread_cond_wait () #1 0x8056714 in system.os_interface.pthread_cond_wait () #2 0x805cb63 in system.task_primitives.operations.sleep () #3 0x806153e in system.tasking.stages.activate_tasks () #4 0x804aacc in un () at un.adb:5 |
break linespec task taskno
break linespec task taskno if ...
break ... thread ...
command (see section 5.5 Stopping and Starting Multi-thread Programs).
linespec specifies source lines, as described
in 9.2 Specifying a Location.
Use the qualifier `task taskno' with a breakpoint command to specify that you only want GDB to stop the program when a particular Ada task reaches this breakpoint. taskno is one of the numeric task identifiers assigned by GDB, shown in the first column of the `info tasks' display.
If you do not specify `task taskno' when you set a breakpoint, the breakpoint applies to all tasks of your program.
You can use the task
qualifier on conditional breakpoints as
well; in this case, place `task taskno' before the
breakpoint condition (before the if
).
For example,
(gdb) info tasks ID TID P-ID Pri State Name 1 140022020 0 15 Child Activation Wait main_task 2 140045060 1 15 Accept/Select Wait t2 3 140044840 1 15 Runnable t1 * 4 140056040 1 15 Runnable t3 (gdb) b 15 task 2 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15. (gdb) cont Continuing. task # 1 running task # 2 running Breakpoint 5, test_task_debug () at test_task_debug.adb:15 15 flush; (gdb) info tasks ID TID P-ID Pri State Name 1 140022020 0 15 Child Activation Wait main_task * 2 140045060 1 15 Runnable t2 3 140044840 1 15 Runnable t1 4 140056040 1 15 Delay Sleep t3 |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When inspecting a core file, as opposed to debugging a live program, tasking support may be limited or even unavailable, depending on the platform being used. For instance, on x86-linux, the list of tasks is available, but task switching is not supported. On Tru64, however, task switching will work as usual.
On certain platforms, including Tru64, the debugger needs to perform some memory writes in order to provide Ada tasking support. When inspecting a core file, this means that the core file must be opened with read-write privileges, using the command `"set write on"' (see section 17.6 Patching Programs). Under these circumstances, you should make a backup copy of the core file before inspecting it with GDB.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Ravenscar Profile is a subset of the Ada tasking features, specifically designed for systems with safety-critical real-time requirements.
set ravenscar task-switching on
set ravenscar task-switching off
show ravenscar task-switching
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNAT always uses code expansion for generic instantiation. This means that each time an instantiation occurs, a complete copy of the original code is made with appropriate substitutions.
It is not possible to refer to the original generic entities themselves
in GDB (there is no code to refer to), but it
is certainly possible to debug a particular instance of a generic, simply by
using the appropriate expanded names. For example, suppose that
Gen
is a generic package:
-- In file gen.ads: generic package Gen is function F (v1 : Integer) return Integer; end Gen; -- In file gen.adb: package body Gen is function F (v1 : Integer) return Integer is begin return v1+1; -- Line 5 end F; end Gen; |
and we have the following expansions
with Gen; procedure G is package Gen1 is new Gen; package Gen2 is new Gen; I : Integer := 0; begin I := Gen1.F (I); I := Gen2.F (I); I := Gen1.F (I); I := Gen2.F (I); end; |
Then to break on a call to procedure F
in the Gen2
instance, simply
use the command:
(gdb) break G.Gen2.F |
To break at a particular line in a particular generic instance, say the return
statement in G.Gen2
, append the line specification to the file and
function name:
(gdb) break gen.adb:G.Gen2.F:5 |
To break on this line line in all instances of Gen
, use `*'
as the function name:
(gdb) break gen.adb:*:5 |
This will set individual breakpoints at all instances; they are independent of each other and you may remove, conditionalize, or otherwise modify them individually.
When a breakpoint occurs, you can step through the code of the generic instance in the normal manner. You can also examine values of data in the normal manner, providing the appropriate generic package qualification to refer to non-local entities.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Ada introduces new set
commands.
set varsize-limit size
x.y.z
, may
fail if the size of x.y is dynamic and exceeds size.
On the other hand, GDB is sometimes clever;
the expression A(i)
, where A is an
array variable with non-constant size, will generally succeed regardless of the
bounds on A, as long as the component size is less than size.
show varsize-limit
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Besides the omissions listed previously (see section 15.4.8.2 Omissions from Ada), we know of several problems with and limitations of Ada mode in GDB, some of which will be fixed with planned future releases of the debugger and the GNU Ada compiler.
up
commands to get to
frame containing the variable you wish to see.
Access to non-local variables does not, at the moment, work in
the test expressions for conditional breakpoints
(see section Break conditions) unless you happen to specify these
while stopped in the subprogram in which they are to be applied.
Standard
for any of
the standard symbols defined by the Ada language. GDB knows about
this: it will strip the prefix from names when you use it, and will never
look for a name you have so qualified among local symbols, nor match against
symbols in other packages or subprograms. If you have
defined entities anywhere in your program other than parameters and
local variables whose simple names match names in Standard
,
GNAT's lack of qualification here can cause confusion. When this happens,
you can usually resolve the confusion
by qualifying the problematic names with package
Standard
explicitly.
Older versions of the compiler sometimes generate erroneous debugging information, resulting in the debugger incorrectly printing the value of affected entities. In some cases, the debugger is able to work around an issue automatically. In other cases, the debugger is able to work around the issue, but the work-around has to be specifically enabled.
set ada trust-PAD-over-XVS on
PAD
and PAD___XVS
types are involved (see ada/exp_dbug.ads
in the GCC sources for
a complete description of the encoding used by the GNAT compiler).
This is the default.
set ada trust-PAD-over-XVS off
ada
trust-PAD-over-XVS
to off
activates a work-around which may fix
the issue. It is always safe to set ada trust-PAD-over-XVS
to
off
, but this incurs a slight performance penalty, so it is
recommended to leave this setting to on
unless necessary.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In addition to the other fully-supported programming languages,
GDB also provides a pseudo-language, called minimal
.
It does not represent a real programming language, but provides a set
of capabilities close to what the C or assembly languages provide.
This should allow most simple operations to be performed while debugging
an application that uses a language currently not supported by GDB.
If the language is set to auto
, GDB will automatically
select this language if the current frame corresponds to an unsupported
language.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |