The Maple Debugger - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Debugging : debugger

The Maple Debugger

  

The Maple debugger is a tool that you can use to detect errors in your procedures.  Using this facility, you can follow step-by-step execution of your code to determine why it is not returning the results that you expect.

  

You can use the command-line Maple debugger or the debugger available in the standard interface.  The same functionality is available through both interfaces.

• 

For command-line usage, see the following Description section.

• 

For usage in the standard interface, see the Interactive Maple Debugger help page.

  

Note: Both the command-line and interactive debugger can use the Commands listed in this help page.

 

Description

Commands

Examples

Description

• 

When the Debugger is invoked, it displays an expression (unless the previous debugger command was terminated by a colon), the next statement to be executed, and a debugging prompt (or a prompt in a debugging window).

  

If the Debugger was invoked by a breakpoint (as set by stopat), or the result of executing one of the debugger commands next, step, into, outfrom, or return, the displayed expression is the result of the last statement executed.

  

If it was invoked by a watchpoint on a variable (as set by stopwhen or stopwhenif), the expression is an equality, the left-hand side of which is the name of the variable that was being watched, and the right-hand side of which shows the value that was assigned to the variable.

  

If it was invoked by a watchpoint on an error message (as set by stoperror), the expression is the error message.

• 

Large rtables are displayed by the debugger in an abbreviated form (the data stored in the rtable is elided). This is done for rtables of more than two dimensions, or any dimension of more than interfacertablesize elements.

Commands

  

At the debugging prompt, the following commands are available. Items shown in square brackets are optional.

  

cont [N]

  

Continues execution until another breakpoint or watchpoint is encountered, or until execution terminates normally. If an optional positive integer N was specified, execution continues until the Nth next breakpoint is encountered.

  

next [N]

  

Executes the next statement at the current nesting level. If the statement is a control structure (for example, "if"), it is executed in its entirety before execution stops again. Likewise, if the statement contains function calls, these are executed in their entirety as well.  After executing the statement, control returns to the Debugger as though a breakpoint had been set. If an optional positive integer N was specified, execution continues for N statements at the current nesting level.

  

step [N]

  

Executes the next statement at any level. Execution stops before the following statement, regardless of whether it is at the current nesting level, in the body of a control structure (for example, "if"), or in a called function. If an optional positive integer N was specified, execution continues for N statements at any level.

  

into [N]

  

Halfway between next and step. Executes the next statement. Execution stops before the following statement within the current function, regardless of whether it is at the current nesting level or in the body of a control structure. Execution will NOT stop in a called function. If an optional positive integer N was specified, execution continues for N statements at any level within the current function.

  

outfrom [N]

  

Execution continues until the current statement sequence has finished executing, or until a breakpoint or watchpoint is encountered. If the outfrom command is executed while stopped in a loop, execution continues until just before the first statement to be executed after the closing end do. Note that if the same breakpoint that caused execution to stop in the loop is encountered again in a subsequent iteration of the loop, execution will stop again. If the outfrom command is executed while stopped in the body of an if statement, execution continues until just before the first statement to be executed after the closing end if. If an optional positive integer N was specified, execution continues until N levels of nested statements have finished executing.

  

return [N]

  

Execution continues until the first statement to be executed after the currently executing procedure returns. If an optional positive integer N was specified, execution continues until N procedures have finished executing.

  

quit, done, or stop

  

Execution is terminated entirely, and the user is returned to the top level of Maple (that is, the prompt).

  

where [numLevels]

  

Shows a stack of the procedure calls leading to where execution is currently stopped. If a number of levels is specified, only that number of levels is shown (the lowest levels are shown). The topmost level is shown first. For each level, the calling procedure and the statement within it are shown, followed on the next line by a list giving the arguments that were passed. If the where command was terminated with a colon (":"), the arguments are not shown.

  

where? [numLevels] (or showstack [numLevels])

  

Shows an abbreviated stack of the procedure calls leading to where execution is currently stopped. Only the names of the procedures in the call chain are listed.

  

showstat [procName] [statNumber[..statNumber]]

  

Displays the specified procedure (the currently stopped procedure by default) with statement numbers. If a specific statement number or range of statement numbers is given, only those statements are displayed. The elided statements are represented by "..." in the output.

  

showstop

  

Displays a list of all procedures containing breakpoints, all watchpoints, and all error watchpoints.

  

list [procName] [statNumber[..statNumber]]

  

Similar to showstat, except that if no arguments are given, the previous five statements, the current statement, and the next statement are shown. This is an easy way to see some context in the procedure.

  

stopat [procName] [statNumber] [condition]

  

A breakpoint is set in the specified procedure (the currently stopped procedure by default) at the specified statement number (the first statement by default). The optional condition, which must be a Boolean expression, causes execution to stop at the breakpoint only if the condition is met. If a condition is specified, the procedure name and statement number must be specified.

  

unstopat [procName] [statNumber]

  

The specified breakpoint (all breakpoints by default) in the specified procedure (the currently stopped procedure by default) is removed.

  

stopwhen [globVar]

  

stopwhen [procName locOrGlobVar]

  

Sets a watchpoint on the specified local or global variable, and displays the current list of watchpoints.  If no variable is specified, the current list of watchpoints is displayed.

  

stopwhenif globVar value

  

Sets a conditional watchpoint on the specified global variable, and displays the current list of all watchpoints.

  

unstopwhen [globVar]

  

unstopwhen [procName locOrGlobVar]

  

Clears the watchpoint on the specified local or global variable and displays the current list of watchpoints.  If no variable is specified, all watchpoints are cleared.

  

stoperror [errMsg]

  

Sets a watchpoint on the specified error, and returns the current list of watchpoints.  If no error is specified, the current list of watchpoints is displayed. If passed the name "all", execution stops and the Debugger is invoked when any untrapped error occurs.  If passed the name "traperror", execution stops when any error is trapped. For more details on using stoperror, see stoperror.

  

unstoperror [errMsg]

  

Clears the watchpoints on the specified error and displays the current list of watchpoints.  If no error is specified, all error watchpoints are cleared.

  

showerror

  

showexception

  

Displays the value of lasterror or lastexception at the time the Debugger was invoked. The displayed value is enclosed in a list; the enclosing list is not part of the actual value.

  

Any Maple Expression

  

The expression is evaluated in the context of the stopped procedure, and the result is displayed. The semantics of variable names and evaluation are exactly the same as though the expression had originally appeared within the procedure (except that using a variable as the control variable of seq() will not make that variable local if it is not already local). Because the Debugger runs in its own environment, the expressions lasterror and lastexception do not refer to the error that may have caused the Debugger to be invoked. Use the showerror or showexception commands instead.

  

statement Any-Maple-Expression

  

Similar to the above, except the expression is evaluated in a global context and the result is displayed.  The keyword statement precedes the Maple expression.

  

lvalue := expression

  

The expression is evaluated in the context of the stopped procedure, and the result is assigned to the expression on the left-hand side, which can refer to global variables, environment variables, or local variables of the stopped procedure.  A space must precede the assignment operator for it to be recognized.

• 

The following example illustrates the function of each control flow command of the Debugger. It is assumed that computation started by calling proc1. The line marked <START> is where execution is assumed to be stopped initially. The other lines of the form <command> show where execution would stop if the respective command were issued at that point:

                     proc3 := proc()

<step>                   statement1;

                         statement2;

                         true;

                     end proc;

                     proc2 := proc()

                         statement1;

                         statement2;

                         if 1 < 2 then

<START>                      if proc3() then

<into>                           statement5;

                                 statement6;

                             end if;

<next>                       statement7;

                         end if;

<outfrom>                statement8;

                     end proc;

                     proc1 := proc()

                         statement1;

                         statement2;

                         proc2();

<return>                 statement4;

                         statement5;

                     end proc;

• 

In the above example, the cont command would cause execution to continue to completion.

• 

Maple statements that are not expressions (for example, "if", "while", and so on) are not permitted at the Debugger prompt.

• 

If the global variable debugger/max_width is set to a positive integer value, expressions and error messages displayed by the Debugger are truncated to that width.

• 

The Debugger is implemented as a Maple procedure which is invoked automatically by Maple when a breakpoint or watchpoint is encountered, or when the DEBUG function is executed. The Debugger procedure should not be invoked by the user.

Examples

Note: These examples illustrate the use of these debugger commands in Maple's command-line interface. In the standard (graphical) interface, the debugger runs in its own window, with controls for most of the common commands.  See Interactive Maple Debugger for details.

f := proc(x,y) local a; global b;
    if x < y then
        a := x; b := y + a;
    else
        a := y; b := x + a;
    end if;
    a + b + x + y
end proc:

stopatf

f

(1)

f2&comma;3

 f:

    1*   if x < y then

           ...

         else

           ...

         end if;

 

 DBG> stopwhen b

 [b]

 f:

    1*   if x < y then

           ...

         else

           ...

         end if;

 

 DBG> cont

 b := 5

 f:

    6    a+b+x+y

 

 DBG> showstat

 f := proc(x, y)

 local a;

 global b;

    1*   if x < y then

    2      a := x;

    3      b := y+a

         else

    4      a := y;

    5      b := x+a

         end if;

    6 !  a+b+x+y

 end

 

 DBG> quit

 Warning, computation interrupted

See Also

DEBUG

Interactive Maple Debugger

lists

showstat

stopat

stoperror

stopwhen

stopwhenif

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam