Next: M2 Defaults, Previous: M2 Constants, Up: Modula-2

##### 15.4.8.4 Modula-2 Types

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