Running External Programs under a Debugger

MathLink allows you to run external programs under whatever debugger is provided in your software environment.

MathLink-compatible programs are typically set up to take arguments, usually on the command line, which specify what MathLink connections they should use.

In debugger:run -linkcreate -linkprotocol TCPIP
In Mathematica:Install[LinkConnect["port",LinkProtocol->"TCPIP"]]

Running an external program under a debugger.

Note that in order to get a version of an external program that can be run under a debugger, you need to compile the program so that the output is suitable for use with your debugger. Unix compilers commonly use as a command-line argument for producing a debuggable program. See your compiler documentation for specific information on the steps you should take.

Unix debugger

Set a breakpoint in the C function .
break f
Breakpoint set: f: line 1
Start the external program.
run -linkcreate -linkprotocol TCPIP 
The program responds with what port it is listening on.
Link created on: 2981@frog.wolfram.com,2982@frog.wolfram.com 

Mathematica session

This connects to the program running under the debugger.
In[1]:=
Click for copyable input
Out[1]=
This calls a function that executes code in the external program.
In[2]:=
Click for copyable input

Unix debugger

The external program stops at the breakpoint.
Breakpoint: f(16) 
This tells the debugger to continue.
continue 

Mathematica session

Now returns.
Out[3]=
New to Mathematica? Find your learning path »
Have a question? Ask support »