Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 5235

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>the debugger</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_then.html">next</a> | <a href="_tex__Math.html">previous</a> | <a href="_then.html">forward</a> | <a href="_tex__Math.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<hr/>
<div><h1>the debugger</h1>
<div>We have a Macaulay2 source file with a pair of functions in it that we can use for demonstrating the debugger.  Let's load it so we can run the functions in it.<table class="examples"><tr><td><pre>i1 : load "Macaulay2Doc/demo1.m2"</pre>
</td></tr>
</table>
We can see what functions were provided to us with <a href="_list__User__Symbols.html" title="display the user's symbols">listUserSymbols</a>.<table class="examples"><tr><td><pre>i2 : listUserSymbols

o2 = symbol   class              value
     ------   -----              -----
     g      : FunctionClosure -- g    
     ------------------------------------------------------------------------
     location of symbol
     ------------------                                                      
     /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/m2/setup.m2:40:26
     ------------------------------------------------------------------------
           
     -40:26</pre>
</td></tr>
</table>
Let's peek at the code of the function <tt>g</tt>.<table class="examples"><tr><td><pre>i3 : code g

o3 = /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:11:7-14:8: --source code:
     g = y -> (
          c := f(y-1);
          d := f(y-2);
          c+d)</pre>
</td></tr>
</table>
We see that the function g calls a function <tt>f</tt>, but <tt>f</tt> is not visible to us (because <tt>f</tt> is a local variable).  In emacs' <em>Macaulay2 Interaction Mode</em>, pressing return (<tt>RET</tt> or <tt>enter</tt>) after positioning the cursor on the output line displaying the file name and line number will bring up the source code in a new buffer.<p>The first few times we use <tt>g</tt>, it seems to work.</p>
<table class="examples"><tr><td><pre>i4 : g 4

     17
o4 = --
      6

o4 : QQ</pre>
</td></tr>
<tr><td><pre>i5 : g 3

     7
o5 = -
     2

o5 : QQ</pre>
</td></tr>
</table>
However, the following attempt results in an error, and the debugger starts up automatically.<table class="examples"><tr><td><pre>i6 : g 2
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: error: division by zero
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
     b := 1/x;</pre>
</td></tr>
</table>
We use <a href="_help.html" title="help command">help</a>, as instructed, to view the commands available in the debugger.<table class="examples"><tr><td><pre>ii7 : help
--loading the Macaulay2 documentation from /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/

oo7 = --debugging control:
          return              -- bypass current expression, return null, stop
          return x            -- bypass current expression, return x, stop
          step                -- step 1 line
          step n              -- step n lines
          step (-n)           -- trace n microsteps
          end (or eof char)   -- enter debugger one level up
          continue            -- leave the debugger, continuing execution
                              -- with current expression
          break               -- leave the debugger, returning to top level
      --debugging information:
          listLocalSymbols    -- display local symbols and their values
          listUserSymbols     -- display user symbols and their values
          current             -- the current expression; initially, the one
                              -- that produced an error
          code current        -- source code of current expression
          value current       -- execute current expression, obtain value
          disassemble current -- display microcode of current expression
          currentString       -- the string being evaluated by 'value', if
                              -- an error occurred within it
      -- emacs commands in *M2* buffer:
          RET                 -- on an file/position line, go to source</pre>
</td></tr>
</table>
As suggested, we can use <a href="_list__Local__Symbols.html" title="display of local symbols and their values">listLocalSymbols</a> to list the local symbols and their values.<table class="examples"><tr><td><pre>ii8 : listLocalSymbols

oo8 = symbol   class              value                                                   location of symbol
      ------   -----              -----                                                   ------------------                                                                           
      x      : ZZ              -- 0                                                       /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:6-6:6
      a      : String          -- "hi there"                                              /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:7:6-7:6
      b      : Nothing         -- null                                                    /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:6-8:6
      f      : FunctionClosure -- {*Function[/builddir/build/BUILD/Macaulay2-1.3.1-r1073. /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:1-6:1</pre>
</td></tr>
</table>
We see the the value of <tt>x</tt> is 0, and that explains the error message about division by zero.  The other local symbols are the ones defined in the body of the function <tt>f</tt>, whose code can now be displayed with <a href="_code.html" title="display source code">code</a>.<table class="examples"><tr><td><pre>ii9 : code f

oo9 = /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:8-9:8: --source code:
      f := x -> (
           a := "hi there";
           b := 1/x;
           b+1)</pre>
</td></tr>
</table>
We can use <a href="_step.html" title="step by single lines in the debugger">step</a> with argument 0 to bypass the current expression.<table class="examples"><tr><td><pre>ii10 : step 0
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --stepping limit reached
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
     b := 1/x;</pre>
</td></tr>
</table>
If we decide the problem is one level up, we can use <tt>end</tt> or the end-of-file character (which often is CTRL-D) to quit this instance of the debugger.  In this case, the debugger will be entered again (triggered by the same error indication that caused it to be entered originally) at the point inside the function <tt>g</tt> from which the function <tt>f</tt> was called.<table class="examples"><tr><td><pre>ii11 : end
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:11:(3):[1]: --entering debugger (type help to see debugger commands)
/builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:11-13:15: --source code:
     d := f(y-2);</pre>
</td></tr>
</table>
We can use <a href="_list__Local__Symbols.html" title="display of local symbols and their values">listLocalSymbols</a> again to see the local variables of <tt>g</tt>.<table class="examples"><tr><td><pre>ii12 : listLocalSymbols

oo12 = symbol   class              value                                                   location of symbol
       ------   -----              -----                                                   ------------------                                                                             
       y      : ZZ              -- 2                                                       /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:11:5-11:5
       c      : QQ              -- 2                                                       /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:12:6-12:6
       d      : Nothing         -- null                                                    /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:13:6-13:6
       f      : FunctionClosure -- {*Function[/builddir/build/BUILD/Macaulay2-1.3.1-r1073. /builddir/build/BUILD/Macaulay2-1.3.1-r10737/Macaulay2/packages/Macaulay2Doc/demo1.m2:6:1-6:1  </pre>
</td></tr>
</table>
After we are done debugging, we can quit the debugger entirely and return to top level with <a href="_break.html" title="break from a loop">break</a>.<table class="examples"><tr><td><pre>ii13 : break</pre>
</td></tr>
</table>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_break.html" title="break from a loop">break</a> -- break from a loop</span></li>
<li><span><a href="_end.html" title="stop loading a file">end</a> -- stop loading a file</span></li>
<li><span><a href="_step.html" title="step by single lines in the debugger">step</a> -- step by single lines in the debugger</span></li>
<li><span><a href="_continue.html" title="continue with the next iteration of a loop">continue</a> -- continue with the next iteration of a loop</span></li>
<li><span><a href="_return.html" title="return from a function">return</a> -- return from a function</span></li>
<li><span><a href="_list__Local__Symbols.html" title="display of local symbols and their values">listLocalSymbols</a> -- display of local symbols and their values</span></li>
<li><span><a href="_list__User__Symbols.html" title="display the user's symbols">listUserSymbols</a> -- display the user's symbols</span></li>
<li><span><a href="_code.html" title="display source code">code</a> -- display source code</span></li>
<li><span><a href="_value.html" title="evaluate">value</a> -- evaluate</span></li>
<li><span><a href="_disassemble.html" title="disassemble pseudocode or a function">disassemble</a> -- disassemble pseudocode or a function</span></li>
</ul>
</div>
</div>
</body>
</html>