blob: 2fe11f8bdf2e6a797b9bd55db6af03ae4ab78600 [file] [log] [blame]
<html lang="en">
<head>
<title>M2 Types - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Modula_002d2.html#Modula_002d2" title="Modula-2">
<link rel="prev" href="M2-Constants.html#M2-Constants" title="M2 Constants">
<link rel="next" href="M2-Defaults.html#M2-Defaults" title="M2 Defaults">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="M2-Types"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="M2-Defaults.html#M2-Defaults">M2 Defaults</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="M2-Constants.html#M2-Constants">M2 Constants</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Modula_002d2.html#Modula_002d2">Modula-2</a>
<hr>
</div>
<h5 class="subsubsection">15.4.6.4 Modula-2 Types</h5>
<p><a name="index-Modula_002d2-types-849"></a>
Currently <span class="sc">gdb</span> 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 <span class="sc">gdb</span> sessions.
<p>The first example contains the following section of code:
<pre class="smallexample"> VAR
s: SET OF CHAR ;
r: [20..40] ;
</pre>
<p class="noindent">and you can request <span class="sc">gdb</span> to interrogate the type and value of
<code>r</code> and <code>s</code>.
<pre class="smallexample"> (gdb) print s
{'A'..'C', 'Z'}
(gdb) ptype s
SET OF CHAR
(gdb) print r
21
(gdb) ptype r
[20..40]
</pre>
<p class="noindent">Likewise if your source code declares <code>s</code> as:
<pre class="smallexample"> VAR
s: SET ['A'..'Z'] ;
</pre>
<p class="noindent">then you may query the type of <code>s</code> by:
<pre class="smallexample"> (gdb) ptype s
type = SET ['A'..'Z']
</pre>
<p class="noindent">Note that at present you cannot interactively manipulate set
expressions using the debugger.
<p>The following example shows how you might declare an array in Modula-2
and how you can interact with <span class="sc">gdb</span> to print its type and contents:
<pre class="smallexample"> VAR
s: ARRAY [-10..10] OF CHAR ;
</pre>
<pre class="smallexample"> (gdb) ptype s
ARRAY [-10..10] OF CHAR
</pre>
<p>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 <code>-10</code> as in the example
above.
<p>Here are some more type related Modula-2 examples:
<pre class="smallexample"> TYPE
colour = (blue, red, yellow, green) ;
t = [blue..yellow] ;
VAR
s: t ;
BEGIN
s := blue ;
</pre>
<p class="noindent">The <span class="sc">gdb</span> interaction shows how you can query the data type
and value of a variable.
<pre class="smallexample"> (gdb) print s
$1 = blue
(gdb) ptype t
type = [blue..yellow]
</pre>
<p class="noindent">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 <code>C</code> counterparts.
<pre class="smallexample"> VAR
s: ARRAY [1..5] OF CARDINAL ;
BEGIN
s[1] := 1 ;
</pre>
<pre class="smallexample"> (gdb) print s
$1 = {1, 0, 0, 0, 0}
(gdb) ptype s
type = ARRAY [1..5] OF CARDINAL
</pre>
<p>The Modula-2 language interface to <span class="sc">gdb</span> also understands
pointer types as shown in this example:
<pre class="smallexample"> VAR
s: POINTER TO ARRAY [1..5] OF CARDINAL ;
BEGIN
NEW(s) ;
s^[1] := 1 ;
</pre>
<p class="noindent">and you can request that <span class="sc">gdb</span> describes the type of <code>s</code>.
<pre class="smallexample"> (gdb) ptype s
type = POINTER TO ARRAY [1..5] OF CARDINAL
</pre>
<p><span class="sc">gdb</span> handles compound types as we can see in this example.
Here we combine array types, record types, pointer types and subrange
types:
<pre class="smallexample"> 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 ;
</pre>
<p class="noindent">and you can ask <span class="sc">gdb</span> to describe the type of <code>s</code> as shown
below.
<pre class="smallexample"> (gdb) ptype s
type = POINTER TO ARRAY [-2..2] OF foo = RECORD
f1 : CARDINAL;
f2 : CHAR;
f3 : ARRAY [-2..2] OF CARDINAL;
END
</pre>
</body></html>