manpagez: man pages & more
info gdb
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.4.5.4 Modula-2 Types

Currently No value for GDBN 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 No value for GDBN sessions.

The first example contains the following section of code:

 
VAR
   s: SET OF CHAR ;
   r: [20..40] ;

and you can request No value for GDBN to interrogate the type and value of r and s.

 
(No value for GDBP) print s
{'A'..'C', 'Z'}
(No value for GDBP) ptype s
SET OF CHAR
(No value for GDBP) print r
21
(No value for GDBP) 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:

 
(No value for GDBP) 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 No value for GDBN to print its type and contents:

 
VAR
   s: ARRAY [-10..10] OF CHAR ;
 
(No value for GDBP) 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. Unbounded arrays are also not yet recognized in No value for GDBN.

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 No value for GDBN interaction shows how you can query the data type and value of a variable.

 
(No value for GDBP) print s
$1 = blue
(No value for GDBP) 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 ;
 
(No value for GDBP) print s
$1 = {1, 0, 0, 0, 0}
(No value for GDBP) ptype s
type = ARRAY [1..5] OF CARDINAL

The Modula-2 language interface to No value for GDBN 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 No value for GDBN describes the type of s.

 
(No value for GDBP) ptype s
type = POINTER TO ARRAY [1..5] OF CARDINAL

No value for GDBN 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 No value for GDBN to describe the type of s as shown below.

 
(No value for GDBP) 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] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.