Function Repository Resource:

TraceInteractive

Source Notebook

Trace an evaluation with an interface that allows interactive debugging

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["TraceInteractive"][expr]

evaluates expr in an interactive interface where each step of the evaluation can be inspected.

ResourceFunction["TraceInteractive"][expr,patt]

sets patt as a breakpoint for entering subsessions.

Details and Options

ResourceFunction["TraceInteractive"] has the following options:
CreateWindowTruecreate a new window for tracing
NotebookCloseFalseclose the window when finished
The buttons at the top of the window perform the following actions:
Return: Finish the evaluation with no further interruptions and return the result.
Continue: Resume evaluation until the next breakpoint is encountered.
Next: Proceed to the next expression in the trace.
Step: Same as ,except includes atomic expressions.

Examples

Basic Examples (3) 

Retrieve the ResourceFunction:

In[1]:=
ResourceFunction["TraceInteractive"]
Out[1]=

Trace an evaluation and stop whenever addition occurs:

In[2]:=
ResourceFunction["TraceInteractive"][# + 2 # & /@ Range[3], _Plus]
Out[2]=

Additional breakpoints can be added during evaluation by clicking the + button to the right of the breakpoints:

To remove breakpoints, just click them in the list.

Now clicking Continue will stop on multiplication as well:

The Return button will complete the evaluation with no further interruptions:


The colored numbers on the left of each cell correspond to the current trace level of the evaluation:

In[3]:=
factorial[0] = 1;
factorial[x_Integer?Positive] := factorial[x - 1]*x;
ResourceFunction["TraceInteractive"][factorial[4], _factorial]
Out[3]=

Options (2) 

Use the current notebook instead of creating a new one:

In[4]:=
ResourceFunction["TraceInteractive"][# + 1 & /@ Range[3], _Plus, CreateWindow -> False]

Automatically close the trace notebook when evaluation is complete (result is returned to the current notebook):

In[5]:=
ResourceFunction["TraceInteractive"][# + 1 & /@ Range[3], _Plus, NotebookClose -> True]
Out[5]=

Applications (1) 

Enter a subsession when an error occurs to investigate the current Stack:

In[6]:=
bytes = ByteArray[{56, 67, 58, 120, 156, 45, 200, 177, 14, 130, 48, 16, 6, 96, 67, 162, 29, 116, 209, 39, 96, 240, 77, 136, 50, 233, 2,
    139, 155, 135, 253, 75, 47, 148, 59, 210, 131, 196, 199, 183, 131,
    219, 151, 47, 84, 182, 111, 34, 62, 83, 168, 236, 210, 232, 188, 232, 38, 254, 246, 93, 50, 204, 88, 165, 172, 123, 20, 210, 136, 194, 227, 159, 79, 154, 97, 174, 133, 32, 83, 234, 14, 44, 43, 114,
    238, 78, 47, 221, 234, 33, 235, 132, 154, 215, 176, 179, 115, 155,
    116, 160, 244, 246, 218, 71, 244, 145, 101, 52, 119, 189, 19, 39, 248, 31, 134, 178, 41, 81}];
BinaryDeserialize[bytes]
Out[6]=
In[7]:=
ResourceFunction["TraceInteractive"][BinaryDeserialize[bytes], HoldPattern[General::interr]]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.1.0 – 29 October 2018
  • 1.0.0 – 12 October 2018

Related Resources

License Information